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

Side by Side Diff: src/arm/lithium-codegen-arm.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 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-arm.cc ('k') | src/assembler.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 3938 matching lines...) Expand 10 before | Expand all | Expand 10 after
3949 MathPowStub stub(MathPowStub::INTEGER); 3949 MathPowStub stub(MathPowStub::INTEGER);
3950 __ CallStub(&stub); 3950 __ CallStub(&stub);
3951 } else { 3951 } else {
3952 ASSERT(exponent_type.IsDouble()); 3952 ASSERT(exponent_type.IsDouble());
3953 MathPowStub stub(MathPowStub::DOUBLE); 3953 MathPowStub stub(MathPowStub::DOUBLE);
3954 __ CallStub(&stub); 3954 __ CallStub(&stub);
3955 } 3955 }
3956 } 3956 }
3957 3957
3958 3958
3959 void LCodeGen::DoRandom(LRandom* instr) {
3960 // Assert that the register size is indeed the size of each seed.
3961 static const int kSeedSize = sizeof(uint32_t);
3962 STATIC_ASSERT(kPointerSize == kSeedSize);
3963
3964 // Load native context
3965 Register global_object = ToRegister(instr->global_object());
3966 Register native_context = global_object;
3967 __ ldr(native_context, FieldMemOperand(
3968 global_object, GlobalObject::kNativeContextOffset));
3969
3970 // Load state (FixedArray of the native context's random seeds)
3971 static const int kRandomSeedOffset =
3972 FixedArray::kHeaderSize + Context::RANDOM_SEED_INDEX * kPointerSize;
3973 Register state = native_context;
3974 __ ldr(state, FieldMemOperand(native_context, kRandomSeedOffset));
3975
3976 // Load state[0].
3977 Register state0 = ToRegister(instr->scratch());
3978 __ ldr(state0, FieldMemOperand(state, ByteArray::kHeaderSize));
3979 // Load state[1].
3980 Register state1 = ToRegister(instr->scratch2());
3981 __ ldr(state1, FieldMemOperand(state, ByteArray::kHeaderSize + kSeedSize));
3982
3983 // state[0] = 18273 * (state[0] & 0xFFFF) + (state[0] >> 16)
3984 Register scratch3 = ToRegister(instr->scratch3());
3985 Register scratch4 = scratch0();
3986 __ and_(scratch3, state0, Operand(0xFFFF));
3987 __ mov(scratch4, Operand(18273));
3988 __ mul(scratch3, scratch3, scratch4);
3989 __ add(state0, scratch3, Operand(state0, LSR, 16));
3990 // Save state[0].
3991 __ str(state0, FieldMemOperand(state, ByteArray::kHeaderSize));
3992
3993 // state[1] = 36969 * (state[1] & 0xFFFF) + (state[1] >> 16)
3994 __ and_(scratch3, state1, Operand(0xFFFF));
3995 __ mov(scratch4, Operand(36969));
3996 __ mul(scratch3, scratch3, scratch4);
3997 __ add(state1, scratch3, Operand(state1, LSR, 16));
3998 // Save state[1].
3999 __ str(state1, FieldMemOperand(state, ByteArray::kHeaderSize + kSeedSize));
4000
4001 // Random bit pattern = (state[0] << 14) + (state[1] & 0x3FFFF)
4002 Register random = scratch4;
4003 __ and_(random, state1, Operand(0x3FFFF));
4004 __ add(random, random, Operand(state0, LSL, 14));
4005
4006 // 0x41300000 is the top half of 1.0 x 2^20 as a double.
4007 // Create this constant using mov/orr to avoid PC relative load.
4008 __ mov(scratch3, Operand(0x41000000));
4009 __ orr(scratch3, scratch3, Operand(0x300000));
4010 // Move 0x41300000xxxxxxxx (x = random bits) to VFP.
4011 DwVfpRegister result = ToDoubleRegister(instr->result());
4012 __ vmov(result, random, scratch3);
4013 // Move 0x4130000000000000 to VFP.
4014 __ mov(scratch4, Operand::Zero());
4015 DwVfpRegister scratch5 = double_scratch0();
4016 __ vmov(scratch5, scratch4, scratch3);
4017 __ vsub(result, result, scratch5);
4018 }
4019
4020
4021 void LCodeGen::DoMathExp(LMathExp* instr) { 3959 void LCodeGen::DoMathExp(LMathExp* instr) {
4022 DwVfpRegister input = ToDoubleRegister(instr->value()); 3960 DwVfpRegister input = ToDoubleRegister(instr->value());
4023 DwVfpRegister result = ToDoubleRegister(instr->result()); 3961 DwVfpRegister result = ToDoubleRegister(instr->result());
4024 DwVfpRegister double_scratch1 = ToDoubleRegister(instr->double_temp()); 3962 DwVfpRegister double_scratch1 = ToDoubleRegister(instr->double_temp());
4025 DwVfpRegister double_scratch2 = double_scratch0(); 3963 DwVfpRegister double_scratch2 = double_scratch0();
4026 Register temp1 = ToRegister(instr->temp1()); 3964 Register temp1 = ToRegister(instr->temp1());
4027 Register temp2 = ToRegister(instr->temp2()); 3965 Register temp2 = ToRegister(instr->temp2());
4028 3966
4029 MathExpGenerator::EmitMathExp( 3967 MathExpGenerator::EmitMathExp(
4030 masm(), input, result, double_scratch1, double_scratch2, 3968 masm(), input, result, double_scratch1, double_scratch2,
(...skipping 1909 matching lines...) Expand 10 before | Expand all | Expand 10 after
5940 __ sub(scratch, result, Operand::PointerOffsetFromSmiKey(index)); 5878 __ sub(scratch, result, Operand::PointerOffsetFromSmiKey(index));
5941 __ ldr(result, FieldMemOperand(scratch, 5879 __ ldr(result, FieldMemOperand(scratch,
5942 FixedArray::kHeaderSize - kPointerSize)); 5880 FixedArray::kHeaderSize - kPointerSize));
5943 __ bind(&done); 5881 __ bind(&done);
5944 } 5882 }
5945 5883
5946 5884
5947 #undef __ 5885 #undef __
5948 5886
5949 } } // namespace v8::internal 5887 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/arm/lithium-arm.cc ('k') | src/assembler.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698