[PowerPC] Add more missing overloads to altivec.h
authorNemanja Ivanovic <nemanja.i.ibm@gmail.com>
Tue, 23 Mar 2021 01:22:21 +0000 (20:22 -0500)
committerNemanja Ivanovic <nemanja.i.ibm@gmail.com>
Tue, 23 Mar 2021 01:23:07 +0000 (20:23 -0500)
Add vec_ctd which is similar to vec_ctf except the return type is
vector double rather than vector float.

clang/lib/Headers/altivec.h
clang/test/CodeGen/builtins-ppc-vsx.c

index ee39b52..0d8961e 100644 (file)
@@ -3033,10 +3033,32 @@ static __inline__ vector double __ATTRS_o_ai vec_cpsgn(vector double __a,
                                                    (__b)))
 #endif
 
+/* vec_ctd */
+#ifdef __VSX__
+#define vec_ctd(__a, __b)                                                      \
+  _Generic((__a), vector signed int                                            \
+           : (vec_doublee((vector signed int)(__a)) *                          \
+              (vector double)(vector unsigned long long)((0x3ffULL - (__b))    \
+                                                         << 52)),              \
+             vector unsigned int                                               \
+           : (vec_doublee((vector unsigned int)(__a)) *                        \
+              (vector double)(vector unsigned long long)((0x3ffULL - (__b))    \
+                                                         << 52)),              \
+             vector unsigned long long                                         \
+           : (__builtin_convertvector((vector unsigned long long)(__a),        \
+                                      vector double) *                         \
+              (vector double)(vector unsigned long long)((0x3ffULL - (__b))    \
+                                                         << 52)),              \
+             vector signed long long                                           \
+           : (__builtin_convertvector((vector signed long long)(__a),          \
+                                      vector double) *                         \
+              (vector double)(vector unsigned long long)((0x3ffULL - (__b))    \
+                                                         << 52)))
+#endif // __VSX__
+
 /* vec_vcfsx */
 
 #define vec_vcfux __builtin_altivec_vcfux
-
 /* vec_vcfux */
 
 #define vec_vcfsx(__a, __b) __builtin_altivec_vcfsx((vector int)(__a), (__b))
index e13f1ee..d133b5e 100644 (file)
@@ -1294,6 +1294,32 @@ void test1() {
 // CHECK-LE: uitofp <2 x i64> %{{.*}} to <2 x double>
 // CHECK-LE: fmul <2 x double>
 
+  res_vd = vec_ctd(vsll, 2);
+// CHECK: sitofp <2 x i64> %{{.*}} to <2 x double>
+// CHECK: fmul <2 x double> {{.*}} <double 2.500000e-01, double 2.500000e-01>
+// CHECK-LE: sitofp <2 x i64> %{{.*}} to <2 x double>
+// CHECK-LE: fmul <2 x double> {{.*}} <double 2.500000e-01, double 2.500000e-01>
+
+  res_vd = vec_ctd(vull, 2);
+// CHECK: uitofp <2 x i64> %{{.*}} to <2 x double>
+// CHECK: fmul <2 x double> {{.*}} <double 2.500000e-01, double 2.500000e-01>
+// CHECK-LE: uitofp <2 x i64> %{{.*}} to <2 x double>
+// CHECK-LE: fmul <2 x double> {{.*}} <double 2.500000e-01, double 2.500000e-01>
+
+  res_vd = vec_ctd(vsi, 2);
+// CHECK: call <2 x double> @llvm.ppc.vsx.xvcvsxwdp(<4 x i32>
+// CHECK: fmul <2 x double> {{.*}} <double 2.500000e-01, double 2.500000e-01>
+// CHECK-LE: vperm
+// CHECK-LE: call <2 x double> @llvm.ppc.vsx.xvcvsxwdp(<4 x i32>
+// CHECK-LE: fmul <2 x double> {{.*}} <double 2.500000e-01, double 2.500000e-01>
+
+  res_vd = vec_ctd(vui, 2);
+// CHECK: call <2 x double> @llvm.ppc.vsx.xvcvuxwdp(<4 x i32>
+// CHECK: fmul <2 x double> {{.*}} <double 2.500000e-01, double 2.500000e-01>
+// CHECK-LE: vperm
+// CHECK-LE: call <2 x double> @llvm.ppc.vsx.xvcvuxwdp(<4 x i32>
+// CHECK-LE: fmul <2 x double> {{.*}} <double 2.500000e-01, double 2.500000e-01>
+
   res_vsll = vec_signed(vd);
 // CHECK: fptosi <2 x double>
 // CHECK-LE: fptosi <2 x double>