1 2/*============================================================================ 3 4This C source file is part of the SoftFloat IEEE Floating-Point Arithmetic 5Package, Release 3e, by John R. Hauser. 6 7Copyright 2011, 2012, 2013, 2014, 2015, 2016 The Regents of the University of 8California. All rights reserved. 9 10Redistribution and use in source and binary forms, with or without 11modification, are permitted provided that the following conditions are met: 12 13 1. Redistributions of source code must retain the above copyright notice, 14 this list of conditions, and the following disclaimer. 15 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. 19 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. 23 24THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS", AND ANY 25EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED 26WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, ARE 27DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY 28DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES 29(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; 30LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND 31ON 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 33SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 34 35=============================================================================*/ 36 37#include <stdbool.h> 38#include <stdint.h> 39#include "platform.h" 40#include "internals.h" 41#include "specialize.h" 42#include "softfloat.h" 43 44#ifdef SOFTFLOAT_FAST_INT64 45 46void 47 f128M_mul( const float128_t *aPtr, const float128_t *bPtr, float128_t *zPtr ) 48{ 49 50 *zPtr = f128_mul( *aPtr, *bPtr ); 51 52} 53 54#else 55 56void 57 f128M_mul( const float128_t *aPtr, const float128_t *bPtr, float128_t *zPtr ) 58{ 59 const uint32_t *aWPtr, *bWPtr; 60 uint32_t *zWPtr; 61 uint32_t uiA96; 62 int32_t expA; 63 uint32_t uiB96; 64 int32_t expB; 65 bool signZ; 66 const uint32_t *ptr; 67 uint32_t uiZ96, sigA[4]; 68 uint_fast8_t shiftDist; 69 uint32_t sigB[4]; 70 int32_t expZ; 71 uint32_t sigProd[8], *extSigZPtr; 72 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; 89 ptr = aWPtr; 90 if ( ! expA ) goto possiblyInvalid; 91 if ( ! expB ) { 92 ptr = bWPtr; 93 possiblyInvalid: 94 if ( 95 ! fracF128UI96( ptr[indexWordHi( 4 )] ) 96 && ! (ptr[indexWord( 4, 2 )] | ptr[indexWord( 4, 1 )] 97 | ptr[indexWord( 4, 0 )]) 98 ) { 99 softfloat_invalidF128M( zWPtr ); 100 return; 101 } 102 } 103 uiZ96 = packToF128UI96( signZ, 0x7FFF, 0 ); 104 goto uiZ96; 105 } 106 /*------------------------------------------------------------------------ 107 *------------------------------------------------------------------------*/ 108 if ( expA ) { 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 )]; 113 } else { 114 expA = softfloat_shiftNormSigF128M( aWPtr, 0, sigA ); 115 if ( expA == -128 ) goto zero; 116 } 117 if ( expB ) { 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 )]; 122 } else { 123 expB = softfloat_shiftNormSigF128M( bWPtr, 0, sigB ); 124 if ( expB == -128 ) goto zero; 125 } 126 /*------------------------------------------------------------------------ 127 *------------------------------------------------------------------------*/ 128 expZ = expA + expB - 0x4000; 129 softfloat_mul128MTo256M( sigA, sigB, sigProd ); 130 if ( 131 sigProd[indexWord( 8, 2 )] 132 || (sigProd[indexWord( 8, 1 )] | sigProd[indexWord( 8, 0 )]) 133 ) { 134 sigProd[indexWord( 8, 3 )] |= 1; 135 } 136 extSigZPtr = &sigProd[indexMultiwordHi( 8, 5 )]; 137 shiftDist = 16; 138 if ( extSigZPtr[indexWordHi( 5 )] & 2 ) { 139 ++expZ; 140 shiftDist = 15; 141 } 142 softfloat_shortShiftLeft160M( extSigZPtr, shiftDist, extSigZPtr ); 143 softfloat_roundPackMToF128M( signZ, expZ, extSigZPtr, zWPtr ); 144 return; 145 /*------------------------------------------------------------------------ 146 *------------------------------------------------------------------------*/ 147 zero: 148 uiZ96 = packToF128UI96( signZ, 0, 0 ); 149 uiZ96: 150 zWPtr[indexWordHi( 4 )] = uiZ96; 151 zWPtr[indexWord( 4, 2 )] = 0; 152 zWPtr[indexWord( 4, 1 )] = 0; 153 zWPtr[indexWord( 4, 0 )] = 0; 154 155} 156 157#endif 158 159