| 1 |
/* |
| 2 |
Test of vec_xst_trunc (truncate and store rightmost vector element) */ |
| 3 |
|
| 4 |
/* { dg-do run { target power10_hw } } */ |
| 5 |
/* { dg-do compile { target { ! power10_hw } } } */ |
| 6 |
/* { dg-require-effective-target power10_ok } */ |
| 7 |
/* { dg-require-effective-target int128 } */ |
| 8 |
/* Deliberately set optization to zero for this test to confirm |
| 9 |
the stxvr*x instruction is generated. At higher optimization levels |
| 10 |
the instruction we are looking for is sometimes replaced by other |
| 11 |
store instructions. */ |
| 12 |
/* { dg-options "-mdejagnu-cpu=power10 -O0 -save-temps" } */ |
| 13 |
|
| 14 |
/* { dg-final { scan-assembler-times {\mstxvrbx\M} 2 } } */ |
| 15 |
/* { dg-final { scan-assembler-times {\mstbx\M} 0 } } */ |
| 16 |
|
| 17 |
#include <altivec.h> |
| 18 |
#include <stdio.h> |
| 19 |
#include <inttypes.h> |
| 20 |
#include <string.h> |
| 21 |
#include <stdlib.h> |
| 22 |
|
| 23 |
vector signed __int128 store_this_s[4] = { |
| 24 |
{ (__int128) 0x7000000000000000 << 64 | (__int128) 0x123456789abcdef8ULL}, |
| 25 |
{ (__int128) 0x8000000000000000 << 64 | (__int128) 0xfedcba9876543217ULL}, |
| 26 |
{ (__int128) 0x1000000000000000 << 64 | (__int128) 0xccccccccccccccccULL}, |
| 27 |
{ (__int128) 0xf000000000000000 << 64 | (__int128) 0xaaaaaaaaaaaaaaaaULL} |
| 28 |
}; |
| 29 |
|
| 30 |
vector unsigned __int128 store_this_us[4] = { |
| 31 |
{ (unsigned __int128) 0x7000000000000000 << 64 | (unsigned __int128) 0x123456789abcdef8ULL}, |
| 32 |
{ (unsigned __int128) 0x8000000000000000 << 64 | (unsigned __int128) 0xfedcba9876543217ULL}, |
| 33 |
{ (unsigned __int128) 0x1000000000000000 << 64 | (unsigned __int128) 0xeeeeeeeeeeeeeeeeULL}, |
| 34 |
{ (unsigned __int128) 0xf000000000000000 << 64 | (unsigned __int128) 0x5555555555555555ULL} |
| 35 |
}; |
| 36 |
|
| 37 |
#define NUM_VEC_ELEMS 16 |
| 38 |
|
| 39 |
vector signed char signed_expected[4] = { |
| 40 |
{ 0xf8, 0x0, 0x0, 0x0, 0x0 , 0x0, 0x0, 0x0, 0x0 , 0x0, 0x0, 0x0, 0x0 , 0x0, 0x0, 0x0}, |
| 41 |
{ 0x0 , 0x0, 0x0, 0x0, 0x17, 0x0, 0x0, 0x0, 0x0 , 0x0, 0x0, 0x0, 0x0 , 0x0, 0x0, 0x0}, |
| 42 |
{ 0x0 , 0x0, 0x0, 0x0, 0x0 , 0x0, 0x0, 0x0, 0xcc, 0x0, 0x0, 0x0, 0x0 , 0x0, 0x0, 0x0}, |
| 43 |
{ 0x0 , 0x0, 0x0, 0x0, 0x0 , 0x0, 0x0, 0x0, 0x0 , 0x0, 0x0, 0x0, 0xaa, 0x0, 0x0, 0x0} |
| 44 |
}; |
| 45 |
vector unsigned char unsigned_expected[4] = { |
| 46 |
{ 0xf8, 0x0, 0x0, 0x0, 0x0 , 0x0, 0x0, 0x0, 0x0 , 0x0, 0x0, 0x0, 0x0 , 0x0, 0x0, 0x0}, |
| 47 |
{ 0x0 , 0x0, 0x0, 0x0, 0x17, 0x0, 0x0, 0x0, 0x0 , 0x0, 0x0, 0x0, 0x0 , 0x0, 0x0, 0x0}, |
| 48 |
{ 0x0 , 0x0, 0x0, 0x0, 0x0 , 0x0, 0x0, 0x0, 0xee, 0x0, 0x0, 0x0, 0x0 , 0x0, 0x0, 0x0}, |
| 49 |
{ 0x0 , 0x0, 0x0, 0x0, 0x0 , 0x0, 0x0, 0x0, 0x0 , 0x0, 0x0, 0x0, 0x55, 0x0, 0x0, 0x0} |
| 50 |
}; |
| 51 |
|
| 52 |
unsigned long long rawbuffer[32]; |
| 53 |
signed char * vsbuffer = (char *)rawbuffer; |
| 54 |
unsigned char * vubuffer = (unsigned char *)rawbuffer; |
| 55 |
|
| 56 |
void reset_buffer() { |
| 57 |
memset (&rawbuffer,0,sizeof(rawbuffer)); |
| 58 |
} |
| 59 |
|
| 60 |
#define PRINT_VEC(V) \ |
| 61 |
for (int j=0;j<NUM_VEC_ELEMS;j++) { printf ("(0x%lx) ", V[j] ); } |
| 62 |
|
| 63 |
void test_signed_store(vector signed __int128 myvec, int offset, signed char * store_data ) { |
| 64 |
vec_xst_trunc (myvec, offset, store_data ); |
| 65 |
} |
| 66 |
|
| 67 |
void test_unsigned_store(vector unsigned __int128 myvec, int offset, unsigned char * store_data ) { |
| 68 |
vec_xst_trunc (myvec, offset, store_data ); |
| 69 |
} |
| 70 |
|
| 71 |
int main (int argc, char *argv []) |
| 72 |
{ |
| 73 |
int i; |
| 74 |
int memcmpresult; |
| 75 |
int mismatch=0; |
| 76 |
int verbose=0; |
| 77 |
|
| 78 |
#if VERBOSE |
| 79 |
verbose=1; |
| 80 |
printf("%s %s\n", __DATE__, __TIME__); |
| 81 |
#endif |
| 82 |
|
| 83 |
if (verbose) { |
| 84 |
printf("expected results from signed tests:\n"); |
| 85 |
for (i = 0; i < 4 ; i++ ) { |
| 86 |
PRINT_VEC(signed_expected[i]); |
| 87 |
printf("\n"); |
| 88 |
} |
| 89 |
} |
| 90 |
|
| 91 |
for (i = 0; i < 4 ; i++ ) { |
| 92 |
reset_buffer(); |
| 93 |
test_signed_store (store_this_s[i], 4*i, vsbuffer); |
| 94 |
memcmpresult = memcmp(rawbuffer,&signed_expected[i],sizeof(vector char)); |
| 95 |
if (memcmpresult) { |
| 96 |
printf("mismatch signed buffer, i %d (memcmpresult:%d) \n",i,memcmpresult); |
| 97 |
mismatch++; |
| 98 |
if (verbose) { |
| 99 |
printf("results: "); |
| 100 |
PRINT_VEC(vsbuffer); |
| 101 |
printf("\n"); |
| 102 |
} |
| 103 |
} |
| 104 |
} |
| 105 |
|
| 106 |
for (i = 0; i < 4 ; i++ ) { |
| 107 |
reset_buffer(); |
| 108 |
test_unsigned_store (store_this_us[i], 4*i, vubuffer); |
| 109 |
memcmpresult = memcmp(rawbuffer,&unsigned_expected[i],sizeof(vector char)); |
| 110 |
if (memcmpresult) { |
| 111 |
printf("mismatch unsigned buffer, i %d (memcmpresult:%d) \n",i,memcmpresult); |
| 112 |
mismatch++; |
| 113 |
if (verbose) { |
| 114 |
printf("results :"); |
| 115 |
PRINT_VEC(vubuffer); |
| 116 |
printf("\n"); |
| 117 |
} |
| 118 |
} |
| 119 |
} |
| 120 |
|
| 121 |
if (mismatch) { |
| 122 |
printf("%d mismatches. \n",mismatch); |
| 123 |
abort(); |
| 124 |
} |
| 125 |
return 0; |
| 126 |
} |
| 127 |
|