Path: blob/main/contrib/llvm-project/compiler-rt/lib/builtins/divmoddi4.c
35260 views
//===-- divmoddi4.c - Implement __divmoddi4 -------------------------------===//1//2// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.3// See https://llvm.org/LICENSE.txt for license information.4// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception5//6//===----------------------------------------------------------------------===//7//8// This file implements __divmoddi4 for the compiler_rt library.9//10//===----------------------------------------------------------------------===//1112#include "int_lib.h"1314// Returns: a / b, *rem = a % b1516COMPILER_RT_ABI di_int __divmoddi4(di_int a, di_int b, di_int *rem) {17const int bits_in_dword_m1 = (int)(sizeof(di_int) * CHAR_BIT) - 1;18di_int s_a = a >> bits_in_dword_m1; // s_a = a < 0 ? -1 : 019di_int s_b = b >> bits_in_dword_m1; // s_b = b < 0 ? -1 : 020a = (du_int)(a ^ s_a) - s_a; // negate if s_a == -121b = (du_int)(b ^ s_b) - s_b; // negate if s_b == -122s_b ^= s_a; // sign of quotient23du_int r;24di_int q = (__udivmoddi4(a, b, &r) ^ s_b) - s_b; // negate if s_b == -125*rem = (r ^ s_a) - s_a; // negate if s_a == -126return q;27}282930