OLD | NEW |
1 // Copyright 2006-2009 the V8 project authors. All rights reserved. | 1 // Copyright 2006-2009 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 153 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
164 } | 164 } |
165 | 165 |
166 | 166 |
167 // Use a union type to avoid type-aliasing optimizations in GCC. | 167 // Use a union type to avoid type-aliasing optimizations in GCC. |
168 typedef union { | 168 typedef union { |
169 double double_value; | 169 double double_value; |
170 uint64_t uint64_t_value; | 170 uint64_t uint64_t_value; |
171 } double_int_union; | 171 } double_int_union; |
172 | 172 |
173 | 173 |
174 Object* V8::FillHeapNumberWithRandom(Object* heap_number) { | 174 Object* V8::FillHeapNumberWithRandom(Object* heap_number, Isolate* isolate) { |
175 uint64_t random_bits = Random(Isolate::Current()); | 175 uint64_t random_bits = Random(isolate); |
176 // Make a double* from address (heap_number + sizeof(double)). | 176 // Make a double* from address (heap_number + sizeof(double)). |
177 double_int_union* r = reinterpret_cast<double_int_union*>( | 177 double_int_union* r = reinterpret_cast<double_int_union*>( |
178 reinterpret_cast<char*>(heap_number) + | 178 reinterpret_cast<char*>(heap_number) + |
179 HeapNumber::kValueOffset - kHeapObjectTag); | 179 HeapNumber::kValueOffset - kHeapObjectTag); |
180 // Convert 32 random bits to 0.(32 random bits) in a double | 180 // Convert 32 random bits to 0.(32 random bits) in a double |
181 // by computing: | 181 // by computing: |
182 // ( 1.(20 0s)(32 random bits) x 2^20 ) - (1.0 x 2^20)). | 182 // ( 1.(20 0s)(32 random bits) x 2^20 ) - (1.0 x 2^20)). |
183 const double binary_million = 1048576.0; | 183 const double binary_million = 1048576.0; |
184 r->double_value = binary_million; | 184 r->double_value = binary_million; |
185 r->uint64_t_value |= random_bits; | 185 r->uint64_t_value |= random_bits; |
186 r->double_value -= binary_million; | 186 r->double_value -= binary_million; |
187 | 187 |
188 return heap_number; | 188 return heap_number; |
189 } | 189 } |
190 | 190 |
191 } } // namespace v8::internal | 191 } } // namespace v8::internal |
OLD | NEW |