[Bug c/93819] PPC64 builtin vec_rlnm() argument order is wrong.

2020-02-18 Thread cel at us dot ibm.com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93819

--- Comment #2 from Carl Love  ---
With the attached patch, the test program now runs as follows:

ABI says:
VEC_RLNM (ARG1, ARG2, ARG3)
ARG2 contains the shift count for each element in the low-order
byte, with other bytes zero.
ARG3 contains the mask begin and mask end for each element, with
the mask end in the low-order byte, the mask begin in the next
higher byte, and other bytes zero.

Vector int test case: mask begin = 0, mask end = 4, shift = 16

vec_arg1_int[0] = 0x12345678
vec_arg2_int[0] = 16 (0x10)
vec_arg3_int[0] = 4 (0x4)
vec_result_int[0] = 0x5000
Int result matches expected result 0x5000
vec_arg1_int[1] = 0x23456789
vec_arg2_int[1] = 16 (0x10)
vec_arg3_int[1] = 4 (0x4)
vec_result_int[1] = 0x6000
Int result matches expected result 0x6000
vec_arg1_int[2] = 0x3456789a
vec_arg2_int[2] = 16 (0x10)
vec_arg3_int[2] = 4 (0x4)
vec_result_int[2] = 0x7800
Int result matches expected result 0x7800
vec_arg1_int[3] = 0x456789ab
vec_arg2_int[3] = 16 (0x10)
vec_arg3_int[3] = 4 (0x4)
vec_result_int[3] = 0x8800
Int result matches expected result 0x8800
Vector long long int test case: mask begin = 0, mask end = 4, shift = 20

vec_arg1_di[0] = 0x123456789abcde00
vec_arg2_di[0] = 20 (0x14)
vec_arg3_di[0] = 4 (0x4)
vec_result_di[0] = 0x6000
Long long int result matches expected result 0x6000
vec_arg1_di[1] = 0x23456789abcdef11
vec_arg2_di[1] = 20 (0x14)
vec_arg3_di[1] = 4 (0x4)
vec_result_di[1] = 0x7800
Long long int result matches expected result 0x7800

[Bug c/93819] PPC64 builtin vec_rlnm() argument order is wrong.

2020-02-18 Thread cel at us dot ibm.com
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=93819

--- Comment #1 from Carl Love  ---
Created attachment 47873
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=47873=edit
Patch to fix vec_vrlnm() functionality

The issue with the vec_rlnm() builtin is the order of the arguments in the
builtin macro definition in gcc/config/rs6000/altivec.h.  I have attached a
patch to fix the issue.  Here is the fix as well

--- a/gcc/config/rs6000/altivec.h
+++ b/gcc/config/rs6000/altivec.h
@@ -182,7 +182,7 @@
 #define vec_recipdiv __builtin_vec_recipdiv
 #define vec_rlmi __builtin_vec_rlmi
 #define vec_vrlnm __builtin_vec_rlnm
-#define vec_rlnm(a,b,c) (__builtin_vec_rlnm((a),((b)<<8)|(c)))
+#define vec_rlnm(a,b,c) (__builtin_vec_rlnm((a),((c)<<8)|(b)))
 #define vec_rsqrt __builtin_vec_rsqrt
 #define vec_rsqrte __builtin_vec_rsqrte
 #define vec_signed __builtin_vec_vsigned

Basically the second and third arguments to the macro need to be reversed.