Debian Codegraph @

gcc/testsuite/gcc.target/i386/bmi2-mulx32-2.c

raw
1 /* { dg-do run { target { bmi2 && ia32 } } } */
2 /* { dg-options "-mbmi2 -O2" } */
3
4 #include <x86intrin.h>
5
6 #include "bmi2-check.h"
7
8 __attribute__((noinline))
9 unsigned long long
10 calc_mul_u32 (unsigned volatile a, unsigned b)
11 {
12 unsigned long long res = 0;
13 int i;
14 for (i = 0; i < b; ++i)
15 res += a;
16
17 return res;
18 }
19
20 __attribute__((noinline, regparm (2)))
21 unsigned calc_mulx_u32 (unsigned x, unsigned y, unsigned *res_h)
22 {
23 return (unsigned) _mulx_u32 (x, y, res_h);
24 }
25
26 static void
27 bmi2_test ()
28 {
29 unsigned i;
30 unsigned a = 0xce7ace0;
31 unsigned b = 0xfacefff;
32 unsigned res_l, res_h;
33 unsigned long long res, res_ref;
34
35 for (i = 0; i < 5; ++i) {
36 a = a * (i + 1);
37 b = b / (i + 1);
38
39 res_ref = calc_mul_u32 (a, b);
40 res_l = calc_mulx_u32 (a, b, &res_h);
41
42 res = ((unsigned long long) res_h << 32) | res_l;
43
44 if (res != res_ref)
45 abort();
46 }
47 }