1 /* { dg-do run } */
2 /* { dg-options "-O3 -mpower8-vector -Wno-psabi" } */
3 /* { dg-require-effective-target p8vector_hw } */
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 #ifndef __AVX__
20 /* Test the 64-bit form */
21 static void
ssse3_test_pmaddubsw(__m64 * i1,__m64 * i2,__m64 * r)22 ssse3_test_pmaddubsw (__m64 *i1, __m64 *i2, __m64 *r)
23 {
24 *(__m64 *) r = _mm_maddubs_pi16 (*i1, *i2);
25 _mm_empty ();
26 }
27 #endif
28
29 /* Test the 128-bit form */
30 static void
ssse3_test_pmaddubsw128(__m128i * i1,__m128i * i2,__m128i * r)31 ssse3_test_pmaddubsw128 (__m128i *i1, __m128i *i2, __m128i *r)
32 {
33 /* Assumes incoming pointers are 16-byte aligned */
34 *r = _mm_maddubs_epi16 (*i1, *i2);
35 }
36
37 static short
signed_saturate_to_word(int x)38 signed_saturate_to_word(int x)
39 {
40 if (x > (int) 0x7fff)
41 return 0x7fff;
42
43 if (x < (int) 0xffff8000)
44 return 0x8000;
45
46 return (short) x;
47 }
48
49 /* Routine to manually compute the results */
50 static void
compute_correct_result(unsigned char * i1,signed char * i2,short * r)51 compute_correct_result (unsigned char *i1, signed char *i2, short *r)
52 {
53 int t0;
54 int i;
55
56 for (i = 0; i < 8; i++)
57 {
58 t0 = ((int) i1[2 * i] * (int) i2[2 * i] +
59 (int) i1[2 * i + 1] * (int) i2[2 * i + 1]);
60 r[i] = signed_saturate_to_word (t0);
61 }
62 }
63
64 static void
TEST(void)65 TEST (void)
66 {
67 int i;
68 union data r __attribute__ ((aligned(16)));
69 union data ck;
70 int fail = 0;
71
72 for (i = 0; i < ARRAY_SIZE (vals) - 1; i++)
73 {
74 /* Manually compute the result */
75 compute_correct_result (&vals[i + 0].ub[0], &vals[i + 1].b[0], &ck.h[0]);
76
77 #ifndef __AVX__
78 /* Run the 64-bit tests */
79 ssse3_test_pmaddubsw (&vals[i + 0].ll[0], &vals[i + 1].ll[0], &r.ll[0]);
80 ssse3_test_pmaddubsw (&vals[i + 0].ll[1], &vals[i + 1].ll[1], &r.ll[1]);
81 fail += chk_128 (ck.m[0], r.m[0]);
82 #endif
83
84 /* Run the 128-bit tests */
85 ssse3_test_pmaddubsw128 (&vals[i + 0].m[0], &vals[i + 1].m[0], &r.m[0]);
86 fail += chk_128 (ck.m[0], r.m[0]);
87 }
88
89 if (fail != 0)
90 abort ();
91 }
92