OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. Use of this |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // source code is governed by a BSD-style license that can be found in the |
3 // found in the LICENSE file. | 3 // LICENSE file. |
4 | 4 |
5 #include <cmath> | 5 #include <cmath> |
6 #include <functional> | 6 #include <functional> |
7 #include <limits> | 7 #include <limits> |
8 | 8 |
9 #include "src/base/bits.h" | 9 #include "src/base/bits.h" |
10 #include "src/base/utils/random-number-generator.h" | 10 #include "src/base/utils/random-number-generator.h" |
11 #include "src/codegen.h" | 11 #include "src/codegen.h" |
12 #include "test/cctest/cctest.h" | 12 #include "test/cctest/cctest.h" |
13 #include "test/cctest/compiler/codegen-tester.h" | 13 #include "test/cctest/compiler/codegen-tester.h" |
| 14 #include "test/cctest/compiler/graph-builder-tester.h" |
14 #include "test/cctest/compiler/value-helper.h" | 15 #include "test/cctest/compiler/value-helper.h" |
15 | 16 |
16 using namespace v8::base; | 17 using namespace v8::base; |
17 using namespace v8::internal; | 18 using namespace v8::internal; |
18 using namespace v8::internal::compiler; | 19 using namespace v8::internal::compiler; |
19 | 20 |
20 typedef RawMachineAssembler::Label MLabel; | 21 typedef RawMachineAssembler::Label MLabel; |
21 | 22 |
22 TEST(RunInt32Add) { | 23 TEST(RunInt32Add) { |
23 RawMachineAssemblerTester<int32_t> m; | 24 RawMachineAssemblerTester<int32_t> m; |
(...skipping 5475 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5499 FOR_INT32_INPUTS(i) { | 5500 FOR_INT32_INPUTS(i) { |
5500 input = *i; | 5501 input = *i; |
5501 CHECK_EQ(11, m.Call()); | 5502 CHECK_EQ(11, m.Call()); |
5502 float expected = bit_cast<float>(input); | 5503 float expected = bit_cast<float>(input); |
5503 CHECK_EQ(bit_cast<int32_t>(expected), bit_cast<int32_t>(output)); | 5504 CHECK_EQ(bit_cast<int32_t>(expected), bit_cast<int32_t>(output)); |
5504 } | 5505 } |
5505 } | 5506 } |
5506 | 5507 |
5507 | 5508 |
5508 TEST(RunComputedCodeObject) { | 5509 TEST(RunComputedCodeObject) { |
5509 RawMachineAssemblerTester<int32_t> a; | 5510 GraphBuilderTester<int32_t> a; |
5510 a.Return(a.Int32Constant(33)); | 5511 a.Return(a.Int32Constant(33)); |
5511 CHECK_EQ(33, a.Call()); | 5512 a.End(); |
| 5513 Handle<Code> code_a = a.GetCode(); |
5512 | 5514 |
5513 RawMachineAssemblerTester<int32_t> b; | 5515 GraphBuilderTester<int32_t> b; |
5514 b.Return(b.Int32Constant(44)); | 5516 b.Return(b.Int32Constant(44)); |
5515 CHECK_EQ(44, b.Call()); | 5517 b.End(); |
| 5518 Handle<Code> code_b = b.GetCode(); |
5516 | 5519 |
5517 RawMachineAssemblerTester<int32_t> r(kMachInt32); | 5520 RawMachineAssemblerTester<int32_t> r(kMachInt32); |
5518 RawMachineAssembler::Label tlabel; | 5521 RawMachineAssembler::Label tlabel; |
5519 RawMachineAssembler::Label flabel; | 5522 RawMachineAssembler::Label flabel; |
5520 RawMachineAssembler::Label merge; | 5523 RawMachineAssembler::Label merge; |
5521 r.Branch(r.Parameter(0), &tlabel, &flabel); | 5524 r.Branch(r.Parameter(0), &tlabel, &flabel); |
5522 r.Bind(&tlabel); | 5525 r.Bind(&tlabel); |
5523 Node* fa = r.HeapConstant(a.GetCode()); | 5526 Node* fa = r.HeapConstant(code_a); |
5524 r.Goto(&merge); | 5527 r.Goto(&merge); |
5525 r.Bind(&flabel); | 5528 r.Bind(&flabel); |
5526 Node* fb = r.HeapConstant(b.GetCode()); | 5529 Node* fb = r.HeapConstant(code_b); |
5527 r.Goto(&merge); | 5530 r.Goto(&merge); |
5528 r.Bind(&merge); | 5531 r.Bind(&merge); |
5529 Node* phi = r.Phi(kMachInt32, fa, fb); | 5532 Node* phi = r.Phi(kMachInt32, fa, fb); |
5530 | 5533 |
5531 // TODO(titzer): all this descriptor hackery is just to call the above | 5534 // TODO(titzer): all this descriptor hackery is just to call the above |
5532 // functions as code objects instead of direct addresses. | 5535 // functions as code objects instead of direct addresses. |
5533 CSignature0<int32_t> sig; | 5536 CSignature0<int32_t> sig; |
5534 CallDescriptor* c = Linkage::GetSimplifiedCDescriptor(r.zone(), &sig); | 5537 CallDescriptor* c = Linkage::GetSimplifiedCDescriptor(r.zone(), &sig); |
5535 LinkageLocation ret[] = {c->GetReturnLocation(0)}; | 5538 LinkageLocation ret[] = {c->GetReturnLocation(0)}; |
5536 Signature<LinkageLocation> loc(1, 0, ret); | 5539 Signature<LinkageLocation> loc(1, 0, ret); |
5537 CallDescriptor* desc = new (r.zone()) CallDescriptor( // -- | 5540 CallDescriptor* desc = new (r.zone()) CallDescriptor( // -- |
5538 CallDescriptor::kCallCodeObject, // kind | 5541 CallDescriptor::kCallCodeObject, // kind |
5539 kMachAnyTagged, // target_type | 5542 kMachAnyTagged, // target_type |
5540 c->GetInputLocation(0), // target_loc | 5543 c->GetInputLocation(0), // target_loc |
5541 &sig, // machine_sig | 5544 &sig, // machine_sig |
5542 &loc, // location_sig | 5545 &loc, // location_sig |
5543 0, // stack count | 5546 0, // stack count |
5544 Operator::kNoProperties, // properties | 5547 Operator::kNoProperties, // properties |
5545 c->CalleeSavedRegisters(), // callee saved | 5548 c->CalleeSavedRegisters(), // callee saved |
5546 c->CalleeSavedFPRegisters(), // callee saved FP | 5549 c->CalleeSavedFPRegisters(), // callee saved FP |
5547 CallDescriptor::kNoFlags, // flags | 5550 CallDescriptor::kNoFlags, // flags |
5548 "c-call-as-code"); | 5551 "c-call-as-code"); |
5549 Node* call = r.AddNode(r.common()->Call(desc), phi); | 5552 Node* call = r.AddNode(r.common()->Call(desc), phi); |
5550 r.Return(call); | 5553 r.Return(call); |
5551 | 5554 |
5552 CHECK_EQ(33, r.Call(1)); | 5555 CHECK_EQ(33, r.Call(1)); |
5553 CHECK_EQ(44, r.Call(0)); | 5556 CHECK_EQ(44, r.Call(0)); |
5554 } | 5557 } |
OLD | NEW |