OLD | NEW |
1 // Copyright 2012 the V8 project authors. All rights reserved. | 1 // Copyright 2012 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 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
62 | 62 |
63 #endif // __GNUC__ | 63 #endif // __GNUC__ |
64 | 64 |
65 | 65 |
66 // Windows specific stuff. | 66 // Windows specific stuff. |
67 #ifdef WIN32 | 67 #ifdef WIN32 |
68 | 68 |
69 // Microsoft Visual C++ specific stuff. | 69 // Microsoft Visual C++ specific stuff. |
70 #ifdef _MSC_VER | 70 #ifdef _MSC_VER |
71 | 71 |
| 72 #include "win32-headers.h" |
72 #include "win32-math.h" | 73 #include "win32-math.h" |
73 | 74 |
74 int strncasecmp(const char* s1, const char* s2, int n); | 75 int strncasecmp(const char* s1, const char* s2, int n); |
75 | 76 |
76 inline int lrint(double flt) { | 77 inline int lrint(double flt) { |
77 int intgr; | 78 int intgr; |
78 #if defined(V8_TARGET_ARCH_IA32) | 79 #if defined(V8_TARGET_ARCH_IA32) |
79 __asm { | 80 __asm { |
80 fld flt | 81 fld flt |
81 fistp intgr | 82 fistp intgr |
82 }; | 83 }; |
83 #else | 84 #else |
84 intgr = static_cast<int>(flt + 0.5); | 85 intgr = static_cast<int>(flt + 0.5); |
85 if ((intgr & 1) != 0 && intgr - flt == 0.5) { | 86 if ((intgr & 1) != 0 && intgr - flt == 0.5) { |
86 // If the number is halfway between two integers, round to the even one. | 87 // If the number is halfway between two integers, round to the even one. |
87 intgr--; | 88 intgr--; |
88 } | 89 } |
89 #endif | 90 #endif |
90 return intgr; | 91 return intgr; |
91 } | 92 } |
92 | 93 |
93 | |
94 #endif // _MSC_VER | 94 #endif // _MSC_VER |
95 | 95 |
96 #ifndef __CYGWIN__ | 96 #ifndef __CYGWIN__ |
97 // Random is missing on both Visual Studio and MinGW. | 97 // Random is missing on both Visual Studio and MinGW. |
98 int random(); | 98 int random(); |
99 #endif | 99 #endif |
100 | 100 |
101 #endif // WIN32 | 101 #endif // WIN32 |
102 | 102 |
103 #include "lazy-instance.h" | 103 #include "lazy-instance.h" |
104 #include "platform-tls.h" | |
105 #include "utils.h" | 104 #include "utils.h" |
106 #include "v8globals.h" | 105 #include "v8globals.h" |
107 | 106 |
108 namespace v8 { | 107 namespace v8 { |
109 namespace internal { | 108 namespace internal { |
110 | 109 |
111 class Semaphore; | 110 class Semaphore; |
112 class Mutex; | 111 class Mutex; |
113 | 112 |
114 double ceiling(double x); | 113 double ceiling(double x); |
115 double modulo(double x, double y); | 114 double modulo(double x, double y); |
116 | 115 |
117 // Custom implementation of math functions. | 116 // Custom implementation of math functions. |
118 double fast_sin(double input); | 117 double fast_sin(double input); |
119 double fast_cos(double input); | 118 double fast_cos(double input); |
120 double fast_tan(double input); | 119 double fast_tan(double input); |
121 double fast_log(double input); | 120 double fast_log(double input); |
122 double fast_exp(double input); | 121 double fast_exp(double input); |
123 double fast_sqrt(double input); | 122 double fast_sqrt(double input); |
124 // The custom exp implementation needs 16KB of lookup data; initialize it | 123 // The custom exp implementation needs 16KB of lookup data; initialize it |
125 // on demand. | 124 // on demand. |
126 void lazily_initialize_fast_exp(); | 125 void lazily_initialize_fast_exp(); |
127 | 126 |
128 // Forward declarations. | 127 // Forward declarations. |
129 class Socket; | 128 class Socket; |
130 | 129 |
131 // ---------------------------------------------------------------------------- | 130 // ---------------------------------------------------------------------------- |
| 131 // Fast TLS support |
| 132 |
| 133 #ifndef V8_NO_FAST_TLS |
| 134 |
| 135 #if defined(_MSC_VER) && V8_HOST_ARCH_IA32 |
| 136 |
| 137 #define V8_FAST_TLS_SUPPORTED 1 |
| 138 |
| 139 INLINE(intptr_t InternalGetExistingThreadLocal(intptr_t index)); |
| 140 |
| 141 inline intptr_t InternalGetExistingThreadLocal(intptr_t index) { |
| 142 const intptr_t kTibInlineTlsOffset = 0xE10; |
| 143 const intptr_t kTibExtraTlsOffset = 0xF94; |
| 144 const intptr_t kMaxInlineSlots = 64; |
| 145 const intptr_t kMaxSlots = kMaxInlineSlots + 1024; |
| 146 ASSERT(0 <= index && index < kMaxSlots); |
| 147 if (index < kMaxInlineSlots) { |
| 148 return static_cast<intptr_t>(__readfsdword(kTibInlineTlsOffset + |
| 149 kPointerSize * index)); |
| 150 } |
| 151 intptr_t extra = static_cast<intptr_t>(__readfsdword(kTibExtraTlsOffset)); |
| 152 ASSERT(extra != 0); |
| 153 return *reinterpret_cast<intptr_t*>(extra + |
| 154 kPointerSize * (index - kMaxInlineSlots)); |
| 155 } |
| 156 |
| 157 #elif defined(__APPLE__) && (V8_HOST_ARCH_IA32 || V8_HOST_ARCH_X64) |
| 158 |
| 159 #define V8_FAST_TLS_SUPPORTED 1 |
| 160 |
| 161 extern intptr_t kMacTlsBaseOffset; |
| 162 |
| 163 INLINE(intptr_t InternalGetExistingThreadLocal(intptr_t index)); |
| 164 |
| 165 inline intptr_t InternalGetExistingThreadLocal(intptr_t index) { |
| 166 intptr_t result; |
| 167 #if V8_HOST_ARCH_IA32 |
| 168 asm("movl %%gs:(%1,%2,4), %0;" |
| 169 :"=r"(result) // Output must be a writable register. |
| 170 :"r"(kMacTlsBaseOffset), "r"(index)); |
| 171 #else |
| 172 asm("movq %%gs:(%1,%2,8), %0;" |
| 173 :"=r"(result) |
| 174 :"r"(kMacTlsBaseOffset), "r"(index)); |
| 175 #endif |
| 176 return result; |
| 177 } |
| 178 |
| 179 #endif |
| 180 |
| 181 #endif // V8_NO_FAST_TLS |
| 182 |
| 183 |
| 184 // ---------------------------------------------------------------------------- |
132 // OS | 185 // OS |
133 // | 186 // |
134 // This class has static methods for the different platform specific | 187 // This class has static methods for the different platform specific |
135 // functions. Add methods here to cope with differences between the | 188 // functions. Add methods here to cope with differences between the |
136 // supported platforms. | 189 // supported platforms. |
137 | 190 |
138 class OS { | 191 class OS { |
139 public: | 192 public: |
140 // Initializes the platform OS support. Called once at VM startup. | 193 // Initializes the platform OS support. Called once at VM startup. |
141 static void SetUp(); | 194 static void SetUp(); |
(...skipping 622 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
764 static uint16_t HToN(uint16_t value); | 817 static uint16_t HToN(uint16_t value); |
765 static uint16_t NToH(uint16_t value); | 818 static uint16_t NToH(uint16_t value); |
766 static uint32_t HToN(uint32_t value); | 819 static uint32_t HToN(uint32_t value); |
767 static uint32_t NToH(uint32_t value); | 820 static uint32_t NToH(uint32_t value); |
768 }; | 821 }; |
769 | 822 |
770 | 823 |
771 } } // namespace v8::internal | 824 } } // namespace v8::internal |
772 | 825 |
773 #endif // V8_PLATFORM_H_ | 826 #endif // V8_PLATFORM_H_ |
OLD | NEW |