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

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

Issue 9615012: Port r10939 to x64 and arm (inline Math.random in crankshaft). (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Created 8 years, 9 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/arm/lithium-codegen-arm.h ('k') | src/ia32/lithium-codegen-ia32.cc » ('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 3212 matching lines...) Expand 10 before | Expand all | Expand 10 after
3223 __ CallStub(&stub); 3223 __ CallStub(&stub);
3224 } else { 3224 } else {
3225 ASSERT(exponent_type.IsDouble()); 3225 ASSERT(exponent_type.IsDouble());
3226 MathPowStub stub(MathPowStub::DOUBLE); 3226 MathPowStub stub(MathPowStub::DOUBLE);
3227 __ CallStub(&stub); 3227 __ CallStub(&stub);
3228 } 3228 }
3229 } 3229 }
3230 3230
3231 3231
3232 void LCodeGen::DoRandom(LRandom* instr) { 3232 void LCodeGen::DoRandom(LRandom* instr) {
3233 class DeferredDoRandom: public LDeferredCode {
3234 public:
3235 DeferredDoRandom(LCodeGen* codegen, LRandom* instr)
3236 : LDeferredCode(codegen), instr_(instr) { }
3237 virtual void Generate() { codegen()->DoDeferredRandom(instr_); }
3238 virtual LInstruction* instr() { return instr_; }
3239 private:
3240 LRandom* instr_;
3241 };
3242
3243 DeferredDoRandom* deferred = new DeferredDoRandom(this, instr);
3244
3233 // Having marked this instruction as a call we can use any 3245 // Having marked this instruction as a call we can use any
3234 // registers. 3246 // registers.
3235 ASSERT(ToDoubleRegister(instr->result()).is(d7)); 3247 ASSERT(ToDoubleRegister(instr->result()).is(d7));
3236 ASSERT(ToRegister(instr->InputAt(0)).is(r0)); 3248 ASSERT(ToRegister(instr->InputAt(0)).is(r0));
3237 3249
3238 __ PrepareCallCFunction(1, scratch0()); 3250 static const int kSeedSize = sizeof(uint32_t);
3251 STATIC_ASSERT(kPointerSize == kSeedSize);
3252
3239 __ ldr(r0, FieldMemOperand(r0, GlobalObject::kGlobalContextOffset)); 3253 __ ldr(r0, FieldMemOperand(r0, GlobalObject::kGlobalContextOffset));
3240 __ CallCFunction(ExternalReference::random_uint32_function(isolate()), 1); 3254 static const int kRandomSeedOffset =
3255 FixedArray::kHeaderSize + Context::RANDOM_SEED_INDEX * kPointerSize;
3256 __ ldr(r2, FieldMemOperand(r0, kRandomSeedOffset));
3257 // r2: FixedArray of the global context's random seeds
3241 3258
3259 // Load state[0].
3260 __ ldr(r1, FieldMemOperand(r2, ByteArray::kHeaderSize));
3261 __ cmp(r1, Operand(0));
3262 __ b(eq, deferred->entry());
3263 // Load state[1].
3264 __ ldr(r0, FieldMemOperand(r2, ByteArray::kHeaderSize + kSeedSize));
3265 // r1: state[0].
3266 // r0: state[1].
3267
3268 // state[0] = 18273 * (state[0] & 0xFFFF) + (state[0] >> 16)
3269 __ and_(r3, r1, Operand(0xFFFF));
3270 __ mov(r4, Operand(18273));
3271 __ mul(r3, r3, r4);
3272 __ add(r1, r3, Operand(r1, LSR, 16));
3273 // Save state[0].
3274 __ str(r1, FieldMemOperand(r2, ByteArray::kHeaderSize));
3275
3276 // state[1] = 36969 * (state[1] & 0xFFFF) + (state[1] >> 16)
3277 __ and_(r3, r0, Operand(0xFFFF));
3278 __ mov(r4, Operand(36969));
3279 __ mul(r3, r3, r4);
3280 __ add(r0, r3, Operand(r0, LSR, 16));
3281 // Save state[1].
3282 __ str(r0, FieldMemOperand(r2, ByteArray::kHeaderSize + kSeedSize));
3283
3284 // Random bit pattern = (state[0] << 14) + (state[1] & 0x3FFFF)
3285 __ and_(r0, r0, Operand(0x3FFFF));
3286 __ add(r0, r0, Operand(r1, LSL, 14));
3287
3288 __ bind(deferred->exit());
3242 // 0x41300000 is the top half of 1.0 x 2^20 as a double. 3289 // 0x41300000 is the top half of 1.0 x 2^20 as a double.
3243 // Create this constant using mov/orr to avoid PC relative load. 3290 // Create this constant using mov/orr to avoid PC relative load.
3244 __ mov(r1, Operand(0x41000000)); 3291 __ mov(r1, Operand(0x41000000));
3245 __ orr(r1, r1, Operand(0x300000)); 3292 __ orr(r1, r1, Operand(0x300000));
3246 // Move 0x41300000xxxxxxxx (x = random bits) to VFP. 3293 // Move 0x41300000xxxxxxxx (x = random bits) to VFP.
3247 __ vmov(d7, r0, r1); 3294 __ vmov(d7, r0, r1);
3248 // Move 0x4130000000000000 to VFP. 3295 // Move 0x4130000000000000 to VFP.
3249 __ mov(r0, Operand(0, RelocInfo::NONE)); 3296 __ mov(r0, Operand(0, RelocInfo::NONE));
3250 __ vmov(d8, r0, r1); 3297 __ vmov(d8, r0, r1);
3251 // Subtract and store the result in the heap number. 3298 // Subtract and store the result in the heap number.
3252 __ vsub(d7, d7, d8); 3299 __ vsub(d7, d7, d8);
3253 } 3300 }
3254 3301
3255 3302
3303 void LCodeGen::DoDeferredRandom(LRandom* instr) {
3304 __ PrepareCallCFunction(1, scratch0());
3305 __ CallCFunction(ExternalReference::random_uint32_function(isolate()), 1);
3306 // Return value is in r0.
3307 }
3308
3309
3256 void LCodeGen::DoMathLog(LUnaryMathOperation* instr) { 3310 void LCodeGen::DoMathLog(LUnaryMathOperation* instr) {
3257 ASSERT(ToDoubleRegister(instr->result()).is(d2)); 3311 ASSERT(ToDoubleRegister(instr->result()).is(d2));
3258 TranscendentalCacheStub stub(TranscendentalCache::LOG, 3312 TranscendentalCacheStub stub(TranscendentalCache::LOG,
3259 TranscendentalCacheStub::UNTAGGED); 3313 TranscendentalCacheStub::UNTAGGED);
3260 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); 3314 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr);
3261 } 3315 }
3262 3316
3263 3317
3264 void LCodeGen::DoMathTan(LUnaryMathOperation* instr) { 3318 void LCodeGen::DoMathTan(LUnaryMathOperation* instr) {
3265 ASSERT(ToDoubleRegister(instr->result()).is(d2)); 3319 ASSERT(ToDoubleRegister(instr->result()).is(d2));
(...skipping 1746 matching lines...) Expand 10 before | Expand all | Expand 10 after
5012 __ sub(scratch, result, Operand(index, LSL, kPointerSizeLog2 - kSmiTagSize)); 5066 __ sub(scratch, result, Operand(index, LSL, kPointerSizeLog2 - kSmiTagSize));
5013 __ ldr(result, FieldMemOperand(scratch, 5067 __ ldr(result, FieldMemOperand(scratch,
5014 FixedArray::kHeaderSize - kPointerSize)); 5068 FixedArray::kHeaderSize - kPointerSize));
5015 __ bind(&done); 5069 __ bind(&done);
5016 } 5070 }
5017 5071
5018 5072
5019 #undef __ 5073 #undef __
5020 5074
5021 } } // namespace v8::internal 5075 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/arm/lithium-codegen-arm.h ('k') | src/ia32/lithium-codegen-ia32.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698