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 4182 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4193 MathPowStub stub(MathPowStub::INTEGER); | 4193 MathPowStub stub(MathPowStub::INTEGER); |
4194 __ CallStub(&stub); | 4194 __ CallStub(&stub); |
4195 } else { | 4195 } else { |
4196 ASSERT(exponent_type.IsDouble()); | 4196 ASSERT(exponent_type.IsDouble()); |
4197 MathPowStub stub(MathPowStub::DOUBLE); | 4197 MathPowStub stub(MathPowStub::DOUBLE); |
4198 __ CallStub(&stub); | 4198 __ CallStub(&stub); |
4199 } | 4199 } |
4200 } | 4200 } |
4201 | 4201 |
4202 | 4202 |
4203 void LCodeGen::DoRandom(LRandom* instr) { | |
4204 CpuFeatureScope scope(masm(), SSE2); | |
4205 | |
4206 // Assert that the register size is indeed the size of each seed. | |
4207 static const int kSeedSize = sizeof(uint32_t); | |
4208 STATIC_ASSERT(kPointerSize == kSeedSize); | |
4209 | |
4210 // Load native context | |
4211 Register global_object = ToRegister(instr->global_object()); | |
4212 Register native_context = global_object; | |
4213 __ mov(native_context, FieldOperand( | |
4214 global_object, GlobalObject::kNativeContextOffset)); | |
4215 | |
4216 // Load state (FixedArray of the native context's random seeds) | |
4217 static const int kRandomSeedOffset = | |
4218 FixedArray::kHeaderSize + Context::RANDOM_SEED_INDEX * kPointerSize; | |
4219 Register state = native_context; | |
4220 __ mov(state, FieldOperand(native_context, kRandomSeedOffset)); | |
4221 | |
4222 // Load state[0]. | |
4223 Register state0 = ToRegister(instr->scratch()); | |
4224 __ mov(state0, FieldOperand(state, ByteArray::kHeaderSize)); | |
4225 // Load state[1]. | |
4226 Register state1 = ToRegister(instr->scratch2()); | |
4227 __ mov(state1, FieldOperand(state, ByteArray::kHeaderSize + kSeedSize)); | |
4228 | |
4229 // state[0] = 18273 * (state[0] & 0xFFFF) + (state[0] >> 16) | |
4230 Register scratch3 = ToRegister(instr->scratch3()); | |
4231 __ movzx_w(scratch3, state0); | |
4232 __ imul(scratch3, scratch3, 18273); | |
4233 __ shr(state0, 16); | |
4234 __ add(state0, scratch3); | |
4235 // Save state[0]. | |
4236 __ mov(FieldOperand(state, ByteArray::kHeaderSize), state0); | |
4237 | |
4238 // state[1] = 36969 * (state[1] & 0xFFFF) + (state[1] >> 16) | |
4239 __ movzx_w(scratch3, state1); | |
4240 __ imul(scratch3, scratch3, 36969); | |
4241 __ shr(state1, 16); | |
4242 __ add(state1, scratch3); | |
4243 // Save state[1]. | |
4244 __ mov(FieldOperand(state, ByteArray::kHeaderSize + kSeedSize), state1); | |
4245 | |
4246 // Random bit pattern = (state[0] << 14) + (state[1] & 0x3FFFF) | |
4247 Register random = state0; | |
4248 __ shl(random, 14); | |
4249 __ and_(state1, Immediate(0x3FFFF)); | |
4250 __ add(random, state1); | |
4251 | |
4252 // Convert 32 random bits in random to 0.(32 random bits) in a double | |
4253 // by computing: | |
4254 // ( 1.(20 0s)(32 random bits) x 2^20 ) - (1.0 x 2^20)). | |
4255 XMMRegister result = ToDoubleRegister(instr->result()); | |
4256 XMMRegister scratch4 = double_scratch0(); | |
4257 __ mov(scratch3, Immediate(0x49800000)); // 1.0 x 2^20 as single. | |
4258 __ movd(scratch4, scratch3); | |
4259 __ movd(result, random); | |
4260 __ cvtss2sd(scratch4, scratch4); | |
4261 __ xorps(result, scratch4); | |
4262 __ subsd(result, scratch4); | |
4263 } | |
4264 | |
4265 | |
4266 void LCodeGen::DoMathLog(LMathLog* instr) { | 4203 void LCodeGen::DoMathLog(LMathLog* instr) { |
4267 CpuFeatureScope scope(masm(), SSE2); | 4204 CpuFeatureScope scope(masm(), SSE2); |
4268 ASSERT(instr->value()->Equals(instr->result())); | 4205 ASSERT(instr->value()->Equals(instr->result())); |
4269 XMMRegister input_reg = ToDoubleRegister(instr->value()); | 4206 XMMRegister input_reg = ToDoubleRegister(instr->value()); |
4270 XMMRegister xmm_scratch = double_scratch0(); | 4207 XMMRegister xmm_scratch = double_scratch0(); |
4271 Label positive, done, zero; | 4208 Label positive, done, zero; |
4272 __ xorps(xmm_scratch, xmm_scratch); | 4209 __ xorps(xmm_scratch, xmm_scratch); |
4273 __ ucomisd(input_reg, xmm_scratch); | 4210 __ ucomisd(input_reg, xmm_scratch); |
4274 __ j(above, &positive, Label::kNear); | 4211 __ j(above, &positive, Label::kNear); |
4275 __ j(equal, &zero, Label::kNear); | 4212 __ j(equal, &zero, Label::kNear); |
(...skipping 2228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6504 FixedArray::kHeaderSize - kPointerSize)); | 6441 FixedArray::kHeaderSize - kPointerSize)); |
6505 __ bind(&done); | 6442 __ bind(&done); |
6506 } | 6443 } |
6507 | 6444 |
6508 | 6445 |
6509 #undef __ | 6446 #undef __ |
6510 | 6447 |
6511 } } // namespace v8::internal | 6448 } } // namespace v8::internal |
6512 | 6449 |
6513 #endif // V8_TARGET_ARCH_IA32 | 6450 #endif // V8_TARGET_ARCH_IA32 |
OLD | NEW |