Debian Codegraph @

gcc/testsuite/gcc.target/i386/avx-ne-convert-vcvtneobf162ps-2.c

raw
1 /* { dg-do run } */
2 /* { dg-options "-mavxneconvert -O2" } */
3 /* { dg-require-effective-target avxneconvert } */
4 #define AVXNECONVERT
5 #include <stdint.h>
6
7 #ifndef CHECK
8 #define CHECK "avx-check.h"
9 #endif
10
11 #ifndef TEST
12 #define TEST avx_test
13 #endif
14
15 #include CHECK
16
17 typedef union
18 {
19 uint32_t int32;
20 float flt;
21 } float_int_t;
22
23 typedef union
24 {
25 __m128bh x;
26 uint32_t a[4];
27 } union128bf16_i;
28
29 typedef union
30 {
31 __m256bh x;
32 uint32_t a[8];
33 } union256bf16_i;
34
35 static uint16_t convert_fp32_to_bf16 (float fp)
36 {
37 float_int_t fi;
38 fi.flt = fp;
39 return ((fi.int32 >> 16) & 0xffff);
40 }
41
42 void TEST (void)
43 {
44 union128 dst_128;
45 union256 dst_256;
46 float res_ref_128[4], res_ref_256[8], fp32;
47 uint16_t bf16;
48 union128bf16_i src_128bh;
49 union256bf16_i src_256bh;
50
51 for (int i = 0; i < 4; i++)
52 {
53 fp32 = (float) 3 * i + 5 + i * 0.5;
54 bf16 = convert_fp32_to_bf16 (fp32);
55 // store bf16 at the upper part of the dword
56 src_128bh.a[i] = (bf16 << 16) & 0xffff0000;
57 res_ref_128[i] = fp32;
58 dst_128.a[i] = 117;
59 }
60 for (int i = 0; i < 8; i++)
61 {
62 fp32 = (float) 3 * i + 5 + i * 0.5;
63 bf16 = convert_fp32_to_bf16 (fp32);
64 // store bf16 at the upper part of the dword
65 src_256bh.a[i] = (bf16 << 16) & 0xffff0000;
66 res_ref_256[i] = fp32;
67 dst_256.a[i] = 117;
68 }
69 dst_128.x = _mm_cvtneobf16_ps (&src_128bh.x);
70 dst_256.x = _mm256_cvtneobf16_ps (&src_256bh.x);
71 if (check_union128 (dst_128, res_ref_128))
72 abort();
73 if (check_union256 (dst_256, res_ref_256))
74 abort();
75 }