OLD | NEW |
1 // Copyright 2010 the V8 project authors. All rights reserved. | 1 // Copyright 2010 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 4075 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
4086 case kMathSqrt: | 4086 case kMathSqrt: |
4087 if (argument_count == 2) { | 4087 if (argument_count == 2) { |
4088 HValue* argument = Pop(); | 4088 HValue* argument = Pop(); |
4089 // Pop receiver. | 4089 // Pop receiver. |
4090 Pop(); | 4090 Pop(); |
4091 HUnaryMathOperation* op = new HUnaryMathOperation(argument, id); | 4091 HUnaryMathOperation* op = new HUnaryMathOperation(argument, id); |
4092 PushAndAdd(op, expr->position()); | 4092 PushAndAdd(op, expr->position()); |
4093 return true; | 4093 return true; |
4094 } | 4094 } |
4095 break; | 4095 break; |
| 4096 case kMathPow: |
| 4097 if (argument_count == 3) { |
| 4098 HValue* right = Pop(); |
| 4099 HValue* left = Pop(); |
| 4100 Pop(); // Pop receiver. |
| 4101 // Use sqrt() if exponent is 0.5 or -0.5. |
| 4102 if (right->IsConstant() && HConstant::cast(right)->HasDoubleValue()) { |
| 4103 double exponent = HConstant::cast(right)->DoubleValue(); |
| 4104 if (exponent == 0.5) { |
| 4105 PushAndAdd(new HUnaryMathOperation(left, kMathPowHalf)); |
| 4106 return true; |
| 4107 } else if (exponent == -0.5) { |
| 4108 HConstant* double_one = |
| 4109 new HConstant(Handle<Object>(Smi::FromInt(1)), |
| 4110 Representation::Double()); |
| 4111 AddInstruction(double_one); |
| 4112 HUnaryMathOperation* square_root = |
| 4113 new HUnaryMathOperation(left, kMathPowHalf); |
| 4114 AddInstruction(square_root); |
| 4115 PushAndAdd(new HDiv(double_one, square_root)); |
| 4116 return true; |
| 4117 } else if (exponent == 2.0) { |
| 4118 PushAndAdd(new HMul(left, left)); |
| 4119 return true; |
| 4120 } |
| 4121 } else if (right->IsConstant() && |
| 4122 HConstant::cast(right)->HasInteger32Value() && |
| 4123 HConstant::cast(right)->Integer32Value() == 2) { |
| 4124 PushAndAdd(new HMul(left, left)); |
| 4125 return true; |
| 4126 } |
| 4127 |
| 4128 PushAndAdd(new HPower(left, right)); |
| 4129 return true; |
| 4130 } |
| 4131 break; |
4096 default: | 4132 default: |
4097 // Either not a special math function or not yet supported for inlining. | 4133 // Either not a special math function or not yet supported for inlining. |
4098 break; | 4134 break; |
4099 } | 4135 } |
4100 return false; | 4136 return false; |
4101 } | 4137 } |
4102 | 4138 |
4103 | 4139 |
4104 bool HGraphBuilder::TryCallApply(Call* expr) { | 4140 bool HGraphBuilder::TryCallApply(Call* expr) { |
4105 Expression* callee = expr->expression(); | 4141 Expression* callee = expr->expression(); |
(...skipping 907 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5013 | 5049 |
5014 // Fast call for custom callbacks. | 5050 // Fast call for custom callbacks. |
5015 void HGraphBuilder::GenerateCallFunction(int argument_count) { | 5051 void HGraphBuilder::GenerateCallFunction(int argument_count) { |
5016 BAILOUT("inlined runtime function: CallFunction"); | 5052 BAILOUT("inlined runtime function: CallFunction"); |
5017 } | 5053 } |
5018 | 5054 |
5019 | 5055 |
5020 // Fast call to math functions. | 5056 // Fast call to math functions. |
5021 void HGraphBuilder::GenerateMathPow(int argument_count) { | 5057 void HGraphBuilder::GenerateMathPow(int argument_count) { |
5022 ASSERT_EQ(2, argument_count); | 5058 ASSERT_EQ(2, argument_count); |
5023 PushArgumentsForStubCall(argument_count); | 5059 HValue* right = Pop(); |
5024 PushAndAdd(new HCallStub(CodeStub::MathPow, argument_count), | 5060 HValue* left = Pop(); |
5025 RelocInfo::kNoPosition); | 5061 PushAndAdd(new HPower(left, right)); |
5026 } | 5062 } |
5027 | 5063 |
5028 | 5064 |
5029 void HGraphBuilder::GenerateMathSin(int argument_count) { | 5065 void HGraphBuilder::GenerateMathSin(int argument_count) { |
5030 ASSERT_EQ(1, argument_count); | 5066 ASSERT_EQ(1, argument_count); |
5031 PushArgumentsForStubCall(argument_count); | 5067 PushArgumentsForStubCall(argument_count); |
5032 HCallStub* instr = | 5068 HCallStub* instr = |
5033 new HCallStub(CodeStub::TranscendentalCache, argument_count); | 5069 new HCallStub(CodeStub::TranscendentalCache, argument_count); |
5034 instr->set_transcendental_type(TranscendentalCache::SIN); | 5070 instr->set_transcendental_type(TranscendentalCache::SIN); |
5035 PushAndAdd(instr, RelocInfo::kNoPosition); | 5071 PushAndAdd(instr, RelocInfo::kNoPosition); |
(...skipping 505 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5541 } | 5577 } |
5542 | 5578 |
5543 #ifdef DEBUG | 5579 #ifdef DEBUG |
5544 if (graph_ != NULL) graph_->Verify(); | 5580 if (graph_ != NULL) graph_->Verify(); |
5545 if (chunk_ != NULL) chunk_->Verify(); | 5581 if (chunk_ != NULL) chunk_->Verify(); |
5546 if (allocator_ != NULL) allocator_->Verify(); | 5582 if (allocator_ != NULL) allocator_->Verify(); |
5547 #endif | 5583 #endif |
5548 } | 5584 } |
5549 | 5585 |
5550 } } // namespace v8::internal | 5586 } } // namespace v8::internal |
OLD | NEW |