OLD | NEW |
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 2948 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2959 __ CallStub(&stub); | 2959 __ CallStub(&stub); |
2960 } else { | 2960 } else { |
2961 ASSERT(exponent_type.IsDouble()); | 2961 ASSERT(exponent_type.IsDouble()); |
2962 MathPowStub stub(MathPowStub::DOUBLE); | 2962 MathPowStub stub(MathPowStub::DOUBLE); |
2963 __ CallStub(&stub); | 2963 __ CallStub(&stub); |
2964 } | 2964 } |
2965 } | 2965 } |
2966 | 2966 |
2967 | 2967 |
2968 void LCodeGen::DoRandom(LRandom* instr) { | 2968 void LCodeGen::DoRandom(LRandom* instr) { |
| 2969 class DeferredDoRandom: public LDeferredCode { |
| 2970 public: |
| 2971 DeferredDoRandom(LCodeGen* codegen, LRandom* instr) |
| 2972 : LDeferredCode(codegen), instr_(instr) { } |
| 2973 virtual void Generate() { codegen()->DoDeferredRandom(instr_); } |
| 2974 virtual LInstruction* instr() { return instr_; } |
| 2975 private: |
| 2976 LRandom* instr_; |
| 2977 }; |
| 2978 |
| 2979 DeferredDoRandom* deferred = new DeferredDoRandom(this, instr); |
| 2980 |
2969 // Having marked this instruction as a call we can use any | 2981 // Having marked this instruction as a call we can use any |
2970 // registers. | 2982 // registers. |
2971 ASSERT(ToDoubleRegister(instr->result()).is(xmm1)); | 2983 ASSERT(ToDoubleRegister(instr->result()).is(xmm1)); |
2972 | 2984 |
2973 // Choose the right register for the first argument depending on | 2985 // Choose the right register for the first argument depending on |
2974 // calling convention. | 2986 // calling convention. |
2975 #ifdef _WIN64 | 2987 #ifdef _WIN64 |
2976 ASSERT(ToRegister(instr->InputAt(0)).is(rcx)); | 2988 ASSERT(ToRegister(instr->InputAt(0)).is(rcx)); |
2977 Register global_object = rcx; | 2989 Register global_object = rcx; |
2978 #else | 2990 #else |
2979 ASSERT(ToRegister(instr->InputAt(0)).is(rdi)); | 2991 ASSERT(ToRegister(instr->InputAt(0)).is(rdi)); |
2980 Register global_object = rdi; | 2992 Register global_object = rdi; |
2981 #endif | 2993 #endif |
2982 | 2994 |
2983 __ PrepareCallCFunction(1); | 2995 static const int kSeedSize = sizeof(uint32_t); |
| 2996 STATIC_ASSERT(kPointerSize == 2 * kSeedSize); |
| 2997 |
2984 __ movq(global_object, | 2998 __ movq(global_object, |
2985 FieldOperand(global_object, GlobalObject::kGlobalContextOffset)); | 2999 FieldOperand(global_object, GlobalObject::kGlobalContextOffset)); |
2986 __ CallCFunction(ExternalReference::random_uint32_function(isolate()), 1); | 3000 static const int kRandomSeedOffset = |
2987 __ movq(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); | 3001 FixedArray::kHeaderSize + Context::RANDOM_SEED_INDEX * kPointerSize; |
| 3002 __ movq(rbx, FieldOperand(global_object, kRandomSeedOffset)); |
| 3003 // rbx: FixedArray of the global context's random seeds |
2988 | 3004 |
| 3005 // Load state[0]. |
| 3006 __ movl(rax, FieldOperand(rbx, ByteArray::kHeaderSize)); |
| 3007 // If state[0] == 0, call runtime to initialize seeds. |
| 3008 __ testl(rax, rax); |
| 3009 __ j(zero, deferred->entry()); |
| 3010 // Load state[1]. |
| 3011 __ movl(rcx, FieldOperand(rbx, ByteArray::kHeaderSize + kSeedSize)); |
| 3012 |
| 3013 // state[0] = 18273 * (state[0] & 0xFFFF) + (state[0] >> 16) |
| 3014 // Only operate on the lower 32 bit of rax. |
| 3015 __ movl(rdx, rax); |
| 3016 __ andl(rdx, Immediate(0xFFFF)); |
| 3017 __ imull(rdx, rdx, Immediate(18273)); |
| 3018 __ shrl(rax, Immediate(16)); |
| 3019 __ addl(rax, rdx); |
| 3020 // Save state[0]. |
| 3021 __ movl(FieldOperand(rbx, ByteArray::kHeaderSize), rax); |
| 3022 |
| 3023 // state[1] = 36969 * (state[1] & 0xFFFF) + (state[1] >> 16) |
| 3024 __ movl(rdx, rcx); |
| 3025 __ andl(rdx, Immediate(0xFFFF)); |
| 3026 __ imull(rdx, rdx, Immediate(36969)); |
| 3027 __ shrl(rcx, Immediate(16)); |
| 3028 __ addl(rcx, rdx); |
| 3029 // Save state[1]. |
| 3030 __ movl(FieldOperand(rbx, ByteArray::kHeaderSize + kSeedSize), rcx); |
| 3031 |
| 3032 // Random bit pattern = (state[0] << 14) + (state[1] & 0x3FFFF) |
| 3033 __ shll(rax, Immediate(14)); |
| 3034 __ andl(rcx, Immediate(0x3FFFF)); |
| 3035 __ addl(rax, rcx); |
| 3036 |
| 3037 __ bind(deferred->exit()); |
2989 // Convert 32 random bits in rax to 0.(32 random bits) in a double | 3038 // Convert 32 random bits in rax to 0.(32 random bits) in a double |
2990 // by computing: | 3039 // by computing: |
2991 // ( 1.(20 0s)(32 random bits) x 2^20 ) - (1.0 x 2^20)). | 3040 // ( 1.(20 0s)(32 random bits) x 2^20 ) - (1.0 x 2^20)). |
2992 __ movl(rcx, Immediate(0x49800000)); // 1.0 x 2^20 as single. | 3041 __ movl(rcx, Immediate(0x49800000)); // 1.0 x 2^20 as single. |
2993 __ movd(xmm2, rcx); | 3042 __ movd(xmm2, rcx); |
2994 __ movd(xmm1, rax); | 3043 __ movd(xmm1, rax); |
2995 __ cvtss2sd(xmm2, xmm2); | 3044 __ cvtss2sd(xmm2, xmm2); |
2996 __ xorps(xmm1, xmm2); | 3045 __ xorps(xmm1, xmm2); |
2997 __ subsd(xmm1, xmm2); | 3046 __ subsd(xmm1, xmm2); |
2998 } | 3047 } |
2999 | 3048 |
3000 | 3049 |
| 3050 void LCodeGen::DoDeferredRandom(LRandom* instr) { |
| 3051 __ PrepareCallCFunction(1); |
| 3052 __ CallCFunction(ExternalReference::random_uint32_function(isolate()), 1); |
| 3053 __ movq(rsi, Operand(rbp, StandardFrameConstants::kContextOffset)); |
| 3054 // Return value is in rax. |
| 3055 } |
| 3056 |
| 3057 |
3001 void LCodeGen::DoMathLog(LUnaryMathOperation* instr) { | 3058 void LCodeGen::DoMathLog(LUnaryMathOperation* instr) { |
3002 ASSERT(ToDoubleRegister(instr->result()).is(xmm1)); | 3059 ASSERT(ToDoubleRegister(instr->result()).is(xmm1)); |
3003 TranscendentalCacheStub stub(TranscendentalCache::LOG, | 3060 TranscendentalCacheStub stub(TranscendentalCache::LOG, |
3004 TranscendentalCacheStub::UNTAGGED); | 3061 TranscendentalCacheStub::UNTAGGED); |
3005 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); | 3062 CallCode(stub.GetCode(), RelocInfo::CODE_TARGET, instr); |
3006 } | 3063 } |
3007 | 3064 |
3008 | 3065 |
3009 void LCodeGen::DoMathTan(LUnaryMathOperation* instr) { | 3066 void LCodeGen::DoMathTan(LUnaryMathOperation* instr) { |
3010 ASSERT(ToDoubleRegister(instr->result()).is(xmm1)); | 3067 ASSERT(ToDoubleRegister(instr->result()).is(xmm1)); |
(...skipping 1626 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4637 FixedArray::kHeaderSize - kPointerSize)); | 4694 FixedArray::kHeaderSize - kPointerSize)); |
4638 __ bind(&done); | 4695 __ bind(&done); |
4639 } | 4696 } |
4640 | 4697 |
4641 | 4698 |
4642 #undef __ | 4699 #undef __ |
4643 | 4700 |
4644 } } // namespace v8::internal | 4701 } } // namespace v8::internal |
4645 | 4702 |
4646 #endif // V8_TARGET_ARCH_X64 | 4703 #endif // V8_TARGET_ARCH_X64 |
OLD | NEW |