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

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

Issue 9615008: Inline Math.random in crankshaft (ia32). (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/ia32/lithium-codegen-ia32.h ('k') | test/cctest/SConscript » ('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 3032 matching lines...) Expand 10 before | Expand all | Expand 10 after
3043 __ CallStub(&stub); 3043 __ CallStub(&stub);
3044 } else { 3044 } else {
3045 ASSERT(exponent_type.IsDouble()); 3045 ASSERT(exponent_type.IsDouble());
3046 MathPowStub stub(MathPowStub::DOUBLE); 3046 MathPowStub stub(MathPowStub::DOUBLE);
3047 __ CallStub(&stub); 3047 __ CallStub(&stub);
3048 } 3048 }
3049 } 3049 }
3050 3050
3051 3051
3052 void LCodeGen::DoRandom(LRandom* instr) { 3052 void LCodeGen::DoRandom(LRandom* instr) {
3053 class DeferredDoRandom: public LDeferredCode {
3054 public:
3055 DeferredDoRandom(LCodeGen* codegen, LRandom* instr)
3056 : LDeferredCode(codegen), instr_(instr) { }
3057 virtual void Generate() { codegen()->DoDeferredRandom(instr_); }
3058 virtual LInstruction* instr() { return instr_; }
3059 private:
3060 LRandom* instr_;
3061 };
3062
3063 DeferredDoRandom* deferred = new DeferredDoRandom(this, instr);
3064
3053 // Having marked this instruction as a call we can use any 3065 // Having marked this instruction as a call we can use any
3054 // registers. 3066 // registers.
3055 ASSERT(ToDoubleRegister(instr->result()).is(xmm1)); 3067 ASSERT(ToDoubleRegister(instr->result()).is(xmm1));
3056 ASSERT(ToRegister(instr->InputAt(0)).is(eax)); 3068 ASSERT(ToRegister(instr->InputAt(0)).is(eax));
3069 // Assert that the register size is indeed the size of each seed.
3070 const int kSeedSize = sizeof(uint32_t);
Jakob Kummerow 2012/03/06 10:49:30 static?
3071 STATIC_ASSERT(kPointerSize == kSeedSize);
3057 3072
3058 __ PrepareCallCFunction(1, ebx);
3059 __ mov(eax, FieldOperand(eax, GlobalObject::kGlobalContextOffset)); 3073 __ mov(eax, FieldOperand(eax, GlobalObject::kGlobalContextOffset));
3060 __ mov(Operand(esp, 0), eax); 3074 const int kRandomSeedOffset =
Jakob Kummerow 2012/03/06 10:49:30 static?
3061 __ CallCFunction(ExternalReference::random_uint32_function(isolate()), 1); 3075 FixedArray::kHeaderSize + Context::RANDOM_SEED_INDEX * kPointerSize;
3076 __ mov(ebx, FieldOperand(eax, kRandomSeedOffset));
3077 // ebx: FixedArray of the global context's random seeds
3062 3078
3079 // Load state[0].
3080 __ mov(ecx, FieldOperand(ebx, ByteArray::kHeaderSize));
3081 // If state[0] == 0, call runtime to initialize seeds.
3082 __ test(ecx, ecx);
3083 __ j(zero, deferred->entry());
3084
3085 // state[0] = 18273 * (state[0] & 0xFFFF) + (state[0] >> 16)
3086 __ movzx_w(edx, ecx);
3087 __ imul(edx, edx, 18273);
3088 __ shr(ecx, 16);
3089 __ add(ecx, edx);
3090 __ mov(FieldOperand(ebx, ByteArray::kHeaderSize), ecx);
3091
3092 // Load state[1].
3093 // state[1] = 36969 * (state[1] & 0xFFFF) + (state[1] >> 16);
3094 __ mov(eax, FieldOperand(ebx, ByteArray::kHeaderSize + kSeedSize));
3095 __ movzx_w(edx, eax);
3096 __ imul(edx, edx, 36969);
3097 __ shr(eax, 16);
3098 __ add(eax, edx);
3099 __ mov(FieldOperand(ebx, ByteArray::kHeaderSize + kSeedSize), eax);
3100
3101 // ecx: state[0]
3102 // eax: state[1]
3103 // Random bit pattern = (state[0] << 14) + (state[1] & 0x3FFFF)
3104 __ shl(ecx, 14);
3105 __ and_(eax, Immediate(0x3FFFF));
3106 __ add(eax, ecx);
3107
3108 __ bind(deferred->exit());
3063 // Convert 32 random bits in eax to 0.(32 random bits) in a double 3109 // Convert 32 random bits in eax to 0.(32 random bits) in a double
3064 // by computing: 3110 // by computing:
3065 // ( 1.(20 0s)(32 random bits) x 2^20 ) - (1.0 x 2^20)). 3111 // ( 1.(20 0s)(32 random bits) x 2^20 ) - (1.0 x 2^20)).
3066 __ mov(ebx, Immediate(0x49800000)); // 1.0 x 2^20 as single. 3112 __ mov(ebx, Immediate(0x49800000)); // 1.0 x 2^20 as single.
3067 __ movd(xmm2, ebx); 3113 __ movd(xmm2, ebx);
3068 __ movd(xmm1, eax); 3114 __ movd(xmm1, eax);
3069 __ cvtss2sd(xmm2, xmm2); 3115 __ cvtss2sd(xmm2, xmm2);
3070 __ xorps(xmm1, xmm2); 3116 __ xorps(xmm1, xmm2);
3071 __ subsd(xmm1, xmm2); 3117 __ subsd(xmm1, xmm2);
3072 } 3118 }
3073 3119
3074 3120
3121 void LCodeGen::DoDeferredRandom(LRandom* instr) {
3122 __ PrepareCallCFunction(1, ebx);
3123 __ mov(Operand(esp, 0), eax);
3124 __ CallCFunction(ExternalReference::random_uint32_function(isolate()), 1);
3125 // Return value is in eax.
3126 }
3127
3128
3075 void LCodeGen::DoMathLog(LUnaryMathOperation* instr) { 3129 void LCodeGen::DoMathLog(LUnaryMathOperation* instr) {
3076 ASSERT(instr->value()->Equals(instr->result())); 3130 ASSERT(instr->value()->Equals(instr->result()));
3077 XMMRegister input_reg = ToDoubleRegister(instr->value()); 3131 XMMRegister input_reg = ToDoubleRegister(instr->value());
3078 Label positive, done, zero; 3132 Label positive, done, zero;
3079 __ xorps(xmm0, xmm0); 3133 __ xorps(xmm0, xmm0);
3080 __ ucomisd(input_reg, xmm0); 3134 __ ucomisd(input_reg, xmm0);
3081 __ j(above, &positive, Label::kNear); 3135 __ j(above, &positive, Label::kNear);
3082 __ j(equal, &zero, Label::kNear); 3136 __ j(equal, &zero, Label::kNear);
3083 ExternalReference nan = 3137 ExternalReference nan =
3084 ExternalReference::address_of_canonical_non_hole_nan(); 3138 ExternalReference::address_of_canonical_non_hole_nan();
(...skipping 1816 matching lines...) Expand 10 before | Expand all | Expand 10 after
4901 FixedArray::kHeaderSize - kPointerSize)); 4955 FixedArray::kHeaderSize - kPointerSize));
4902 __ bind(&done); 4956 __ bind(&done);
4903 } 4957 }
4904 4958
4905 4959
4906 #undef __ 4960 #undef __
4907 4961
4908 } } // namespace v8::internal 4962 } } // namespace v8::internal
4909 4963
4910 #endif // V8_TARGET_ARCH_IA32 4964 #endif // V8_TARGET_ARCH_IA32
OLDNEW
« no previous file with comments | « src/ia32/lithium-codegen-ia32.h ('k') | test/cctest/SConscript » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698