2009-08-08 04:30:09 +08:00
|
|
|
/*===-- moddi3.c - Implement __moddi3 -------------------------------------===
|
|
|
|
*
|
|
|
|
* The LLVM Compiler Infrastructure
|
|
|
|
*
|
2010-11-17 06:13:33 +08:00
|
|
|
* This file is dual licensed under the MIT and the University of Illinois Open
|
|
|
|
* Source Licenses. See LICENSE.TXT for details.
|
2009-08-08 04:30:09 +08:00
|
|
|
*
|
|
|
|
* ===----------------------------------------------------------------------===
|
|
|
|
*
|
|
|
|
* This file implements __moddi3 for the compiler_rt library.
|
|
|
|
*
|
|
|
|
* ===----------------------------------------------------------------------===
|
|
|
|
*/
|
2009-06-27 00:47:03 +08:00
|
|
|
|
|
|
|
#include "int_lib.h"
|
|
|
|
|
2011-04-20 01:52:09 +08:00
|
|
|
COMPILER_RT_ABI du_int __udivmoddi4(du_int a, du_int b, du_int* rem);
|
2009-06-27 00:47:03 +08:00
|
|
|
|
2009-08-08 04:30:09 +08:00
|
|
|
/* Returns: a % b */
|
2009-06-27 00:47:03 +08:00
|
|
|
|
2011-04-20 01:52:09 +08:00
|
|
|
COMPILER_RT_ABI di_int
|
2009-06-27 00:47:03 +08:00
|
|
|
__moddi3(di_int a, di_int b)
|
|
|
|
{
|
|
|
|
const int bits_in_dword_m1 = (int)(sizeof(di_int) * CHAR_BIT) - 1;
|
2009-08-08 04:30:09 +08:00
|
|
|
di_int s = b >> bits_in_dword_m1; /* s = b < 0 ? -1 : 0 */
|
|
|
|
b = (b ^ s) - s; /* negate if s == -1 */
|
|
|
|
s = a >> bits_in_dword_m1; /* s = a < 0 ? -1 : 0 */
|
|
|
|
a = (a ^ s) - s; /* negate if s == -1 */
|
2009-06-27 00:47:03 +08:00
|
|
|
di_int r;
|
|
|
|
__udivmoddi4(a, b, (du_int*)&r);
|
2009-08-08 04:30:09 +08:00
|
|
|
return (r ^ s) - s; /* negate if s == -1 */
|
2009-06-27 00:47:03 +08:00
|
|
|
}
|