Changeset 1d83419 in mainline
- Timestamp:
- 2006-02-24T17:27:19Z (19 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- ba5870d
- Parents:
- a82695c
- Location:
- softfloat
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
softfloat/arch/ia32/include/functions.h
ra82695c r1d83419 46 46 #define float64_to_ulonglong(X) float64_to_uint64(X); 47 47 48 #define int_to_float32(X) int32_to_float32(X); 49 #define long_to_float32(X) int32_to_float32(X); 50 #define longlong_to_float32(X) int64_to_float32(X); 51 52 #define int_to_float64(X) int32_to_float64(X); 53 #define long_to_float64(X) int32_to_float64(X); 54 #define longlong_to_float64(X) int64_to_float64(X); 55 56 #define uint_to_float32(X) uint32_to_float32(X); 57 #define ulong_to_float32(X) uint32_to_float32(X); 58 #define ulonglong_to_float32(X) uint64_to_float32(X); 59 60 #define uint_to_float64(X) uint32_to_float64(X); 61 #define ulong_to_float64(X) uint32_to_float64(X); 62 #define ulonglong_to_float64(X) uint64_to_float64(X); 63 64 65 48 66 #endif -
softfloat/generic/common.c
ra82695c r1d83419 30 30 #include<common.h> 31 31 32 /* Table for fast leading zeroes counting */ 33 char zeroTable[256] = { 34 8, 7, 7, 6, 6, 6, 6, 4, 4, 4, 4, 4, 4, 4, 4, \ 35 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, \ 36 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, \ 37 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, \ 38 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \ 39 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \ 40 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \ 41 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, \ 42 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \ 43 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \ 44 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \ 45 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \ 46 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \ 47 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \ 48 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, \ 49 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 50 }; 51 52 53 32 54 /** Take fraction shifted by 10 bits to left, round it, normalize it and detect exceptions 33 55 * @param exp exponent with bias … … 63 85 cfrac += (0x1 << (64 - FLOAT64_FRACTION_SIZE - 3)); 64 86 65 if (!(cfrac & (FLOAT64_HIDDEN_BIT_MASK << (64 - FLOAT64_ HIDDEN_BIT_MASK- 1)))) {87 if (!(cfrac & (FLOAT64_HIDDEN_BIT_MASK << (64 - FLOAT64_FRACTION_SIZE - 1)))) { 66 88 67 89 result.parts.fraction = ((cfrac >>(64 - FLOAT64_FRACTION_SIZE - 2) ) & (~FLOAT64_HIDDEN_BIT_MASK)); … … 94 116 } 95 117 118 /** Counts leading zeroes in 64bit unsigned integer 119 * @param i 120 */ 121 int countZeroes64(__u64 i) 122 { 123 int j; 124 for (j =0; j < 64; j += 8) { 125 if ( i & (0xFFll << (56 - j))) { 126 return (j + countZeroes8(i >> (56 - j))); 127 } 128 } 129 130 return 64; 131 } 132 133 /** Counts leading zeroes in 32bit unsigned integer 134 * @param i 135 */ 136 int countZeroes32(__u32 i) 137 { 138 int j; 139 for (j =0; j < 32; j += 8) { 140 if ( i & (0xFF << (24 - j))) { 141 return (j + countZeroes8(i >> (24 - j))); 142 } 143 } 144 145 return 32; 146 } 147 148 /** Counts leading zeroes in byte 149 * @param i 150 */ 151 int countZeroes8(__u8 i) 152 { 153 return zeroTable[i]; 154 } 155 156 /** Round and normalize number expressed by exponent and fraction with first bit (equal to hidden bit) at 30. bit 157 * @param exp exponent 158 * @param fraction part with hidden bit shifted to 30. bit 159 */ 160 void roundFloat32(__s32 *exp, __u32 *fraction) 161 { 162 /* rounding - if first bit after fraction is set then round up */ 163 (*fraction) += (0x1 << 6); 164 165 if ((*fraction) & (FLOAT32_HIDDEN_BIT_MASK << 8)) { 166 /* rounding overflow */ 167 ++(*exp); 168 (*fraction) >>= 1; 169 }; 170 171 if (((*exp) >= FLOAT32_MAX_EXPONENT ) || ((*exp) < 0)) { 172 /* overflow - set infinity as result */ 173 (*exp) = FLOAT32_MAX_EXPONENT; 174 (*fraction) = 0; 175 return; 176 } 177 178 return; 179 } 180 181 /** Round and normalize number expressed by exponent and fraction with first bit (equal to hidden bit) at 62. bit 182 * @param exp exponent 183 * @param fraction part with hidden bit shifted to 62. bit 184 */ 185 void roundFloat64(__s32 *exp, __u64 *fraction) 186 { 187 /* rounding - if first bit after fraction is set then round up */ 188 (*fraction) += (0x1 << 9); 189 190 if ((*fraction) & (FLOAT64_HIDDEN_BIT_MASK << 11)) { 191 /* rounding overflow */ 192 ++(*exp); 193 (*fraction) >>= 1; 194 }; 195 196 if (((*exp) >= FLOAT64_MAX_EXPONENT ) || ((*exp) < 0)) { 197 /* overflow - set infinity as result */ 198 (*exp) = FLOAT64_MAX_EXPONENT; 199 (*fraction) = 0; 200 return; 201 } 202 203 return; 204 } 205 -
softfloat/generic/conversion.c
ra82695c r1d83419 30 30 #include "conversion.h" 31 31 #include "comparison.h" 32 #include "common.h" 32 33 33 34 float64 convertFloat32ToFloat64(float32 a) … … 386 387 } 387 388 388 389 390 /** Convert unsigned integer to float32 391 * 392 * 393 */ 394 float32 uint32_to_float32(__u32 i) 395 { 396 int counter; 397 __s32 exp; 398 float32 result; 399 400 result.parts.sign = 0; 401 result.parts.fraction = 0; 402 403 counter = countZeroes32(i); 404 405 exp = FLOAT32_BIAS + 32 - counter - 1; 406 407 if (counter == 32) { 408 result.binary = 0; 409 return result; 410 } 411 412 if (counter > 0) { 413 i <<= counter - 1; 414 } else { 415 i >>= 1; 416 } 417 418 roundFloat32(&exp, &i); 419 420 result.parts.fraction = i >> 7; 421 result.parts.exp = exp; 422 423 return result; 424 } 425 426 float32 int32_to_float32(__s32 i) 427 { 428 float32 result; 429 430 if (i < 0) { 431 result = uint32_to_float32((__u32)(-i)); 432 } else { 433 result = uint32_to_float32((__u32)i); 434 } 435 436 result.parts.sign = i < 0; 437 438 return result; 439 } 440 441 442 float32 uint64_to_float32(__u64 i) 443 { 444 } 445 446 float32 int64_to_float32(__s64 i) 447 { 448 float32 result; 449 450 if (i < 0) { 451 result = uint64_to_float32((__u64)(-i)); 452 } else { 453 result = uint64_to_float32((__u64)i); 454 } 455 456 result.parts.sign = i < 0; 457 458 return result; 459 } -
softfloat/generic/softfloat.c
ra82695c r1d83419 257 257 float __floatsisf(int i) 258 258 { 259 float32 fa; 260 261 fa = int_to_float32(i); 262 return fa.f; 259 263 } 260 264 double __floatsidf(int i) … … 264 268 float __floatdisf(long i) 265 269 { 270 float32 fa; 271 272 fa = long_to_float32(i); 273 return fa.f; 266 274 } 267 275 double __floatdidf(long i) … … 271 279 float __floattisf(long long i) 272 280 { 281 float32 fa; 282 283 fa = longlong_to_float32(i); 284 return fa.f; 273 285 } 274 286 double __floattidf(long long i) … … 278 290 float __floatunsisf(unsigned int i) 279 291 { 292 float32 fa; 293 294 fa = uint_to_float32(i); 295 return fa.f; 280 296 } 281 297 double __floatunsidf(unsigned int i) … … 285 301 float __floatundisf(unsigned long i) 286 302 { 303 float32 fa; 304 305 fa = ulong_to_float32(i); 306 return fa.f; 287 307 } 288 308 double __floatundidf(unsigned long i) … … 292 312 float __floatuntisf(unsigned long long i) 293 313 { 314 float32 fa; 315 316 fa = ulonglong_to_float32(i); 317 return fa.f; 294 318 } 295 319 double __floatuntidf(unsigned long long i) -
softfloat/include/common.h
ra82695c r1d83419 34 34 float64 finishFloat64(__s32 cexp, __u64 cfrac, char sign); 35 35 36 int countZeroes32(__u32 i); 37 int countZeroes8(__u8 i); 38 39 void roundFloat32(__s32 *exp, __u32 *fraction); 40 void roundFloat64(__s32 *exp, __u64 *fraction); 41 36 42 #endif -
softfloat/include/conversion.h
ra82695c r1d83419 36 36 __u32 float32_to_uint32(float32 a); 37 37 __s32 float32_to_int32(float32 a); 38 39 __u64 float32_to_uint64(float32 a); 40 __s64 float32_to_int64(float32 a); 41 38 42 __u64 float64_to_uint64(float64 a); 39 43 __s64 float64_to_int64(float64 a); 40 __u64 float32_to_uint64(float32 a); 41 __s64 float32_to_int64(float32 a); 44 42 45 __u32 float64_to_uint32(float64 a); 43 46 __s32 float64_to_int32(float64 a); 44 47 48 float32 uint32_to_float32(__u32 i); 49 float32 int32_to_float32(__s32 i); 45 50 51 float32 uint64_to_float32(__u64 i); 52 float32 int64_to_float32(__s64 i); 46 53 #endif 47 54
Note:
See TracChangeset
for help on using the changeset viewer.