1 /* { dg-do run } */
2 /* { dg-options "-O3" } */
3 /* { dg-require-effective-target lp64 } */
4 /* { dg-require-effective-target ppc_cpu_supports_hw } */
5
6 #define NO_WARN_X86_INTRINSICS 1
7 #include <x86intrin.h>
8 #include "bmi2-check.h"
9
10 __attribute__((noinline))
11 unsigned __int128
12 calc_mul_u64 (unsigned long long volatile a, unsigned long long b)
13 {
14 unsigned __int128 res = 0;
15 int i;
16 for (i = 0; i < b; ++i)
17 res += (unsigned __int128) a;
18
19 return res;
20 }
21
22 __attribute__((noinline))
23 unsigned long long
24 calc_mulx_u64 (unsigned long long x,
25 unsigned long long y,
26 unsigned long long *res_h)
27 {
28 return _mulx_u64 (x, y, res_h);
29 }
30
31
32 static void
33 bmi2_test ()
34 {
35 unsigned i;
36 unsigned long long a = 0xce7ace0ce7ace0;
37 unsigned long long b = 0xface;
38 unsigned long long res_l, res_h;
39 unsigned __int128 res, res_ref;
40
41 for (i=0; i<5; ++i) {
42 a = a * (i + 1);
43 b = b / (i + 1);
44
45 res_ref = calc_mul_u64 (a, b);
46
47 res_l = calc_mulx_u64 (a, b, &res_h);
48
49 res = ((unsigned __int128) res_h << 64) | res_l;
50
51 if (res != res_ref)
52 abort();
53 }
54 }