1 ;; Copyright (C) 2001-2024 Free Software Foundation, Inc.
3 ;; This file is part of GCC.
5 ;; GCC is free software; you can redistribute it and/or modify it under
6 ;; the terms of the GNU General Public License as published by the Free
7 ;; Software Foundation; either version 3, or (at your option) any later
10 ;; GCC is distributed in the hope that it will be useful, but WITHOUT ANY
11 ;; WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 ;; FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 ;; Under Section 7 of GPL version 3, you are granted additional
16 ;; permissions described in the GCC Runtime Library Exception, version
17 ;; 3.1, as published by the Free Software Foundation.
19 ;; You should have received a copy of the GNU General Public License and
20 ;; a copy of the GCC Runtime Library Exception along with this program;
21 ;; see the files COPYING3 and COPYING.RUNTIME respectively. If not, see
22 ;; <http://www.gnu.org/licenses/>.
24 ;; This code is derived from mulsi3.S, observing that the mstep*16-based
25 ;; multiplications there, from which it is formed, are actually
26 ;; zero-extending; in gcc-speak "umulhisi3". The difference to *this*
27 ;; function is just a missing top mstep*16 sequence and shifts and 64-bit
28 ;; additions for the high part. Compared to an implementation based on
29 ;; calling __Mul four times (see default implementation of umul_ppmm in
30 ;; longlong.h), this will complete in a time between a fourth and a third
31 ;; of that, assuming the value-based optimizations don't strike. If they
32 ;; all strike there (very often) but none here, we still win, though by a
33 ;; lesser margin, due to lesser total overhead.
36 #define CONCAT1(a, b) CONCAT2(a, b)
37 #define CONCAT2(a, b) a ## b
39 #ifdef __USER_LABEL_PREFIX__
40 # define SYM(x) CONCAT1 (__USER_LABEL_PREFIX__, x)
45 .global SYM(__umulsidi3)
46 .type SYM(__umulsidi3),@function
48 #if defined (__CRIS_arch_version) && __CRIS_arch_version >= 10
49 ;; Can't have the mulu.d last on a cache-line, due to a hardware bug. See
50 ;; the documentation for -mmul-bug-workaround.
51 ;; Not worthwhile to conditionalize here.
64 movu.w $r11,$r9 ; ab*cd = (a*c)<<32 (a*d + b*c)<<16 + b*d
66 ;; We're called for floating point numbers very often with the "low" 16
67 ;; bits zero, so it's worthwhile to optimize for that.
111 ;; d*a in $r10, d*b in $r13, ab in $r12 and cd in $r11
112 ;; $r9 = d, need to do b*c and a*c; we can drop d.
113 ;; so $r9 is up for use and we can shift down $r11 as the mstep
114 ;; source for the next mstep-part.
140 ;; d*a in $r10, d*b in $r13, c*b in $r9, ab in $r12 and c in $r11,
141 ;; need to do a*c. We want that to end up in $r11, so we shift up $r11 to
142 ;; now use as the destination operand. We'd need a test insn to update N
143 ;; to do it the other way round.
164 ;; d*a in $r10, d*b in $r13, c*b in $r9, a*c in $r11 ($r12 free).
165 ;; Need (a*d + b*c)<<16 + b*d into $r10 and
166 ;; a*c + (a*d + b*c)>>16 plus carry from the additions into $r11.
168 add.d $r9,$r10 ; (a*d + b*c) - may produce a carry.
169 scs $r12 ; The carry corresponds to bit 16 of $r11.
171 add.d $r12,$r11 ; $r11 = a*c + carry from (a*d + b*c).
173 #if defined (__CRIS_arch_version) && __CRIS_arch_version >= 8
175 addu.w $r10,$r11 ; $r11 = a*c + (a*d + b*c) >> 16 including carry.
176 clear.w $r10 ; $r10 = (a*d + b*c) << 16
180 add.d $r9,$r11 ; $r11 = a*c + (a*d + b*c) >> 16 including carry.
181 lslq 16,$r10 ; $r10 = (a*d + b*c) << 16
183 add.d $r13,$r10 ; $r10 = (a*d + b*c) << 16 + b*d - may produce a carry.
186 add.d $r9,$r11 ; Last carry added to the high-order 32 bits.
199 ;; Form the maximum in $r10, by knowing the minimum, $r9.
200 ;; (We don't know which one of $r10 or $r11 it is.)
201 ;; Check if the largest operand is still just 16 bits.
209 ;; We have ab*cd = (a*c)<<32 + (a*d + b*c)<<16 + b*d, but c==0
210 ;; so we only need (a*d)<<16 + b*d with d = $r13, ab = $r10.
211 ;; Remember that the upper part of (a*d)<<16 goes into the lower part
212 ;; of $r11 and there may be a carry from adding the low 32 parts.
238 mstep $r13,$r10 ; a*d
263 ;; We have ab*cd = (a*c)<<32 + (a*d + b*c)<<16 + b*d, but a and c==0
264 ;; so b*d (with min=b=$r13, max=d=$r10) it is. As it won't overflow the
265 ;; 32-bit part, just set $r11 to 0.
289 .size SYM(__umulsidi3),L(Lfe1)-SYM(__umulsidi3)