1 /* Copyright (C) 2008-2013 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 /* XMAC schedule: directly back-to-back multiplies stall; the third
27 instruction after a multiply stalls unless it is also a multiply. */
28 #include "arc-ieee-754.h"
54 #define __muldf3 __muldf3_asm
56 /* N.B. This is optimized for ARC700.
57 ARC600 has very different scheduling / instruction selection criteria. */
58 /* For the standard multiplier, instead of mpyu rx,DBL0L,DBL1L; tst rx,rx ,
60 sub rx,DBL0L,1; bic rx,DBL0L,rx; lsr rx,rx; norm rx,rx; asl.f 0,DBL1L,rx */
62 __muldf3_support: /* This label makes debugger output saner. */
63 /* If one number is denormal, subtract some from the exponent of the other
64 one (if the other exponent is too small, return 0), and normalize the
65 denormal. Then re-run the computation. */
78 brhs 0x3ca00001,r11,.Lret0
79 sub_s DBL0H,DBL0H,DBL1H
81 add_s DBL0H,DBL0H,DBL1H
82 breq_s DBL1H,0,.Ldenorm_2
98 xor_s DBL1H,DBL1H,DBL0H
100 max r8,DBL0H,r12 ; either NaN -> NaN ; otherwise inf
103 or.ne.f DBL1L,DBL1L,r12
104 not_s DBL0H,DBL0L ; inf * 0 -> NaN
108 bset.mi DBL0H,DBL0H,31
110 .Lret0: xor_s DBL0H,DBL0H,DBL1H
112 xor_s DBL0H,DBL0H,DBL1H
118 breq_s DBL1L,0,.Lret0 ; 0 input -> 0 output
125 lsr.f DBL1H,DBL1L,r11
127 sub_s DBL0H,DBL0H,r12
129 sub_s DBL1L,DBL1L,DBL1H
134 ld.as r9,[pcl,0x4b] ; ((.L7ff00000-.+2)/4)]
140 breq r11,0,.Ldenorm_dbl0
148 breq r12,0,.Ldenorm_dbl1
151 breq r11,r9,.Linf_nan
152 breq r12,r9,.Linf_nan
157 bclr r8,r9,30 ; 0x3ff00000
159 ; XMAC write-back stall / std. mult stall is one cycle later
160 bclr r6,r9,20 ; 0x7fe00000
161 add.cs r7,r7,1 ; fraction product in r7:r5:r4
163 bset.ne r4,r4,0 ; put least significant word into sticky bit
165 add_l r12,r12,r11 ; add exponents
166 rsub.eq r8,r8,r9 ; 0x40000000
167 sub r12,r12,r8 ; subtract bias + implicit 1
168 brhs.d r12,r6,.Linf_denorm
176 cmp.eq r4,r4 ; round to nearest / round to even
185 bset.mi DBL0H,DBL0H,31
187 /* We have checked for infinity / NaN input before, and transformed
188 denormalized inputs into normalized inputs. Thus, the worst case
189 exponent overflows are:
190 1 + 1 - 0x400 == 0xc02 : maximum underflow
191 0x7fe + 0x7fe - 0x3ff == 0xbfd ; maximum overflow
192 N.B. 0x7e and 0x7f are also values for overflow.
194 If (r12 <= -54), we have an underflow to zero. */
197 brlo r12,0xc0000000,.Linf
201 brgt r10,0,.Lshift_frac
210 brge r10,1,.Lshift_frac
211 breq r10,0,.Lround_frac
213 brgt r10,21,.Lshift32_frac
221 adc.eq.f DBL0L,DBL0L,0
226 .Linf: xor.f DBL1H,DBL1H,DBL0H
230 bset.mi DBL0H,DBL0H,31