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

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

Issue 68723002: Implement Math.random() purely in JavaScript. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Comments only Created 7 years, 1 month 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/mips/full-codegen-mips.cc ('k') | src/mips/lithium-mips.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 3824 matching lines...) Expand 10 before | Expand all | Expand 10 after
3835 MathPowStub stub(MathPowStub::INTEGER); 3835 MathPowStub stub(MathPowStub::INTEGER);
3836 __ CallStub(&stub); 3836 __ CallStub(&stub);
3837 } else { 3837 } else {
3838 ASSERT(exponent_type.IsDouble()); 3838 ASSERT(exponent_type.IsDouble());
3839 MathPowStub stub(MathPowStub::DOUBLE); 3839 MathPowStub stub(MathPowStub::DOUBLE);
3840 __ CallStub(&stub); 3840 __ CallStub(&stub);
3841 } 3841 }
3842 } 3842 }
3843 3843
3844 3844
3845 void LCodeGen::DoRandom(LRandom* instr) {
3846 // Assert that the register size is indeed the size of each seed.
3847 static const int kSeedSize = sizeof(uint32_t);
3848 STATIC_ASSERT(kPointerSize == kSeedSize);
3849
3850 // Load native context.
3851 Register global_object = ToRegister(instr->global_object());
3852 Register native_context = global_object;
3853 __ lw(native_context, FieldMemOperand(
3854 global_object, GlobalObject::kNativeContextOffset));
3855
3856 // Load state (FixedArray of the native context's random seeds).
3857 static const int kRandomSeedOffset =
3858 FixedArray::kHeaderSize + Context::RANDOM_SEED_INDEX * kPointerSize;
3859 Register state = native_context;
3860 __ lw(state, FieldMemOperand(native_context, kRandomSeedOffset));
3861
3862 // Load state[0].
3863 Register state0 = ToRegister(instr->scratch());
3864 __ lw(state0, FieldMemOperand(state, ByteArray::kHeaderSize));
3865 // Load state[1].
3866 Register state1 = ToRegister(instr->scratch2());
3867 __ lw(state1, FieldMemOperand(state, ByteArray::kHeaderSize + kSeedSize));
3868
3869 // state[0] = 18273 * (state[0] & 0xFFFF) + (state[0] >> 16)
3870 Register scratch3 = ToRegister(instr->scratch3());
3871 Register scratch4 = scratch0();
3872 __ And(scratch3, state0, Operand(0xFFFF));
3873 __ li(scratch4, Operand(18273));
3874 __ Mul(scratch3, scratch3, scratch4);
3875 __ srl(state0, state0, 16);
3876 __ Addu(state0, scratch3, state0);
3877 // Save state[0].
3878 __ sw(state0, FieldMemOperand(state, ByteArray::kHeaderSize));
3879
3880 // state[1] = 36969 * (state[1] & 0xFFFF) + (state[1] >> 16)
3881 __ And(scratch3, state1, Operand(0xFFFF));
3882 __ li(scratch4, Operand(36969));
3883 __ Mul(scratch3, scratch3, scratch4);
3884 __ srl(state1, state1, 16),
3885 __ Addu(state1, scratch3, state1);
3886 // Save state[1].
3887 __ sw(state1, FieldMemOperand(state, ByteArray::kHeaderSize + kSeedSize));
3888
3889 // Random bit pattern = (state[0] << 14) + (state[1] & 0x3FFFF)
3890 Register random = scratch4;
3891 __ And(random, state1, Operand(0x3FFFF));
3892 __ sll(state0, state0, 14);
3893 __ Addu(random, random, state0);
3894
3895 // 0x41300000 is the top half of 1.0 x 2^20 as a double.
3896 __ li(scratch3, Operand(0x41300000));
3897 // Move 0x41300000xxxxxxxx (x = random bits in v0) to FPU.
3898 DoubleRegister result = ToDoubleRegister(instr->result());
3899 __ Move(result, random, scratch3);
3900 // Move 0x4130000000000000 to FPU.
3901 DoubleRegister scratch5 = double_scratch0();
3902 __ Move(scratch5, zero_reg, scratch3);
3903 __ sub_d(result, result, scratch5);
3904 }
3905
3906
3907 void LCodeGen::DoMathExp(LMathExp* instr) { 3845 void LCodeGen::DoMathExp(LMathExp* instr) {
3908 DoubleRegister input = ToDoubleRegister(instr->value()); 3846 DoubleRegister input = ToDoubleRegister(instr->value());
3909 DoubleRegister result = ToDoubleRegister(instr->result()); 3847 DoubleRegister result = ToDoubleRegister(instr->result());
3910 DoubleRegister double_scratch1 = ToDoubleRegister(instr->double_temp()); 3848 DoubleRegister double_scratch1 = ToDoubleRegister(instr->double_temp());
3911 DoubleRegister double_scratch2 = double_scratch0(); 3849 DoubleRegister double_scratch2 = double_scratch0();
3912 Register temp1 = ToRegister(instr->temp1()); 3850 Register temp1 = ToRegister(instr->temp1());
3913 Register temp2 = ToRegister(instr->temp2()); 3851 Register temp2 = ToRegister(instr->temp2());
3914 3852
3915 MathExpGenerator::EmitMathExp( 3853 MathExpGenerator::EmitMathExp(
3916 masm(), input, result, double_scratch1, double_scratch2, 3854 masm(), input, result, double_scratch1, double_scratch2,
(...skipping 1976 matching lines...) Expand 10 before | Expand all | Expand 10 after
5893 __ Subu(scratch, result, scratch); 5831 __ Subu(scratch, result, scratch);
5894 __ lw(result, FieldMemOperand(scratch, 5832 __ lw(result, FieldMemOperand(scratch,
5895 FixedArray::kHeaderSize - kPointerSize)); 5833 FixedArray::kHeaderSize - kPointerSize));
5896 __ bind(&done); 5834 __ bind(&done);
5897 } 5835 }
5898 5836
5899 5837
5900 #undef __ 5838 #undef __
5901 5839
5902 } } // namespace v8::internal 5840 } } // namespace v8::internal
OLDNEW
« no previous file with comments | « src/mips/full-codegen-mips.cc ('k') | src/mips/lithium-mips.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698