* builtins.def (BUILT_IN_SETJMP): Revert latest change.
[official-gcc.git] / libgcc / config / riscv / multi3.S
blob4d454e65013d93add649b0a6c3f077be7aaf7dd2
1 /* Integer multiplication 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
10 version.
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
15 for more details.
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/>.  */
26   .text
27   .align 2
29 #if __riscv_xlen == 32
30 /* Our RV64 64-bit routines are equivalent to our RV32 32-bit routines.  */
31 # define __multi3 __muldi3
32 #endif
34   .globl __multi3
35 __multi3:
37 #if __riscv_xlen == 32
38 /* Our RV64 64-bit routines are equivalent to our RV32 32-bit routines.  */
39 # define __muldi3 __mulsi3
40 #endif
42 /* We rely on the fact that __muldi3 doesn't clobber the t-registers.  */
44   mv  t0, ra
45   mv  t5, a0
46   mv  a0, a1
47   mv  t6, a3
48   mv  a1, t5
49   mv  a4, a2
50   li  a5, 0
51   li  t2, 0
52   li  t4, 0
53 .L1:
54   add  a6, t2, a1
55   andi t3, a4, 1
56   slli a7, a5, 1
57   slti t1, a1, 0
58   srli a4, a4, 1
59   add  a5, t4, a5
60   beqz t3, .L2
61   sltu t3, a6, t2
62   mv   t2, a6
63   add  t4, t3, a5
64 .L2:
65   slli a1, a1, 1
66   or   a5, t1, a7
67   bnez a4, .L1
68   beqz a0, .L3
69   mv   a1, a2
70   call __muldi3
71   add  t4, t4, a0
72 .L3:
73   beqz t6, .L4
74   mv   a1, t6
75   mv   a0, t5
76   call  __muldi3
77   add  t4, t4, a0
78 .L4:
79   mv  a0, t2
80   mv  a1, t4
81   jr  t0