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

Side by Side Diff: src/ia32/lithium-codegen-ia32.cc

Issue 82763005: Reland "Implement Math.random() purely in JavaScript" plus fixes. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Added assertion Created 7 years, 1 month 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/ia32/full-codegen-ia32.cc ('k') | src/ia32/lithium-ia32.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 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 4167 matching lines...) Expand 10 before | Expand all | Expand 10 after
4178 MathPowStub stub(MathPowStub::INTEGER); 4178 MathPowStub stub(MathPowStub::INTEGER);
4179 __ CallStub(&stub); 4179 __ CallStub(&stub);
4180 } else { 4180 } else {
4181 ASSERT(exponent_type.IsDouble()); 4181 ASSERT(exponent_type.IsDouble());
4182 MathPowStub stub(MathPowStub::DOUBLE); 4182 MathPowStub stub(MathPowStub::DOUBLE);
4183 __ CallStub(&stub); 4183 __ CallStub(&stub);
4184 } 4184 }
4185 } 4185 }
4186 4186
4187 4187
4188 void LCodeGen::DoRandom(LRandom* instr) {
4189 CpuFeatureScope scope(masm(), SSE2);
4190
4191 // Assert that the register size is indeed the size of each seed.
4192 static const int kSeedSize = sizeof(uint32_t);
4193 STATIC_ASSERT(kPointerSize == kSeedSize);
4194
4195 // Load native context
4196 Register global_object = ToRegister(instr->global_object());
4197 Register native_context = global_object;
4198 __ mov(native_context, FieldOperand(
4199 global_object, GlobalObject::kNativeContextOffset));
4200
4201 // Load state (FixedArray of the native context's random seeds)
4202 static const int kRandomSeedOffset =
4203 FixedArray::kHeaderSize + Context::RANDOM_SEED_INDEX * kPointerSize;
4204 Register state = native_context;
4205 __ mov(state, FieldOperand(native_context, kRandomSeedOffset));
4206
4207 // Load state[0].
4208 Register state0 = ToRegister(instr->scratch());
4209 __ mov(state0, FieldOperand(state, ByteArray::kHeaderSize));
4210 // Load state[1].
4211 Register state1 = ToRegister(instr->scratch2());
4212 __ mov(state1, FieldOperand(state, ByteArray::kHeaderSize + kSeedSize));
4213
4214 // state[0] = 18273 * (state[0] & 0xFFFF) + (state[0] >> 16)
4215 Register scratch3 = ToRegister(instr->scratch3());
4216 __ movzx_w(scratch3, state0);
4217 __ imul(scratch3, scratch3, 18273);
4218 __ shr(state0, 16);
4219 __ add(state0, scratch3);
4220 // Save state[0].
4221 __ mov(FieldOperand(state, ByteArray::kHeaderSize), state0);
4222
4223 // state[1] = 36969 * (state[1] & 0xFFFF) + (state[1] >> 16)
4224 __ movzx_w(scratch3, state1);
4225 __ imul(scratch3, scratch3, 36969);
4226 __ shr(state1, 16);
4227 __ add(state1, scratch3);
4228 // Save state[1].
4229 __ mov(FieldOperand(state, ByteArray::kHeaderSize + kSeedSize), state1);
4230
4231 // Random bit pattern = (state[0] << 14) + (state[1] & 0x3FFFF)
4232 Register random = state0;
4233 __ shl(random, 14);
4234 __ and_(state1, Immediate(0x3FFFF));
4235 __ add(random, state1);
4236
4237 // Convert 32 random bits in random to 0.(32 random bits) in a double
4238 // by computing:
4239 // ( 1.(20 0s)(32 random bits) x 2^20 ) - (1.0 x 2^20)).
4240 XMMRegister result = ToDoubleRegister(instr->result());
4241 XMMRegister scratch4 = double_scratch0();
4242 __ mov(scratch3, Immediate(0x49800000)); // 1.0 x 2^20 as single.
4243 __ movd(scratch4, scratch3);
4244 __ movd(result, random);
4245 __ cvtss2sd(scratch4, scratch4);
4246 __ xorps(result, scratch4);
4247 __ subsd(result, scratch4);
4248 }
4249
4250
4251 void LCodeGen::DoMathLog(LMathLog* instr) { 4188 void LCodeGen::DoMathLog(LMathLog* instr) {
4252 CpuFeatureScope scope(masm(), SSE2); 4189 CpuFeatureScope scope(masm(), SSE2);
4253 ASSERT(instr->value()->Equals(instr->result())); 4190 ASSERT(instr->value()->Equals(instr->result()));
4254 XMMRegister input_reg = ToDoubleRegister(instr->value()); 4191 XMMRegister input_reg = ToDoubleRegister(instr->value());
4255 XMMRegister xmm_scratch = double_scratch0(); 4192 XMMRegister xmm_scratch = double_scratch0();
4256 Label positive, done, zero; 4193 Label positive, done, zero;
4257 __ xorps(xmm_scratch, xmm_scratch); 4194 __ xorps(xmm_scratch, xmm_scratch);
4258 __ ucomisd(input_reg, xmm_scratch); 4195 __ ucomisd(input_reg, xmm_scratch);
4259 __ j(above, &positive, Label::kNear); 4196 __ j(above, &positive, Label::kNear);
4260 __ j(equal, &zero, Label::kNear); 4197 __ j(equal, &zero, Label::kNear);
(...skipping 2233 matching lines...) Expand 10 before | Expand all | Expand 10 after
6494 FixedArray::kHeaderSize - kPointerSize)); 6431 FixedArray::kHeaderSize - kPointerSize));
6495 __ bind(&done); 6432 __ bind(&done);
6496 } 6433 }
6497 6434
6498 6435
6499 #undef __ 6436 #undef __
6500 6437
6501 } } // namespace v8::internal 6438 } } // namespace v8::internal
6502 6439
6503 #endif // V8_TARGET_ARCH_IA32 6440 #endif // V8_TARGET_ARCH_IA32
OLDNEW
« no previous file with comments | « src/ia32/full-codegen-ia32.cc ('k') | src/ia32/lithium-ia32.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698