VirtualBox

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

Last change on this file was 94558, checked in by vboxsync, 3 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: 7.1 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, 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
44 softfloat_roundPackMToF128M(
45 bool sign, int32_t exp, uint32_t *extSigPtr, uint32_t *zWPtr SOFTFLOAT_STATE_DECL_COMMA )
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
64 == (sign ? softfloat_round_min : softfloat_round_max))
65 && sigExtra;
66 }
67 /*------------------------------------------------------------------------
68 *------------------------------------------------------------------------*/
69 if ( 0x7FFD <= (uint32_t) exp ) {
70 if ( exp < 0 ) {
71 /*----------------------------------------------------------------
72 *----------------------------------------------------------------*/
73 isTiny =
74 (softfloat_detectTininess
75 == softfloat_tininess_beforeRounding)
76 || (exp < -1)
77 || ! doIncrement
78 || (softfloat_compare128M(
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 ) {
85 softfloat_raiseFlags( softfloat_flag_underflow SOFTFLOAT_STATE_ARG_COMMA );
86 }
87 doIncrement = (0x80000000 <= sigExtra);
88 if (
89 ! roundNearEven
90 && (roundingMode != softfloat_round_near_maxMag)
91 ) {
92 doIncrement =
93 (roundingMode
94 == (sign ? softfloat_round_min : softfloat_round_max))
95 && sigExtra;
96 }
97 } else if (
98 (0x7FFD < exp)
99 || ((exp == 0x7FFD) && doIncrement
100 && (softfloat_compare128M(
101 extSigPtr + indexMultiwordHi( 5, 4 ), maxSig )
102 == 0))
103 ) {
104 /*----------------------------------------------------------------
105 *----------------------------------------------------------------*/
106 softfloat_raiseFlags(
107 softfloat_flag_overflow | softfloat_flag_inexact
108 SOFTFLOAT_STATE_ARG_COMMA );
109 if (
110 roundNearEven
111 || (roundingMode == softfloat_round_near_maxMag)
112 || (roundingMode
113 == (sign ? softfloat_round_min : softfloat_round_max))
114 ) {
115 ui = packToF128UI96( sign, 0x7FFF, 0 );
116 uj = 0;
117 } else {
118 ui = packToF128UI96( sign, 0x7FFE, 0x0000FFFF );
119 uj = 0xFFFFFFFF;
120 }
121 zWPtr[indexWordHi( 4 )] = ui;
122 zWPtr[indexWord( 4, 2 )] = uj;
123 zWPtr[indexWord( 4, 1 )] = uj;
124 zWPtr[indexWord( 4, 0 )] = uj;
125 return;
126 }
127 }
128 /*------------------------------------------------------------------------
129 *------------------------------------------------------------------------*/
130 uj = extSigPtr[indexWord( 5, 1 )];
131 if ( sigExtra ) {
132 softfloat_exceptionFlags |= softfloat_flag_inexact;
133#ifdef SOFTFLOAT_ROUND_ODD
134 if ( roundingMode == softfloat_round_odd ) {
135 uj |= 1;
136 goto noIncrementPackReturn;
137 }
138#endif
139 }
140 if ( doIncrement ) {
141 ++uj;
142 if ( uj ) {
143 if ( ! (sigExtra & 0x7FFFFFFF) && roundNearEven ) uj &= ~1;
144 zWPtr[indexWord( 4, 2 )] = extSigPtr[indexWord( 5, 3 )];
145 zWPtr[indexWord( 4, 1 )] = extSigPtr[indexWord( 5, 2 )];
146 zWPtr[indexWord( 4, 0 )] = uj;
147 ui = extSigPtr[indexWordHi( 5 )];
148 } else {
149 zWPtr[indexWord( 4, 0 )] = uj;
150 ui = extSigPtr[indexWord( 5, 2 )] + 1;
151 zWPtr[indexWord( 4, 1 )] = ui;
152 uj = extSigPtr[indexWord( 5, 3 )];
153 if ( ui ) {
154 zWPtr[indexWord( 4, 2 )] = uj;
155 ui = extSigPtr[indexWordHi( 5 )];
156 } else {
157 ++uj;
158 zWPtr[indexWord( 4, 2 )] = uj;
159 ui = extSigPtr[indexWordHi( 5 )];
160 if ( ! uj ) ++ui;
161 }
162 }
163 } else {
164 noIncrementPackReturn:
165 zWPtr[indexWord( 4, 0 )] = uj;
166 ui = extSigPtr[indexWord( 5, 2 )];
167 zWPtr[indexWord( 4, 1 )] = ui;
168 uj |= ui;
169 ui = extSigPtr[indexWord( 5, 3 )];
170 zWPtr[indexWord( 4, 2 )] = ui;
171 uj |= ui;
172 ui = extSigPtr[indexWordHi( 5 )];
173 uj |= ui;
174 if ( ! uj ) exp = 0;
175 }
176 zWPtr[indexWordHi( 4 )] = packToF128UI96( sign, exp, ui );
177
178}
179
Note: See TracBrowser for help on using the repository browser.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette