2009-08-07 20:30:09 +00:00
|
|
|
/*===-- moddi3.c - Implement __moddi3 -------------------------------------===
|
|
|
|
*
|
2019-01-19 10:56:40 +00:00
|
|
|
* Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
|
|
|
|
* See https://llvm.org/LICENSE.txt for license information.
|
|
|
|
* SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
|
2009-08-07 20:30:09 +00:00
|
|
|
*
|
|
|
|
* ===----------------------------------------------------------------------===
|
|
|
|
*
|
|
|
|
* This file implements __moddi3 for the compiler_rt library.
|
|
|
|
*
|
|
|
|
* ===----------------------------------------------------------------------===
|
|
|
|
*/
|
2009-06-26 16:47:03 +00:00
|
|
|
|
|
|
|
#include "int_lib.h"
|
|
|
|
|
2009-08-07 20:30:09 +00:00
|
|
|
/* Returns: a % b */
|
2009-06-26 16:47:03 +00:00
|
|
|
|
2019-04-28 21:53:32 +00:00
|
|
|
COMPILER_RT_ABI di_int __moddi3(di_int a, di_int b) {
|
|
|
|
const int bits_in_dword_m1 = (int)(sizeof(di_int) * CHAR_BIT) - 1;
|
|
|
|
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 */
|
|
|
|
du_int r;
|
|
|
|
__udivmoddi4(a, b, &r);
|
|
|
|
return ((di_int)r ^ s) - s; /* negate if s == -1 */
|
2009-06-26 16:47:03 +00:00
|
|
|
}
|