| 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 4134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 4145 MathPowStub stub(MathPowStub::INTEGER); | 4145 MathPowStub stub(MathPowStub::INTEGER); |
| 4146 __ CallStub(&stub); | 4146 __ CallStub(&stub); |
| 4147 } else { | 4147 } else { |
| 4148 ASSERT(exponent_type.IsDouble()); | 4148 ASSERT(exponent_type.IsDouble()); |
| 4149 MathPowStub stub(MathPowStub::DOUBLE); | 4149 MathPowStub stub(MathPowStub::DOUBLE); |
| 4150 __ CallStub(&stub); | 4150 __ CallStub(&stub); |
| 4151 } | 4151 } |
| 4152 } | 4152 } |
| 4153 | 4153 |
| 4154 | 4154 |
| 4155 void LCodeGen::DoRandom(LRandom* instr) { | |
| 4156 CpuFeatureScope scope(masm(), SSE2); | |
| 4157 | |
| 4158 // Assert that the register size is indeed the size of each seed. | |
| 4159 static const int kSeedSize = sizeof(uint32_t); | |
| 4160 STATIC_ASSERT(kPointerSize == kSeedSize); | |
| 4161 | |
| 4162 // Load native context | |
| 4163 Register global_object = ToRegister(instr->global_object()); | |
| 4164 Register native_context = global_object; | |
| 4165 __ mov(native_context, FieldOperand( | |
| 4166 global_object, GlobalObject::kNativeContextOffset)); | |
| 4167 | |
| 4168 // Load state (FixedArray of the native context's random seeds) | |
| 4169 static const int kRandomSeedOffset = | |
| 4170 FixedArray::kHeaderSize + Context::RANDOM_SEED_INDEX * kPointerSize; | |
| 4171 Register state = native_context; | |
| 4172 __ mov(state, FieldOperand(native_context, kRandomSeedOffset)); | |
| 4173 | |
| 4174 // Load state[0]. | |
| 4175 Register state0 = ToRegister(instr->scratch()); | |
| 4176 __ mov(state0, FieldOperand(state, ByteArray::kHeaderSize)); | |
| 4177 // Load state[1]. | |
| 4178 Register state1 = ToRegister(instr->scratch2()); | |
| 4179 __ mov(state1, FieldOperand(state, ByteArray::kHeaderSize + kSeedSize)); | |
| 4180 | |
| 4181 // state[0] = 18273 * (state[0] & 0xFFFF) + (state[0] >> 16) | |
| 4182 Register scratch3 = ToRegister(instr->scratch3()); | |
| 4183 __ movzx_w(scratch3, state0); | |
| 4184 __ imul(scratch3, scratch3, 18273); | |
| 4185 __ shr(state0, 16); | |
| 4186 __ add(state0, scratch3); | |
| 4187 // Save state[0]. | |
| 4188 __ mov(FieldOperand(state, ByteArray::kHeaderSize), state0); | |
| 4189 | |
| 4190 // state[1] = 36969 * (state[1] & 0xFFFF) + (state[1] >> 16) | |
| 4191 __ movzx_w(scratch3, state1); | |
| 4192 __ imul(scratch3, scratch3, 36969); | |
| 4193 __ shr(state1, 16); | |
| 4194 __ add(state1, scratch3); | |
| 4195 // Save state[1]. | |
| 4196 __ mov(FieldOperand(state, ByteArray::kHeaderSize + kSeedSize), state1); | |
| 4197 | |
| 4198 // Random bit pattern = (state[0] << 14) + (state[1] & 0x3FFFF) | |
| 4199 Register random = state0; | |
| 4200 __ shl(random, 14); | |
| 4201 __ and_(state1, Immediate(0x3FFFF)); | |
| 4202 __ add(random, state1); | |
| 4203 | |
| 4204 // Convert 32 random bits in random to 0.(32 random bits) in a double | |
| 4205 // by computing: | |
| 4206 // ( 1.(20 0s)(32 random bits) x 2^20 ) - (1.0 x 2^20)). | |
| 4207 XMMRegister result = ToDoubleRegister(instr->result()); | |
| 4208 XMMRegister scratch4 = double_scratch0(); | |
| 4209 __ mov(scratch3, Immediate(0x49800000)); // 1.0 x 2^20 as single. | |
| 4210 __ movd(scratch4, scratch3); | |
| 4211 __ movd(result, random); | |
| 4212 __ cvtss2sd(scratch4, scratch4); | |
| 4213 __ xorps(result, scratch4); | |
| 4214 __ subsd(result, scratch4); | |
| 4215 } | |
| 4216 | |
| 4217 | |
| 4218 void LCodeGen::DoMathLog(LMathLog* instr) { | 4155 void LCodeGen::DoMathLog(LMathLog* instr) { |
| 4219 CpuFeatureScope scope(masm(), SSE2); | 4156 CpuFeatureScope scope(masm(), SSE2); |
| 4220 ASSERT(instr->value()->Equals(instr->result())); | 4157 ASSERT(instr->value()->Equals(instr->result())); |
| 4221 XMMRegister input_reg = ToDoubleRegister(instr->value()); | 4158 XMMRegister input_reg = ToDoubleRegister(instr->value()); |
| 4222 XMMRegister xmm_scratch = double_scratch0(); | 4159 XMMRegister xmm_scratch = double_scratch0(); |
| 4223 Label positive, done, zero; | 4160 Label positive, done, zero; |
| 4224 __ xorps(xmm_scratch, xmm_scratch); | 4161 __ xorps(xmm_scratch, xmm_scratch); |
| 4225 __ ucomisd(input_reg, xmm_scratch); | 4162 __ ucomisd(input_reg, xmm_scratch); |
| 4226 __ j(above, &positive, Label::kNear); | 4163 __ j(above, &positive, Label::kNear); |
| 4227 __ j(equal, &zero, Label::kNear); | 4164 __ j(equal, &zero, Label::kNear); |
| (...skipping 2208 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 6436 FixedArray::kHeaderSize - kPointerSize)); | 6373 FixedArray::kHeaderSize - kPointerSize)); |
| 6437 __ bind(&done); | 6374 __ bind(&done); |
| 6438 } | 6375 } |
| 6439 | 6376 |
| 6440 | 6377 |
| 6441 #undef __ | 6378 #undef __ |
| 6442 | 6379 |
| 6443 } } // namespace v8::internal | 6380 } } // namespace v8::internal |
| 6444 | 6381 |
| 6445 #endif // V8_TARGET_ARCH_IA32 | 6382 #endif // V8_TARGET_ARCH_IA32 |
| OLD | NEW |