1 typedef unsigned long long uint64_t;
4 #define BASE 0x1234567812345678ull
6 #define DEF_BBIT_TAKEN(BRANCH_IF, BIT) \
7 int bbit_is_taken_##BRANCH_IF##_##BIT (volatile uint64_t *p) \
10 asm (".set push \n\t" \
11 ".set noreorder \n\t" \
12 "bbit" #BRANCH_IF " %1, " #BIT ", 1f \n\t" \
21 : "=r"(ret) : "r"(*p)); \
24 volatile uint64_t taken_##BRANCH_IF##_##BIT = \
25 BASE & (~(1ull << BIT)) | ((uint64_t) BRANCH_IF << BIT); \
26 volatile uint64_t not_taken_##BRANCH_IF##_##BIT = \
27 BASE & (~(1ull << BIT)) | (((uint64_t) !BRANCH_IF) << BIT);
29 DEF_BBIT_TAKEN (0, 10);
30 DEF_BBIT_TAKEN (0, 36);
31 DEF_BBIT_TAKEN (1, 20);
32 DEF_BBIT_TAKEN (1, 49);
34 #define EXPECT(X) if (!(X)) abort ();
38 EXPECT (bbit_is_taken_0_10 (&taken_0_10
));
39 EXPECT (!bbit_is_taken_0_10 (¬_taken_0_10
));
41 EXPECT (bbit_is_taken_0_36 (&taken_0_36
));
42 EXPECT (!bbit_is_taken_0_36 (¬_taken_0_36
));
44 EXPECT (bbit_is_taken_1_20 (&taken_1_20
));
45 EXPECT (!bbit_is_taken_1_20 (¬_taken_1_20
));
47 EXPECT (bbit_is_taken_1_49 (&taken_1_49
));
48 EXPECT (!bbit_is_taken_1_49 (¬_taken_1_49
));