Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(561)

Side by Side Diff: src/v8.cc

Issue 1599019: Change Math.random() to return 32 bits of random goodness, instead of 30 rand... (Closed) Base URL: http://v8.googlecode.com/svn/branches/bleeding_edge/
Patch Set: '' Created 10 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/v8.h ('k') | src/x64/codegen-x64.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 190 matching lines...) Expand 10 before | Expand all | Expand 10 after
201 201
202 bool V8::IdleNotification() { 202 bool V8::IdleNotification() {
203 // Returning true tells the caller that there is no need to call 203 // Returning true tells the caller that there is no need to call
204 // IdleNotification again. 204 // IdleNotification again.
205 if (!FLAG_use_idle_notification) return true; 205 if (!FLAG_use_idle_notification) return true;
206 206
207 // Tell the heap that it may want to adjust. 207 // Tell the heap that it may want to adjust.
208 return Heap::IdleNotification(); 208 return Heap::IdleNotification();
209 } 209 }
210 210
211 static const uint32_t kRandomPositiveSmiMax = 0x3fffffff;
212 211
213 Smi* V8::RandomPositiveSmi() { 212 // Use a union type to avoid type-aliasing optimizations in GCC.
214 uint32_t random = Random(); 213 typedef union {
215 ASSERT(static_cast<uint32_t>(Smi::kMaxValue) >= kRandomPositiveSmiMax); 214 double double_value;
216 // kRandomPositiveSmiMax must match the value being divided 215 uint64_t uint64_t_value;
217 // by in math.js. 216 } double_int_union;
218 return Smi::FromInt(random & kRandomPositiveSmiMax); 217
218
219 Object* V8::FillHeapNumberWithRandom(Object* heap_number) {
220 uint64_t random_bits = Random();
221 // Make a double* from address (heap_number + sizeof(double)).
222 double_int_union* r = reinterpret_cast<double_int_union*>(
223 reinterpret_cast<char*>(heap_number) +
224 HeapNumber::kValueOffset - kHeapObjectTag);
225 // Create a random number between 0.0 and 1.0 by putting random bits into
226 // the mantissa of 1.0 and subtracting 1.0.
227 r->double_value = 1.0;
228 r->uint64_t_value |= (random_bits << 20);
229 r->double_value -= 1.0; // Force into the range [0.0, 1.0).
230
231 return heap_number;
219 } 232 }
220 233
221 } } // namespace v8::internal 234 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/v8.h ('k') | src/x64/codegen-x64.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698