nemanjai created this revision.
nemanjai added reviewers: cebowleratibm, hubert.reinterpretcast, bmahjour, 
PowerPC.
Herald added subscribers: shchenz, kbarton.
nemanjai requested review of this revision.
Herald added a project: clang.

There are some interfaces in altivec.h that are not compatible between Clang 
and XL (although Clang is compatible with GCC). Currently, we have found 3 but 
there may be others.

Clang/GCC signatures:

  vector double vec_ctf(vector signed long long)
  vector double vec_ctf(vector unsigned long long)
  vector signed long long vec_cts(vector double)
  vector unsigned long long vec_ctu(vector double)

XL signatures:

  vector float vec_ctf(vector signed long long)
  vector float vec_ctf(vector unsigned long long)
  vector signed int vec_cts(vector double)
  vector unsigned int vec_ctu(vector double)

This patch provides the XL behaviour under the `__XL_COMPAT_ALTIVEC__` macro 
for users that rely on XL behaviour.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D101130

Files:
  clang/lib/Headers/altivec.h
  clang/test/CodeGen/builtins-ppc-xlcompat.c

Index: clang/test/CodeGen/builtins-ppc-xlcompat.c
===================================================================
--- /dev/null
+++ clang/test/CodeGen/builtins-ppc-xlcompat.c
@@ -0,0 +1,41 @@
+// REQUIRES: powerpc-registered-target
+// RUN: %clang_cc1 -target-feature +altivec -target-feature +vsx \
+  // RUN:   -triple powerpc64-unknown-unknown -emit-llvm %s -o - \
+// RUN:   -D__XL_COMPAT_ALTIVEC__ | FileCheck %s
+// RUN: %clang_cc1 -target-feature +altivec -target-feature +vsx \
+  // RUN:   -triple powerpc64le-unknown-unknown -emit-llvm %s -o - \
+// RUN:   -D__XL_COMPAT_ALTIVEC__ | FileCheck %s
+#include <altivec.h>
+vector double vd = { 3.4e22, 1.8e-3 };
+vector signed long long vsll = { -12345678999ll, 12345678999 };
+vector unsigned long long vull = { 11547229456923630743llu, 18014402265226391llu };
+vector float res_vf;
+vector signed int res_vsi;
+vector unsigned int res_vui;
+
+void test() {
+// CHECK-LABEL: @test(
+// CHECK-NEXT:  entry:
+// CHECK-LE-LABEL: @test(
+// CHECK-LE-NEXT:  entry:
+
+  res_vf = vec_ctf(vsll, 4);
+// CHECK:         [[TMP0:%.*]] = load <2 x i64>, <2 x i64>* @vsll, align 16
+// CHECK-NEXT:    [[TMP1:%.*]] = call <4 x float> @llvm.ppc.vsx.xvcvsxdsp(<2 x i64> [[TMP0]])
+// CHECK-NEXT:    fmul <4 x float> [[TMP1]], <float 6.250000e-02, float 6.250000e-02, float 6.250000e-02, float 6.250000e-02>
+
+  res_vf = vec_ctf(vull, 4);
+// CHECK:         [[TMP2:%.*]] = load <2 x i64>, <2 x i64>* @vull, align 16
+// CHECK-NEXT:    [[TMP3:%.*]] = call <4 x float> @llvm.ppc.vsx.xvcvuxdsp(<2 x i64> [[TMP2]])
+// CHECK-NEXT:    fmul <4 x float> [[TMP3]], <float 6.250000e-02, float 6.250000e-02, float 6.250000e-02, float 6.250000e-02>
+
+  res_vsi = vec_cts(vd, 4);
+// CHECK:         [[TMP4:%.*]] = load <2 x double>, <2 x double>* @vd, align 16
+// CHECK-NEXT:    fmul <2 x double> [[TMP4]], <double 1.600000e+01, double 1.600000e+01>
+// CHECK:         call <4 x i32> @llvm.ppc.vsx.xvcvdpsxws(<2 x double>
+
+  res_vui = vec_ctu(vd, 4);
+// CHECK:         [[TMP8:%.*]] = load <2 x double>, <2 x double>* @vd, align 16
+// CHECK-NEXT:    fmul <2 x double> [[TMP8]], <double 1.600000e+01, double 1.600000e+01>
+// CHECK:         call <4 x i32> @llvm.ppc.vsx.xvcvdpuxws(<2 x double>
+}
Index: clang/lib/Headers/altivec.h
===================================================================
--- clang/lib/Headers/altivec.h
+++ clang/lib/Headers/altivec.h
@@ -3052,6 +3052,31 @@
 }
 #endif
 
+#ifdef __XL_COMPAT_ALTIVEC__
+/* vec_ctf */
+
+#ifdef __VSX__
+#define vec_ctf(__a, __b)                                                      \
+  _Generic((__a), vector int                                                   \
+           : (vector float)__builtin_altivec_vcfsx((vector int)(__a), (__b)),  \
+             vector unsigned int                                               \
+           : (vector float)__builtin_altivec_vcfux((vector unsigned int)(__a), \
+                                                   (__b)),                     \
+             vector unsigned long long                                         \
+           : (__builtin_vsx_xvcvuxdsp((vector unsigned long long)(__a)) *      \
+              (vector float)(vector unsigned)((0x7f - (__b)) << 23)),          \
+             vector signed long long                                           \
+           : (__builtin_vsx_xvcvsxdsp((vector signed long long)(__a)) *        \
+              (vector float)(vector unsigned)((0x7f - (__b)) << 23)))
+#else
+#define vec_ctf(__a, __b)                                                      \
+  _Generic((__a), vector int                                                   \
+           : (vector float)__builtin_altivec_vcfsx((vector int)(__a), (__b)),  \
+             vector unsigned int                                               \
+           : (vector float)__builtin_altivec_vcfux((vector unsigned int)(__a), \
+                                                   (__b)))
+#endif
+#else // __XL_COMPAT_ALTIVEC__
 /* vec_ctf */
 
 #ifdef __VSX__
@@ -3079,6 +3104,7 @@
            : (vector float)__builtin_altivec_vcfux((vector unsigned int)(__a), \
                                                    (__b)))
 #endif
+#endif // __XL_COMPAT_ALTIVEC__
 
 /* vec_ctd */
 #ifdef __VSX__
@@ -3110,6 +3136,47 @@
 
 #define vec_vcfsx(__a, __b) __builtin_altivec_vcfsx((vector int)(__a), (__b))
 
+#ifdef __XL_COMPAT_ALTIVEC__
+/* vec_cts */
+
+#ifdef __VSX__
+#define vec_cts(__a, __b)                                                      \
+  _Generic((__a), vector float                                                 \
+           : __builtin_altivec_vctsxs((vector float)(__a), (__b)),             \
+             vector double                                                     \
+           : __extension__({                                                   \
+             vector double __ret =                                             \
+                 (vector double)(__a) *                                        \
+                 (vector double)(vector unsigned long long)((0x3ffULL + (__b)) \
+                                                            << 52);            \
+             __builtin_vsx_xvcvdpsxws(__ret);                                  \
+           }))
+#else
+#define vec_cts __builtin_altivec_vctsxs
+#endif
+
+/* vec_vctsxs */
+
+#define vec_vctsxs __builtin_altivec_vctsxs
+
+/* vec_ctu */
+
+#ifdef __VSX__
+#define vec_ctu(__a, __b)                                                      \
+  _Generic((__a), vector float                                                 \
+           : __builtin_altivec_vctuxs((vector float)(__a), (__b)),             \
+             vector double                                                     \
+           : __extension__({                                                   \
+             vector double __ret =                                             \
+                 (vector double)(__a) *                                        \
+                 (vector double)(vector unsigned long long)((0x3ffULL + __b)   \
+                                                            << 52);            \
+             __builtin_vsx_xvcvdpuxws(__ret);                                  \
+           }))
+#else
+#define vec_ctu __builtin_altivec_vctuxs
+#endif
+#else // __XL_COMPAT_ALTIVEC__
 /* vec_cts */
 
 #ifdef __VSX__
@@ -3149,6 +3216,7 @@
 #else
 #define vec_ctu __builtin_altivec_vctuxs
 #endif
+#endif // __XL_COMPAT_ALTIVEC__
 
 /* vec_vctuxs */
 
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to