1 /* Copyright (C) 2008-2022 Free Software Foundation, Inc.
2 Contributor: Joern Rennecke <joern.rennecke@embecosm.com>
3 on behalf of Synopsys 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/>. */
26 #include "arc-ieee-754.h"
64 #define __addsf3 __addsf3_asm
65 #define __subsf3 __subsf3_asm
67 /* N.B. This is optimized for ARC700.
68 ARC600 has very different scheduling / instruction selection criteria. */
72 clobber: r1-r10, r12, flags */
79 .long 0x7f800000 ; exponent mask
91 brne r12,0,.Lsmall_shift
92 brge r10,0,.Ladd_same_exp ; r12 == 0
93 /* After subtracting, we need to normalize; when shifting to place the
94 leading 1 into position for the implicit 1 and adding that to DBL0,
95 we increment the exponent. Thus, we have to subtract one more than
96 the shift count from the exponent beforehand. Iff the exponent drops thus
97 below zero (before adding in the fraction with the leading one), we have
98 generated a denormal number. Denormal handling is basicallly reducing the
99 shift count so that we produce a zero exponent instead; FWIW, this way
100 the shift count can become zero (if we started out with exponent 1).
101 On the plus side, we don't need to check for denorm input, the result
102 of subtracing these looks just the same as denormals generated during
123 ; If both inputs are inf, but with different signs, the result is NaN.
130 /* This is a special case because we can't test for need to shift
131 down by checking if bit 23 of DBL0 changes. OTOH, here we know
132 that we always need to shift down. */
133 ; adding the two floating point numbers together makes the sign
134 ; cancel out and apear as carry; the exponent is doubled, and the
135 ; fraction also in need of shifting left by one. The two implicit
136 ; ones of the sources make an implicit 1 of the result, again
137 ; non-existent in a place shifted by one.
140 breq r6,0,.Ldenorm_add
141 add.ne r0,r0,1 ; round to even.
144 add r0,r0,r1 ; increment exponent
145 bic.f 0,r9,r0; check for overflow -> infinity.
160 brhi r12,25,.Lret_dbl0
161 breq.d r6,0,.Ldenorm_small_shift
164 .Lfixed_denorm_small_shift:
169 /* subtract, abs(DBL0) > abs(DBL1) */
170 /* DBL0: original values
171 DBL1: fraction with explicit leading 1, shifted into place
172 r4: orig. DBL0 & 0x7fffffff
173 r6: orig. DBL1 & 0x7f800000
175 r10: orig. DBL0H ^ DBL1H
183 beq.d .Large_cancel_sub
189 breq r3,1,.Lsub_done_noshift
192 brlo r6,r5,.Ldenorm_sub
210 .Ldenorm_small_shift:
211 brne.d r12,1,.Lfixed_denorm_small_shift
214 mov_s r5,r12 ; zero r5, and align following code
215 .Ladd: ; Both bit 23 of DBL1 and bit 0 of r5 are clear.
218 bbit0.d r2,23,.Lno_shiftdown
220 bic.f 0,r9,r0; check for overflow -> infinity; eq : infinity
222 lsr.ne.f r2,r2,2; cc: even ; hi: might round down
224 rcmp.hi r5,1; hi : round down
229 /* r4: DBL0H & 0x7fffffff
230 r6: DBL1H & 0x7f800000
233 r12: shift count (negative) */
236 brhs r6,r9,.Lret_dbl1 ; inf or NaN
238 brhi r8,25,.Lret_dbl1
240 breq.d r6,0,.Ldenorm_small_shift_dbl0
243 .Lfixed_denorm_small_shift_dbl0:
245 brge.d r10,0,.Ladd_dbl1_gt
247 /* subtract, abs(DBL0) < abs(DBL1) */
248 /* DBL0: fraction with explicit leading 1, shifted into place
250 r6: orig. DBL1 & 0x7f800000
260 bne.d .Lsub_done ; note: r6 is already set up.
264 /* r4:r12 : unnormalized result fraction
265 r7: result sign and exponent */
266 /* When seeing large cancellation, only the topmost guard bit might be set. */
271 xor.f 0,r0,r7 ; test if exponent is negative
272 tst.pl r9,r0 ; test if exponent is zero
273 jpnz [blink] ; return if non-denormal result
281 ; If a denorm is produced, we have an exact result -
282 ; no need for rounding.
316 .Ldenorm_small_shift_dbl0:
318 bne.d .Lfixed_denorm_small_shift_dbl0
322 .Ladd_dbl1_gt: ; both bit 23 of DBL0 and bit 0 of r5 are clear.
325 bbit0.d r2,23,.Lno_shiftdown_dbl1_gt
327 bic.f 0,r9,r0; check for overflow -> infinity; eq : infinity
329 lsr.ne.f r2,r2,2; cc: even ; hi: might round down
331 rcmp.hi r5,1; hi : round down
337 .Lno_shiftdown_dbl1_gt: