2 /*============================================================================
4 This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
5 Package, Release 3e, by John R. Hauser.
7 Copyright 2011, 2012, 2013, 2014, 2015, 2016 The Regents of the University of
8 California. All rights reserved.
10 Redistribution and use in source and binary forms, with or without
11 modification, are permitted provided that the following conditions are met:
13 1. Redistributions of source code must retain the above copyright notice,
14 this list of conditions, and the following disclaimer.
16 2. Redistributions in binary form must reproduce the above copyright notice,
17 this list of conditions, and the following disclaimer in the documentation
18 and/or other materials provided with the distribution.
20 3. Neither the name of the University nor the names of its contributors may
21 be used to endorse or promote products derived from this software without
22 specific prior written permission.
24 THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
25 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
26 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
27 DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
28 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
29 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
30 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
31 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
32 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
33 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 =============================================================================*/
40 #include "internals.h"
41 #include "specialize.h"
42 #include "softfloat.h"
44 #ifdef SOFTFLOAT_FAST_INT64
47 f128M_mul( const float128_t
*aPtr
, const float128_t
*bPtr
, float128_t
*zPtr
)
50 *zPtr
= f128_mul( *aPtr
, *bPtr
);
57 f128M_mul( const float128_t
*aPtr
, const float128_t
*bPtr
, float128_t
*zPtr
)
59 const uint32_t *aWPtr
, *bWPtr
;
67 uint32_t uiZ96
, sigA
[4];
68 uint_fast8_t shiftDist
;
71 uint32_t sigProd
[8], *extSigZPtr
;
73 /*------------------------------------------------------------------------
74 *------------------------------------------------------------------------*/
75 aWPtr
= (const uint32_t *) aPtr
;
76 bWPtr
= (const uint32_t *) bPtr
;
77 zWPtr
= (uint32_t *) zPtr
;
78 /*------------------------------------------------------------------------
79 *------------------------------------------------------------------------*/
80 uiA96
= aWPtr
[indexWordHi( 4 )];
81 expA
= expF128UI96( uiA96
);
82 uiB96
= bWPtr
[indexWordHi( 4 )];
83 expB
= expF128UI96( uiB96
);
84 signZ
= signF128UI96( uiA96
) ^ signF128UI96( uiB96
);
85 /*------------------------------------------------------------------------
86 *------------------------------------------------------------------------*/
87 if ( (expA
== 0x7FFF) || (expB
== 0x7FFF) ) {
88 if ( softfloat_tryPropagateNaNF128M( aWPtr
, bWPtr
, zWPtr
) ) return;
90 if ( ! expA
) goto possiblyInvalid
;
95 ! fracF128UI96( ptr
[indexWordHi( 4 )] )
96 && ! (ptr
[indexWord( 4, 2 )] | ptr
[indexWord( 4, 1 )]
97 | ptr
[indexWord( 4, 0 )])
99 softfloat_invalidF128M( zWPtr
);
103 uiZ96
= packToF128UI96( signZ
, 0x7FFF, 0 );
106 /*------------------------------------------------------------------------
107 *------------------------------------------------------------------------*/
109 sigA
[indexWordHi( 4 )] = fracF128UI96( uiA96
) | 0x00010000;
110 sigA
[indexWord( 4, 2 )] = aWPtr
[indexWord( 4, 2 )];
111 sigA
[indexWord( 4, 1 )] = aWPtr
[indexWord( 4, 1 )];
112 sigA
[indexWord( 4, 0 )] = aWPtr
[indexWord( 4, 0 )];
114 expA
= softfloat_shiftNormSigF128M( aWPtr
, 0, sigA
);
115 if ( expA
== -128 ) goto zero
;
118 sigB
[indexWordHi( 4 )] = fracF128UI96( uiB96
) | 0x00010000;
119 sigB
[indexWord( 4, 2 )] = bWPtr
[indexWord( 4, 2 )];
120 sigB
[indexWord( 4, 1 )] = bWPtr
[indexWord( 4, 1 )];
121 sigB
[indexWord( 4, 0 )] = bWPtr
[indexWord( 4, 0 )];
123 expB
= softfloat_shiftNormSigF128M( bWPtr
, 0, sigB
);
124 if ( expB
== -128 ) goto zero
;
126 /*------------------------------------------------------------------------
127 *------------------------------------------------------------------------*/
128 expZ
= expA
+ expB
- 0x4000;
129 softfloat_mul128MTo256M( sigA
, sigB
, sigProd
);
131 sigProd
[indexWord( 8, 2 )]
132 || (sigProd
[indexWord( 8, 1 )] | sigProd
[indexWord( 8, 0 )])
134 sigProd
[indexWord( 8, 3 )] |= 1;
136 extSigZPtr
= &sigProd
[indexMultiwordHi( 8, 5 )];
138 if ( extSigZPtr
[indexWordHi( 5 )] & 2 ) {
142 softfloat_shortShiftLeft160M( extSigZPtr
, shiftDist
, extSigZPtr
);
143 softfloat_roundPackMToF128M( signZ
, expZ
, extSigZPtr
, zWPtr
);
145 /*------------------------------------------------------------------------
146 *------------------------------------------------------------------------*/
148 uiZ96
= packToF128UI96( signZ
, 0, 0 );
150 zWPtr
[indexWordHi( 4 )] = uiZ96
;
151 zWPtr
[indexWord( 4, 2 )] = 0;
152 zWPtr
[indexWord( 4, 1 )] = 0;
153 zWPtr
[indexWord( 4, 0 )] = 0;