VirtualBox

source: vbox/trunk/src/libs/softfloat-3e/source/extF80_roundToInt.c@ 94548

最後變更 在這個檔案從94548是 94548,由 vboxsync 提交於 3 年 前

libs/softfloat-3e: GCC build fixes for the ring-0 library version. bugref:9898

  • 屬性 svn:eol-style 設為 native
檔案大小: 5.6 KB
 
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 "specialize.h"
42#include "softfloat.h"
43#include <iprt/cdefs.h> /* VBox: for RT_FALL_THROUGH */
44
45extFloat80_t
46 extF80_roundToInt( extFloat80_t a, uint_fast8_t roundingMode, bool exact )
47{
48 union { struct extFloat80M s; extFloat80_t f; } uA;
49 uint_fast16_t uiA64, signUI64;
50 int_fast32_t exp;
51 uint_fast64_t sigA;
52 uint_fast16_t uiZ64;
53 uint_fast64_t sigZ;
54 struct exp32_sig64 normExpSig;
55 struct uint128 uiZ;
56 uint_fast64_t lastBitMask, roundBitsMask;
57 union { struct extFloat80M s; extFloat80_t f; } uZ;
58
59 /*------------------------------------------------------------------------
60 *------------------------------------------------------------------------*/
61 uA.f = a;
62 uiA64 = uA.s.signExp;
63 signUI64 = uiA64 & packToExtF80UI64( 1, 0 );
64 exp = expExtF80UI64( uiA64 );
65 sigA = uA.s.signif;
66 /*------------------------------------------------------------------------
67 *------------------------------------------------------------------------*/
68 if ( !(sigA & UINT64_C( 0x8000000000000000 )) && (exp != 0x7FFF) ) {
69 if ( !sigA ) {
70 uiZ64 = signUI64;
71 sigZ = 0;
72 goto uiZ;
73 }
74 normExpSig = softfloat_normSubnormalExtF80Sig( sigA );
75 exp += normExpSig.exp;
76 sigA = normExpSig.sig;
77 }
78 /*------------------------------------------------------------------------
79 *------------------------------------------------------------------------*/
80 if ( 0x403E <= exp ) {
81 if ( exp == 0x7FFF ) {
82 if ( sigA & UINT64_C( 0x7FFFFFFFFFFFFFFF ) ) {
83 uiZ = softfloat_propagateNaNExtF80UI( uiA64, sigA, 0, 0 );
84 uiZ64 = uiZ.v64;
85 sigZ = uiZ.v0;
86 goto uiZ;
87 }
88 sigZ = UINT64_C( 0x8000000000000000 );
89 } else {
90 sigZ = sigA;
91 }
92 uiZ64 = signUI64 | exp;
93 goto uiZ;
94 }
95 if ( exp <= 0x3FFE ) {
96 if ( exact ) softfloat_exceptionFlags |= softfloat_flag_inexact;
97 switch ( roundingMode ) {
98 case softfloat_round_near_even:
99 if ( !(sigA & UINT64_C( 0x7FFFFFFFFFFFFFFF )) ) break;
100 RT_FALL_THROUGH(); /* VBox */
101 case softfloat_round_near_maxMag:
102 if ( exp == 0x3FFE ) goto mag1;
103 break;
104 case softfloat_round_min:
105 if ( signUI64 ) goto mag1;
106 break;
107 case softfloat_round_max:
108 if ( !signUI64 ) goto mag1;
109 break;
110#ifdef SOFTFLOAT_ROUND_ODD
111 case softfloat_round_odd:
112 goto mag1;
113#endif
114 }
115 uiZ64 = signUI64;
116 sigZ = 0;
117 goto uiZ;
118 mag1:
119 uiZ64 = signUI64 | 0x3FFF;
120 sigZ = UINT64_C( 0x8000000000000000 );
121 goto uiZ;
122 }
123 /*------------------------------------------------------------------------
124 *------------------------------------------------------------------------*/
125 uiZ64 = signUI64 | exp;
126 lastBitMask = (uint_fast64_t) 1<<(0x403E - exp);
127 roundBitsMask = lastBitMask - 1;
128 sigZ = sigA;
129 if ( roundingMode == softfloat_round_near_maxMag ) {
130 sigZ += lastBitMask>>1;
131 } else if ( roundingMode == softfloat_round_near_even ) {
132 sigZ += lastBitMask>>1;
133 if ( !(sigZ & roundBitsMask) ) sigZ &= ~lastBitMask;
134 } else if (
135 roundingMode == (signUI64 ? softfloat_round_min : softfloat_round_max)
136 ) {
137 sigZ += roundBitsMask;
138 }
139 sigZ &= ~roundBitsMask;
140 if ( !sigZ ) {
141 ++uiZ64;
142 sigZ = UINT64_C( 0x8000000000000000 );
143 }
144 if ( sigZ != sigA ) {
145#ifdef SOFTFLOAT_ROUND_ODD
146 if ( roundingMode == softfloat_round_odd ) sigZ |= lastBitMask;
147#endif
148 if ( exact ) softfloat_exceptionFlags |= softfloat_flag_inexact;
149 }
150 uiZ:
151 uZ.s.signExp = uiZ64;
152 uZ.s.signif = sigZ;
153 return uZ.f;
154
155}
156
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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