PR inline-asm/84742
[official-gcc.git] / gcc / testsuite / gcc.target / i386 / ssse3-phsubsw.c
blob371c8d112d1d60993b3d6ee30fbc1bc4b989c52d
1 /* { dg-do run } */
2 /* { dg-require-effective-target ssse3 } */
3 /* { dg-options "-O2 -fno-strict-aliasing -mssse3" } */
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_phsubsw (int *i1, int *i2, int *r)
24 __m64 t1 = *(__m64 *) i1;
25 __m64 t2 = *(__m64 *) i2;
27 *(__m64 *) r = _mm_hsubs_pi16 (t1, t2);
29 _mm_empty ();
31 #endif
33 /* Test the 128-bit form */
34 static void
35 ssse3_test_phsubsw128 (int *i1, int *i2, int *r)
37 /* Assumes incoming pointers are 16-byte aligned */
38 __m128i t1 = *(__m128i *) i1;
39 __m128i t2 = *(__m128i *) i2;
40 *(__m128i *) r = _mm_hsubs_epi16 (t1, t2);
43 static short
44 signed_saturate_to_word (int x)
46 if (x > (int )0x7fff)
47 return 0x7fff;
49 if (x < (int) 0xffff8000)
50 return 0x8000;
52 return (short)x;
55 /* Routine to manually compute the results */
56 static void
57 compute_correct_result (int *i1, int *i2, int *r)
59 short *s1 = (short *) i1;
60 short *s2 = (short *) i2;
61 short *sout = (short *) r;
62 int i;
64 for (i = 0; i < 4; i++)
65 sout[i] = signed_saturate_to_word (s1[2 * i] - s1[2 * i + 1]);
67 for (i = 0; i < 4; i++)
68 sout[i + 4] = signed_saturate_to_word (s2[2 * i] - s2[2 * i + 1]);
71 static void
72 TEST (void)
74 int i;
75 int r [4] __attribute__ ((aligned(16)));
76 int ck [4];
77 int fail = 0;
79 for (i = 0; i < 256; i += 8)
81 /* Manually compute the result */
82 compute_correct_result (&vals[i + 0], &vals[i + 4], ck);
84 #ifndef __AVX__
85 /* Run the 64-bit tests */
86 ssse3_test_phsubsw (&vals[i + 0], &vals[i + 2], &r[0]);
87 ssse3_test_phsubsw (&vals[i + 4], &vals[i + 6], &r[2]);
88 fail += chk_128 (ck, r);
89 #endif
91 /* Run the 128-bit tests */
92 ssse3_test_phsubsw128 (&vals[i + 0], &vals[i + 4], r);
93 fail += chk_128 (ck, r);
96 if (fail != 0)
97 abort ();