Debian Codegraph @

gcc/testsuite/gcc.target/i386/ssse3-pmaddubsw.c

raw
1 /* { dg-do run } */
2 /* { dg-require-effective-target ssse3 } */
3 /* { dg-options "-O2 -fno-strict-aliasing -mssse3" } */
4
5 #ifndef CHECK_H
6 #define CHECK_H "ssse3-check.h"
7 #endif
8
9 #ifndef TEST
10 #define TEST ssse3_test
11 #endif
12
13 #include CHECK_H
14
15 #include "ssse3-vals.h"
16
17 #include <tmmintrin.h>
18
19 /* Test the 64-bit form */
20 static void
21 ssse3_test_pmaddubsw (int *i1, int *i2, int *r)
22 {
23 __m64 t1 = *(__m64 *) i1;
24 __m64 t2 = *(__m64 *) i2;
25 *(__m64 *) r = _mm_maddubs_pi16 (t1, t2);
26 _mm_empty ();
27 }
28
29 /* Test the 128-bit form */
30 static void
31 ssse3_test_pmaddubsw128 (int *i1, int *i2, int *r)
32 {
33 /* Assumes incoming pointers are 16-byte aligned */
34 __m128i t1 = *(__m128i *) i1;
35 __m128i t2 = *(__m128i *) i2;
36 *(__m128i *) r = _mm_maddubs_epi16 (t1, t2);
37 }
38
39 static short
40 signed_saturate_to_word(int x)
41 {
42 if (x > (int) 0x7fff)
43 return 0x7fff;
44
45 if (x < (int) 0xffff8000)
46 return 0x8000;
47
48 return (short) x;
49 }
50
51 /* Routine to manually compute the results */
52 static void
53 compute_correct_result (int *i1, int *i2, int *r)
54 {
55 unsigned char *ub1 = (unsigned char *) i1;
56 char *sb2 = (char *) i2;
57 short *sout = (short *) r;
58 int t0;
59 int i;
60
61 for (i = 0; i < 8; i++)
62 {
63 t0 = ((int) ub1[2 * i] * (int) sb2[2 * i] +
64 (int) ub1[2 * i + 1] * (int) sb2[2 * i + 1]);
65 sout[i] = signed_saturate_to_word (t0);
66 }
67 }
68
69 static void
70 TEST (void)
71 {
72 int i;
73 int r [4] __attribute__ ((aligned(16)));
74 int ck [4];
75 int fail = 0;
76
77 for (i = 0; i < 256; i += 8)
78 {
79 /* Manually compute the result */
80 compute_correct_result (&vals[i + 0], &vals[i + 4], ck);
81
82 /* Run the 64-bit tests */
83 ssse3_test_pmaddubsw (&vals[i + 0], &vals[i + 4], &r[0]);
84 ssse3_test_pmaddubsw (&vals[i + 2], &vals[i + 6], &r[2]);
85 fail += chk_128 (ck, r);
86
87 /* Run the 128-bit tests */
88 ssse3_test_pmaddubsw128 (&vals[i + 0], &vals[i + 4], r);
89 fail += chk_128 (ck, r);
90 }
91
92 if (fail != 0)
93 abort ();
94 }