testsuite, rs6000: Fix builtins-6-p9-runnable.c for BE [PR114744]

Message ID e4e7785d-b788-d9aa-8d50-86d0994d0f4a@linux.ibm.com
State New
Headers
Series testsuite, rs6000: Fix builtins-6-p9-runnable.c for BE [PR114744] |

Checks

Context Check Description
linaro-tcwg-bot/tcwg_gcc_build--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gcc_check--master-aarch64 success Testing passed
linaro-tcwg-bot/tcwg_gcc_build--master-arm success Testing passed
linaro-tcwg-bot/tcwg_gcc_check--master-arm success Testing passed

Commit Message

Kewen.Lin April 17, 2024, 9:30 a.m. UTC
  Hi,

Test case builtins-6-p9-runnable.c doesn't work well on BE
due to two problems:
  - When applying vec_xl_len onto data_128 and data_u128
    with length 8, it expects to load 1280000[01] from
    the memory, but unfortunately assigning 1280000[01] to
    a {vector} {u,}int128 type variable, the value isn't
    guaranteed to be at the beginning of storage (in the
    low part of memory), which means the loaded value can
    be unexpected (as shown on BE).  So this patch is to
    introduce getU128 which can ensure the given value
    shows up as expected and also update some dumping code
    for debugging.
  - When applying vec_xl_len_r with length 16, on BE it's
    just like the normal vector load, so the expected data
    should not be reversed from the original.

Tested well on both powerpc64{,le}-linux-gnu, I'm going to
push this soon.

BR,
Kewen
-----
	PR testsuite/114744

gcc/testsuite/ChangeLog:

	* gcc.target/powerpc/builtins-6-p9-runnable.c: Adjust for BE by fixing
	data_{u,}128, their uses and vec_uc_expected1, also adjust some formats.
---
 .../powerpc/builtins-6-p9-runnable.c          | 119 ++++++++++--------
 1 file changed, 64 insertions(+), 55 deletions(-)

--
2.43.0
  

Patch

diff --git a/gcc/testsuite/gcc.target/powerpc/builtins-6-p9-runnable.c b/gcc/testsuite/gcc.target/powerpc/builtins-6-p9-runnable.c
index 20fdd3bb4ec..36101c2b861 100644
--- a/gcc/testsuite/gcc.target/powerpc/builtins-6-p9-runnable.c
+++ b/gcc/testsuite/gcc.target/powerpc/builtins-6-p9-runnable.c
@@ -337,6 +337,30 @@  void print_f (vector float vec_expected,
 }
 #endif

+typedef union
+{
+  vector __int128_t i1;
+  __int128_t i2;
+  vector __uint128_t u1;
+  __uint128_t u2;
+  struct
+  {
+    long long d1;
+    long long d2;
+  };
+} U128;
+
+/* For a given long long VALUE, ensure it's stored from the beginning
+   of {u,}int128 memory storage (the low address), it avoids to load
+   unexpected data without the whole vector length.  */
+
+static inline void
+getU128 (U128 *pu, unsigned long long value)
+{
+  pu->d1 = value;
+  pu->d2 = 0;
+}
+
 int main() {
   int i, j;
   size_t len;
@@ -835,21 +859,24 @@  int main() {
 #endif
     }

+  U128 u_temp;
   /* vec_xl_len() tests */
   for (i = 0; i < 100; i++)
     {
-      data_c[i] = i;
-      data_uc[i] = i+1;
-      data_ssi[i] = i+10;
-      data_usi[i] = i+11;
-      data_si[i] = i+100;
-      data_ui[i] = i+101;
-      data_sll[i] = i+1000;
-      data_ull[i] = i+1001;
-      data_f[i] = i+100000.0;
-      data_d[i] = i+1000000.0;
-      data_128[i] = i + 12800000;
-      data_u128[i] = i + 12800001;
+       data_c[i] = i;
+       data_uc[i] = i + 1;
+       data_ssi[i] = i + 10;
+       data_usi[i] = i + 11;
+       data_si[i] = i + 100;
+       data_ui[i] = i + 101;
+       data_sll[i] = i + 1000;
+       data_ull[i] = i + 1001;
+       data_f[i] = i + 100000.0;
+       data_d[i] = i + 1000000.0;
+       getU128 (&u_temp, i + 12800000);
+       data_128[i] = u_temp.i2;
+       getU128 (&u_temp, i + 12800001);
+       data_u128[i] = u_temp.u2;
     }

   len = 16;
@@ -1160,34 +1187,38 @@  int main() {
 #endif
     }

-  vec_s128_expected1 = (vector __int128_t){12800000};
+  getU128 (&u_temp, 12800000);
+  vec_s128_expected1 = u_temp.i1;
   vec_s128_result1 = vec_xl_len (data_128, len);

   if (vec_s128_expected1[0] != vec_s128_result1[0])
     {
 #ifdef DEBUG
-       printf("Error: vec_xl_len(), len = %d, vec_s128_result1[0] = %lld %llu; ",
-	      len, vec_s128_result1[0] >> 64,
-	      vec_s128_result1[0] & (__int128_t)0xFFFFFFFFFFFFFFFF);
-       printf("vec_s128_expected1[0] = %lld %llu\n",
-	      vec_s128_expected1[0] >> 64,
-	      vec_s128_expected1[0] & (__int128_t)0xFFFFFFFFFFFFFFFF);
+      U128 u1, u2;
+      u1.i1 = vec_s128_result1;
+      u2.i1 = vec_s128_expected1;
+      printf ("Error: vec_xl_len(), len = %d,"
+	      "vec_s128_result1[0] = %llx %llx; ",
+	      len, u1.d1, u1.d2);
+      printf ("vec_s128_expected1[0] = %llx %llx\n", u2.d1, u2.d2);
 #else
        abort ();
 #endif
     }

   vec_u128_result1 = vec_xl_len (data_u128, len);
-  vec_u128_expected1 = (vector __uint128_t){12800001};
+  getU128 (&u_temp, 12800001);
+  vec_u128_expected1 = u_temp.u1;
   if (vec_u128_expected1[0] != vec_u128_result1[0])
 #ifdef DEBUG
     {
-       printf("Error: vec_xl_len(), len = %d, vec_u128_result1[0] = %lld; ",
-	      len, vec_u128_result1[0] >> 64,
-	      vec_u128_result1[0] & (__int128_t)0xFFFFFFFFFFFFFFFF);
-       printf("vec_u128_expected1[0] = %lld\n",
-	      vec_u128_expected1[0] >> 64,
-	      vec_u128_expected1[0] & (__int128_t)0xFFFFFFFFFFFFFFFF);
+      U128 u1, u2;
+      u1.u1 = vec_u128_result1;
+      u2.u1 = vec_u128_expected1;
+      printf ("Error: vec_xl_len(), len = %d,"
+	      "vec_u128_result1[0] = %llx %llx; ",
+	      len, u1.d1, u1.d2);
+      printf ("vec_u128_expected1[0] = %llx %llx\n", u2.d1, u2.d2);
     }
 #else
     abort ();
@@ -1421,8 +1452,13 @@  int main() {
        and post data initialization is done.  */

   len = 16;
-  vec_uc_expected1 = (vector unsigned char){ 16,15, 14, 13, 12, 11, 10, 9,
-					     8, 7, 6, 5, 4, 3, 2, 1 };
+#if __LITTLE_ENDIAN__
+  vec_uc_expected1 = (vector unsigned char){16, 15, 14, 13, 12, 11, 10, 9,
+					    8,	7,  6,	5,  4,	3,  2,	1};
+#else
+  vec_uc_expected1 = (vector unsigned char){1, 2,  3,  4,  5,  6,  7,  8,
+					    9, 10, 11, 12, 13, 14, 15, 16};
+#endif
   input_uc = (vector unsigned char){ 1, 2, 3, 4, 5, 6, 7, 8, 9,
 				   10, 11, 12, 13, 14, 15, 16 };
   vec_uc_result1 = vec_xl_len_r (&input_uc[0], len);
@@ -1441,30 +1477,3 @@  int main() {
     }

 }
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-