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

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

Issue 9615016: MIPS: Port r10939 to x64 and arm (inline Math.random in crankshaft). (Closed)
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
« no previous file with comments | « src/mips/lithium-codegen-mips.h ('k') | no next file » | 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 3115 matching lines...) Expand 10 before | Expand all | Expand 10 after
3126 __ CallStub(&stub); 3126 __ CallStub(&stub);
3127 } else { 3127 } else {
3128 ASSERT(exponent_type.IsDouble()); 3128 ASSERT(exponent_type.IsDouble());
3129 MathPowStub stub(MathPowStub::DOUBLE); 3129 MathPowStub stub(MathPowStub::DOUBLE);
3130 __ CallStub(&stub); 3130 __ CallStub(&stub);
3131 } 3131 }
3132 } 3132 }
3133 3133
3134 3134
3135 void LCodeGen::DoRandom(LRandom* instr) { 3135 void LCodeGen::DoRandom(LRandom* instr) {
3136 class DeferredDoRandom: public LDeferredCode {
3137 public:
3138 DeferredDoRandom(LCodeGen* codegen, LRandom* instr)
3139 : LDeferredCode(codegen), instr_(instr) { }
3140 virtual void Generate() { codegen()->DoDeferredRandom(instr_); }
3141 virtual LInstruction* instr() { return instr_; }
3142 private:
3143 LRandom* instr_;
3144 };
3145
3146 DeferredDoRandom* deferred = new DeferredDoRandom(this, instr);
3136 // Having marked this instruction as a call we can use any 3147 // Having marked this instruction as a call we can use any
3137 // registers. 3148 // registers.
3138 ASSERT(ToDoubleRegister(instr->result()).is(f0)); 3149 ASSERT(ToDoubleRegister(instr->result()).is(f0));
3139 ASSERT(ToRegister(instr->InputAt(0)).is(a0)); 3150 ASSERT(ToRegister(instr->InputAt(0)).is(a0));
3140 3151
3141 __ PrepareCallCFunction(1, a1); 3152 static const int kSeedSize = sizeof(uint32_t);
3153 STATIC_ASSERT(kPointerSize == kSeedSize);
3154
3142 __ lw(a0, FieldMemOperand(a0, GlobalObject::kGlobalContextOffset)); 3155 __ lw(a0, FieldMemOperand(a0, GlobalObject::kGlobalContextOffset));
3143 __ CallCFunction(ExternalReference::random_uint32_function(isolate()), 1); 3156 static const int kRandomSeedOffset =
3157 FixedArray::kHeaderSize + Context::RANDOM_SEED_INDEX * kPointerSize;
3158 __ lw(a2, FieldMemOperand(a0, kRandomSeedOffset));
3159 // a2: FixedArray of the global context's random seeds
3160
3161 // Load state[0].
3162 __ lw(a1, FieldMemOperand(a2, ByteArray::kHeaderSize));
3163 __ Branch(deferred->entry(), eq, a1, Operand(zero_reg));
3164 // Load state[1].
3165 __ lw(a0, FieldMemOperand(a2, ByteArray::kHeaderSize + kSeedSize));
3166 // a1: state[0].
3167 // a0: state[1].
3168
3169 // state[0] = 18273 * (state[0] & 0xFFFF) + (state[0] >> 16)
3170 __ And(a3, a1, Operand(0xFFFF));
3171 __ li(t0, Operand(18273));
3172 __ mul(a3, a3, t0);
3173 __ srl(a1, a1, 16);
3174 __ Addu(a1, a3, a1);
3175 // Save state[0].
3176 __ sw(a1, FieldMemOperand(a2, ByteArray::kHeaderSize));
3177
3178 // state[1] = 36969 * (state[1] & 0xFFFF) + (state[1] >> 16)
3179 __ And(a3, a0, Operand(0xFFFF));
3180 __ li(t0, Operand(36969));
3181 __ mul(a3, a3, t0);
3182 __ srl(a0, a0, 16),
3183 __ Addu(a0, a3, a0);
3184 // Save state[1].
3185 __ sw(a0, FieldMemOperand(a2, ByteArray::kHeaderSize + kSeedSize));
3186
3187 // Random bit pattern = (state[0] << 14) + (state[1] & 0x3FFFF)
3188 __ And(a0, a0, Operand(0x3FFFF));
3189 __ sll(a1, a1, 14);
3190 __ Addu(v0, a0, a1);
3191
3192 __ bind(deferred->exit());
3144 3193
3145 // 0x41300000 is the top half of 1.0 x 2^20 as a double. 3194 // 0x41300000 is the top half of 1.0 x 2^20 as a double.
3146 __ li(a2, Operand(0x41300000)); 3195 __ li(a2, Operand(0x41300000));
3147 // Move 0x41300000xxxxxxxx (x = random bits in v0) to FPU. 3196 // Move 0x41300000xxxxxxxx (x = random bits in v0) to FPU.
3148 __ Move(f12, v0, a2); 3197 __ Move(f12, v0, a2);
3149 // Move 0x4130000000000000 to FPU. 3198 // Move 0x4130000000000000 to FPU.
3150 __ Move(f14, zero_reg, a2); 3199 __ Move(f14, zero_reg, a2);
3151 // Subtract to get the result. 3200 // Subtract to get the result.
3152 __ sub_d(f0, f12, f14); 3201 __ sub_d(f0, f12, f14);
3153 } 3202 }
3154 3203
3204 void LCodeGen::DoDeferredRandom(LRandom* instr) {
3205 __ PrepareCallCFunction(1, scratch0());
3206 __ CallCFunction(ExternalReference::random_uint32_function(isolate()), 1);
3207 // Return value is in v0.
3208 }
3209
3155 3210
3156 void LCodeGen::DoMathLog(LUnaryMathOperation* instr) { 3211 void LCodeGen::DoMathLog(LUnaryMathOperation* instr) {
3157 ASSERT(ToDoubleRegister(instr->result()).is(f4)); 3212 ASSERT(ToDoubleRegister(instr->result()).is(f4));
3158 TranscendentalCacheStub stub(TranscendentalCache::LOG, 3213 TranscendentalCacheStub stub(TranscendentalCache::LOG,
3159 TranscendentalCacheStub::UNTAGGED); 3214 TranscendentalCacheStub::UNTAGGED);
3160 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); 3215 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr);
3161 } 3216 }
3162 3217
3163 3218
3164 void LCodeGen::DoMathTan(LUnaryMathOperation* instr) { 3219 void LCodeGen::DoMathTan(LUnaryMathOperation* instr) {
(...skipping 1786 matching lines...) Expand 10 before | Expand all | Expand 10 after
4951 __ Subu(scratch, result, scratch); 5006 __ Subu(scratch, result, scratch);
4952 __ lw(result, FieldMemOperand(scratch, 5007 __ lw(result, FieldMemOperand(scratch,
4953 FixedArray::kHeaderSize - kPointerSize)); 5008 FixedArray::kHeaderSize - kPointerSize));
4954 __ bind(&done); 5009 __ bind(&done);
4955 } 5010 }
4956 5011
4957 5012
4958 #undef __ 5013 #undef __
4959 5014
4960 } } // namespace v8::internal 5015 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/mips/lithium-codegen-mips.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698