1 /* Integer division routines for RISC-V.
3 Copyright (C) 2016-2017 Free Software Foundation, Inc.
5 This file is part of GCC.
7 GCC is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 3, or (at your option) any later
12 GCC is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 Under Section 7 of GPL version 3, you are granted additional
18 permissions described in the GCC Runtime Library Exception, version
19 3.1, as published by the Free Software Foundation.
21 You should have received a copy of the GNU General Public License and
22 a copy of the GCC Runtime Library Exception along with this program;
23 see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
24 <http://www.gnu.org/licenses/>. */
29 #if __riscv_xlen == 32
30 /* Our RV64 64-bit routines are equivalent to our RV32 32-bit routines. */
31 # define __udivdi3 __udivsi3
32 # define __umoddi3 __umodsi3
33 # define __divdi3 __divsi3
34 # define __moddi3 __modsi3
38 /* Compute __udivdi3(a0 << 32, a1 << 32); cast result to uint32_t. */
48 /* Compute __udivdi3((uint32_t)a0, (uint32_t)a1); cast a1 to uint32_t. */
63 /* Check for special case of INT_MIN/-1. Otherwise, fall into __divdi3. */
72 /* Since the quotient is positive, fall into __udivdi3. */
102 /* Call __udivdi3(a0, a1), then return the remainder, which is in a1. */
108 /* Handle negative arguments to __divdi3. */
111 bgez a1, .L12 /* Compute __udivdi3(-a0, a1), then negate the result. */
113 j __udivdi3 /* Compute __udivdi3(-a0, -a1). */
114 .L11: /* Compute __udivdi3(a0, -a1), then negate the result. */
128 jal __udivdi3 /* The dividend is not negative. */
136 jal __udivdi3 /* The dividend is hella negative. */
140 #if __riscv_xlen == 64
141 /* continuation of __divsi3 */