Path: blob/master/libs/compiler-rt/lib/builtins/divdi3.c
4395 views
/* ===-- divdi3.c - Implement __divdi3 -------------------------------------===1*2* The LLVM Compiler Infrastructure3*4* This file is dual licensed under the MIT and the University of Illinois Open5* Source Licenses. See LICENSE.TXT for details.6*7* ===----------------------------------------------------------------------===8*9* This file implements __divdi3 for the compiler_rt library.10*11* ===----------------------------------------------------------------------===12*/1314#include "int_lib.h"1516/* Returns: a / b */1718COMPILER_RT_ABI di_int19__divdi3(di_int a, di_int b)20{21const int bits_in_dword_m1 = (int)(sizeof(di_int) * CHAR_BIT) - 1;22di_int s_a = a >> bits_in_dword_m1; /* s_a = a < 0 ? -1 : 0 */23di_int s_b = b >> bits_in_dword_m1; /* s_b = b < 0 ? -1 : 0 */24a = (a ^ s_a) - s_a; /* negate if s_a == -1 */25b = (b ^ s_b) - s_b; /* negate if s_b == -1 */26s_a ^= s_b; /*sign of quotient */27return (__udivmoddi4(a, b, (du_int*)0) ^ s_a) - s_a; /* negate if s_a == -1 */28}293031