Changeset 90924df in mainline
- Timestamp:
- 2012-04-08T12:08:49Z (13 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- f2b3d3e
- Parents:
- d9f53877 (diff), f3378ba (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the(diff)
links above to see all the changes relative to each parent. - Files:
-
- 3 added
- 11 deleted
- 54 edited
- 5 moved
Legend:
- Unmodified
- Added
- Removed
-
boot/arch/arm32/Makefile.inc
rd9f53877 r90924df 49 49 SOURCES = \ 50 50 arch/$(BARCH)/src/asm.S \ 51 arch/$(BARCH)/src/eabi.S \ 51 52 arch/$(BARCH)/src/main.c \ 52 53 arch/$(BARCH)/src/mm.c \ -
boot/genarch/include/division.h
rd9f53877 r90924df 33 33 #define BOOT_DIVISION_H_ 34 34 35 /* 32bit integer division */36 35 extern int __divsi3(int, int); 37 38 /* 64bit integer division */39 36 extern long long __divdi3(long long, long long); 40 37 41 /* 32bit unsigned integer division */42 38 extern unsigned int __udivsi3(unsigned int, unsigned int); 43 44 /* 64bit unsigned integer division */45 39 extern unsigned long long __udivdi3(unsigned long long, unsigned long long); 46 40 47 /* 32bit remainder of the signed division */48 41 extern int __modsi3(int, int); 49 50 /* 64bit remainder of the signed division */51 42 extern long long __moddi3(long long, long long); 52 43 53 /* 32bit remainder of the unsigned division */54 44 extern unsigned int __umodsi3(unsigned int, unsigned int); 55 56 /* 64bit remainder of the unsigned division */57 45 extern unsigned long long __umoddi3(unsigned long long, unsigned long long); 58 46 47 extern int __divmodsi3(int, int, int *); 48 extern unsigned int __udivmodsi3(unsigned int, unsigned int, unsigned int *); 49 50 extern long long __divmoddi3(long long, long long, long long *); 59 51 extern unsigned long long __udivmoddi3(unsigned long long, unsigned long long, 60 52 unsigned long long *); -
boot/genarch/src/division.c
rd9f53877 r90924df 73 73 { 74 74 unsigned long long result; 75 int steps = sizeof(unsigned long long) * 8; 75 int steps = sizeof(unsigned long long) * 8; 76 76 77 77 *remainder = 0; … … 104 104 105 105 /* 32bit integer division */ 106 int __divsi3(int a, int b) 106 int __divsi3(int a, int b) 107 107 { 108 108 unsigned int rem; … … 116 116 117 117 /* 64bit integer division */ 118 long long __divdi3(long long a, long long b) 118 long long __divdi3(long long a, long long b) 119 119 { 120 120 unsigned long long rem; … … 155 155 156 156 /* 64bit remainder of the signed division */ 157 long long __moddi3(long long a, longlong b)157 long long __moddi3(long long a, long long b) 158 158 { 159 159 unsigned long long rem; … … 183 183 } 184 184 185 int __divmodsi3(int a, int b, int *c) 186 { 187 unsigned int rem; 188 int result = (int) divandmod32(ABSVAL(a), ABSVAL(b), &rem); 189 190 if (SGN(a) == SGN(b)) { 191 *c = rem; 192 return result; 193 } 194 195 *c = -rem; 196 return -result; 197 } 198 199 unsigned int __udivmodsi3(unsigned int a, unsigned int b, 200 unsigned int *c) 201 { 202 return divandmod32(a, b, c); 203 } 204 205 long long __divmoddi3(long long a, long long b, long long *c) 206 { 207 unsigned long long rem; 208 long long result = (int) divandmod64(ABSVAL(a), ABSVAL(b), &rem); 209 210 if (SGN(a) == SGN(b)) { 211 *c = rem; 212 return result; 213 } 214 215 *c = -rem; 216 return -result; 217 } 218 185 219 unsigned long long __udivmoddi3(unsigned long long a, unsigned long long b, 186 220 unsigned long long *c) -
boot/generic/src/str.c
rd9f53877 r90924df 100 100 #include <str.h> 101 101 #include <errno.h> 102 103 /** Check the condition if wchar_t is signed */ 104 #ifdef WCHAR_IS_UNSIGNED 105 #define WCHAR_SIGNED_CHECK(cond) (true) 106 #else 107 #define WCHAR_SIGNED_CHECK(cond) (cond) 108 #endif 102 109 103 110 /** Byte mask consisting of lowest @n bits (out of 8) */ … … 198 205 * code was invalid. 199 206 */ 200 int chr_encode( wchar_t ch, char *str, size_t *offset, size_t size)207 int chr_encode(const wchar_t ch, char *str, size_t *offset, size_t size) 201 208 { 202 209 if (*offset >= size) … … 325 332 bool ascii_check(wchar_t ch) 326 333 { 327 if ( (ch >= 0) && (ch <= 127))334 if (WCHAR_SIGNED_CHECK(ch >= 0) && (ch <= 127)) 328 335 return true; 329 336 … … 338 345 bool chr_check(wchar_t ch) 339 346 { 340 if ( (ch >= 0) && (ch <= 1114111))347 if (WCHAR_SIGNED_CHECK(ch >= 0) && (ch <= 1114111)) 341 348 return true; 342 349 -
kernel/arch/arm32/Makefile.inc
rd9f53877 r90924df 41 41 arch/$(KARCH)/src/start.S \ 42 42 arch/$(KARCH)/src/asm.S \ 43 arch/$(KARCH)/src/eabi.S \ 43 44 arch/$(KARCH)/src/exc_handler.S \ 44 45 arch/$(KARCH)/src/arm32.c \ -
kernel/genarch/include/softint/division.h
rd9f53877 r90924df 36 36 #define KERN_DIVISION_H_ 37 37 38 /* 32bit integer division */ 39 int __divsi3(int a, int b);38 extern int __divsi3(int, int); 39 extern long long __divdi3(long long, long long); 40 40 41 /* 64bit integer division */ 42 long long __divdi3(long long a, long long b);41 extern unsigned int __udivsi3(unsigned int, unsigned int); 42 extern unsigned long long __udivdi3(unsigned long long, unsigned long long); 43 43 44 /* 32bit unsigned integer division */ 45 unsigned int __udivsi3(unsigned int a, unsigned int b);44 extern int __modsi3(int, int); 45 extern long long __moddi3(long long, long long); 46 46 47 /* 64bit unsigned integer division */ 48 unsigned long long __udivdi3(unsigned long long a, unsigned long long b);47 extern unsigned int __umodsi3(unsigned int, unsigned int); 48 extern unsigned long long __umoddi3(unsigned long long, unsigned long long); 49 49 50 /* 32bit remainder of the signed division */ 51 int __modsi3(int a, int b);50 extern int __divmodsi3(int, int, int *); 51 extern unsigned int __udivmodsi3(unsigned int, unsigned int, unsigned int *); 52 52 53 /* 64bit remainder of the signed division */ 54 long long __moddi3(long long a, long long b); 55 56 /* 32bit remainder of the unsigned division */ 57 unsigned int __umodsi3(unsigned int a, unsigned int b); 58 59 /* 64bit remainder of the unsigned division */ 60 unsigned long long __umoddi3(unsigned long long a, unsigned long long b); 61 62 unsigned long long __udivmoddi3(unsigned long long a, unsigned long long b, unsigned long long *c); 53 extern long long __divmoddi3(long long, long long, long long *); 54 extern unsigned long long __udivmoddi3(unsigned long long, unsigned long long, 55 unsigned long long *); 63 56 64 57 #endif -
kernel/genarch/include/softint/multiplication.h
rd9f53877 r90924df 29 29 /** @addtogroup genarch 30 30 * @{ 31 */ 31 */ 32 32 /** 33 33 * @file 34 34 */ 35 35 36 #ifndef __SOFTINT_MULTIPLICATION_H__37 #define __SOFTINT_MULTIPLICATION_H__36 #ifndef KERN_MULTIPLICATION_H_ 37 #define KERN_MULTIPLICATION_H_ 38 38 39 39 /* 64 bit multiplication */ 40 long long __muldi3(long long a, long long b);40 extern long long __muldi3(long long, long long); 41 41 42 42 #endif … … 44 44 /** @} 45 45 */ 46 47 -
kernel/genarch/src/softint/division.c
rd9f53877 r90924df 27 27 */ 28 28 29 /** @addtogroup genarch 29 /** @addtogroup genarch 30 30 * @{ 31 31 */ … … 35 35 #include <genarch/softint/division.h> 36 36 37 #define ABSVAL(x) ((x) > 0 ? (x) : -(x))38 #define SGN(x) ((x) >= 0 ? 1 : 0)39 37 #define ABSVAL(x) ((x) > 0 ? (x) : -(x)) 38 #define SGN(x) ((x) >= 0 ? 1 : 0) 39 40 40 static unsigned int divandmod32(unsigned int a, unsigned int b, 41 41 unsigned int *remainder) … … 56 56 return 0; 57 57 } 58 58 59 59 for (; steps > 0; steps--) { 60 60 /* shift one bit to remainder */ … … 68 68 a <<= 1; 69 69 } 70 70 71 71 return result; 72 72 } 73 74 73 75 74 static unsigned long long divandmod64(unsigned long long a, … … 77 76 { 78 77 unsigned long long result; 79 int steps = sizeof(unsigned long long) * 8; 78 int steps = sizeof(unsigned long long) * 8; 80 79 81 80 *remainder = 0; … … 91 90 return 0; 92 91 } 93 92 94 93 for (; steps > 0; steps--) { 95 94 /* shift one bit to remainder */ … … 103 102 a <<= 1; 104 103 } 105 104 106 105 return result; 107 106 } 108 107 109 108 /* 32bit integer division */ 110 int __divsi3(int a, int b) 111 { 112 unsigned int rem; 113 int result; 114 115 result = (int) divandmod32(ABSVAL(a), ABSVAL(b), &rem); 116 109 int __divsi3(int a, int b) 110 { 111 unsigned int rem; 112 int result = (int) divandmod32(ABSVAL(a), ABSVAL(b), &rem); 113 117 114 if (SGN(a) == SGN(b)) 118 115 return result; 116 119 117 return -result; 120 118 } 121 119 122 120 /* 64bit integer division */ 123 long long __divdi3(long long a, long long b) 124 { 125 unsigned long long rem; 126 long long result; 127 128 result = (long long) divandmod64(ABSVAL(a), ABSVAL(b), &rem); 129 121 long long __divdi3(long long a, long long b) 122 { 123 unsigned long long rem; 124 long long result = (long long) divandmod64(ABSVAL(a), ABSVAL(b), &rem); 125 130 126 if (SGN(a) == SGN(b)) 131 127 return result; 128 132 129 return -result; 133 130 } … … 143 140 unsigned long long __udivdi3(unsigned long long a, unsigned long long b) 144 141 { 145 unsigned long long 142 unsigned long long rem; 146 143 return divandmod64(a, b, &rem); 147 144 } … … 154 151 155 152 /* if divident is negative, remainder must be too */ 156 if (!(SGN(a))) {153 if (!(SGN(a))) 157 154 return -((int) rem); 158 }159 155 160 156 return (int) rem; … … 162 158 163 159 /* 64bit remainder of the signed division */ 164 long long __moddi3(long long a, longlong b)160 long long __moddi3(long long a, long long b) 165 161 { 166 162 unsigned long long rem; … … 168 164 169 165 /* if divident is negative, remainder must be too */ 170 if (!(SGN(a))) {166 if (!(SGN(a))) 171 167 return -((long long) rem); 172 }173 168 174 169 return (long long) rem; … … 191 186 } 192 187 188 int __divmodsi3(int a, int b, int *c) 189 { 190 unsigned int rem; 191 int result = (int) divandmod32(ABSVAL(a), ABSVAL(b), &rem); 192 193 if (SGN(a) == SGN(b)) { 194 *c = rem; 195 return result; 196 } 197 198 *c = -rem; 199 return -result; 200 } 201 202 unsigned int __udivmodsi3(unsigned int a, unsigned int b, 203 unsigned int *c) 204 { 205 return divandmod32(a, b, c); 206 } 207 208 long long __divmoddi3(long long a, long long b, long long *c) 209 { 210 unsigned long long rem; 211 long long result = (int) divandmod64(ABSVAL(a), ABSVAL(b), &rem); 212 213 if (SGN(a) == SGN(b)) { 214 *c = rem; 215 return result; 216 } 217 218 *c = -rem; 219 return -result; 220 } 221 193 222 unsigned long long __udivmoddi3(unsigned long long a, unsigned long long b, 194 223 unsigned long long *c) -
kernel/genarch/src/softint/multiplication.c
rd9f53877 r90924df 29 29 /** @addtogroup genarch 30 30 * @{ 31 */ 31 */ 32 32 /** 33 33 * @file … … 130 130 131 131 return result; 132 } 132 } 133 133 134 134 /** @} -
kernel/generic/src/lib/str.c
rd9f53877 r90924df 111 111 #include <debug.h> 112 112 #include <macros.h> 113 114 /** Check the condition if wchar_t is signed */ 115 #ifdef WCHAR_IS_UNSIGNED 116 #define WCHAR_SIGNED_CHECK(cond) (true) 117 #else 118 #define WCHAR_SIGNED_CHECK(cond) (cond) 119 #endif 113 120 114 121 /** Byte mask consisting of lowest @n bits (out of 8) */ … … 206 213 * 207 214 * @return EOK if the character was encoded successfully, EOVERFLOW if there 208 * 209 * 210 */ 211 int chr_encode( wchar_t ch, char *str, size_t *offset, size_t size)215 * was not enough space in the output buffer or EINVAL if the character 216 * code was invalid. 217 */ 218 int chr_encode(const wchar_t ch, char *str, size_t *offset, size_t size) 212 219 { 213 220 if (*offset >= size) … … 427 434 bool ascii_check(wchar_t ch) 428 435 { 429 if ( (ch >= 0) && (ch <= 127))436 if (WCHAR_SIGNED_CHECK(ch >= 0) && (ch <= 127)) 430 437 return true; 431 438 … … 440 447 bool chr_check(wchar_t ch) 441 448 { 442 if ( (ch >= 0) && (ch <= 1114111))449 if (WCHAR_SIGNED_CHECK(ch >= 0) && (ch <= 1114111)) 443 450 return true; 444 451 -
tools/autotool.py
rd9f53877 r90924df 49 49 50 50 PACKAGE_BINUTILS = "usually part of binutils" 51 PACKAGE_GCC = "preferably version 4. 5.1or newer"51 PACKAGE_GCC = "preferably version 4.7.0 or newer" 52 52 PACKAGE_CROSS = "use tools/toolchain.sh to build the cross-compiler toolchain" 53 53 … … 66 66 67 67 #define DECLARE_BUILTIN_TYPE(tag, type) \\ 68 AUTOTOOL_DECLARE("builtin", "", tag, STRING(type), "", "", sizeof(type)); 68 AUTOTOOL_DECLARE("builtin_size", "", tag, STRING(type), "", "", sizeof(type)); \\ 69 AUTOTOOL_DECLARE("builtin_sign", "unsigned long long int", tag, STRING(type), "unsigned", "", __builtin_types_compatible_p(type, unsigned long long int)); \\ 70 AUTOTOOL_DECLARE("builtin_sign", "unsigned long int", tag, STRING(type), "unsigned", "", __builtin_types_compatible_p(type, unsigned long int)); \\ 71 AUTOTOOL_DECLARE("builtin_sign", "unsigned int", tag, STRING(type), "unsigned", "", __builtin_types_compatible_p(type, unsigned int)); \\ 72 AUTOTOOL_DECLARE("builtin_sign", "unsigned short int", tag, STRING(type), "unsigned", "", __builtin_types_compatible_p(type, unsigned short int)); \\ 73 AUTOTOOL_DECLARE("builtin_sign", "unsigned char", tag, STRING(type), "unsigned", "", __builtin_types_compatible_p(type, unsigned char)); \\ 74 AUTOTOOL_DECLARE("builtin_sign", "signed long long int", tag, STRING(type), "signed", "", __builtin_types_compatible_p(type, signed long long int)); \\ 75 AUTOTOOL_DECLARE("builtin_sign", "signed long int", tag, STRING(type), "signed", "", __builtin_types_compatible_p(type, signed long int)); \\ 76 AUTOTOOL_DECLARE("builtin_sign", "signed int", tag, STRING(type), "signed", "", __builtin_types_compatible_p(type, signed int)); \\ 77 AUTOTOOL_DECLARE("builtin_sign", "signed short int", tag, STRING(type), "signed", "", __builtin_types_compatible_p(type, signed short int)); \\ 78 AUTOTOOL_DECLARE("builtin_sign", "signed char", tag, STRING(type), "signed", "", __builtin_types_compatible_p(type, signed char)); 69 79 70 80 #define DECLARE_INTSIZE(tag, type, strc, conc) \\ 71 81 AUTOTOOL_DECLARE("intsize", "unsigned", tag, #type, strc, conc, sizeof(unsigned type)); \\ 72 82 AUTOTOOL_DECLARE("intsize", "signed", tag, #type, strc, conc, sizeof(signed type)); 83 84 #define DECLARE_FLOATSIZE(tag, type) \\ 85 AUTOTOOL_DECLARE("floatsize", "", tag, #type, "", "", sizeof(type)); 73 86 74 87 int main(int argc, char *argv[]) … … 262 275 return int(value, base) 263 276 264 def probe_compiler(common, sizes):277 def probe_compiler(common, intsizes, floatsizes): 265 278 "Generate, compile and parse probing source" 266 279 … … 270 283 outf.write(PROBE_HEAD) 271 284 272 for typedef in sizes:285 for typedef in intsizes: 273 286 outf.write("\tDECLARE_INTSIZE(\"%s\", %s, %s, %s);\n" % (typedef['tag'], typedef['type'], typedef['strc'], typedef['conc'])) 287 288 for typedef in floatsizes: 289 outf.write("\nDECLARE_FLOATSIZE(\"%s\", %s);\n" % (typedef['tag'], typedef['type'])) 274 290 275 291 outf.write(PROBE_TAIL) … … 315 331 signed_concs = {} 316 332 317 builtins = {} 333 float_tags = {} 334 335 builtin_sizes = {} 336 builtin_signs = {} 318 337 319 338 for j in range(len(lines)): … … 352 371 print_error(["Unexpected keyword \"%s\" in \"%s\" on line %s." % (subcategory, PROBE_OUTPUT, j), COMPILER_FAIL]) 353 372 354 if (category == " builtin"):373 if (category == "floatsize"): 355 374 try: 356 375 value_int = decode_value(value) … … 358 377 print_error(["Integer value expected in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL]) 359 378 360 builtins[tag] = {'name': name, 'value': value_int} 361 362 return {'unsigned_sizes': unsigned_sizes, 'signed_sizes': signed_sizes, 'unsigned_tags': unsigned_tags, 'signed_tags': signed_tags, 'unsigned_strcs': unsigned_strcs, 'signed_strcs': signed_strcs, 'unsigned_concs': unsigned_concs, 'signed_concs': signed_concs, 'builtins': builtins} 363 364 def detect_uints(probe, bytes, tags): 365 "Detect correct types for fixed-size integer types" 379 float_tags[tag] = value_int 380 381 if (category == "builtin_size"): 382 try: 383 value_int = decode_value(value) 384 except: 385 print_error(["Integer value expected in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL]) 386 387 builtin_sizes[tag] = {'name': name, 'value': value_int} 388 389 if (category == "builtin_sign"): 390 try: 391 value_int = decode_value(value) 392 except: 393 print_error(["Integer value expected in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL]) 394 395 if (value_int == 1): 396 if (not tag in builtin_signs): 397 builtin_signs[tag] = strc; 398 elif (builtin_signs[tag] != strc): 399 print_error(["Inconsistent builtin type detection in \"%s\" on line %s." % (PROBE_OUTPUT, j), COMPILER_FAIL]) 400 401 return {'unsigned_sizes': unsigned_sizes, 'signed_sizes': signed_sizes, 'unsigned_tags': unsigned_tags, 'signed_tags': signed_tags, 'unsigned_strcs': unsigned_strcs, 'signed_strcs': signed_strcs, 'unsigned_concs': unsigned_concs, 'signed_concs': signed_concs, 'float_tags': float_tags, 'builtin_sizes': builtin_sizes, 'builtin_signs': builtin_signs} 402 403 def detect_sizes(probe, bytes, inttags, floattags): 404 "Detect correct types for fixed-size types" 366 405 367 406 macros = [] … … 370 409 for b in bytes: 371 410 if (not b in probe['unsigned_sizes']): 372 print_error(['Unable to find appropriate unsigned integer type for %u bytes ' % b,411 print_error(['Unable to find appropriate unsigned integer type for %u bytes.' % b, 373 412 COMPILER_FAIL]) 374 413 375 414 if (not b in probe['signed_sizes']): 376 print_error(['Unable to find appropriate signed integer type for %u bytes ' % b,415 print_error(['Unable to find appropriate signed integer type for %u bytes.' % b, 377 416 COMPILER_FAIL]) 378 417 379 418 if (not b in probe['unsigned_strcs']): 380 print_error(['Unable to find appropriate unsigned printf formatter for %u bytes ' % b,419 print_error(['Unable to find appropriate unsigned printf formatter for %u bytes.' % b, 381 420 COMPILER_FAIL]) 382 421 383 422 if (not b in probe['signed_strcs']): 384 print_error(['Unable to find appropriate signed printf formatter for %u bytes ' % b,423 print_error(['Unable to find appropriate signed printf formatter for %u bytes.' % b, 385 424 COMPILER_FAIL]) 386 425 387 426 if (not b in probe['unsigned_concs']): 388 print_error(['Unable to find appropriate unsigned literal macro for %u bytes ' % b,427 print_error(['Unable to find appropriate unsigned literal macro for %u bytes.' % b, 389 428 COMPILER_FAIL]) 390 429 391 430 if (not b in probe['signed_concs']): 392 print_error(['Unable to find appropriate signed literal macro for %u bytes ' % b,431 print_error(['Unable to find appropriate signed literal macro for %u bytes.' % b, 393 432 COMPILER_FAIL]) 394 433 … … 417 456 macros.append({'oldmacro': "c ## %s" % name, 'newmacro': "INT%u_C(c)" % (b * 8)}) 418 457 419 for tag in tags:458 for tag in inttags: 420 459 newmacro = "U%s" % tag 421 460 if (not tag in probe['unsigned_tags']): 422 print_error(['Unable to find appropriate size macro for %s ' % newmacro,461 print_error(['Unable to find appropriate size macro for %s.' % newmacro, 423 462 COMPILER_FAIL]) 424 463 … … 426 465 macros.append({'oldmacro': "%s_MIN" % oldmacro, 'newmacro': "%s_MIN" % newmacro}) 427 466 macros.append({'oldmacro': "%s_MAX" % oldmacro, 'newmacro': "%s_MAX" % newmacro}) 467 macros.append({'oldmacro': "1", 'newmacro': 'U%s_SIZE_%s' % (tag, probe['unsigned_tags'][tag] * 8)}) 428 468 429 469 newmacro = tag 430 if (not tag in probe[' unsigned_tags']):470 if (not tag in probe['signed_tags']): 431 471 print_error(['Unable to find appropriate size macro for %s' % newmacro, 432 472 COMPILER_FAIL]) … … 435 475 macros.append({'oldmacro': "%s_MIN" % oldmacro, 'newmacro': "%s_MIN" % newmacro}) 436 476 macros.append({'oldmacro': "%s_MAX" % oldmacro, 'newmacro': "%s_MAX" % newmacro}) 477 macros.append({'oldmacro': "1", 'newmacro': '%s_SIZE_%s' % (tag, probe['signed_tags'][tag] * 8)}) 478 479 for tag in floattags: 480 if (not tag in probe['float_tags']): 481 print_error(['Unable to find appropriate size macro for %s' % tag, 482 COMPILER_FAIL]) 483 484 macros.append({'oldmacro': "1", 'newmacro': '%s_SIZE_%s' % (tag, probe['float_tags'][tag] * 8)}) 485 486 if (not 'size' in probe['builtin_signs']): 487 print_error(['Unable to determine whether size_t is signed or unsigned.', 488 COMPILER_FAIL]) 489 490 if (probe['builtin_signs']['size'] != 'unsigned'): 491 print_error(['The type size_t is not unsigned.', 492 COMPILER_FAIL]) 437 493 438 494 fnd = True 439 495 440 if (not 'wchar' in probe['builtin s']):496 if (not 'wchar' in probe['builtin_sizes']): 441 497 print_warning(['The compiler does not provide the macro __WCHAR_TYPE__', 442 498 'for defining the compiler-native type wchar_t. We are', … … 445 501 fnd = False 446 502 447 if (probe['builtin s']['wchar']['value'] != 4):503 if (probe['builtin_sizes']['wchar']['value'] != 4): 448 504 print_warning(['The compiler provided macro __WCHAR_TYPE__ for defining', 449 505 'the compiler-native type wchar_t is not compliant with', … … 458 514 macros.append({'oldmacro': "__WCHAR_TYPE__", 'newmacro': "wchar_t"}) 459 515 516 if (not 'wchar' in probe['builtin_signs']): 517 print_error(['Unable to determine whether wchar_t is signed or unsigned.', 518 COMPILER_FAIL]) 519 520 if (probe['builtin_signs']['wchar'] == 'unsigned'): 521 macros.append({'oldmacro': "1", 'newmacro': 'WCHAR_IS_UNSIGNED'}) 522 if (probe['builtin_signs']['wchar'] == 'signed'): 523 macros.append({'oldmacro': "1", 'newmacro': 'WCHAR_IS_SIGNED'}) 524 460 525 fnd = True 461 526 462 if (not 'wint' in probe['builtin s']):527 if (not 'wint' in probe['builtin_sizes']): 463 528 print_warning(['The compiler does not provide the macro __WINT_TYPE__', 464 529 'for defining the compiler-native type wint_t. We are', … … 467 532 fnd = False 468 533 469 if (probe['builtin s']['wint']['value'] != 4):534 if (probe['builtin_sizes']['wint']['value'] != 4): 470 535 print_warning(['The compiler provided macro __WINT_TYPE__ for defining', 471 536 'the compiler-native type wint_t is not compliant with', … … 479 544 else: 480 545 macros.append({'oldmacro': "__WINT_TYPE__", 'newmacro': "wint_t"}) 546 547 if (not 'wint' in probe['builtin_signs']): 548 print_error(['Unable to determine whether wint_t is signed or unsigned.', 549 COMPILER_FAIL]) 550 551 if (probe['builtin_signs']['wint'] == 'unsigned'): 552 macros.append({'oldmacro': "1", 'newmacro': 'WINT_IS_UNSIGNED'}) 553 if (probe['builtin_signs']['wint'] == 'signed'): 554 macros.append({'oldmacro': "1", 'newmacro': 'WINT_IS_SIGNED'}) 481 555 482 556 return {'macros': macros, 'typedefs': typedefs} … … 571 645 572 646 if (config['CROSS_TARGET'] == "arm32"): 573 gnu_target = "arm-linux-gnu "647 gnu_target = "arm-linux-gnueabi" 574 648 575 649 if (config['CROSS_TARGET'] == "ia32"): … … 586 660 if (config['PLATFORM'] == "arm32"): 587 661 target = config['PLATFORM'] 588 gnu_target = "arm-linux-gnu "662 gnu_target = "arm-linux-gnueabi" 589 663 590 664 if (config['PLATFORM'] == "ia32"): … … 669 743 {'type': 'short int', 'tag': 'SHORT', 'strc': '"h"', 'conc': '"@"'}, 670 744 {'type': 'char', 'tag': 'CHAR', 'strc': '"hh"', 'conc': '"@@"'} 745 ], 746 [ 747 {'type': 'long double', 'tag': 'LONG_DOUBLE'}, 748 {'type': 'double', 'tag': 'DOUBLE'}, 749 {'type': 'float', 'tag': 'FLOAT'} 671 750 ] 672 751 ) 673 752 674 maps = detect_ uints(probe, [1, 2, 4, 8], ['CHAR', 'SHORT', 'INT', 'LONG', 'LLONG'])753 maps = detect_sizes(probe, [1, 2, 4, 8], ['CHAR', 'SHORT', 'INT', 'LONG', 'LLONG'], ['LONG_DOUBLE', 'DOUBLE', 'FLOAT']) 675 754 676 755 finally: -
tools/toolchain.sh
rd9f53877 r90924df 55 55 BINUTILS_VERSION="2.22" 56 56 BINUTILS_RELEASE="" 57 GCC_VERSION="4. 6.3"57 GCC_VERSION="4.7.0" 58 58 GDB_VERSION="7.4" 59 59 60 60 BASEDIR="`pwd`" 61 61 BINUTILS="binutils-${BINUTILS_VERSION}${BINUTILS_RELEASE}.tar.bz2" 62 GCC_CORE="gcc-core-${GCC_VERSION}.tar.bz2" 63 GCC_OBJC="gcc-objc-${GCC_VERSION}.tar.bz2" 64 GCC_CPP="gcc-g++-${GCC_VERSION}.tar.bz2" 62 GCC="gcc-${GCC_VERSION}.tar.bz2" 65 63 GDB="gdb-${GDB_VERSION}.tar.bz2" 66 64 … … 275 273 276 274 download_fetch "${BINUTILS_SOURCE}" "${BINUTILS}" "ee0f10756c84979622b992a4a61ea3f5" 277 download_fetch "${GCC_SOURCE}" "${GCC_CORE}" "766091220c6a14fcaa2c06dd573e3758" 278 download_fetch "${GCC_SOURCE}" "${GCC_OBJC}" "48ba23770c34b1cb468f72618b4452c5" 279 download_fetch "${GCC_SOURCE}" "${GCC_CPP}" "37515158a0fb3d0800ec41a08c05e69e" 275 download_fetch "${GCC_SOURCE}" "${GCC}" "2a0f1d99fda235c29d40b561f81d9a77" 280 276 download_fetch "${GDB_SOURCE}" "${GDB}" "95a9a8305fed4d30a30a6dc28ff9d060" 281 277 } … … 299 295 echo ">>> Downloading tarballs" 300 296 source_check "${BASEDIR}/${BINUTILS}" 301 source_check "${BASEDIR}/${GCC_CORE}" 302 source_check "${BASEDIR}/${GCC_OBJC}" 303 source_check "${BASEDIR}/${GCC_CPP}" 297 source_check "${BASEDIR}/${GCC}" 304 298 source_check "${BASEDIR}/${GDB}" 305 299 … … 316 310 317 311 unpack_tarball "${BASEDIR}/${BINUTILS}" "binutils" 318 unpack_tarball "${BASEDIR}/${GCC_CORE}" "GCC Core" 319 unpack_tarball "${BASEDIR}/${GCC_OBJC}" "Objective C" 320 unpack_tarball "${BASEDIR}/${GCC_CPP}" "C++" 312 unpack_tarball "${BASEDIR}/${GCC}" "GCC" 321 313 unpack_tarball "${BASEDIR}/${GDB}" "GDB" 322 314 … … 378 370 "arm32") 379 371 prepare 380 build_target "arm32" "arm-linux-gnu "372 build_target "arm32" "arm-linux-gnueabi" 381 373 ;; 382 374 "ia32") … … 415 407 prepare 416 408 build_target "amd64" "amd64-linux-gnu" 417 build_target "arm32" "arm-linux-gnu "409 build_target "arm32" "arm-linux-gnueabi" 418 410 build_target "ia32" "i686-pc-linux-gnu" 419 411 build_target "ia64" "ia64-pc-linux-gnu" … … 428 420 prepare 429 421 build_target "amd64" "amd64-linux-gnu" & 430 build_target "arm32" "arm-linux-gnu " &422 build_target "arm32" "arm-linux-gnueabi" & 431 423 build_target "ia32" "i686-pc-linux-gnu" & 432 424 build_target "ia64" "ia64-pc-linux-gnu" & -
uspace/Makefile.common
rd9f53877 r90924df 149 149 endif 150 150 151 ifeq ($(STATIC_BUILD), 152 BASE_LIBS = $(LIBC_PREFIX)/libc.a $(LIBSOFTINT_PREFIX)/libsoftint.a153 LINKER_SCRIPT ?= $(LIBC_PREFIX)/arch/$(UARCH)/_link.ld154 else 155 BASE_LIBS = $(LIBC_PREFIX)/libc.so0 $(LIBSOFTINT_PREFIX)/libsofti.so0156 LFLAGS = -Bdynamic157 LINKER_SCRIPT ?= $(LIBC_PREFIX)/arch/$(UARCH)/_link-dlexe.ld151 ifeq ($(STATIC_BUILD),y) 152 BASE_LIBS = $(LIBC_PREFIX)/libc.a $(LIBSOFTINT_PREFIX)/libsoftint.a 153 LINKER_SCRIPT ?= $(LIBC_PREFIX)/arch/$(UARCH)/_link.ld 154 else 155 BASE_LIBS = $(LIBC_PREFIX)/libc.so0 $(LIBSOFTINT_PREFIX)/libsofti.so0 156 LFLAGS = -Bdynamic 157 LINKER_SCRIPT ?= $(LIBC_PREFIX)/arch/$(UARCH)/_link-dlexe.ld 158 158 endif 159 159 -
uspace/app/binutils/Makefile
rd9f53877 r90924df 112 112 endif 113 113 ifeq ($(PLATFORM),arm32) 114 TARGET = arm-linux-gnu 114 TARGET = arm-linux-gnueabi 115 115 endif 116 116 ifeq ($(PLATFORM),ia32) -
uspace/app/sbi/src/run_texpr.c
rd9f53877 r90924df 98 98 { 99 99 stree_symbol_t *sym; 100 tdata_item_t *targ_i ;101 tdata_item_t *titem ;100 tdata_item_t *targ_i = NULL; 101 tdata_item_t *titem = NULL;; 102 102 tdata_object_t *tobject; 103 103 tdata_deleg_t *tdeleg; … … 139 139 return; 140 140 } 141 142 /* Make compiler happy. */143 titem = NULL;144 141 145 142 switch (sym->sc) { … … 222 219 stree_tindex_t *tindex, tdata_item_t **res) 223 220 { 224 tdata_item_t *base_ti ;221 tdata_item_t *base_ti = NULL; 225 222 tdata_item_t *titem; 226 223 tdata_array_t *tarray; -
uspace/app/tester/fault/fault2.c
rd9f53877 r90924df 35 35 const char *test_fault2(void) 36 36 { 37 volatile long long var; 38 volatile int var1; 39 40 var1 = *((aliasing_int *) (((char *) (&var)) + 1)); 37 volatile long long var = 0; 38 volatile int var1 = *((aliasing_int *) (((char *) (&var)) + 1)); 41 39 printf("Read %d\n", var1); 42 40 -
uspace/drv/bus/usb/ehci/Makefile
rd9f53877 r90924df 43 43 SOURCES = \ 44 44 main.c \ 45 pci.c45 res.c 46 46 47 47 include $(USPACE_PREFIX)/Makefile.common -
uspace/drv/bus/usb/ehci/main.c
rd9f53877 r90924df 44 44 #include <usb/host/hcd.h> 45 45 46 #include " pci.h"46 #include "res.h" 47 47 48 48 #define NAME "ehci" … … 81 81 int irq = 0; 82 82 83 int ret = pci_get_my_registers(device, ®_base, ®_size, &irq);83 int ret = get_my_registers(device, ®_base, ®_size, &irq); 84 84 CHECK_RET_RETURN(ret, 85 85 "Failed to get memory addresses for %" PRIun ": %s.\n", … … 88 88 reg_base, reg_size, irq); 89 89 90 ret = pci_disable_legacy(device, reg_base, reg_size, irq);90 ret = disable_legacy(device, reg_base, reg_size); 91 91 CHECK_RET_RETURN(ret, 92 92 "Failed to disable legacy USB: %s.\n", str_error(ret)); -
uspace/drv/bus/usb/ehci/res.h
rd9f53877 r90924df 38 38 #include <ddf/driver.h> 39 39 40 int pci_get_my_registers(const ddf_dev_t *, uintptr_t *, size_t *, int *);41 int pci_enable_interrupts(const ddf_dev_t *);42 int pci_disable_legacy(const ddf_dev_t *, uintptr_t, size_t, int);40 int get_my_registers(const ddf_dev_t *, uintptr_t *, size_t *, int *); 41 int enable_interrupts(const ddf_dev_t *); 42 int disable_legacy(const ddf_dev_t *, uintptr_t, size_t); 43 43 44 44 #endif -
uspace/drv/bus/usb/ohci/Makefile
rd9f53877 r90924df 50 50 ohci_batch.c \ 51 51 ohci_endpoint.c \ 52 pci.c \52 res.c \ 53 53 root_hub.c \ 54 54 hw_struct/endpoint_descriptor.c \ -
uspace/drv/bus/usb/ohci/hw_struct/hcca.h
rd9f53877 r90924df 46 46 uint16_t pad1; 47 47 uint32_t done_head; 48 uint32_t reserved[ 29];49 } __attribute__((packed, aligned))hcca_t;48 uint32_t reserved[30]; 49 } hcca_t; 50 50 51 51 static inline void * hcca_get(void) -
uspace/drv/bus/usb/ohci/ohci.c
rd9f53877 r90924df 42 42 43 43 #include "ohci.h" 44 #include " pci.h"44 #include "res.h" 45 45 #include "hc.h" 46 46 … … 180 180 int irq = 0; 181 181 182 ret = pci_get_my_registers(device, ®_base, ®_size, &irq);182 ret = get_my_registers(device, ®_base, ®_size, &irq); 183 183 CHECK_RET_DEST_FREE_RETURN(ret, 184 184 "Failed to get register memory addresses for %" PRIun ": %s.\n", … … 211 211 /* Try to enable interrupts */ 212 212 bool interrupts = false; 213 ret = pci_enable_interrupts(device);213 ret = enable_interrupts(device); 214 214 if (ret != EOK) { 215 215 usb_log_warning("Failed to enable interrupts: %s." -
uspace/drv/bus/usb/ohci/res.c
rd9f53877 r90924df 38 38 #include <errno.h> 39 39 #include <assert.h> 40 #include <as.h>41 40 #include <devman.h> 42 #include <ddi.h>43 #include <libarch/ddi.h>44 41 #include <device/hw_res_parsed.h> 45 42 46 43 #include <usb/debug.h> 47 #include <pci_dev_iface.h>48 44 49 #include " pci.h"45 #include "res.h" 50 46 51 47 /** Get address of registers and IRQ for given device. … … 57 53 * @return Error code. 58 54 */ 59 int pci_get_my_registers(ddf_dev_t *dev,55 int get_my_registers(const ddf_dev_t *dev, 60 56 uintptr_t *mem_reg_address, size_t *mem_reg_size, int *irq_no) 61 57 { … … 98 94 * @return Error code. 99 95 */ 100 int pci_enable_interrupts(ddf_dev_t *device)96 int enable_interrupts(const ddf_dev_t *device) 101 97 { 102 98 async_sess_t *parent_sess = … … 106 102 return ENOMEM; 107 103 108 bool enabled = hw_res_enable_interrupt(parent_sess);104 const bool enabled = hw_res_enable_interrupt(parent_sess); 109 105 async_hangup(parent_sess); 110 106 -
uspace/drv/bus/usb/ohci/res.h
rd9f53877 r90924df 32 32 * PCI related functions needed by OHCI driver. 33 33 */ 34 #ifndef DRV_OHCI_ PCI_H35 #define DRV_OHCI_ PCI_H34 #ifndef DRV_OHCI_RES_H 35 #define DRV_OHCI_RES_H 36 36 37 37 #include <ddf/driver.h> 38 38 39 int pci_get_my_registers(ddf_dev_t *, uintptr_t *, size_t *, int *); 40 int pci_enable_interrupts(ddf_dev_t *); 41 int pci_disable_legacy(ddf_dev_t *); 39 int get_my_registers(const ddf_dev_t *, uintptr_t *, size_t *, int *); 40 int enable_interrupts(const ddf_dev_t *); 42 41 43 42 #endif -
uspace/drv/bus/usb/uhci/Makefile
rd9f53877 r90924df 44 44 hc.c \ 45 45 main.c \ 46 pci.c \46 res.c \ 47 47 root_hub.c \ 48 48 transfer_list.c \ -
uspace/drv/bus/usb/uhci/res.c
rd9f53877 r90924df 39 39 #include <devman.h> 40 40 #include <device/hw_res_parsed.h> 41 #include <device/pci.h> 41 42 42 #include <usb/debug.h> 43 #include <pci_dev_iface.h> 44 45 #include "pci.h" 43 #include "res.h" 46 44 47 45 /** Get I/O address of registers and IRQ for given device. … … 53 51 * @return Error code. 54 52 */ 55 int pci_get_my_registers(const ddf_dev_t *dev,53 int get_my_registers(const ddf_dev_t *dev, 56 54 uintptr_t *io_reg_address, size_t *io_reg_size, int *irq_no) 57 55 { 58 56 assert(dev); 59 assert(io_reg_address);60 assert(io_reg_size);61 assert(irq_no);62 57 63 58 async_sess_t *parent_sess = … … 97 92 * @return Error code. 98 93 */ 99 int pci_enable_interrupts(const ddf_dev_t *device)94 int enable_interrupts(const ddf_dev_t *device) 100 95 { 101 96 async_sess_t *parent_sess = … … 116 111 * @return Error code. 117 112 */ 118 int pci_disable_legacy(const ddf_dev_t *device)113 int disable_legacy(const ddf_dev_t *device) 119 114 { 120 115 assert(device); 121 116 122 async_sess_t *parent_sess = 123 devman_parent_device_connect(EXCHANGE_SERIALIZE, device->handle, 124 IPC_FLAG_BLOCKING); 117 async_sess_t *parent_sess = devman_parent_device_connect( 118 EXCHANGE_SERIALIZE, device->handle, IPC_FLAG_BLOCKING); 125 119 if (!parent_sess) 126 120 return ENOMEM; 127 121 128 /* See UHCI design guide for these values p.45, 129 * write all WC bits in USB legacy register */ 130 const sysarg_t address = 0xc0; 131 const sysarg_t value = 0xaf00; 122 /* See UHCI design guide page 45 for these values. 123 * Write all WC bits in USB legacy register */ 124 const int rc = pci_config_space_write_16(parent_sess, 0xc0, 0xaf00); 132 125 133 async_exch_t *exch = async_exchange_begin(parent_sess);134 135 const int rc = async_req_3_0(exch, DEV_IFACE_ID(PCI_DEV_IFACE),136 IPC_M_CONFIG_SPACE_WRITE_16, address, value);137 138 async_exchange_end(exch);139 126 async_hangup(parent_sess); 140 141 127 return rc; 142 128 } -
uspace/drv/bus/usb/uhci/res.h
rd9f53877 r90924df 38 38 #include <ddf/driver.h> 39 39 40 int pci_get_my_registers(const ddf_dev_t *, uintptr_t *, size_t *, int *);41 int pci_enable_interrupts(const ddf_dev_t *);42 int pci_disable_legacy(const ddf_dev_t *);40 int get_my_registers(const ddf_dev_t *, uintptr_t *, size_t *, int *); 41 int enable_interrupts(const ddf_dev_t *); 42 int disable_legacy(const ddf_dev_t *); 43 43 44 44 #endif -
uspace/drv/bus/usb/uhci/uhci.c
rd9f53877 r90924df 41 41 42 42 #include "uhci.h" 43 #include "pci.h" 44 43 44 #include "res.h" 45 45 #include "hc.h" 46 46 #include "root_hub.h" … … 49 49 * and USB root hub */ 50 50 typedef struct uhci { 51 /** Pointer to DDF represen ation of UHCI host controller */51 /** Pointer to DDF representation of UHCI host controller */ 52 52 ddf_fun_t *hc_fun; 53 /** Pointer to DDF represen ation of UHCI root hub */53 /** Pointer to DDF representation of UHCI root hub */ 54 54 ddf_fun_t *rh_fun; 55 55 56 /** Internal driver's represen ation of UHCI host controller */56 /** Internal driver's representation of UHCI host controller */ 57 57 hc_t hc; 58 /** Internal driver's represen ation of UHCI root hub */58 /** Internal driver's representation of UHCI root hub */ 59 59 rh_t rh; 60 60 } uhci_t; … … 187 187 int irq = 0; 188 188 189 ret = pci_get_my_registers(device, ®_base, ®_size, &irq);189 ret = get_my_registers(device, ®_base, ®_size, &irq); 190 190 CHECK_RET_DEST_FREE_RETURN(ret, 191 191 "Failed to get I/O addresses for %" PRIun ": %s.\n", … … 194 194 (void *) reg_base, reg_size, irq); 195 195 196 ret = pci_disable_legacy(device);196 ret = disable_legacy(device); 197 197 CHECK_RET_DEST_FREE_RETURN(ret, 198 198 "Failed to disable legacy USB: %s.\n", str_error(ret)); … … 220 220 221 221 bool interrupts = false; 222 ret = pci_enable_interrupts(device);222 ret = enable_interrupts(device); 223 223 if (ret != EOK) { 224 224 usb_log_warning("Failed to enable interrupts: %s." -
uspace/lib/c/arch/arm32/src/eabi.S
rd9f53877 r90924df 1 1 # 2 # Copyright (c) 20 07 Pavel Jancik2 # Copyright (c) 2012 Martin Decky 3 3 # All rights reserved. 4 4 # … … 31 31 .global __aeabi_read_tp 32 32 33 .global __aeabi_idiv 34 .global __aeabi_uidiv 35 36 .global __aeabi_idivmod 37 .global __aeabi_uidivmod 38 39 .global __aeabi_ldivmod 40 .global __aeabi_uldivmod 41 33 42 __aeabi_read_tp: 34 43 mov r0, r9 35 44 mov pc, lr 45 46 __aeabi_idiv: 47 push {sp, lr} 48 bl __divsi3 49 ldr lr, [sp, #4] 50 add sp, sp, #8 51 bx lr 52 53 __aeabi_uidiv: 54 push {sp, lr} 55 bl __udivsi3 56 ldr lr, [sp, #4] 57 add sp, sp, #8 58 bx lr 59 60 __aeabi_idivmod: 61 sub sp, sp, #8 62 push {sp, lr} 63 bl __divmodsi3 64 ldr lr, [sp, #4] 65 add sp, sp, #8 66 pop {r1, r2} 67 bx lr 68 69 __aeabi_uidivmod: 70 sub sp, sp, #8 71 push {sp, lr} 72 bl __udivmodsi3 73 ldr lr, [sp, #4] 74 add sp, sp, #8 75 pop {r1, r2} 76 bx lr 77 78 __aeabi_ldivmod: 79 sub sp, sp, #8 80 push {sp, lr} 81 bl __divmoddi3 82 ldr lr, [sp, #4] 83 add sp, sp, #8 84 pop {r2, r3} 85 bx lr 86 87 __aeabi_uldivmod: 88 sub sp, sp, #8 89 push {sp, lr} 90 bl __udivmoddi3 91 ldr lr, [sp, #4] 92 add sp, sp, #8 93 pop {r2, r3} 94 bx lr -
uspace/lib/c/generic/str.c
rd9f53877 r90924df 46 46 #include <mem.h> 47 47 #include <str.h> 48 49 /** Check the condition if wchar_t is signed */ 50 #ifdef WCHAR_IS_UNSIGNED 51 #define WCHAR_SIGNED_CHECK(cond) (true) 52 #else 53 #define WCHAR_SIGNED_CHECK(cond) (cond) 54 #endif 48 55 49 56 /** Byte mask consisting of lowest @n bits (out of 8) */ … … 399 406 bool ascii_check(wchar_t ch) 400 407 { 401 if ( (ch >= 0) && (ch <= 127))408 if (WCHAR_SIGNED_CHECK(ch >= 0) && (ch <= 127)) 402 409 return true; 403 410 … … 412 419 bool chr_check(wchar_t ch) 413 420 { 414 if ( (ch >= 0) && (ch <= 1114111))421 if (WCHAR_SIGNED_CHECK(ch >= 0) && (ch <= 1114111)) 415 422 return true; 416 423 … … 513 520 * @param count Size of the destination buffer (must be > 0). 514 521 * @param src Source string. 522 * 515 523 */ 516 524 void str_cpy(char *dest, size_t size, const char *src) … … 545 553 * @param src Source string. 546 554 * @param n Maximum number of bytes to read from @a src. 555 * 547 556 */ 548 557 void str_ncpy(char *dest, size_t size, const char *src, size_t n) -
uspace/lib/softfloat/Makefile
rd9f53877 r90924df 29 29 30 30 USPACE_PREFIX = ../.. 31 EXTRA_CFLAGS = -Iinclude -Iarch/$(UARCH)/include/31 EXTRA_CFLAGS = -Iinclude 32 32 LIBRARY = libsoftfloat 33 33 -
uspace/lib/softfloat/generic/add.c
rd9f53877 r90924df 39 39 #include <common.h> 40 40 41 /** 42 * Add two single-precision floats with the same signs. 41 /** Add two single-precision floats with the same sign. 43 42 * 44 43 * @param a First input operand. … … 46 45 * @return Result of addition. 47 46 */ 48 float32 add Float32(float32 a, float32 b)47 float32 add_float32(float32 a, float32 b) 49 48 { 50 49 int expdiff; … … 53 52 expdiff = a.parts.exp - b.parts.exp; 54 53 if (expdiff < 0) { 55 if (is Float32NaN(b)) {56 /* TODO: fix SigNaN */ 57 if (is Float32SigNaN(b)) {54 if (is_float32_nan(b)) { 55 /* TODO: fix SigNaN */ 56 if (is_float32_signan(b)) { 58 57 } 59 58 … … 71 70 expdiff *= -1; 72 71 } else { 73 if ((is Float32NaN(a)) || (isFloat32NaN(b))) {74 /* TODO: fix SigNaN */ 75 if (is Float32SigNaN(a) || isFloat32SigNaN(b)) {76 } 77 return (is Float32NaN(a) ? a : b);72 if ((is_float32_nan(a)) || (is_float32_nan(b))) { 73 /* TODO: fix SigNaN */ 74 if (is_float32_signan(a) || is_float32_signan(b)) { 75 } 76 return (is_float32_nan(a) ? a : b); 78 77 } 79 78 … … 150 149 } 151 150 152 /** 153 * Add two double-precision floats with the same signs. 151 /** Add two double-precision floats with the same sign. 154 152 * 155 153 * @param a First input operand. … … 157 155 * @return Result of addition. 158 156 */ 159 float64 add Float64(float64 a, float64 b)157 float64 add_float64(float64 a, float64 b) 160 158 { 161 159 int expdiff; … … 165 163 expdiff = ((int) a.parts.exp) - b.parts.exp; 166 164 if (expdiff < 0) { 167 if (is Float64NaN(b)) {168 /* TODO: fix SigNaN */ 169 if (is Float64SigNaN(b)) {170 } 171 172 return b; 173 } 174 175 /* b is infinity and a not */ 176 if (b.parts.exp == FLOAT64_MAX_EXPONENT) { 165 if (is_float64_nan(b)) { 166 /* TODO: fix SigNaN */ 167 if (is_float64_signan(b)) { 168 } 169 170 return b; 171 } 172 173 /* b is infinity and a not */ 174 if (b.parts.exp == FLOAT64_MAX_EXPONENT) { 177 175 return b; 178 176 } … … 184 182 expdiff *= -1; 185 183 } else { 186 if (is Float64NaN(a)) {187 /* TODO: fix SigNaN */ 188 if (is Float64SigNaN(a) || isFloat64SigNaN(b)) {184 if (is_float64_nan(a)) { 185 /* TODO: fix SigNaN */ 186 if (is_float64_signan(a) || is_float64_signan(b)) { 189 187 } 190 188 return a; … … 265 263 } 266 264 267 /** 268 * Add two quadruple-precision floats with the same signs. 265 /** Add two quadruple-precision floats with the same sign. 269 266 * 270 267 * @param a First input operand. … … 272 269 * @return Result of addition. 273 270 */ 274 float128 add Float128(float128 a, float128 b)271 float128 add_float128(float128 a, float128 b) 275 272 { 276 273 int expdiff; … … 280 277 expdiff = ((int) a.parts.exp) - b.parts.exp; 281 278 if (expdiff < 0) { 282 if (is Float128NaN(b)) {283 /* TODO: fix SigNaN */ 284 if (is Float128SigNaN(b)) {279 if (is_float128_nan(b)) { 280 /* TODO: fix SigNaN */ 281 if (is_float128_signan(b)) { 285 282 } 286 283 … … 301 298 expdiff *= -1; 302 299 } else { 303 if (is Float128NaN(a)) {304 /* TODO: fix SigNaN */ 305 if (is Float128SigNaN(a) || isFloat128SigNaN(b)) {300 if (is_float128_nan(a)) { 301 /* TODO: fix SigNaN */ 302 if (is_float128_signan(a) || is_float128_signan(b)) { 306 303 } 307 304 return a; -
uspace/lib/softfloat/generic/common.c
rd9f53877 r90924df 66 66 * @return Finished double-precision float. 67 67 */ 68 float64 finish Float64(int32_t cexp, uint64_t cfrac, char sign)68 float64 finish_float64(int32_t cexp, uint64_t cfrac, char sign) 69 69 { 70 70 float64 result; … … 140 140 * @return Finished quadruple-precision float. 141 141 */ 142 float128 finish Float128(int32_t cexp, uint64_t cfrac_hi, uint64_t cfrac_lo,142 float128 finish_float128(int32_t cexp, uint64_t cfrac_hi, uint64_t cfrac_lo, 143 143 char sign, uint64_t shift_out) 144 144 { … … 238 238 * @return Number of detected leading zeroes. 239 239 */ 240 int count Zeroes8(uint8_t i)240 int count_zeroes8(uint8_t i) 241 241 { 242 242 return zeroTable[i]; … … 249 249 * @return Number of detected leading zeroes. 250 250 */ 251 int count Zeroes32(uint32_t i)251 int count_zeroes32(uint32_t i) 252 252 { 253 253 int j; 254 254 for (j = 0; j < 32; j += 8) { 255 255 if (i & (0xFF << (24 - j))) { 256 return (j + count Zeroes8(i >> (24 - j)));256 return (j + count_zeroes8(i >> (24 - j))); 257 257 } 258 258 } … … 267 267 * @return Number of detected leading zeroes. 268 268 */ 269 int count Zeroes64(uint64_t i)269 int count_zeroes64(uint64_t i) 270 270 { 271 271 int j; 272 272 for (j = 0; j < 64; j += 8) { 273 273 if (i & (0xFFll << (56 - j))) { 274 return (j + count Zeroes8(i >> (56 - j)));274 return (j + count_zeroes8(i >> (56 - j))); 275 275 } 276 276 } … … 286 286 * @param fraction Fraction with hidden bit shifted to 30th bit. 287 287 */ 288 void round Float32(int32_t *exp, uint32_t *fraction)288 void round_float32(int32_t *exp, uint32_t *fraction) 289 289 { 290 290 /* rounding - if first bit after fraction is set then round up */ … … 312 312 * @param fraction Fraction with hidden bit shifted to 62nd bit. 313 313 */ 314 void round Float64(int32_t *exp, uint64_t *fraction)314 void round_float64(int32_t *exp, uint64_t *fraction) 315 315 { 316 316 /* rounding - if first bit after fraction is set then round up */ … … 339 339 * @param frac_lo Low part of fraction part with hidden bit shifted to 126th bit. 340 340 */ 341 void round Float128(int32_t *exp, uint64_t *frac_hi, uint64_t *frac_lo)341 void round_float128(int32_t *exp, uint64_t *frac_hi, uint64_t *frac_lo) 342 342 { 343 343 uint64_t tmp_hi, tmp_lo; -
uspace/lib/softfloat/generic/comparison.c
rd9f53877 r90924df 45 45 * @return 1 if float is NaN, 0 otherwise. 46 46 */ 47 int is Float32NaN(float32 f)47 int is_float32_nan(float32 f) 48 48 { 49 49 /* NaN : exp = 0xff and nonzero fraction */ … … 58 58 * @return 1 if float is NaN, 0 otherwise. 59 59 */ 60 int is Float64NaN(float64 d)60 int is_float64_nan(float64 d) 61 61 { 62 62 /* NaN : exp = 0x7ff and nonzero fraction */ … … 71 71 * @return 1 if float is NaN, 0 otherwise. 72 72 */ 73 int is Float128NaN(float128 ld)73 int is_float128_nan(float128 ld) 74 74 { 75 75 /* NaN : exp = 0x7fff and nonzero fraction */ … … 84 84 * @return 1 if float is signalling NaN, 0 otherwise. 85 85 */ 86 int is Float32SigNaN(float32 f)86 int is_float32_signan(float32 f) 87 87 { 88 88 /* SigNaN : exp = 0xff and fraction = 0xxxxx..x (binary), … … 98 98 * @return 1 if float is signalling NaN, 0 otherwise. 99 99 */ 100 int is Float64SigNaN(float64 d)100 int is_float64_signan(float64 d) 101 101 { 102 102 /* SigNaN : exp = 0x7ff and fraction = 0xxxxx..x (binary), … … 112 112 * @return 1 if float is signalling NaN, 0 otherwise. 113 113 */ 114 int is Float128SigNaN(float128 ld)114 int is_float128_signan(float128 ld) 115 115 { 116 116 /* SigNaN : exp = 0x7fff and fraction = 0xxxxx..x (binary), … … 128 128 * @return 1 if float is infinite, 0 otherwise. 129 129 */ 130 int is Float32Infinity(float32 f)130 int is_float32_infinity(float32 f) 131 131 { 132 132 /* NaN : exp = 0x7ff and zero fraction */ … … 140 140 * @return 1 if float is infinite, 0 otherwise. 141 141 */ 142 int is Float64Infinity(float64 d)142 int is_float64_infinity(float64 d) 143 143 { 144 144 /* NaN : exp = 0x7ff and zero fraction */ … … 152 152 * @return 1 if float is infinite, 0 otherwise. 153 153 */ 154 int is Float128Infinity(float128 ld)154 int is_float128_infinity(float128 ld) 155 155 { 156 156 /* NaN : exp = 0x7fff and zero fraction */ … … 165 165 * @return 1 if float is zero, 0 otherwise. 166 166 */ 167 int is Float32Zero(float32 f)168 { 169 return (((f.bin ary) & 0x7FFFFFFF) == 0);167 int is_float32_zero(float32 f) 168 { 169 return (((f.bin) & 0x7FFFFFFF) == 0); 170 170 } 171 171 … … 176 176 * @return 1 if float is zero, 0 otherwise. 177 177 */ 178 int is Float64Zero(float64 d)179 { 180 return (((d.bin ary) & 0x7FFFFFFFFFFFFFFFll) == 0);178 int is_float64_zero(float64 d) 179 { 180 return (((d.bin) & 0x7FFFFFFFFFFFFFFFll) == 0); 181 181 } 182 182 … … 187 187 * @return 1 if float is zero, 0 otherwise. 188 188 */ 189 int is Float128Zero(float128 ld)189 int is_float128_zero(float128 ld) 190 190 { 191 191 uint64_t tmp_hi; 192 192 uint64_t tmp_lo; 193 194 and128(ld.bin ary.hi, ld.binary.lo,193 194 and128(ld.bin.hi, ld.bin.lo, 195 195 0x7FFFFFFFFFFFFFFFll, 0xFFFFFFFFFFFFFFFFll, &tmp_hi, &tmp_lo); 196 196 197 197 return eq128(tmp_hi, tmp_lo, 0x0ll, 0x0ll); 198 198 } … … 205 205 * @return 1 if both floats are equal, 0 otherwise. 206 206 */ 207 int is Float32eq(float32 a, float32 b)207 int is_float32_eq(float32 a, float32 b) 208 208 { 209 209 /* a equals to b or both are zeros (with any sign) */ 210 return ((a.bin ary == b.binary) ||211 (((a.bin ary | b.binary) & 0x7FFFFFFF) == 0));210 return ((a.bin == b.bin) || 211 (((a.bin | b.bin) & 0x7FFFFFFF) == 0)); 212 212 } 213 213 … … 219 219 * @return 1 if both floats are equal, 0 otherwise. 220 220 */ 221 int is Float64eq(float64 a, float64 b)221 int is_float64_eq(float64 a, float64 b) 222 222 { 223 223 /* a equals to b or both are zeros (with any sign) */ 224 return ((a.bin ary == b.binary) ||225 (((a.bin ary | b.binary) & 0x7FFFFFFFFFFFFFFFll) == 0));224 return ((a.bin == b.bin) || 225 (((a.bin | b.bin) & 0x7FFFFFFFFFFFFFFFll) == 0)); 226 226 } 227 227 … … 233 233 * @return 1 if both floats are equal, 0 otherwise. 234 234 */ 235 int is Float128eq(float128 a, float128 b)235 int is_float128_eq(float128 a, float128 b) 236 236 { 237 237 uint64_t tmp_hi; 238 238 uint64_t tmp_lo; 239 239 240 240 /* both are zeros (with any sign) */ 241 or128(a.bin ary.hi, a.binary.lo,242 b.bin ary.hi, b.binary.lo, &tmp_hi, &tmp_lo);241 or128(a.bin.hi, a.bin.lo, 242 b.bin.hi, b.bin.lo, &tmp_hi, &tmp_lo); 243 243 and128(tmp_hi, tmp_lo, 244 244 0x7FFFFFFFFFFFFFFFll, 0xFFFFFFFFFFFFFFFFll, &tmp_hi, &tmp_lo); … … 246 246 247 247 /* a equals to b */ 248 int are_equal = eq128(a.bin ary.hi, a.binary.lo, b.binary.hi, b.binary.lo);249 248 int are_equal = eq128(a.bin.hi, a.bin.lo, b.bin.hi, b.bin.lo); 249 250 250 return are_equal || both_zero; 251 251 } … … 258 258 * @return 1 if a is lower than b, 0 otherwise. 259 259 */ 260 int isFloat32lt(float32 a, float32 b) 261 { 262 if (((a.binary | b.binary) & 0x7FFFFFFF) == 0) { 263 return 0; /* +- zeroes */ 260 int is_float32_lt(float32 a, float32 b) 261 { 262 if (((a.bin | b.bin) & 0x7FFFFFFF) == 0) { 263 /* +- zeroes */ 264 return 0; 264 265 } 265 266 266 267 if ((a.parts.sign) && (b.parts.sign)) { 267 268 /* if both are negative, smaller is that with greater binary value */ 268 return (a.binary > b.binary); 269 } 270 271 /* lets negate signs - now will be positive numbers allways bigger than 272 * negative (first bit will be set for unsigned integer comparison) */ 273 a.parts.sign = !a.parts.sign; 274 b.parts.sign = !b.parts.sign; 275 return (a.binary < b.binary); 269 return (a.bin > b.bin); 270 } 271 272 /* 273 * lets negate signs - now will be positive numbers always 274 * bigger than negative (first bit will be set for unsigned 275 * integer comparison) 276 */ 277 a.parts.sign = !a.parts.sign; 278 b.parts.sign = !b.parts.sign; 279 return (a.bin < b.bin); 276 280 } 277 281 … … 283 287 * @return 1 if a is lower than b, 0 otherwise. 284 288 */ 285 int isFloat64lt(float64 a, float64 b) 286 { 287 if (((a.binary | b.binary) & 0x7FFFFFFFFFFFFFFFll) == 0) { 288 return 0; /* +- zeroes */ 289 } 290 289 int is_float64_lt(float64 a, float64 b) 290 { 291 if (((a.bin | b.bin) & 0x7FFFFFFFFFFFFFFFll) == 0) { 292 /* +- zeroes */ 293 return 0; 294 } 295 291 296 if ((a.parts.sign) && (b.parts.sign)) { 292 297 /* if both are negative, smaller is that with greater binary value */ 293 return (a.binary > b.binary); 294 } 295 296 /* lets negate signs - now will be positive numbers allways bigger than 297 * negative (first bit will be set for unsigned integer comparison) */ 298 a.parts.sign = !a.parts.sign; 299 b.parts.sign = !b.parts.sign; 300 return (a.binary < b.binary); 298 return (a.bin > b.bin); 299 } 300 301 /* 302 * lets negate signs - now will be positive numbers always 303 * bigger than negative (first bit will be set for unsigned 304 * integer comparison) 305 */ 306 a.parts.sign = !a.parts.sign; 307 b.parts.sign = !b.parts.sign; 308 return (a.bin < b.bin); 301 309 } 302 310 … … 308 316 * @return 1 if a is lower than b, 0 otherwise. 309 317 */ 310 int is Float128lt(float128 a, float128 b)318 int is_float128_lt(float128 a, float128 b) 311 319 { 312 320 uint64_t tmp_hi; 313 321 uint64_t tmp_lo; 314 315 or128(a.bin ary.hi, a.binary.lo,316 b.bin ary.hi, b.binary.lo, &tmp_hi, &tmp_lo);322 323 or128(a.bin.hi, a.bin.lo, 324 b.bin.hi, b.bin.lo, &tmp_hi, &tmp_lo); 317 325 and128(tmp_hi, tmp_lo, 318 326 0x7FFFFFFFFFFFFFFFll, 0xFFFFFFFFFFFFFFFFll, &tmp_hi, &tmp_lo); 319 327 if (eq128(tmp_hi, tmp_lo, 0x0ll, 0x0ll)) { 320 return 0; /* +- zeroes */ 321 } 322 328 /* +- zeroes */ 329 return 0; 330 } 331 323 332 if ((a.parts.sign) && (b.parts.sign)) { 324 333 /* if both are negative, smaller is that with greater binary value */ 325 return lt128(b.binary.hi, b.binary.lo, a.binary.hi, a.binary.lo); 326 } 327 328 /* lets negate signs - now will be positive numbers allways bigger than 329 * negative (first bit will be set for unsigned integer comparison) */ 330 a.parts.sign = !a.parts.sign; 331 b.parts.sign = !b.parts.sign; 332 return lt128(a.binary.hi, a.binary.lo, b.binary.hi, b.binary.lo); 334 return lt128(b.bin.hi, b.bin.lo, a.bin.hi, a.bin.lo); 335 } 336 337 /* 338 * lets negate signs - now will be positive numbers always 339 * bigger than negative (first bit will be set for unsigned 340 * integer comparison) 341 */ 342 a.parts.sign = !a.parts.sign; 343 b.parts.sign = !b.parts.sign; 344 return lt128(a.bin.hi, a.bin.lo, b.bin.hi, b.bin.lo); 333 345 } 334 346 … … 340 352 * @return 1 if a is greater than b, 0 otherwise. 341 353 */ 342 int isFloat32gt(float32 a, float32 b) 343 { 344 if (((a.binary | b.binary) & 0x7FFFFFFF) == 0) { 345 return 0; /* zeroes are equal with any sign */ 354 int is_float32_gt(float32 a, float32 b) 355 { 356 if (((a.bin | b.bin) & 0x7FFFFFFF) == 0) { 357 /* zeroes are equal with any sign */ 358 return 0; 346 359 } 347 360 348 361 if ((a.parts.sign) && (b.parts.sign)) { 349 362 /* if both are negative, greater is that with smaller binary value */ 350 return (a.binary < b.binary); 351 } 352 353 /* lets negate signs - now will be positive numbers allways bigger than 354 * negative (first bit will be set for unsigned integer comparison) */ 355 a.parts.sign = !a.parts.sign; 356 b.parts.sign = !b.parts.sign; 357 return (a.binary > b.binary); 363 return (a.bin < b.bin); 364 } 365 366 /* 367 * lets negate signs - now will be positive numbers always 368 * bigger than negative (first bit will be set for unsigned 369 * integer comparison) 370 */ 371 a.parts.sign = !a.parts.sign; 372 b.parts.sign = !b.parts.sign; 373 return (a.bin > b.bin); 358 374 } 359 375 … … 365 381 * @return 1 if a is greater than b, 0 otherwise. 366 382 */ 367 int isFloat64gt(float64 a, float64 b) 368 { 369 if (((a.binary | b.binary) & 0x7FFFFFFFFFFFFFFFll) == 0) { 370 return 0; /* zeroes are equal with any sign */ 371 } 372 383 int is_float64_gt(float64 a, float64 b) 384 { 385 if (((a.bin | b.bin) & 0x7FFFFFFFFFFFFFFFll) == 0) { 386 /* zeroes are equal with any sign */ 387 return 0; 388 } 389 373 390 if ((a.parts.sign) && (b.parts.sign)) { 374 391 /* if both are negative, greater is that with smaller binary value */ 375 return (a.binary < b.binary); 376 } 377 378 /* lets negate signs - now will be positive numbers allways bigger than 379 * negative (first bit will be set for unsigned integer comparison) */ 380 a.parts.sign = !a.parts.sign; 381 b.parts.sign = !b.parts.sign; 382 return (a.binary > b.binary); 392 return (a.bin < b.bin); 393 } 394 395 /* 396 * lets negate signs - now will be positive numbers always 397 * bigger than negative (first bit will be set for unsigned 398 * integer comparison) 399 */ 400 a.parts.sign = !a.parts.sign; 401 b.parts.sign = !b.parts.sign; 402 return (a.bin > b.bin); 383 403 } 384 404 … … 390 410 * @return 1 if a is greater than b, 0 otherwise. 391 411 */ 392 int is Float128gt(float128 a, float128 b)412 int is_float128_gt(float128 a, float128 b) 393 413 { 394 414 uint64_t tmp_hi; 395 415 uint64_t tmp_lo; 396 397 or128(a.bin ary.hi, a.binary.lo,398 b.bin ary.hi, b.binary.lo, &tmp_hi, &tmp_lo);416 417 or128(a.bin.hi, a.bin.lo, 418 b.bin.hi, b.bin.lo, &tmp_hi, &tmp_lo); 399 419 and128(tmp_hi, tmp_lo, 400 420 0x7FFFFFFFFFFFFFFFll, 0xFFFFFFFFFFFFFFFFll, &tmp_hi, &tmp_lo); 401 421 if (eq128(tmp_hi, tmp_lo, 0x0ll, 0x0ll)) { 402 return 0; /* zeroes are equal with any sign */ 403 } 404 422 /* zeroes are equal with any sign */ 423 return 0; 424 } 425 405 426 if ((a.parts.sign) && (b.parts.sign)) { 406 427 /* if both are negative, greater is that with smaller binary value */ 407 return lt128(a.binary.hi, a.binary.lo, b.binary.hi, b.binary.lo); 408 } 409 410 /* lets negate signs - now will be positive numbers allways bigger than 411 * negative (first bit will be set for unsigned integer comparison) */ 412 a.parts.sign = !a.parts.sign; 413 b.parts.sign = !b.parts.sign; 414 return lt128(b.binary.hi, b.binary.lo, a.binary.hi, a.binary.lo); 428 return lt128(a.bin.hi, a.bin.lo, b.bin.hi, b.bin.lo); 429 } 430 431 /* 432 * lets negate signs - now will be positive numbers always 433 * bigger than negative (first bit will be set for unsigned 434 * integer comparison) 435 */ 436 a.parts.sign = !a.parts.sign; 437 b.parts.sign = !b.parts.sign; 438 return lt128(b.bin.hi, b.bin.lo, a.bin.hi, a.bin.lo); 415 439 } 416 440 -
uspace/lib/softfloat/generic/conversion.c
rd9f53877 r90924df 39 39 #include <common.h> 40 40 41 float64 convertFloat32ToFloat64(float32 a)41 float64 float32_to_float64(float32 a) 42 42 { 43 43 float64 result; … … 48 48 result.parts.fraction <<= (FLOAT64_FRACTION_SIZE - FLOAT32_FRACTION_SIZE); 49 49 50 if ((is Float32Infinity(a)) || (isFloat32NaN(a))) {50 if ((is_float32_infinity(a)) || (is_float32_nan(a))) { 51 51 result.parts.exp = FLOAT64_MAX_EXPONENT; 52 / * TODO; check if its correct for SigNaNs*/52 // TODO; check if its correct for SigNaNs 53 53 return result; 54 54 } … … 57 57 if (a.parts.exp == 0) { 58 58 /* normalize denormalized numbers */ 59 59 60 60 if (result.parts.fraction == 0) { /* fix zero */ 61 61 result.parts.exp = 0; … … 77 77 } 78 78 79 float128 convertFloat32ToFloat128(float32 a)79 float128 float32_to_float128(float32 a) 80 80 { 81 81 float128 result; 82 82 uint64_t frac_hi, frac_lo; 83 83 uint64_t tmp_hi, tmp_lo; 84 84 85 85 result.parts.sign = a.parts.sign; 86 86 result.parts.frac_hi = 0; … … 91 91 result.parts.frac_hi = frac_hi; 92 92 result.parts.frac_lo = frac_lo; 93 94 if ((is Float32Infinity(a)) || (isFloat32NaN(a))) {93 94 if ((is_float32_infinity(a)) || (is_float32_nan(a))) { 95 95 result.parts.exp = FLOAT128_MAX_EXPONENT; 96 / * TODO; check if its correct for SigNaNs*/97 return result; 98 } 99 96 // TODO; check if its correct for SigNaNs 97 return result; 98 } 99 100 100 result.parts.exp = a.parts.exp + ((int) FLOAT128_BIAS - FLOAT32_BIAS); 101 101 if (a.parts.exp == 0) { 102 102 /* normalize denormalized numbers */ 103 103 104 104 if (eq128(result.parts.frac_hi, 105 105 result.parts.frac_lo, 0x0ll, 0x0ll)) { /* fix zero */ … … 107 107 return result; 108 108 } 109 109 110 110 frac_hi = result.parts.frac_hi; 111 111 frac_lo = result.parts.frac_lo; 112 112 113 113 and128(frac_hi, frac_lo, 114 114 FLOAT128_HIDDEN_BIT_MASK_HI, FLOAT128_HIDDEN_BIT_MASK_LO, … … 118 118 --result.parts.exp; 119 119 } 120 120 121 121 ++result.parts.exp; 122 122 result.parts.frac_hi = frac_hi; 123 123 result.parts.frac_lo = frac_lo; 124 124 } 125 126 return result; 127 } 128 129 float128 convertFloat64ToFloat128(float64 a)125 126 return result; 127 } 128 129 float128 float64_to_float128(float64 a) 130 130 { 131 131 float128 result; 132 132 uint64_t frac_hi, frac_lo; 133 133 uint64_t tmp_hi, tmp_lo; 134 134 135 135 result.parts.sign = a.parts.sign; 136 136 result.parts.frac_hi = 0; … … 141 141 result.parts.frac_hi = frac_hi; 142 142 result.parts.frac_lo = frac_lo; 143 144 if ((is Float64Infinity(a)) || (isFloat64NaN(a))) {143 144 if ((is_float64_infinity(a)) || (is_float64_nan(a))) { 145 145 result.parts.exp = FLOAT128_MAX_EXPONENT; 146 / * TODO; check if its correct for SigNaNs*/147 return result; 148 } 149 146 // TODO; check if its correct for SigNaNs 147 return result; 148 } 149 150 150 result.parts.exp = a.parts.exp + ((int) FLOAT128_BIAS - FLOAT64_BIAS); 151 151 if (a.parts.exp == 0) { 152 152 /* normalize denormalized numbers */ 153 153 154 154 if (eq128(result.parts.frac_hi, 155 155 result.parts.frac_lo, 0x0ll, 0x0ll)) { /* fix zero */ … … 157 157 return result; 158 158 } 159 159 160 160 frac_hi = result.parts.frac_hi; 161 161 frac_lo = result.parts.frac_lo; 162 162 163 163 and128(frac_hi, frac_lo, 164 164 FLOAT128_HIDDEN_BIT_MASK_HI, FLOAT128_HIDDEN_BIT_MASK_LO, … … 168 168 --result.parts.exp; 169 169 } 170 170 171 171 ++result.parts.exp; 172 172 result.parts.frac_hi = frac_hi; 173 173 result.parts.frac_lo = frac_lo; 174 174 } 175 176 return result; 177 } 178 179 float32 convertFloat64ToFloat32(float64 a)175 176 return result; 177 } 178 179 float32 float64_to_float32(float64 a) 180 180 { 181 181 float32 result; … … 185 185 result.parts.sign = a.parts.sign; 186 186 187 if (is Float64NaN(a)) {187 if (is_float64_nan(a)) { 188 188 result.parts.exp = FLOAT32_MAX_EXPONENT; 189 189 190 if (is Float64SigNaN(a)) {190 if (is_float64_signan(a)) { 191 191 /* set first bit of fraction nonzero */ 192 192 result.parts.fraction = FLOAT32_HIDDEN_BIT_MASK >> 1; 193 193 return result; 194 194 } 195 195 196 196 /* fraction nonzero but its first bit is zero */ 197 197 result.parts.fraction = 0x1; 198 198 return result; 199 199 } 200 201 if (is Float64Infinity(a)) {200 201 if (is_float64_infinity(a)) { 202 202 result.parts.fraction = 0; 203 203 result.parts.exp = FLOAT32_MAX_EXPONENT; 204 204 return result; 205 205 } 206 206 207 207 exp = (int) a.parts.exp - FLOAT64_BIAS + FLOAT32_BIAS; 208 208 … … 239 239 return result; 240 240 } 241 241 242 242 result.parts.exp = exp; 243 243 result.parts.fraction = … … 246 246 } 247 247 248 float32 convertFloat128ToFloat32(float128 a)248 float32 float128_to_float32(float128 a) 249 249 { 250 250 float32 result; 251 251 int32_t exp; 252 252 uint64_t frac_hi, frac_lo; 253 253 254 254 result.parts.sign = a.parts.sign; 255 256 if (is Float128NaN(a)) {255 256 if (is_float128_nan(a)) { 257 257 result.parts.exp = FLOAT32_MAX_EXPONENT; 258 259 if (is Float128SigNaN(a)) {258 259 if (is_float128_signan(a)) { 260 260 /* set first bit of fraction nonzero */ 261 261 result.parts.fraction = FLOAT32_HIDDEN_BIT_MASK >> 1; 262 262 return result; 263 263 } 264 264 265 265 /* fraction nonzero but its first bit is zero */ 266 266 result.parts.fraction = 0x1; 267 267 return result; 268 268 } 269 270 if (is Float128Infinity(a)) {269 270 if (is_float128_infinity(a)) { 271 271 result.parts.fraction = 0; 272 272 result.parts.exp = FLOAT32_MAX_EXPONENT; 273 273 return result; 274 274 } 275 275 276 276 exp = (int) a.parts.exp - FLOAT128_BIAS + FLOAT32_BIAS; 277 277 278 278 if (exp >= FLOAT32_MAX_EXPONENT) { 279 279 /* FIXME: overflow */ … … 283 283 } else if (exp <= 0) { 284 284 /* underflow or denormalized */ 285 285 286 286 result.parts.exp = 0; 287 287 288 288 exp *= -1; 289 289 if (exp > FLOAT32_FRACTION_SIZE) { … … 292 292 return result; 293 293 } 294 294 295 295 /* denormalized */ 296 296 297 297 frac_hi = a.parts.frac_hi; 298 298 frac_lo = a.parts.frac_lo; 299 299 300 300 /* denormalize and set hidden bit */ 301 301 frac_hi |= FLOAT128_HIDDEN_BIT_MASK_HI; 302 302 303 303 rshift128(frac_hi, frac_lo, 304 304 (FLOAT128_FRACTION_SIZE - FLOAT32_FRACTION_SIZE + 1), 305 305 &frac_hi, &frac_lo); 306 306 307 307 while (exp > 0) { 308 308 --exp; … … 310 310 } 311 311 result.parts.fraction = frac_lo; 312 313 return result; 314 } 315 312 313 return result; 314 } 315 316 316 result.parts.exp = exp; 317 317 frac_hi = a.parts.frac_hi; … … 324 324 } 325 325 326 float64 convertFloat128ToFloat64(float128 a)326 float64 float128_to_float64(float128 a) 327 327 { 328 328 float64 result; 329 329 int32_t exp; 330 330 uint64_t frac_hi, frac_lo; 331 331 332 332 result.parts.sign = a.parts.sign; 333 334 if (is Float128NaN(a)) {333 334 if (is_float128_nan(a)) { 335 335 result.parts.exp = FLOAT64_MAX_EXPONENT; 336 337 if (is Float128SigNaN(a)) {336 337 if (is_float128_signan(a)) { 338 338 /* set first bit of fraction nonzero */ 339 339 result.parts.fraction = FLOAT64_HIDDEN_BIT_MASK >> 1; 340 340 return result; 341 341 } 342 342 343 343 /* fraction nonzero but its first bit is zero */ 344 344 result.parts.fraction = 0x1; 345 345 return result; 346 346 } 347 348 if (is Float128Infinity(a)) {347 348 if (is_float128_infinity(a)) { 349 349 result.parts.fraction = 0; 350 350 result.parts.exp = FLOAT64_MAX_EXPONENT; 351 351 return result; 352 352 } 353 353 354 354 exp = (int) a.parts.exp - FLOAT128_BIAS + FLOAT64_BIAS; 355 355 356 356 if (exp >= FLOAT64_MAX_EXPONENT) { 357 357 /* FIXME: overflow */ … … 361 361 } else if (exp <= 0) { 362 362 /* underflow or denormalized */ 363 363 364 364 result.parts.exp = 0; 365 365 366 366 exp *= -1; 367 367 if (exp > FLOAT64_FRACTION_SIZE) { … … 370 370 return result; 371 371 } 372 372 373 373 /* denormalized */ 374 374 375 375 frac_hi = a.parts.frac_hi; 376 376 frac_lo = a.parts.frac_lo; 377 377 378 378 /* denormalize and set hidden bit */ 379 379 frac_hi |= FLOAT128_HIDDEN_BIT_MASK_HI; 380 380 381 381 rshift128(frac_hi, frac_lo, 382 382 (FLOAT128_FRACTION_SIZE - FLOAT64_FRACTION_SIZE + 1), 383 383 &frac_hi, &frac_lo); 384 384 385 385 while (exp > 0) { 386 386 --exp; … … 388 388 } 389 389 result.parts.fraction = frac_lo; 390 391 return result; 392 } 393 390 391 return result; 392 } 393 394 394 result.parts.exp = exp; 395 395 frac_hi = a.parts.frac_hi; … … 402 402 } 403 403 404 405 /** 406 * Helping procedure for converting float32 to uint32. 404 /** Helper procedure for converting float32 to uint32. 407 405 * 408 406 * @param a Floating point number in normalized form … … 424 422 /* shift fraction to left so hidden bit will be the most significant bit */ 425 423 frac <<= 32 - FLOAT32_FRACTION_SIZE - 1; 426 424 427 425 frac >>= 32 - (a.parts.exp - FLOAT32_BIAS) - 1; 428 426 if ((a.parts.sign == 1) && (frac != 0)) { … … 434 432 } 435 433 436 /* 437 * FIXME: Im not sure what to return if overflow/underflow happens 438 * 439 */ 434 /* 435 * FIXME: Im not sure what to return if overflow/underflow happens 436 * - now its the biggest or the smallest int 437 */ 440 438 uint32_t float32_to_uint32(float32 a) 441 439 { 442 if (is Float32NaN(a))440 if (is_float32_nan(a)) 443 441 return UINT32_MAX; 444 442 445 if (is Float32Infinity(a) || (a.parts.exp >= (32 + FLOAT32_BIAS))) {443 if (is_float32_infinity(a) || (a.parts.exp >= (32 + FLOAT32_BIAS))) { 446 444 if (a.parts.sign) 447 445 return UINT32_MIN; … … 453 451 } 454 452 455 /* 456 * FIXME: Im not sure what to return if overflow/underflow happens 457 * 458 */ 453 /* 454 * FIXME: Im not sure what to return if overflow/underflow happens 455 * - now its the biggest or the smallest int 456 */ 459 457 int32_t float32_to_int32(float32 a) 460 458 { 461 if (is Float32NaN(a))459 if (is_float32_nan(a)) 462 460 return INT32_MAX; 463 461 464 if (is Float32Infinity(a) || (a.parts.exp >= (32 + FLOAT32_BIAS))) {462 if (is_float32_infinity(a) || (a.parts.exp >= (32 + FLOAT32_BIAS))) { 465 463 if (a.parts.sign) 466 464 return INT32_MIN; … … 472 470 } 473 471 474 475 /** 476 * Helping procedure for converting float32 to uint64. 472 /** Helper procedure for converting float32 to uint64. 477 473 * 478 474 * @param a Floating point number in normalized form … … 483 479 { 484 480 uint64_t frac; 485 481 486 482 if (a.parts.exp < FLOAT32_BIAS) { 487 / *TODO: rounding*/483 // TODO: rounding 488 484 return 0; 489 485 } 490 486 491 487 frac = a.parts.fraction; 492 488 493 489 frac |= FLOAT32_HIDDEN_BIT_MASK; 494 490 /* shift fraction to left so hidden bit will be the most significant bit */ 495 491 frac <<= 64 - FLOAT32_FRACTION_SIZE - 1; 496 492 497 493 frac >>= 64 - (a.parts.exp - FLOAT32_BIAS) - 1; 498 494 if ((a.parts.sign == 1) && (frac != 0)) { … … 500 496 ++frac; 501 497 } 502 498 503 499 return frac; 504 500 } 505 501 506 /* 502 /* 507 503 * FIXME: Im not sure what to return if overflow/underflow happens 508 * 504 * - now its the biggest or the smallest int 509 505 */ 510 506 uint64_t float32_to_uint64(float32 a) 511 507 { 512 if (is Float32NaN(a))508 if (is_float32_nan(a)) 513 509 return UINT64_MAX; 514 515 516 if (isFloat32Infinity(a) || (a.parts.exp >= (64 + FLOAT32_BIAS))) { 510 511 if (is_float32_infinity(a) || (a.parts.exp >= (64 + FLOAT32_BIAS))) { 517 512 if (a.parts.sign) 518 513 return UINT64_MIN; 519 514 520 515 return UINT64_MAX; 521 516 } 522 517 523 518 return _float32_to_uint64_helper(a); 524 519 } 525 520 526 /* 521 /* 527 522 * FIXME: Im not sure what to return if overflow/underflow happens 528 * 523 * - now its the biggest or the smallest int 529 524 */ 530 525 int64_t float32_to_int64(float32 a) 531 526 { 532 if (is Float32NaN(a))527 if (is_float32_nan(a)) 533 528 return INT64_MAX; 534 535 if (is Float32Infinity(a) || (a.parts.exp >= (64 + FLOAT32_BIAS))) {529 530 if (is_float32_infinity(a) || (a.parts.exp >= (64 + FLOAT32_BIAS))) { 536 531 if (a.parts.sign) 537 532 return INT64_MIN; 538 533 539 534 return INT64_MAX; 540 535 } 541 536 542 537 return _float32_to_uint64_helper(a); 543 538 } 544 539 545 546 /** 547 * Helping procedure for converting float64 to uint64. 540 /** Helper procedure for converting float64 to uint64. 548 541 * 549 542 * @param a Floating point number in normalized form … … 554 547 { 555 548 uint64_t frac; 556 549 557 550 if (a.parts.exp < FLOAT64_BIAS) { 558 / *TODO: rounding*/551 // TODO: rounding 559 552 return 0; 560 553 } 561 554 562 555 frac = a.parts.fraction; 563 556 564 557 frac |= FLOAT64_HIDDEN_BIT_MASK; 565 558 /* shift fraction to left so hidden bit will be the most significant bit */ 566 559 frac <<= 64 - FLOAT64_FRACTION_SIZE - 1; 567 560 568 561 frac >>= 64 - (a.parts.exp - FLOAT64_BIAS) - 1; 569 562 if ((a.parts.sign == 1) && (frac != 0)) { … … 571 564 ++frac; 572 565 } 573 566 574 567 return frac; 575 568 } … … 577 570 /* 578 571 * FIXME: Im not sure what to return if overflow/underflow happens 579 * 572 * - now its the biggest or the smallest int 580 573 */ 581 574 uint32_t float64_to_uint32(float64 a) 582 575 { 583 if (is Float64NaN(a))576 if (is_float64_nan(a)) 584 577 return UINT32_MAX; 585 586 if (is Float64Infinity(a) || (a.parts.exp >= (32 + FLOAT64_BIAS))) {578 579 if (is_float64_infinity(a) || (a.parts.exp >= (32 + FLOAT64_BIAS))) { 587 580 if (a.parts.sign) 588 581 return UINT32_MIN; 589 582 590 583 return UINT32_MAX; 591 584 } 592 585 593 586 return (uint32_t) _float64_to_uint64_helper(a); 594 587 } … … 596 589 /* 597 590 * FIXME: Im not sure what to return if overflow/underflow happens 598 * 591 * - now its the biggest or the smallest int 599 592 */ 600 593 int32_t float64_to_int32(float64 a) 601 594 { 602 if (is Float64NaN(a))595 if (is_float64_nan(a)) 603 596 return INT32_MAX; 604 605 if (is Float64Infinity(a) || (a.parts.exp >= (32 + FLOAT64_BIAS))) {597 598 if (is_float64_infinity(a) || (a.parts.exp >= (32 + FLOAT64_BIAS))) { 606 599 if (a.parts.sign) 607 600 return INT32_MIN; 608 601 609 602 return INT32_MAX; 610 603 } 611 604 612 605 return (int32_t) _float64_to_uint64_helper(a); 613 606 } 614 607 615 616 /* 608 /* 617 609 * FIXME: Im not sure what to return if overflow/underflow happens 618 * 619 */ 610 * - now its the biggest or the smallest int 611 */ 620 612 uint64_t float64_to_uint64(float64 a) 621 613 { 622 if (is Float64NaN(a))614 if (is_float64_nan(a)) 623 615 return UINT64_MAX; 624 616 625 if (is Float64Infinity(a) || (a.parts.exp >= (64 + FLOAT64_BIAS))) {617 if (is_float64_infinity(a) || (a.parts.exp >= (64 + FLOAT64_BIAS))) { 626 618 if (a.parts.sign) 627 619 return UINT64_MIN; … … 633 625 } 634 626 635 /* 627 /* 636 628 * FIXME: Im not sure what to return if overflow/underflow happens 637 * 638 */ 629 * - now its the biggest or the smallest int 630 */ 639 631 int64_t float64_to_int64(float64 a) 640 632 { 641 if (is Float64NaN(a))633 if (is_float64_nan(a)) 642 634 return INT64_MAX; 643 635 644 if (is Float64Infinity(a) || (a.parts.exp >= (64 + FLOAT64_BIAS))) {636 if (is_float64_infinity(a) || (a.parts.exp >= (64 + FLOAT64_BIAS))) { 645 637 if (a.parts.sign) 646 638 return INT64_MIN; … … 652 644 } 653 645 654 655 /** 656 * Helping procedure for converting float128 to uint64. 646 /** Helper procedure for converting float128 to uint64. 657 647 * 658 648 * @param a Floating point number in normalized form … … 663 653 { 664 654 uint64_t frac_hi, frac_lo; 665 655 666 656 if (a.parts.exp < FLOAT128_BIAS) { 667 / *TODO: rounding*/657 // TODO: rounding 668 658 return 0; 669 659 } 670 660 671 661 frac_hi = a.parts.frac_hi; 672 662 frac_lo = a.parts.frac_lo; 673 663 674 664 frac_hi |= FLOAT128_HIDDEN_BIT_MASK_HI; 675 665 /* shift fraction to left so hidden bit will be the most significant bit */ 676 666 lshift128(frac_hi, frac_lo, 677 667 (128 - FLOAT128_FRACTION_SIZE - 1), &frac_hi, &frac_lo); 678 668 679 669 rshift128(frac_hi, frac_lo, 680 670 (128 - (a.parts.exp - FLOAT128_BIAS) - 1), &frac_hi, &frac_lo); … … 683 673 add128(frac_hi, frac_lo, 0x0ll, 0x1ll, &frac_hi, &frac_lo); 684 674 } 685 675 686 676 return frac_lo; 687 677 } … … 689 679 /* 690 680 * FIXME: Im not sure what to return if overflow/underflow happens 691 * 681 * - now its the biggest or the smallest int 692 682 */ 693 683 uint32_t float128_to_uint32(float128 a) 694 684 { 695 if (is Float128NaN(a))685 if (is_float128_nan(a)) 696 686 return UINT32_MAX; 697 698 if (is Float128Infinity(a) || (a.parts.exp >= (32 + FLOAT128_BIAS))) {687 688 if (is_float128_infinity(a) || (a.parts.exp >= (32 + FLOAT128_BIAS))) { 699 689 if (a.parts.sign) 700 690 return UINT32_MIN; 701 691 702 692 return UINT32_MAX; 703 693 } 704 694 705 695 return (uint32_t) _float128_to_uint64_helper(a); 706 696 } … … 708 698 /* 709 699 * FIXME: Im not sure what to return if overflow/underflow happens 710 * 700 * - now its the biggest or the smallest int 711 701 */ 712 702 int32_t float128_to_int32(float128 a) 713 703 { 714 if (is Float128NaN(a))704 if (is_float128_nan(a)) 715 705 return INT32_MAX; 716 717 if (is Float128Infinity(a) || (a.parts.exp >= (32 + FLOAT128_BIAS))) {706 707 if (is_float128_infinity(a) || (a.parts.exp >= (32 + FLOAT128_BIAS))) { 718 708 if (a.parts.sign) 719 709 return INT32_MIN; 720 710 721 711 return INT32_MAX; 722 712 } 723 713 724 714 return (int32_t) _float128_to_uint64_helper(a); 725 715 } 726 716 727 728 717 /* 729 718 * FIXME: Im not sure what to return if overflow/underflow happens 730 * 719 * - now its the biggest or the smallest int 731 720 */ 732 721 uint64_t float128_to_uint64(float128 a) 733 722 { 734 if (is Float128NaN(a))723 if (is_float128_nan(a)) 735 724 return UINT64_MAX; 736 737 if (is Float128Infinity(a) || (a.parts.exp >= (64 + FLOAT128_BIAS))) {725 726 if (is_float128_infinity(a) || (a.parts.exp >= (64 + FLOAT128_BIAS))) { 738 727 if (a.parts.sign) 739 728 return UINT64_MIN; 740 729 741 730 return UINT64_MAX; 742 731 } 743 732 744 733 return _float128_to_uint64_helper(a); 745 734 } … … 747 736 /* 748 737 * FIXME: Im not sure what to return if overflow/underflow happens 749 * 738 * - now its the biggest or the smallest int 750 739 */ 751 740 int64_t float128_to_int64(float128 a) 752 741 { 753 if (is Float128NaN(a))742 if (is_float128_nan(a)) 754 743 return INT64_MAX; 755 756 if (is Float128Infinity(a) || (a.parts.exp >= (64 + FLOAT128_BIAS))) {744 745 if (is_float128_infinity(a) || (a.parts.exp >= (64 + FLOAT128_BIAS))) { 757 746 if (a.parts.sign) 758 747 return INT64_MIN; 759 748 760 749 return INT64_MAX; 761 750 } 762 751 763 752 return _float128_to_uint64_helper(a); 764 753 } 765 766 754 767 755 float32 uint32_to_float32(uint32_t i) … … 773 761 result.parts.sign = 0; 774 762 result.parts.fraction = 0; 775 776 counter = count Zeroes32(i);777 763 764 counter = count_zeroes32(i); 765 778 766 exp = FLOAT32_BIAS + 32 - counter - 1; 779 767 780 768 if (counter == 32) { 781 result.bin ary= 0;769 result.bin = 0; 782 770 return result; 783 771 } … … 788 776 i >>= 1; 789 777 } 790 791 round Float32(&exp, &i);792 778 779 round_float32(&exp, &i); 780 793 781 result.parts.fraction = i >> (32 - FLOAT32_FRACTION_SIZE - 2); 794 782 result.parts.exp = exp; 795 796 return result; 797 } 798 799 float32 int32_to_float32(int32_t i) 783 784 return result; 785 } 786 787 float32 int32_to_float32(int32_t i) 800 788 { 801 789 float32 result; 802 803 if (i < 0) {790 791 if (i < 0) 804 792 result = uint32_to_float32((uint32_t) (-i)); 805 } else {793 else 806 794 result = uint32_to_float32((uint32_t) i); 807 }808 795 809 796 result.parts.sign = i < 0; 810 811 return result; 812 } 813 814 815 float32 uint64_to_float32(uint64_t i) 797 798 return result; 799 } 800 801 float32 uint64_to_float32(uint64_t i) 816 802 { 817 803 int counter; … … 822 808 result.parts.sign = 0; 823 809 result.parts.fraction = 0; 824 825 counter = count Zeroes64(i);826 810 811 counter = count_zeroes64(i); 812 827 813 exp = FLOAT32_BIAS + 64 - counter - 1; 828 814 829 815 if (counter == 64) { 830 result.bin ary= 0;816 result.bin = 0; 831 817 return result; 832 818 } … … 840 826 841 827 j = (uint32_t) i; 842 round Float32(&exp, &j);843 828 round_float32(&exp, &j); 829 844 830 result.parts.fraction = j >> (32 - FLOAT32_FRACTION_SIZE - 2); 845 831 result.parts.exp = exp; … … 847 833 } 848 834 849 float32 int64_to_float32(int64_t i) 835 float32 int64_to_float32(int64_t i) 850 836 { 851 837 float32 result; 852 853 if (i < 0) {838 839 if (i < 0) 854 840 result = uint64_to_float32((uint64_t) (-i)); 855 } else {841 else 856 842 result = uint64_to_float32((uint64_t) i); 857 }858 843 859 844 result.parts.sign = i < 0; 860 861 845 846 return result; 862 847 } 863 848 … … 871 856 result.parts.sign = 0; 872 857 result.parts.fraction = 0; 873 874 counter = count Zeroes32(i);875 858 859 counter = count_zeroes32(i); 860 876 861 exp = FLOAT64_BIAS + 32 - counter - 1; 877 862 878 863 if (counter == 32) { 879 result.bin ary= 0;864 result.bin = 0; 880 865 return result; 881 866 } 882 867 883 868 frac = i; 884 frac <<= counter + 32 - 1; 885 886 round Float64(&exp, &frac);887 869 frac <<= counter + 32 - 1; 870 871 round_float64(&exp, &frac); 872 888 873 result.parts.fraction = frac >> (64 - FLOAT64_FRACTION_SIZE - 2); 889 874 result.parts.exp = exp; 890 891 return result; 892 } 893 894 float64 int32_to_float64(int32_t i) 875 876 return result; 877 } 878 879 float64 int32_to_float64(int32_t i) 895 880 { 896 881 float64 result; 897 898 if (i < 0) {882 883 if (i < 0) 899 884 result = uint32_to_float64((uint32_t) (-i)); 900 } else {885 else 901 886 result = uint32_to_float64((uint32_t) i); 902 }903 887 904 888 result.parts.sign = i < 0; 905 906 907 } 908 909 910 float64 uint64_to_float64(uint64_t i) 889 890 return result; 891 } 892 893 894 float64 uint64_to_float64(uint64_t i) 911 895 { 912 896 int counter; … … 916 900 result.parts.sign = 0; 917 901 result.parts.fraction = 0; 918 919 counter = count Zeroes64(i);920 902 903 counter = count_zeroes64(i); 904 921 905 exp = FLOAT64_BIAS + 64 - counter - 1; 922 906 923 907 if (counter == 64) { 924 result.bin ary= 0;908 result.bin = 0; 925 909 return result; 926 910 } … … 931 915 i >>= 1; 932 916 } 933 934 round Float64(&exp, &i);935 917 918 round_float64(&exp, &i); 919 936 920 result.parts.fraction = i >> (64 - FLOAT64_FRACTION_SIZE - 2); 937 921 result.parts.exp = exp; … … 939 923 } 940 924 941 float64 int64_to_float64(int64_t i) 925 float64 int64_to_float64(int64_t i) 942 926 { 943 927 float64 result; 944 945 if (i < 0) {928 929 if (i < 0) 946 930 result = uint64_to_float64((uint64_t) (-i)); 947 } else {931 else 948 932 result = uint64_to_float64((uint64_t) i); 949 }950 933 951 934 result.parts.sign = i < 0; 952 953 return result; 954 } 955 935 936 return result; 937 } 956 938 957 939 float128 uint32_to_float128(uint32_t i) … … 961 943 float128 result; 962 944 uint64_t frac_hi, frac_lo; 963 945 964 946 result.parts.sign = 0; 965 947 result.parts.frac_hi = 0; 966 948 result.parts.frac_lo = 0; 967 968 counter = count Zeroes32(i);969 949 950 counter = count_zeroes32(i); 951 970 952 exp = FLOAT128_BIAS + 32 - counter - 1; 971 953 972 954 if (counter == 32) { 973 result.bin ary.hi = 0;974 result.bin ary.lo = 0;975 return result; 976 } 977 955 result.bin.hi = 0; 956 result.bin.lo = 0; 957 return result; 958 } 959 978 960 frac_hi = 0; 979 961 frac_lo = i; 980 962 lshift128(frac_hi, frac_lo, (counter + 96 - 1), &frac_hi, &frac_lo); 981 982 round Float128(&exp, &frac_hi, &frac_lo);983 963 964 round_float128(&exp, &frac_hi, &frac_lo); 965 984 966 rshift128(frac_hi, frac_lo, 985 967 (128 - FLOAT128_FRACTION_SIZE - 2), &frac_hi, &frac_lo); … … 987 969 result.parts.frac_lo = frac_lo; 988 970 result.parts.exp = exp; 989 971 990 972 return result; 991 973 } … … 994 976 { 995 977 float128 result; 996 997 if (i < 0) {978 979 if (i < 0) 998 980 result = uint32_to_float128((uint32_t) (-i)); 999 } else {981 else 1000 982 result = uint32_to_float128((uint32_t) i); 1001 } 1002 983 1003 984 result.parts.sign = i < 0; 1004 1005 985 986 return result; 1006 987 } 1007 988 … … 1013 994 float128 result; 1014 995 uint64_t frac_hi, frac_lo; 1015 996 1016 997 result.parts.sign = 0; 1017 998 result.parts.frac_hi = 0; 1018 999 result.parts.frac_lo = 0; 1019 1020 counter = count Zeroes64(i);1021 1000 1001 counter = count_zeroes64(i); 1002 1022 1003 exp = FLOAT128_BIAS + 64 - counter - 1; 1023 1004 1024 1005 if (counter == 64) { 1025 result.bin ary.hi = 0;1026 result.bin ary.lo = 0;1027 return result; 1028 } 1029 1006 result.bin.hi = 0; 1007 result.bin.lo = 0; 1008 return result; 1009 } 1010 1030 1011 frac_hi = 0; 1031 1012 frac_lo = i; 1032 1013 lshift128(frac_hi, frac_lo, (counter + 64 - 1), &frac_hi, &frac_lo); 1033 1034 round Float128(&exp, &frac_hi, &frac_lo);1035 1014 1015 round_float128(&exp, &frac_hi, &frac_lo); 1016 1036 1017 rshift128(frac_hi, frac_lo, 1037 1018 (128 - FLOAT128_FRACTION_SIZE - 2), &frac_hi, &frac_lo); … … 1039 1020 result.parts.frac_lo = frac_lo; 1040 1021 result.parts.exp = exp; 1041 1022 1042 1023 return result; 1043 1024 } … … 1046 1027 { 1047 1028 float128 result; 1048 1049 if (i < 0) {1029 1030 if (i < 0) 1050 1031 result = uint64_to_float128((uint64_t) (-i)); 1051 } else {1032 else 1052 1033 result = uint64_to_float128((uint64_t) i); 1053 } 1054 1034 1055 1035 result.parts.sign = i < 0; 1056 1057 1036 1037 return result; 1058 1038 } 1059 1039 -
uspace/lib/softfloat/generic/div.c
rd9f53877 r90924df 41 41 #include <common.h> 42 42 43 /** 44 * Divide two single-precision floats. 45 * 43 /** Divide two single-precision floats. 44 * 46 45 * @param a Nominator. 47 46 * @param b Denominator. 47 * 48 48 * @return Result of division. 49 */ 50 float32 divFloat32(float32 a, float32 b) 49 * 50 */ 51 float32 div_float32(float32 a, float32 b) 51 52 { 52 53 float32 result; … … 56 57 result.parts.sign = a.parts.sign ^ b.parts.sign; 57 58 58 if (is Float32NaN(a)) {59 if (is Float32SigNaN(a)) {60 / *FIXME: SigNaN*/61 } 62 /* NaN*/59 if (is_float32_nan(a)) { 60 if (is_float32_signan(a)) { 61 // FIXME: SigNaN 62 } 63 /* NaN */ 63 64 return a; 64 65 } 65 66 66 if (is Float32NaN(b)) {67 if (is Float32SigNaN(b)) {68 / *FIXME: SigNaN*/69 } 70 /* NaN*/67 if (is_float32_nan(b)) { 68 if (is_float32_signan(b)) { 69 // FIXME: SigNaN 70 } 71 /* NaN */ 71 72 return b; 72 73 } 73 74 74 if (is Float32Infinity(a)) {75 if (is Float32Infinity(b)) {75 if (is_float32_infinity(a)) { 76 if (is_float32_infinity(b)) { 76 77 /*FIXME: inf / inf */ 77 result.bin ary= FLOAT32_NAN;78 result.bin = FLOAT32_NAN; 78 79 return result; 79 80 } … … 83 84 return result; 84 85 } 85 86 if (is Float32Infinity(b)) {87 if (is Float32Zero(a)) {86 87 if (is_float32_infinity(b)) { 88 if (is_float32_zero(a)) { 88 89 /* FIXME 0 / inf */ 89 90 result.parts.exp = 0; … … 97 98 } 98 99 99 if (is Float32Zero(b)) {100 if (is Float32Zero(a)) {100 if (is_float32_zero(b)) { 101 if (is_float32_zero(a)) { 101 102 /*FIXME: 0 / 0*/ 102 result.bin ary= FLOAT32_NAN;103 result.bin = FLOAT32_NAN; 103 104 return result; 104 105 } … … 121 122 return result; 122 123 } 123 124 124 125 /* normalize it*/ 125 126 afrac <<= 1; 126 /* afrac is nonzero => it must stop */ 127 /* afrac is nonzero => it must stop */ 127 128 while (!(afrac & FLOAT32_HIDDEN_BIT_MASK)) { 128 129 afrac <<= 1; … … 130 131 } 131 132 } 132 133 133 134 if (bexp == 0) { 134 135 bfrac <<= 1; 135 /* bfrac is nonzero => it must stop */ 136 /* bfrac is nonzero => it must stop */ 136 137 while (!(bfrac & FLOAT32_HIDDEN_BIT_MASK)) { 137 138 bfrac <<= 1; … … 139 140 } 140 141 } 141 142 afrac = 143 bfrac = 144 142 143 afrac = (afrac | FLOAT32_HIDDEN_BIT_MASK) << (32 - FLOAT32_FRACTION_SIZE - 1); 144 bfrac = (bfrac | FLOAT32_HIDDEN_BIT_MASK) << (32 - FLOAT32_FRACTION_SIZE); 145 145 146 if (bfrac <= (afrac << 1)) { 146 147 afrac >>= 1; … … 169 170 ++cexp; 170 171 cfrac >>= 1; 171 } 172 172 } 173 173 174 /* check overflow */ 174 175 if (cexp >= FLOAT32_MAX_EXPONENT) { … … 178 179 return result; 179 180 } 180 181 181 182 if (cexp < 0) { 182 183 /* FIXME: underflow */ … … 190 191 cexp++; 191 192 cfrac >>= 1; 192 } 193 } 193 194 } else { 194 195 result.parts.exp = (uint32_t) cexp; … … 197 198 result.parts.fraction = ((cfrac >> 6) & (~FLOAT32_HIDDEN_BIT_MASK)); 198 199 199 return result; 200 return result; 200 201 } 201 202 202 /** 203 * Divide two double-precision floats. 203 /** Divide two double-precision floats. 204 204 * 205 205 * @param a Nominator. 206 206 * @param b Denominator. 207 * 207 208 * @return Result of division. 208 */ 209 float64 divFloat64(float64 a, float64 b) 209 * 210 */ 211 float64 div_float64(float64 a, float64 b) 210 212 { 211 213 float64 result; … … 217 219 result.parts.sign = a.parts.sign ^ b.parts.sign; 218 220 219 if (is Float64NaN(a)) {220 if (is Float64SigNaN(b)) {221 / *FIXME: SigNaN*/221 if (is_float64_nan(a)) { 222 if (is_float64_signan(b)) { 223 // FIXME: SigNaN 222 224 return b; 223 225 } 224 226 225 if (is Float64SigNaN(a)) {226 / *FIXME: SigNaN*/227 } 228 /* NaN*/227 if (is_float64_signan(a)) { 228 // FIXME: SigNaN 229 } 230 /* NaN */ 229 231 return a; 230 232 } 231 233 232 if (is Float64NaN(b)) {233 if (is Float64SigNaN(b)) {234 / *FIXME: SigNaN*/235 } 236 /* NaN*/234 if (is_float64_nan(b)) { 235 if (is_float64_signan(b)) { 236 // FIXME: SigNaN 237 } 238 /* NaN */ 237 239 return b; 238 240 } 239 241 240 if (is Float64Infinity(a)) {241 if (is Float64Infinity(b) || isFloat64Zero(b)) {242 / *FIXME: inf / inf */243 result.bin ary= FLOAT64_NAN;242 if (is_float64_infinity(a)) { 243 if (is_float64_infinity(b) || is_float64_zero(b)) { 244 // FIXME: inf / inf 245 result.bin = FLOAT64_NAN; 244 246 return result; 245 247 } … … 249 251 return result; 250 252 } 251 252 if (is Float64Infinity(b)) {253 if (is Float64Zero(a)) {253 254 if (is_float64_infinity(b)) { 255 if (is_float64_zero(a)) { 254 256 /* FIXME 0 / inf */ 255 257 result.parts.exp = 0; … … 263 265 } 264 266 265 if (is Float64Zero(b)) {266 if (is Float64Zero(a)) {267 if (is_float64_zero(b)) { 268 if (is_float64_zero(a)) { 267 269 /*FIXME: 0 / 0*/ 268 result.bin ary= FLOAT64_NAN;270 result.bin = FLOAT64_NAN; 269 271 return result; 270 272 } … … 274 276 return result; 275 277 } 276 278 277 279 afrac = a.parts.fraction; 278 280 aexp = a.parts.exp; … … 287 289 return result; 288 290 } 289 291 290 292 /* normalize it*/ 291 293 aexp++; … … 296 298 } 297 299 } 298 300 299 301 if (bexp == 0) { 300 302 bexp++; … … 305 307 } 306 308 } 307 308 afrac = 309 bfrac = 310 309 310 afrac = (afrac | FLOAT64_HIDDEN_BIT_MASK) << (64 - FLOAT64_FRACTION_SIZE - 2); 311 bfrac = (bfrac | FLOAT64_HIDDEN_BIT_MASK) << (64 - FLOAT64_FRACTION_SIZE - 1); 312 311 313 if (bfrac <= (afrac << 1)) { 312 314 afrac >>= 1; … … 330 332 331 333 /* round and shift */ 332 result = finish Float64(cexp, cfrac, result.parts.sign);334 result = finish_float64(cexp, cfrac, result.parts.sign); 333 335 return result; 334 336 } 335 337 336 /** 337 * Divide two quadruple-precision floats. 338 /** Divide two quadruple-precision floats. 338 339 * 339 340 * @param a Nominator. 340 341 * @param b Denominator. 342 * 341 343 * @return Result of division. 342 */ 343 float128 divFloat128(float128 a, float128 b) 344 * 345 */ 346 float128 div_float128(float128 a, float128 b) 344 347 { 345 348 float128 result; … … 349 352 uint64_t rem_hihi, rem_hilo, rem_lohi, rem_lolo; 350 353 uint64_t tmp_hihi, tmp_hilo, tmp_lohi, tmp_lolo; 351 354 352 355 result.parts.sign = a.parts.sign ^ b.parts.sign; 353 354 if (is Float128NaN(a)) {355 if (is Float128SigNaN(b)) {356 / *FIXME: SigNaN*/356 357 if (is_float128_nan(a)) { 358 if (is_float128_signan(b)) { 359 // FIXME: SigNaN 357 360 return b; 358 361 } 359 360 if (is Float128SigNaN(a)) {361 / *FIXME: SigNaN*/362 } 363 /* NaN*/362 363 if (is_float128_signan(a)) { 364 // FIXME: SigNaN 365 } 366 /* NaN */ 364 367 return a; 365 368 } 366 367 if (is Float128NaN(b)) {368 if (is Float128SigNaN(b)) {369 / *FIXME: SigNaN*/370 } 371 /* NaN*/369 370 if (is_float128_nan(b)) { 371 if (is_float128_signan(b)) { 372 // FIXME: SigNaN 373 } 374 /* NaN */ 372 375 return b; 373 376 } 374 375 if (is Float128Infinity(a)) {376 if (is Float128Infinity(b) || isFloat128Zero(b)) {377 / *FIXME: inf / inf */378 result.bin ary.hi = FLOAT128_NAN_HI;379 result.bin ary.lo = FLOAT128_NAN_LO;377 378 if (is_float128_infinity(a)) { 379 if (is_float128_infinity(b) || is_float128_zero(b)) { 380 // FIXME: inf / inf 381 result.bin.hi = FLOAT128_NAN_HI; 382 result.bin.lo = FLOAT128_NAN_LO; 380 383 return result; 381 384 } … … 386 389 return result; 387 390 } 388 389 if (is Float128Infinity(b)) {390 if (is Float128Zero(a)) {391 / * FIXME 0 / inf */391 392 if (is_float128_infinity(b)) { 393 if (is_float128_zero(a)) { 394 // FIXME 0 / inf 392 395 result.parts.exp = 0; 393 396 result.parts.frac_hi = 0; … … 395 398 return result; 396 399 } 397 / * FIXME: num / inf*/400 // FIXME: num / inf 398 401 result.parts.exp = 0; 399 402 result.parts.frac_hi = 0; … … 401 404 return result; 402 405 } 403 404 if (is Float128Zero(b)) {405 if (is Float128Zero(a)) {406 / *FIXME: 0 / 0*/407 result.bin ary.hi = FLOAT128_NAN_HI;408 result.bin ary.lo = FLOAT128_NAN_LO;409 return result; 410 } 411 / * FIXME: division by zero */406 407 if (is_float128_zero(b)) { 408 if (is_float128_zero(a)) { 409 // FIXME: 0 / 0 410 result.bin.hi = FLOAT128_NAN_HI; 411 result.bin.lo = FLOAT128_NAN_LO; 412 return result; 413 } 414 // FIXME: division by zero 412 415 result.parts.exp = 0; 413 416 result.parts.frac_hi = 0; … … 415 418 return result; 416 419 } 417 420 418 421 afrac_hi = a.parts.frac_hi; 419 422 afrac_lo = a.parts.frac_lo; … … 422 425 bfrac_lo = b.parts.frac_lo; 423 426 bexp = b.parts.exp; 424 427 425 428 /* denormalized numbers */ 426 429 if (aexp == 0) { … … 431 434 return result; 432 435 } 433 436 434 437 /* normalize it*/ 435 438 aexp++; … … 443 446 } 444 447 } 445 448 446 449 if (bexp == 0) { 447 450 bexp++; … … 455 458 } 456 459 } 457 460 458 461 or128(afrac_hi, afrac_lo, 459 462 FLOAT128_HIDDEN_BIT_MASK_HI, FLOAT128_HIDDEN_BIT_MASK_LO, … … 466 469 lshift128(bfrac_hi, bfrac_lo, 467 470 (128 - FLOAT128_FRACTION_SIZE - 1), &bfrac_hi, &bfrac_lo); 468 471 469 472 if (le128(bfrac_hi, bfrac_lo, afrac_hi, afrac_lo)) { 470 473 rshift128(afrac_hi, afrac_lo, 1, &afrac_hi, &afrac_lo); 471 474 aexp++; 472 475 } 473 476 474 477 cexp = aexp - bexp + FLOAT128_BIAS - 2; 475 478 476 479 cfrac_hi = div128est(afrac_hi, afrac_lo, bfrac_hi); 477 480 478 481 mul128(bfrac_hi, bfrac_lo, 0x0ll, cfrac_hi, 479 482 &tmp_lolo /* dummy */, &tmp_hihi, &tmp_hilo, &tmp_lohi); 480 481 /* sub192(afrac_hi, afrac_lo, 0, 483 484 /* sub192(afrac_hi, afrac_lo, 0, 482 485 * tmp_hihi, tmp_hilo, tmp_lohi 483 486 * &rem_hihi, &rem_hilo, &rem_lohi); */ … … 487 490 } 488 491 rem_lohi = -tmp_lohi; 489 492 490 493 while ((int64_t) rem_hihi < 0) { 491 494 --cfrac_hi; 492 /* add192(rem_hihi, rem_hilo, rem_lohi, 495 /* add192(rem_hihi, rem_hilo, rem_lohi, 493 496 * 0, bfrac_hi, bfrac_lo, 494 497 * &rem_hihi, &rem_hilo, &rem_lohi); */ … … 498 501 } 499 502 } 500 503 501 504 cfrac_lo = div128est(rem_hilo, rem_lohi, bfrac_lo); 502 505 503 506 if ((cfrac_lo & 0x3FFF) <= 4) { 504 507 mul128(bfrac_hi, bfrac_lo, 0x0ll, cfrac_lo, 505 506 508 &tmp_hihi /* dummy */, &tmp_hilo, &tmp_lohi, &tmp_lolo); 509 507 510 /* sub192(rem_hilo, rem_lohi, 0, 508 511 * tmp_hilo, tmp_lohi, tmp_lolo, … … 513 516 } 514 517 rem_lolo = -tmp_lolo; 515 518 516 519 while ((int64_t) rem_hilo < 0) { 517 520 --cfrac_lo; … … 524 527 } 525 528 } 526 529 527 530 cfrac_lo |= ((rem_hilo | rem_lohi | rem_lolo) != 0 ); 528 531 } 529 532 530 533 shift_out = cfrac_lo << (64 - (128 - FLOAT128_FRACTION_SIZE - 1)); 531 534 rshift128(cfrac_hi, cfrac_lo, (128 - FLOAT128_FRACTION_SIZE - 1), 532 535 &cfrac_hi, &cfrac_lo); 533 534 result = finish Float128(cexp, cfrac_hi, cfrac_lo, result.parts.sign, shift_out);536 537 result = finish_float128(cexp, cfrac_hi, cfrac_lo, result.parts.sign, shift_out); 535 538 return result; 536 539 } -
uspace/lib/softfloat/generic/mul.c
rd9f53877 r90924df 39 39 #include <common.h> 40 40 41 /** 42 * Multiply two single-precision floats. 41 /** Multiply two single-precision floats. 43 42 * 44 43 * @param a First input operand. 45 44 * @param b Second input operand. 45 * 46 46 * @return Result of multiplication. 47 */ 48 float32 mulFloat32(float32 a, float32 b) 47 * 48 */ 49 float32 mul_float32(float32 a, float32 b) 49 50 { 50 51 float32 result; 51 52 uint64_t frac1, frac2; 52 53 int32_t exp; 53 54 54 55 result.parts.sign = a.parts.sign ^ b.parts.sign; 55 56 56 if (is Float32NaN(a) || isFloat32NaN(b)) {57 if (is_float32_nan(a) || is_float32_nan(b)) { 57 58 /* TODO: fix SigNaNs */ 58 if (is Float32SigNaN(a)) {59 if (is_float32_signan(a)) { 59 60 result.parts.fraction = a.parts.fraction; 60 61 result.parts.exp = a.parts.exp; 61 62 return result; 62 63 } 63 if (is Float32SigNaN(b)) { /* TODO: fix SigNaN */64 if (is_float32_signan(b)) { /* TODO: fix SigNaN */ 64 65 result.parts.fraction = b.parts.fraction; 65 66 result.parts.exp = b.parts.exp; … … 67 68 } 68 69 /* set NaN as result */ 69 result.bin ary= FLOAT32_NAN;70 return result; 71 } 72 73 if (is Float32Infinity(a)) {74 if (is Float32Zero(b)) {75 /* FIXME: zero * infinity */ 76 result.bin ary= FLOAT32_NAN;70 result.bin = FLOAT32_NAN; 71 return result; 72 } 73 74 if (is_float32_infinity(a)) { 75 if (is_float32_zero(b)) { 76 /* FIXME: zero * infinity */ 77 result.bin = FLOAT32_NAN; 77 78 return result; 78 79 } … … 81 82 return result; 82 83 } 83 84 if (is Float32Infinity(b)) {85 if (is Float32Zero(a)) {86 /* FIXME: zero * infinity */ 87 result.bin ary= FLOAT32_NAN;84 85 if (is_float32_infinity(b)) { 86 if (is_float32_zero(a)) { 87 /* FIXME: zero * infinity */ 88 result.bin = FLOAT32_NAN; 88 89 return result; 89 90 } … … 92 93 return result; 93 94 } 94 95 95 96 /* exp is signed so we can easy detect underflow */ 96 97 exp = a.parts.exp + b.parts.exp; … … 100 101 /* FIXME: overflow */ 101 102 /* set infinity as result */ 102 result.bin ary= FLOAT32_INF;103 result.bin = FLOAT32_INF; 103 104 result.parts.sign = a.parts.sign ^ b.parts.sign; 104 105 return result; … … 121 122 122 123 frac2 = b.parts.fraction; 123 124 124 125 if (b.parts.exp > 0) { 125 126 frac2 |= FLOAT32_HIDDEN_BIT_MASK; … … 127 128 ++exp; 128 129 } 129 130 130 131 frac1 <<= 1; /* one bit space for rounding */ 131 132 132 133 frac1 = frac1 * frac2; 133 134 134 135 /* round and return */ 135 while ((exp < FLOAT32_MAX_EXPONENT) && (frac1 >= (1 << (FLOAT32_FRACTION_SIZE + 2)))) { 136 while ((exp < FLOAT32_MAX_EXPONENT) && 137 (frac1 >= (1 << (FLOAT32_FRACTION_SIZE + 2)))) { 136 138 /* 23 bits of fraction + one more for hidden bit (all shifted 1 bit left) */ 137 139 ++exp; 138 140 frac1 >>= 1; 139 141 } 140 142 141 143 /* rounding */ 142 144 /* ++frac1; FIXME: not works - without it is ok */ 143 145 frac1 >>= 1; /* shift off rounding space */ 144 146 145 if ((exp < FLOAT32_MAX_EXPONENT) && (frac1 >= (1 << (FLOAT32_FRACTION_SIZE + 1)))) { 147 if ((exp < FLOAT32_MAX_EXPONENT) && 148 (frac1 >= (1 << (FLOAT32_FRACTION_SIZE + 1)))) { 146 149 ++exp; 147 150 frac1 >>= 1; 148 151 } 149 150 if (exp >= FLOAT32_MAX_EXPONENT) { 152 153 if (exp >= FLOAT32_MAX_EXPONENT) { 151 154 /* TODO: fix overflow */ 152 155 /* return infinity*/ … … 157 160 158 161 exp -= FLOAT32_FRACTION_SIZE; 159 160 if (exp <= FLOAT32_FRACTION_SIZE) { 162 163 if (exp <= FLOAT32_FRACTION_SIZE) { 161 164 /* denormalized number */ 162 165 frac1 >>= 1; /* denormalize */ … … 175 178 result.parts.fraction = frac1 & ((1 << FLOAT32_FRACTION_SIZE) - 1); 176 179 177 return result; 180 return result; 178 181 } 179 182 180 /** 181 * Multiply two double-precision floats. 183 /** Multiply two double-precision floats. 182 184 * 183 185 * @param a First input operand. 184 186 * @param b Second input operand. 187 * 185 188 * @return Result of multiplication. 186 */ 187 float64 mulFloat64(float64 a, float64 b) 189 * 190 */ 191 float64 mul_float64(float64 a, float64 b) 188 192 { 189 193 float64 result; 190 194 uint64_t frac1, frac2; 191 195 int32_t exp; 192 196 193 197 result.parts.sign = a.parts.sign ^ b.parts.sign; 194 198 195 if (is Float64NaN(a) || isFloat64NaN(b)) {199 if (is_float64_nan(a) || is_float64_nan(b)) { 196 200 /* TODO: fix SigNaNs */ 197 if (is Float64SigNaN(a)) {201 if (is_float64_signan(a)) { 198 202 result.parts.fraction = a.parts.fraction; 199 203 result.parts.exp = a.parts.exp; 200 204 return result; 201 205 } 202 if (is Float64SigNaN(b)) { /* TODO: fix SigNaN */206 if (is_float64_signan(b)) { /* TODO: fix SigNaN */ 203 207 result.parts.fraction = b.parts.fraction; 204 208 result.parts.exp = b.parts.exp; … … 206 210 } 207 211 /* set NaN as result */ 208 result.bin ary= FLOAT64_NAN;209 return result; 210 } 211 212 if (is Float64Infinity(a)) {213 if (is Float64Zero(b)) {214 /* FIXME: zero * infinity */ 215 result.bin ary= FLOAT64_NAN;212 result.bin = FLOAT64_NAN; 213 return result; 214 } 215 216 if (is_float64_infinity(a)) { 217 if (is_float64_zero(b)) { 218 /* FIXME: zero * infinity */ 219 result.bin = FLOAT64_NAN; 216 220 return result; 217 221 } … … 220 224 return result; 221 225 } 222 223 if (is Float64Infinity(b)) {224 if (is Float64Zero(a)) {225 /* FIXME: zero * infinity */ 226 result.bin ary= FLOAT64_NAN;226 227 if (is_float64_infinity(b)) { 228 if (is_float64_zero(a)) { 229 /* FIXME: zero * infinity */ 230 result.bin = FLOAT64_NAN; 227 231 return result; 228 232 } … … 231 235 return result; 232 236 } 233 237 234 238 /* exp is signed so we can easy detect underflow */ 235 239 exp = a.parts.exp + b.parts.exp - FLOAT64_BIAS; 236 240 237 241 frac1 = a.parts.fraction; 238 242 239 243 if (a.parts.exp > 0) { 240 244 frac1 |= FLOAT64_HIDDEN_BIT_MASK; … … 244 248 245 249 frac2 = b.parts.fraction; 246 250 247 251 if (b.parts.exp > 0) { 248 252 frac2 |= FLOAT64_HIDDEN_BIT_MASK; … … 250 254 ++exp; 251 255 } 252 256 253 257 frac1 <<= (64 - FLOAT64_FRACTION_SIZE - 1); 254 258 frac2 <<= (64 - FLOAT64_FRACTION_SIZE - 2); 255 259 256 260 mul64(frac1, frac2, &frac1, &frac2); 257 261 258 262 frac1 |= (frac2 != 0); 259 263 if (frac1 & (0x1ll << 62)) { … … 261 265 exp--; 262 266 } 263 264 result = finish Float64(exp, frac1, result.parts.sign);267 268 result = finish_float64(exp, frac1, result.parts.sign); 265 269 return result; 266 270 } 267 271 268 /** 269 * Multiply two quadruple-precision floats. 272 /** Multiply two quadruple-precision floats. 270 273 * 271 274 * @param a First input operand. 272 275 * @param b Second input operand. 276 * 273 277 * @return Result of multiplication. 274 */ 275 float128 mulFloat128(float128 a, float128 b) 278 * 279 */ 280 float128 mul_float128(float128 a, float128 b) 276 281 { 277 282 float128 result; 278 283 uint64_t frac1_hi, frac1_lo, frac2_hi, frac2_lo, tmp_hi, tmp_lo; 279 284 int32_t exp; 280 285 281 286 result.parts.sign = a.parts.sign ^ b.parts.sign; 282 283 if (is Float128NaN(a) || isFloat128NaN(b)) {287 288 if (is_float128_nan(a) || is_float128_nan(b)) { 284 289 /* TODO: fix SigNaNs */ 285 if (is Float128SigNaN(a)) {290 if (is_float128_signan(a)) { 286 291 result.parts.frac_hi = a.parts.frac_hi; 287 292 result.parts.frac_lo = a.parts.frac_lo; … … 289 294 return result; 290 295 } 291 if (is Float128SigNaN(b)) { /* TODO: fix SigNaN */296 if (is_float128_signan(b)) { /* TODO: fix SigNaN */ 292 297 result.parts.frac_hi = b.parts.frac_hi; 293 298 result.parts.frac_lo = b.parts.frac_lo; … … 296 301 } 297 302 /* set NaN as result */ 298 result.bin ary.hi = FLOAT128_NAN_HI;299 result.bin ary.lo = FLOAT128_NAN_LO;300 return result; 301 } 302 303 if (is Float128Infinity(a)) {304 if (is Float128Zero(b)) {305 /* FIXME: zero * infinity */ 306 result.bin ary.hi = FLOAT128_NAN_HI;307 result.bin ary.lo = FLOAT128_NAN_LO;303 result.bin.hi = FLOAT128_NAN_HI; 304 result.bin.lo = FLOAT128_NAN_LO; 305 return result; 306 } 307 308 if (is_float128_infinity(a)) { 309 if (is_float128_zero(b)) { 310 /* FIXME: zero * infinity */ 311 result.bin.hi = FLOAT128_NAN_HI; 312 result.bin.lo = FLOAT128_NAN_LO; 308 313 return result; 309 314 } … … 313 318 return result; 314 319 } 315 316 if (is Float128Infinity(b)) {317 if (is Float128Zero(a)) {318 /* FIXME: zero * infinity */ 319 result.bin ary.hi = FLOAT128_NAN_HI;320 result.bin ary.lo = FLOAT128_NAN_LO;320 321 if (is_float128_infinity(b)) { 322 if (is_float128_zero(a)) { 323 /* FIXME: zero * infinity */ 324 result.bin.hi = FLOAT128_NAN_HI; 325 result.bin.lo = FLOAT128_NAN_LO; 321 326 return result; 322 327 } … … 326 331 return result; 327 332 } 328 333 329 334 /* exp is signed so we can easy detect underflow */ 330 335 exp = a.parts.exp + b.parts.exp - FLOAT128_BIAS - 1; 331 336 332 337 frac1_hi = a.parts.frac_hi; 333 338 frac1_lo = a.parts.frac_lo; 334 339 335 340 if (a.parts.exp > 0) { 336 341 or128(frac1_hi, frac1_lo, 337 338 339 } else { 340 ++exp; 341 } 342 342 FLOAT128_HIDDEN_BIT_MASK_HI, FLOAT128_HIDDEN_BIT_MASK_LO, 343 &frac1_hi, &frac1_lo); 344 } else { 345 ++exp; 346 } 347 343 348 frac2_hi = b.parts.frac_hi; 344 349 frac2_lo = b.parts.frac_lo; 345 350 346 351 if (b.parts.exp > 0) { 347 352 or128(frac2_hi, frac2_lo, … … 351 356 ++exp; 352 357 } 353 358 354 359 lshift128(frac2_hi, frac2_lo, 355 360 128 - FLOAT128_FRACTION_SIZE, &frac2_hi, &frac2_lo); 356 361 357 362 tmp_hi = frac1_hi; 358 363 tmp_lo = frac1_lo; … … 361 366 add128(frac1_hi, frac1_lo, tmp_hi, tmp_lo, &frac1_hi, &frac1_lo); 362 367 frac2_hi |= (frac2_lo != 0x0ll); 363 368 364 369 if ((FLOAT128_HIDDEN_BIT_MASK_HI << 1) <= frac1_hi) { 365 370 frac2_hi >>= 1; … … 370 375 ++exp; 371 376 } 372 373 result = finish Float128(exp, frac1_hi, frac1_lo, result.parts.sign, frac2_hi);377 378 result = finish_float128(exp, frac1_hi, frac1_lo, result.parts.sign, frac2_hi); 374 379 return result; 375 380 } -
uspace/lib/softfloat/generic/softfloat.c
rd9f53877 r90924df 48 48 #include <other.h> 49 49 50 #include <functions.h>51 52 50 /* Arithmetic functions */ 53 51 54 52 float __addsf3(float a, float b) 55 53 { 56 float32 fa, fb; 57 fa.f = a; 58 fb.f = b; 59 if (fa.parts.sign != fb.parts.sign) { 60 if (fa.parts.sign) { 61 fa.parts.sign = 0; 62 return subFloat32(fb, fa).f; 63 }; 64 fb.parts.sign = 0; 65 return subFloat32(fa, fb).f; 66 } 67 return addFloat32(fa, fb).f; 54 float_t fa; 55 float_t fb; 56 float_t res; 57 58 fa.val = a; 59 fb.val = b; 60 61 if (fa.data.parts.sign != fb.data.parts.sign) { 62 if (fa.data.parts.sign) { 63 fa.data.parts.sign = 0; 64 res.data = sub_float(fb.data, fa.data); 65 66 return res.val; 67 } 68 69 fb.data.parts.sign = 0; 70 res.data = sub_float(fa.data, fb.data); 71 72 return res.val; 73 } 74 75 res.data = add_float(fa.data, fb.data); 76 return res.val; 68 77 } 69 78 70 79 double __adddf3(double a, double b) 71 80 { 72 float64 da, db; 73 da.d = a; 74 db.d = b; 75 if (da.parts.sign != db.parts.sign) { 76 if (da.parts.sign) { 77 da.parts.sign = 0; 78 return subFloat64(db, da).d; 79 }; 80 db.parts.sign = 0; 81 return subFloat64(da, db).d; 82 } 83 return addFloat64(da, db).d; 81 double_t da; 82 double_t db; 83 double_t res; 84 85 da.val = a; 86 db.val = b; 87 88 if (da.data.parts.sign != db.data.parts.sign) { 89 if (da.data.parts.sign) { 90 da.data.parts.sign = 0; 91 res.data = sub_double(db.data, da.data); 92 93 return res.val; 94 } 95 96 db.data.parts.sign = 0; 97 res.data = sub_double(da.data, db.data); 98 99 return res.val; 100 } 101 102 res.data = add_double(da.data, db.data); 103 return res.val; 84 104 } 85 105 86 106 long double __addtf3(long double a, long double b) 87 107 { 88 float128 ta, tb; 89 ta.ld = a; 90 tb.ld = b; 91 if (ta.parts.sign != tb.parts.sign) { 92 if (ta.parts.sign) { 93 ta.parts.sign = 0; 94 return subFloat128(tb, ta).ld; 95 }; 96 tb.parts.sign = 0; 97 return subFloat128(ta, tb).ld; 98 } 99 return addFloat128(ta, tb).ld; 108 long_double_t ta; 109 long_double_t tb; 110 long_double_t res; 111 112 ta.val = a; 113 tb.val = b; 114 115 if (ta.data.parts.sign != tb.data.parts.sign) { 116 if (ta.data.parts.sign) { 117 ta.data.parts.sign = 0; 118 res.data = sub_long_double(tb.data, ta.data); 119 120 return res.val; 121 } 122 123 tb.data.parts.sign = 0; 124 res.data = sub_long_double(ta.data, tb.data); 125 126 return res.val; 127 } 128 129 res.data = add_long_double(ta.data, tb.data); 130 return res.val; 100 131 } 101 132 102 133 float __subsf3(float a, float b) 103 134 { 104 float32 fa, fb; 105 fa.f = a; 106 fb.f = b; 107 if (fa.parts.sign != fb.parts.sign) { 108 fb.parts.sign = !fb.parts.sign; 109 return addFloat32(fa, fb).f; 110 } 111 return subFloat32(fa, fb).f; 135 float_t fa; 136 float_t fb; 137 float_t res; 138 139 fa.val = a; 140 fb.val = b; 141 142 if (fa.data.parts.sign != fb.data.parts.sign) { 143 fb.data.parts.sign = !fb.data.parts.sign; 144 res.data = add_float(fa.data, fb.data); 145 146 return res.val; 147 } 148 149 res.data = sub_float(fa.data, fb.data); 150 return res.val; 112 151 } 113 152 114 153 double __subdf3(double a, double b) 115 154 { 116 float64 da, db; 117 da.d = a; 118 db.d = b; 119 if (da.parts.sign != db.parts.sign) { 120 db.parts.sign = !db.parts.sign; 121 return addFloat64(da, db).d; 122 } 123 return subFloat64(da, db).d; 155 double_t da; 156 double_t db; 157 double_t res; 158 159 da.val = a; 160 db.val = b; 161 162 if (da.data.parts.sign != db.data.parts.sign) { 163 db.data.parts.sign = !db.data.parts.sign; 164 res.data = add_double(da.data, db.data); 165 166 return res.val; 167 } 168 169 res.data = sub_double(da.data, db.data); 170 return res.val; 124 171 } 125 172 126 173 long double __subtf3(long double a, long double b) 127 174 { 128 float128 ta, tb; 129 ta.ld = a; 130 tb.ld = b; 131 if (ta.parts.sign != tb.parts.sign) { 132 tb.parts.sign = !tb.parts.sign; 133 return addFloat128(ta, tb).ld; 134 } 135 return subFloat128(ta, tb).ld; 136 } 137 138 float __mulsf3(float a, float b) 139 { 140 float32 fa, fb; 141 fa.f = a; 142 fb.f = b; 143 return mulFloat32(fa, fb).f; 144 } 145 146 double __muldf3(double a, double b) 147 { 148 float64 da, db; 149 da.d = a; 150 db.d = b; 151 return mulFloat64(da, db).d; 175 long_double_t ta; 176 long_double_t tb; 177 long_double_t res; 178 179 ta.val = a; 180 tb.val = b; 181 182 if (ta.data.parts.sign != tb.data.parts.sign) { 183 tb.data.parts.sign = !tb.data.parts.sign; 184 res.data = add_long_double(ta.data, tb.data); 185 186 return res.val; 187 } 188 189 res.data = sub_long_double(ta.data, tb.data); 190 return res.val; 191 } 192 193 float __mulsf3(float a, float b) 194 { 195 float_t fa; 196 float_t fb; 197 float_t res; 198 199 fa.val = a; 200 fb.val = b; 201 202 res.data = mul_float(fa.data, fb.data); 203 return res.val; 204 } 205 206 double __muldf3(double a, double b) 207 { 208 double_t da; 209 double_t db; 210 double_t res; 211 212 da.val = a; 213 db.val = b; 214 215 res.data = mul_double(da.data, db.data); 216 return res.val; 152 217 } 153 218 154 219 long double __multf3(long double a, long double b) 155 220 { 156 float128 ta, tb; 157 ta.ld = a; 158 tb.ld = b; 159 return mulFloat128(ta, tb).ld; 160 } 161 162 float __divsf3(float a, float b) 163 { 164 float32 fa, fb; 165 fa.f = a; 166 fb.f = b; 167 return divFloat32(fa, fb).f; 168 } 169 170 double __divdf3(double a, double b) 171 { 172 float64 da, db; 173 da.d = a; 174 db.d = b; 175 return divFloat64(da, db).d; 221 long_double_t ta; 222 long_double_t tb; 223 long_double_t res; 224 225 ta.val = a; 226 tb.val = b; 227 228 res.data = mul_long_double(ta.data, tb.data); 229 return res.val; 230 } 231 232 float __divsf3(float a, float b) 233 { 234 float_t fa; 235 float_t fb; 236 float_t res; 237 238 fa.val = a; 239 fb.val = b; 240 241 res.data = div_float(fa.data, fb.data); 242 return res.val; 243 } 244 245 double __divdf3(double a, double b) 246 { 247 double_t da; 248 double_t db; 249 double_t res; 250 251 da.val = a; 252 db.val = b; 253 254 res.data = div_double(da.data, db.data); 255 return res.val; 176 256 } 177 257 178 258 long double __divtf3(long double a, long double b) 179 259 { 180 float128 ta, tb; 181 ta.ld = a; 182 tb.ld = b; 183 return divFloat128(ta, tb).ld; 260 long_double_t ta; 261 long_double_t tb; 262 long_double_t res; 263 264 ta.val = a; 265 tb.val = b; 266 267 res.data = div_long_double(ta.data, tb.data); 268 return res.val; 184 269 } 185 270 186 271 float __negsf2(float a) 187 272 { 188 float32 fa; 189 fa.f = a; 190 fa.parts.sign = !fa.parts.sign; 191 return fa.f; 273 float_t fa; 274 275 fa.val = a; 276 fa.data.parts.sign = !fa.data.parts.sign; 277 278 return fa.val; 192 279 } 193 280 194 281 double __negdf2(double a) 195 282 { 196 float64 da; 197 da.d = a; 198 da.parts.sign = !da.parts.sign; 199 return da.d; 283 double_t da; 284 285 da.val = a; 286 da.data.parts.sign = !da.data.parts.sign; 287 288 return da.val; 200 289 } 201 290 202 291 long double __negtf2(long double a) 203 292 { 204 float128 ta; 205 ta.ld = a; 206 ta.parts.sign = !ta.parts.sign; 207 return ta.ld; 293 long_double_t ta; 294 295 ta.val = a; 296 ta.data.parts.sign = !ta.data.parts.sign; 297 298 return ta.val; 208 299 } 209 300 210 301 /* Conversion functions */ 211 302 212 double __extendsfdf2(float a) 213 { 214 float32 fa; 215 fa.f = a; 216 return convertFloat32ToFloat64(fa).d; 303 double __extendsfdf2(float a) 304 { 305 float_t fa; 306 double_t res; 307 308 fa.val = a; 309 res.data = float_to_double(fa.data); 310 311 return res.val; 217 312 } 218 313 219 314 long double __extendsftf2(float a) 220 315 { 221 float32 fa; 222 fa.f = a; 223 return convertFloat32ToFloat128(fa).ld; 316 float_t fa; 317 long_double_t res; 318 319 fa.val = a; 320 res.data = float_to_long_double(fa.data); 321 322 return res.val; 224 323 } 225 324 226 325 long double __extenddftf2(double a) 227 326 { 228 float64 da; 229 da.d = a; 230 return convertFloat64ToFloat128(da).ld; 231 } 232 233 float __truncdfsf2(double a) 234 { 235 float64 da; 236 da.d = a; 237 return convertFloat64ToFloat32(da).f; 327 double_t da; 328 long_double_t res; 329 330 da.val = a; 331 res.data = double_to_long_double(da.data); 332 333 return res.val; 334 } 335 336 float __truncdfsf2(double a) 337 { 338 double_t da; 339 float_t res; 340 341 da.val = a; 342 res.data = double_to_float(da.data); 343 344 return res.val; 238 345 } 239 346 240 347 float __trunctfsf2(long double a) 241 348 { 242 float128 ta; 243 ta.ld = a; 244 return convertFloat128ToFloat32(ta).f; 349 long_double_t ta; 350 float_t res; 351 352 ta.val = a; 353 res.data = long_double_to_float(ta.data); 354 355 return res.val; 245 356 } 246 357 247 358 double __trunctfdf2(long double a) 248 359 { 249 float128 ta; 250 ta.ld = a; 251 return convertFloat128ToFloat64(ta).d; 360 long_double_t ta; 361 double_t res; 362 363 ta.val = a; 364 res.data = long_double_to_double(ta.data); 365 366 return res.val; 252 367 } 253 368 254 369 int __fixsfsi(float a) 255 370 { 256 float 32fa;257 fa.f = a;258 259 return float 32_to_int(fa);371 float_t fa; 372 373 fa.val = a; 374 return float_to_int(fa.data); 260 375 } 261 376 262 377 int __fixdfsi(double a) 263 378 { 264 float64da;265 da.d = a;266 267 return float64_to_int(da);379 double_t da; 380 381 da.val = a; 382 return double_to_int(da.data); 268 383 } 269 384 270 385 int __fixtfsi(long double a) 271 386 { 272 float128ta;273 ta.ld = a;274 275 return float128_to_int(ta);387 long_double_t ta; 388 389 ta.val = a; 390 return long_double_to_int(ta.data); 276 391 } 277 392 278 393 long __fixsfdi(float a) 279 394 { 280 float 32fa;281 fa.f = a;282 283 return float 32_to_long(fa);395 float_t fa; 396 397 fa.val = a; 398 return float_to_long(fa.data); 284 399 } 285 400 286 401 long __fixdfdi(double a) 287 402 { 288 float64da;289 da.d = a;290 291 return float64_to_long(da);403 double_t da; 404 405 da.val = a; 406 return double_to_long(da.data); 292 407 } 293 408 294 409 long __fixtfdi(long double a) 295 410 { 296 float128ta;297 ta.ld = a;298 299 return float128_to_long(ta);411 long_double_t ta; 412 413 ta.val = a; 414 return long_double_to_long(ta.data); 300 415 } 301 416 302 417 long long __fixsfti(float a) 303 418 { 304 float 32fa;305 fa.f = a;306 307 return float 32_to_longlong(fa);419 float_t fa; 420 421 fa.val = a; 422 return float_to_llong(fa.data); 308 423 } 309 424 310 425 long long __fixdfti(double a) 311 426 { 312 float64da;313 da.d = a;314 315 return float64_to_longlong(da);427 double_t da; 428 429 da.val = a; 430 return double_to_llong(da.data); 316 431 } 317 432 318 433 long long __fixtfti(long double a) 319 434 { 320 float128ta;321 ta.ld = a;322 323 return float128_to_longlong(ta);435 long_double_t ta; 436 437 ta.val = a; 438 return long_double_to_llong(ta.data); 324 439 } 325 440 326 441 unsigned int __fixunssfsi(float a) 327 442 { 328 float 32fa;329 fa.f = a;330 331 return float 32_to_uint(fa);443 float_t fa; 444 445 fa.val = a; 446 return float_to_uint(fa.data); 332 447 } 333 448 334 449 unsigned int __fixunsdfsi(double a) 335 450 { 336 float64da;337 da.d = a;338 339 return float64_to_uint(da);451 double_t da; 452 453 da.val = a; 454 return double_to_uint(da.data); 340 455 } 341 456 342 457 unsigned int __fixunstfsi(long double a) 343 458 { 344 float128ta;345 ta.ld = a;346 347 return float128_to_uint(ta);459 long_double_t ta; 460 461 ta.val = a; 462 return long_double_to_uint(ta.data); 348 463 } 349 464 350 465 unsigned long __fixunssfdi(float a) 351 466 { 352 float 32fa;353 fa.f = a;354 355 return float 32_to_ulong(fa);467 float_t fa; 468 469 fa.val = a; 470 return float_to_ulong(fa.data); 356 471 } 357 472 358 473 unsigned long __fixunsdfdi(double a) 359 474 { 360 float64da;361 da.d = a;362 363 return float64_to_ulong(da);475 double_t da; 476 477 da.val = a; 478 return double_to_ulong(da.data); 364 479 } 365 480 366 481 unsigned long __fixunstfdi(long double a) 367 482 { 368 float128ta;369 ta.ld = a;370 371 return float128_to_ulong(ta);483 long_double_t ta; 484 485 ta.val = a; 486 return long_double_to_ulong(ta.data); 372 487 } 373 488 374 489 unsigned long long __fixunssfti(float a) 375 490 { 376 float 32fa;377 fa.f = a;378 379 return float 32_to_ulonglong(fa);491 float_t fa; 492 493 fa.val = a; 494 return float_to_ullong(fa.data); 380 495 } 381 496 382 497 unsigned long long __fixunsdfti(double a) 383 498 { 384 float64da;385 da.d = a;386 387 return float64_to_ulonglong(da);499 double_t da; 500 501 da.val = a; 502 return double_to_ullong(da.data); 388 503 } 389 504 390 505 unsigned long long __fixunstfti(long double a) 391 506 { 392 float128ta;393 ta.ld = a;394 395 return float128_to_ulonglong(ta);507 long_double_t ta; 508 509 ta.val = a; 510 return long_double_to_ullong(ta.data); 396 511 } 397 512 398 513 float __floatsisf(int i) 399 514 { 400 float 32 fa;401 402 fa = int_to_float32(i);403 return fa.f;515 float_t res; 516 517 res.data = int_to_float(i); 518 return res.val; 404 519 } 405 520 406 521 double __floatsidf(int i) 407 522 { 408 float64 da;409 410 da = int_to_float64(i);411 return da.d;523 double_t res; 524 525 res.data = int_to_double(i); 526 return res.val; 412 527 } 413 528 414 529 long double __floatsitf(int i) 415 530 { 416 float128 ta;417 418 ta = int_to_float128(i);419 return ta.ld;531 long_double_t res; 532 533 res.data = int_to_long_double(i); 534 return res.val; 420 535 } 421 536 422 537 float __floatdisf(long i) 423 538 { 424 float 32 fa;425 426 fa = long_to_float32(i);427 return fa.f;539 float_t res; 540 541 res.data = long_to_float(i); 542 return res.val; 428 543 } 429 544 430 545 double __floatdidf(long i) 431 546 { 432 float64 da;433 434 da = long_to_float64(i);435 return da.d;547 double_t res; 548 549 res.data = long_to_double(i); 550 return res.val; 436 551 } 437 552 438 553 long double __floatditf(long i) 439 554 { 440 float128 ta;441 442 ta = long_to_float128(i);443 return ta.ld;444 } 445 555 long_double_t res; 556 557 res.data = long_to_long_double(i); 558 return res.val; 559 } 560 446 561 float __floattisf(long long i) 447 562 { 448 float 32 fa;449 450 fa = longlong_to_float32(i);451 return fa.f;563 float_t res; 564 565 res.data = llong_to_float(i); 566 return res.val; 452 567 } 453 568 454 569 double __floattidf(long long i) 455 570 { 456 float64 da;457 458 da = longlong_to_float64(i);459 return da.d;571 double_t res; 572 573 res.data = llong_to_double(i); 574 return res.val; 460 575 } 461 576 462 577 long double __floattitf(long long i) 463 578 { 464 float128 ta;465 466 ta = longlong_to_float128(i);467 return ta.ld;579 long_double_t res; 580 581 res.data = llong_to_long_double(i); 582 return res.val; 468 583 } 469 584 470 585 float __floatunsisf(unsigned int i) 471 586 { 472 float 32 fa;473 474 fa = uint_to_float32(i);475 return fa.f;587 float_t res; 588 589 res.data = uint_to_float(i); 590 return res.val; 476 591 } 477 592 478 593 double __floatunsidf(unsigned int i) 479 594 { 480 float64 da;481 482 da = uint_to_float64(i);483 return da.d;595 double_t res; 596 597 res.data = uint_to_double(i); 598 return res.val; 484 599 } 485 600 486 601 long double __floatunsitf(unsigned int i) 487 602 { 488 float128 ta;489 490 ta = uint_to_float128(i);491 return ta.ld;603 long_double_t res; 604 605 res.data = uint_to_long_double(i); 606 return res.val; 492 607 } 493 608 494 609 float __floatundisf(unsigned long i) 495 610 { 496 float 32 fa;497 498 fa = ulong_to_float32(i);499 return fa.f;611 float_t res; 612 613 res.data = ulong_to_float(i); 614 return res.val; 500 615 } 501 616 502 617 double __floatundidf(unsigned long i) 503 618 { 504 float64 da;505 506 da = ulong_to_float64(i);507 return da.d;619 double_t res; 620 621 res.data = ulong_to_double(i); 622 return res.val; 508 623 } 509 624 510 625 long double __floatunditf(unsigned long i) 511 626 { 512 float128 ta;513 514 ta = ulong_to_float128(i);515 return ta.ld;627 long_double_t res; 628 629 res.data = ulong_to_long_double(i); 630 return res.val; 516 631 } 517 632 518 633 float __floatuntisf(unsigned long long i) 519 634 { 520 float 32 fa;521 522 fa = ulonglong_to_float32(i);523 return fa.f;635 float_t res; 636 637 res.data = ullong_to_float(i); 638 return res.val; 524 639 } 525 640 526 641 double __floatuntidf(unsigned long long i) 527 642 { 528 float64 da;529 530 da = ulonglong_to_float64(i);531 return da.d;643 double_t res; 644 645 res.data = ullong_to_double(i); 646 return res.val; 532 647 } 533 648 534 649 long double __floatuntitf(unsigned long long i) 535 650 { 536 float128 ta;537 538 ta = ulonglong_to_float128(i);539 return ta.ld;651 long_double_t res; 652 653 res.data = ullong_to_long_double(i); 654 return res.val; 540 655 } 541 656 … … 544 659 int __cmpsf2(float a, float b) 545 660 { 546 float32 fa, fb; 547 fa.f = a; 548 fb.f = b; 549 550 if ((isFloat32NaN(fa)) || (isFloat32NaN(fb))) { 551 return 1; /* no special constant for unordered - maybe signaled? */ 552 } 553 554 if (isFloat32eq(fa, fb)) { 555 return 0; 556 } 557 558 if (isFloat32lt(fa, fb)) { 559 return -1; 560 } 561 661 float_t fa; 662 float_t fb; 663 664 fa.val = a; 665 fb.val = b; 666 667 if ((is_float_nan(fa.data)) || (is_float_nan(fb.data))) { 668 /* no special constant for unordered - maybe signaled? */ 669 return 1; 670 } 671 672 if (is_float_eq(fa.data, fb.data)) 673 return 0; 674 675 if (is_float_lt(fa.data, fb.data)) 676 return -1; 677 562 678 return 1; 563 679 } … … 565 681 int __cmpdf2(double a, double b) 566 682 { 567 float64 da, db; 568 da.d = a; 569 db.d = b; 570 571 if ((isFloat64NaN(da)) || (isFloat64NaN(db))) { 572 return 1; /* no special constant for unordered - maybe signaled? */ 573 } 574 575 if (isFloat64eq(da, db)) { 576 return 0; 577 } 578 579 if (isFloat64lt(da, db)) { 580 return -1; 581 } 582 683 double_t da; 684 double_t db; 685 686 da.val = a; 687 db.val = b; 688 689 if ((is_double_nan(da.data)) || (is_double_nan(db.data))) { 690 /* no special constant for unordered - maybe signaled? */ 691 return 1; 692 } 693 694 if (is_double_eq(da.data, db.data)) 695 return 0; 696 697 if (is_double_lt(da.data, db.data)) 698 return -1; 699 583 700 return 1; 584 701 } … … 586 703 int __cmptf2(long double a, long double b) 587 704 { 588 float128 ta, tb; 589 ta.ld = a; 590 tb.ld = b; 591 592 if ((isFloat128NaN(ta)) || (isFloat128NaN(tb))) { 593 return 1; /* no special constant for unordered - maybe signaled? */ 594 } 595 596 if (isFloat128eq(ta, tb)) { 597 return 0; 598 } 599 600 if (isFloat128lt(ta, tb)) { 601 return -1; 602 } 603 705 long_double_t ta; 706 long_double_t tb; 707 708 ta.val = a; 709 tb.val = b; 710 711 if ((is_long_double_nan(ta.data)) || (is_long_double_nan(tb.data))) { 712 /* no special constant for unordered - maybe signaled? */ 713 return 1; 714 } 715 716 if (is_long_double_eq(ta.data, tb.data)) 717 return 0; 718 719 if (is_long_double_lt(ta.data, tb.data)) 720 return -1; 721 604 722 return 1; 605 723 } 606 724 607 int __unordsf2(float a, float b) 608 { 609 float32 fa, fb; 610 fa.f = a; 611 fb.f = b; 612 return ((isFloat32NaN(fa)) || (isFloat32NaN(fb))); 725 int __unordsf2(float a, float b) 726 { 727 float_t fa; 728 float_t fb; 729 730 fa.val = a; 731 fb.val = b; 732 733 return ((is_float_nan(fa.data)) || (is_float_nan(fb.data))); 613 734 } 614 735 615 736 int __unorddf2(double a, double b) 616 737 { 617 float64 da, db; 618 da.d = a; 619 db.d = b; 620 return ((isFloat64NaN(da)) || (isFloat64NaN(db))); 738 double_t da; 739 double_t db; 740 741 da.val = a; 742 db.val = b; 743 744 return ((is_double_nan(da.data)) || (is_double_nan(db.data))); 621 745 } 622 746 623 747 int __unordtf2(long double a, long double b) 624 748 { 625 float128 ta, tb; 626 ta.ld = a; 627 tb.ld = b; 628 return ((isFloat128NaN(ta)) || (isFloat128NaN(tb))); 629 } 630 631 int __eqsf2(float a, float b) 632 { 633 float32 fa, fb; 634 fa.f = a; 635 fb.f = b; 636 if ((isFloat32NaN(fa)) || (isFloat32NaN(fb))) { 637 /* TODO: sigNaNs */ 638 return 1; 639 } 640 return isFloat32eq(fa, fb) - 1; 749 long_double_t ta; 750 long_double_t tb; 751 752 ta.val = a; 753 tb.val = b; 754 755 return ((is_long_double_nan(ta.data)) || (is_long_double_nan(tb.data))); 756 } 757 758 int __eqsf2(float a, float b) 759 { 760 float_t fa; 761 float_t fb; 762 763 fa.val = a; 764 fb.val = b; 765 766 if ((is_float_nan(fa.data)) || (is_float_nan(fb.data))) { 767 // TODO: sigNaNs 768 return 1; 769 } 770 771 return is_float_eq(fa.data, fb.data) - 1; 641 772 } 642 773 643 774 int __eqdf2(double a, double b) 644 775 { 645 float64 da, db; 646 da.d = a; 647 db.d = b; 648 if ((isFloat64NaN(da)) || (isFloat64NaN(db))) { 649 /* TODO: sigNaNs */ 650 return 1; 651 } 652 return isFloat64eq(da, db) - 1; 776 double_t da; 777 double_t db; 778 779 da.val = a; 780 db.val = b; 781 782 if ((is_double_nan(da.data)) || (is_double_nan(db.data))) { 783 // TODO: sigNaNs 784 return 1; 785 } 786 787 return is_double_eq(da.data, db.data) - 1; 653 788 } 654 789 655 790 int __eqtf2(long double a, long double b) 656 791 { 657 float128 ta, tb; 658 ta.ld = a; 659 tb.ld = b; 660 if ((isFloat128NaN(ta)) || (isFloat128NaN(tb))) { 661 /* TODO: sigNaNs */ 662 return 1; 663 } 664 return isFloat128eq(ta, tb) - 1; 665 } 666 667 int __nesf2(float a, float b) 792 long_double_t ta; 793 long_double_t tb; 794 795 ta.val = a; 796 tb.val = b; 797 798 if ((is_long_double_nan(ta.data)) || (is_long_double_nan(tb.data))) { 799 // TODO: sigNaNs 800 return 1; 801 } 802 803 return is_long_double_eq(ta.data, tb.data) - 1; 804 } 805 806 int __nesf2(float a, float b) 668 807 { 669 808 /* strange behavior, but it was in gcc documentation */ … … 685 824 int __gesf2(float a, float b) 686 825 { 687 float 32 fa, fb;688 f a.f = a;689 fb.f = b;690 691 if ((isFloat32NaN(fa)) || (isFloat32NaN(fb))) {692 /* TODO: sigNaNs */693 return -1;694 }695 696 if (isFloat32eq(fa, fb)) {697 return 0;698 }699 700 if (isFloat32gt(fa, fb)) {701 return 1;702 }826 float_t fa; 827 float_t fb; 828 829 fa.val = a; 830 fb.val = b; 831 832 if ((is_float_nan(fa.data)) || (is_float_nan(fb.data))) { 833 // TODO: sigNaNs 834 return -1; 835 } 836 837 if (is_float_eq(fa.data, fb.data)) 838 return 0; 839 840 if (is_float_gt(fa.data, fb.data)) 841 return 1; 703 842 704 843 return -1; … … 707 846 int __gedf2(double a, double b) 708 847 { 709 float64 da, db;710 d a.d = a;711 db.d = b;712 713 if ((isFloat64NaN(da)) || (isFloat64NaN(db))) {714 /* TODO: sigNaNs */715 return -1;716 }717 718 if (isFloat64eq(da, db)) {719 return 0;720 }721 722 if (isFloat64gt(da, db)) {723 return 1;724 }725 848 double_t da; 849 double_t db; 850 851 da.val = a; 852 db.val = b; 853 854 if ((is_double_nan(da.data)) || (is_double_nan(db.data))) { 855 // TODO: sigNaNs 856 return -1; 857 } 858 859 if (is_double_eq(da.data, db.data)) 860 return 0; 861 862 if (is_double_gt(da.data, db.data)) 863 return 1; 864 726 865 return -1; 727 866 } … … 729 868 int __getf2(long double a, long double b) 730 869 { 731 float128 ta, tb;732 ta.ld = a;733 tb.ld = b;734 735 if ((isFloat128NaN(ta)) || (isFloat128NaN(tb))) {736 /* TODO: sigNaNs */737 return -1;738 }739 740 if (isFloat128eq(ta, tb)) {741 return 0;742 }743 744 if (isFloat128gt(ta, tb)) {745 return 1;746 }747 870 long_double_t ta; 871 long_double_t tb; 872 873 ta.val = a; 874 tb.val = b; 875 876 if ((is_long_double_nan(ta.data)) || (is_long_double_nan(tb.data))) { 877 // TODO: sigNaNs 878 return -1; 879 } 880 881 if (is_long_double_eq(ta.data, tb.data)) 882 return 0; 883 884 if (is_long_double_gt(ta.data, tb.data)) 885 return 1; 886 748 887 return -1; 749 888 } … … 751 890 int __ltsf2(float a, float b) 752 891 { 753 float32 fa, fb; 754 fa.f = a; 755 fb.f = b; 756 757 if ((isFloat32NaN(fa)) || (isFloat32NaN(fb))) { 758 /* TODO: sigNaNs */ 759 return 1; 760 } 761 762 if (isFloat32lt(fa, fb)) { 763 return -1; 764 } 765 892 float_t fa; 893 float_t fb; 894 895 fa.val = a; 896 fb.val = b; 897 898 if ((is_float_nan(fa.data)) || (is_float_nan(fb.data))) { 899 // TODO: sigNaNs 900 return 1; 901 } 902 903 if (is_float_lt(fa.data, fb.data)) 904 return -1; 905 766 906 return 0; 767 907 } … … 769 909 int __ltdf2(double a, double b) 770 910 { 771 float64 da, db; 772 da.d = a; 773 db.d = b; 774 775 if ((isFloat64NaN(da)) || (isFloat64NaN(db))) { 776 /* TODO: sigNaNs */ 777 return 1; 778 } 779 780 if (isFloat64lt(da, db)) { 781 return -1; 782 } 783 911 double_t da; 912 double_t db; 913 914 da.val = a; 915 db.val = b; 916 917 if ((is_double_nan(da.data)) || (is_double_nan(db.data))) { 918 // TODO: sigNaNs 919 return 1; 920 } 921 922 if (is_double_lt(da.data, db.data)) 923 return -1; 924 784 925 return 0; 785 926 } … … 787 928 int __lttf2(long double a, long double b) 788 929 { 789 float128 ta, tb; 790 ta.ld = a; 791 tb.ld = b; 792 793 if ((isFloat128NaN(ta)) || (isFloat128NaN(tb))) { 794 /* TODO: sigNaNs */ 795 return 1; 796 } 797 798 if (isFloat128lt(ta, tb)) { 799 return -1; 800 } 801 930 long_double_t ta; 931 long_double_t tb; 932 933 ta.val = a; 934 tb.val = b; 935 936 if ((is_long_double_nan(ta.data)) || (is_long_double_nan(tb.data))) { 937 // TODO: sigNaNs 938 return 1; 939 } 940 941 if (is_long_double_lt(ta.data, tb.data)) 942 return -1; 943 802 944 return 0; 803 945 } … … 805 947 int __lesf2(float a, float b) 806 948 { 807 float 32 fa, fb;808 f a.f = a;809 fb.f = b;810 811 if ((isFloat32NaN(fa)) || (isFloat32NaN(fb))) {812 /* TODO: sigNaNs */813 return 1;814 }815 816 if (isFloat32eq(fa, fb)) {817 return 0;818 }819 820 if (isFloat32lt(fa, fb)) {821 return -1;822 }949 float_t fa; 950 float_t fb; 951 952 fa.val = a; 953 fb.val = b; 954 955 if ((is_float_nan(fa.data)) || (is_float_nan(fb.data))) { 956 // TODO: sigNaNs 957 return 1; 958 } 959 960 if (is_float_eq(fa.data, fb.data)) 961 return 0; 962 963 if (is_float_lt(fa.data, fb.data)) 964 return -1; 823 965 824 966 return 1; … … 827 969 int __ledf2(double a, double b) 828 970 { 829 float64 da, db;830 d a.d = a;831 db.d = b;832 833 if ((isFloat64NaN(da)) || (isFloat64NaN(db))) {834 /* TODO: sigNaNs */835 return 1;836 }837 838 if (isFloat64eq(da, db)) {839 return 0;840 }841 842 if (isFloat64lt(da, db)) {843 return -1;844 }845 971 double_t da; 972 double_t db; 973 974 da.val = a; 975 db.val = b; 976 977 if ((is_double_nan(da.data)) || (is_double_nan(db.data))) { 978 // TODO: sigNaNs 979 return 1; 980 } 981 982 if (is_double_eq(da.data, db.data)) 983 return 0; 984 985 if (is_double_lt(da.data, db.data)) 986 return -1; 987 846 988 return 1; 847 989 } … … 849 991 int __letf2(long double a, long double b) 850 992 { 851 float128 ta, tb;852 ta.ld = a;853 tb.ld = b;854 855 if ((isFloat128NaN(ta)) || (isFloat128NaN(tb))) {856 /* TODO: sigNaNs */857 return 1;858 }859 860 if (isFloat128eq(ta, tb)) {861 return 0;862 }863 864 if (isFloat128lt(ta, tb)) {865 return -1;866 }867 993 long_double_t ta; 994 long_double_t tb; 995 996 ta.val = a; 997 tb.val = b; 998 999 if ((is_long_double_nan(ta.data)) || (is_long_double_nan(tb.data))) { 1000 // TODO: sigNaNs 1001 return 1; 1002 } 1003 1004 if (is_long_double_eq(ta.data, tb.data)) 1005 return 0; 1006 1007 if (is_long_double_lt(ta.data, tb.data)) 1008 return -1; 1009 868 1010 return 1; 869 1011 } … … 871 1013 int __gtsf2(float a, float b) 872 1014 { 873 float32 fa, fb; 874 fa.f = a; 875 fb.f = b; 876 877 if ((isFloat32NaN(fa)) || (isFloat32NaN(fb))) { 878 /* TODO: sigNaNs */ 879 return -1; 880 } 881 882 if (isFloat32gt(fa, fb)) { 883 return 1; 884 } 885 1015 float_t fa; 1016 float_t fb; 1017 1018 fa.val = a; 1019 fb.val = b; 1020 1021 if ((is_float_nan(fa.data)) || (is_float_nan(fb.data))) { 1022 // TODO: sigNaNs 1023 return -1; 1024 } 1025 1026 if (is_float_gt(fa.data, fb.data)) 1027 return 1; 1028 886 1029 return 0; 887 1030 } … … 889 1032 int __gtdf2(double a, double b) 890 1033 { 891 float64 da, db; 892 da.d = a; 893 db.d = b; 894 895 if ((isFloat64NaN(da)) || (isFloat64NaN(db))) { 896 /* TODO: sigNaNs */ 897 return -1; 898 } 899 900 if (isFloat64gt(da, db)) { 901 return 1; 902 } 903 1034 double_t da; 1035 double_t db; 1036 1037 da.val = a; 1038 db.val = b; 1039 1040 if ((is_double_nan(da.data)) || (is_double_nan(db.data))) { 1041 // TODO: sigNaNs 1042 return -1; 1043 } 1044 1045 if (is_double_gt(da.data, db.data)) 1046 return 1; 1047 904 1048 return 0; 905 1049 } … … 907 1051 int __gttf2(long double a, long double b) 908 1052 { 909 float128 ta, tb; 910 ta.ld = a; 911 tb.ld = b; 912 913 if ((isFloat128NaN(ta)) || (isFloat128NaN(tb))) { 914 /* TODO: sigNaNs */ 915 return -1; 916 } 917 918 if (isFloat128gt(ta, tb)) { 919 return 1; 920 } 921 1053 long_double_t ta; 1054 long_double_t tb; 1055 1056 ta.val = a; 1057 tb.val = b; 1058 1059 if ((is_long_double_nan(ta.data)) || (is_long_double_nan(tb.data))) { 1060 // TODO: sigNaNs 1061 return -1; 1062 } 1063 1064 if (is_long_double_gt(ta.data, tb.data)) 1065 return 1; 1066 922 1067 return 0; 923 1068 } 924 1069 925 926 927 #ifdef SPARC_SOFTFLOAT928 929 1070 /* SPARC quadruple-precision wrappers */ 930 1071 … … 1016 1157 int _Qp_cmp(long double *a, long double *b) 1017 1158 { 1018 float128 ta, tb; 1019 ta.ld = *a; 1020 tb.ld = *b; 1021 1022 if ((isFloat128NaN(ta)) || (isFloat128NaN(tb))) { 1159 long_double_t ta; 1160 long_double_t tb; 1161 1162 ta.val = *a; 1163 tb.val = *b; 1164 1165 if ((is_long_double_nan(ta.data)) || (is_long_double_nan(tb.data))) 1023 1166 return 3; 1024 } 1025 1026 if (isFloat128eq(ta, tb)) { 1027 return 0; 1028 } 1029 1030 if (isFloat128lt(ta, tb)) { 1031 return 1; 1032 } 1033 1167 1168 if (is_long_double_eq(ta.data, tb.data)) 1169 return 0; 1170 1171 if (is_long_double_lt(ta.data, tb.data)) 1172 return 1; 1173 1034 1174 return 2; 1035 1175 } … … 1043 1183 int _Qp_feq(long double *a, long double *b) 1044 1184 { 1045 float128 ta, tb; 1046 ta.ld = *a; 1047 tb.ld = *b; 1048 1049 if ((isFloat128NaN(ta)) || (isFloat128NaN(tb))) { 1050 return 0; 1051 } 1052 1053 return isFloat128eq(ta, tb); 1185 long_double_t ta; 1186 long_double_t tb; 1187 1188 ta.val = *a; 1189 tb.val = *b; 1190 1191 if ((is_long_double_nan(ta.data)) || (is_long_double_nan(tb.data))) 1192 return 0; 1193 1194 return is_long_double_eq(ta.data, tb.data); 1054 1195 } 1055 1196 1056 1197 int _Qp_fge(long double *a, long double *b) 1057 1198 { 1058 float128 ta, tb; 1059 ta.ld = *a; 1060 tb.ld = *b; 1061 1062 if ((isFloat128NaN(ta)) || (isFloat128NaN(tb))) { 1063 return 0; 1064 } 1065 1066 return isFloat128eq(ta, tb) || isFloat128gt(ta, tb); 1199 long_double_t ta; 1200 long_double_t tb; 1201 1202 ta.val = *a; 1203 tb.val = *b; 1204 1205 if ((is_long_double_nan(ta.data)) || (is_long_double_nan(tb.data))) 1206 return 0; 1207 1208 return is_long_double_eq(ta.data, tb.data) || 1209 is_long_double_gt(ta.data, tb.data); 1067 1210 } 1068 1211 1069 1212 int _Qp_fgt(long double *a, long double *b) 1070 1213 { 1071 float128 ta, tb; 1072 ta.ld = *a; 1073 tb.ld = *b; 1074 1075 if ((isFloat128NaN(ta)) || (isFloat128NaN(tb))) { 1076 return 0; 1077 } 1078 1079 return isFloat128gt(ta, tb); 1214 long_double_t ta; 1215 long_double_t tb; 1216 1217 ta.val = *a; 1218 tb.val = *b; 1219 1220 if ((is_long_double_nan(ta.data)) || (is_long_double_nan(tb.data))) 1221 return 0; 1222 1223 return is_long_double_gt(ta.data, tb.data); 1080 1224 } 1081 1225 1082 1226 int _Qp_fle(long double*a, long double *b) 1083 1227 { 1084 float128 ta, tb; 1085 ta.ld = *a; 1086 tb.ld = *b; 1087 1088 if ((isFloat128NaN(ta)) || (isFloat128NaN(tb))) { 1089 return 0; 1090 } 1091 1092 return isFloat128eq(ta, tb) || isFloat128lt(ta, tb); 1228 long_double_t ta; 1229 long_double_t tb; 1230 1231 ta.val = *a; 1232 tb.val = *b; 1233 1234 if ((is_long_double_nan(ta.data)) || (is_long_double_nan(tb.data))) 1235 return 0; 1236 1237 return is_long_double_eq(ta.data, tb.data) || 1238 is_long_double_lt(ta.data, tb.data); 1093 1239 } 1094 1240 1095 1241 int _Qp_flt(long double *a, long double *b) 1096 1242 { 1097 float128 ta, tb; 1098 ta.ld = *a; 1099 tb.ld = *b; 1100 1101 if ((isFloat128NaN(ta)) || (isFloat128NaN(tb))) { 1102 return 0; 1103 } 1104 1105 return isFloat128lt(ta, tb); 1243 long_double_t ta; 1244 long_double_t tb; 1245 1246 ta.val = *a; 1247 tb.val = *b; 1248 1249 if ((is_long_double_nan(ta.data)) || (is_long_double_nan(tb.data))) 1250 return 0; 1251 1252 return is_long_double_lt(ta.data, tb.data); 1106 1253 } 1107 1254 1108 1255 int _Qp_fne(long double *a, long double *b) 1109 1256 { 1110 float128 ta, tb; 1111 ta.ld = *a; 1112 tb.ld = *b; 1113 1114 if ((isFloat128NaN(ta)) || (isFloat128NaN(tb))) { 1115 return 1; 1116 } 1117 1118 return !isFloat128eq(ta, tb); 1119 } 1120 1121 #endif 1257 long_double_t ta; 1258 long_double_t tb; 1259 1260 ta.val = *a; 1261 tb.val = *b; 1262 1263 if ((is_long_double_nan(ta.data)) || (is_long_double_nan(tb.data))) 1264 return 0; 1265 1266 return !is_long_double_eq(ta.data, tb.data); 1267 } 1122 1268 1123 1269 /** @} -
uspace/lib/softfloat/generic/sub.c
rd9f53877 r90924df 39 39 #include <common.h> 40 40 41 /** 42 * Subtract two single-precision floats with the same signs. 41 /** Subtract two single-precision floats with the same sign. 43 42 * 44 43 * @param a First input operand. 45 44 * @param b Second input operand. 45 * 46 46 * @return Result of substraction. 47 */ 48 float32 subFloat32(float32 a, float32 b) 47 * 48 */ 49 float32 sub_float32(float32 a, float32 b) 49 50 { 50 51 int expdiff; 51 52 uint32_t exp1, exp2, frac1, frac2; 52 53 float32 result; 53 54 result. f= 0;54 55 result.bin = 0; 55 56 56 57 expdiff = a.parts.exp - b.parts.exp; 57 if ((expdiff < 0 ) || ((expdiff == 0) && (a.parts.fraction < b.parts.fraction))) { 58 if (isFloat32NaN(b)) { 59 /* TODO: fix SigNaN */ 60 if (isFloat32SigNaN(b)) { 61 } 62 return b; 63 } 64 65 if (b.parts.exp == FLOAT32_MAX_EXPONENT) { 66 b.parts.sign = !b.parts.sign; /* num -(+-inf) = -+inf */ 67 return b; 68 } 69 70 result.parts.sign = !a.parts.sign; 58 if ((expdiff < 0 ) || ((expdiff == 0) && 59 (a.parts.fraction < b.parts.fraction))) { 60 if (is_float32_nan(b)) { 61 if (is_float32_signan(b)) { 62 // TODO: fix SigNaN 63 } 64 65 return b; 66 } 67 68 if (b.parts.exp == FLOAT32_MAX_EXPONENT) { 69 /* num -(+-inf) = -+inf */ 70 b.parts.sign = !b.parts.sign; 71 return b; 72 } 73 74 result.parts.sign = !a.parts.sign; 71 75 72 76 frac1 = b.parts.fraction; … … 76 80 expdiff *= -1; 77 81 } else { 78 if (isFloat32NaN(a)) { 79 /* TODO: fix SigNaN */ 80 if (isFloat32SigNaN(a) || isFloat32SigNaN(b)) { 81 } 82 return a; 83 } 84 85 if (a.parts.exp == FLOAT32_MAX_EXPONENT) { 82 if (is_float32_nan(a)) { 83 if ((is_float32_signan(a)) || (is_float32_signan(b))) { 84 // TODO: fix SigNaN 85 } 86 87 return a; 88 } 89 90 if (a.parts.exp == FLOAT32_MAX_EXPONENT) { 86 91 if (b.parts.exp == FLOAT32_MAX_EXPONENT) { 87 92 /* inf - inf => nan */ 88 / * TODO: fix exception */89 result.bin ary= FLOAT32_NAN;93 // TODO: fix exception 94 result.bin = FLOAT32_NAN; 90 95 return result; 91 96 } 97 92 98 return a; 93 99 } … … 98 104 exp1 = a.parts.exp; 99 105 frac2 = b.parts.fraction; 100 exp2 = b.parts.exp; 106 exp2 = b.parts.exp; 101 107 } 102 108 … … 105 111 result.parts.fraction = frac1 - frac2; 106 112 if (result.parts.fraction > frac1) { 107 / * TODO: underflow exception */113 // TODO: underflow exception 108 114 return result; 109 115 } 116 110 117 result.parts.exp = 0; 111 118 return result; 112 119 } 113 120 114 121 /* add hidden bit */ 115 frac1 |= FLOAT32_HIDDEN_BIT_MASK; 122 frac1 |= FLOAT32_HIDDEN_BIT_MASK; 116 123 117 124 if (exp2 == 0) { 118 125 /* denormalized */ 119 --expdiff; 126 --expdiff; 120 127 } else { 121 128 /* normalized */ … … 127 134 frac2 <<= 6; 128 135 129 if (expdiff > FLOAT32_FRACTION_SIZE + 1) {136 if (expdiff > FLOAT32_FRACTION_SIZE + 1) 130 137 goto done; 131 }132 138 133 139 frac1 = frac1 - (frac2 >> expdiff); 134 140 135 141 done: 136 142 /* TODO: find first nonzero digit and shift result and detect possibly underflow */ … … 143 149 /* rounding - if first bit after fraction is set then round up */ 144 150 frac1 += 0x20; 145 151 146 152 if (frac1 & (FLOAT32_HIDDEN_BIT_MASK << 7)) { 147 153 ++exp1; … … 150 156 151 157 /* Clear hidden bit and shift */ 152 result.parts.fraction = ((frac1 >> 6) & (~FLOAT32_HIDDEN_BIT_MASK)); 158 result.parts.fraction = ((frac1 >> 6) & (~FLOAT32_HIDDEN_BIT_MASK)); 153 159 result.parts.exp = exp1; 154 160 … … 156 162 } 157 163 158 /** 159 * Subtract two double-precision floats with the same signs. 164 /** Subtract two double-precision floats with the same sign. 160 165 * 161 166 * @param a First input operand. 162 167 * @param b Second input operand. 168 * 163 169 * @return Result of substraction. 164 */ 165 float64 subFloat64(float64 a, float64 b) 170 * 171 */ 172 float64 sub_float64(float64 a, float64 b) 166 173 { 167 174 int expdiff; … … 169 176 uint64_t frac1, frac2; 170 177 float64 result; 171 172 result. d= 0;178 179 result.bin = 0; 173 180 174 181 expdiff = a.parts.exp - b.parts.exp; 175 if ((expdiff < 0 ) || ((expdiff == 0) && (a.parts.fraction < b.parts.fraction))) { 176 if (isFloat64NaN(b)) { 177 /* TODO: fix SigNaN */ 178 if (isFloat64SigNaN(b)) { 179 } 180 return b; 181 } 182 183 if (b.parts.exp == FLOAT64_MAX_EXPONENT) { 184 b.parts.sign = !b.parts.sign; /* num -(+-inf) = -+inf */ 185 return b; 186 } 187 188 result.parts.sign = !a.parts.sign; 182 if ((expdiff < 0 ) || 183 ((expdiff == 0) && (a.parts.fraction < b.parts.fraction))) { 184 if (is_float64_nan(b)) { 185 if (is_float64_signan(b)) { 186 // TODO: fix SigNaN 187 } 188 189 return b; 190 } 191 192 if (b.parts.exp == FLOAT64_MAX_EXPONENT) { 193 /* num -(+-inf) = -+inf */ 194 b.parts.sign = !b.parts.sign; 195 return b; 196 } 197 198 result.parts.sign = !a.parts.sign; 189 199 190 200 frac1 = b.parts.fraction; … … 194 204 expdiff *= -1; 195 205 } else { 196 if (isFloat64NaN(a)) { 197 /* TODO: fix SigNaN */ 198 if (isFloat64SigNaN(a) || isFloat64SigNaN(b)) { 199 } 200 return a; 201 } 202 203 if (a.parts.exp == FLOAT64_MAX_EXPONENT) { 206 if (is_float64_nan(a)) { 207 if (is_float64_signan(a) || is_float64_signan(b)) { 208 // TODO: fix SigNaN 209 } 210 211 return a; 212 } 213 214 if (a.parts.exp == FLOAT64_MAX_EXPONENT) { 204 215 if (b.parts.exp == FLOAT64_MAX_EXPONENT) { 205 216 /* inf - inf => nan */ 206 / * TODO: fix exception */207 result.bin ary= FLOAT64_NAN;217 // TODO: fix exception 218 result.bin = FLOAT64_NAN; 208 219 return result; 209 220 } 221 210 222 return a; 211 223 } … … 216 228 exp1 = a.parts.exp; 217 229 frac2 = b.parts.fraction; 218 exp2 = b.parts.exp; 230 exp2 = b.parts.exp; 219 231 } 220 232 … … 223 235 result.parts.fraction = frac1 - frac2; 224 236 if (result.parts.fraction > frac1) { 225 / * TODO: underflow exception */237 // TODO: underflow exception 226 238 return result; 227 239 } 240 228 241 result.parts.exp = 0; 229 242 return result; 230 243 } 231 244 232 245 /* add hidden bit */ 233 frac1 |= FLOAT64_HIDDEN_BIT_MASK; 246 frac1 |= FLOAT64_HIDDEN_BIT_MASK; 234 247 235 248 if (exp2 == 0) { 236 249 /* denormalized */ 237 --expdiff; 250 --expdiff; 238 251 } else { 239 252 /* normalized */ … … 245 258 frac2 <<= 6; 246 259 247 if (expdiff > FLOAT64_FRACTION_SIZE + 1) {260 if (expdiff > FLOAT64_FRACTION_SIZE + 1) 248 261 goto done; 249 }250 262 251 263 frac1 = frac1 - (frac2 >> expdiff); 252 264 253 265 done: 254 266 /* TODO: find first nonzero digit and shift result and detect possibly underflow */ … … 261 273 /* rounding - if first bit after fraction is set then round up */ 262 274 frac1 += 0x20; 263 275 264 276 if (frac1 & (FLOAT64_HIDDEN_BIT_MASK << 7)) { 265 277 ++exp1; … … 268 280 269 281 /* Clear hidden bit and shift */ 270 result.parts.fraction = ((frac1 >> 6) & (~FLOAT64_HIDDEN_BIT_MASK)); 282 result.parts.fraction = ((frac1 >> 6) & (~FLOAT64_HIDDEN_BIT_MASK)); 271 283 result.parts.exp = exp1; 272 284 … … 274 286 } 275 287 276 /** 277 * Subtract two quadruple-precision floats with the same signs. 288 /** Subtract two quadruple-precision floats with the same sign. 278 289 * 279 290 * @param a First input operand. 280 291 * @param b Second input operand. 292 * 281 293 * @return Result of substraction. 282 */ 283 float128 subFloat128(float128 a, float128 b) 294 * 295 */ 296 float128 sub_float128(float128 a, float128 b) 284 297 { 285 298 int expdiff; … … 287 300 uint64_t frac1_hi, frac1_lo, frac2_hi, frac2_lo, tmp_hi, tmp_lo; 288 301 float128 result; 289 290 result.bin ary.hi = 0;291 result.bin ary.lo = 0;292 302 303 result.bin.hi = 0; 304 result.bin.lo = 0; 305 293 306 expdiff = a.parts.exp - b.parts.exp; 294 307 if ((expdiff < 0 ) || ((expdiff == 0) && 295 308 lt128(a.parts.frac_hi, a.parts.frac_lo, b.parts.frac_hi, b.parts.frac_lo))) { 296 if (isFloat128NaN(b)) { 297 /* TODO: fix SigNaN */ 298 if (isFloat128SigNaN(b)) { 299 } 300 return b; 301 } 302 309 if (is_float128_nan(b)) { 310 if (is_float128_signan(b)) { 311 // TODO: fix SigNaN 312 } 313 314 return b; 315 } 316 303 317 if (b.parts.exp == FLOAT128_MAX_EXPONENT) { 304 b.parts.sign = !b.parts.sign; /* num -(+-inf) = -+inf */ 305 return b; 306 } 307 318 /* num -(+-inf) = -+inf */ 319 b.parts.sign = !b.parts.sign; 320 return b; 321 } 322 308 323 result.parts.sign = !a.parts.sign; 309 324 310 325 frac1_hi = b.parts.frac_hi; 311 326 frac1_lo = b.parts.frac_lo; … … 316 331 expdiff *= -1; 317 332 } else { 318 if (isFloat128NaN(a)) { 319 /* TODO: fix SigNaN */ 320 if (isFloat128SigNaN(a) || isFloat128SigNaN(b)) { 321 } 322 return a; 323 } 324 333 if (is_float128_nan(a)) { 334 if (is_float128_signan(a) || is_float128_signan(b)) { 335 // TODO: fix SigNaN 336 } 337 338 return a; 339 } 340 325 341 if (a.parts.exp == FLOAT128_MAX_EXPONENT) { 326 342 if (b.parts.exp == FLOAT128_MAX_EXPONENT) { 327 343 /* inf - inf => nan */ 328 / * TODO: fix exception */329 result.bin ary.hi = FLOAT128_NAN_HI;330 result.bin ary.lo = FLOAT128_NAN_LO;344 // TODO: fix exception 345 result.bin.hi = FLOAT128_NAN_HI; 346 result.bin.lo = FLOAT128_NAN_LO; 331 347 return result; 332 348 } 333 349 return a; 334 350 } 335 351 336 352 result.parts.sign = a.parts.sign; 337 353 338 354 frac1_hi = a.parts.frac_hi; 339 355 frac1_lo = a.parts.frac_lo; … … 343 359 exp2 = b.parts.exp; 344 360 } 345 361 346 362 if (exp1 == 0) { 347 363 /* both are denormalized */ … … 350 366 result.parts.frac_lo = tmp_lo; 351 367 if (lt128(frac1_hi, frac1_lo, result.parts.frac_hi, result.parts.frac_lo)) { 352 / * TODO: underflow exception */368 // TODO: underflow exception 353 369 return result; 354 370 } 371 355 372 result.parts.exp = 0; 356 373 return result; 357 374 } 358 375 359 376 /* add hidden bit */ 360 377 or128(frac1_hi, frac1_lo, 361 378 FLOAT128_HIDDEN_BIT_MASK_HI, FLOAT128_HIDDEN_BIT_MASK_LO, 362 379 &frac1_hi, &frac1_lo); 363 380 364 381 if (exp2 == 0) { 365 382 /* denormalized */ … … 371 388 &frac2_hi, &frac2_lo); 372 389 } 373 390 374 391 /* create some space for rounding */ 375 392 lshift128(frac1_hi, frac1_lo, 6, &frac1_hi, &frac1_lo); 376 393 lshift128(frac2_hi, frac2_lo, 6, &frac2_hi, &frac2_lo); 377 378 if (expdiff > FLOAT128_FRACTION_SIZE + 1) {394 395 if (expdiff > FLOAT128_FRACTION_SIZE + 1) 379 396 goto done; 380 } 381 397 382 398 rshift128(frac2_hi, frac2_lo, expdiff, &tmp_hi, &tmp_lo); 383 399 sub128(frac1_hi, frac1_lo, tmp_hi, tmp_lo, &frac1_hi, &frac1_lo); 384 400 385 401 done: 386 402 /* TODO: find first nonzero digit and shift result and detect possibly underflow */ … … 392 408 lshift128(frac1_hi, frac1_lo, 1, &frac1_hi, &frac1_lo); 393 409 /* TODO: fix underflow - frac1 == 0 does not necessary means underflow... */ 394 410 395 411 lshift128(FLOAT128_HIDDEN_BIT_MASK_HI, FLOAT128_HIDDEN_BIT_MASK_LO, 6, 396 412 &tmp_hi, &tmp_lo); 397 413 and128(frac1_hi, frac1_lo, tmp_hi, tmp_lo, &tmp_hi, &tmp_lo); 398 414 } 399 415 400 416 /* rounding - if first bit after fraction is set then round up */ 401 417 add128(frac1_hi, frac1_lo, 0x0ll, 0x20ll, &frac1_hi, &frac1_lo); 402 418 403 419 lshift128(FLOAT128_HIDDEN_BIT_MASK_HI, FLOAT128_HIDDEN_BIT_MASK_LO, 7, 404 420 &tmp_hi, &tmp_lo); … … 408 424 rshift128(frac1_hi, frac1_lo, 1, &frac1_hi, &frac1_lo); 409 425 } 410 426 411 427 /* Clear hidden bit and shift */ 412 428 rshift128(frac1_hi, frac1_lo, 6, &frac1_hi, &frac1_lo); … … 416 432 result.parts.frac_hi = tmp_hi; 417 433 result.parts.frac_lo = tmp_lo; 418 434 419 435 result.parts.exp = exp1; 420 436 421 437 return result; 422 438 } -
uspace/lib/softfloat/include/add.h
rd9f53877 r90924df 37 37 #define __ADD_H__ 38 38 39 extern float32 addFloat32(float32, float32); 40 extern float64 addFloat64(float64, float64); 41 extern float128 addFloat128(float128, float128); 39 extern float32 add_float32(float32, float32); 40 extern float64 add_float64(float64, float64); 41 extern float96 add_float96(float96, float96); 42 extern float128 add_float128(float128, float128); 42 43 43 44 #endif -
uspace/lib/softfloat/include/common.h
rd9f53877 r90924df 39 39 #include <sftypes.h> 40 40 41 extern float64 finish Float64(int32_t, uint64_t, char);42 extern float128 finish Float128(int32_t, uint64_t, uint64_t, char, uint64_t);41 extern float64 finish_float64(int32_t, uint64_t, char); 42 extern float128 finish_float128(int32_t, uint64_t, uint64_t, char, uint64_t); 43 43 44 extern int count Zeroes8(uint8_t);45 extern int count Zeroes32(uint32_t);46 extern int count Zeroes64(uint64_t);44 extern int count_zeroes8(uint8_t); 45 extern int count_zeroes32(uint32_t); 46 extern int count_zeroes64(uint64_t); 47 47 48 extern void round Float32(int32_t *, uint32_t *);49 extern void round Float64(int32_t *, uint64_t *);50 extern void round Float128(int32_t *, uint64_t *, uint64_t *);48 extern void round_float32(int32_t *, uint32_t *); 49 extern void round_float64(int32_t *, uint64_t *); 50 extern void round_float128(int32_t *, uint64_t *, uint64_t *); 51 51 52 52 extern void lshift128(uint64_t, uint64_t, int, uint64_t *, uint64_t *); -
uspace/lib/softfloat/include/comparison.h
rd9f53877 r90924df 37 37 #define __COMPARISON_H__ 38 38 39 extern int is Float32NaN(float32);40 extern int is Float32SigNaN(float32);39 extern int is_float32_nan(float32); 40 extern int is_float32_signan(float32); 41 41 42 extern int is Float32Infinity(float32);43 extern int is Float32Zero(float32);42 extern int is_float32_infinity(float32); 43 extern int is_float32_zero(float32); 44 44 45 extern int is Float32eq(float32, float32);46 extern int is Float32lt(float32, float32);47 extern int is Float32gt(float32, float32);45 extern int is_float32_eq(float32, float32); 46 extern int is_float32_lt(float32, float32); 47 extern int is_float32_gt(float32, float32); 48 48 49 extern int is Float64NaN(float64);50 extern int is Float64SigNaN(float64);49 extern int is_float64_nan(float64); 50 extern int is_float64_signan(float64); 51 51 52 extern int is Float64Infinity(float64);53 extern int is Float64Zero(float64);52 extern int is_float64_infinity(float64); 53 extern int is_float64_zero(float64); 54 54 55 extern int is Float64eq(float64, float64);56 extern int is Float64lt(float64, float64);57 extern int is Float64gt(float64, float64);55 extern int is_float64_eq(float64, float64); 56 extern int is_float64_lt(float64, float64); 57 extern int is_float64_gt(float64, float64); 58 58 59 extern int is Float128NaN(float128);60 extern int is Float128SigNaN(float128);59 extern int is_float96_nan(float96); 60 extern int is_float96_signan(float96); 61 61 62 extern int is Float128Infinity(float128);63 extern int is Float128Zero(float128);62 extern int is_float96_infinity(float96); 63 extern int is_float96_zero(float96); 64 64 65 extern int isFloat128eq(float128, float128); 66 extern int isFloat128lt(float128, float128); 67 extern int isFloat128gt(float128, float128); 65 extern int is_float96_eq(float96, float96); 66 extern int is_float96_lt(float96, float96); 67 extern int is_float96_gt(float96, float96); 68 69 extern int is_float128_nan(float128); 70 extern int is_float128_signan(float128); 71 72 extern int is_float128_infinity(float128); 73 extern int is_float128_zero(float128); 74 75 extern int is_float128_eq(float128, float128); 76 extern int is_float128_lt(float128, float128); 77 extern int is_float128_gt(float128, float128); 68 78 69 79 #endif -
uspace/lib/softfloat/include/conversion.h
rd9f53877 r90924df 37 37 #define __CONVERSION_H__ 38 38 39 extern float64 convertFloat32ToFloat64(float32); 40 extern float128 convertFloat32ToFloat128(float32); 41 extern float128 convertFloat64ToFloat128(float64); 39 extern float64 float32_to_float64(float32); 40 extern float96 float32_to_float96(float32); 41 extern float128 float32_to_float128(float32); 42 extern float96 float64_to_float96(float64); 43 extern float128 float64_to_float128(float64); 44 extern float128 float96_to_float128(float96); 42 45 43 44 extern float32 convertFloat64ToFloat32(float64); 45 extern float32 convertFloat128ToFloat32(float128); 46 extern float64 convertFloat128ToFloat64(float128); 47 46 extern float32 float64_to_float32(float64); 47 extern float32 float96_to_float32(float96); 48 extern float64 float96_to_float64(float96); 49 extern float32 float128_to_float32(float128); 50 extern float64 float128_to_float64(float128); 51 extern float96 float128_to_float96(float128); 48 52 49 53 extern uint32_t float32_to_uint32(float32); … … 59 63 extern int64_t float64_to_int64(float64); 60 64 65 extern uint32_t float96_to_uint32(float96); 66 extern int32_t float96_to_int32(float96); 67 68 extern uint64_t float96_to_uint64(float96); 69 extern int64_t float96_to_int64(float96); 70 61 71 extern uint32_t float128_to_uint32(float128); 62 72 extern int32_t float128_to_int32(float128); … … 64 74 extern uint64_t float128_to_uint64(float128); 65 75 extern int64_t float128_to_int64(float128); 66 67 76 68 77 extern float32 uint32_to_float32(uint32_t); … … 78 87 extern float64 int64_to_float64(int64_t); 79 88 89 extern float96 uint32_to_float96(uint32_t); 90 extern float96 int32_to_float96(int32_t); 91 92 extern float96 uint64_to_float96(uint64_t); 93 extern float96 int64_to_float96(int64_t); 94 80 95 extern float128 uint32_to_float128(uint32_t); 81 96 extern float128 int32_to_float128(int32_t); -
uspace/lib/softfloat/include/div.h
rd9f53877 r90924df 37 37 #define __DIV_H__ 38 38 39 extern float32 divFloat32(float32, float32); 40 extern float64 divFloat64(float64, float64); 41 extern float128 divFloat128(float128, float128); 39 extern float32 div_float32(float32, float32); 40 extern float64 div_float64(float64, float64); 41 extern float96 div_float96(float96, float96); 42 extern float128 div_float128(float128, float128); 42 43 43 44 #endif -
uspace/lib/softfloat/include/mul.h
rd9f53877 r90924df 37 37 #define __MUL_H__ 38 38 39 extern float32 mulFloat32(float32, float32); 40 extern float64 mulFloat64(float64, float64); 41 extern float128 mulFloat128(float128, float128); 39 extern float32 mul_float32(float32, float32); 40 extern float64 mul_float64(float64, float64); 41 extern float96 mul_float96(float96, float96); 42 extern float128 mul_float128(float128, float128); 42 43 43 44 #endif -
uspace/lib/softfloat/include/sftypes.h
rd9f53877 r90924df 40 40 #include <stdint.h> 41 41 42 typedef union { 43 float f; 44 uint32_t binary; 45 46 struct { 42 /* 43 * For recognizing NaNs or infinity use specialized comparison 44 * functions, comparing with these constants is not sufficient. 45 */ 46 47 #define FLOAT32_NAN UINT32_C(0x7FC00001) 48 #define FLOAT32_SIGNAN UINT32_C(0x7F800001) 49 #define FLOAT32_INF UINT32_C(0x7F800000) 50 51 #define FLOAT64_NAN UINT64_C(0x7FF8000000000001) 52 #define FLOAT64_SIGNAN UINT64_C(0x7FF0000000000001) 53 #define FLOAT64_INF UINT64_C(0x7FF0000000000000) 54 55 #define FLOAT96_NAN_HI UINT64_C(0x7FFF80000000) 56 #define FLOAT96_NAN_LO UINT32_C(0x00010000) 57 #define FLOAT96_SIGNAN_HI UINT64_C(0x7FFF00000000) 58 #define FLOAT96_SIGNAN_LO UINT32_C(0x00010000) 59 60 #define FLOAT128_NAN_HI UINT64_C(0x7FFF800000000000) 61 #define FLOAT128_NAN_LO UINT64_C(0x0000000000000001) 62 #define FLOAT128_SIGNAN_HI UINT64_C(0x7FFF000000000000) 63 #define FLOAT128_SIGNAN_LO UINT64_C(0x0000000000000001) 64 #define FLOAT128_INF_HI UINT64_C(0x7FFF000000000000) 65 #define FLOAT128_INF_LO UINT64_C(0x0000000000000000) 66 67 #define FLOAT32_FRACTION_SIZE 23 68 #define FLOAT64_FRACTION_SIZE 52 69 #define FLOAT96_FRACTION_SIZE 64 70 #define FLOAT128_FRACTION_SIZE 112 71 #define FLOAT128_FRAC_HI_SIZE 48 72 #define FLOAT128_FRAC_LO_SIZE 64 73 74 #define FLOAT32_HIDDEN_BIT_MASK UINT32_C(0x800000) 75 #define FLOAT64_HIDDEN_BIT_MASK UINT64_C(0x10000000000000) 76 #define FLOAT128_HIDDEN_BIT_MASK_HI UINT64_C(0x1000000000000) 77 #define FLOAT128_HIDDEN_BIT_MASK_LO UINT64_C(0x0000000000000000) 78 79 #define FLOAT32_MAX_EXPONENT 0xFF 80 #define FLOAT64_MAX_EXPONENT 0x7FF 81 #define FLOAT96_MAX_EXPONENT 0x7FFF 82 #define FLOAT128_MAX_EXPONENT 0x7FFF 83 84 #define FLOAT32_BIAS 0x7F 85 #define FLOAT64_BIAS 0x3FF 86 #define FLOAT96_BIAS 0x3FFF 87 #define FLOAT128_BIAS 0x3FFF 88 47 89 #if defined(__BE__) 90 91 typedef union { 92 uint32_t bin; 93 94 struct { 48 95 uint32_t sign : 1; 49 96 uint32_t exp : 8; 50 97 uint32_t fraction : 23; 51 #elif defined(__LE__) 52 uint32_t fraction : 23; 53 uint32_t exp : 8; 54 uint32_t sign : 1; 55 #else 56 #error Unknown endianess 57 #endif 58 } parts __attribute__ ((packed)); 98 } parts __attribute__((packed)); 59 99 } float32; 60 100 61 101 typedef union { 62 double d; 63 uint64_t binary; 64 65 struct { 66 #if defined(__BE__) 102 uint64_t bin; 103 104 struct { 67 105 uint64_t sign : 1; 68 106 uint64_t exp : 11; 69 107 uint64_t fraction : 52; 70 #elif defined(__LE__) 71 uint64_t fraction : 52; 72 uint64_t exp : 11; 108 } parts __attribute__((packed)); 109 } float64; 110 111 typedef union { 112 struct { 113 uint64_t hi; 114 uint32_t lo; 115 } bin __attribute__((packed)); 116 117 struct { 118 uint64_t padding : 16; 73 119 uint64_t sign : 1; 74 #else 75 #error Unknown endianess 76 #endif 77 } parts __attribute__ ((packed)); 78 } float64; 79 80 typedef union { 81 long double ld; 82 struct { 83 #if defined(__BE__) 120 uint64_t exp : 15; 121 uint64_t fraction : 64; 122 } parts __attribute__((packed)); 123 } float96; 124 125 typedef union { 126 struct { 84 127 uint64_t hi; 85 128 uint64_t lo; 86 #elif defined(__LE__) 87 uint64_t lo; 88 uint64_t hi; 89 #else 90 #error Unknown endianess 91 #endif 92 } binary; 93 94 struct { 95 #if defined(__BE__) 129 } bin __attribute__((packed)); 130 131 struct { 96 132 uint64_t sign : 1; 97 133 uint64_t exp : 15; 98 134 uint64_t frac_hi : 48; 99 135 uint64_t frac_lo : 64; 136 } parts __attribute__((packed)); 137 } float128; 138 100 139 #elif defined(__LE__) 140 141 typedef union { 142 uint32_t bin; 143 144 struct { 145 uint32_t fraction : 23; 146 uint32_t exp : 8; 147 uint32_t sign : 1; 148 } parts __attribute__((packed)); 149 } float32; 150 151 typedef union { 152 uint64_t bin; 153 154 struct { 155 uint64_t fraction : 52; 156 uint64_t exp : 11; 157 uint64_t sign : 1; 158 } parts __attribute__((packed)); 159 } float64; 160 161 typedef union { 162 struct { 163 uint32_t lo; 164 uint64_t hi; 165 } bin __attribute__((packed)); 166 167 struct { 168 uint64_t fraction : 64; 169 uint64_t exp : 15; 170 uint64_t sign : 1; 171 uint64_t padding : 16; 172 } parts __attribute__((packed)); 173 } float96; 174 175 typedef union { 176 struct { 177 uint64_t lo; 178 uint64_t hi; 179 } bin __attribute__((packed)); 180 181 struct { 101 182 uint64_t frac_lo : 64; 102 183 uint64_t frac_hi : 48; 103 184 uint64_t exp : 15; 104 185 uint64_t sign : 1; 186 } parts __attribute__((packed)); 187 } float128; 188 105 189 #else 106 190 #error Unknown endianess 107 191 #endif 108 } parts __attribute__ ((packed)); 109 } float128; 110 111 /* 112 * For recognizing NaNs or infinity use specialized comparison functions, 113 * comparing with these constants is not sufficient. 114 */ 115 116 #define FLOAT32_NAN 0x7FC00001 117 #define FLOAT32_SIGNAN 0x7F800001 118 #define FLOAT32_INF 0x7F800000 119 120 #define FLOAT64_NAN 0x7FF8000000000001ll 121 #define FLOAT64_SIGNAN 0x7FF0000000000001ll 122 #define FLOAT64_INF 0x7FF0000000000000ll 123 124 #define FLOAT128_NAN_HI 0x7FFF800000000000ll 125 #define FLOAT128_NAN_LO 0x0000000000000001ll 126 #define FLOAT128_SIGNAN_HI 0x7FFF000000000000ll 127 #define FLOAT128_SIGNAN_LO 0x0000000000000001ll 128 #define FLOAT128_INF_HI 0x7FFF000000000000ll 129 #define FLOAT128_INF_LO 0x0000000000000000ll 130 131 #define FLOAT32_FRACTION_SIZE 23 132 #define FLOAT64_FRACTION_SIZE 52 133 #define FLOAT128_FRACTION_SIZE 112 134 #define FLOAT128_FRAC_HI_SIZE 48 135 #define FLOAT128_FRAC_LO_SIZE 64 136 137 #define FLOAT32_HIDDEN_BIT_MASK 0x800000 138 #define FLOAT64_HIDDEN_BIT_MASK 0x10000000000000ll 139 #define FLOAT128_HIDDEN_BIT_MASK_HI 0x1000000000000ll 140 #define FLOAT128_HIDDEN_BIT_MASK_LO 0x0000000000000000ll 141 142 #define FLOAT32_MAX_EXPONENT 0xFF 143 #define FLOAT64_MAX_EXPONENT 0x7FF 144 #define FLOAT128_MAX_EXPONENT 0x7FFF 145 146 #define FLOAT32_BIAS 0x7F 147 #define FLOAT64_BIAS 0x3FF 148 #define FLOAT80_BIAS 0x3FFF 149 #define FLOAT128_BIAS 0x3FFF 192 193 typedef union { 194 float val; 195 196 #if defined(FLOAT_SIZE_32) 197 float32 data; 198 #elif defined(FLOAT_SIZE_64) 199 float64 data; 200 #elif defined(FLOAT_SIZE_96) 201 float96 data; 202 #elif defined(FLOAT_SIZE_128) 203 float128 data; 204 #else 205 #error Unsupported float size 206 #endif 207 } float_t; 208 209 typedef union { 210 double val; 211 212 #if defined(DOUBLE_SIZE_32) 213 float32 data; 214 #elif defined(DOUBLE_SIZE_64) 215 float64 data; 216 #elif defined(DOUBLE_SIZE_96) 217 float96 data; 218 #elif defined(DOUBLE_SIZE_128) 219 float128 data; 220 #else 221 #error Unsupported double size 222 #endif 223 } double_t; 224 225 typedef union { 226 long double val; 227 228 #if defined(LONG_DOUBLE_SIZE_32) 229 float32 data; 230 #elif defined(LONG_DOUBLE_SIZE_64) 231 float64 data; 232 #elif defined(LONG_DOUBLE_SIZE_96) 233 float96 data; 234 #elif defined(LONG_DOUBLE_SIZE_128) 235 float128 data; 236 #else 237 #error Unsupported long double size 238 #endif 239 } long_double_t; 240 241 242 #if defined(INT_SIZE_8) 243 244 #define _to_int _to_int8 245 #define from_int int8 246 247 #elif defined(INT_SIZE_16) 248 249 #define _to_int _to_int16 250 #define from_int int16 251 252 #elif defined(INT_SIZE_32) 253 254 #define _to_int _to_int32 255 #define from_int int32 256 257 #elif defined(INT_SIZE_64) 258 259 #define _to_int _to_int64 260 #define from_int int64 261 262 #endif 263 264 265 #if defined(UINT_SIZE_8) 266 267 #define _to_uint _to_uint8 268 #define from_uint uint8 269 270 #elif defined(UINT_SIZE_16) 271 272 #define _to_uint _to_uint16 273 #define from_uint uint16 274 275 #elif defined(UINT_SIZE_32) 276 277 #define _to_uint _to_uint32 278 #define from_uint uint32 279 280 #elif defined(UINT_SIZE_64) 281 282 #define _to_uint _to_uint64 283 #define from_uint uint64 284 285 #endif 286 287 288 #if defined(LONG_SIZE_8) 289 290 #define _to_long _to_int8 291 #define from_long int8 292 293 #elif defined(LONG_SIZE_16) 294 295 #define _to_long _to_int16 296 #define from_long int16 297 298 #elif defined(LONG_SIZE_32) 299 300 #define _to_long _to_int32 301 #define from_long int32 302 303 #elif defined(LONG_SIZE_64) 304 305 #define _to_long _to_int64 306 #define from_long int64 307 308 #endif 309 310 311 #if defined(ULONG_SIZE_8) 312 313 #define _to_ulong _to_uint8 314 #define from_ulong uint8 315 316 #elif defined(ULONG_SIZE_16) 317 318 #define _to_ulong _to_uint16 319 #define from_ulong uint16 320 321 #elif defined(ULONG_SIZE_32) 322 323 #define _to_ulong _to_uint32 324 #define from_ulong uint32 325 326 #elif defined(ULONG_SIZE_64) 327 328 #define _to_ulong _to_uint64 329 #define from_ulong uint64 330 331 #endif 332 333 334 #if defined(LLONG_SIZE_8) 335 336 #define _to_llong _to_int8 337 #define from_llong int8 338 339 #elif defined(LLONG_SIZE_16) 340 341 #define _to_llong _to_int16 342 #define from_llong int16 343 344 #elif defined(LLONG_SIZE_32) 345 346 #define _to_llong _to_int32 347 #define from_llong int32 348 349 #elif defined(LLONG_SIZE_64) 350 351 #define _to_llong _to_int64 352 #define from_llong int64 353 354 #endif 355 356 357 #if defined(ULLONG_SIZE_8) 358 359 #define _to_ullong _to_uint8 360 #define from_ullong uint8 361 362 #elif defined(ULLONG_SIZE_16) 363 364 #define _to_ullong _to_uint16 365 #define from_ullong uint16 366 367 #elif defined(ULLONG_SIZE_32) 368 369 #define _to_ullong _to_uint32 370 #define from_ullong uint32 371 372 #elif defined(ULLONG_SIZE_64) 373 374 #define _to_ullong _to_uint64 375 #define from_ullong uint64 376 377 #endif 378 379 380 #if defined(FLOAT_SIZE_32) 381 382 #define add_float add_float32 383 #define sub_float sub_float32 384 #define mul_float mul_float32 385 #define div_float div_float32 386 #define _to_float _to_float32 387 #define from_float float32 388 #define is_float_nan is_float32_nan 389 #define is_float_eq is_float32_eq 390 #define is_float_lt is_float32_lt 391 #define is_float_gt is_float32_gt 392 393 #elif defined(FLOAT_SIZE_64) 394 395 #define add_float add_float64 396 #define sub_float sub_float64 397 #define mul_float mul_float64 398 #define div_float div_float64 399 #define _to_float _to_float64 400 #define from_float float64 401 #define is_float_nan is_float64_nan 402 #define is_float_eq is_float64_eq 403 #define is_float_lt is_float64_lt 404 #define is_float_gt is_float64_gt 405 406 #elif defined(FLOAT_SIZE_96) 407 408 #define add_float add_float96 409 #define sub_float sub_float96 410 #define mul_float mul_float96 411 #define div_float div_float96 412 #define _to_float _to_float96 413 #define from_float float96 414 #define is_float_nan is_float96_nan 415 #define is_float_eq is_float96_eq 416 #define is_float_lt is_float96_lt 417 #define is_float_gt is_float96_gt 418 419 #elif defined(FLOAT_SIZE_128) 420 421 #define add_float add_float128 422 #define sub_float sub_float128 423 #define mul_float mul_float128 424 #define div_float div_float128 425 #define _to_float _to_float128 426 #define from_float float128 427 #define is_float_nan is_float128_nan 428 #define is_float_eq is_float128_eq 429 #define is_float_lt is_float128_lt 430 #define is_float_gt is_float128_gt 431 432 #endif 433 434 435 #if defined(DOUBLE_SIZE_32) 436 437 #define add_double add_float32 438 #define sub_double sub_float32 439 #define mul_double mul_float32 440 #define div_double div_float32 441 #define _to_double _to_float32 442 #define from_double float32 443 #define is_double_nan is_float32_nan 444 #define is_double_eq is_float32_eq 445 #define is_double_lt is_float32_lt 446 #define is_double_gt is_float32_gt 447 448 #elif defined(DOUBLE_SIZE_64) 449 450 #define add_double add_float64 451 #define sub_double sub_float64 452 #define mul_double mul_float64 453 #define div_double div_float64 454 #define _to_double _to_float64 455 #define from_double float64 456 #define is_double_nan is_float64_nan 457 #define is_double_eq is_float64_eq 458 #define is_double_lt is_float64_lt 459 #define is_double_gt is_float64_gt 460 461 #elif defined(DOUBLE_SIZE_96) 462 463 #define add_double add_float96 464 #define sub_double sub_float96 465 #define mul_double mul_float96 466 #define div_double div_float96 467 #define _to_double _to_float96 468 #define from_double float96 469 #define is_double_nan is_float96_nan 470 #define is_double_eq is_float96_eq 471 #define is_double_lt is_float96_lt 472 #define is_double_gt is_float96_gt 473 474 #elif defined(DOUBLE_SIZE_128) 475 476 #define add_double add_float128 477 #define sub_double sub_float128 478 #define mul_double mul_float128 479 #define div_double div_float128 480 #define _to_double _to_float128 481 #define from_double float128 482 #define is_double_nan is_float128_nan 483 #define is_double_eq is_float128_eq 484 #define is_double_lt is_float128_lt 485 #define is_double_gt is_float128_gt 486 487 #endif 488 489 490 #if defined(LONG_DOUBLE_SIZE_32) 491 492 #define add_long_double add_float32 493 #define sub_long_double sub_float32 494 #define mul_long_double mul_float32 495 #define div_long_double div_float32 496 #define _to_long_double _to_float32 497 #define from_long_double float32 498 #define is_long_double_nan is_float32_nan 499 #define is_long_double_eq is_float32_eq 500 #define is_long_double_lt is_float32_lt 501 #define is_long_double_gt is_float32_gt 502 503 #elif defined(LONG_DOUBLE_SIZE_64) 504 505 #define add_long_double add_float64 506 #define sub_long_double sub_float64 507 #define mul_long_double mul_float64 508 #define div_long_double div_float64 509 #define _to_long_double _to_float64 510 #define from_long_double float64 511 #define is_long_double_nan is_float64_nan 512 #define is_long_double_eq is_float64_eq 513 #define is_long_double_lt is_float64_lt 514 #define is_long_double_gt is_float64_gt 515 516 #elif defined(LONG_DOUBLE_SIZE_96) 517 518 #define add_long_double add_float96 519 #define sub_long_double sub_float96 520 #define mul_long_double mul_float96 521 #define div_long_double div_float96 522 #define _to_long_double _to_float96 523 #define from_long_double float96 524 #define is_long_double_nan is_float96_nan 525 #define is_long_double_eq is_float96_eq 526 #define is_long_double_lt is_float96_lt 527 #define is_long_double_gt is_float96_gt 528 529 #elif defined(LONG_DOUBLE_SIZE_128) 530 531 #define add_long_double add_float128 532 #define sub_long_double sub_float128 533 #define mul_long_double mul_float128 534 #define div_long_double div_float128 535 #define _to_long_double _to_float128 536 #define from_long_double float128 537 #define is_long_double_nan is_float128_nan 538 #define is_long_double_eq is_float128_eq 539 #define is_long_double_lt is_float128_lt 540 #define is_long_double_gt is_float128_gt 541 542 #endif 543 544 545 #define CONCAT(a, b) CONCAT_ARGS(a, b) 546 #define CONCAT_ARGS(a, b) a ## b 547 548 #define float32_to_float32(arg) (arg) 549 #define float64_to_float64(arg) (arg) 550 #define float96_to_float96(arg) (arg) 551 #define float128_to_float128(arg) (arg) 552 553 #define float_to_double CONCAT(from_float, _to_double) 554 #define float_to_long_double CONCAT(from_float, _to_long_double) 555 #define float_to_int CONCAT(from_float, _to_int) 556 #define float_to_uint CONCAT(from_float, _to_uint) 557 #define float_to_long CONCAT(from_float, _to_long) 558 #define float_to_ulong CONCAT(from_float, _to_ulong) 559 #define float_to_llong CONCAT(from_float, _to_llong) 560 #define float_to_ullong CONCAT(from_float, _to_ullong) 561 562 #define double_to_float CONCAT(from_double, _to_float) 563 #define double_to_long_double CONCAT(from_double, _to_long_double) 564 #define double_to_int CONCAT(from_double, _to_int) 565 #define double_to_uint CONCAT(from_double, _to_uint) 566 #define double_to_long CONCAT(from_double, _to_long) 567 #define double_to_ulong CONCAT(from_double, _to_ulong) 568 #define double_to_llong CONCAT(from_double, _to_llong) 569 #define double_to_ullong CONCAT(from_double, _to_ullong) 570 571 #define long_double_to_float CONCAT(from_long_double, _to_float) 572 #define long_double_to_double CONCAT(from_long_double, _to_double) 573 #define long_double_to_int CONCAT(from_long_double, _to_int) 574 #define long_double_to_uint CONCAT(from_long_double, _to_uint) 575 #define long_double_to_long CONCAT(from_long_double, _to_long) 576 #define long_double_to_ulong CONCAT(from_long_double, _to_ulong) 577 #define long_double_to_llong CONCAT(from_long_double, _to_llong) 578 #define long_double_to_ullong CONCAT(from_long_double, _to_ullong) 579 580 #define int_to_float CONCAT(from_int, _to_float) 581 #define int_to_double CONCAT(from_int, _to_double) 582 #define int_to_long_double CONCAT(from_int, _to_long_double) 583 584 #define uint_to_float CONCAT(from_uint, _to_float) 585 #define uint_to_double CONCAT(from_uint, _to_double) 586 #define uint_to_long_double CONCAT(from_uint, _to_long_double) 587 588 #define long_to_float CONCAT(from_long, _to_float) 589 #define long_to_double CONCAT(from_long, _to_double) 590 #define long_to_long_double CONCAT(from_long, _to_long_double) 591 592 #define ulong_to_float CONCAT(from_ulong, _to_float) 593 #define ulong_to_double CONCAT(from_ulong, _to_double) 594 #define ulong_to_long_double CONCAT(from_ulong, _to_long_double) 595 596 #define llong_to_float CONCAT(from_llong, _to_float) 597 #define llong_to_double CONCAT(from_llong, _to_double) 598 #define llong_to_long_double CONCAT(from_llong, _to_long_double) 599 600 #define ullong_to_float CONCAT(from_ullong, _to_float) 601 #define ullong_to_double CONCAT(from_ullong, _to_double) 602 #define ullong_to_long_double CONCAT(from_ullong, _to_long_double) 603 150 604 151 605 #endif -
uspace/lib/softfloat/include/softfloat.h
rd9f53877 r90924df 169 169 extern float __powisf2(float, int); 170 170 extern double __powidf2 (double, int); 171 extern long double __powitf2 (long double, int); 172 extern long double __powixf2 (long double, int); 173 174 171 extern long double __powitf2(long double, int); 172 extern long double __powixf2(long double, int); 175 173 176 174 /* SPARC quadruple-precision wrappers */ -
uspace/lib/softfloat/include/sub.h
rd9f53877 r90924df 37 37 #define __SUB_H__ 38 38 39 extern float32 subFloat32(float32, float32); 40 extern float64 subFloat64(float64, float64); 41 extern float128 subFloat128(float128, float128); 39 extern float32 sub_float32(float32, float32); 40 extern float64 sub_float64(float64, float64); 41 extern float96 sub_float96(float96, float96); 42 extern float128 sub_float128(float128, float128); 42 43 43 44 #endif -
uspace/lib/softint/generic/division.c
rd9f53877 r90924df 37 37 #include <division.h> 38 38 39 #define ABSVAL(x) ( (x) > 0 ? (x) : -(x)) 40 #define SGN(x) ( (x) >= 0 ? 1 : 0 ) 41 42 static unsigned int divandmod32(unsigned int a, unsigned int b, unsigned int *remainder) 39 #define ABSVAL(x) ((x) > 0 ? (x) : -(x)) 40 #define SGN(x) ((x) >= 0 ? 1 : 0) 41 42 static unsigned int divandmod32(unsigned int a, unsigned int b, 43 unsigned int *remainder) 43 44 { 44 45 unsigned int result; … … 53 54 } 54 55 55 if ( 56 if (a < b) { 56 57 *remainder = a; 57 58 return 0; 58 59 } 59 60 for ( 60 61 for (; steps > 0; steps--) { 61 62 /* shift one bit to remainder */ 62 *remainder = ( 63 *remainder = ((*remainder) << 1) | (( a >> 31) & 0x1); 63 64 result <<= 1; 64 65 65 66 if (*remainder >= b) { 66 67 67 *remainder -= b; 68 result |= 0x1; 68 69 } 69 70 a <<= 1; 70 71 } 71 72 72 73 return result; 73 74 } 74 75 75 76 static unsigned long long divandmod64(unsigned long long a,unsigned long long b, unsigned long long *remainder)76 static unsigned long long divandmod64(unsigned long long a, 77 unsigned long long b, unsigned long long *remainder) 77 78 { 78 79 unsigned long long result; 79 int steps = sizeof(unsigned long long) * 8; 80 int steps = sizeof(unsigned long long) * 8; 80 81 81 82 *remainder = 0; … … 87 88 } 88 89 89 if ( 90 if (a < b) { 90 91 *remainder = a; 91 92 return 0; 92 93 } 93 94 for ( 94 95 for (; steps > 0; steps--) { 95 96 /* shift one bit to remainder */ 96 *remainder = ( 97 *remainder = ((*remainder) << 1) | ((a >> 63) & 0x1); 97 98 result <<= 1; 98 99 99 100 if (*remainder >= b) { 100 101 101 *remainder -= b; 102 result |= 0x1; 102 103 } 103 104 a <<= 1; 104 105 } 105 106 106 107 return result; 107 108 } 108 109 109 110 /* 32bit integer division */ 110 int __divsi3(int a, int b) 111 { 112 unsigned int rem; 113 int result ;114 115 result = (int)divandmod32(ABSVAL(a), ABSVAL(b), &rem);116 117 if ( SGN(a) == SGN(b)) return result;111 int __divsi3(int a, int b) 112 { 113 unsigned int rem; 114 int result = (int) divandmod32(ABSVAL(a), ABSVAL(b), &rem); 115 116 if (SGN(a) == SGN(b)) 117 return result; 118 118 119 return -result; 119 120 } 120 121 121 122 /* 64bit integer division */ 122 long long __divdi3(long long a, long long b) 123 { 124 unsigned long long rem; 125 long long result ;126 127 result = (long long)divandmod64(ABSVAL(a), ABSVAL(b), &rem);128 129 if ( SGN(a) == SGN(b)) return result;123 long long __divdi3(long long a, long long b) 124 { 125 unsigned long long rem; 126 long long result = (long long) divandmod64(ABSVAL(a), ABSVAL(b), &rem); 127 128 if (SGN(a) == SGN(b)) 129 return result; 130 130 131 return -result; 131 132 } … … 141 142 unsigned long long __udivdi3(unsigned long long a, unsigned long long b) 142 143 { 143 unsigned long long 144 unsigned long long rem; 144 145 return divandmod64(a, b, &rem); 145 146 } … … 152 153 153 154 /* if divident is negative, remainder must be too */ 154 if (!(SGN(a))) { 155 return -((int)rem); 156 } 157 158 return (int)rem; 155 if (!(SGN(a))) 156 return -((int) rem); 157 158 return (int) rem; 159 159 } 160 160 161 161 /* 64bit remainder of the signed division */ 162 long long __moddi3(long long a, longlong b)162 long long __moddi3(long long a, long long b) 163 163 { 164 164 unsigned long long rem; … … 166 166 167 167 /* if divident is negative, remainder must be too */ 168 if (!(SGN(a))) { 169 return -((long long)rem); 170 } 171 172 return (long long)rem; 168 if (!(SGN(a))) 169 return -((long long) rem); 170 171 return (long long) rem; 173 172 } 174 173 … … 189 188 } 190 189 191 unsigned long long __udivmoddi3(unsigned long long a, unsigned long long b, unsigned long long *c) 190 int __divmodsi3(int a, int b, int *c) 191 { 192 unsigned int rem; 193 int result = (int) divandmod32(ABSVAL(a), ABSVAL(b), &rem); 194 195 if (SGN(a) == SGN(b)) { 196 *c = rem; 197 return result; 198 } 199 200 *c = -rem; 201 return -result; 202 } 203 204 unsigned int __udivmodsi3(unsigned int a, unsigned int b, 205 unsigned int *c) 206 { 207 return divandmod32(a, b, c); 208 } 209 210 long long __divmoddi3(long long a, long long b, long long *c) 211 { 212 unsigned long long rem; 213 long long result = (int) divandmod64(ABSVAL(a), ABSVAL(b), &rem); 214 215 if (SGN(a) == SGN(b)) { 216 *c = rem; 217 return result; 218 } 219 220 *c = -rem; 221 return -result; 222 } 223 224 unsigned long long __udivmoddi3(unsigned long long a, unsigned long long b, 225 unsigned long long *c) 192 226 { 193 227 return divandmod64(a, b, c); -
uspace/lib/softint/include/comparison.h
rd9f53877 r90924df 38 38 39 39 /* Signed comparison (a < b => 0, a == b => 1, a > b => 2). */ 40 int __cmpdi2 (long long a, long long b);40 extern int __cmpdi2(long long, long long); 41 41 42 42 /* Unsigned comparison (a < b => 0, a == b => 1, a > b => 2). */ 43 int __ucmpdi2 (unsigned long long a, unsigned long long b);43 extern int __ucmpdi2(unsigned long long, unsigned long long); 44 44 45 45 #endif -
uspace/lib/softint/include/division.h
rd9f53877 r90924df 29 29 /** @addtogroup softint 30 30 * @{ 31 */ 31 */ 32 32 /** 33 33 * @file … … 37 37 #define __SOFTINT_DIVISION_H__ 38 38 39 extern int __divsi3(int, int); 40 extern long long __divdi3(long long, long long); 39 41 40 /* 32bit integer division */ 41 int __divsi3(int a, int b);42 extern unsigned int __udivsi3(unsigned int, unsigned int); 43 extern unsigned long long __udivdi3(unsigned long long, unsigned long long); 42 44 43 /* 64bit integer division */ 44 long long __divdi3(long long a, long long b);45 extern int __modsi3(int, int); 46 extern long long __moddi3(long long, long long); 45 47 46 /* 32bit unsigned integer division */ 47 unsigned int __udivsi3(unsigned int a, unsigned int b);48 extern unsigned int __umodsi3(unsigned int, unsigned int); 49 extern unsigned long long __umoddi3(unsigned long long, unsigned long long); 48 50 49 /* 64bit unsigned integer division */ 50 unsigned long long __udivdi3(unsigned long long a, unsigned long long b);51 extern int __divmodsi3(int, int, int *); 52 extern unsigned int __udivmodsi3(unsigned int, unsigned int, unsigned int *); 51 53 52 /* 32bit remainder of the signed division */ 53 int __modsi3(int a, int b); 54 55 /* 64bit remainder of the signed division */ 56 long long __moddi3(long long a, long long b); 57 58 /* 32bit remainder of the unsigned division */ 59 unsigned int __umodsi3(unsigned int a, unsigned int b); 60 61 /* 64bit remainder of the unsigned division */ 62 unsigned long long __umoddi3(unsigned long long a, unsigned long long b); 63 64 unsigned long long __udivmoddi3(unsigned long long a, unsigned long long b, unsigned long long *c); 54 extern long long __divmoddi3(long long, long long, long long *); 55 extern unsigned long long __udivmoddi3(unsigned long long, unsigned long long, 56 unsigned long long *); 65 57 66 58 #endif … … 68 60 /** @} 69 61 */ 70 -
uspace/lib/softint/include/lltype.h
rd9f53877 r90924df 39 39 #include <stdint.h> 40 40 41 #define HALF_BIT_CNT (sizeof(int32_t) * sizeof(char))42 #define WHOLE_BIT_CNT (sizeof(int64_t) * sizeof(char))41 #define HALF_BIT_CNT (sizeof(int32_t) * sizeof(char)) 42 #define WHOLE_BIT_CNT (sizeof(int64_t) * sizeof(char)) 43 43 44 44 #ifdef __BE__ -
uspace/lib/softint/include/multiplication.h
rd9f53877 r90924df 29 29 /** @addtogroup softint 30 30 * @{ 31 */ 31 */ 32 32 /** 33 33 * @file … … 38 38 39 39 /* 64 bit multiplication */ 40 long long __muldi3(long long a, long long b);40 extern long long __muldi3(long long, long long); 41 41 42 42 #endif -
uspace/lib/softint/include/shift.h
rd9f53877 r90924df 38 38 39 39 /* Arithmetic/logical shift left. */ 40 long long __ashldi3 (long long val, int shift);40 extern long long __ashldi3(long long, int); 41 41 42 42 /* Arithmetic shift right. */ 43 long long __ashrdi3 (long long val, int shift);43 extern long long __ashrdi3(long long, int); 44 44 45 45 /* Logical shift right. */ 46 long long __lshrdi3 (long long val, int shift);46 extern long long __lshrdi3(long long, int); 47 47 48 48 #endif -
uspace/srv/fs/exfat/exfat_fat.c
rd9f53877 r90924df 127 127 { 128 128 exfat_cluster_t firstc = nodep->firstc; 129 exfat_cluster_t currc ;129 exfat_cluster_t currc = 0; 130 130 aoff64_t relbn = bn; 131 131 int rc; -
uspace/srv/hid/fb/port/ega.c
rd9f53877 r90924df 117 117 uint8_t glyph; 118 118 119 if ( (field->ch >= 0) && (field->ch < 128))119 if (ascii_check(field->ch)) 120 120 glyph = field->ch; 121 121 else -
uspace/srv/hid/fb/port/kchar.c
rd9f53877 r90924df 48 48 static void kchar_putchar(wchar_t ch) 49 49 { 50 if ( (ch >= 0) && (ch < 128))50 if (ascii_check(ch)) 51 51 *kchar.addr = ch; 52 52 else -
uspace/srv/hid/fb/port/kfb.c
rd9f53877 r90924df 409 409 charfield_t *field = screenbuffer_field_at(vp->backbuf, col, row); 410 410 411 pixel_t bgcolor ;412 pixel_t fgcolor ;411 pixel_t bgcolor = 0; 412 pixel_t fgcolor = 0; 413 413 attrs_rgb(field->attrs, &bgcolor, &fgcolor); 414 414 … … 525 525 } 526 526 527 pixel_t bgcolor ;528 pixel_t fgcolor ;527 pixel_t bgcolor = 0; 528 pixel_t fgcolor = 0; 529 529 attrs_rgb(vp->attrs, &bgcolor, &fgcolor); 530 530 -
uspace/srv/hid/fb/port/niagara.c
rd9f53877 r90924df 68 68 static void niagara_putchar(wchar_t ch) 69 69 { 70 if ( (ch >= 0) && (ch < 128))70 if (ascii_check(ch)) 71 71 niagara_putc(ch); 72 72 else
Note:
See TracChangeset
for help on using the changeset viewer.