none/tests/fdleak_cmsg_supp.supp: Add suppressions for older glibc
[valgrind.git] / none / tests / amd64 / f16c.c
blobdb27e4f43b13c0ee59c38c910a9d36b052f4f489
2 #include <stdio.h>
3 #include <stdlib.h>
4 #include <assert.h>
5 #include "tests/malloc.h"
7 typedef unsigned char UChar;
8 typedef unsigned int UInt;
9 typedef unsigned long int UWord;
10 typedef unsigned long long int ULong;
12 #define IS_32_ALIGNED(_ptr) (0 == (0x1F & (UWord)(_ptr)))
14 typedef union { UChar u8[32]; UInt u32[8]; } YMM;
16 typedef struct { YMM a1; YMM a2; YMM a3; YMM a4; ULong u64; } Block;
18 void showYMM ( YMM* vec )
20 int i;
21 assert(IS_32_ALIGNED(vec));
22 for (i = 31; i >= 0; i--) {
23 printf("%02x", (UInt)vec->u8[i]);
24 if (i > 0 && 0 == ((i+0) & 7)) printf(".");
28 void showBlock ( char* msg, Block* block )
30 printf(" %s\n", msg);
31 printf(" "); showYMM(&block->a1); printf("\n");
32 printf(" "); showYMM(&block->a2); printf("\n");
33 printf(" "); showYMM(&block->a3); printf("\n");
34 printf(" "); showYMM(&block->a4); printf("\n");
35 printf(" %016llx\n", block->u64);
38 UChar randUChar ( void )
40 static UInt seed = 80021;
41 seed = 1103515245 * seed + 12345;
42 return (seed >> 17) & 0xFF;
45 void randBlock ( Block* b )
47 int i;
48 UChar* p = (UChar*)b;
49 for (i = 0; i < sizeof(Block); i++)
50 p[i] = randUChar();
54 /* Generate a function test_NAME, that tests the given insn, in both
55 its mem and reg forms. The reg form of the insn may mention, as
56 operands only %ymm6, %ymm7, %ymm8, %ymm9 and %r14. The mem form of
57 the insn may mention as operands only (%rax), %ymm7, %ymm8, %ymm9
58 and %r14. It's OK for the insn to clobber ymm0, as this is needed
59 for testing PCMPxSTRx, and ymm6, as this is needed for testing
60 MOVMASK variants. */
62 #define GEN_test_RandM(_name, _reg_form, _mem_form) \
64 __attribute__ ((noinline)) static void test_##_name ( void ) \
65 { \
66 Block* b = memalign32(sizeof(Block)); \
67 randBlock(b); \
68 printf("%s(reg)\n", #_name); \
69 showBlock("before", b); \
70 __asm__ __volatile__( \
71 "vmovdqa 0(%0),%%ymm7" "\n\t" \
72 "vmovdqa 32(%0),%%ymm8" "\n\t" \
73 "vmovdqa 64(%0),%%ymm6" "\n\t" \
74 "vmovdqa 96(%0),%%ymm9" "\n\t" \
75 "movq 128(%0),%%r14" "\n\t" \
76 _reg_form "\n\t" \
77 "vmovdqa %%ymm7, 0(%0)" "\n\t" \
78 "vmovdqa %%ymm8, 32(%0)" "\n\t" \
79 "vmovdqa %%ymm6, 64(%0)" "\n\t" \
80 "vmovdqa %%ymm9, 96(%0)" "\n\t" \
81 "movq %%r14, 128(%0)" "\n\t" \
82 : /*OUT*/ \
83 : /*IN*/"r"(b) \
84 : /*TRASH*/"xmm0","xmm7","xmm8","xmm6","xmm9","r14","memory","cc" \
85 ); \
86 showBlock("after", b); \
87 randBlock(b); \
88 printf("%s(mem)\n", #_name); \
89 showBlock("before", b); \
90 __asm__ __volatile__( \
91 "leaq 0(%0),%%rax" "\n\t" \
92 "vmovdqa 32(%0),%%ymm8" "\n\t" \
93 "vmovdqa 64(%0),%%ymm7" "\n\t" \
94 "vmovdqa 96(%0),%%ymm9" "\n\t" \
95 "movq 128(%0),%%r14" "\n\t" \
96 _mem_form "\n\t" \
97 "vmovdqa %%ymm8, 32(%0)" "\n\t" \
98 "vmovdqa %%ymm7, 64(%0)" "\n\t" \
99 "vmovdqa %%ymm9, 96(%0)" "\n\t" \
100 "movq %%r14, 128(%0)" "\n\t" \
101 : /*OUT*/ \
102 : /*IN*/"r"(b) \
103 : /*TRASH*/"xmm6", \
104 "xmm0","xmm8","xmm7","xmm9","r14","rax","memory","cc" \
105 ); \
106 showBlock("after", b); \
107 printf("\n"); \
108 free(b); \
111 #define GEN_test_Ronly(_name, _reg_form) \
112 GEN_test_RandM(_name, _reg_form, "")
113 #define GEN_test_Monly(_name, _mem_form) \
114 GEN_test_RandM(_name, "", _mem_form)
116 GEN_test_RandM(VCVTPH2PS_128,
117 "vcvtph2ps %%xmm6, %%xmm8",
118 "vcvtph2ps (%%rax), %%xmm8");
119 GEN_test_RandM(VCVTPH2PS_256,
120 "vcvtph2ps %%xmm6, %%ymm8",
121 "vcvtph2ps (%%rax), %%ymm8");
123 GEN_test_RandM(VCVTPS2PH_128_0,
124 "vcvtps2ph $0, %%xmm8, %%xmm6",
125 "vcvtps2ph $0, %%xmm8, (%%rax)");
126 GEN_test_RandM(VCVTPS2PH_256_0,
127 "vcvtps2ph $0, %%ymm8, %%xmm6",
128 "vcvtps2ph $0, %%ymm8, (%%rax)");
130 GEN_test_RandM(VCVTPS2PH_128_1,
131 "vcvtps2ph $1, %%xmm8, %%xmm6",
132 "vcvtps2ph $1, %%xmm8, (%%rax)");
133 GEN_test_RandM(VCVTPS2PH_256_1,
134 "vcvtps2ph $1, %%ymm8, %%xmm6",
135 "vcvtps2ph $1, %%ymm8, (%%rax)");
137 GEN_test_RandM(VCVTPS2PH_128_2,
138 "vcvtps2ph $2, %%xmm8, %%xmm6",
139 "vcvtps2ph $2, %%xmm8, (%%rax)");
140 GEN_test_RandM(VCVTPS2PH_256_2,
141 "vcvtps2ph $2, %%ymm8, %%xmm6",
142 "vcvtps2ph $2, %%ymm8, (%%rax)");
144 GEN_test_RandM(VCVTPS2PH_128_3,
145 "vcvtps2ph $3, %%xmm8, %%xmm6",
146 "vcvtps2ph $3, %%xmm8, (%%rax)");
147 GEN_test_RandM(VCVTPS2PH_256_3,
148 "vcvtps2ph $3, %%ymm8, %%xmm6",
149 "vcvtps2ph $3, %%ymm8, (%%rax)");
151 GEN_test_RandM(VCVTPS2PH_128_4,
152 "vcvtps2ph $4, %%xmm8, %%xmm6",
153 "vcvtps2ph $4, %%xmm8, (%%rax)");
154 GEN_test_RandM(VCVTPS2PH_256_4,
155 "vcvtps2ph $4, %%ymm8, %%xmm6",
156 "vcvtps2ph $4, %%ymm8, (%%rax)");
158 /* Comment duplicated above, for convenient reference:
159 Allowed operands in test insns:
160 Reg form: %ymm6, %ymm7, %ymm8, %ymm9 and %r14.
161 Mem form: (%rax), %ymm7, %ymm8, %ymm9 and %r14.
162 Imm8 etc fields are also allowed, where they make sense.
163 Both forms may use ymm0 as scratch. Mem form may also use
164 ymm6 as scratch.
167 #define N_DEFAULT_ITERS 3
169 // Do the specified test some number of times
170 #define DO_N(_iters, _testfn) \
171 do { int i; for (i = 0; i < (_iters); i++) { test_##_testfn(); } } while (0)
173 // Do the specified test the default number of times
174 #define DO_D(_testfn) DO_N(N_DEFAULT_ITERS, _testfn)
177 int main ( void )
179 DO_D( VCVTPH2PS_128 );
180 DO_D( VCVTPH2PS_256 );
182 DO_D( VCVTPS2PH_128_0 );
183 DO_D( VCVTPS2PH_256_0 );
185 DO_D( VCVTPS2PH_128_1 );
186 DO_D( VCVTPS2PH_256_1 );
188 DO_D( VCVTPS2PH_128_2 );
189 DO_D( VCVTPS2PH_256_2 );
191 DO_D( VCVTPS2PH_128_3 );
192 DO_D( VCVTPS2PH_256_3 );
194 DO_D( VCVTPS2PH_128_4 );
195 DO_D( VCVTPS2PH_256_4 );
197 return 0;