1 // SPDX-License-Identifier: BSD-3-Clause
2 
3 /*============================================================================
4 
5 This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic
6 Package, Release 3a, by John R. Hauser.
7 
8 Copyright 2011, 2012, 2013, 2014 The Regents of the University of California.
9 All rights reserved.
10 
11 Redistribution and use in source and binary forms, with or without
12 modification, are permitted provided that the following conditions are met:
13 
14  1. Redistributions of source code must retain the above copyright notice,
15     this list of conditions, and the following disclaimer.
16 
17  2. Redistributions in binary form must reproduce the above copyright notice,
18     this list of conditions, and the following disclaimer in the documentation
19     and/or other materials provided with the distribution.
20 
21  3. Neither the name of the University nor the names of its contributors may
22     be used to endorse or promote products derived from this software without
23     specific prior written permission.
24 
25 THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY
26 EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
27 WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE
28 DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY
29 DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
30 (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
31 LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
32 ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
33 (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
34 SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
35 
36 =============================================================================*/
37 
38 #include <stdbool.h>
39 #include <stdint.h>
40 #include "platform.h"
41 #include "internals.h"
42 #include "specialize.h"
43 #include "softfloat.h"
44 
45 #ifdef SOFTFLOAT_FAST_INT64
46 
47 void
extF80M_mul(const extFloat80_t * aPtr,const extFloat80_t * bPtr,extFloat80_t * zPtr)48  extF80M_mul(
49      const extFloat80_t *aPtr, const extFloat80_t *bPtr, extFloat80_t *zPtr )
50 {
51 
52     *zPtr = extF80_mul( *aPtr, *bPtr );
53 
54 }
55 
56 #else
57 
58 void
extF80M_mul(const extFloat80_t * aPtr,const extFloat80_t * bPtr,extFloat80_t * zPtr)59  extF80M_mul(
60      const extFloat80_t *aPtr, const extFloat80_t *bPtr, extFloat80_t *zPtr )
61 {
62     const struct extFloat80M *aSPtr, *bSPtr;
63     struct extFloat80M *zSPtr;
64     uint_fast16_t uiA64;
65     int32_t expA;
66     uint_fast16_t uiB64;
67     int32_t expB;
68     bool signZ;
69     uint_fast16_t exp, uiZ64;
70     uint64_t uiZ0, sigA, sigB;
71     int32_t expZ;
72     uint32_t sigProd[4], *extSigZPtr;
73 
74     /*------------------------------------------------------------------------
75     *------------------------------------------------------------------------*/
76     aSPtr = (const struct extFloat80M *) aPtr;
77     bSPtr = (const struct extFloat80M *) bPtr;
78     zSPtr = (struct extFloat80M *) zPtr;
79     /*------------------------------------------------------------------------
80     *------------------------------------------------------------------------*/
81     uiA64 = aSPtr->signExp;
82     expA = expExtF80UI64( uiA64 );
83     uiB64 = bSPtr->signExp;
84     expB = expExtF80UI64( uiB64 );
85     signZ = signExtF80UI64( uiA64 ) ^ signExtF80UI64( uiB64 );
86     /*------------------------------------------------------------------------
87     *------------------------------------------------------------------------*/
88     if ( (expA == 0x7FFF) || (expB == 0x7FFF) ) {
89         if ( softfloat_tryPropagateNaNExtF80M( aSPtr, bSPtr, zSPtr ) ) return;
90         if (
91                (! aSPtr->signif && (expA != 0x7FFF))
92             || (! bSPtr->signif && (expB != 0x7FFF))
93         ) {
94             softfloat_invalidExtF80M( zSPtr );
95             return;
96         }
97         uiZ64 = packToExtF80UI64( signZ, 0x7FFF );
98         uiZ0  = UINT64_C( 0x8000000000000000 );
99         goto uiZ;
100     }
101     /*------------------------------------------------------------------------
102     *------------------------------------------------------------------------*/
103     if ( ! expA ) expA = 1;
104     sigA = aSPtr->signif;
105     if ( ! (sigA & UINT64_C( 0x8000000000000000 )) ) {
106         if ( ! sigA ) goto zero;
107         expA += softfloat_normExtF80SigM( &sigA );
108     }
109     if ( ! expB ) expB = 1;
110     sigB = bSPtr->signif;
111     if ( ! (sigB & UINT64_C( 0x8000000000000000 )) ) {
112         if ( ! sigB ) goto zero;
113         expB += softfloat_normExtF80SigM( &sigB );
114     }
115     /*------------------------------------------------------------------------
116     *------------------------------------------------------------------------*/
117     expZ = expA + expB - 0x3FFE;
118     softfloat_mul64To128M( sigA, sigB, sigProd );
119     if ( sigProd[indexWordLo( 4 )] ) sigProd[indexWord( 4, 1 )] |= 1;
120     extSigZPtr = &sigProd[indexMultiwordHi( 4, 3 )];
121     if ( sigProd[indexWordHi( 4 )] < 0x80000000 ) {
122         --expZ;
123         softfloat_add96M( extSigZPtr, extSigZPtr, extSigZPtr );
124     }
125     softfloat_roundPackMToExtF80M(
126         signZ, expZ, extSigZPtr, extF80_roundingPrecision, zSPtr );
127     return;
128     /*------------------------------------------------------------------------
129     *------------------------------------------------------------------------*/
130  zero:
131     uiZ64 = packToExtF80UI64( signZ, 0 );
132     uiZ0  = 0;
133  uiZ:
134     zSPtr->signExp = uiZ64;
135     zSPtr->signif  = uiZ0;
136 
137 }
138 
139 #endif
140 
141