Index: test/cctest/test-macro-assembler-mips.cc |
diff --git a/test/cctest/test-macro-assembler-mips.cc b/test/cctest/test-macro-assembler-mips.cc |
index 77dc85902292a79c76745c2c20ad9f458e413a83..2ec069884ebe7c05f7e7e37c93dad8f4dbea0fb5 100644 |
--- a/test/cctest/test-macro-assembler-mips.cc |
+++ b/test/cctest/test-macro-assembler-mips.cc |
@@ -389,4 +389,81 @@ TEST(Lsa) { |
} |
} |
+static const std::vector<uint32_t> uint32_test_values() { |
+ static const uint32_t kValues[] = {0x00000000, 0x00000001, 0x00ffff00, |
+ 0x7fffffff, 0x80000000, 0x80000001, |
+ 0x80ffff00, 0x8fffffff, 0xffffffff}; |
+ return std::vector<uint32_t>(&kValues[0], &kValues[arraysize(kValues)]); |
+} |
+ |
+static const std::vector<int32_t> int32_test_values() { |
+ static const int32_t kValues[] = { |
+ static_cast<int32_t>(0x00000000), static_cast<int32_t>(0x00000001), |
+ static_cast<int32_t>(0x00ffff00), static_cast<int32_t>(0x7fffffff), |
+ static_cast<int32_t>(0x80000000), static_cast<int32_t>(0x80000001), |
+ static_cast<int32_t>(0x80ffff00), static_cast<int32_t>(0x8fffffff), |
+ static_cast<int32_t>(0xffffffff)}; |
+ return std::vector<int32_t>(&kValues[0], &kValues[arraysize(kValues)]); |
+} |
+ |
+// Helper macros that can be used in FOR_INT32_INPUTS(i) { ... *i ... } |
+#define FOR_INPUTS(ctype, itype, var) \ |
+ std::vector<ctype> var##_vec = itype##_test_values(); \ |
+ for (std::vector<ctype>::iterator var = var##_vec.begin(); \ |
+ var != var##_vec.end(); ++var) |
+ |
+#define FOR_UINT32_INPUTS(var) FOR_INPUTS(uint32_t, uint32, var) |
+#define FOR_INT32_INPUTS(var) FOR_INPUTS(int32_t, int32, var) |
+ |
+template <typename RET_TYPE, typename IN_TYPE, typename Func> |
+RET_TYPE run_Cvt(IN_TYPE x, Func GenerateConvertInstructionFunc) { |
+ typedef RET_TYPE (*F_CVT)(IN_TYPE x0, int x1, int x2, int x3, int x4); |
+ |
+ Isolate* isolate = CcTest::i_isolate(); |
+ HandleScope scope(isolate); |
+ MacroAssembler assm(isolate, nullptr, 0, |
+ v8::internal::CodeObjectRequired::kYes); |
+ MacroAssembler* masm = &assm; |
+ |
+ __ mtc1(a0, f4); |
+ GenerateConvertInstructionFunc(masm); |
+ __ mfc1(v0, f2); |
+ __ jr(ra); |
+ __ nop(); |
+ |
+ CodeDesc desc; |
+ assm.GetCode(&desc); |
+ Handle<Code> code = isolate->factory()->NewCode( |
+ desc, Code::ComputeFlags(Code::STUB), Handle<Code>()); |
+ |
+ F_CVT f = FUNCTION_CAST<F_CVT>(code->entry()); |
+ |
+ return reinterpret_cast<RET_TYPE>( |
+ CALL_GENERATED_CODE(isolate, f, x, 0, 0, 0, 0)); |
+} |
+ |
+TEST(cvt_s_w_Trunc_uw_s) { |
+ CcTest::InitializeVM(); |
+ FOR_UINT32_INPUTS(i) { |
+ uint32_t input = *i; |
+ CHECK_EQ(static_cast<float>(input), |
+ run_Cvt<uint32_t>(input, [](MacroAssembler* masm) { |
+ __ cvt_s_w(f0, f4); |
+ __ Trunc_uw_s(f2, f0, f1); |
+ })); |
+ } |
+} |
+ |
+TEST(cvt_d_w_Trunc_w_d) { |
+ CcTest::InitializeVM(); |
+ FOR_INT32_INPUTS(i) { |
+ int32_t input = *i; |
+ CHECK_EQ(static_cast<double>(input), |
+ run_Cvt<int32_t>(input, [](MacroAssembler* masm) { |
+ __ cvt_d_w(f0, f4); |
+ __ Trunc_w_d(f2, f0); |
+ })); |
+ } |
+} |
+ |
#undef __ |