1 /* { dg-do run } */
2 /* { dg-require-effective-target sse4 } */
3 /* { dg-options "-O2 -msse4.2" } */
4 
5 #ifndef CHECK_H
6 #define CHECK_H "sse4_2-check.h"
7 #endif
8 
9 #ifndef TEST
10 #define TEST sse4_2_test
11 #endif
12 
13 #include CHECK_H
14 
15 #include "sse4_2-pcmpstr.h"
16 
17 #define NUM 1024
18 
19 #define IMM_VAL0 \
20   (_SIDD_SBYTE_OPS | _SIDD_CMP_RANGES | _SIDD_MASKED_POSITIVE_POLARITY)
21 #define IMM_VAL1 \
22   (_SIDD_UBYTE_OPS | _SIDD_CMP_EQUAL_EACH | _SIDD_NEGATIVE_POLARITY \
23    | _SIDD_BIT_MASK)
24 #define IMM_VAL2 \
25   (_SIDD_UWORD_OPS | _SIDD_CMP_EQUAL_ANY | _SIDD_MASKED_NEGATIVE_POLARITY)
26 #define IMM_VAL3 \
27   (_SIDD_SWORD_OPS | _SIDD_CMP_EQUAL_ORDERED \
28    | _SIDD_MASKED_NEGATIVE_POLARITY | _SIDD_UNIT_MASK)
29 
30 
31 static void
TEST(void)32 TEST (void)
33 {
34   union
35     {
36       __m128i x[NUM];
37       char c[NUM *16];
38     } src1, src2;
39   __m128i res, correct;
40   int l1, l2;
41   int i;
42 
43   for (i = 0; i < NUM *16; i++)
44     {
45       src1.c[i] = rand ();
46       src2.c[i] = rand ();
47     }
48 
49   for (i = 0; i < NUM; i++)
50     {
51       l1 = rand () % 18;
52       l2 = rand () % 18;
53 
54       switch((rand() % 4))
55 	{
56 	case 0:
57 	  res  = _mm_cmpestrm (src1.x[i], l1, src2.x[i], l2, IMM_VAL0);
58 	  correct = cmp_em (&src1.x[i], l1, &src2.x[i], l2, IMM_VAL0,
59 			    NULL);
60 	  break;
61 
62 	case 1:
63 	  res  = _mm_cmpestrm (src1.x[i], l1, src2.x[i], l2, IMM_VAL1);
64 	  correct = cmp_em (&src1.x[i], l1, &src2.x[i], l2, IMM_VAL1,
65 			    NULL);
66 	  break;
67 
68 	case 2:
69 	  res  = _mm_cmpestrm (src1.x[i], l1, src2.x[i], l2, IMM_VAL2);
70 	  correct = cmp_em (&src1.x[i], l1, &src2.x[i], l2, IMM_VAL2,
71 			    NULL);
72 	  break;
73 
74 	default:
75 	  res  = _mm_cmpestrm (src1.x[i], l1, src2.x[i], l2, IMM_VAL3);
76 	  correct = cmp_em (&src1.x[i], l1, &src2.x[i], l2, IMM_VAL3,
77 			    NULL);
78 	  break;
79         }
80 
81       if (memcmp (&correct, &res, sizeof (res)))
82 	abort ();
83     }
84 }
85