[RS6000] dg-do !compile and scan-assembler
[official-gcc.git] / gcc / testsuite / gcc.target / powerpc / ssse3-phaddsw.c
blobefbdd5544b475684a9cfedba0f45df884c02124d
1 /* { dg-do run } */
2 /* { dg-options "-O3 -mpower8-vector -Wno-psabi" } */
3 /* { dg-require-effective-target p8vector_hw } */
5 #ifndef CHECK_H
6 #define CHECK_H "ssse3-check.h"
7 #endif
9 #ifndef TEST
10 #define TEST ssse3_test
11 #endif
13 #include CHECK_H
15 #include "ssse3-vals.h"
17 #include <tmmintrin.h>
19 #ifndef __AVX__
20 /* Test the 64-bit form */
21 static void
22 ssse3_test_phaddsw (__m64 *i1, __m64 *i2, __m64 *r)
24 *r = _mm_hadds_pi16 (*i1, *i2);
25 _mm_empty ();
27 #endif
29 /* Test the 128-bit form */
30 static void
31 ssse3_test_phaddsw128 (__m128i *i1, __m128i *i2, __m128i *r)
33 /* Assumes incoming pointers are 16-byte aligned */
34 *(__m128i *) r = _mm_hadds_epi16 (*i1, *i2);
37 static short
38 signed_saturate_to_word (int x)
40 if (x > (int) 0x7fff)
41 return 0x7fff;
43 if (x < (int) 0xffff8000)
44 return 0x8000;
46 return (short) x;
49 /* Routine to manually compute the results */
50 static void
51 compute_correct_result (short *i1, short *i2, short *r)
53 int i;
55 for (i = 0; i < 4; i++)
56 r[i + 0] = signed_saturate_to_word(i1[2 * i] + i1[2 * i + 1]);
57 for (i = 0; i < 4; i++)
58 r[i + 4] = signed_saturate_to_word(i2[2 * i] + i2[2 * i + 1]);
61 static void
62 TEST (void)
64 int i;
65 union data r __attribute__ ((aligned(16)));
66 union data ck;
67 int fail = 0;
69 for (i = 0; i < ARRAY_SIZE (vals) - 1; i++)
71 /* Manually compute the result */
72 compute_correct_result (&vals[i + 0].h[0], &vals[i + 1].h[0], &ck.h[0]);
74 #ifndef __AVX__
75 /* Run the 64-bit tests */
76 ssse3_test_phaddsw (&vals[i + 0].ll[0], &vals[i + 0].ll[1], &r.ll[0]);
77 ssse3_test_phaddsw (&vals[i + 1].ll[0], &vals[i + 1].ll[1], &r.ll[1]);
78 fail += chk_128 (ck.m[0], r.m[0]);
79 #endif
81 /* Run the 128-bit tests */
82 ssse3_test_phaddsw128 (&vals[i + 0].m[0], &vals[i + 1].m[0], &r.m[0]);
83 fail += chk_128 (ck.m[0], r.m[0]);
86 if (fail != 0)
87 abort ();