]> git.ipfire.org Git - thirdparty/gcc.git/blame - libgcc/config/rl78/mulsi3.S
rl78.c (rl78_asm_file_start): Specify alternate vregs location for RL78/G10.
[thirdparty/gcc.git] / libgcc / config / rl78 / mulsi3.S
CommitLineData
5d5bf775 1; Copyright (C) 2011-2013 Free Software Foundation, Inc.
85b8555e
DD
2; Contributed by Red Hat.
3;
4; This file is free software; you can redistribute it and/or modify it
5; under the terms of the GNU General Public License as published by the
6; Free Software Foundation; either version 3, or (at your option) any
7; later version.
8;
9; This file is distributed in the hope that it will be useful, but
10; WITHOUT ANY WARRANTY; without even the implied warranty of
11; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12; General Public License for more details.
13;
14; Under Section 7 of GPL version 3, you are granted additional
15; permissions described in the GCC Runtime Library Exception, version
16; 3.1, as published by the Free Software Foundation.
17;
18; You should have received a copy of the GNU General Public License and
19; a copy of the GCC Runtime Library Exception along with this program;
20; see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
21; <http://www.gnu.org/licenses/>.
22
23;; 32x32=32 multiply
24
5c0029de
DD
25#include "vregs.h"
26
27; the G10 only has one register bank, so cannot use these optimized
28; versions. Use the C version instead.
29
30#ifndef __RL78_G10__
85b8555e
DD
31
32
33;----------------------------------------------------------------------
34
35; Register use:
36; RB0 RB1 RB2
37; AX op2L res32L res32H
38; BC op2H (resH) op1
39; DE count (resL-tmp)
40; HL [sp+4]
41
42 .text
43 nop
44 .global ___mulsi3 ; (USI a, USI b)
45___mulsi3:
46 ;; A is at [sp+4]
47 ;; B is at [sp+8]
48 ;; result is in R8..R11
49
85b8555e
DD
50 sel rb2
51 push ax
52 push bc
53 sel rb0
54
55 clrw ax
56 movw r8, ax
57 movw r16, ax
58
ceb2fc49 59 movw ax, [sp+14]
85b8555e
DD
60 cmpw ax, #0
61 bz $1f
62 cmpw ax, #0xffff
63 bnz $2f
ceb2fc49 64 movw ax, [sp+8]
85b8555e
DD
65 sel rb1
66 subw ax, r_0
67 sel rb0
68 br $1f
692:
70 movw bc, ax
ceb2fc49 71 movw ax, [sp+8]
85b8555e
DD
72 cmpw ax, #0
73 skz
74 call !.Lmul_hi
751:
76
ceb2fc49 77 movw ax, [sp+10]
85b8555e
DD
78 cmpw ax, #0
79 bz $1f
80 cmpw ax, #0xffff
81 bnz $2f
ceb2fc49 82 movw ax, [sp+12]
85b8555e
DD
83 sel rb1
84 subw ax, r_0
85 sel rb0
86 br $1f
872:
88 movw bc, ax
ceb2fc49 89 movw ax, [sp+12]
85b8555e
DD
90 cmpw ax, #0
91 skz
92 call !.Lmul_hi
931:
94
95 movw ax, r8
96 movw r16, ax
97 clrw ax
98 movw r8, ax
99
100 ;; now do R16:R8 += op1L * op2L
101
102 ;; op1 is in AX.0 (needs to shrw)
103 ;; op2 is in BC.2 and BC.1 (bc can shlw/rolcw)
104 ;; res is in AX.2 and AX.1 (needs to addw)
105
ceb2fc49 106 movw ax, [sp+8]
85b8555e 107 movw r10, ax ; BC.1
ceb2fc49 108 movw ax, [sp+12]
85b8555e
DD
109
110 cmpw ax, r10
111 bc $.Lmul_hisi_top
112 movw bc, r10
113 movw r10, ax
114 movw ax, bc
115
116
117.Lmul_hisi_top:
118 movw bc, #0
119
120.Lmul_hisi_loop:
121 shrw ax, 1
122 bnc $.Lmul_hisi_no_add
123 sel rb1
124 addw ax, bc
125 sel rb2
126 sknc
127 incw ax
128 addw ax, r_2
129.Lmul_hisi_no_add:
130 sel rb1
131 shlw bc, 1
132 sel rb0
133 rolwc bc, 1
134 cmpw ax, #0
135 bz $.Lmul_hisi_done
136
137 shrw ax, 1
138 bnc $.Lmul_hisi_no_add2
139 sel rb1
140 addw ax, bc
141 sel rb2
142 sknc
143 incw ax
144 addw ax, r_2
145.Lmul_hisi_no_add2:
146 sel rb1
147 shlw bc, 1
148 sel rb0
149 rolwc bc, 1
150 cmpw ax, #0
151 bnz $.Lmul_hisi_loop
152
153.Lmul_hisi_done:
154
155 movw ax, r16
156 movw r10, ax
157
158 sel rb2
159 pop bc
160 pop ax
161 sel rb0
162
163 ret
164
165;----------------------------------------------------------------------
166
ceb2fc49
DD
167 .global ___mulhi3
168___mulhi3:
169 movw r8, #0
170 movw ax, [sp+6]
171 movw bc, ax
172 movw ax, [sp+4]
173
85b8555e
DD
174 ;; R8 += AX * BC
175.Lmul_hi:
176 cmpw ax, bc
177 skc
178 xchw ax, bc
179 br $.Lmul_hi_loop
180
181.Lmul_hi_top:
182 sel rb1
183 addw ax, r_2
184 sel rb0
185.Lmul_hi_no_add:
186 shlw bc, 1
187.Lmul_hi_loop:
188 shrw ax, 1
189 bc $.Lmul_hi_top
190 cmpw ax, #0
191 bz $.Lmul_hi_done
192
193 shlw bc, 1
194 shrw ax, 1
195 bc $.Lmul_hi_top
196 cmpw ax, #0
197 bnz $.Lmul_hi_no_add
198
199.Lmul_hi_done:
200 ret
5c0029de
DD
201
202#endif