[PowerPC] Fix rounding mode for vec_round in altivec.h

The function is supposed to be the equivalent of rint() (as in
round to nearest, ties to even) rather than round() (round to
nearest, ties away from zero). In fact, the instruction we emit
without VSX is vrfin which is correct. However, with VSX we emit
xvrspi which is the equivalent of round() and therefore incorrect.
Since there is no equivalent VSX instruction, simply use vrfin
regardless of availability of VSX.
This commit is contained in:
Nemanja Ivanovic 2021-07-12 05:49:12 -05:00
parent 8bbf2f7a44
commit 84e429693f
2 changed files with 2 additions and 6 deletions

View File

@ -8386,11 +8386,7 @@ vec_vrlw(vector unsigned int __a, vector unsigned int __b) {
/* vec_round */
static __inline__ vector float __ATTRS_o_ai vec_round(vector float __a) {
#ifdef __VSX__
return __builtin_vsx_xvrspi(__a);
#else
return __builtin_altivec_vrfin(__a);
#endif
}
#ifdef __VSX__

View File

@ -407,8 +407,8 @@ void test1() {
// CHECK-LE: call <4 x i32> @llvm.ppc.altivec.vperm(<4 x i32> [[T1]], <4 x i32> [[T2]], <16 x i8>
res_vf = vec_round(vf);
// CHECK: call <4 x float> @llvm.round.v4f32(<4 x float>
// CHECK-LE: call <4 x float> @llvm.round.v4f32(<4 x float>
// CHECK: call <4 x float> @llvm.ppc.altivec.vrfin(<4 x float>
// CHECK-LE: call <4 x float> @llvm.ppc.altivec.vrfin(<4 x float>
res_vd = vec_round(vd);
// CHECK: call <2 x double> @llvm.round.v2f64(<2 x double>