1 /* { dg-do compile } */
2 /* { dg-options "-O2 -mbmi2 -fdump-tree-optimized" } */
3 /* { dg-final { scan-tree-dump-not "link_error" "optimized" } } */
4
5 #include <x86intrin.h>
6
7 extern void link_error (void);
8 unsigned int a;
9 unsigned long long b;
10
f1(void)11 static inline unsigned int f1 (void) { return _bzhi_u32 (a, 0); }
f2(unsigned int x)12 static inline unsigned int f2 (unsigned int x) { return _bzhi_u32 (x, 0); }
f3(void)13 static inline unsigned int f3 (void) { return _bzhi_u32 (a, 5); }
f4(unsigned int x)14 static inline unsigned int f4 (unsigned int x) { return _bzhi_u32 (x, 5); }
f5(void)15 static inline unsigned int f5 (void) { return _bzhi_u32 (a, 31); }
f6(unsigned int x)16 static inline unsigned int f6 (unsigned int x) { return _bzhi_u32 (x, 31); }
f7(void)17 static inline unsigned int f7 (void) { return _bzhi_u32 (a, 32); }
f8(unsigned int x)18 static inline unsigned int f8 (unsigned int x) { return _bzhi_u32 (x, 32); }
f9(void)19 static inline unsigned int f9 (void) { return _bzhi_u32 (a, 37); }
f10(unsigned int x)20 static inline unsigned int f10 (unsigned int x) { return _bzhi_u32 (x, 37); }
f11(void)21 static inline unsigned int f11 (void) { return _bzhi_u32 (a, 257); }
f12(unsigned int x)22 static inline unsigned int f12 (unsigned int x) { return _bzhi_u32 (x, 257); }
f13(void)23 static inline unsigned int f13 (void) { return _bzhi_u32 (a, 289); }
f14(unsigned int x)24 static inline unsigned int f14 (unsigned int x) { return _bzhi_u32 (x, 289); }
25 #ifdef __x86_64__
f21(void)26 static inline unsigned long long f21 (void) { return _bzhi_u64 (b, 0); }
f22(unsigned long long x)27 static inline unsigned long long f22 (unsigned long long x) { return _bzhi_u64 (x, 0); }
f23(void)28 static inline unsigned long long f23 (void) { return _bzhi_u64 (b, 5); }
f24(unsigned long long x)29 static inline unsigned long long f24 (unsigned long long x) { return _bzhi_u64 (x, 5); }
f25(void)30 static inline unsigned long long f25 (void) { return _bzhi_u64 (b, 63); }
f26(unsigned long long x)31 static inline unsigned long long f26 (unsigned long long x) { return _bzhi_u64 (x, 63); }
f27(void)32 static inline unsigned long long f27 (void) { return _bzhi_u64 (b, 64); }
f28(unsigned long long x)33 static inline unsigned long long f28 (unsigned long long x) { return _bzhi_u64 (x, 64); }
f29(void)34 static inline unsigned long long f29 (void) { return _bzhi_u64 (b, 69); }
f30(unsigned long long x)35 static inline unsigned long long f30 (unsigned long long x) { return _bzhi_u64 (x, 69); }
f31(void)36 static inline unsigned long long f31 (void) { return _bzhi_u64 (b, 257); }
f32(unsigned long long x)37 static inline unsigned long long f32 (unsigned long long x) { return _bzhi_u64 (x, 257); }
f33(void)38 static inline unsigned long long f33 (void) { return _bzhi_u64 (b, 321); }
f34(unsigned long long x)39 static inline unsigned long long f34 (unsigned long long x) { return _bzhi_u64 (x, 321); }
40 #endif
41
42 unsigned int c;
43 unsigned long long d;
44
45 int
main()46 main ()
47 {
48 asm volatile ("" : : "g" (&c), "g" (&d) : "memory");
49 a = -1U;
50 b = -1ULL;
51 if (f1 () != 0 || f2 (-1U) != 0
52 || f3 () != 0x1f || f4 (-1U) != 0x1f
53 || f5 () != 0x7fffffffU || f6 (-1U) != 0x7fffffffU
54 || f7 () != -1U || f8 (-1U) != -1U
55 || f9 () != -1U || f10 (-1U) != -1U
56 || f11 () != 1 || f12 (-1U) != 1
57 || f13 () != -1U || f14 (-1U) != -1U)
58 link_error ();
59 if (_bzhi_u32 (c, 32) != c
60 || _bzhi_u32 (c, 64) != c
61 || _bzhi_u32 (c, 255) != c
62 || _bzhi_u32 (c, 544) != c
63 || _bzhi_u32 (c, 0) != 0
64 || _bzhi_u32 (c, 256) != 0
65 || _bzhi_u32 (c, 1024) != 0)
66 link_error ();
67 #ifdef __x86_64__
68 if (f21 () != 0 || f22 (-1ULL) != 0
69 || f23 () != 0x1f || f24 (-1ULL) != 0x1f
70 || f25 () != 0x7fffffffffffffffULL || f26 (-1ULL) != 0x7fffffffffffffffULL
71 || f27 () != -1ULL || f28 (-1ULL) != -1ULL
72 || f29 () != -1ULL || f30 (-1ULL) != -1ULL
73 || f31 () != 1 || f32 (-1ULL) != 1
74 || f33 () != -1ULL || f34 (-1ULL) != -1ULL)
75 link_error ();
76 if (_bzhi_u64 (d, 64) != d
77 || _bzhi_u64 (d, 255) != d
78 || _bzhi_u64 (d, 576) != d
79 || _bzhi_u64 (d, 0) != 0
80 || _bzhi_u64 (d, 256) != 0
81 || _bzhi_u64 (d, 512) != 0)
82 link_error ();
83 #endif
84 return 0;
85 }
86