Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
s_addF128M.c File Reference
#include <stdbool.h>
#include <stdint.h>
#include "platform.h"
#include "internals.h"
#include "specialize.h"
#include "softfloat.h"
Include dependency graph for s_addF128M.c:

Go to the source code of this file.

Functions

void softfloat_addF128M (const uint32_t *aWPtr, const uint32_t *bWPtr, uint32_t *zWPtr, bool negateB)
 

Function Documentation

◆ softfloat_addF128M()

void softfloat_addF128M ( const uint32_t * aWPtr,
const uint32_t * bWPtr,
uint32_t * zWPtr,
bool negateB )

Definition at line 45 of file s_addF128M.c.

51{
52 uint32_t uiA96;
53 int32_t expA;
54 uint32_t uiB96;
55 int32_t expB;
56 uint32_t uiZ96;
57 bool signZ, signB;
58 const uint32_t *tempPtr;
59 uint32_t sig96A, sig96B;
60 int32_t expDiff;
62 (*addCarryMRoutinePtr)(
64 const uint32_t *,
65 const uint32_t *,
67 uint32_t *
68 );
69 uint32_t extSigZ[5], wordSigZ;
70 uint_fast8_t carry;
71 void (*roundPackRoutinePtr)( bool, int32_t, uint32_t *, uint32_t * );
72
73 /*------------------------------------------------------------------------
74 *------------------------------------------------------------------------*/
75 uiA96 = aWPtr[indexWordHi( 4 )];
76 expA = expF128UI96( uiA96 );
77 uiB96 = bWPtr[indexWordHi( 4 )];
78 expB = expF128UI96( uiB96 );
79 /*------------------------------------------------------------------------
80 *------------------------------------------------------------------------*/
81 if ( (expA == 0x7FFF) || (expB == 0x7FFF) ) {
82 if ( softfloat_tryPropagateNaNF128M( aWPtr, bWPtr, zWPtr ) ) return;
83 uiZ96 = uiA96;
84 if ( expB == 0x7FFF ) {
85 uiZ96 = uiB96 ^ packToF128UI96( negateB, 0, 0 );
86 if ( (expA == 0x7FFF) && (uiZ96 != uiA96) ) {
88 return;
89 }
90 }
91 zWPtr[indexWordHi( 4 )] = uiZ96;
92 zWPtr[indexWord( 4, 2 )] = 0;
93 zWPtr[indexWord( 4, 1 )] = 0;
94 zWPtr[indexWord( 4, 0 )] = 0;
95 return;
96 }
97 /*------------------------------------------------------------------------
98 *------------------------------------------------------------------------*/
99 signZ = signF128UI96( uiA96 );
100 signB = signF128UI96( uiB96 ) ^ negateB;
101 negateB = (signZ != signB);
102 if ( (uint32_t) (uiA96<<1) < (uint32_t) (uiB96<<1) ) {
103 signZ = signB;
104 expA = expB;
105 expB = expF128UI96( uiA96 );
106 tempPtr = aWPtr;
107 aWPtr = bWPtr;
108 bWPtr = tempPtr;
109 uiA96 = uiB96;
110 uiB96 = bWPtr[indexWordHi( 4 )];
111 }
112 sig96A = fracF128UI96( uiA96 );
113 sig96B = fracF128UI96( uiB96 );
114 if ( expA ) {
115 --expA;
116 sig96A |= 0x00010000;
117 if ( expB ) {
118 --expB;
119 sig96B |= 0x00010000;
120 }
121 }
122 /*------------------------------------------------------------------------
123 *------------------------------------------------------------------------*/
124 addCarryMRoutinePtr =
126 expDiff = expA - expB;
127 if ( expDiff ) {
128 /*--------------------------------------------------------------------
129 *--------------------------------------------------------------------*/
130 extSigZ[indexWordHi( 5 )] = sig96B;
131 extSigZ[indexWord( 5, 3 )] = bWPtr[indexWord( 4, 2 )];
132 extSigZ[indexWord( 5, 2 )] = bWPtr[indexWord( 4, 1 )];
133 extSigZ[indexWord( 5, 1 )] = bWPtr[indexWord( 4, 0 )];
134 extSigZ[indexWord( 5, 0 )] = 0;
135 softfloat_shiftRightJam160M( extSigZ, expDiff, extSigZ );
136 sig96B = extSigZ[indexWordHi( 5 )];
137 carry = 0;
138 if ( negateB ) {
139 sig96B = ~sig96B;
140 wordSigZ = extSigZ[indexWordLo( 5 )];
141 extSigZ[indexWordLo( 5 )] = -wordSigZ;
142 carry = ! wordSigZ;
143 }
144 carry =
145 (*addCarryMRoutinePtr)(
146 3,
147 &aWPtr[indexMultiwordLo( 4, 3 )],
148 &extSigZ[indexMultiword( 5, 3, 1 )],
149 carry,
150 &extSigZ[indexMultiword( 5, 3, 1 )]
151 );
152 wordSigZ = sig96A + sig96B + carry;
153 } else {
154 /*--------------------------------------------------------------------
155 *--------------------------------------------------------------------*/
156 extSigZ[indexWordLo( 5 )] = 0;
157 carry =
158 (*addCarryMRoutinePtr)(
159 3,
160 &aWPtr[indexMultiwordLo( 4, 3 )],
161 &bWPtr[indexMultiwordLo( 4, 3 )],
162 negateB,
163 &extSigZ[indexMultiword( 5, 3, 1 )]
164 );
165 if ( negateB ) {
166 wordSigZ = sig96A + ~sig96B + carry;
167 if ( wordSigZ & 0x80000000 ) {
168 signZ = ! signZ;
169 carry =
171 &bWPtr[indexMultiwordLo( 4, 3 )],
172 &aWPtr[indexMultiwordLo( 4, 3 )],
173 1,
174 &extSigZ[indexMultiword( 5, 3, 1 )]
175 );
176 wordSigZ = sig96B + ~sig96A + carry;
177 } else {
178 if (
179 ! wordSigZ && ! extSigZ[indexWord( 5, 3 )]
180 && ! ( extSigZ[indexWord( 5, 2 )]
181 | extSigZ[indexWord( 5, 1 )]
182 | extSigZ[indexWord( 5, 0 )]
183 )
184 ) {
186 zWPtr[indexWordHi( 4 )] = packToF128UI96( signZ, 0, 0 );
187 zWPtr[indexWord( 4, 2 )] = 0;
188 zWPtr[indexWord( 4, 1 )] = 0;
189 zWPtr[indexWord( 4, 0 )] = 0;
190 return;
191 }
192 }
193 } else {
194 wordSigZ = sig96A + sig96B + carry;
195 }
196 }
197 extSigZ[indexWordHi( 5 )] = wordSigZ;
198 /*------------------------------------------------------------------------
199 *------------------------------------------------------------------------*/
200 roundPackRoutinePtr = softfloat_normRoundPackMToF128M;
201 if ( 0x00010000 <= wordSigZ ) {
202 if ( 0x00020000 <= wordSigZ ) {
203 ++expA;
204 softfloat_shortShiftRightJam160M( extSigZ, 1, extSigZ );
205 }
206 roundPackRoutinePtr = softfloat_roundPackMToF128M;
207 }
208 (*roundPackRoutinePtr)( signZ, expA, extSigZ, zWPtr );
209
210}
void softfloat_invalidF128M(uint32_t *)
void softfloat_normRoundPackMToF128M(bool, int32_t, uint32_t *, uint32_t *)
#define fracF128UI96(a96)
Definition internals.h:249
void softfloat_roundPackMToF128M(bool, int32_t, uint32_t *, uint32_t *)
#define packToF128UI96(sign, exp, sig96)
Definition internals.h:250
bool softfloat_tryPropagateNaNF128M(const uint32_t *, const uint32_t *, uint32_t *)
#define signF128UI96(a96)
Definition internals.h:247
#define expF128UI96(a96)
Definition internals.h:248
#define indexMultiwordLo(total, n)
#define indexWordLo(total)
#define indexWord(total, n)
#define indexMultiword(total, m, n)
#define indexWordHi(total)
#define softfloat_shiftRightJam160M(aPtr, dist, zPtr)
Definition primitives.h:889
uint_fast8_t softfloat_addCarryM(uint_fast8_t size_words, const uint32_t *aPtr, const uint32_t *bPtr, uint_fast8_t carry, uint32_t *zPtr)
Definition s_addCarryM.c:44
uint_fast8_t softfloat_addComplCarryM(uint_fast8_t size_words, const uint32_t *aPtr, const uint32_t *bPtr, uint_fast8_t carry, uint32_t *zPtr)
#define softfloat_shortShiftRightJam160M(aPtr, dist, zPtr)
Definition primitives.h:814
#define softfloat_addComplCarry96M(aPtr, bPtr, carry, zPtr)
Definition primitives.h:974
THREAD_LOCAL uint_fast8_t softfloat_roundingMode
@ softfloat_round_min
Definition softfloat.h:74
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