[ASan/Win] Handle SEH exceptions (best-effort, similar to longjmp)
[blocksruntime.git] / lib / builtins / divti3.c
blobc73eae28fe08e78905f3ad7bbcd0b816771c63f1
1 /* ===-- divti3.c - Implement __divti3 -------------------------------------===
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 __divti3 for the compiler_rt library.
12 * ===----------------------------------------------------------------------===
15 #include "int_lib.h"
17 #ifdef CRT_HAS_128BIT
19 /* Returns: a / b */
21 COMPILER_RT_ABI ti_int
22 __divti3(ti_int a, ti_int b)
24 const int bits_in_tword_m1 = (int)(sizeof(ti_int) * CHAR_BIT) - 1;
25 ti_int s_a = a >> bits_in_tword_m1; /* s_a = a < 0 ? -1 : 0 */
26 ti_int s_b = b >> bits_in_tword_m1; /* s_b = b < 0 ? -1 : 0 */
27 a = (a ^ s_a) - s_a; /* negate if s_a == -1 */
28 b = (b ^ s_b) - s_b; /* negate if s_b == -1 */
29 s_a ^= s_b; /* sign of quotient */
30 return (__udivmodti4(a, b, (tu_int*)0) ^ s_a) - s_a; /* negate if s_a == -1 */
33 #endif /* CRT_HAS_128BIT */