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

Side by Side Diff: src/v8.cc

Issue 1631008: Optimize the assembly code generated for Math.random() (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/serialize.cc ('k') | src/x64/assembler-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 192 matching lines...) Expand 10 before | Expand all | Expand 10 after
203 uint64_t uint64_t_value; 203 uint64_t uint64_t_value;
204 } double_int_union; 204 } double_int_union;
205 205
206 206
207 Object* V8::FillHeapNumberWithRandom(Object* heap_number) { 207 Object* V8::FillHeapNumberWithRandom(Object* heap_number) {
208 uint64_t random_bits = Random(); 208 uint64_t random_bits = Random();
209 // Make a double* from address (heap_number + sizeof(double)). 209 // Make a double* from address (heap_number + sizeof(double)).
210 double_int_union* r = reinterpret_cast<double_int_union*>( 210 double_int_union* r = reinterpret_cast<double_int_union*>(
211 reinterpret_cast<char*>(heap_number) + 211 reinterpret_cast<char*>(heap_number) +
212 HeapNumber::kValueOffset - kHeapObjectTag); 212 HeapNumber::kValueOffset - kHeapObjectTag);
213 // Create a random number between 0.0 and 1.0 by putting random bits into 213 // Convert 32 random bits to 0.(32 random bits) in a double
214 // the mantissa of 1.0 and subtracting 1.0. 214 // by computing:
215 r->double_value = 1.0; 215 // ( 1.(20 0s)(32 random bits) x 2^20 ) - (1.0 x 2^20)).
216 r->uint64_t_value |= (random_bits << 20); 216 const double binary_million = 1048576.0;
217 r->double_value -= 1.0; // Force into the range [0.0, 1.0). 217 r->double_value = binary_million;
218 r->uint64_t_value |= random_bits;
219 r->double_value -= binary_million;
218 220
219 return heap_number; 221 return heap_number;
220 } 222 }
221 223
222 } } // namespace v8::internal 224 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/serialize.cc ('k') | src/x64/assembler-x64.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698