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
extF80M_to_f128M(const extFloat80_t * aPtr,float128_t * zPtr)47 void extF80M_to_f128M( const extFloat80_t *aPtr, float128_t *zPtr )
48 {
49
50 *zPtr = extF80_to_f128( *aPtr );
51
52 }
53
54 #else
55
extF80M_to_f128M(const extFloat80_t * aPtr,float128_t * zPtr)56 void extF80M_to_f128M( const extFloat80_t *aPtr, float128_t *zPtr )
57 {
58 const struct extFloat80M *aSPtr;
59 uint32_t *zWPtr;
60 uint_fast16_t uiA64;
61 bool sign;
62 int32_t exp;
63 uint64_t sig;
64 struct commonNaN commonNaN;
65 uint32_t uiZ96;
66
67 /*------------------------------------------------------------------------
68 *------------------------------------------------------------------------*/
69 aSPtr = (const struct extFloat80M *) aPtr;
70 zWPtr = (uint32_t *) zPtr;
71 /*------------------------------------------------------------------------
72 *------------------------------------------------------------------------*/
73 uiA64 = aSPtr->signExp;
74 sign = signExtF80UI64( uiA64 );
75 exp = expExtF80UI64( uiA64 );
76 sig = aSPtr->signif;
77 /*------------------------------------------------------------------------
78 *------------------------------------------------------------------------*/
79 zWPtr[indexWord( 4, 0 )] = 0;
80 if ( exp == 0x7FFF ) {
81 if ( sig & UINT64_C( 0x7FFFFFFFFFFFFFFF ) ) {
82 softfloat_extF80MToCommonNaN( aSPtr, &commonNaN );
83 softfloat_commonNaNToF128M( &commonNaN, zWPtr );
84 return;
85 }
86 uiZ96 = packToF128UI96( sign, 0x7FFF, 0 );
87 goto uiZ;
88 }
89 /*------------------------------------------------------------------------
90 *------------------------------------------------------------------------*/
91 if ( exp ) --exp;
92 if ( ! (sig & UINT64_C( 0x8000000000000000 )) ) {
93 if ( ! sig ) {
94 uiZ96 = packToF128UI96( sign, 0, 0 );
95 goto uiZ;
96 }
97 exp += softfloat_normExtF80SigM( &sig );
98 }
99 /*------------------------------------------------------------------------
100 *------------------------------------------------------------------------*/
101 zWPtr[indexWord( 4, 1 )] = (uint32_t) sig<<17;
102 sig >>= 15;
103 zWPtr[indexWord( 4, 2 )] = sig;
104 if ( exp < 0 ) {
105 zWPtr[indexWordHi( 4 )] = sig>>32;
106 softfloat_shiftRight96M(
107 &zWPtr[indexMultiwordHi( 4, 3 )],
108 -exp,
109 &zWPtr[indexMultiwordHi( 4, 3 )]
110 );
111 exp = 0;
112 sig = (uint64_t) zWPtr[indexWordHi( 4 )]<<32;
113 }
114 zWPtr[indexWordHi( 4 )] = packToF128UI96( sign, exp, sig>>32 );
115 return;
116 /*------------------------------------------------------------------------
117 *------------------------------------------------------------------------*/
118 uiZ:
119 zWPtr[indexWord( 4, 3 )] = uiZ96;
120 zWPtr[indexWord( 4, 2 )] = 0;
121 zWPtr[indexWord( 4, 1 )] = 0;
122
123 }
124
125 #endif
126
127