1 /* ===-- mulvti3.c - Implement __mulvti3 -----------------------------------===
3 * The LLVM Compiler Infrastructure
5 * This file is dual licensed under the MIT and the University of Illinois Open
6 * Source Licenses. See LICENSE.TXT for details.
8 * ===----------------------------------------------------------------------===
10 * This file implements __mulvti3 for the compiler_rt library.
12 * ===----------------------------------------------------------------------===
21 /* Effects: aborts if a * b overflows */
23 COMPILER_RT_ABI ti_int
24 __mulvti3(ti_int a
, ti_int b
)
26 const int N
= (int)(sizeof(ti_int
) * CHAR_BIT
);
27 const ti_int MIN
= (ti_int
)1 << (N
-1);
28 const ti_int MAX
= ~MIN
;
41 ti_int sa
= a
>> (N
- 1);
42 ti_int abs_a
= (a
^ sa
) - sa
;
43 ti_int sb
= b
>> (N
- 1);
44 ti_int abs_b
= (b
^ sb
) - sb
;
45 if (abs_a
< 2 || abs_b
< 2)
49 if (abs_a
> MAX
/ abs_b
)
54 if (abs_a
> MIN
/ -abs_b
)
60 #endif /* CRT_HAS_128BIT */