Debian Codegraph @

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

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