VirtualBox

source: vbox/trunk/src/libs/softfloat-3e/source/s_addMagsF32.c

Last change on this file was 94558, checked in by vboxsync, 2 years ago

VMM/IEM,libs/softfloat: Don't use global variables in SoftFloat, pass in a state pointer to (almost) all functions instead. Started on fsqrt instruction implementation. bugref:9898

  • Property svn:eol-style set to native
File size: 4.7 KB
Line 
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
43float32_t softfloat_addMagsF32( uint_fast32_t uiA, uint_fast32_t uiB SOFTFLOAT_STATE_DECL_COMMA )
44{
45 int_fast16_t expA;
46 uint_fast32_t sigA;
47 int_fast16_t expB;
48 uint_fast32_t sigB;
49 int_fast16_t expDiff;
50 uint_fast32_t uiZ;
51 bool signZ;
52 int_fast16_t expZ;
53 uint_fast32_t sigZ;
54 union ui32_f32 uZ;
55
56 /*------------------------------------------------------------------------
57 *------------------------------------------------------------------------*/
58 expA = expF32UI( uiA );
59 sigA = fracF32UI( uiA );
60 expB = expF32UI( uiB );
61 sigB = fracF32UI( uiB );
62 /*------------------------------------------------------------------------
63 *------------------------------------------------------------------------*/
64 expDiff = expA - expB;
65 if ( ! expDiff ) {
66 /*--------------------------------------------------------------------
67 *--------------------------------------------------------------------*/
68 if ( ! expA ) {
69 uiZ = uiA + sigB;
70 goto uiZ;
71 }
72 if ( expA == 0xFF ) {
73 if ( sigA | sigB ) goto propagateNaN;
74 uiZ = uiA;
75 goto uiZ;
76 }
77 signZ = signF32UI( uiA );
78 expZ = expA;
79 sigZ = 0x01000000 + sigA + sigB;
80 if ( ! (sigZ & 1) && (expZ < 0xFE) ) {
81 uiZ = packToF32UI( signZ, expZ, sigZ>>1 );
82 goto uiZ;
83 }
84 sigZ <<= 6;
85 } else {
86 /*--------------------------------------------------------------------
87 *--------------------------------------------------------------------*/
88 signZ = signF32UI( uiA );
89 sigA <<= 6;
90 sigB <<= 6;
91 if ( expDiff < 0 ) {
92 if ( expB == 0xFF ) {
93 if ( sigB ) goto propagateNaN;
94 uiZ = packToF32UI( signZ, 0xFF, 0 );
95 goto uiZ;
96 }
97 expZ = expB;
98 sigA += expA ? 0x20000000 : sigA;
99 sigA = softfloat_shiftRightJam32( sigA, -expDiff );
100 } else {
101 if ( expA == 0xFF ) {
102 if ( sigA ) goto propagateNaN;
103 uiZ = uiA;
104 goto uiZ;
105 }
106 expZ = expA;
107 sigB += expB ? 0x20000000 : sigB;
108 sigB = softfloat_shiftRightJam32( sigB, expDiff );
109 }
110 sigZ = 0x20000000 + sigA + sigB;
111 if ( sigZ < 0x40000000 ) {
112 --expZ;
113 sigZ <<= 1;
114 }
115 }
116 return softfloat_roundPackToF32( signZ, expZ, sigZ SOFTFLOAT_STATE_ARG_COMMA );
117 /*------------------------------------------------------------------------
118 *------------------------------------------------------------------------*/
119 propagateNaN:
120 uiZ = softfloat_propagateNaNF32UI( uiA, uiB SOFTFLOAT_STATE_ARG_COMMA );
121 uiZ:
122 uZ.ui = uiZ;
123 return uZ.f;
124
125}
126
Note: See TracBrowser for help on using the repository browser.

© 2023 Oracle
ContactPrivacy policyTerms of Use