Changeset 9539be6 in mainline
- Timestamp:
- 2010-06-22T14:13:55Z (14 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 851f33a
- Parents:
- 402eda5
- Files:
-
- 8 deleted
- 22 edited
- 2 moved
Legend:
- Unmodified
- Added
- Removed
-
boot/genarch/src/multiplication.c
r402eda5 r9539be6 33 33 34 34 #include <genarch/multiplication.h> 35 #include <typedefs.h> 35 36 36 /** Set 1 to return MAX_INT64 or MIN_INT64on overflow */37 /** Set 1 to return INT64_MAX or INT64_MIN on overflow */ 37 38 #ifndef SOFTINT_CHECK_OF 38 #define SOFTINT_CHECK_OF 039 #define SOFTINT_CHECK_OF 0 39 40 #endif 40 41 #define MAX_UINT16 (0xFFFFu)42 #define MAX_UINT32 (0xFFFFFFFFu)43 #define MAX_INT64 (0x7FFFFFFFFFFFFFFFll)44 #define MIN_INT64 (0x8000000000000000ll)45 41 46 42 /** Multiply two integers and return long long as result. … … 51 47 static unsigned long long mul(unsigned int a, unsigned int b) { 52 48 unsigned int a1 = a >> 16; 53 unsigned int a2 = a & MAX_UINT16;49 unsigned int a2 = a & UINT16_MAX; 54 50 unsigned int b1 = b >> 16; 55 unsigned int b2 = b & MAX_UINT16;51 unsigned int b2 = b & UINT16_MAX; 56 52 57 53 unsigned long long t1 = a1 * b1; … … 85 81 unsigned long long b1 = b >> 32; 86 82 87 unsigned long long a2 = a & ( MAX_UINT32);88 unsigned long long b2 = b & ( MAX_UINT32);83 unsigned long long a2 = a & (UINT32_MAX); 84 unsigned long long b2 = b & (UINT32_MAX); 89 85 90 86 if (SOFTINT_CHECK_OF && (a1 != 0) && (b1 != 0)) { 91 87 /* Error (overflow) */ 92 return (neg ? MIN_INT64 : MAX_INT64);88 return (neg ? INT64_MIN : INT64_MAX); 93 89 } 94 90 … … 98 94 unsigned long long t1 = mul(a1, b2) + mul(b1, a2); 99 95 100 if ((SOFTINT_CHECK_OF) && (t1 > MAX_UINT32)) {96 if ((SOFTINT_CHECK_OF) && (t1 > UINT32_MAX)) { 101 97 /* Error (overflow) */ 102 return (neg ? MIN_INT64 : MAX_INT64);98 return (neg ? INT64_MIN : INT64_MAX); 103 99 } 104 100 … … 112 108 if ((SOFTINT_CHECK_OF) && ((t2 < t1) || (t2 & (1ull << 63)))) { 113 109 /* Error (overflow) */ 114 return (neg ? MIN_INT64 : MAX_INT64);110 return (neg ? INT64_MIN : INT64_MAX); 115 111 } 116 112 -
boot/generic/include/stdint.h
r402eda5 r9539be6 27 27 */ 28 28 29 /** @addtogroup libcia6430 * @{31 */32 29 /** @file 33 30 */ 34 31 35 #ifndef LIBC_ia64_LIMITS_H_36 #define LIBC_ia64_LIMITS_H_32 #ifndef BOOT_STDINT_H_ 33 #define BOOT_STDINT_H_ 37 34 38 #define LONG_MIN MIN_INT64 39 #define LONG_MAX MAX_INT64 40 #define ULONG_MIN MIN_UINT64 41 #define ULONG_MAX MAX_UINT64 35 #define INT8_MIN (0x80) 36 #define INT8_MAX (0x7F) 42 37 43 #define SIZE_MIN MIN_UINT64 44 #define SIZE_MAX MAX_UINT64 45 #define SSIZE_MIN MIN_INT64 46 #define SSIZE_MAX MAX_INT64 38 #define UINT8_MIN (0u) 39 #define UINT8_MAX (0xFFu) 40 41 #define INT16_MIN (0x8000) 42 #define INT16_MAX (0x7FFF) 43 44 #define UINT16_MIN (0u) 45 #define UINT16_MAX (0xFFFFu) 46 47 #define INT32_MIN (0x80000000l) 48 #define INT32_MAX (0x7FFFFFFFl) 49 50 #define UINT32_MIN (0ul) 51 #define UINT32_MAX (0xFFFFFFFFul) 52 53 #define INT64_MIN (0x8000000000000000ll) 54 #define INT64_MAX (0x7FFFFFFFFFFFFFFFll) 55 56 #define UINT64_MIN (0ull) 57 #define UINT64_MAX (0xFFFFFFFFFFFFFFFFull) 47 58 48 59 #endif -
boot/generic/include/typedefs.h
r402eda5 r9539be6 33 33 #define BOOT_TYPEDEFS_H_ 34 34 35 #include <stdint.h> 35 36 #include <arch/common.h> 36 37 #include <arch/types.h> -
kernel/generic/include/stdint.h
r402eda5 r9539be6 27 27 */ 28 28 29 /** @addtogroup libcamd6429 /** @addtogroup generic 30 30 * @{ 31 31 */ … … 33 33 */ 34 34 35 #ifndef LIBC_amd64_LIMITS_H_36 #define LIBC_amd64_LIMITS_H_35 #ifndef KERN_STDINT_H_ 36 #define KERN_STDINT_H_ 37 37 38 #define LONG_MIN MIN_INT64 39 #define LONG_MAX MAX_INT64 40 #define ULONG_MIN MIN_UINT64 41 #define ULONG_MAX MAX_UINT64 38 #define INT8_MIN (0x80) 39 #define INT8_MAX (0x7F) 42 40 43 #define SIZE_MIN MIN_UINT64 44 #define SIZE_MAX MAX_UINT64 45 #define SSIZE_MIN MIN_INT64 46 #define SSIZE_MAX MAX_INT64 41 #define UINT8_MIN (0u) 42 #define UINT8_MAX (0xFFu) 43 44 #define INT16_MIN (0x8000) 45 #define INT16_MAX (0x7FFF) 46 47 #define UINT16_MIN (0u) 48 #define UINT16_MAX (0xFFFFu) 49 50 #define INT32_MIN (0x80000000l) 51 #define INT32_MAX (0x7FFFFFFFl) 52 53 #define UINT32_MIN (0ul) 54 #define UINT32_MAX (0xFFFFFFFFul) 55 56 #define INT64_MIN (0x8000000000000000ll) 57 #define INT64_MAX (0x7FFFFFFFFFFFFFFFll) 58 59 #define UINT64_MIN (0ull) 60 #define UINT64_MAX (0xFFFFFFFFFFFFFFFFull) 47 61 48 62 #endif -
kernel/generic/include/typedefs.h
r402eda5 r9539be6 36 36 #define KERN_TYPEDEFS_H_ 37 37 38 #include <stdint.h> 38 39 #include <arch/common.h> 39 40 #include <arch/types.h> -
tools/autotool.py
r402eda5 r9539be6 54 54 COMPILER_FAIL = "The compiler is probably not capable to compile HelenOS." 55 55 56 PROBE_HEAD = """#define AUTOTOOL_DECLARE(category, subcategory, name, value) \\56 PROBE_HEAD = """#define AUTOTOOL_DECLARE(category, subcategory, tag, name, value) \\ 57 57 asm volatile ( \\ 58 "AUTOTOOL_DECLARE\\t" category "\\t" subcategory "\\t" name "\\t%[val]\\n" \\58 "AUTOTOOL_DECLARE\\t" category "\\t" subcategory "\\t" tag "\\t" name "\\t%[val]\\n" \\ 59 59 : \\ 60 60 : [val] "n" (value) \\ 61 61 ) 62 62 63 #define DECLARE_INTSIZE(t ype) \\64 AUTOTOOL_DECLARE("intsize", "unsigned", #type, sizeof(unsigned type)); \\65 AUTOTOOL_DECLARE("intsize", "signed", #type, sizeof(signed type))63 #define DECLARE_INTSIZE(tag, type) \\ 64 AUTOTOOL_DECLARE("intsize", "unsigned", tag, #type, sizeof(unsigned type)); \\ 65 AUTOTOOL_DECLARE("intsize", "signed", tag, #type, sizeof(signed type)) 66 66 67 67 int main(int argc, char *argv[]) … … 195 195 196 196 for typedef in sizes: 197 outf.write("\tDECLARE_INTSIZE( %s);\n" % typedef)197 outf.write("\tDECLARE_INTSIZE(\"%s\", %s);\n" % (typedef['tag'], typedef['type'])) 198 198 199 199 outf.write(PROBE_TAIL) … … 228 228 signed_sizes = {} 229 229 230 unsigned_tags = {} 231 signed_tags = {} 232 230 233 for j in range(len(lines)): 231 234 tokens = lines[j].strip().split("\t") … … 238 241 category = tokens[1] 239 242 subcategory = tokens[2] 240 name = tokens[3] 241 value = tokens[4] 243 tag = tokens[3] 244 name = tokens[4] 245 value = tokens[5] 242 246 243 247 if (category == "intsize"): … … 258 262 if (subcategory == "unsigned"): 259 263 unsigned_sizes[name] = value_int 264 unsigned_tags[tag] = value_int 260 265 elif (subcategory == "signed"): 261 266 signed_sizes[name] = value_int 267 signed_tags[tag] = value_int 262 268 else: 263 269 print_error(["Unexpected keyword \"%s\" in \"%s\" on line %s." % (subcategory, PROBE_OUTPUT, j), COMPILER_FAIL]) 264 270 265 return {'unsigned_sizes' : unsigned_sizes, 'signed_sizes' : signed_sizes }266 267 def detect_uints( unsigned_sizes, signed_sizes, bytes):271 return {'unsigned_sizes' : unsigned_sizes, 'signed_sizes' : signed_sizes, 'unsigned_tags': unsigned_tags, 'signed_tags': signed_tags} 272 273 def detect_uints(probe, bytes): 268 274 "Detect correct types for fixed-size integer types" 269 275 276 macros = [] 270 277 typedefs = [] 271 278 … … 274 281 newtype = "uint%s_t" % (b * 8) 275 282 276 for name, value in unsigned_sizes.items():283 for name, value in probe['unsigned_sizes'].items(): 277 284 if (value == b): 278 285 oldtype = "unsigned %s" % name … … 289 296 newtype = "int%s_t" % (b * 8) 290 297 291 for name, value in signed_sizes.items():298 for name, value in probe['signed_sizes'].items(): 292 299 if (value == b): 293 300 oldtype = "signed %s" % name … … 300 307 COMPILER_FAIL]) 301 308 302 return typedefs 309 for tag in ['CHAR', 'SHORT', 'INT', 'LONG', 'LLONG']: 310 fnd = False; 311 newmacro = "U%s" % tag 312 313 for name, value in probe['unsigned_tags'].items(): 314 if (name == tag): 315 oldmacro = "UINT%s" % (value * 8) 316 macros.append({'oldmacro': "%s_MIN" % oldmacro, 'newmacro': "%s_MIN" % newmacro}) 317 macros.append({'oldmacro': "%s_MAX" % oldmacro, 'newmacro': "%s_MAX" % newmacro}) 318 fnd = True 319 break 320 321 if (not fnd): 322 print_error(['Unable to find appropriate size macro for %s' % newmacro, 323 COMPILER_FAIL]) 324 325 fnd = False; 326 newmacro = tag 327 328 for name, value in probe['signed_tags'].items(): 329 if (name == tag): 330 oldmacro = "INT%s" % (value * 8) 331 macros.append({'oldmacro': "%s_MIN" % oldmacro, 'newmacro': "%s_MIN" % newmacro}) 332 macros.append({'oldmacro': "%s_MAX" % oldmacro, 'newmacro': "%s_MAX" % newmacro}) 333 fnd = True 334 break 335 336 if (not fnd): 337 print_error(['Unable to find appropriate size macro for %s' % newmacro, 338 COMPILER_FAIL]) 339 340 return {'macros': macros, 'typedefs': typedefs} 303 341 304 342 def create_makefile(mkname, common): … … 316 354 outmk.close() 317 355 318 def create_header(hdname, typedefs):356 def create_header(hdname, maps): 319 357 "Create header output" 320 358 … … 328 366 outhd.write('#define %s\n\n' % GUARD) 329 367 330 for typedef in typedefs: 368 for macro in maps['macros']: 369 outhd.write('#define %s %s\n' % (macro['newmacro'], macro['oldmacro'])) 370 371 outhd.write('\n') 372 373 for typedef in maps['typedefs']: 331 374 outhd.write('typedef %s %s;\n' % (typedef['oldtype'], typedef['newtype'])) 332 375 … … 465 508 probe = probe_compiler(common, 466 509 [ 467 "char",468 "short int",469 "int",470 "long int",471 "long long int",510 {'type': 'char', 'tag': 'CHAR'}, 511 {'type': 'short int', 'tag': 'SHORT'}, 512 {'type': 'int', 'tag': 'INT'}, 513 {'type': 'long int', 'tag': 'LONG'}, 514 {'type': 'long long int', 'tag': 'LLONG'} 472 515 ] 473 516 ) 474 517 475 typedefs = detect_uints(probe['unsigned_sizes'], probe['signed_sizes'], [1, 2, 4, 8])518 maps = detect_uints(probe, [1, 2, 4, 8]) 476 519 477 520 finally: … … 479 522 480 523 create_makefile(MAKEFILE, common) 481 create_header(HEADER, typedefs)524 create_header(HEADER, maps) 482 525 483 526 return 0 -
uspace/lib/c/arch/abs32le/include/types.h
r402eda5 r9539be6 40 40 #include <libarch/common.h> 41 41 42 #define SIZE_MIN UINT32_MIN 43 #define SIZE_MAX UINT32_MAX 44 45 #define SSIZE_MIN INT32_MIN 46 #define SSIZE_MAX INT32_MAX 47 42 48 typedef uint32_t sysarg_t; 43 49 -
uspace/lib/c/arch/amd64/include/types.h
r402eda5 r9539be6 40 40 #include <libarch/common.h> 41 41 42 #define SIZE_MIN UINT64_MIN 43 #define SIZE_MAX UINT64_MAX 44 45 #define SSIZE_MIN INT64_MIN 46 #define SSIZE_MAX INT64_MAX 47 42 48 typedef uint64_t sysarg_t; 43 49 -
uspace/lib/c/arch/arm32/include/types.h
r402eda5 r9539be6 41 41 #include <libarch/common.h> 42 42 43 #define SIZE_MIN UINT32_MIN 44 #define SIZE_MAX UINT32_MAX 45 46 #define SSIZE_MIN INT32_MIN 47 #define SSIZE_MAX INT32_MAX 48 43 49 typedef uint32_t sysarg_t; 44 50 -
uspace/lib/c/arch/ia32/include/types.h
r402eda5 r9539be6 40 40 #include <libarch/common.h> 41 41 42 #define SIZE_MIN UINT32_MIN 43 #define SIZE_MAX UINT32_MAX 44 45 #define SSIZE_MIN INT32_MIN 46 #define SSIZE_MAX INT32_MAX 47 42 48 typedef uint32_t sysarg_t; 43 49 -
uspace/lib/c/arch/ia64/include/types.h
r402eda5 r9539be6 40 40 #include <libarch/common.h> 41 41 42 #define SIZE_MIN UINT64_MIN 43 #define SIZE_MAX UINT64_MAX 44 45 #define SSIZE_MIN INT64_MIN 46 #define SSIZE_MAX INT64_MAX 47 42 48 typedef struct { 43 49 uint64_t lo; -
uspace/lib/c/arch/mips32/include/types.h
r402eda5 r9539be6 41 41 #include <libarch/common.h> 42 42 43 #define SIZE_MIN UINT32_MIN 44 #define SIZE_MAX UINT32_MAX 45 46 #define SSIZE_MIN INT32_MIN 47 #define SSIZE_MAX INT32_MAX 48 43 49 typedef uint32_t sysarg_t; 44 50 -
uspace/lib/c/arch/ppc32/include/types.h
r402eda5 r9539be6 40 40 #include <libarch/common.h> 41 41 42 #define SIZE_MIN UINT32_MIN 43 #define SIZE_MAX UINT32_MAX 44 45 #define SSIZE_MIN INT32_MIN 46 #define SSIZE_MAX INT32_MAX 47 42 48 typedef uint32_t sysarg_t; 43 49 -
uspace/lib/c/arch/sparc64/include/types.h
r402eda5 r9539be6 40 40 #include <libarch/common.h> 41 41 42 #define SIZE_MIN UINT64_MIN 43 #define SIZE_MAX UINT64_MAX 44 45 #define SSIZE_MIN INT64_MIN 46 #define SSIZE_MAX INT64_MAX 47 42 48 typedef uint64_t sysarg_t; 43 49 -
uspace/lib/c/generic/str.c
r402eda5 r9539be6 37 37 #include <stdlib.h> 38 38 #include <assert.h> 39 #include < limits.h>39 #include <stdint.h> 40 40 #include <ctype.h> 41 41 #include <malloc.h> -
uspace/lib/c/include/stdint.h
r402eda5 r9539be6 36 36 #define LIBC_STDINT_H_ 37 37 38 /* Definitions of types with fixed size */ 38 #define INT8_MIN (0x80) 39 #define INT8_MAX (0x7F) 40 41 #define UINT8_MIN (0u) 42 #define UINT8_MAX (0xFFu) 43 44 #define INT16_MIN (0x8000) 45 #define INT16_MAX (0x7FFF) 46 47 #define UINT16_MIN (0u) 48 #define UINT16_MAX (0xFFFFu) 49 50 #define INT32_MIN (0x80000000l) 51 #define INT32_MAX (0x7FFFFFFFl) 52 53 #define UINT32_MIN (0ul) 54 #define UINT32_MAX (0xFFFFFFFFul) 55 56 #define INT64_MIN (0x8000000000000000ll) 57 #define INT64_MAX (0x7FFFFFFFFFFFFFFFll) 58 59 #define UINT64_MIN (0ull) 60 #define UINT64_MAX (0xFFFFFFFFFFFFFFFFull) 61 39 62 #include <libarch/types.h> 40 63 41 #define MAX_INT8 (0x7F) 42 #define MIN_INT8 (0x80) 43 #define MAX_UINT8 (0xFFu) 44 #define MIN_UINT8 (0u) 64 /* off64_t */ 65 #define OFF64_MIN INT64_MIN 66 #define OFF64_MAX INT64_MAX 45 67 46 #define MAX_INT16 (0x7FFF) 47 #define MIN_INT16 (0x8000) 48 #define MAX_UINT16 (0xFFFFu) 49 #define MIN_UINT16 (0u) 50 51 #define MAX_INT32 (0x7FFFFFFF) 52 #define MIN_INT32 (0x80000000) 53 #define MAX_UINT32 (0xFFFFFFFFu) 54 #define MIN_UINT32 (0u) 55 56 #define MAX_INT64 (0x7FFFFFFFFFFFFFFFll) 57 #define MIN_INT64 (0x8000000000000000ll) 58 #define MAX_UINT64 (0xFFFFFFFFFFFFFFFFull) 59 #define MIN_UINT64 (0ull) 68 /* aoff64_t */ 69 #define AOFF64_MIN UINT64_MIN 70 #define AOFF64_MAX UINT64_MAX 60 71 61 72 #endif -
uspace/lib/pci/types.h
r402eda5 r9539be6 18 18 19 19 #ifdef PCI_HAVE_64BIT_ADDRESS 20 #include <limits.h> 20 21 #include <stdint.h> 22 21 23 #if ULONG_MAX > 0xffffffff 24 22 25 typedef unsigned long u64; 23 26 #define PCI_U64_FMT "l" 24 #else 27 28 #else /* ULONG_MAX > 0xffffffff */ 29 25 30 typedef unsigned long long u64; 26 31 #define PCI_U64_FMT "ll" 27 #endif28 #endif29 32 30 #endif /* PCI_HAVE_Uxx_TYPES */ 33 #endif /* ULONG_MAX > 0xffffffff */ 34 #endif /* PCI_HAVE_64BIT_ADDRESS */ 35 #endif /* PCI_HAVE_Uxx_TYPES */ 31 36 32 37 #ifdef PCI_HAVE_64BIT_ADDRESS 38 33 39 typedef u64 pciaddr_t; 34 40 #define PCIADDR_T_FMT "%08" PCI_U64_FMT "x" 35 41 #define PCIADDR_PORT_FMT "%04" PCI_U64_FMT "x" 36 #else 42 43 #else /* PCI_HAVE_64BIT_ADDRESS */ 44 37 45 typedef u32 pciaddr_t; 38 46 #define PCIADDR_T_FMT "%08x" 39 47 #define PCIADDR_PORT_FMT "%04x" 40 #endif 48 49 #endif /* PCI_HAVE_64BIT_ADDRESS */ 41 50 42 51 #ifdef PCI_ARCH_SPARC64 52 43 53 /* On sparc64 Linux the kernel reports remapped port addresses and IRQ numbers */ 44 54 #undef PCIADDR_PORT_FMT 45 55 #define PCIADDR_PORT_FMT PCIADDR_T_FMT 46 56 #define PCIIRQ_FMT "%08x" 47 #else 57 58 #else /* PCI_ARCH_SPARC64 */ 59 48 60 #define PCIIRQ_FMT "%d" 49 #endif 61 62 #endif /* PCI_ARCH_SPARC64 */ -
uspace/lib/socket/generic/socket_client.c
r402eda5 r9539be6 40 40 #include <async.h> 41 41 #include <fibril_synch.h> 42 #include < limits.h>42 #include <stdint.h> 43 43 #include <stdlib.h> 44 44 -
uspace/lib/socket/generic/socket_core.c
r402eda5 r9539be6 35 35 */ 36 36 37 #include < limits.h>37 #include <stdint.h> 38 38 #include <stdlib.h> 39 39 -
uspace/lib/softfloat/generic/conversion.c
r402eda5 r9539be6 27 27 */ 28 28 29 /** @addtogroup softfloat 29 /** @addtogroup softfloat 30 30 * @{ 31 31 */ … … 45 45 result.parts.sign = a.parts.sign; 46 46 result.parts.fraction = a.parts.fraction; 47 result.parts.fraction <<= (FLOAT64_FRACTION_SIZE - FLOAT32_FRACTION_SIZE 48 49 if ((isFloat32Infinity(a)) ||(isFloat32NaN(a))) {47 result.parts.fraction <<= (FLOAT64_FRACTION_SIZE - FLOAT32_FRACTION_SIZE); 48 49 if ((isFloat32Infinity(a)) || (isFloat32NaN(a))) { 50 50 result.parts.exp = 0x7FF; 51 51 /* TODO; check if its correct for SigNaNs*/ … … 53 53 }; 54 54 55 result.parts.exp = a.parts.exp + ( (int)FLOAT64_BIAS - FLOAT32_BIAS);55 result.parts.exp = a.parts.exp + ((int) FLOAT64_BIAS - FLOAT32_BIAS); 56 56 if (a.parts.exp == 0) { 57 57 /* normalize denormalized numbers */ … … 181 181 uint32_t float32_to_uint32(float32 a) 182 182 { 183 if (isFloat32NaN(a)) { 184 return MAX_UINT32; 185 } 186 187 if (isFloat32Infinity(a) || (a.parts.exp >= (32 + FLOAT32_BIAS))) { 188 if (a.parts.sign) { 189 return MIN_UINT32; 190 } 191 return MAX_UINT32; 192 } 193 194 return _float32_to_uint32_helper(a); 183 if (isFloat32NaN(a)) 184 return UINT32_MAX; 185 186 if (isFloat32Infinity(a) || (a.parts.exp >= (32 + FLOAT32_BIAS))) { 187 if (a.parts.sign) 188 return UINT32_MIN; 189 190 return UINT32_MAX; 191 } 192 193 return _float32_to_uint32_helper(a); 195 194 } 196 195 … … 201 200 int32_t float32_to_int32(float32 a) 202 201 { 203 if (isFloat32NaN(a)) {204 return MAX_INT32;205 }206 207 if (isFloat32Infinity(a) || (a.parts.exp >= (32 + FLOAT32_BIAS))) {208 if (a.parts.sign) {209 return MIN_INT32;210 }211 return MAX_INT32;212 }202 if (isFloat32NaN(a)) 203 return INT32_MAX; 204 205 if (isFloat32Infinity(a) || (a.parts.exp >= (32 + FLOAT32_BIAS))) { 206 if (a.parts.sign) 207 return INT32_MIN; 208 209 return INT32_MAX; 210 } 211 213 212 return _float32_to_uint32_helper(a); 214 } 213 } 215 214 216 215 … … 249 248 uint64_t float64_to_uint64(float64 a) 250 249 { 251 if (isFloat64NaN(a)) {252 return MAX_UINT64;253 }254 255 if (isFloat64Infinity(a) || (a.parts.exp >= (64 + FLOAT64_BIAS))) 256 if (a.parts.sign) {257 return MIN_UINT64;258 }259 return MAX_UINT64;260 } 261 262 return _float64_to_uint64_helper(a); 250 if (isFloat64NaN(a)) 251 return UINT64_MAX; 252 253 254 if (isFloat64Infinity(a) || (a.parts.exp >= (64 + FLOAT64_BIAS))) { 255 if (a.parts.sign) 256 return UINT64_MIN; 257 258 return UINT64_MAX; 259 } 260 261 return _float64_to_uint64_helper(a); 263 262 } 264 263 … … 269 268 int64_t float64_to_int64(float64 a) 270 269 { 271 if (isFloat64NaN(a)) { 272 return MAX_INT64; 273 } 274 275 if (isFloat64Infinity(a) || (a.parts.exp >= (64 + FLOAT64_BIAS))) { 276 if (a.parts.sign) { 277 return MIN_INT64; 278 } 279 return MAX_INT64; 280 } 270 if (isFloat64NaN(a)) 271 return INT64_MAX; 272 273 274 if (isFloat64Infinity(a) || (a.parts.exp >= (64 + FLOAT64_BIAS))) { 275 if (a.parts.sign) 276 return INT64_MIN; 277 278 return INT64_MAX; 279 } 280 281 281 return _float64_to_uint64_helper(a); 282 } 282 } 283 283 284 284 … … 320 320 uint64_t float32_to_uint64(float32 a) 321 321 { 322 if (isFloat32NaN(a)) {323 return MAX_UINT64;324 }325 326 if (isFloat32Infinity(a) || (a.parts.exp >= (64 + FLOAT32_BIAS))) 327 if (a.parts.sign) {328 return MIN_UINT64;329 }330 return MAX_UINT64;331 } 332 333 return _float32_to_uint64_helper(a); 322 if (isFloat32NaN(a)) 323 return UINT64_MAX; 324 325 326 if (isFloat32Infinity(a) || (a.parts.exp >= (64 + FLOAT32_BIAS))) { 327 if (a.parts.sign) 328 return UINT64_MIN; 329 330 return UINT64_MAX; 331 } 332 333 return _float32_to_uint64_helper(a); 334 334 } 335 335 … … 340 340 int64_t float32_to_int64(float32 a) 341 341 { 342 if (isFloat32NaN(a)) {343 return MAX_INT64;344 }345 346 if (isFloat32Infinity(a) || (a.parts.exp >= (64 + FLOAT32_BIAS))) {347 if (a.parts.sign) {348 return (MIN_INT64);349 }350 return MAX_INT64;351 }342 if (isFloat32NaN(a)) 343 return INT64_MAX; 344 345 if (isFloat32Infinity(a) || (a.parts.exp >= (64 + FLOAT32_BIAS))) { 346 if (a.parts.sign) 347 return INT64_MIN; 348 349 return INT64_MAX; 350 } 351 352 352 return _float32_to_uint64_helper(a); 353 } 353 } 354 354 355 355 … … 360 360 uint32_t float64_to_uint32(float64 a) 361 361 { 362 if (isFloat64NaN(a)) {363 return MAX_UINT32;364 }365 366 if (isFloat64Infinity(a) || (a.parts.exp >= (32 + FLOAT64_BIAS))) 367 if (a.parts.sign) {368 return MIN_UINT32;369 }370 return MAX_UINT32;371 } 372 373 return (uint32_t) _float64_to_uint64_helper(a);362 if (isFloat64NaN(a)) 363 return UINT32_MAX; 364 365 366 if (isFloat64Infinity(a) || (a.parts.exp >= (32 + FLOAT64_BIAS))) { 367 if (a.parts.sign) 368 return UINT32_MIN; 369 370 return UINT32_MAX; 371 } 372 373 return (uint32_t) _float64_to_uint64_helper(a); 374 374 } 375 375 … … 380 380 int32_t float64_to_int32(float64 a) 381 381 { 382 if (isFloat64NaN(a)) { 383 return MAX_INT32; 384 } 385 386 if (isFloat64Infinity(a) || (a.parts.exp >= (32 + FLOAT64_BIAS))) { 387 if (a.parts.sign) { 388 return MIN_INT32; 389 } 390 return MAX_INT32; 391 } 392 return (int32_t)_float64_to_uint64_helper(a); 393 } 382 if (isFloat64NaN(a)) 383 return INT32_MAX; 384 385 386 if (isFloat64Infinity(a) || (a.parts.exp >= (32 + FLOAT64_BIAS))) { 387 if (a.parts.sign) 388 return INT32_MIN; 389 390 return INT32_MAX; 391 } 392 393 return (int32_t) _float64_to_uint64_helper(a); 394 } 394 395 395 396 /** Convert unsigned integer to float32 -
uspace/lib/softint/generic/multiplication.c
r402eda5 r9539be6 29 29 /** @addtogroup softint 30 30 * @{ 31 */ 31 */ 32 32 /** 33 33 * @file … … 36 36 37 37 #include <multiplication.h> 38 #include <stdint.h> 38 #include <stdint.h> 39 39 40 /** Set 1 to return MAX_INT64 or MIN_INT64on overflow */40 /** Set 1 to return INT64_MAX or INT64_MIN on overflow */ 41 41 #ifndef SOFTINT_CHECK_OF 42 # define SOFTINT_CHECK_OF042 #define SOFTINT_CHECK_OF 0 43 43 #endif 44 44 45 /** 46 * Multiply two integers and return long long as result.45 /** Multiply two integers and return long long as result. 46 * 47 47 * This function is overflow safe. 48 * @param a 49 * @param b 50 * @result 48 * 51 49 */ 52 50 static unsigned long long mul(unsigned int a, unsigned int b) { 53 unsigned int a1, a2, b1, b2; 54 unsigned long long t1, t2, t3; 55 56 a1 = a >> 16; 57 a2 = a & MAX_UINT16; 58 b1 = b >> 16; 59 b2 = b & MAX_UINT16; 60 61 t1 = a1 * b1; 62 t2 = a1*b2; 63 t2 += a2*b1; 64 t3 = a2*b2; 65 66 t3 = (((t1 << 16) + t2) << 16) + t3; 67 51 unsigned int a1 = a >> 16; 52 unsigned int a2 = a & UINT16_MAX; 53 unsigned int b1 = b >> 16; 54 unsigned int b2 = b & UINT16_MAX; 55 56 unsigned long long t1 = a1 * b1; 57 unsigned long long t2 = a1 * b2; 58 t2 += a2 * b1; 59 unsigned long long t3 = a2 * b2; 60 61 t3 = (((t1 << 16) + t2) << 16) + t3; 62 68 63 return t3; 69 64 } … … 74 69 long long __muldi3 (long long a, long long b) 75 70 { 76 long long result;77 unsigned long long t1,t2;78 unsigned long long a1, a2, b1, b2;79 71 char neg = 0; 80 72 81 73 if (a < 0) { 82 74 neg = !neg; 83 75 a = -a; 84 76 } 85 77 86 78 if (b < 0) { 87 79 neg = !neg; 88 80 b = -b; 89 81 } 90 91 a1 = a >> 32;92 b1 = b >> 32;93 94 a2 = a & (MAX_UINT32);95 b2 = b & (MAX_UINT32);96 82 83 unsigned long long a1 = a >> 32; 84 unsigned long long b1 = b >> 32; 85 86 unsigned long long a2 = a & (UINT32_MAX); 87 unsigned long long b2 = b & (UINT32_MAX); 88 97 89 if (SOFTINT_CHECK_OF && (a1 != 0) && (b1 != 0)) { 98 / / error, overflow99 return (neg ?MIN_INT64:MAX_INT64);90 /* Error (overflow) */ 91 return (neg ? INT64_MIN : INT64_MAX); 100 92 } 101 102 // (if OF checked) a1 or b1 is zero => result fits in 64 bits, no need to another overflow check 103 t1 = mul(a1,b2) + mul(b1,a2); 104 105 if (SOFTINT_CHECK_OF && t1 > MAX_UINT32) { 106 // error, overflow 107 return (neg?MIN_INT64:MAX_INT64); 93 94 /* (if OF checked) a1 or b1 is zero => result fits in 64 bits, 95 * no need to another overflow check 96 */ 97 unsigned long long t1 = mul(a1, b2) + mul(b1, a2); 98 99 if ((SOFTINT_CHECK_OF) && (t1 > UINT32_MAX)) { 100 /* Error (overflow) */ 101 return (neg ? INT64_MIN : INT64_MAX); 108 102 } 109 103 110 104 t1 = t1 << 32; 111 t2 = mul(a2,b2);105 unsigned long long t2 = mul(a2, b2); 112 106 t2 += t1; 113 107 114 108 /* t2 & (1ull << 63) - if this bit is set in unsigned long long, 115 109 * result does not fit in signed one */ 116 110 if (SOFTINT_CHECK_OF && ((t2 < t1) || (t2 & (1ull << 63)))) { 117 111 // error, overflow 118 return (neg ?MIN_INT64:MAX_INT64);112 return (neg ? INT64_MIN : INT64_MAX); 119 113 } 120 121 result = t2; 122 123 if (neg) { 114 115 long long result = t2; 116 if (neg) 124 117 result = -result; 125 } 126 118 127 119 return result; 128 } 120 } 129 121 130 122 /** @} -
uspace/srv/fs/tmpfs/tmpfs_ops.c
r402eda5 r9539be6 41 41 #include <ipc/ipc.h> 42 42 #include <macros.h> 43 #include < limits.h>43 #include <stdint.h> 44 44 #include <async.h> 45 45 #include <errno.h> -
uspace/srv/net/tl/icmp/icmp.c
r402eda5 r9539be6 98 98 /** Free identifier numbers pool end. 99 99 */ 100 #define ICMP_FREE_IDS_END MAX_UINT16100 #define ICMP_FREE_IDS_END UINT16_MAX 101 101 102 102 /** Computes the ICMP datagram checksum. … … 263 263 }else{ 264 264 res = icmp_echo(echo_data->identifier, echo_data->sequence_number, size, timeout, ttl, tos, dont_fragment, addr, addrlen); 265 if(echo_data->sequence_number < MAX_UINT16){265 if(echo_data->sequence_number < UINT16_MAX){ 266 266 ++ echo_data->sequence_number; 267 267 }else{ … … 731 731 fibril_rwlock_write_unlock(&icmp_globals.lock); 732 732 free(addr); 733 if(echo_data->sequence_number < MAX_UINT16){733 if(echo_data->sequence_number < UINT16_MAX){ 734 734 ++ echo_data->sequence_number; 735 735 }else{ -
uspace/srv/vfs/vfs_ops.c
r402eda5 r9539be6 39 39 #include <ipc/ipc.h> 40 40 #include <macros.h> 41 #include < limits.h>41 #include <stdint.h> 42 42 #include <async.h> 43 43 #include <errno.h>
Note:
See TracChangeset
for help on using the changeset viewer.