Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
s_roundPackMToF128M.c
Go to the documentation of this file.
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, 2017 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 "softfloat.h"
42
43void
45 bool sign, int32_t exp, uint32_t *extSigPtr, uint32_t *zWPtr )
46{
47 uint_fast8_t roundingMode;
48 bool roundNearEven;
49 uint32_t sigExtra;
50 bool doIncrement, isTiny;
51 static const uint32_t maxSig[4] =
52 INIT_UINTM4( 0x0001FFFF, 0xFFFFFFFF, 0xFFFFFFFF, 0xFFFFFFFF );
53 uint32_t ui, uj;
54
55 /*------------------------------------------------------------------------
56 *------------------------------------------------------------------------*/
57 roundingMode = softfloat_roundingMode;
58 roundNearEven = (roundingMode == softfloat_round_near_even);
59 sigExtra = extSigPtr[indexWordLo( 5 )];
60 doIncrement = (0x80000000 <= sigExtra);
61 if ( ! roundNearEven && (roundingMode != softfloat_round_near_maxMag) ) {
62 doIncrement =
63 (roundingMode
65 && sigExtra;
66 }
67 /*------------------------------------------------------------------------
68 *------------------------------------------------------------------------*/
69 if ( 0x7FFD <= (uint32_t) exp ) {
70 if ( exp < 0 ) {
71 /*----------------------------------------------------------------
72 *----------------------------------------------------------------*/
73 isTiny =
76 || (exp < -1)
77 || ! doIncrement
79 extSigPtr + indexMultiwordHi( 5, 4 ), maxSig )
80 < 0);
81 softfloat_shiftRightJam160M( extSigPtr, -exp, extSigPtr );
82 exp = 0;
83 sigExtra = extSigPtr[indexWordLo( 5 )];
84 if ( isTiny && sigExtra ) {
86 }
87 doIncrement = (0x80000000 <= sigExtra);
88 if (
89 ! roundNearEven
90 && (roundingMode != softfloat_round_near_maxMag)
91 ) {
92 doIncrement =
93 (roundingMode
95 && sigExtra;
96 }
97 } else if (
98 (0x7FFD < exp)
99 || ((exp == 0x7FFD) && doIncrement
101 extSigPtr + indexMultiwordHi( 5, 4 ), maxSig )
102 == 0))
103 ) {
104 /*----------------------------------------------------------------
105 *----------------------------------------------------------------*/
108 if (
109 roundNearEven
110 || (roundingMode == softfloat_round_near_maxMag)
111 || (roundingMode
113 ) {
114 ui = packToF128UI96( sign, 0x7FFF, 0 );
115 uj = 0;
116 } else {
117 ui = packToF128UI96( sign, 0x7FFE, 0x0000FFFF );
118 uj = 0xFFFFFFFF;
119 }
120 zWPtr[indexWordHi( 4 )] = ui;
121 zWPtr[indexWord( 4, 2 )] = uj;
122 zWPtr[indexWord( 4, 1 )] = uj;
123 zWPtr[indexWord( 4, 0 )] = uj;
124 return;
125 }
126 }
127 /*------------------------------------------------------------------------
128 *------------------------------------------------------------------------*/
129 uj = extSigPtr[indexWord( 5, 1 )];
130 if ( sigExtra ) {
132#ifdef SOFTFLOAT_ROUND_ODD
133 if ( roundingMode == softfloat_round_odd ) {
134 uj |= 1;
135 goto noIncrementPackReturn;
136 }
137#endif
138 }
139 if ( doIncrement ) {
140 ++uj;
141 if ( uj ) {
142 if ( ! (sigExtra & 0x7FFFFFFF) && roundNearEven ) uj &= ~1;
143 zWPtr[indexWord( 4, 2 )] = extSigPtr[indexWord( 5, 3 )];
144 zWPtr[indexWord( 4, 1 )] = extSigPtr[indexWord( 5, 2 )];
145 zWPtr[indexWord( 4, 0 )] = uj;
146 ui = extSigPtr[indexWordHi( 5 )];
147 } else {
148 zWPtr[indexWord( 4, 0 )] = uj;
149 ui = extSigPtr[indexWord( 5, 2 )] + 1;
150 zWPtr[indexWord( 4, 1 )] = ui;
151 uj = extSigPtr[indexWord( 5, 3 )];
152 if ( ui ) {
153 zWPtr[indexWord( 4, 2 )] = uj;
154 ui = extSigPtr[indexWordHi( 5 )];
155 } else {
156 ++uj;
157 zWPtr[indexWord( 4, 2 )] = uj;
158 ui = extSigPtr[indexWordHi( 5 )];
159 if ( ! uj ) ++ui;
160 }
161 }
162 } else {
163 noIncrementPackReturn:
164 zWPtr[indexWord( 4, 0 )] = uj;
165 ui = extSigPtr[indexWord( 5, 2 )];
166 zWPtr[indexWord( 4, 1 )] = ui;
167 uj |= ui;
168 ui = extSigPtr[indexWord( 5, 3 )];
169 zWPtr[indexWord( 4, 2 )] = ui;
170 uj |= ui;
171 ui = extSigPtr[indexWordHi( 5 )];
172 uj |= ui;
173 if ( ! uj ) exp = 0;
174 }
175 zWPtr[indexWordHi( 4 )] = packToF128UI96( sign, exp, ui );
176
177}
178
void softfloat_raiseFlags(uint_fast8_t flags)
#define packToF128UI96(sign, exp, sig96)
Definition internals.h:250
#define indexMultiwordHi(total, n)
#define INIT_UINTM4(v3, v2, v1, v0)
#define indexWordLo(total)
#define indexWord(total, n)
#define indexWordHi(total)
int_fast8_t softfloat_compare128M(const uint32_t *aPtr, const uint32_t *bPtr)
#define softfloat_shiftRightJam160M(aPtr, dist, zPtr)
Definition primitives.h:889
THREAD_LOCAL uint_fast8_t softfloat_roundingMode
@ softfloat_flag_inexact
Definition softfloat.h:85
@ softfloat_flag_underflow
Definition softfloat.h:86
@ softfloat_flag_overflow
Definition softfloat.h:87
THREAD_LOCAL uint_fast8_t softfloat_exceptionFlags
THREAD_LOCAL uint_fast8_t softfloat_detectTininess
@ softfloat_round_odd
Definition softfloat.h:77
@ softfloat_round_max
Definition softfloat.h:75
@ softfloat_round_min
Definition softfloat.h:74
@ softfloat_round_near_even
Definition softfloat.h:72
@ softfloat_round_near_maxMag
Definition softfloat.h:76
@ softfloat_tininess_beforeRounding
Definition softfloat.h:62
void softfloat_roundPackMToF128M(bool sign, int32_t exp, uint32_t *extSigPtr, uint32_t *zWPtr)
unsigned int uint32_t
Definition stdint.h:126
signed int int32_t
Definition stdint.h:123
uint8_t uint_fast8_t
Definition stdint.h:154