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 * ===----------------------------------------------------------------------===
22 /* Effects: aborts if a * b overflows */
25 __mulvti3(ti_int a, ti_int b)
27 const int N = (int)(sizeof(ti_int) * CHAR_BIT);
28 const ti_int MIN = (ti_int)1 << (N-1);
29 const ti_int MAX = ~MIN;
42 ti_int sa = a >> (N - 1);
43 ti_int abs_a = (a ^ sa) - sa;
44 ti_int sb = b >> (N - 1);
45 ti_int abs_b = (b ^ sb) - sb;
46 if (abs_a < 2 || abs_b < 2)
50 if (abs_a > MAX / abs_b)
55 if (abs_a > MIN / -abs_b)