1 /* { dg-do run { target int128 } } */
2 /* { dg-options "-std=gnu99" { target c } } */
3 /* { dg-options "" { target c++ } } */
6 extern void abort (void);
8 extern "C" void abort (void);
11 #define MK_CONST128(A,B,C,D) \
12 ( (((unsigned __int128) (unsigned int) A) << 96) \
13 | (((unsigned __int128) (unsigned int) B) << 64) \
14 | (((unsigned __int128) (unsigned int) C) << 32) \
15 | ((unsigned __int128) (unsigned int) D) )
17 #define MK_CONST128_SIGNED(A,B,C,D) \
18 ((__int128) MK_CONST128(A, B, C, D))
20 #define MINUS_2 MK_CONST128_SIGNED (0xffffffffu, 0xffffffffu, 0xffffffffu, \
22 #define MINUS_3 MK_CONST128_SIGNED (0xffffffffu, 0xffffffffu, 0xffffffffu, \
24 #define MINUS_6 MK_CONST128_SIGNED (0xffffffffu, 0xffffffffu, 0xffffffffu, \
26 #define PLUS_1 MK_CONST128_SIGNED (0, 0, 0, 1)
27 #define PLUS_2 MK_CONST128_SIGNED (0, 0, 0, 2)
28 #define PLUS_3 MK_CONST128_SIGNED (0, 0, 0, 3)
29 #define PLUS_6 MK_CONST128_SIGNED (0, 0, 0, 6)
30 #define PLUS_10 MK_CONST128_SIGNED (0, 0, 0, 10)
32 #define U_8 MK_CONST128 (0, 0, 0, 8)
33 #define U_MAX MK_CONST128 (0xffffffff,0xffffffff,0xffffffff,0xffffffff)
34 #define U_CST1 MK_CONST128 (0xbeeffeed, 0xdeafcafe, 0xaffefade, 0x12345678)
35 #define U_CST2 MK_CONST128 (0x41100112, 0x21503501, 0x50010521, 0xedcba987)
37 signed __int128
foo_neg (signed __int128 v
)
42 unsigned __int128
foo_xor (unsigned __int128 x
, unsigned __int128 y
)
47 unsigned __int128
foo_inv (unsigned __int128 v
)
52 unsigned __int128
foo_rotate_left (unsigned __int128 v
)
56 for (i
= 0; i
< 128; i
++)
65 unsigned __int128
foo_rotate_right (unsigned __int128 v
)
69 for (i
= 0; i
< 128; i
++)
71 c
= (v
& ((unsigned __int128
) 1)) << 127;
78 void foo_swap (unsigned __int128
*x
, unsigned __int128
*y
)
80 unsigned __int128 x1
= x
[0];
81 unsigned __int128 y1
= y
[0];
87 __int128
foo_add (signed __int128 a
, unsigned __int128 b
)
89 return (__int128
) (a
+ (__int128
) b
);
92 __int128
foo_sub (unsigned __int128 a
, signed __int128 b
)
94 return (__int128
) ((__int128
) a
- b
);
97 __int128
foo_mul (signed __int128 a
, signed __int128 b
)
102 __int128
foo_div (signed __int128 a
, signed __int128 b
)
107 __int128
foo_shl (signed __int128 a
, int shift
)
109 return a
<< (shift
& 127);
112 __int128
foo_shr (signed __int128 a
, int shift
)
114 return a
>> (shift
& 127);
120 unsigned __int128 u1
, u2
;
122 rslt
= foo_add (MINUS_2
, U_8
);
125 rslt
= foo_sub (U_8
, MINUS_2
);
128 rslt
= foo_sub ((unsigned __int128
) foo_mul (MINUS_2
, MINUS_2
), MINUS_2
);
131 if (rslt
!= foo_shl (PLUS_3
, 1))
133 rslt
= foo_shl (MINUS_3
, 1);
136 if (foo_shr (MINUS_6
, 1) != MINUS_3
)
138 if (foo_div (MINUS_6
, MINUS_3
) != PLUS_2
)
140 if (foo_rotate_left (U_CST1
) != U_CST1
)
142 if (foo_rotate_right (U_CST1
) != U_CST1
)
147 if (u1
!= U_8
|| u2
!= U_CST1
)
150 if (foo_inv (U_CST2
) != U_CST1
)
152 if (foo_neg (PLUS_2
) != MINUS_2
)
154 if (foo_neg ((signed __int128
) U_CST1
) != foo_add (PLUS_1
, foo_xor (U_CST1
, U_MAX
)))