OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 the V8 project authors. All rights reserved. |
2 // Redistribution and use in source and binary forms, with or without | 2 // Redistribution and use in source and binary forms, with or without |
3 // modification, are permitted provided that the following conditions are | 3 // modification, are permitted provided that the following conditions are |
4 // met: | 4 // met: |
5 // | 5 // |
6 // * Redistributions of source code must retain the above copyright | 6 // * Redistributions of source code must retain the above copyright |
7 // notice, this list of conditions and the following disclaimer. | 7 // notice, this list of conditions and the following disclaimer. |
8 // * Redistributions in binary form must reproduce the above | 8 // * Redistributions in binary form must reproduce the above |
9 // copyright notice, this list of conditions and the following | 9 // copyright notice, this list of conditions and the following |
10 // disclaimer in the documentation and/or other materials provided | 10 // disclaimer in the documentation and/or other materials provided |
(...skipping 16 matching lines...) Expand all Loading... |
27 | 27 |
28 #ifndef DOUBLE_CONVERSION_UTILS_H_ | 28 #ifndef DOUBLE_CONVERSION_UTILS_H_ |
29 #define DOUBLE_CONVERSION_UTILS_H_ | 29 #define DOUBLE_CONVERSION_UTILS_H_ |
30 | 30 |
31 #include <stdlib.h> | 31 #include <stdlib.h> |
32 #include <string.h> | 32 #include <string.h> |
33 | 33 |
34 #include <assert.h> | 34 #include <assert.h> |
35 #ifndef ASSERT | 35 #ifndef ASSERT |
36 #define ASSERT(condition) \ | 36 #define ASSERT(condition) \ |
37 do { \ | 37 assert(condition); |
38 assert(condition); \ | |
39 } while (false && (condition)) | |
40 #endif | 38 #endif |
41 #ifndef UNIMPLEMENTED | 39 #ifndef UNIMPLEMENTED |
42 #define UNIMPLEMENTED() (abort()) | 40 #define UNIMPLEMENTED() (abort()) |
43 #endif | 41 #endif |
44 #ifndef UNREACHABLE | 42 #ifndef UNREACHABLE |
45 #define UNREACHABLE() (abort()) | 43 #define UNREACHABLE() (abort()) |
46 #endif | 44 #endif |
47 | 45 |
48 // Double operations detection based on target architecture. | 46 // Double operations detection based on target architecture. |
49 // Linux uses a 80bit wide floating point stack on x86. This induces double | 47 // Linux uses a 80bit wide floating point stack on x86. This induces double |
50 // rounding, which in turn leads to wrong results. | 48 // rounding, which in turn leads to wrong results. |
51 // An easy way to test if the floating-point operations are correct is to | 49 // An easy way to test if the floating-point operations are correct is to |
52 // evaluate: 89255.0/1e22. If the floating-point stack is 64 bits wide then | 50 // evaluate: 89255.0/1e22. If the floating-point stack is 64 bits wide then |
53 // the result is equal to 89255e-22. | 51 // the result is equal to 89255e-22. |
54 // The best way to test this, is to create a division-function and to compare | 52 // The best way to test this, is to create a division-function and to compare |
55 // the output of the division with the expected result. (Inlining must be | 53 // the output of the division with the expected result. (Inlining must be |
56 // disabled.) | 54 // disabled.) |
57 // On Linux,x86 89255e-22 != Div_double(89255.0/1e22) | 55 // On Linux,x86 89255e-22 != Div_double(89255.0/1e22) |
58 #if defined(_M_X64) || defined(__x86_64__) || \ | 56 #if defined(_M_X64) || defined(__x86_64__) || \ |
59 defined(__ARMEL__) || \ | 57 defined(__ARMEL__) || defined(__avr32__) || \ |
60 defined(_MIPS_ARCH_MIPS32) | 58 defined(__hppa__) || defined(__ia64__) || \ |
| 59 defined(__mips__) || \ |
| 60 defined(__powerpc__) || defined(__ppc__) || defined(__ppc64__) || \ |
| 61 defined(__sparc__) || defined(__sparc) || defined(__s390__) || \ |
| 62 defined(__SH4__) || defined(__alpha__) || \ |
| 63 defined(_MIPS_ARCH_MIPS32R2) || \ |
| 64 defined(__AARCH64EL__) |
61 #define DOUBLE_CONVERSION_CORRECT_DOUBLE_OPERATIONS 1 | 65 #define DOUBLE_CONVERSION_CORRECT_DOUBLE_OPERATIONS 1 |
62 #elif defined(_M_IX86) || defined(__i386__) | 66 #elif defined(_M_IX86) || defined(__i386__) || defined(__i386) |
63 #if defined(_WIN32) | 67 #if defined(_WIN32) |
64 // Windows uses a 64bit wide floating point stack. | 68 // Windows uses a 64bit wide floating point stack. |
65 #define DOUBLE_CONVERSION_CORRECT_DOUBLE_OPERATIONS 1 | 69 #define DOUBLE_CONVERSION_CORRECT_DOUBLE_OPERATIONS 1 |
66 #else | 70 #else |
67 #undef DOUBLE_CONVERSION_CORRECT_DOUBLE_OPERATIONS | 71 #undef DOUBLE_CONVERSION_CORRECT_DOUBLE_OPERATIONS |
68 #endif // _WIN32 | 72 #endif // _WIN32 |
69 #else | 73 #else |
70 #error Target architecture was not detected as supported by Double-Conversion. | 74 #error Target architecture was not detected as supported by Double-Conversion. |
71 #endif | 75 #endif |
72 | 76 |
| 77 #if defined(__GNUC__) |
| 78 #define DOUBLE_CONVERSION_UNUSED __attribute__((unused)) |
| 79 #else |
| 80 #define DOUBLE_CONVERSION_UNUSED |
| 81 #endif |
73 | 82 |
74 #if defined(_WIN32) && !defined(__MINGW32__) | 83 #if defined(_WIN32) && !defined(__MINGW32__) |
75 | 84 |
76 typedef signed char int8_t; | 85 typedef signed char int8_t; |
77 typedef unsigned char uint8_t; | 86 typedef unsigned char uint8_t; |
78 typedef short int16_t; // NOLINT | 87 typedef short int16_t; // NOLINT |
79 typedef unsigned short uint16_t; // NOLINT | 88 typedef unsigned short uint16_t; // NOLINT |
80 typedef int int32_t; | 89 typedef int int32_t; |
81 typedef unsigned int uint32_t; | 90 typedef unsigned int uint32_t; |
82 typedef __int64 int64_t; | 91 typedef __int64 int64_t; |
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
288 // There is an additional use for BitCast. | 297 // There is an additional use for BitCast. |
289 // Recent gccs will warn when they see casts that may result in breakage due to | 298 // Recent gccs will warn when they see casts that may result in breakage due to |
290 // the type-based aliasing rule. If you have checked that there is no breakage | 299 // the type-based aliasing rule. If you have checked that there is no breakage |
291 // you can use BitCast to cast one pointer type to another. This confuses gcc | 300 // you can use BitCast to cast one pointer type to another. This confuses gcc |
292 // enough that it can no longer see that you have cast one pointer type to | 301 // enough that it can no longer see that you have cast one pointer type to |
293 // another thus avoiding the warning. | 302 // another thus avoiding the warning. |
294 template <class Dest, class Source> | 303 template <class Dest, class Source> |
295 inline Dest BitCast(const Source& source) { | 304 inline Dest BitCast(const Source& source) { |
296 // Compile time assertion: sizeof(Dest) == sizeof(Source) | 305 // Compile time assertion: sizeof(Dest) == sizeof(Source) |
297 // A compile error here means your Dest and Source have different sizes. | 306 // A compile error here means your Dest and Source have different sizes. |
298 typedef char VerifySizesAreEqual[sizeof(Dest) == sizeof(Source) ? 1 : -1]; | 307 DOUBLE_CONVERSION_UNUSED |
| 308 typedef char VerifySizesAreEqual[sizeof(Dest) == sizeof(Source) ? 1 : -1]; |
299 | 309 |
300 Dest dest; | 310 Dest dest; |
301 memmove(&dest, &source, sizeof(dest)); | 311 memmove(&dest, &source, sizeof(dest)); |
302 return dest; | 312 return dest; |
303 } | 313 } |
304 | 314 |
305 template <class Dest, class Source> | 315 template <class Dest, class Source> |
306 inline Dest BitCast(Source* source) { | 316 inline Dest BitCast(Source* source) { |
307 return BitCast<Dest>(reinterpret_cast<uintptr_t>(source)); | 317 return BitCast<Dest>(reinterpret_cast<uintptr_t>(source)); |
308 } | 318 } |
309 | 319 |
310 } // namespace double_conversion | 320 } // namespace double_conversion |
311 | 321 |
312 #endif // DOUBLE_CONVERSION_UTILS_H_ | 322 #endif // DOUBLE_CONVERSION_UTILS_H_ |
OLD | NEW |