OLD | NEW |
1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the 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" |
(...skipping 5369 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
5380 &output, kMachFloat32, | 5380 &output, kMachFloat32, |
5381 m.BitcastInt32ToFloat32(m.LoadFromPointer(&input, kMachInt32))); | 5381 m.BitcastInt32ToFloat32(m.LoadFromPointer(&input, kMachInt32))); |
5382 m.Return(m.Int32Constant(11)); | 5382 m.Return(m.Int32Constant(11)); |
5383 FOR_INT32_INPUTS(i) { | 5383 FOR_INT32_INPUTS(i) { |
5384 input = *i; | 5384 input = *i; |
5385 CHECK_EQ(11, m.Call()); | 5385 CHECK_EQ(11, m.Call()); |
5386 float expected = bit_cast<float>(input); | 5386 float expected = bit_cast<float>(input); |
5387 CHECK_EQ(bit_cast<int32_t>(expected), bit_cast<int32_t>(output)); | 5387 CHECK_EQ(bit_cast<int32_t>(expected), bit_cast<int32_t>(output)); |
5388 } | 5388 } |
5389 } | 5389 } |
| 5390 |
| 5391 |
| 5392 TEST(RunComputedCodeObject) { |
| 5393 RawMachineAssemblerTester<int32_t> a; |
| 5394 a.Return(a.Int32Constant(33)); |
| 5395 CHECK_EQ(33, a.Call()); |
| 5396 |
| 5397 RawMachineAssemblerTester<int32_t> b; |
| 5398 b.Return(b.Int32Constant(44)); |
| 5399 CHECK_EQ(44, b.Call()); |
| 5400 |
| 5401 RawMachineAssemblerTester<int32_t> r(kMachInt32); |
| 5402 RawMachineAssembler::Label tlabel; |
| 5403 RawMachineAssembler::Label flabel; |
| 5404 RawMachineAssembler::Label merge; |
| 5405 r.Branch(r.Parameter(0), &tlabel, &flabel); |
| 5406 r.Bind(&tlabel); |
| 5407 Node* fa = r.HeapConstant(a.code()); |
| 5408 r.Goto(&merge); |
| 5409 r.Bind(&flabel); |
| 5410 Node* fb = r.HeapConstant(b.code()); |
| 5411 r.Goto(&merge); |
| 5412 r.Bind(&merge); |
| 5413 Node* phi = r.Phi(kMachInt32, fa, fb); |
| 5414 |
| 5415 // TODO(titzer): all this descriptor hackery is just to call the above |
| 5416 // functions as code objects instead of direct addresses. |
| 5417 CSignature0<int32_t> sig; |
| 5418 CallDescriptor* c = Linkage::GetSimplifiedCDescriptor(r.zone(), &sig); |
| 5419 LinkageLocation ret[] = {c->GetReturnLocation(0)}; |
| 5420 Signature<LinkageLocation> loc(1, 0, ret); |
| 5421 CallDescriptor* desc = new (r.zone()) CallDescriptor( // -- |
| 5422 CallDescriptor::kCallCodeObject, // kind |
| 5423 kMachAnyTagged, // target_type |
| 5424 c->GetInputLocation(0), // target_loc |
| 5425 &sig, // machine_sig |
| 5426 &loc, // location_sig |
| 5427 0, // stack count |
| 5428 Operator::kNoProperties, // properties |
| 5429 c->CalleeSavedRegisters(), // callee saved |
| 5430 c->CalleeSavedFPRegisters(), // callee saved FP |
| 5431 CallDescriptor::kNoFlags, // flags |
| 5432 "c-call-as-code"); |
| 5433 Node* call = r.AddNode(r.common()->Call(desc), phi); |
| 5434 r.Return(call); |
| 5435 |
| 5436 CHECK_EQ(33, r.Call(1)); |
| 5437 CHECK_EQ(44, r.Call(0)); |
| 5438 } |
OLD | NEW |