diff options
author | Daniel Dunbar <daniel@zuster.org> | 2009-06-26 16:47:03 +0000 |
---|---|---|
committer | Daniel Dunbar <daniel@zuster.org> | 2009-06-26 16:47:03 +0000 |
commit | fd089990f76ec6392dbd0138ab874d90c632d2a4 (patch) | |
tree | 792c0fd3ba36e1cb85218b0c72df71427b168678 /compiler-rt/lib/divti3.c | |
parent | 455df54003677523ab702c564f52d2587a55733e (diff) | |
download | bcm5719-llvm-fd089990f76ec6392dbd0138ab874d90c632d2a4.tar.gz bcm5719-llvm-fd089990f76ec6392dbd0138ab874d90c632d2a4.zip |
Initial import of compiler-rt.
-
llvm-svn: 74292
Diffstat (limited to 'compiler-rt/lib/divti3.c')
-rw-r--r-- | compiler-rt/lib/divti3.c | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/compiler-rt/lib/divti3.c b/compiler-rt/lib/divti3.c new file mode 100644 index 00000000000..b8eda254cba --- /dev/null +++ b/compiler-rt/lib/divti3.c @@ -0,0 +1,34 @@ +//===-- divti3.c - Implement __divti3 -------------------------------------===// +// +// The LLVM Compiler Infrastructure +// +// This file is distributed under the University of Illinois Open Source +// License. See LICENSE.TXT for details. +// +//===----------------------------------------------------------------------===// +// +// This file implements __divti3 for the compiler_rt library. +// +//===----------------------------------------------------------------------===// + +#if __x86_64 + +#include "int_lib.h" + +tu_int __udivmodti4(tu_int a, tu_int b, tu_int* rem); + +// Returns: a / b + +ti_int +__divti3(ti_int a, ti_int b) +{ + const int bits_in_tword_m1 = (int)(sizeof(ti_int) * CHAR_BIT) - 1; + ti_int s_a = a >> bits_in_tword_m1; // s_a = a < 0 ? -1 : 0 + ti_int s_b = b >> bits_in_tword_m1; // s_b = b < 0 ? -1 : 0 + a = (a ^ s_a) - s_a; // negate if s_a == -1 + b = (b ^ s_b) - s_b; // negate if s_b == -1 + s_a ^= s_b; // sign of quotient + return (__udivmodti4(a, b, (tu_int*)0) ^ s_a) - s_a; // negate if s_a == -1 +} + +#endif |