Wire Sysio Wire Sysion 1.0.0
Loading...
Searching...
No Matches
s_subMagsF32.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, 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
45{
46 int_fast16_t expA;
47 uint_fast32_t sigA;
48 int_fast16_t expB;
49 uint_fast32_t sigB;
50 int_fast16_t expDiff;
51 uint_fast32_t uiZ;
52 int_fast32_t sigDiff;
53 bool signZ;
54 int_fast8_t shiftDist;
55 int_fast16_t expZ;
56 uint_fast32_t sigX, sigY;
57 union ui32_f32 uZ;
58
59 /*------------------------------------------------------------------------
60 *------------------------------------------------------------------------*/
61 expA = expF32UI( uiA );
62 sigA = fracF32UI( uiA );
63 expB = expF32UI( uiB );
64 sigB = fracF32UI( uiB );
65 /*------------------------------------------------------------------------
66 *------------------------------------------------------------------------*/
67 expDiff = expA - expB;
68 if ( ! expDiff ) {
69 /*--------------------------------------------------------------------
70 *--------------------------------------------------------------------*/
71 if ( expA == 0xFF ) {
72 if ( sigA | sigB ) goto propagateNaN;
74 uiZ = defaultNaNF32UI;
75 goto uiZ;
76 }
77 sigDiff = sigA - sigB;
78 if ( ! sigDiff ) {
79 uiZ =
82 goto uiZ;
83 }
84 if ( expA ) --expA;
85 signZ = signF32UI( uiA );
86 if ( sigDiff < 0 ) {
87 signZ = ! signZ;
88 sigDiff = -sigDiff;
89 }
90 shiftDist = softfloat_countLeadingZeros32( sigDiff ) - 8;
91 expZ = expA - shiftDist;
92 if ( expZ < 0 ) {
93 shiftDist = expA;
94 expZ = 0;
95 }
96 uiZ = packToF32UI( signZ, expZ, sigDiff<<shiftDist );
97 goto uiZ;
98 } else {
99 /*--------------------------------------------------------------------
100 *--------------------------------------------------------------------*/
101 signZ = signF32UI( uiA );
102 sigA <<= 7;
103 sigB <<= 7;
104 if ( expDiff < 0 ) {
105 /*----------------------------------------------------------------
106 *----------------------------------------------------------------*/
107 signZ = ! signZ;
108 if ( expB == 0xFF ) {
109 if ( sigB ) goto propagateNaN;
110 uiZ = packToF32UI( signZ, 0xFF, 0 );
111 goto uiZ;
112 }
113 expZ = expB - 1;
114 sigX = sigB | 0x40000000;
115 sigY = sigA + (expA ? 0x40000000 : sigA);
116 expDiff = -expDiff;
117 } else {
118 /*----------------------------------------------------------------
119 *----------------------------------------------------------------*/
120 if ( expA == 0xFF ) {
121 if ( sigA ) goto propagateNaN;
122 uiZ = uiA;
123 goto uiZ;
124 }
125 expZ = expA - 1;
126 sigX = sigA | 0x40000000;
127 sigY = sigB + (expB ? 0x40000000 : sigB);
128 }
129 return
131 signZ, expZ, sigX - softfloat_shiftRightJam32( sigY, expDiff )
132 );
133 }
134 /*------------------------------------------------------------------------
135 *------------------------------------------------------------------------*/
136 propagateNaN:
137 uiZ = softfloat_propagateNaNF32UI( uiA, uiB );
138 uiZ:
139 uZ.ui = uiZ;
140 return uZ.f;
141
142}
143
uint_fast32_t softfloat_propagateNaNF32UI(uint_fast32_t uiA, uint_fast32_t uiB)
void softfloat_raiseFlags(uint_fast8_t flags)
#define defaultNaNF32UI
Definition specialize.h:123
#define expF32UI(a)
Definition internals.h:105
#define fracF32UI(a)
Definition internals.h:106
#define signF32UI(a)
Definition internals.h:104
float32_t softfloat_normRoundPackToF32(bool, int_fast16_t, uint_fast32_t)
#define packToF32UI(sign, exp, sig)
Definition internals.h:107
uint32_t softfloat_shiftRightJam32(uint32_t a, uint_fast16_t dist)
THREAD_LOCAL uint_fast8_t softfloat_roundingMode
@ softfloat_flag_invalid
Definition softfloat.h:89
@ softfloat_round_min
Definition softfloat.h:74
#define softfloat_countLeadingZeros32
float32_t softfloat_subMagsF32(uint_fast32_t uiA, uint_fast32_t uiB)
int8_t int_fast8_t
Definition stdint.h:150
uint32_t uint_fast32_t
Definition stdint.h:156
int32_t int_fast32_t
Definition stdint.h:152
int16_t int_fast16_t
Definition stdint.h:151
uint32_t ui
Definition internals.h:46
float32_t f
Definition internals.h:46