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 5120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
5131 m.Float64RoundTiesAway(m.LoadFromPointer(&input, kMachFloat64))); | 5131 m.Float64RoundTiesAway(m.LoadFromPointer(&input, kMachFloat64))); |
5132 m.Return(m.Int32Constant(0)); | 5132 m.Return(m.Int32Constant(0)); |
5133 for (size_t i = 0; i < arraysize(kValues); ++i) { | 5133 for (size_t i = 0; i < arraysize(kValues); ++i) { |
5134 input = kValues[i]; | 5134 input = kValues[i]; |
5135 CHECK_EQ(0, m.Call()); | 5135 CHECK_EQ(0, m.Call()); |
5136 double expected = round(kValues[i]); | 5136 double expected = round(kValues[i]); |
5137 CHECK_EQ(expected, result); | 5137 CHECK_EQ(expected, result); |
5138 } | 5138 } |
5139 } | 5139 } |
5140 | 5140 |
5141 | |
5142 #if !USE_SIMULATOR | |
5143 | |
5144 namespace { | |
5145 | |
5146 int32_t const kMagicFoo0 = 0xdeadbeef; | |
5147 | |
5148 | |
5149 int32_t foo0() { return kMagicFoo0; } | |
5150 | |
5151 | |
5152 int32_t foo1(int32_t x) { return x; } | |
5153 | |
5154 | |
5155 int32_t foo2(int32_t x, int32_t y) { return x - y; } | |
5156 | |
5157 | |
5158 int32_t foo8(int32_t a, int32_t b, int32_t c, int32_t d, int32_t e, int32_t f, | |
5159 int32_t g, int32_t h) { | |
5160 return a + b + c + d + e + f + g + h; | |
Sven Panne
2015/06/25 08:35:09
Using a non-commutative and non-associative operat
| |
5161 } | |
5162 | |
5163 } // namespace | |
5164 | |
5165 | |
5166 TEST(RunCallCFunction0) { | |
5167 auto* foo0_ptr = &foo0; | |
5168 RawMachineAssemblerTester<int32_t> m; | |
5169 Node* function = m.LoadFromPointer(&foo0_ptr, kMachPtr); | |
5170 m.Return(m.CallCFunction0(kMachInt32, function)); | |
5171 CHECK_EQ(kMagicFoo0, m.Call()); | |
5172 } | |
5173 | |
5174 | |
5175 TEST(RunCallCFunction1) { | |
5176 auto* foo1_ptr = &foo1; | |
5177 RawMachineAssemblerTester<int32_t> m(kMachInt32); | |
5178 Node* function = m.LoadFromPointer(&foo1_ptr, kMachPtr); | |
5179 m.Return(m.CallCFunction1(kMachInt32, kMachInt32, function, m.Parameter(0))); | |
5180 FOR_INT32_INPUTS(i) { | |
5181 int32_t const expected = *i; | |
5182 CHECK_EQ(expected, m.Call(expected)); | |
5183 } | |
5184 } | |
5185 | |
5186 | |
5187 TEST(RunCallCFunction2) { | |
5188 auto* foo2_ptr = &foo2; | |
5189 RawMachineAssemblerTester<int32_t> m(kMachInt32, kMachInt32); | |
5190 Node* function = m.LoadFromPointer(&foo2_ptr, kMachPtr); | |
5191 m.Return(m.CallCFunction2(kMachInt32, kMachInt32, kMachInt32, function, | |
5192 m.Parameter(0), m.Parameter(1))); | |
5193 FOR_INT32_INPUTS(i) { | |
5194 int32_t const x = *i; | |
5195 FOR_INT32_INPUTS(j) { | |
5196 int32_t const y = *j; | |
5197 CHECK_EQ(x - y, m.Call(x, y)); | |
5198 } | |
5199 } | |
5200 } | |
5201 | |
5202 | |
5203 TEST(RunCallCFunction8) { | |
5204 auto* foo8_ptr = &foo8; | |
5205 RawMachineAssemblerTester<int32_t> m(kMachInt32); | |
5206 Node* function = m.LoadFromPointer(&foo8_ptr, kMachPtr); | |
5207 Node* param = m.Parameter(0); | |
5208 m.Return(m.CallCFunction8(kMachInt32, kMachInt32, kMachInt32, kMachInt32, | |
5209 kMachInt32, kMachInt32, kMachInt32, kMachInt32, | |
5210 kMachInt32, function, param, param, param, param, | |
Sven Panne
2015/06/25 08:35:09
Using the same actual parameter for all formal par
| |
5211 param, param, param, param)); | |
5212 FOR_INT32_INPUTS(i) { | |
5213 int32_t const x = *i; | |
5214 CHECK_EQ(x * 8, m.Call(x)); | |
5215 } | |
5216 } | |
5217 | |
5218 #endif // USE_SIMULATOR | |
5219 | |
5141 #endif // V8_TURBOFAN_TARGET | 5220 #endif // V8_TURBOFAN_TARGET |
OLD | NEW |