code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F2 f = FUNCTION_CAST(code->entry()); int64_t res = reinterpret_cast( CALL_GENERATED_CODE(isolate, f, 0xab0, 0xc, 0, 0, 0)); CHECK_EQ(0xabcL, res); } TEST(MIPS1) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); Label L, C; __ mov(a1, a0); __ li(v0, 0); __ b(&C); __ nop(); __ bind(&L); __ addu(v0, v0, a1); __ addiu(a1, a1, -1); __ bind(&C); __ xori(v1, a1, 0); __ Branch(&L, ne, v1, Operand((int64_t)0)); __ nop(); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F1 f = FUNCTION_CAST(code->entry()); int64_t res = reinterpret_cast( CALL_GENERATED_CODE(isolate, f, 50, 0, 0, 0, 0)); CHECK_EQ(1275L, res); } TEST(MIPS2) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); Label exit, error; // ----- Test all instructions. // Test lui, ori, and addiu, used in the li pseudo-instruction. // This way we can then safely load registers with chosen values. __ ori(a4, zero_reg, 0); __ lui(a4, 0x1234); __ ori(a4, a4, 0); __ ori(a4, a4, 0x0f0f); __ ori(a4, a4, 0xf0f0); __ addiu(a5, a4, 1); __ addiu(a6, a5, -0x10); // Load values in temporary registers. __ li(a4, 0x00000004); __ li(a5, 0x00001234); __ li(a6, 0x12345678); __ li(a7, 0x7fffffff); __ li(t0, 0xfffffffc); __ li(t1, 0xffffedcc); __ li(t2, 0xedcba988); __ li(t3, 0x80000000); // SPECIAL class. __ srl(v0, a6, 8); // 0x00123456 __ sll(v0, v0, 11); // 0x91a2b000 __ sra(v0, v0, 3); // 0xf2345600 __ srav(v0, v0, a4); // 0xff234560 __ sllv(v0, v0, a4); // 0xf2345600 __ srlv(v0, v0, a4); // 0x0f234560 __ Branch(&error, ne, v0, Operand(0x0f234560)); __ nop(); __ addu(v0, a4, a5); // 0x00001238 __ subu(v0, v0, a4); // 0x00001234 __ Branch(&error, ne, v0, Operand(0x00001234)); __ nop(); __ addu(v1, a7, a4); // 32bit addu result is sign-extended into 64bit reg. __ Branch(&error, ne, v1, Operand(0xffffffff80000003)); __ nop(); __ subu(v1, t3, a4); // 0x7ffffffc __ Branch(&error, ne, v1, Operand(0x7ffffffc)); __ nop(); __ and_(v0, a5, a6); // 0x0000000000001230 __ or_(v0, v0, a5); // 0x0000000000001234 __ xor_(v0, v0, a6); // 0x000000001234444c __ nor(v0, v0, a6); // 0xffffffffedcba987 __ Branch(&error, ne, v0, Operand(0xffffffffedcba983)); __ nop(); // Shift both 32bit number to left, to preserve meaning of next comparison. __ dsll32(a7, a7, 0); __ dsll32(t3, t3, 0); __ slt(v0, t3, a7); __ Branch(&error, ne, v0, Operand(0x1)); __ nop(); __ sltu(v0, t3, a7); __ Branch(&error, ne, v0, Operand(zero_reg)); __ nop(); // Restore original values in registers. __ dsrl32(a7, a7, 0); __ dsrl32(t3, t3, 0); // End of SPECIAL class. __ addiu(v0, zero_reg, 0x7421); // 0x00007421 __ addiu(v0, v0, -0x1); // 0x00007420 __ addiu(v0, v0, -0x20); // 0x00007400 __ Branch(&error, ne, v0, Operand(0x00007400)); __ nop(); __ addiu(v1, a7, 0x1); // 0x80000000 - result is sign-extended. __ Branch(&error, ne, v1, Operand(0xffffffff80000000)); __ nop(); __ slti(v0, a5, 0x00002000); // 0x1 __ slti(v0, v0, 0xffff8000); // 0x0 __ Branch(&error, ne, v0, Operand(zero_reg)); __ nop(); __ sltiu(v0, a5, 0x00002000); // 0x1 __ sltiu(v0, v0, 0x00008000); // 0x1 __ Branch(&error, ne, v0, Operand(0x1)); __ nop(); __ andi(v0, a5, 0xf0f0); // 0x00001030 __ ori(v0, v0, 0x8a00); // 0x00009a30 __ xori(v0, v0, 0x83cc); // 0x000019fc __ Branch(&error, ne, v0, Operand(0x000019fc)); __ nop(); __ lui(v1, 0x8123); // Result is sign-extended into 64bit register. __ Branch(&error, ne, v1, Operand(0xffffffff81230000)); __ nop(); // Bit twiddling instructions & conditional moves. // Uses a4-t3 as set above. __ Clz(v0, a4); // 29 __ Clz(v1, a5); // 19 __ addu(v0, v0, v1); // 48 __ Clz(v1, a6); // 3 __ addu(v0, v0, v1); // 51 __ Clz(v1, t3); // 0 __ addu(v0, v0, v1); // 51 __ Branch(&error, ne, v0, Operand(51)); __ Movn(a0, a7, a4); // Move a0<-a7 (a4 is NOT 0). __ Ins(a0, a5, 12, 8); // 0x7ff34fff __ Branch(&error, ne, a0, Operand(0x7ff34fff)); __ Movz(a0, t2, t3); // a0 not updated (t3 is NOT 0). __ Ext(a1, a0, 8, 12); // 0x34f __ Branch(&error, ne, a1, Operand(0x34f)); __ Movz(a0, t2, v1); // a0<-t2, v0 is 0, from 8 instr back. __ Branch(&error, ne, a0, Operand(t2)); // Everything was correctly executed. Load the expected result. __ li(v0, 0x31415926); __ b(&exit); __ nop(); __ bind(&error); // Got an error. Return a wrong result. __ li(v0, 666); __ bind(&exit); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F2 f = FUNCTION_CAST(code->entry()); int64_t res = reinterpret_cast( CALL_GENERATED_CODE(isolate, f, 0xab0, 0xc, 0, 0, 0)); CHECK_EQ(0x31415926L, res); } TEST(MIPS3) { // Test floating point instructions. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double a; double b; double c; double d; double e; double f; double g; double h; double i; float fa; float fb; float fc; float fd; float fe; float ff; float fg; } T; T t; // Create a function that accepts &t, and loads, manipulates, and stores // the doubles t.a ... t.f. MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); Label L, C; // Double precision floating point instructions. __ ldc1(f4, MemOperand(a0, offsetof(T, a)) ); __ ldc1(f6, MemOperand(a0, offsetof(T, b)) ); __ add_d(f8, f4, f6); __ sdc1(f8, MemOperand(a0, offsetof(T, c)) ); // c = a + b. __ mov_d(f10, f8); // c __ neg_d(f12, f6); // -b __ sub_d(f10, f10, f12); __ sdc1(f10, MemOperand(a0, offsetof(T, d)) ); // d = c - (-b). __ sdc1(f4, MemOperand(a0, offsetof(T, b)) ); // b = a. __ li(a4, 120); __ mtc1(a4, f14); __ cvt_d_w(f14, f14); // f14 = 120.0. __ mul_d(f10, f10, f14); __ sdc1(f10, MemOperand(a0, offsetof(T, e)) ); // e = d * 120 = 1.8066e16. __ div_d(f12, f10, f4); __ sdc1(f12, MemOperand(a0, offsetof(T, f)) ); // f = e / a = 120.44. __ sqrt_d(f14, f12); __ sdc1(f14, MemOperand(a0, offsetof(T, g)) ); // g = sqrt(f) = 10.97451593465515908537 if (kArchVariant == kMips64r2) { __ ldc1(f4, MemOperand(a0, offsetof(T, h)) ); __ ldc1(f6, MemOperand(a0, offsetof(T, i)) ); __ madd_d(f14, f6, f4, f6); __ sdc1(f14, MemOperand(a0, offsetof(T, h)) ); } // Single precision floating point instructions. __ lwc1(f4, MemOperand(a0, offsetof(T, fa)) ); __ lwc1(f6, MemOperand(a0, offsetof(T, fb)) ); __ add_s(f8, f4, f6); __ swc1(f8, MemOperand(a0, offsetof(T, fc)) ); // fc = fa + fb. __ neg_s(f10, f6); // -fb __ sub_s(f10, f8, f10); __ swc1(f10, MemOperand(a0, offsetof(T, fd)) ); // fd = fc - (-fb). __ swc1(f4, MemOperand(a0, offsetof(T, fb)) ); // fb = fa. __ li(t0, 120); __ mtc1(t0, f14); __ cvt_s_w(f14, f14); // f14 = 120.0. __ mul_s(f10, f10, f14); __ swc1(f10, MemOperand(a0, offsetof(T, fe)) ); // fe = fd * 120 __ div_s(f12, f10, f4); __ swc1(f12, MemOperand(a0, offsetof(T, ff)) ); // ff = fe / fa __ sqrt_s(f14, f12); __ swc1(f14, MemOperand(a0, offsetof(T, fg)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); // Double test values. t.a = 1.5e14; t.b = 2.75e11; t.c = 0.0; t.d = 0.0; t.e = 0.0; t.f = 0.0; t.h = 1.5; t.i = 2.75; // Single test values. t.fa = 1.5e6; t.fb = 2.75e4; t.fc = 0.0; t.fd = 0.0; t.fe = 0.0; t.ff = 0.0; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); // Expected double results. CHECK_EQ(1.5e14, t.a); CHECK_EQ(1.5e14, t.b); CHECK_EQ(1.50275e14, t.c); CHECK_EQ(1.50550e14, t.d); CHECK_EQ(1.8066e16, t.e); CHECK_EQ(120.44, t.f); CHECK_EQ(10.97451593465515908537, t.g); if (kArchVariant == kMips64r2) { CHECK_EQ(6.875, t.h); } // Expected single results. CHECK_EQ(1.5e6, t.fa); CHECK_EQ(1.5e6, t.fb); CHECK_EQ(1.5275e06, t.fc); CHECK_EQ(1.5550e06, t.fd); CHECK_EQ(1.866e08, t.fe); CHECK_EQ(124.40000152587890625, t.ff); CHECK_EQ(11.1534748077392578125, t.fg); } TEST(MIPS4) { // Test moves between floating point and integer registers. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double a; double b; double c; double d; int64_t high; int64_t low; } T; T t; Assembler assm(isolate, NULL, 0); Label L, C; __ ldc1(f4, MemOperand(a0, offsetof(T, a))); __ ldc1(f5, MemOperand(a0, offsetof(T, b))); // Swap f4 and f5, by using 3 integer registers, a4-a6, // both two 32-bit chunks, and one 64-bit chunk. // mXhc1 is mips32/64-r2 only, not r1, // but we will not support r1 in practice. __ mfc1(a4, f4); __ mfhc1(a5, f4); __ dmfc1(a6, f5); __ mtc1(a4, f5); __ mthc1(a5, f5); __ dmtc1(a6, f4); // Store the swapped f4 and f5 back to memory. __ sdc1(f4, MemOperand(a0, offsetof(T, a))); __ sdc1(f5, MemOperand(a0, offsetof(T, c))); // Test sign extension of move operations from coprocessor. __ ldc1(f4, MemOperand(a0, offsetof(T, d))); __ mfhc1(a4, f4); __ mfc1(a5, f4); __ sd(a4, MemOperand(a0, offsetof(T, high))); __ sd(a5, MemOperand(a0, offsetof(T, low))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.a = 1.5e22; t.b = 2.75e11; t.c = 17.17; t.d = -2.75e11; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(2.75e11, t.a); CHECK_EQ(2.75e11, t.b); CHECK_EQ(1.5e22, t.c); CHECK_EQ(static_cast(0xffffffffc25001d1L), t.high); CHECK_EQ(static_cast(0xffffffffbf800000L), t.low); } TEST(MIPS5) { // Test conversions between doubles and integers. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double a; double b; int i; int j; } T; T t; Assembler assm(isolate, NULL, 0); Label L, C; // Load all structure elements to registers. __ ldc1(f4, MemOperand(a0, offsetof(T, a)) ); __ ldc1(f6, MemOperand(a0, offsetof(T, b)) ); __ lw(a4, MemOperand(a0, offsetof(T, i)) ); __ lw(a5, MemOperand(a0, offsetof(T, j)) ); // Convert double in f4 to int in element i. __ cvt_w_d(f8, f4); __ mfc1(a6, f8); __ sw(a6, MemOperand(a0, offsetof(T, i)) ); // Convert double in f6 to int in element j. __ cvt_w_d(f10, f6); __ mfc1(a7, f10); __ sw(a7, MemOperand(a0, offsetof(T, j)) ); // Convert int in original i (a4) to double in a. __ mtc1(a4, f12); __ cvt_d_w(f0, f12); __ sdc1(f0, MemOperand(a0, offsetof(T, a)) ); // Convert int in original j (a5) to double in b. __ mtc1(a5, f14); __ cvt_d_w(f2, f14); __ sdc1(f2, MemOperand(a0, offsetof(T, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.a = 1.5e4; t.b = 2.75e8; t.i = 12345678; t.j = -100000; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(12345678.0, t.a); CHECK_EQ(-100000.0, t.b); CHECK_EQ(15000, t.i); CHECK_EQ(275000000, t.j); } TEST(MIPS6) { // Test simple memory loads and stores. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { uint32_t ui; int32_t si; int32_t r1; int32_t r2; int32_t r3; int32_t r4; int32_t r5; int32_t r6; } T; T t; Assembler assm(isolate, NULL, 0); Label L, C; // Basic word load/store. __ lw(a4, MemOperand(a0, offsetof(T, ui)) ); __ sw(a4, MemOperand(a0, offsetof(T, r1)) ); // lh with positive data. __ lh(a5, MemOperand(a0, offsetof(T, ui)) ); __ sw(a5, MemOperand(a0, offsetof(T, r2)) ); // lh with negative data. __ lh(a6, MemOperand(a0, offsetof(T, si)) ); __ sw(a6, MemOperand(a0, offsetof(T, r3)) ); // lhu with negative data. __ lhu(a7, MemOperand(a0, offsetof(T, si)) ); __ sw(a7, MemOperand(a0, offsetof(T, r4)) ); // lb with negative data. __ lb(t0, MemOperand(a0, offsetof(T, si)) ); __ sw(t0, MemOperand(a0, offsetof(T, r5)) ); // sh writes only 1/2 of word. __ lui(t1, 0x3333); __ ori(t1, t1, 0x3333); __ sw(t1, MemOperand(a0, offsetof(T, r6)) ); __ lhu(t1, MemOperand(a0, offsetof(T, si)) ); __ sh(t1, MemOperand(a0, offsetof(T, r6)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.ui = 0x11223344; t.si = 0x99aabbcc; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(static_cast(0x11223344), t.r1); if (kArchEndian == kLittle) { CHECK_EQ(static_cast(0x3344), t.r2); CHECK_EQ(static_cast(0xffffbbcc), t.r3); CHECK_EQ(static_cast(0x0000bbcc), t.r4); CHECK_EQ(static_cast(0xffffffcc), t.r5); CHECK_EQ(static_cast(0x3333bbcc), t.r6); } else { CHECK_EQ(static_cast(0x1122), t.r2); CHECK_EQ(static_cast(0xffff99aa), t.r3); CHECK_EQ(static_cast(0x000099aa), t.r4); CHECK_EQ(static_cast(0xffffff99), t.r5); CHECK_EQ(static_cast(0x99aa3333), t.r6); } } TEST(MIPS7) { // Test floating point compare and branch instructions. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double a; double b; double c; double d; double e; double f; int32_t result; } T; T t; // Create a function that accepts &t, and loads, manipulates, and stores // the doubles t.a ... t.f. MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); Label neither_is_nan, less_than, outa_here; __ ldc1(f4, MemOperand(a0, offsetof(T, a)) ); __ ldc1(f6, MemOperand(a0, offsetof(T, b)) ); if (kArchVariant != kMips64r6) { __ c(UN, D, f4, f6); __ bc1f(&neither_is_nan); } else { __ cmp(UN, L, f2, f4, f6); __ bc1eqz(&neither_is_nan, f2); } __ nop(); __ sw(zero_reg, MemOperand(a0, offsetof(T, result)) ); __ Branch(&outa_here); __ bind(&neither_is_nan); if (kArchVariant == kMips64r6) { __ cmp(OLT, L, f2, f6, f4); __ bc1nez(&less_than, f2); } else { __ c(OLT, D, f6, f4, 2); __ bc1t(&less_than, 2); } __ nop(); __ sw(zero_reg, MemOperand(a0, offsetof(T, result)) ); __ Branch(&outa_here); __ bind(&less_than); __ Addu(a4, zero_reg, Operand(1)); __ sw(a4, MemOperand(a0, offsetof(T, result)) ); // Set true. // This test-case should have additional tests. __ bind(&outa_here); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.a = 1.5e14; t.b = 2.75e11; t.c = 2.0; t.d = -4.0; t.e = 0.0; t.f = 0.0; t.result = 0; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(1.5e14, t.a); CHECK_EQ(2.75e11, t.b); CHECK_EQ(1, t.result); } TEST(MIPS8) { if (kArchVariant == kMips64r2) { // Test ROTR and ROTRV instructions. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { int32_t input; int32_t result_rotr_4; int32_t result_rotr_8; int32_t result_rotr_12; int32_t result_rotr_16; int32_t result_rotr_20; int32_t result_rotr_24; int32_t result_rotr_28; int32_t result_rotrv_4; int32_t result_rotrv_8; int32_t result_rotrv_12; int32_t result_rotrv_16; int32_t result_rotrv_20; int32_t result_rotrv_24; int32_t result_rotrv_28; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); // Basic word load. __ lw(a4, MemOperand(a0, offsetof(T, input)) ); // ROTR instruction (called through the Ror macro). __ Ror(a5, a4, 0x0004); __ Ror(a6, a4, 0x0008); __ Ror(a7, a4, 0x000c); __ Ror(t0, a4, 0x0010); __ Ror(t1, a4, 0x0014); __ Ror(t2, a4, 0x0018); __ Ror(t3, a4, 0x001c); // Basic word store. __ sw(a5, MemOperand(a0, offsetof(T, result_rotr_4)) ); __ sw(a6, MemOperand(a0, offsetof(T, result_rotr_8)) ); __ sw(a7, MemOperand(a0, offsetof(T, result_rotr_12)) ); __ sw(t0, MemOperand(a0, offsetof(T, result_rotr_16)) ); __ sw(t1, MemOperand(a0, offsetof(T, result_rotr_20)) ); __ sw(t2, MemOperand(a0, offsetof(T, result_rotr_24)) ); __ sw(t3, MemOperand(a0, offsetof(T, result_rotr_28)) ); // ROTRV instruction (called through the Ror macro). __ li(t3, 0x0004); __ Ror(a5, a4, t3); __ li(t3, 0x0008); __ Ror(a6, a4, t3); __ li(t3, 0x000C); __ Ror(a7, a4, t3); __ li(t3, 0x0010); __ Ror(t0, a4, t3); __ li(t3, 0x0014); __ Ror(t1, a4, t3); __ li(t3, 0x0018); __ Ror(t2, a4, t3); __ li(t3, 0x001C); __ Ror(t3, a4, t3); // Basic word store. __ sw(a5, MemOperand(a0, offsetof(T, result_rotrv_4)) ); __ sw(a6, MemOperand(a0, offsetof(T, result_rotrv_8)) ); __ sw(a7, MemOperand(a0, offsetof(T, result_rotrv_12)) ); __ sw(t0, MemOperand(a0, offsetof(T, result_rotrv_16)) ); __ sw(t1, MemOperand(a0, offsetof(T, result_rotrv_20)) ); __ sw(t2, MemOperand(a0, offsetof(T, result_rotrv_24)) ); __ sw(t3, MemOperand(a0, offsetof(T, result_rotrv_28)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.input = 0x12345678; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0x0, 0, 0, 0); USE(dummy); CHECK_EQ(static_cast(0x81234567), t.result_rotr_4); CHECK_EQ(static_cast(0x78123456), t.result_rotr_8); CHECK_EQ(static_cast(0x67812345), t.result_rotr_12); CHECK_EQ(static_cast(0x56781234), t.result_rotr_16); CHECK_EQ(static_cast(0x45678123), t.result_rotr_20); CHECK_EQ(static_cast(0x34567812), t.result_rotr_24); CHECK_EQ(static_cast(0x23456781), t.result_rotr_28); CHECK_EQ(static_cast(0x81234567), t.result_rotrv_4); CHECK_EQ(static_cast(0x78123456), t.result_rotrv_8); CHECK_EQ(static_cast(0x67812345), t.result_rotrv_12); CHECK_EQ(static_cast(0x56781234), t.result_rotrv_16); CHECK_EQ(static_cast(0x45678123), t.result_rotrv_20); CHECK_EQ(static_cast(0x34567812), t.result_rotrv_24); CHECK_EQ(static_cast(0x23456781), t.result_rotrv_28); } } TEST(MIPS9) { // Test BRANCH improvements. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); Label exit, exit2, exit3; __ Branch(&exit, ge, a0, Operand(zero_reg)); __ Branch(&exit2, ge, a0, Operand(0x00001FFF)); __ Branch(&exit3, ge, a0, Operand(0x0001FFFF)); __ bind(&exit); __ bind(&exit2); __ bind(&exit3); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); } TEST(MIPS10) { // Test conversions between doubles and long integers. // Test hos the long ints map to FP regs pairs. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double a; double a_converted; double b; int32_t dbl_mant; int32_t dbl_exp; int32_t long_hi; int32_t long_lo; int64_t long_as_int64; int32_t b_long_hi; int32_t b_long_lo; int64_t b_long_as_int64; } T; T t; Assembler assm(isolate, NULL, 0); Label L, C; if (kArchVariant == kMips64r2) { // Rewritten for FR=1 FPU mode: // - 32 FP regs of 64-bits each, no odd/even pairs. // - Note that cvt_l_d/cvt_d_l ARE legal in FR=1 mode. // Load all structure elements to registers. __ ldc1(f0, MemOperand(a0, offsetof(T, a))); // Save the raw bits of the double. __ mfc1(a4, f0); __ mfhc1(a5, f0); __ sw(a4, MemOperand(a0, offsetof(T, dbl_mant))); __ sw(a5, MemOperand(a0, offsetof(T, dbl_exp))); // Convert double in f0 to long, save hi/lo parts. __ cvt_l_d(f0, f0); __ mfc1(a4, f0); // f0 LS 32 bits of long. __ mfhc1(a5, f0); // f0 MS 32 bits of long. __ sw(a4, MemOperand(a0, offsetof(T, long_lo))); __ sw(a5, MemOperand(a0, offsetof(T, long_hi))); // Combine the high/low ints, convert back to double. __ dsll32(a6, a5, 0); // Move a5 to high bits of a6. __ or_(a6, a6, a4); __ dmtc1(a6, f1); __ cvt_d_l(f1, f1); __ sdc1(f1, MemOperand(a0, offsetof(T, a_converted))); // Convert the b long integers to double b. __ lw(a4, MemOperand(a0, offsetof(T, b_long_lo))); __ lw(a5, MemOperand(a0, offsetof(T, b_long_hi))); __ mtc1(a4, f8); // f8 LS 32-bits. __ mthc1(a5, f8); // f8 MS 32-bits. __ cvt_d_l(f10, f8); __ sdc1(f10, MemOperand(a0, offsetof(T, b))); // Convert double b back to long-int. __ ldc1(f31, MemOperand(a0, offsetof(T, b))); __ cvt_l_d(f31, f31); __ dmfc1(a7, f31); __ sd(a7, MemOperand(a0, offsetof(T, b_long_as_int64))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.a = 2.147483647e9; // 0x7fffffff -> 0x41DFFFFFFFC00000 as double. t.b_long_hi = 0x000000ff; // 0xFF00FF00FF -> 0x426FE01FE01FE000 as double. t.b_long_lo = 0x00ff00ff; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(static_cast(0x41DFFFFF), t.dbl_exp); CHECK_EQ(static_cast(0xFFC00000), t.dbl_mant); CHECK_EQ(0, t.long_hi); CHECK_EQ(static_cast(0x7fffffff), t.long_lo); CHECK_EQ(2.147483647e9, t.a_converted); // 0xFF00FF00FF -> 1.095233372415e12. CHECK_EQ(1.095233372415e12, t.b); CHECK_EQ(static_cast(0xFF00FF00FF), t.b_long_as_int64); } } TEST(MIPS11) { // Do not run test on MIPS64r6, as these instructions are removed. if (kArchVariant != kMips64r6) { // Test LWL, LWR, SWL and SWR instructions. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { int32_t reg_init; int32_t mem_init; int32_t lwl_0; int32_t lwl_1; int32_t lwl_2; int32_t lwl_3; int32_t lwr_0; int32_t lwr_1; int32_t lwr_2; int32_t lwr_3; int32_t swl_0; int32_t swl_1; int32_t swl_2; int32_t swl_3; int32_t swr_0; int32_t swr_1; int32_t swr_2; int32_t swr_3; } T; T t; Assembler assm(isolate, NULL, 0); // Test all combinations of LWL and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, lwl_0))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a5, MemOperand(a0, offsetof(T, mem_init) + 1)); __ sw(a5, MemOperand(a0, offsetof(T, lwl_1))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a6, MemOperand(a0, offsetof(T, mem_init) + 2)); __ sw(a6, MemOperand(a0, offsetof(T, lwl_2))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a7, MemOperand(a0, offsetof(T, mem_init) + 3)); __ sw(a7, MemOperand(a0, offsetof(T, lwl_3))); // Test all combinations of LWR and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, lwr_0))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a5, MemOperand(a0, offsetof(T, mem_init) + 1)); __ sw(a5, MemOperand(a0, offsetof(T, lwr_1))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a6, MemOperand(a0, offsetof(T, mem_init) + 2)); __ sw(a6, MemOperand(a0, offsetof(T, lwr_2)) ); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a7, MemOperand(a0, offsetof(T, mem_init) + 3)); __ sw(a7, MemOperand(a0, offsetof(T, lwr_3)) ); // Test all combinations of SWL and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, swl_0))); __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ swl(a4, MemOperand(a0, offsetof(T, swl_0))); __ lw(a5, MemOperand(a0, offsetof(T, mem_init))); __ sw(a5, MemOperand(a0, offsetof(T, swl_1))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ swl(a5, MemOperand(a0, offsetof(T, swl_1) + 1)); __ lw(a6, MemOperand(a0, offsetof(T, mem_init))); __ sw(a6, MemOperand(a0, offsetof(T, swl_2))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ swl(a6, MemOperand(a0, offsetof(T, swl_2) + 2)); __ lw(a7, MemOperand(a0, offsetof(T, mem_init))); __ sw(a7, MemOperand(a0, offsetof(T, swl_3))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ swl(a7, MemOperand(a0, offsetof(T, swl_3) + 3)); // Test all combinations of SWR and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, swr_0))); __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ swr(a4, MemOperand(a0, offsetof(T, swr_0))); __ lw(a5, MemOperand(a0, offsetof(T, mem_init))); __ sw(a5, MemOperand(a0, offsetof(T, swr_1))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ swr(a5, MemOperand(a0, offsetof(T, swr_1) + 1)); __ lw(a6, MemOperand(a0, offsetof(T, mem_init))); __ sw(a6, MemOperand(a0, offsetof(T, swr_2))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ swr(a6, MemOperand(a0, offsetof(T, swr_2) + 2)); __ lw(a7, MemOperand(a0, offsetof(T, mem_init))); __ sw(a7, MemOperand(a0, offsetof(T, swr_3))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ swr(a7, MemOperand(a0, offsetof(T, swr_3) + 3)); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.reg_init = 0xaabbccdd; t.mem_init = 0x11223344; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); if (kArchEndian == kLittle) { CHECK_EQ(static_cast(0x44bbccdd), t.lwl_0); CHECK_EQ(static_cast(0x3344ccdd), t.lwl_1); CHECK_EQ(static_cast(0x223344dd), t.lwl_2); CHECK_EQ(static_cast(0x11223344), t.lwl_3); CHECK_EQ(static_cast(0x11223344), t.lwr_0); CHECK_EQ(static_cast(0xaa112233), t.lwr_1); CHECK_EQ(static_cast(0xaabb1122), t.lwr_2); CHECK_EQ(static_cast(0xaabbcc11), t.lwr_3); CHECK_EQ(static_cast(0x112233aa), t.swl_0); CHECK_EQ(static_cast(0x1122aabb), t.swl_1); CHECK_EQ(static_cast(0x11aabbcc), t.swl_2); CHECK_EQ(static_cast(0xaabbccdd), t.swl_3); CHECK_EQ(static_cast(0xaabbccdd), t.swr_0); CHECK_EQ(static_cast(0xbbccdd44), t.swr_1); CHECK_EQ(static_cast(0xccdd3344), t.swr_2); CHECK_EQ(static_cast(0xdd223344), t.swr_3); } else { CHECK_EQ(static_cast(0x11223344), t.lwl_0); CHECK_EQ(static_cast(0x223344dd), t.lwl_1); CHECK_EQ(static_cast(0x3344ccdd), t.lwl_2); CHECK_EQ(static_cast(0x44bbccdd), t.lwl_3); CHECK_EQ(static_cast(0xaabbcc11), t.lwr_0); CHECK_EQ(static_cast(0xaabb1122), t.lwr_1); CHECK_EQ(static_cast(0xaa112233), t.lwr_2); CHECK_EQ(static_cast(0x11223344), t.lwr_3); CHECK_EQ(static_cast(0xaabbccdd), t.swl_0); CHECK_EQ(static_cast(0x11aabbcc), t.swl_1); CHECK_EQ(static_cast(0x1122aabb), t.swl_2); CHECK_EQ(static_cast(0x112233aa), t.swl_3); CHECK_EQ(static_cast(0xdd223344), t.swr_0); CHECK_EQ(static_cast(0xccdd3344), t.swr_1); CHECK_EQ(static_cast(0xbbccdd44), t.swr_2); CHECK_EQ(static_cast(0xaabbccdd), t.swr_3); } } } TEST(MIPS12) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { int32_t x; int32_t y; int32_t y1; int32_t y2; int32_t y3; int32_t y4; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ mov(t2, fp); // Save frame pointer. __ mov(fp, a0); // Access struct T by fp. __ lw(a4, MemOperand(a0, offsetof(T, y))); __ lw(a7, MemOperand(a0, offsetof(T, y4))); __ addu(a5, a4, a7); __ subu(t0, a4, a7); __ nop(); __ push(a4); // These instructions disappear after opt. __ Pop(); __ addu(a4, a4, a4); __ nop(); __ Pop(); // These instructions disappear after opt. __ push(a7); __ nop(); __ push(a7); // These instructions disappear after opt. __ pop(a7); __ nop(); __ push(a7); __ pop(t0); __ nop(); __ sw(a4, MemOperand(fp, offsetof(T, y))); __ lw(a4, MemOperand(fp, offsetof(T, y))); __ nop(); __ sw(a4, MemOperand(fp, offsetof(T, y))); __ lw(a5, MemOperand(fp, offsetof(T, y))); __ nop(); __ push(a5); __ lw(a5, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a6); __ nop(); __ push(a6); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a7); __ nop(); __ mov(fp, t2); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.x = 1; t.y = 2; t.y1 = 3; t.y2 = 4; t.y3 = 0XBABA; t.y4 = 0xDEDA; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(3, t.y1); } TEST(MIPS13) { // Test Cvt_d_uw and Trunc_uw_d macros. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double cvt_big_out; double cvt_small_out; uint32_t trunc_big_out; uint32_t trunc_small_out; uint32_t cvt_big_in; uint32_t cvt_small_in; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ sw(a4, MemOperand(a0, offsetof(T, cvt_small_in))); __ Cvt_d_uw(f10, a4); __ sdc1(f10, MemOperand(a0, offsetof(T, cvt_small_out))); __ Trunc_uw_d(f10, f10, f4); __ swc1(f10, MemOperand(a0, offsetof(T, trunc_small_out))); __ sw(a4, MemOperand(a0, offsetof(T, cvt_big_in))); __ Cvt_d_uw(f8, a4); __ sdc1(f8, MemOperand(a0, offsetof(T, cvt_big_out))); __ Trunc_uw_d(f8, f8, f4); __ swc1(f8, MemOperand(a0, offsetof(T, trunc_big_out))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.cvt_big_in = 0xFFFFFFFF; t.cvt_small_in = 333; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(t.cvt_big_out, static_cast(t.cvt_big_in)); CHECK_EQ(t.cvt_small_out, static_cast(t.cvt_small_in)); CHECK_EQ(static_cast(t.trunc_big_out), static_cast(t.cvt_big_in)); CHECK_EQ(static_cast(t.trunc_small_out), static_cast(t.cvt_small_in)); } TEST(MIPS14) { // Test round, floor, ceil, trunc, cvt. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); #define ROUND_STRUCT_ELEMENT(x) \ uint32_t x##_isNaN2008; \ int32_t x##_up_out; \ int32_t x##_down_out; \ int32_t neg_##x##_up_out; \ int32_t neg_##x##_down_out; \ uint32_t x##_err1_out; \ uint32_t x##_err2_out; \ uint32_t x##_err3_out; \ uint32_t x##_err4_out; \ int32_t x##_invalid_result; typedef struct { double round_up_in; double round_down_in; double neg_round_up_in; double neg_round_down_in; double err1_in; double err2_in; double err3_in; double err4_in; ROUND_STRUCT_ELEMENT(round) ROUND_STRUCT_ELEMENT(floor) ROUND_STRUCT_ELEMENT(ceil) ROUND_STRUCT_ELEMENT(trunc) ROUND_STRUCT_ELEMENT(cvt) } T; T t; #undef ROUND_STRUCT_ELEMENT MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); // Save FCSR. __ cfc1(a1, FCSR); // Disable FPU exceptions. __ ctc1(zero_reg, FCSR); #define RUN_ROUND_TEST(x) \ __ cfc1(t0, FCSR);\ __ sw(t0, MemOperand(a0, offsetof(T, x##_isNaN2008))); \ __ ldc1(f0, MemOperand(a0, offsetof(T, round_up_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_up_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, round_down_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_down_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, neg_round_up_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, neg_##x##_up_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, neg_round_down_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, neg_##x##_down_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err1_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err1_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err2_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err2_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err3_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err3_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err4_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err4_out))); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_invalid_result))); RUN_ROUND_TEST(round) RUN_ROUND_TEST(floor) RUN_ROUND_TEST(ceil) RUN_ROUND_TEST(trunc) RUN_ROUND_TEST(cvt) // Restore FCSR. __ ctc1(a1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.round_up_in = 123.51; t.round_down_in = 123.49; t.neg_round_up_in = -123.5; t.neg_round_down_in = -123.49; t.err1_in = 123.51; t.err2_in = 1; t.err3_in = static_cast(1) + 0xFFFFFFFF; t.err4_in = NAN; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); #define GET_FPU_ERR(x) (static_cast(x & kFCSRFlagMask)) #define CHECK_NAN2008(x) (x & kFCSRNaN2008FlagMask) #define CHECK_ROUND_RESULT(type) \ CHECK(GET_FPU_ERR(t.type##_err1_out) & kFCSRInexactFlagMask); \ CHECK_EQ(0, GET_FPU_ERR(t.type##_err2_out)); \ CHECK(GET_FPU_ERR(t.type##_err3_out) & kFCSRInvalidOpFlagMask); \ CHECK(GET_FPU_ERR(t.type##_err4_out) & kFCSRInvalidOpFlagMask); \ if (CHECK_NAN2008(t.type##_isNaN2008) && kArchVariant == kMips64r6) { \ CHECK_EQ(static_cast(0), t.type##_invalid_result);\ } else { \ CHECK_EQ(static_cast(kFPUInvalidResult), t.type##_invalid_result);\ } CHECK_ROUND_RESULT(round); CHECK_ROUND_RESULT(floor); CHECK_ROUND_RESULT(ceil); CHECK_ROUND_RESULT(cvt); } TEST(MIPS15) { // Test chaining of label usages within instructions (issue 1644). CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); Assembler assm(isolate, NULL, 0); Label target; __ beq(v0, v1, &target); __ nop(); __ bne(v0, v1, &target); __ nop(); __ bind(&target); __ nop(); } // ----- mips64 tests ----------------------------------------------- TEST(MIPS16) { // Test 64-bit memory loads and stores. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); struct T { int64_t r1; int64_t r2; int64_t r3; int64_t r4; int64_t r5; int64_t r6; int64_t r7; int64_t r8; int64_t r9; int64_t r10; int64_t r11; int64_t r12; uint32_t ui; int32_t si; }; T t; Assembler assm(isolate, NULL, 0); Label L, C; // Basic 32-bit word load/store, with un-signed data. __ lw(a4, MemOperand(a0, offsetof(T, ui))); __ sw(a4, MemOperand(a0, offsetof(T, r1))); // Check that the data got zero-extended into 64-bit a4. __ sd(a4, MemOperand(a0, offsetof(T, r2))); // Basic 32-bit word load/store, with SIGNED data. __ lw(a5, MemOperand(a0, offsetof(T, si))); __ sw(a5, MemOperand(a0, offsetof(T, r3))); // Check that the data got sign-extended into 64-bit a4. __ sd(a5, MemOperand(a0, offsetof(T, r4))); // 32-bit UNSIGNED word load/store, with SIGNED data. __ lwu(a6, MemOperand(a0, offsetof(T, si))); __ sw(a6, MemOperand(a0, offsetof(T, r5))); // Check that the data got zero-extended into 64-bit a4. __ sd(a6, MemOperand(a0, offsetof(T, r6))); // lh with positive data. __ lh(a5, MemOperand(a0, offsetof(T, ui))); __ sw(a5, MemOperand(a0, offsetof(T, r7))); // lh with negative data. __ lh(a6, MemOperand(a0, offsetof(T, si))); __ sw(a6, MemOperand(a0, offsetof(T, r8))); // lhu with negative data. __ lhu(a7, MemOperand(a0, offsetof(T, si))); __ sw(a7, MemOperand(a0, offsetof(T, r9))); // lb with negative data. __ lb(t0, MemOperand(a0, offsetof(T, si))); __ sw(t0, MemOperand(a0, offsetof(T, r10))); // sh writes only 1/2 of word. __ lw(a4, MemOperand(a0, offsetof(T, ui))); __ sh(a4, MemOperand(a0, offsetof(T, r11))); __ lw(a4, MemOperand(a0, offsetof(T, si))); __ sh(a4, MemOperand(a0, offsetof(T, r12))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.ui = 0x44332211; t.si = 0x99aabbcc; t.r1 = 0x5555555555555555; t.r2 = 0x5555555555555555; t.r3 = 0x5555555555555555; t.r4 = 0x5555555555555555; t.r5 = 0x5555555555555555; t.r6 = 0x5555555555555555; t.r7 = 0x5555555555555555; t.r8 = 0x5555555555555555; t.r9 = 0x5555555555555555; t.r10 = 0x5555555555555555; t.r11 = 0x5555555555555555; t.r12 = 0x5555555555555555; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); if (kArchEndian == kLittle) { // Unsigned data, 32 & 64 CHECK_EQ(static_cast(0x5555555544332211L), t.r1); // lw, sw. CHECK_EQ(static_cast(0x0000000044332211L), t.r2); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x5555555599aabbccL), t.r3); // lw, sw. CHECK_EQ(static_cast(0xffffffff99aabbccL), t.r4); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x5555555599aabbccL), t.r5); // lwu, sw. CHECK_EQ(static_cast(0x0000000099aabbccL), t.r6); // sd. // lh with unsigned and signed data. CHECK_EQ(static_cast(0x5555555500002211L), t.r7); // lh, sw. CHECK_EQ(static_cast(0x55555555ffffbbccL), t.r8); // lh, sw. // lhu with signed data. CHECK_EQ(static_cast(0x555555550000bbccL), t.r9); // lhu, sw. // lb with signed data. CHECK_EQ(static_cast(0x55555555ffffffccL), t.r10); // lb, sw. // sh with unsigned and signed data. CHECK_EQ(static_cast(0x5555555555552211L), t.r11); // lw, sh. CHECK_EQ(static_cast(0x555555555555bbccL), t.r12); // lw, sh. } else { // Unsigned data, 32 & 64 CHECK_EQ(static_cast(0x4433221155555555L), t.r1); // lw, sw. CHECK_EQ(static_cast(0x0000000044332211L), t.r2); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x99aabbcc55555555L), t.r3); // lw, sw. CHECK_EQ(static_cast(0xffffffff99aabbccL), t.r4); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x99aabbcc55555555L), t.r5); // lwu, sw. CHECK_EQ(static_cast(0x0000000099aabbccL), t.r6); // sd. // lh with unsigned and signed data. CHECK_EQ(static_cast(0x0000443355555555L), t.r7); // lh, sw. CHECK_EQ(static_cast(0xffff99aa55555555L), t.r8); // lh, sw. // lhu with signed data. CHECK_EQ(static_cast(0x000099aa55555555L), t.r9); // lhu, sw. // lb with signed data. CHECK_EQ(static_cast(0xffffff9955555555L), t.r10); // lb, sw. // sh with unsigned and signed data. CHECK_EQ(static_cast(0x2211555555555555L), t.r11); // lw, sh. CHECK_EQ(static_cast(0xbbcc555555555555L), t.r12); // lw, sh. } } // ----------------------mips64r6 specific tests---------------------- TEST(seleqz_selnez) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { int a; int b; int c; int d; double e; double f; double g; double h; float i; float j; float k; float l; } Test; Test test; // Integer part of test. __ addiu(t1, zero_reg, 1); // t1 = 1 __ seleqz(t3, t1, zero_reg); // t3 = 1 __ sw(t3, MemOperand(a0, offsetof(Test, a))); // a = 1 __ seleqz(t2, t1, t1); // t2 = 0 __ sw(t2, MemOperand(a0, offsetof(Test, b))); // b = 0 __ selnez(t3, t1, zero_reg); // t3 = 1; __ sw(t3, MemOperand(a0, offsetof(Test, c))); // c = 0 __ selnez(t3, t1, t1); // t3 = 1 __ sw(t3, MemOperand(a0, offsetof(Test, d))); // d = 1 // Floating point part of test. __ ldc1(f0, MemOperand(a0, offsetof(Test, e)) ); // src __ ldc1(f2, MemOperand(a0, offsetof(Test, f)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, i)) ); // src __ lwc1(f10, MemOperand(a0, offsetof(Test, j)) ); // test __ seleqz_d(f4, f0, f2); __ selnez_d(f6, f0, f2); __ seleqz_s(f12, f8, f10); __ selnez_s(f14, f8, f10); __ sdc1(f4, MemOperand(a0, offsetof(Test, g)) ); // src __ sdc1(f6, MemOperand(a0, offsetof(Test, h)) ); // src __ swc1(f12, MemOperand(a0, offsetof(Test, k)) ); // src __ swc1(f14, MemOperand(a0, offsetof(Test, l)) ); // src __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.a, 1); CHECK_EQ(test.b, 0); CHECK_EQ(test.c, 0); CHECK_EQ(test.d, 1); const int test_size = 3; const int input_size = 5; double inputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double outputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float inputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float outputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.e = inputs_D[i]; test.f = tests_D[j]; test.i = inputs_S[i]; test.j = tests_S[j]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, outputs_D[i]); CHECK_EQ(test.h, 0); CHECK_EQ(test.k, outputs_S[i]); CHECK_EQ(test.l, 0); test.f = tests_D[j+1]; test.j = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, 0); CHECK_EQ(test.h, outputs_D[i]); CHECK_EQ(test.k, 0); CHECK_EQ(test.l, outputs_S[i]); } } } } TEST(min_max) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); struct TestFloat { double a; double b; double c; double d; float e; float f; float g; float h; }; TestFloat test; const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); const int kTableLength = 13; double inputsa[kTableLength] = {2.0, 3.0, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = {3.0, 2.0, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double outputsdmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double outputsdmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputse[kTableLength] = {2.0, 3.0, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsf[kTableLength] = {3.0, 2.0, 3.0, fnan, 0.0, -0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float outputsfmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float outputsfmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a))); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, b))); __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, e))); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, f))); __ min_d(f10, f4, f8); __ max_d(f12, f4, f8); __ min_s(f14, f2, f6); __ max_s(f16, f2, f6); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, c))); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, d))); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, g))); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, h))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 4; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.e = inputse[i]; test.f = inputsf[i]; CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0); CHECK_EQ(0, memcmp(&test.c, &outputsdmin[i], sizeof(test.c))); CHECK_EQ(0, memcmp(&test.d, &outputsdmax[i], sizeof(test.d))); CHECK_EQ(0, memcmp(&test.g, &outputsfmin[i], sizeof(test.g))); CHECK_EQ(0, memcmp(&test.h, &outputsfmax[i], sizeof(test.h))); } } } TEST(rint_d) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; int fcsr; }TestFloat; TestFloat test; double inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E+308, 6.27463370218383111104242366943E-307, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ ctc1(t0, FCSR); __ rint_d(f8, f4); __ sdc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(sel) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { double dd; double ds; double dt; float fd; float fs; float ft; } Test; Test test; __ ldc1(f0, MemOperand(a0, offsetof(Test, dd)) ); // test __ ldc1(f2, MemOperand(a0, offsetof(Test, ds)) ); // src1 __ ldc1(f4, MemOperand(a0, offsetof(Test, dt)) ); // src2 __ lwc1(f6, MemOperand(a0, offsetof(Test, fd)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, fs)) ); // src1 __ lwc1(f10, MemOperand(a0, offsetof(Test, ft)) ); // src2 __ sel_d(f0, f2, f4); __ sel_s(f6, f8, f10); __ sdc1(f0, MemOperand(a0, offsetof(Test, dd)) ); __ swc1(f6, MemOperand(a0, offsetof(Test, fd)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); const int test_size = 3; const int input_size = 5; double inputs_dt[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double inputs_ds[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; float inputs_ft[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float inputs_fs[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.dt = inputs_dt[i]; test.dd = tests_D[j]; test.ds = inputs_ds[i]; test.ft = inputs_ft[i]; test.fd = tests_S[j]; test.fs = inputs_fs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_ds[i]); CHECK_EQ(test.fd, inputs_fs[i]); test.dd = tests_D[j+1]; test.fd = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_dt[i]); CHECK_EQ(test.fd, inputs_ft[i]); } } } } TEST(rint_s) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; int fcsr; }TestFloat; TestFloat test; float inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E+38, 6.27463370218383111104242366943E-37, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; float* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ rint_s(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(mina_maxa) { if (kArchVariant == kMips64r6) { const int kTableLength = 23; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); struct TestFloat { double a; double b; double resd; double resd1; float c; float d; float resf; float resf1; }; TestFloat test; double inputsa[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = { 4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double resd[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double resd1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputsc[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsd[kTableLength] = {4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, fnan, -0.0, 0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float resf[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float resf1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ lwc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ lwc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ mina_d(f6, f2, f4); __ mina_s(f12, f8, f10); __ maxa_d(f14, f2, f4); __ maxa_s(f16, f8, f10); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, resf)) ); __ sdc1(f6, MemOperand(a0, offsetof(TestFloat, resd)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resf1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resd1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.c = inputsc[i]; test.d = inputsd[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if (i < kTableLength - 1) { CHECK_EQ(test.resd, resd[i]); CHECK_EQ(test.resf, resf[i]); CHECK_EQ(test.resd1, resd1[i]); CHECK_EQ(test.resf1, resf1[i]); } else { CHECK(std::isnan(test.resd)); CHECK(std::isnan(test.resf)); CHECK(std::isnan(test.resd1)); CHECK(std::isnan(test.resf1)); } } } } // ----------------------mips64r2 specific tests---------------------- TEST(trunc_l) { if (kArchVariant == kMips64r2) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; // a trunc result int64_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_l_d(f8, f4); __ trunc_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } } TEST(movz_movn) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { int64_t rt; double a; double b; double bold; double b1; double bold1; float c; float d; float dold; float d1; float dold1; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ld(t0, MemOperand(a0, offsetof(TestFloat, rt))); __ Move(f12, 0.0); __ Move(f10, 0.0); __ Move(f16, 0.0); __ Move(f14, 0.0); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, bold)) ); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, dold)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, bold1)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, dold1)) ); __ movz_s(f10, f6, t0); __ movz_d(f12, f2, t0); __ movn_s(f14, f6, t0); __ movn_d(f16, f2, t0); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, b)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, d1)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, b1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; test.rt = 1; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, test.bold); CHECK_EQ(test.d, test.dold); CHECK_EQ(test.b1, outputs_D[i]); CHECK_EQ(test.d1, outputs_S[i]); test.rt = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); CHECK_EQ(test.b1, test.bold1); CHECK_EQ(test.d1, test.dold1); } } } TEST(movt_movd) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); typedef struct test_float { double srcd; double dstd; double dstdold; double dstd1; double dstdold1; float srcf; float dstf; float dstfold; float dstf1; float dstfold1; int32_t cc; int32_t fcsr; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; double inputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; int condition_flags[8] = {0, 1, 2, 3, 4, 5, 6, 7}; for (int i = 0; i < kTableLength; i++) { test.srcd = inputs_D[i]; test.srcf = inputs_S[i]; for (int j = 0; j< 8; j++) { test.cc = condition_flags[j]; if (test.cc == 0) { test.fcsr = 1 << 23; } else { test.fcsr = 1 << (24+condition_flags[j]); } HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, srcd)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, srcf)) ); __ lw(t1, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t0, FCSR); __ ctc1(t1, FCSR); __ li(t2, 0x0); __ mtc1(t2, f12); __ mtc1(t2, f10); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold)) ); __ movt_s(f12, f4, test.cc); __ movt_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold1)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold1)) ); __ movf_s(f12, f4, test.cc); __ movf_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf1)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd1)) ); __ ctc1(t0, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, outputs_S[i]); CHECK_EQ(test.dstd, outputs_D[i]); CHECK_EQ(test.dstf1, test.dstfold1); CHECK_EQ(test.dstd1, test.dstdold1); test.fcsr = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, test.dstfold); CHECK_EQ(test.dstd, test.dstdold); CHECK_EQ(test.dstf1, outputs_S[i]); CHECK_EQ(test.dstd1, outputs_D[i]); } } } } // ----------------------tests for all archs-------------------------- TEST(cvt_w_d) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; int32_t b; int fcsr; }Test; const int kTableLength = 24; double inputs[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, 2147483653.0 }; double outputs_RN[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RZ[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RP[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RM[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lw(t0, MemOperand(a0, offsetof(Test, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ cvt_w_d(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(Test, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } TEST(trunc_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_w_d(f8, f4); __ trunc_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_w_d(f8, f4); __ round_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_l_d(f8, f4); __ round_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(sub) { const int kTableLength = 12; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; double inputft_D[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; double outputs_D[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; float inputfs_S[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; float inputft_S[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; float outputs_S[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sub_s(f6, f2, f4); __ sub_d(f12, f8, f10); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(sqrt_rsqrt_recip) { const int kTableLength = 4; const double deltaDouble = 2E-15; const float deltaFloat = 2E-7; const float sqrt2_s = sqrt(2); const double sqrt2_d = sqrt(2); CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; float resultS1; float resultS2; double c; double resultD; double resultD1; double resultD2; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 0.0L, 4.0L, 2.0L, 4e-28L }; double outputs_D[kTableLength] = { 0.0L, 2.0L, sqrt2_d, 2e-14L }; float inputs_S[kTableLength] = { 0.0, 4.0, 2.0, 4e-28 }; float outputs_S[kTableLength] = { 0.0, 2.0, sqrt2_s, 2e-14 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ sqrt_s(f6, f2); __ sqrt_d(f12, f8); __ rsqrt_d(f14, f8); __ rsqrt_s(f16, f2); __ recip_d(f18, f8); __ recip_s(f4, f2); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resultS1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resultD1)) ); __ swc1(f4, MemOperand(a0, offsetof(TestFloat, resultS2)) ); __ sdc1(f18, MemOperand(a0, offsetof(TestFloat, resultD2)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { float f1; double d1; test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); if (i != 0) { f1 = test.resultS1 - 1.0F/outputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD1 - 1.0L/outputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); f1 = test.resultS2 - 1.0F/inputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD2 - 1.0L/inputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); } else { CHECK_EQ(test.resultS1, 1.0F/outputs_S[i]); CHECK_EQ(test.resultD1, 1.0L/outputs_D[i]); CHECK_EQ(test.resultS2, 1.0F/inputs_S[i]); CHECK_EQ(test.resultD2, 1.0L/inputs_D[i]); } } } TEST(neg) { const int kTableLength = 2; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; double c; double resultD; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 4.0, -2.0 }; double outputs_D[kTableLength] = { -4.0, 2.0 }; float inputs_S[kTableLength] = { 4.0, -2.0 }; float outputs_S[kTableLength] = { -4.0, 2.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ neg_s(f6, f2); __ neg_d(f12, f8); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
()); F2 f = FUNCTION_CAST(code->entry()); int64_t res = reinterpret_cast( CALL_GENERATED_CODE(isolate, f, 0xab0, 0xc, 0, 0, 0)); CHECK_EQ(0xabcL, res); } TEST(MIPS1) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); Label L, C; __ mov(a1, a0); __ li(v0, 0); __ b(&C); __ nop(); __ bind(&L); __ addu(v0, v0, a1); __ addiu(a1, a1, -1); __ bind(&C); __ xori(v1, a1, 0); __ Branch(&L, ne, v1, Operand((int64_t)0)); __ nop(); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F1 f = FUNCTION_CAST(code->entry()); int64_t res = reinterpret_cast( CALL_GENERATED_CODE(isolate, f, 50, 0, 0, 0, 0)); CHECK_EQ(1275L, res); } TEST(MIPS2) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); Label exit, error; // ----- Test all instructions. // Test lui, ori, and addiu, used in the li pseudo-instruction. // This way we can then safely load registers with chosen values. __ ori(a4, zero_reg, 0); __ lui(a4, 0x1234); __ ori(a4, a4, 0); __ ori(a4, a4, 0x0f0f); __ ori(a4, a4, 0xf0f0); __ addiu(a5, a4, 1); __ addiu(a6, a5, -0x10); // Load values in temporary registers. __ li(a4, 0x00000004); __ li(a5, 0x00001234); __ li(a6, 0x12345678); __ li(a7, 0x7fffffff); __ li(t0, 0xfffffffc); __ li(t1, 0xffffedcc); __ li(t2, 0xedcba988); __ li(t3, 0x80000000); // SPECIAL class. __ srl(v0, a6, 8); // 0x00123456 __ sll(v0, v0, 11); // 0x91a2b000 __ sra(v0, v0, 3); // 0xf2345600 __ srav(v0, v0, a4); // 0xff234560 __ sllv(v0, v0, a4); // 0xf2345600 __ srlv(v0, v0, a4); // 0x0f234560 __ Branch(&error, ne, v0, Operand(0x0f234560)); __ nop(); __ addu(v0, a4, a5); // 0x00001238 __ subu(v0, v0, a4); // 0x00001234 __ Branch(&error, ne, v0, Operand(0x00001234)); __ nop(); __ addu(v1, a7, a4); // 32bit addu result is sign-extended into 64bit reg. __ Branch(&error, ne, v1, Operand(0xffffffff80000003)); __ nop(); __ subu(v1, t3, a4); // 0x7ffffffc __ Branch(&error, ne, v1, Operand(0x7ffffffc)); __ nop(); __ and_(v0, a5, a6); // 0x0000000000001230 __ or_(v0, v0, a5); // 0x0000000000001234 __ xor_(v0, v0, a6); // 0x000000001234444c __ nor(v0, v0, a6); // 0xffffffffedcba987 __ Branch(&error, ne, v0, Operand(0xffffffffedcba983)); __ nop(); // Shift both 32bit number to left, to preserve meaning of next comparison. __ dsll32(a7, a7, 0); __ dsll32(t3, t3, 0); __ slt(v0, t3, a7); __ Branch(&error, ne, v0, Operand(0x1)); __ nop(); __ sltu(v0, t3, a7); __ Branch(&error, ne, v0, Operand(zero_reg)); __ nop(); // Restore original values in registers. __ dsrl32(a7, a7, 0); __ dsrl32(t3, t3, 0); // End of SPECIAL class. __ addiu(v0, zero_reg, 0x7421); // 0x00007421 __ addiu(v0, v0, -0x1); // 0x00007420 __ addiu(v0, v0, -0x20); // 0x00007400 __ Branch(&error, ne, v0, Operand(0x00007400)); __ nop(); __ addiu(v1, a7, 0x1); // 0x80000000 - result is sign-extended. __ Branch(&error, ne, v1, Operand(0xffffffff80000000)); __ nop(); __ slti(v0, a5, 0x00002000); // 0x1 __ slti(v0, v0, 0xffff8000); // 0x0 __ Branch(&error, ne, v0, Operand(zero_reg)); __ nop(); __ sltiu(v0, a5, 0x00002000); // 0x1 __ sltiu(v0, v0, 0x00008000); // 0x1 __ Branch(&error, ne, v0, Operand(0x1)); __ nop(); __ andi(v0, a5, 0xf0f0); // 0x00001030 __ ori(v0, v0, 0x8a00); // 0x00009a30 __ xori(v0, v0, 0x83cc); // 0x000019fc __ Branch(&error, ne, v0, Operand(0x000019fc)); __ nop(); __ lui(v1, 0x8123); // Result is sign-extended into 64bit register. __ Branch(&error, ne, v1, Operand(0xffffffff81230000)); __ nop(); // Bit twiddling instructions & conditional moves. // Uses a4-t3 as set above. __ Clz(v0, a4); // 29 __ Clz(v1, a5); // 19 __ addu(v0, v0, v1); // 48 __ Clz(v1, a6); // 3 __ addu(v0, v0, v1); // 51 __ Clz(v1, t3); // 0 __ addu(v0, v0, v1); // 51 __ Branch(&error, ne, v0, Operand(51)); __ Movn(a0, a7, a4); // Move a0<-a7 (a4 is NOT 0). __ Ins(a0, a5, 12, 8); // 0x7ff34fff __ Branch(&error, ne, a0, Operand(0x7ff34fff)); __ Movz(a0, t2, t3); // a0 not updated (t3 is NOT 0). __ Ext(a1, a0, 8, 12); // 0x34f __ Branch(&error, ne, a1, Operand(0x34f)); __ Movz(a0, t2, v1); // a0<-t2, v0 is 0, from 8 instr back. __ Branch(&error, ne, a0, Operand(t2)); // Everything was correctly executed. Load the expected result. __ li(v0, 0x31415926); __ b(&exit); __ nop(); __ bind(&error); // Got an error. Return a wrong result. __ li(v0, 666); __ bind(&exit); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F2 f = FUNCTION_CAST(code->entry()); int64_t res = reinterpret_cast( CALL_GENERATED_CODE(isolate, f, 0xab0, 0xc, 0, 0, 0)); CHECK_EQ(0x31415926L, res); } TEST(MIPS3) { // Test floating point instructions. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double a; double b; double c; double d; double e; double f; double g; double h; double i; float fa; float fb; float fc; float fd; float fe; float ff; float fg; } T; T t; // Create a function that accepts &t, and loads, manipulates, and stores // the doubles t.a ... t.f. MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); Label L, C; // Double precision floating point instructions. __ ldc1(f4, MemOperand(a0, offsetof(T, a)) ); __ ldc1(f6, MemOperand(a0, offsetof(T, b)) ); __ add_d(f8, f4, f6); __ sdc1(f8, MemOperand(a0, offsetof(T, c)) ); // c = a + b. __ mov_d(f10, f8); // c __ neg_d(f12, f6); // -b __ sub_d(f10, f10, f12); __ sdc1(f10, MemOperand(a0, offsetof(T, d)) ); // d = c - (-b). __ sdc1(f4, MemOperand(a0, offsetof(T, b)) ); // b = a. __ li(a4, 120); __ mtc1(a4, f14); __ cvt_d_w(f14, f14); // f14 = 120.0. __ mul_d(f10, f10, f14); __ sdc1(f10, MemOperand(a0, offsetof(T, e)) ); // e = d * 120 = 1.8066e16. __ div_d(f12, f10, f4); __ sdc1(f12, MemOperand(a0, offsetof(T, f)) ); // f = e / a = 120.44. __ sqrt_d(f14, f12); __ sdc1(f14, MemOperand(a0, offsetof(T, g)) ); // g = sqrt(f) = 10.97451593465515908537 if (kArchVariant == kMips64r2) { __ ldc1(f4, MemOperand(a0, offsetof(T, h)) ); __ ldc1(f6, MemOperand(a0, offsetof(T, i)) ); __ madd_d(f14, f6, f4, f6); __ sdc1(f14, MemOperand(a0, offsetof(T, h)) ); } // Single precision floating point instructions. __ lwc1(f4, MemOperand(a0, offsetof(T, fa)) ); __ lwc1(f6, MemOperand(a0, offsetof(T, fb)) ); __ add_s(f8, f4, f6); __ swc1(f8, MemOperand(a0, offsetof(T, fc)) ); // fc = fa + fb. __ neg_s(f10, f6); // -fb __ sub_s(f10, f8, f10); __ swc1(f10, MemOperand(a0, offsetof(T, fd)) ); // fd = fc - (-fb). __ swc1(f4, MemOperand(a0, offsetof(T, fb)) ); // fb = fa. __ li(t0, 120); __ mtc1(t0, f14); __ cvt_s_w(f14, f14); // f14 = 120.0. __ mul_s(f10, f10, f14); __ swc1(f10, MemOperand(a0, offsetof(T, fe)) ); // fe = fd * 120 __ div_s(f12, f10, f4); __ swc1(f12, MemOperand(a0, offsetof(T, ff)) ); // ff = fe / fa __ sqrt_s(f14, f12); __ swc1(f14, MemOperand(a0, offsetof(T, fg)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); // Double test values. t.a = 1.5e14; t.b = 2.75e11; t.c = 0.0; t.d = 0.0; t.e = 0.0; t.f = 0.0; t.h = 1.5; t.i = 2.75; // Single test values. t.fa = 1.5e6; t.fb = 2.75e4; t.fc = 0.0; t.fd = 0.0; t.fe = 0.0; t.ff = 0.0; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); // Expected double results. CHECK_EQ(1.5e14, t.a); CHECK_EQ(1.5e14, t.b); CHECK_EQ(1.50275e14, t.c); CHECK_EQ(1.50550e14, t.d); CHECK_EQ(1.8066e16, t.e); CHECK_EQ(120.44, t.f); CHECK_EQ(10.97451593465515908537, t.g); if (kArchVariant == kMips64r2) { CHECK_EQ(6.875, t.h); } // Expected single results. CHECK_EQ(1.5e6, t.fa); CHECK_EQ(1.5e6, t.fb); CHECK_EQ(1.5275e06, t.fc); CHECK_EQ(1.5550e06, t.fd); CHECK_EQ(1.866e08, t.fe); CHECK_EQ(124.40000152587890625, t.ff); CHECK_EQ(11.1534748077392578125, t.fg); } TEST(MIPS4) { // Test moves between floating point and integer registers. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double a; double b; double c; double d; int64_t high; int64_t low; } T; T t; Assembler assm(isolate, NULL, 0); Label L, C; __ ldc1(f4, MemOperand(a0, offsetof(T, a))); __ ldc1(f5, MemOperand(a0, offsetof(T, b))); // Swap f4 and f5, by using 3 integer registers, a4-a6, // both two 32-bit chunks, and one 64-bit chunk. // mXhc1 is mips32/64-r2 only, not r1, // but we will not support r1 in practice. __ mfc1(a4, f4); __ mfhc1(a5, f4); __ dmfc1(a6, f5); __ mtc1(a4, f5); __ mthc1(a5, f5); __ dmtc1(a6, f4); // Store the swapped f4 and f5 back to memory. __ sdc1(f4, MemOperand(a0, offsetof(T, a))); __ sdc1(f5, MemOperand(a0, offsetof(T, c))); // Test sign extension of move operations from coprocessor. __ ldc1(f4, MemOperand(a0, offsetof(T, d))); __ mfhc1(a4, f4); __ mfc1(a5, f4); __ sd(a4, MemOperand(a0, offsetof(T, high))); __ sd(a5, MemOperand(a0, offsetof(T, low))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.a = 1.5e22; t.b = 2.75e11; t.c = 17.17; t.d = -2.75e11; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(2.75e11, t.a); CHECK_EQ(2.75e11, t.b); CHECK_EQ(1.5e22, t.c); CHECK_EQ(static_cast(0xffffffffc25001d1L), t.high); CHECK_EQ(static_cast(0xffffffffbf800000L), t.low); } TEST(MIPS5) { // Test conversions between doubles and integers. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double a; double b; int i; int j; } T; T t; Assembler assm(isolate, NULL, 0); Label L, C; // Load all structure elements to registers. __ ldc1(f4, MemOperand(a0, offsetof(T, a)) ); __ ldc1(f6, MemOperand(a0, offsetof(T, b)) ); __ lw(a4, MemOperand(a0, offsetof(T, i)) ); __ lw(a5, MemOperand(a0, offsetof(T, j)) ); // Convert double in f4 to int in element i. __ cvt_w_d(f8, f4); __ mfc1(a6, f8); __ sw(a6, MemOperand(a0, offsetof(T, i)) ); // Convert double in f6 to int in element j. __ cvt_w_d(f10, f6); __ mfc1(a7, f10); __ sw(a7, MemOperand(a0, offsetof(T, j)) ); // Convert int in original i (a4) to double in a. __ mtc1(a4, f12); __ cvt_d_w(f0, f12); __ sdc1(f0, MemOperand(a0, offsetof(T, a)) ); // Convert int in original j (a5) to double in b. __ mtc1(a5, f14); __ cvt_d_w(f2, f14); __ sdc1(f2, MemOperand(a0, offsetof(T, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.a = 1.5e4; t.b = 2.75e8; t.i = 12345678; t.j = -100000; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(12345678.0, t.a); CHECK_EQ(-100000.0, t.b); CHECK_EQ(15000, t.i); CHECK_EQ(275000000, t.j); } TEST(MIPS6) { // Test simple memory loads and stores. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { uint32_t ui; int32_t si; int32_t r1; int32_t r2; int32_t r3; int32_t r4; int32_t r5; int32_t r6; } T; T t; Assembler assm(isolate, NULL, 0); Label L, C; // Basic word load/store. __ lw(a4, MemOperand(a0, offsetof(T, ui)) ); __ sw(a4, MemOperand(a0, offsetof(T, r1)) ); // lh with positive data. __ lh(a5, MemOperand(a0, offsetof(T, ui)) ); __ sw(a5, MemOperand(a0, offsetof(T, r2)) ); // lh with negative data. __ lh(a6, MemOperand(a0, offsetof(T, si)) ); __ sw(a6, MemOperand(a0, offsetof(T, r3)) ); // lhu with negative data. __ lhu(a7, MemOperand(a0, offsetof(T, si)) ); __ sw(a7, MemOperand(a0, offsetof(T, r4)) ); // lb with negative data. __ lb(t0, MemOperand(a0, offsetof(T, si)) ); __ sw(t0, MemOperand(a0, offsetof(T, r5)) ); // sh writes only 1/2 of word. __ lui(t1, 0x3333); __ ori(t1, t1, 0x3333); __ sw(t1, MemOperand(a0, offsetof(T, r6)) ); __ lhu(t1, MemOperand(a0, offsetof(T, si)) ); __ sh(t1, MemOperand(a0, offsetof(T, r6)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.ui = 0x11223344; t.si = 0x99aabbcc; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(static_cast(0x11223344), t.r1); if (kArchEndian == kLittle) { CHECK_EQ(static_cast(0x3344), t.r2); CHECK_EQ(static_cast(0xffffbbcc), t.r3); CHECK_EQ(static_cast(0x0000bbcc), t.r4); CHECK_EQ(static_cast(0xffffffcc), t.r5); CHECK_EQ(static_cast(0x3333bbcc), t.r6); } else { CHECK_EQ(static_cast(0x1122), t.r2); CHECK_EQ(static_cast(0xffff99aa), t.r3); CHECK_EQ(static_cast(0x000099aa), t.r4); CHECK_EQ(static_cast(0xffffff99), t.r5); CHECK_EQ(static_cast(0x99aa3333), t.r6); } } TEST(MIPS7) { // Test floating point compare and branch instructions. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double a; double b; double c; double d; double e; double f; int32_t result; } T; T t; // Create a function that accepts &t, and loads, manipulates, and stores // the doubles t.a ... t.f. MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); Label neither_is_nan, less_than, outa_here; __ ldc1(f4, MemOperand(a0, offsetof(T, a)) ); __ ldc1(f6, MemOperand(a0, offsetof(T, b)) ); if (kArchVariant != kMips64r6) { __ c(UN, D, f4, f6); __ bc1f(&neither_is_nan); } else { __ cmp(UN, L, f2, f4, f6); __ bc1eqz(&neither_is_nan, f2); } __ nop(); __ sw(zero_reg, MemOperand(a0, offsetof(T, result)) ); __ Branch(&outa_here); __ bind(&neither_is_nan); if (kArchVariant == kMips64r6) { __ cmp(OLT, L, f2, f6, f4); __ bc1nez(&less_than, f2); } else { __ c(OLT, D, f6, f4, 2); __ bc1t(&less_than, 2); } __ nop(); __ sw(zero_reg, MemOperand(a0, offsetof(T, result)) ); __ Branch(&outa_here); __ bind(&less_than); __ Addu(a4, zero_reg, Operand(1)); __ sw(a4, MemOperand(a0, offsetof(T, result)) ); // Set true. // This test-case should have additional tests. __ bind(&outa_here); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.a = 1.5e14; t.b = 2.75e11; t.c = 2.0; t.d = -4.0; t.e = 0.0; t.f = 0.0; t.result = 0; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(1.5e14, t.a); CHECK_EQ(2.75e11, t.b); CHECK_EQ(1, t.result); } TEST(MIPS8) { if (kArchVariant == kMips64r2) { // Test ROTR and ROTRV instructions. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { int32_t input; int32_t result_rotr_4; int32_t result_rotr_8; int32_t result_rotr_12; int32_t result_rotr_16; int32_t result_rotr_20; int32_t result_rotr_24; int32_t result_rotr_28; int32_t result_rotrv_4; int32_t result_rotrv_8; int32_t result_rotrv_12; int32_t result_rotrv_16; int32_t result_rotrv_20; int32_t result_rotrv_24; int32_t result_rotrv_28; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); // Basic word load. __ lw(a4, MemOperand(a0, offsetof(T, input)) ); // ROTR instruction (called through the Ror macro). __ Ror(a5, a4, 0x0004); __ Ror(a6, a4, 0x0008); __ Ror(a7, a4, 0x000c); __ Ror(t0, a4, 0x0010); __ Ror(t1, a4, 0x0014); __ Ror(t2, a4, 0x0018); __ Ror(t3, a4, 0x001c); // Basic word store. __ sw(a5, MemOperand(a0, offsetof(T, result_rotr_4)) ); __ sw(a6, MemOperand(a0, offsetof(T, result_rotr_8)) ); __ sw(a7, MemOperand(a0, offsetof(T, result_rotr_12)) ); __ sw(t0, MemOperand(a0, offsetof(T, result_rotr_16)) ); __ sw(t1, MemOperand(a0, offsetof(T, result_rotr_20)) ); __ sw(t2, MemOperand(a0, offsetof(T, result_rotr_24)) ); __ sw(t3, MemOperand(a0, offsetof(T, result_rotr_28)) ); // ROTRV instruction (called through the Ror macro). __ li(t3, 0x0004); __ Ror(a5, a4, t3); __ li(t3, 0x0008); __ Ror(a6, a4, t3); __ li(t3, 0x000C); __ Ror(a7, a4, t3); __ li(t3, 0x0010); __ Ror(t0, a4, t3); __ li(t3, 0x0014); __ Ror(t1, a4, t3); __ li(t3, 0x0018); __ Ror(t2, a4, t3); __ li(t3, 0x001C); __ Ror(t3, a4, t3); // Basic word store. __ sw(a5, MemOperand(a0, offsetof(T, result_rotrv_4)) ); __ sw(a6, MemOperand(a0, offsetof(T, result_rotrv_8)) ); __ sw(a7, MemOperand(a0, offsetof(T, result_rotrv_12)) ); __ sw(t0, MemOperand(a0, offsetof(T, result_rotrv_16)) ); __ sw(t1, MemOperand(a0, offsetof(T, result_rotrv_20)) ); __ sw(t2, MemOperand(a0, offsetof(T, result_rotrv_24)) ); __ sw(t3, MemOperand(a0, offsetof(T, result_rotrv_28)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.input = 0x12345678; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0x0, 0, 0, 0); USE(dummy); CHECK_EQ(static_cast(0x81234567), t.result_rotr_4); CHECK_EQ(static_cast(0x78123456), t.result_rotr_8); CHECK_EQ(static_cast(0x67812345), t.result_rotr_12); CHECK_EQ(static_cast(0x56781234), t.result_rotr_16); CHECK_EQ(static_cast(0x45678123), t.result_rotr_20); CHECK_EQ(static_cast(0x34567812), t.result_rotr_24); CHECK_EQ(static_cast(0x23456781), t.result_rotr_28); CHECK_EQ(static_cast(0x81234567), t.result_rotrv_4); CHECK_EQ(static_cast(0x78123456), t.result_rotrv_8); CHECK_EQ(static_cast(0x67812345), t.result_rotrv_12); CHECK_EQ(static_cast(0x56781234), t.result_rotrv_16); CHECK_EQ(static_cast(0x45678123), t.result_rotrv_20); CHECK_EQ(static_cast(0x34567812), t.result_rotrv_24); CHECK_EQ(static_cast(0x23456781), t.result_rotrv_28); } } TEST(MIPS9) { // Test BRANCH improvements. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); Label exit, exit2, exit3; __ Branch(&exit, ge, a0, Operand(zero_reg)); __ Branch(&exit2, ge, a0, Operand(0x00001FFF)); __ Branch(&exit3, ge, a0, Operand(0x0001FFFF)); __ bind(&exit); __ bind(&exit2); __ bind(&exit3); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); } TEST(MIPS10) { // Test conversions between doubles and long integers. // Test hos the long ints map to FP regs pairs. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double a; double a_converted; double b; int32_t dbl_mant; int32_t dbl_exp; int32_t long_hi; int32_t long_lo; int64_t long_as_int64; int32_t b_long_hi; int32_t b_long_lo; int64_t b_long_as_int64; } T; T t; Assembler assm(isolate, NULL, 0); Label L, C; if (kArchVariant == kMips64r2) { // Rewritten for FR=1 FPU mode: // - 32 FP regs of 64-bits each, no odd/even pairs. // - Note that cvt_l_d/cvt_d_l ARE legal in FR=1 mode. // Load all structure elements to registers. __ ldc1(f0, MemOperand(a0, offsetof(T, a))); // Save the raw bits of the double. __ mfc1(a4, f0); __ mfhc1(a5, f0); __ sw(a4, MemOperand(a0, offsetof(T, dbl_mant))); __ sw(a5, MemOperand(a0, offsetof(T, dbl_exp))); // Convert double in f0 to long, save hi/lo parts. __ cvt_l_d(f0, f0); __ mfc1(a4, f0); // f0 LS 32 bits of long. __ mfhc1(a5, f0); // f0 MS 32 bits of long. __ sw(a4, MemOperand(a0, offsetof(T, long_lo))); __ sw(a5, MemOperand(a0, offsetof(T, long_hi))); // Combine the high/low ints, convert back to double. __ dsll32(a6, a5, 0); // Move a5 to high bits of a6. __ or_(a6, a6, a4); __ dmtc1(a6, f1); __ cvt_d_l(f1, f1); __ sdc1(f1, MemOperand(a0, offsetof(T, a_converted))); // Convert the b long integers to double b. __ lw(a4, MemOperand(a0, offsetof(T, b_long_lo))); __ lw(a5, MemOperand(a0, offsetof(T, b_long_hi))); __ mtc1(a4, f8); // f8 LS 32-bits. __ mthc1(a5, f8); // f8 MS 32-bits. __ cvt_d_l(f10, f8); __ sdc1(f10, MemOperand(a0, offsetof(T, b))); // Convert double b back to long-int. __ ldc1(f31, MemOperand(a0, offsetof(T, b))); __ cvt_l_d(f31, f31); __ dmfc1(a7, f31); __ sd(a7, MemOperand(a0, offsetof(T, b_long_as_int64))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.a = 2.147483647e9; // 0x7fffffff -> 0x41DFFFFFFFC00000 as double. t.b_long_hi = 0x000000ff; // 0xFF00FF00FF -> 0x426FE01FE01FE000 as double. t.b_long_lo = 0x00ff00ff; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(static_cast(0x41DFFFFF), t.dbl_exp); CHECK_EQ(static_cast(0xFFC00000), t.dbl_mant); CHECK_EQ(0, t.long_hi); CHECK_EQ(static_cast(0x7fffffff), t.long_lo); CHECK_EQ(2.147483647e9, t.a_converted); // 0xFF00FF00FF -> 1.095233372415e12. CHECK_EQ(1.095233372415e12, t.b); CHECK_EQ(static_cast(0xFF00FF00FF), t.b_long_as_int64); } } TEST(MIPS11) { // Do not run test on MIPS64r6, as these instructions are removed. if (kArchVariant != kMips64r6) { // Test LWL, LWR, SWL and SWR instructions. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { int32_t reg_init; int32_t mem_init; int32_t lwl_0; int32_t lwl_1; int32_t lwl_2; int32_t lwl_3; int32_t lwr_0; int32_t lwr_1; int32_t lwr_2; int32_t lwr_3; int32_t swl_0; int32_t swl_1; int32_t swl_2; int32_t swl_3; int32_t swr_0; int32_t swr_1; int32_t swr_2; int32_t swr_3; } T; T t; Assembler assm(isolate, NULL, 0); // Test all combinations of LWL and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, lwl_0))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a5, MemOperand(a0, offsetof(T, mem_init) + 1)); __ sw(a5, MemOperand(a0, offsetof(T, lwl_1))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a6, MemOperand(a0, offsetof(T, mem_init) + 2)); __ sw(a6, MemOperand(a0, offsetof(T, lwl_2))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a7, MemOperand(a0, offsetof(T, mem_init) + 3)); __ sw(a7, MemOperand(a0, offsetof(T, lwl_3))); // Test all combinations of LWR and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, lwr_0))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a5, MemOperand(a0, offsetof(T, mem_init) + 1)); __ sw(a5, MemOperand(a0, offsetof(T, lwr_1))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a6, MemOperand(a0, offsetof(T, mem_init) + 2)); __ sw(a6, MemOperand(a0, offsetof(T, lwr_2)) ); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a7, MemOperand(a0, offsetof(T, mem_init) + 3)); __ sw(a7, MemOperand(a0, offsetof(T, lwr_3)) ); // Test all combinations of SWL and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, swl_0))); __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ swl(a4, MemOperand(a0, offsetof(T, swl_0))); __ lw(a5, MemOperand(a0, offsetof(T, mem_init))); __ sw(a5, MemOperand(a0, offsetof(T, swl_1))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ swl(a5, MemOperand(a0, offsetof(T, swl_1) + 1)); __ lw(a6, MemOperand(a0, offsetof(T, mem_init))); __ sw(a6, MemOperand(a0, offsetof(T, swl_2))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ swl(a6, MemOperand(a0, offsetof(T, swl_2) + 2)); __ lw(a7, MemOperand(a0, offsetof(T, mem_init))); __ sw(a7, MemOperand(a0, offsetof(T, swl_3))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ swl(a7, MemOperand(a0, offsetof(T, swl_3) + 3)); // Test all combinations of SWR and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, swr_0))); __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ swr(a4, MemOperand(a0, offsetof(T, swr_0))); __ lw(a5, MemOperand(a0, offsetof(T, mem_init))); __ sw(a5, MemOperand(a0, offsetof(T, swr_1))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ swr(a5, MemOperand(a0, offsetof(T, swr_1) + 1)); __ lw(a6, MemOperand(a0, offsetof(T, mem_init))); __ sw(a6, MemOperand(a0, offsetof(T, swr_2))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ swr(a6, MemOperand(a0, offsetof(T, swr_2) + 2)); __ lw(a7, MemOperand(a0, offsetof(T, mem_init))); __ sw(a7, MemOperand(a0, offsetof(T, swr_3))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ swr(a7, MemOperand(a0, offsetof(T, swr_3) + 3)); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.reg_init = 0xaabbccdd; t.mem_init = 0x11223344; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); if (kArchEndian == kLittle) { CHECK_EQ(static_cast(0x44bbccdd), t.lwl_0); CHECK_EQ(static_cast(0x3344ccdd), t.lwl_1); CHECK_EQ(static_cast(0x223344dd), t.lwl_2); CHECK_EQ(static_cast(0x11223344), t.lwl_3); CHECK_EQ(static_cast(0x11223344), t.lwr_0); CHECK_EQ(static_cast(0xaa112233), t.lwr_1); CHECK_EQ(static_cast(0xaabb1122), t.lwr_2); CHECK_EQ(static_cast(0xaabbcc11), t.lwr_3); CHECK_EQ(static_cast(0x112233aa), t.swl_0); CHECK_EQ(static_cast(0x1122aabb), t.swl_1); CHECK_EQ(static_cast(0x11aabbcc), t.swl_2); CHECK_EQ(static_cast(0xaabbccdd), t.swl_3); CHECK_EQ(static_cast(0xaabbccdd), t.swr_0); CHECK_EQ(static_cast(0xbbccdd44), t.swr_1); CHECK_EQ(static_cast(0xccdd3344), t.swr_2); CHECK_EQ(static_cast(0xdd223344), t.swr_3); } else { CHECK_EQ(static_cast(0x11223344), t.lwl_0); CHECK_EQ(static_cast(0x223344dd), t.lwl_1); CHECK_EQ(static_cast(0x3344ccdd), t.lwl_2); CHECK_EQ(static_cast(0x44bbccdd), t.lwl_3); CHECK_EQ(static_cast(0xaabbcc11), t.lwr_0); CHECK_EQ(static_cast(0xaabb1122), t.lwr_1); CHECK_EQ(static_cast(0xaa112233), t.lwr_2); CHECK_EQ(static_cast(0x11223344), t.lwr_3); CHECK_EQ(static_cast(0xaabbccdd), t.swl_0); CHECK_EQ(static_cast(0x11aabbcc), t.swl_1); CHECK_EQ(static_cast(0x1122aabb), t.swl_2); CHECK_EQ(static_cast(0x112233aa), t.swl_3); CHECK_EQ(static_cast(0xdd223344), t.swr_0); CHECK_EQ(static_cast(0xccdd3344), t.swr_1); CHECK_EQ(static_cast(0xbbccdd44), t.swr_2); CHECK_EQ(static_cast(0xaabbccdd), t.swr_3); } } } TEST(MIPS12) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { int32_t x; int32_t y; int32_t y1; int32_t y2; int32_t y3; int32_t y4; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ mov(t2, fp); // Save frame pointer. __ mov(fp, a0); // Access struct T by fp. __ lw(a4, MemOperand(a0, offsetof(T, y))); __ lw(a7, MemOperand(a0, offsetof(T, y4))); __ addu(a5, a4, a7); __ subu(t0, a4, a7); __ nop(); __ push(a4); // These instructions disappear after opt. __ Pop(); __ addu(a4, a4, a4); __ nop(); __ Pop(); // These instructions disappear after opt. __ push(a7); __ nop(); __ push(a7); // These instructions disappear after opt. __ pop(a7); __ nop(); __ push(a7); __ pop(t0); __ nop(); __ sw(a4, MemOperand(fp, offsetof(T, y))); __ lw(a4, MemOperand(fp, offsetof(T, y))); __ nop(); __ sw(a4, MemOperand(fp, offsetof(T, y))); __ lw(a5, MemOperand(fp, offsetof(T, y))); __ nop(); __ push(a5); __ lw(a5, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a6); __ nop(); __ push(a6); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a7); __ nop(); __ mov(fp, t2); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.x = 1; t.y = 2; t.y1 = 3; t.y2 = 4; t.y3 = 0XBABA; t.y4 = 0xDEDA; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(3, t.y1); } TEST(MIPS13) { // Test Cvt_d_uw and Trunc_uw_d macros. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double cvt_big_out; double cvt_small_out; uint32_t trunc_big_out; uint32_t trunc_small_out; uint32_t cvt_big_in; uint32_t cvt_small_in; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ sw(a4, MemOperand(a0, offsetof(T, cvt_small_in))); __ Cvt_d_uw(f10, a4); __ sdc1(f10, MemOperand(a0, offsetof(T, cvt_small_out))); __ Trunc_uw_d(f10, f10, f4); __ swc1(f10, MemOperand(a0, offsetof(T, trunc_small_out))); __ sw(a4, MemOperand(a0, offsetof(T, cvt_big_in))); __ Cvt_d_uw(f8, a4); __ sdc1(f8, MemOperand(a0, offsetof(T, cvt_big_out))); __ Trunc_uw_d(f8, f8, f4); __ swc1(f8, MemOperand(a0, offsetof(T, trunc_big_out))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.cvt_big_in = 0xFFFFFFFF; t.cvt_small_in = 333; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(t.cvt_big_out, static_cast(t.cvt_big_in)); CHECK_EQ(t.cvt_small_out, static_cast(t.cvt_small_in)); CHECK_EQ(static_cast(t.trunc_big_out), static_cast(t.cvt_big_in)); CHECK_EQ(static_cast(t.trunc_small_out), static_cast(t.cvt_small_in)); } TEST(MIPS14) { // Test round, floor, ceil, trunc, cvt. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); #define ROUND_STRUCT_ELEMENT(x) \ uint32_t x##_isNaN2008; \ int32_t x##_up_out; \ int32_t x##_down_out; \ int32_t neg_##x##_up_out; \ int32_t neg_##x##_down_out; \ uint32_t x##_err1_out; \ uint32_t x##_err2_out; \ uint32_t x##_err3_out; \ uint32_t x##_err4_out; \ int32_t x##_invalid_result; typedef struct { double round_up_in; double round_down_in; double neg_round_up_in; double neg_round_down_in; double err1_in; double err2_in; double err3_in; double err4_in; ROUND_STRUCT_ELEMENT(round) ROUND_STRUCT_ELEMENT(floor) ROUND_STRUCT_ELEMENT(ceil) ROUND_STRUCT_ELEMENT(trunc) ROUND_STRUCT_ELEMENT(cvt) } T; T t; #undef ROUND_STRUCT_ELEMENT MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); // Save FCSR. __ cfc1(a1, FCSR); // Disable FPU exceptions. __ ctc1(zero_reg, FCSR); #define RUN_ROUND_TEST(x) \ __ cfc1(t0, FCSR);\ __ sw(t0, MemOperand(a0, offsetof(T, x##_isNaN2008))); \ __ ldc1(f0, MemOperand(a0, offsetof(T, round_up_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_up_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, round_down_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_down_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, neg_round_up_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, neg_##x##_up_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, neg_round_down_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, neg_##x##_down_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err1_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err1_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err2_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err2_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err3_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err3_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err4_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err4_out))); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_invalid_result))); RUN_ROUND_TEST(round) RUN_ROUND_TEST(floor) RUN_ROUND_TEST(ceil) RUN_ROUND_TEST(trunc) RUN_ROUND_TEST(cvt) // Restore FCSR. __ ctc1(a1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.round_up_in = 123.51; t.round_down_in = 123.49; t.neg_round_up_in = -123.5; t.neg_round_down_in = -123.49; t.err1_in = 123.51; t.err2_in = 1; t.err3_in = static_cast(1) + 0xFFFFFFFF; t.err4_in = NAN; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); #define GET_FPU_ERR(x) (static_cast(x & kFCSRFlagMask)) #define CHECK_NAN2008(x) (x & kFCSRNaN2008FlagMask) #define CHECK_ROUND_RESULT(type) \ CHECK(GET_FPU_ERR(t.type##_err1_out) & kFCSRInexactFlagMask); \ CHECK_EQ(0, GET_FPU_ERR(t.type##_err2_out)); \ CHECK(GET_FPU_ERR(t.type##_err3_out) & kFCSRInvalidOpFlagMask); \ CHECK(GET_FPU_ERR(t.type##_err4_out) & kFCSRInvalidOpFlagMask); \ if (CHECK_NAN2008(t.type##_isNaN2008) && kArchVariant == kMips64r6) { \ CHECK_EQ(static_cast(0), t.type##_invalid_result);\ } else { \ CHECK_EQ(static_cast(kFPUInvalidResult), t.type##_invalid_result);\ } CHECK_ROUND_RESULT(round); CHECK_ROUND_RESULT(floor); CHECK_ROUND_RESULT(ceil); CHECK_ROUND_RESULT(cvt); } TEST(MIPS15) { // Test chaining of label usages within instructions (issue 1644). CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); Assembler assm(isolate, NULL, 0); Label target; __ beq(v0, v1, &target); __ nop(); __ bne(v0, v1, &target); __ nop(); __ bind(&target); __ nop(); } // ----- mips64 tests ----------------------------------------------- TEST(MIPS16) { // Test 64-bit memory loads and stores. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); struct T { int64_t r1; int64_t r2; int64_t r3; int64_t r4; int64_t r5; int64_t r6; int64_t r7; int64_t r8; int64_t r9; int64_t r10; int64_t r11; int64_t r12; uint32_t ui; int32_t si; }; T t; Assembler assm(isolate, NULL, 0); Label L, C; // Basic 32-bit word load/store, with un-signed data. __ lw(a4, MemOperand(a0, offsetof(T, ui))); __ sw(a4, MemOperand(a0, offsetof(T, r1))); // Check that the data got zero-extended into 64-bit a4. __ sd(a4, MemOperand(a0, offsetof(T, r2))); // Basic 32-bit word load/store, with SIGNED data. __ lw(a5, MemOperand(a0, offsetof(T, si))); __ sw(a5, MemOperand(a0, offsetof(T, r3))); // Check that the data got sign-extended into 64-bit a4. __ sd(a5, MemOperand(a0, offsetof(T, r4))); // 32-bit UNSIGNED word load/store, with SIGNED data. __ lwu(a6, MemOperand(a0, offsetof(T, si))); __ sw(a6, MemOperand(a0, offsetof(T, r5))); // Check that the data got zero-extended into 64-bit a4. __ sd(a6, MemOperand(a0, offsetof(T, r6))); // lh with positive data. __ lh(a5, MemOperand(a0, offsetof(T, ui))); __ sw(a5, MemOperand(a0, offsetof(T, r7))); // lh with negative data. __ lh(a6, MemOperand(a0, offsetof(T, si))); __ sw(a6, MemOperand(a0, offsetof(T, r8))); // lhu with negative data. __ lhu(a7, MemOperand(a0, offsetof(T, si))); __ sw(a7, MemOperand(a0, offsetof(T, r9))); // lb with negative data. __ lb(t0, MemOperand(a0, offsetof(T, si))); __ sw(t0, MemOperand(a0, offsetof(T, r10))); // sh writes only 1/2 of word. __ lw(a4, MemOperand(a0, offsetof(T, ui))); __ sh(a4, MemOperand(a0, offsetof(T, r11))); __ lw(a4, MemOperand(a0, offsetof(T, si))); __ sh(a4, MemOperand(a0, offsetof(T, r12))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.ui = 0x44332211; t.si = 0x99aabbcc; t.r1 = 0x5555555555555555; t.r2 = 0x5555555555555555; t.r3 = 0x5555555555555555; t.r4 = 0x5555555555555555; t.r5 = 0x5555555555555555; t.r6 = 0x5555555555555555; t.r7 = 0x5555555555555555; t.r8 = 0x5555555555555555; t.r9 = 0x5555555555555555; t.r10 = 0x5555555555555555; t.r11 = 0x5555555555555555; t.r12 = 0x5555555555555555; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); if (kArchEndian == kLittle) { // Unsigned data, 32 & 64 CHECK_EQ(static_cast(0x5555555544332211L), t.r1); // lw, sw. CHECK_EQ(static_cast(0x0000000044332211L), t.r2); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x5555555599aabbccL), t.r3); // lw, sw. CHECK_EQ(static_cast(0xffffffff99aabbccL), t.r4); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x5555555599aabbccL), t.r5); // lwu, sw. CHECK_EQ(static_cast(0x0000000099aabbccL), t.r6); // sd. // lh with unsigned and signed data. CHECK_EQ(static_cast(0x5555555500002211L), t.r7); // lh, sw. CHECK_EQ(static_cast(0x55555555ffffbbccL), t.r8); // lh, sw. // lhu with signed data. CHECK_EQ(static_cast(0x555555550000bbccL), t.r9); // lhu, sw. // lb with signed data. CHECK_EQ(static_cast(0x55555555ffffffccL), t.r10); // lb, sw. // sh with unsigned and signed data. CHECK_EQ(static_cast(0x5555555555552211L), t.r11); // lw, sh. CHECK_EQ(static_cast(0x555555555555bbccL), t.r12); // lw, sh. } else { // Unsigned data, 32 & 64 CHECK_EQ(static_cast(0x4433221155555555L), t.r1); // lw, sw. CHECK_EQ(static_cast(0x0000000044332211L), t.r2); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x99aabbcc55555555L), t.r3); // lw, sw. CHECK_EQ(static_cast(0xffffffff99aabbccL), t.r4); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x99aabbcc55555555L), t.r5); // lwu, sw. CHECK_EQ(static_cast(0x0000000099aabbccL), t.r6); // sd. // lh with unsigned and signed data. CHECK_EQ(static_cast(0x0000443355555555L), t.r7); // lh, sw. CHECK_EQ(static_cast(0xffff99aa55555555L), t.r8); // lh, sw. // lhu with signed data. CHECK_EQ(static_cast(0x000099aa55555555L), t.r9); // lhu, sw. // lb with signed data. CHECK_EQ(static_cast(0xffffff9955555555L), t.r10); // lb, sw. // sh with unsigned and signed data. CHECK_EQ(static_cast(0x2211555555555555L), t.r11); // lw, sh. CHECK_EQ(static_cast(0xbbcc555555555555L), t.r12); // lw, sh. } } // ----------------------mips64r6 specific tests---------------------- TEST(seleqz_selnez) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { int a; int b; int c; int d; double e; double f; double g; double h; float i; float j; float k; float l; } Test; Test test; // Integer part of test. __ addiu(t1, zero_reg, 1); // t1 = 1 __ seleqz(t3, t1, zero_reg); // t3 = 1 __ sw(t3, MemOperand(a0, offsetof(Test, a))); // a = 1 __ seleqz(t2, t1, t1); // t2 = 0 __ sw(t2, MemOperand(a0, offsetof(Test, b))); // b = 0 __ selnez(t3, t1, zero_reg); // t3 = 1; __ sw(t3, MemOperand(a0, offsetof(Test, c))); // c = 0 __ selnez(t3, t1, t1); // t3 = 1 __ sw(t3, MemOperand(a0, offsetof(Test, d))); // d = 1 // Floating point part of test. __ ldc1(f0, MemOperand(a0, offsetof(Test, e)) ); // src __ ldc1(f2, MemOperand(a0, offsetof(Test, f)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, i)) ); // src __ lwc1(f10, MemOperand(a0, offsetof(Test, j)) ); // test __ seleqz_d(f4, f0, f2); __ selnez_d(f6, f0, f2); __ seleqz_s(f12, f8, f10); __ selnez_s(f14, f8, f10); __ sdc1(f4, MemOperand(a0, offsetof(Test, g)) ); // src __ sdc1(f6, MemOperand(a0, offsetof(Test, h)) ); // src __ swc1(f12, MemOperand(a0, offsetof(Test, k)) ); // src __ swc1(f14, MemOperand(a0, offsetof(Test, l)) ); // src __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.a, 1); CHECK_EQ(test.b, 0); CHECK_EQ(test.c, 0); CHECK_EQ(test.d, 1); const int test_size = 3; const int input_size = 5; double inputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double outputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float inputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float outputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.e = inputs_D[i]; test.f = tests_D[j]; test.i = inputs_S[i]; test.j = tests_S[j]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, outputs_D[i]); CHECK_EQ(test.h, 0); CHECK_EQ(test.k, outputs_S[i]); CHECK_EQ(test.l, 0); test.f = tests_D[j+1]; test.j = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, 0); CHECK_EQ(test.h, outputs_D[i]); CHECK_EQ(test.k, 0); CHECK_EQ(test.l, outputs_S[i]); } } } } TEST(min_max) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); struct TestFloat { double a; double b; double c; double d; float e; float f; float g; float h; }; TestFloat test; const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); const int kTableLength = 13; double inputsa[kTableLength] = {2.0, 3.0, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = {3.0, 2.0, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double outputsdmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double outputsdmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputse[kTableLength] = {2.0, 3.0, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsf[kTableLength] = {3.0, 2.0, 3.0, fnan, 0.0, -0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float outputsfmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float outputsfmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a))); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, b))); __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, e))); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, f))); __ min_d(f10, f4, f8); __ max_d(f12, f4, f8); __ min_s(f14, f2, f6); __ max_s(f16, f2, f6); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, c))); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, d))); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, g))); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, h))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 4; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.e = inputse[i]; test.f = inputsf[i]; CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0); CHECK_EQ(0, memcmp(&test.c, &outputsdmin[i], sizeof(test.c))); CHECK_EQ(0, memcmp(&test.d, &outputsdmax[i], sizeof(test.d))); CHECK_EQ(0, memcmp(&test.g, &outputsfmin[i], sizeof(test.g))); CHECK_EQ(0, memcmp(&test.h, &outputsfmax[i], sizeof(test.h))); } } } TEST(rint_d) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; int fcsr; }TestFloat; TestFloat test; double inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E+308, 6.27463370218383111104242366943E-307, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ ctc1(t0, FCSR); __ rint_d(f8, f4); __ sdc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(sel) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { double dd; double ds; double dt; float fd; float fs; float ft; } Test; Test test; __ ldc1(f0, MemOperand(a0, offsetof(Test, dd)) ); // test __ ldc1(f2, MemOperand(a0, offsetof(Test, ds)) ); // src1 __ ldc1(f4, MemOperand(a0, offsetof(Test, dt)) ); // src2 __ lwc1(f6, MemOperand(a0, offsetof(Test, fd)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, fs)) ); // src1 __ lwc1(f10, MemOperand(a0, offsetof(Test, ft)) ); // src2 __ sel_d(f0, f2, f4); __ sel_s(f6, f8, f10); __ sdc1(f0, MemOperand(a0, offsetof(Test, dd)) ); __ swc1(f6, MemOperand(a0, offsetof(Test, fd)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); const int test_size = 3; const int input_size = 5; double inputs_dt[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double inputs_ds[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; float inputs_ft[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float inputs_fs[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.dt = inputs_dt[i]; test.dd = tests_D[j]; test.ds = inputs_ds[i]; test.ft = inputs_ft[i]; test.fd = tests_S[j]; test.fs = inputs_fs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_ds[i]); CHECK_EQ(test.fd, inputs_fs[i]); test.dd = tests_D[j+1]; test.fd = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_dt[i]); CHECK_EQ(test.fd, inputs_ft[i]); } } } } TEST(rint_s) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; int fcsr; }TestFloat; TestFloat test; float inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E+38, 6.27463370218383111104242366943E-37, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; float* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ rint_s(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(mina_maxa) { if (kArchVariant == kMips64r6) { const int kTableLength = 23; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); struct TestFloat { double a; double b; double resd; double resd1; float c; float d; float resf; float resf1; }; TestFloat test; double inputsa[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = { 4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double resd[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double resd1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputsc[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsd[kTableLength] = {4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, fnan, -0.0, 0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float resf[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float resf1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ lwc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ lwc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ mina_d(f6, f2, f4); __ mina_s(f12, f8, f10); __ maxa_d(f14, f2, f4); __ maxa_s(f16, f8, f10); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, resf)) ); __ sdc1(f6, MemOperand(a0, offsetof(TestFloat, resd)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resf1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resd1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.c = inputsc[i]; test.d = inputsd[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if (i < kTableLength - 1) { CHECK_EQ(test.resd, resd[i]); CHECK_EQ(test.resf, resf[i]); CHECK_EQ(test.resd1, resd1[i]); CHECK_EQ(test.resf1, resf1[i]); } else { CHECK(std::isnan(test.resd)); CHECK(std::isnan(test.resf)); CHECK(std::isnan(test.resd1)); CHECK(std::isnan(test.resf1)); } } } } // ----------------------mips64r2 specific tests---------------------- TEST(trunc_l) { if (kArchVariant == kMips64r2) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; // a trunc result int64_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_l_d(f8, f4); __ trunc_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } } TEST(movz_movn) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { int64_t rt; double a; double b; double bold; double b1; double bold1; float c; float d; float dold; float d1; float dold1; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ld(t0, MemOperand(a0, offsetof(TestFloat, rt))); __ Move(f12, 0.0); __ Move(f10, 0.0); __ Move(f16, 0.0); __ Move(f14, 0.0); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, bold)) ); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, dold)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, bold1)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, dold1)) ); __ movz_s(f10, f6, t0); __ movz_d(f12, f2, t0); __ movn_s(f14, f6, t0); __ movn_d(f16, f2, t0); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, b)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, d1)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, b1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; test.rt = 1; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, test.bold); CHECK_EQ(test.d, test.dold); CHECK_EQ(test.b1, outputs_D[i]); CHECK_EQ(test.d1, outputs_S[i]); test.rt = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); CHECK_EQ(test.b1, test.bold1); CHECK_EQ(test.d1, test.dold1); } } } TEST(movt_movd) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); typedef struct test_float { double srcd; double dstd; double dstdold; double dstd1; double dstdold1; float srcf; float dstf; float dstfold; float dstf1; float dstfold1; int32_t cc; int32_t fcsr; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; double inputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; int condition_flags[8] = {0, 1, 2, 3, 4, 5, 6, 7}; for (int i = 0; i < kTableLength; i++) { test.srcd = inputs_D[i]; test.srcf = inputs_S[i]; for (int j = 0; j< 8; j++) { test.cc = condition_flags[j]; if (test.cc == 0) { test.fcsr = 1 << 23; } else { test.fcsr = 1 << (24+condition_flags[j]); } HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, srcd)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, srcf)) ); __ lw(t1, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t0, FCSR); __ ctc1(t1, FCSR); __ li(t2, 0x0); __ mtc1(t2, f12); __ mtc1(t2, f10); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold)) ); __ movt_s(f12, f4, test.cc); __ movt_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold1)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold1)) ); __ movf_s(f12, f4, test.cc); __ movf_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf1)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd1)) ); __ ctc1(t0, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, outputs_S[i]); CHECK_EQ(test.dstd, outputs_D[i]); CHECK_EQ(test.dstf1, test.dstfold1); CHECK_EQ(test.dstd1, test.dstdold1); test.fcsr = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, test.dstfold); CHECK_EQ(test.dstd, test.dstdold); CHECK_EQ(test.dstf1, outputs_S[i]); CHECK_EQ(test.dstd1, outputs_D[i]); } } } } // ----------------------tests for all archs-------------------------- TEST(cvt_w_d) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; int32_t b; int fcsr; }Test; const int kTableLength = 24; double inputs[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, 2147483653.0 }; double outputs_RN[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RZ[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RP[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RM[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lw(t0, MemOperand(a0, offsetof(Test, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ cvt_w_d(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(Test, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } TEST(trunc_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_w_d(f8, f4); __ trunc_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_w_d(f8, f4); __ round_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_l_d(f8, f4); __ round_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(sub) { const int kTableLength = 12; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; double inputft_D[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; double outputs_D[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; float inputfs_S[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; float inputft_S[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; float outputs_S[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sub_s(f6, f2, f4); __ sub_d(f12, f8, f10); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(sqrt_rsqrt_recip) { const int kTableLength = 4; const double deltaDouble = 2E-15; const float deltaFloat = 2E-7; const float sqrt2_s = sqrt(2); const double sqrt2_d = sqrt(2); CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; float resultS1; float resultS2; double c; double resultD; double resultD1; double resultD2; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 0.0L, 4.0L, 2.0L, 4e-28L }; double outputs_D[kTableLength] = { 0.0L, 2.0L, sqrt2_d, 2e-14L }; float inputs_S[kTableLength] = { 0.0, 4.0, 2.0, 4e-28 }; float outputs_S[kTableLength] = { 0.0, 2.0, sqrt2_s, 2e-14 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ sqrt_s(f6, f2); __ sqrt_d(f12, f8); __ rsqrt_d(f14, f8); __ rsqrt_s(f16, f2); __ recip_d(f18, f8); __ recip_s(f4, f2); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resultS1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resultD1)) ); __ swc1(f4, MemOperand(a0, offsetof(TestFloat, resultS2)) ); __ sdc1(f18, MemOperand(a0, offsetof(TestFloat, resultD2)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { float f1; double d1; test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); if (i != 0) { f1 = test.resultS1 - 1.0F/outputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD1 - 1.0L/outputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); f1 = test.resultS2 - 1.0F/inputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD2 - 1.0L/inputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); } else { CHECK_EQ(test.resultS1, 1.0F/outputs_S[i]); CHECK_EQ(test.resultD1, 1.0L/outputs_D[i]); CHECK_EQ(test.resultS2, 1.0F/inputs_S[i]); CHECK_EQ(test.resultD2, 1.0L/inputs_D[i]); } } } TEST(neg) { const int kTableLength = 2; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; double c; double resultD; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 4.0, -2.0 }; double outputs_D[kTableLength] = { -4.0, 2.0 }; float inputs_S[kTableLength] = { 4.0, -2.0 }; float outputs_S[kTableLength] = { -4.0, 2.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ neg_s(f6, f2); __ neg_d(f12, f8); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F1 f = FUNCTION_CAST(code->entry()); int64_t res = reinterpret_cast( CALL_GENERATED_CODE(isolate, f, 50, 0, 0, 0, 0)); CHECK_EQ(1275L, res); } TEST(MIPS2) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); Label exit, error; // ----- Test all instructions. // Test lui, ori, and addiu, used in the li pseudo-instruction. // This way we can then safely load registers with chosen values. __ ori(a4, zero_reg, 0); __ lui(a4, 0x1234); __ ori(a4, a4, 0); __ ori(a4, a4, 0x0f0f); __ ori(a4, a4, 0xf0f0); __ addiu(a5, a4, 1); __ addiu(a6, a5, -0x10); // Load values in temporary registers. __ li(a4, 0x00000004); __ li(a5, 0x00001234); __ li(a6, 0x12345678); __ li(a7, 0x7fffffff); __ li(t0, 0xfffffffc); __ li(t1, 0xffffedcc); __ li(t2, 0xedcba988); __ li(t3, 0x80000000); // SPECIAL class. __ srl(v0, a6, 8); // 0x00123456 __ sll(v0, v0, 11); // 0x91a2b000 __ sra(v0, v0, 3); // 0xf2345600 __ srav(v0, v0, a4); // 0xff234560 __ sllv(v0, v0, a4); // 0xf2345600 __ srlv(v0, v0, a4); // 0x0f234560 __ Branch(&error, ne, v0, Operand(0x0f234560)); __ nop(); __ addu(v0, a4, a5); // 0x00001238 __ subu(v0, v0, a4); // 0x00001234 __ Branch(&error, ne, v0, Operand(0x00001234)); __ nop(); __ addu(v1, a7, a4); // 32bit addu result is sign-extended into 64bit reg. __ Branch(&error, ne, v1, Operand(0xffffffff80000003)); __ nop(); __ subu(v1, t3, a4); // 0x7ffffffc __ Branch(&error, ne, v1, Operand(0x7ffffffc)); __ nop(); __ and_(v0, a5, a6); // 0x0000000000001230 __ or_(v0, v0, a5); // 0x0000000000001234 __ xor_(v0, v0, a6); // 0x000000001234444c __ nor(v0, v0, a6); // 0xffffffffedcba987 __ Branch(&error, ne, v0, Operand(0xffffffffedcba983)); __ nop(); // Shift both 32bit number to left, to preserve meaning of next comparison. __ dsll32(a7, a7, 0); __ dsll32(t3, t3, 0); __ slt(v0, t3, a7); __ Branch(&error, ne, v0, Operand(0x1)); __ nop(); __ sltu(v0, t3, a7); __ Branch(&error, ne, v0, Operand(zero_reg)); __ nop(); // Restore original values in registers. __ dsrl32(a7, a7, 0); __ dsrl32(t3, t3, 0); // End of SPECIAL class. __ addiu(v0, zero_reg, 0x7421); // 0x00007421 __ addiu(v0, v0, -0x1); // 0x00007420 __ addiu(v0, v0, -0x20); // 0x00007400 __ Branch(&error, ne, v0, Operand(0x00007400)); __ nop(); __ addiu(v1, a7, 0x1); // 0x80000000 - result is sign-extended. __ Branch(&error, ne, v1, Operand(0xffffffff80000000)); __ nop(); __ slti(v0, a5, 0x00002000); // 0x1 __ slti(v0, v0, 0xffff8000); // 0x0 __ Branch(&error, ne, v0, Operand(zero_reg)); __ nop(); __ sltiu(v0, a5, 0x00002000); // 0x1 __ sltiu(v0, v0, 0x00008000); // 0x1 __ Branch(&error, ne, v0, Operand(0x1)); __ nop(); __ andi(v0, a5, 0xf0f0); // 0x00001030 __ ori(v0, v0, 0x8a00); // 0x00009a30 __ xori(v0, v0, 0x83cc); // 0x000019fc __ Branch(&error, ne, v0, Operand(0x000019fc)); __ nop(); __ lui(v1, 0x8123); // Result is sign-extended into 64bit register. __ Branch(&error, ne, v1, Operand(0xffffffff81230000)); __ nop(); // Bit twiddling instructions & conditional moves. // Uses a4-t3 as set above. __ Clz(v0, a4); // 29 __ Clz(v1, a5); // 19 __ addu(v0, v0, v1); // 48 __ Clz(v1, a6); // 3 __ addu(v0, v0, v1); // 51 __ Clz(v1, t3); // 0 __ addu(v0, v0, v1); // 51 __ Branch(&error, ne, v0, Operand(51)); __ Movn(a0, a7, a4); // Move a0<-a7 (a4 is NOT 0). __ Ins(a0, a5, 12, 8); // 0x7ff34fff __ Branch(&error, ne, a0, Operand(0x7ff34fff)); __ Movz(a0, t2, t3); // a0 not updated (t3 is NOT 0). __ Ext(a1, a0, 8, 12); // 0x34f __ Branch(&error, ne, a1, Operand(0x34f)); __ Movz(a0, t2, v1); // a0<-t2, v0 is 0, from 8 instr back. __ Branch(&error, ne, a0, Operand(t2)); // Everything was correctly executed. Load the expected result. __ li(v0, 0x31415926); __ b(&exit); __ nop(); __ bind(&error); // Got an error. Return a wrong result. __ li(v0, 666); __ bind(&exit); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F2 f = FUNCTION_CAST(code->entry()); int64_t res = reinterpret_cast( CALL_GENERATED_CODE(isolate, f, 0xab0, 0xc, 0, 0, 0)); CHECK_EQ(0x31415926L, res); } TEST(MIPS3) { // Test floating point instructions. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double a; double b; double c; double d; double e; double f; double g; double h; double i; float fa; float fb; float fc; float fd; float fe; float ff; float fg; } T; T t; // Create a function that accepts &t, and loads, manipulates, and stores // the doubles t.a ... t.f. MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); Label L, C; // Double precision floating point instructions. __ ldc1(f4, MemOperand(a0, offsetof(T, a)) ); __ ldc1(f6, MemOperand(a0, offsetof(T, b)) ); __ add_d(f8, f4, f6); __ sdc1(f8, MemOperand(a0, offsetof(T, c)) ); // c = a + b. __ mov_d(f10, f8); // c __ neg_d(f12, f6); // -b __ sub_d(f10, f10, f12); __ sdc1(f10, MemOperand(a0, offsetof(T, d)) ); // d = c - (-b). __ sdc1(f4, MemOperand(a0, offsetof(T, b)) ); // b = a. __ li(a4, 120); __ mtc1(a4, f14); __ cvt_d_w(f14, f14); // f14 = 120.0. __ mul_d(f10, f10, f14); __ sdc1(f10, MemOperand(a0, offsetof(T, e)) ); // e = d * 120 = 1.8066e16. __ div_d(f12, f10, f4); __ sdc1(f12, MemOperand(a0, offsetof(T, f)) ); // f = e / a = 120.44. __ sqrt_d(f14, f12); __ sdc1(f14, MemOperand(a0, offsetof(T, g)) ); // g = sqrt(f) = 10.97451593465515908537 if (kArchVariant == kMips64r2) { __ ldc1(f4, MemOperand(a0, offsetof(T, h)) ); __ ldc1(f6, MemOperand(a0, offsetof(T, i)) ); __ madd_d(f14, f6, f4, f6); __ sdc1(f14, MemOperand(a0, offsetof(T, h)) ); } // Single precision floating point instructions. __ lwc1(f4, MemOperand(a0, offsetof(T, fa)) ); __ lwc1(f6, MemOperand(a0, offsetof(T, fb)) ); __ add_s(f8, f4, f6); __ swc1(f8, MemOperand(a0, offsetof(T, fc)) ); // fc = fa + fb. __ neg_s(f10, f6); // -fb __ sub_s(f10, f8, f10); __ swc1(f10, MemOperand(a0, offsetof(T, fd)) ); // fd = fc - (-fb). __ swc1(f4, MemOperand(a0, offsetof(T, fb)) ); // fb = fa. __ li(t0, 120); __ mtc1(t0, f14); __ cvt_s_w(f14, f14); // f14 = 120.0. __ mul_s(f10, f10, f14); __ swc1(f10, MemOperand(a0, offsetof(T, fe)) ); // fe = fd * 120 __ div_s(f12, f10, f4); __ swc1(f12, MemOperand(a0, offsetof(T, ff)) ); // ff = fe / fa __ sqrt_s(f14, f12); __ swc1(f14, MemOperand(a0, offsetof(T, fg)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); // Double test values. t.a = 1.5e14; t.b = 2.75e11; t.c = 0.0; t.d = 0.0; t.e = 0.0; t.f = 0.0; t.h = 1.5; t.i = 2.75; // Single test values. t.fa = 1.5e6; t.fb = 2.75e4; t.fc = 0.0; t.fd = 0.0; t.fe = 0.0; t.ff = 0.0; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); // Expected double results. CHECK_EQ(1.5e14, t.a); CHECK_EQ(1.5e14, t.b); CHECK_EQ(1.50275e14, t.c); CHECK_EQ(1.50550e14, t.d); CHECK_EQ(1.8066e16, t.e); CHECK_EQ(120.44, t.f); CHECK_EQ(10.97451593465515908537, t.g); if (kArchVariant == kMips64r2) { CHECK_EQ(6.875, t.h); } // Expected single results. CHECK_EQ(1.5e6, t.fa); CHECK_EQ(1.5e6, t.fb); CHECK_EQ(1.5275e06, t.fc); CHECK_EQ(1.5550e06, t.fd); CHECK_EQ(1.866e08, t.fe); CHECK_EQ(124.40000152587890625, t.ff); CHECK_EQ(11.1534748077392578125, t.fg); } TEST(MIPS4) { // Test moves between floating point and integer registers. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double a; double b; double c; double d; int64_t high; int64_t low; } T; T t; Assembler assm(isolate, NULL, 0); Label L, C; __ ldc1(f4, MemOperand(a0, offsetof(T, a))); __ ldc1(f5, MemOperand(a0, offsetof(T, b))); // Swap f4 and f5, by using 3 integer registers, a4-a6, // both two 32-bit chunks, and one 64-bit chunk. // mXhc1 is mips32/64-r2 only, not r1, // but we will not support r1 in practice. __ mfc1(a4, f4); __ mfhc1(a5, f4); __ dmfc1(a6, f5); __ mtc1(a4, f5); __ mthc1(a5, f5); __ dmtc1(a6, f4); // Store the swapped f4 and f5 back to memory. __ sdc1(f4, MemOperand(a0, offsetof(T, a))); __ sdc1(f5, MemOperand(a0, offsetof(T, c))); // Test sign extension of move operations from coprocessor. __ ldc1(f4, MemOperand(a0, offsetof(T, d))); __ mfhc1(a4, f4); __ mfc1(a5, f4); __ sd(a4, MemOperand(a0, offsetof(T, high))); __ sd(a5, MemOperand(a0, offsetof(T, low))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.a = 1.5e22; t.b = 2.75e11; t.c = 17.17; t.d = -2.75e11; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(2.75e11, t.a); CHECK_EQ(2.75e11, t.b); CHECK_EQ(1.5e22, t.c); CHECK_EQ(static_cast(0xffffffffc25001d1L), t.high); CHECK_EQ(static_cast(0xffffffffbf800000L), t.low); } TEST(MIPS5) { // Test conversions between doubles and integers. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double a; double b; int i; int j; } T; T t; Assembler assm(isolate, NULL, 0); Label L, C; // Load all structure elements to registers. __ ldc1(f4, MemOperand(a0, offsetof(T, a)) ); __ ldc1(f6, MemOperand(a0, offsetof(T, b)) ); __ lw(a4, MemOperand(a0, offsetof(T, i)) ); __ lw(a5, MemOperand(a0, offsetof(T, j)) ); // Convert double in f4 to int in element i. __ cvt_w_d(f8, f4); __ mfc1(a6, f8); __ sw(a6, MemOperand(a0, offsetof(T, i)) ); // Convert double in f6 to int in element j. __ cvt_w_d(f10, f6); __ mfc1(a7, f10); __ sw(a7, MemOperand(a0, offsetof(T, j)) ); // Convert int in original i (a4) to double in a. __ mtc1(a4, f12); __ cvt_d_w(f0, f12); __ sdc1(f0, MemOperand(a0, offsetof(T, a)) ); // Convert int in original j (a5) to double in b. __ mtc1(a5, f14); __ cvt_d_w(f2, f14); __ sdc1(f2, MemOperand(a0, offsetof(T, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.a = 1.5e4; t.b = 2.75e8; t.i = 12345678; t.j = -100000; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(12345678.0, t.a); CHECK_EQ(-100000.0, t.b); CHECK_EQ(15000, t.i); CHECK_EQ(275000000, t.j); } TEST(MIPS6) { // Test simple memory loads and stores. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { uint32_t ui; int32_t si; int32_t r1; int32_t r2; int32_t r3; int32_t r4; int32_t r5; int32_t r6; } T; T t; Assembler assm(isolate, NULL, 0); Label L, C; // Basic word load/store. __ lw(a4, MemOperand(a0, offsetof(T, ui)) ); __ sw(a4, MemOperand(a0, offsetof(T, r1)) ); // lh with positive data. __ lh(a5, MemOperand(a0, offsetof(T, ui)) ); __ sw(a5, MemOperand(a0, offsetof(T, r2)) ); // lh with negative data. __ lh(a6, MemOperand(a0, offsetof(T, si)) ); __ sw(a6, MemOperand(a0, offsetof(T, r3)) ); // lhu with negative data. __ lhu(a7, MemOperand(a0, offsetof(T, si)) ); __ sw(a7, MemOperand(a0, offsetof(T, r4)) ); // lb with negative data. __ lb(t0, MemOperand(a0, offsetof(T, si)) ); __ sw(t0, MemOperand(a0, offsetof(T, r5)) ); // sh writes only 1/2 of word. __ lui(t1, 0x3333); __ ori(t1, t1, 0x3333); __ sw(t1, MemOperand(a0, offsetof(T, r6)) ); __ lhu(t1, MemOperand(a0, offsetof(T, si)) ); __ sh(t1, MemOperand(a0, offsetof(T, r6)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.ui = 0x11223344; t.si = 0x99aabbcc; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(static_cast(0x11223344), t.r1); if (kArchEndian == kLittle) { CHECK_EQ(static_cast(0x3344), t.r2); CHECK_EQ(static_cast(0xffffbbcc), t.r3); CHECK_EQ(static_cast(0x0000bbcc), t.r4); CHECK_EQ(static_cast(0xffffffcc), t.r5); CHECK_EQ(static_cast(0x3333bbcc), t.r6); } else { CHECK_EQ(static_cast(0x1122), t.r2); CHECK_EQ(static_cast(0xffff99aa), t.r3); CHECK_EQ(static_cast(0x000099aa), t.r4); CHECK_EQ(static_cast(0xffffff99), t.r5); CHECK_EQ(static_cast(0x99aa3333), t.r6); } } TEST(MIPS7) { // Test floating point compare and branch instructions. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double a; double b; double c; double d; double e; double f; int32_t result; } T; T t; // Create a function that accepts &t, and loads, manipulates, and stores // the doubles t.a ... t.f. MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); Label neither_is_nan, less_than, outa_here; __ ldc1(f4, MemOperand(a0, offsetof(T, a)) ); __ ldc1(f6, MemOperand(a0, offsetof(T, b)) ); if (kArchVariant != kMips64r6) { __ c(UN, D, f4, f6); __ bc1f(&neither_is_nan); } else { __ cmp(UN, L, f2, f4, f6); __ bc1eqz(&neither_is_nan, f2); } __ nop(); __ sw(zero_reg, MemOperand(a0, offsetof(T, result)) ); __ Branch(&outa_here); __ bind(&neither_is_nan); if (kArchVariant == kMips64r6) { __ cmp(OLT, L, f2, f6, f4); __ bc1nez(&less_than, f2); } else { __ c(OLT, D, f6, f4, 2); __ bc1t(&less_than, 2); } __ nop(); __ sw(zero_reg, MemOperand(a0, offsetof(T, result)) ); __ Branch(&outa_here); __ bind(&less_than); __ Addu(a4, zero_reg, Operand(1)); __ sw(a4, MemOperand(a0, offsetof(T, result)) ); // Set true. // This test-case should have additional tests. __ bind(&outa_here); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.a = 1.5e14; t.b = 2.75e11; t.c = 2.0; t.d = -4.0; t.e = 0.0; t.f = 0.0; t.result = 0; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(1.5e14, t.a); CHECK_EQ(2.75e11, t.b); CHECK_EQ(1, t.result); } TEST(MIPS8) { if (kArchVariant == kMips64r2) { // Test ROTR and ROTRV instructions. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { int32_t input; int32_t result_rotr_4; int32_t result_rotr_8; int32_t result_rotr_12; int32_t result_rotr_16; int32_t result_rotr_20; int32_t result_rotr_24; int32_t result_rotr_28; int32_t result_rotrv_4; int32_t result_rotrv_8; int32_t result_rotrv_12; int32_t result_rotrv_16; int32_t result_rotrv_20; int32_t result_rotrv_24; int32_t result_rotrv_28; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); // Basic word load. __ lw(a4, MemOperand(a0, offsetof(T, input)) ); // ROTR instruction (called through the Ror macro). __ Ror(a5, a4, 0x0004); __ Ror(a6, a4, 0x0008); __ Ror(a7, a4, 0x000c); __ Ror(t0, a4, 0x0010); __ Ror(t1, a4, 0x0014); __ Ror(t2, a4, 0x0018); __ Ror(t3, a4, 0x001c); // Basic word store. __ sw(a5, MemOperand(a0, offsetof(T, result_rotr_4)) ); __ sw(a6, MemOperand(a0, offsetof(T, result_rotr_8)) ); __ sw(a7, MemOperand(a0, offsetof(T, result_rotr_12)) ); __ sw(t0, MemOperand(a0, offsetof(T, result_rotr_16)) ); __ sw(t1, MemOperand(a0, offsetof(T, result_rotr_20)) ); __ sw(t2, MemOperand(a0, offsetof(T, result_rotr_24)) ); __ sw(t3, MemOperand(a0, offsetof(T, result_rotr_28)) ); // ROTRV instruction (called through the Ror macro). __ li(t3, 0x0004); __ Ror(a5, a4, t3); __ li(t3, 0x0008); __ Ror(a6, a4, t3); __ li(t3, 0x000C); __ Ror(a7, a4, t3); __ li(t3, 0x0010); __ Ror(t0, a4, t3); __ li(t3, 0x0014); __ Ror(t1, a4, t3); __ li(t3, 0x0018); __ Ror(t2, a4, t3); __ li(t3, 0x001C); __ Ror(t3, a4, t3); // Basic word store. __ sw(a5, MemOperand(a0, offsetof(T, result_rotrv_4)) ); __ sw(a6, MemOperand(a0, offsetof(T, result_rotrv_8)) ); __ sw(a7, MemOperand(a0, offsetof(T, result_rotrv_12)) ); __ sw(t0, MemOperand(a0, offsetof(T, result_rotrv_16)) ); __ sw(t1, MemOperand(a0, offsetof(T, result_rotrv_20)) ); __ sw(t2, MemOperand(a0, offsetof(T, result_rotrv_24)) ); __ sw(t3, MemOperand(a0, offsetof(T, result_rotrv_28)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.input = 0x12345678; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0x0, 0, 0, 0); USE(dummy); CHECK_EQ(static_cast(0x81234567), t.result_rotr_4); CHECK_EQ(static_cast(0x78123456), t.result_rotr_8); CHECK_EQ(static_cast(0x67812345), t.result_rotr_12); CHECK_EQ(static_cast(0x56781234), t.result_rotr_16); CHECK_EQ(static_cast(0x45678123), t.result_rotr_20); CHECK_EQ(static_cast(0x34567812), t.result_rotr_24); CHECK_EQ(static_cast(0x23456781), t.result_rotr_28); CHECK_EQ(static_cast(0x81234567), t.result_rotrv_4); CHECK_EQ(static_cast(0x78123456), t.result_rotrv_8); CHECK_EQ(static_cast(0x67812345), t.result_rotrv_12); CHECK_EQ(static_cast(0x56781234), t.result_rotrv_16); CHECK_EQ(static_cast(0x45678123), t.result_rotrv_20); CHECK_EQ(static_cast(0x34567812), t.result_rotrv_24); CHECK_EQ(static_cast(0x23456781), t.result_rotrv_28); } } TEST(MIPS9) { // Test BRANCH improvements. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); Label exit, exit2, exit3; __ Branch(&exit, ge, a0, Operand(zero_reg)); __ Branch(&exit2, ge, a0, Operand(0x00001FFF)); __ Branch(&exit3, ge, a0, Operand(0x0001FFFF)); __ bind(&exit); __ bind(&exit2); __ bind(&exit3); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); } TEST(MIPS10) { // Test conversions between doubles and long integers. // Test hos the long ints map to FP regs pairs. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double a; double a_converted; double b; int32_t dbl_mant; int32_t dbl_exp; int32_t long_hi; int32_t long_lo; int64_t long_as_int64; int32_t b_long_hi; int32_t b_long_lo; int64_t b_long_as_int64; } T; T t; Assembler assm(isolate, NULL, 0); Label L, C; if (kArchVariant == kMips64r2) { // Rewritten for FR=1 FPU mode: // - 32 FP regs of 64-bits each, no odd/even pairs. // - Note that cvt_l_d/cvt_d_l ARE legal in FR=1 mode. // Load all structure elements to registers. __ ldc1(f0, MemOperand(a0, offsetof(T, a))); // Save the raw bits of the double. __ mfc1(a4, f0); __ mfhc1(a5, f0); __ sw(a4, MemOperand(a0, offsetof(T, dbl_mant))); __ sw(a5, MemOperand(a0, offsetof(T, dbl_exp))); // Convert double in f0 to long, save hi/lo parts. __ cvt_l_d(f0, f0); __ mfc1(a4, f0); // f0 LS 32 bits of long. __ mfhc1(a5, f0); // f0 MS 32 bits of long. __ sw(a4, MemOperand(a0, offsetof(T, long_lo))); __ sw(a5, MemOperand(a0, offsetof(T, long_hi))); // Combine the high/low ints, convert back to double. __ dsll32(a6, a5, 0); // Move a5 to high bits of a6. __ or_(a6, a6, a4); __ dmtc1(a6, f1); __ cvt_d_l(f1, f1); __ sdc1(f1, MemOperand(a0, offsetof(T, a_converted))); // Convert the b long integers to double b. __ lw(a4, MemOperand(a0, offsetof(T, b_long_lo))); __ lw(a5, MemOperand(a0, offsetof(T, b_long_hi))); __ mtc1(a4, f8); // f8 LS 32-bits. __ mthc1(a5, f8); // f8 MS 32-bits. __ cvt_d_l(f10, f8); __ sdc1(f10, MemOperand(a0, offsetof(T, b))); // Convert double b back to long-int. __ ldc1(f31, MemOperand(a0, offsetof(T, b))); __ cvt_l_d(f31, f31); __ dmfc1(a7, f31); __ sd(a7, MemOperand(a0, offsetof(T, b_long_as_int64))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.a = 2.147483647e9; // 0x7fffffff -> 0x41DFFFFFFFC00000 as double. t.b_long_hi = 0x000000ff; // 0xFF00FF00FF -> 0x426FE01FE01FE000 as double. t.b_long_lo = 0x00ff00ff; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(static_cast(0x41DFFFFF), t.dbl_exp); CHECK_EQ(static_cast(0xFFC00000), t.dbl_mant); CHECK_EQ(0, t.long_hi); CHECK_EQ(static_cast(0x7fffffff), t.long_lo); CHECK_EQ(2.147483647e9, t.a_converted); // 0xFF00FF00FF -> 1.095233372415e12. CHECK_EQ(1.095233372415e12, t.b); CHECK_EQ(static_cast(0xFF00FF00FF), t.b_long_as_int64); } } TEST(MIPS11) { // Do not run test on MIPS64r6, as these instructions are removed. if (kArchVariant != kMips64r6) { // Test LWL, LWR, SWL and SWR instructions. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { int32_t reg_init; int32_t mem_init; int32_t lwl_0; int32_t lwl_1; int32_t lwl_2; int32_t lwl_3; int32_t lwr_0; int32_t lwr_1; int32_t lwr_2; int32_t lwr_3; int32_t swl_0; int32_t swl_1; int32_t swl_2; int32_t swl_3; int32_t swr_0; int32_t swr_1; int32_t swr_2; int32_t swr_3; } T; T t; Assembler assm(isolate, NULL, 0); // Test all combinations of LWL and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, lwl_0))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a5, MemOperand(a0, offsetof(T, mem_init) + 1)); __ sw(a5, MemOperand(a0, offsetof(T, lwl_1))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a6, MemOperand(a0, offsetof(T, mem_init) + 2)); __ sw(a6, MemOperand(a0, offsetof(T, lwl_2))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a7, MemOperand(a0, offsetof(T, mem_init) + 3)); __ sw(a7, MemOperand(a0, offsetof(T, lwl_3))); // Test all combinations of LWR and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, lwr_0))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a5, MemOperand(a0, offsetof(T, mem_init) + 1)); __ sw(a5, MemOperand(a0, offsetof(T, lwr_1))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a6, MemOperand(a0, offsetof(T, mem_init) + 2)); __ sw(a6, MemOperand(a0, offsetof(T, lwr_2)) ); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a7, MemOperand(a0, offsetof(T, mem_init) + 3)); __ sw(a7, MemOperand(a0, offsetof(T, lwr_3)) ); // Test all combinations of SWL and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, swl_0))); __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ swl(a4, MemOperand(a0, offsetof(T, swl_0))); __ lw(a5, MemOperand(a0, offsetof(T, mem_init))); __ sw(a5, MemOperand(a0, offsetof(T, swl_1))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ swl(a5, MemOperand(a0, offsetof(T, swl_1) + 1)); __ lw(a6, MemOperand(a0, offsetof(T, mem_init))); __ sw(a6, MemOperand(a0, offsetof(T, swl_2))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ swl(a6, MemOperand(a0, offsetof(T, swl_2) + 2)); __ lw(a7, MemOperand(a0, offsetof(T, mem_init))); __ sw(a7, MemOperand(a0, offsetof(T, swl_3))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ swl(a7, MemOperand(a0, offsetof(T, swl_3) + 3)); // Test all combinations of SWR and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, swr_0))); __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ swr(a4, MemOperand(a0, offsetof(T, swr_0))); __ lw(a5, MemOperand(a0, offsetof(T, mem_init))); __ sw(a5, MemOperand(a0, offsetof(T, swr_1))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ swr(a5, MemOperand(a0, offsetof(T, swr_1) + 1)); __ lw(a6, MemOperand(a0, offsetof(T, mem_init))); __ sw(a6, MemOperand(a0, offsetof(T, swr_2))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ swr(a6, MemOperand(a0, offsetof(T, swr_2) + 2)); __ lw(a7, MemOperand(a0, offsetof(T, mem_init))); __ sw(a7, MemOperand(a0, offsetof(T, swr_3))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ swr(a7, MemOperand(a0, offsetof(T, swr_3) + 3)); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.reg_init = 0xaabbccdd; t.mem_init = 0x11223344; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); if (kArchEndian == kLittle) { CHECK_EQ(static_cast(0x44bbccdd), t.lwl_0); CHECK_EQ(static_cast(0x3344ccdd), t.lwl_1); CHECK_EQ(static_cast(0x223344dd), t.lwl_2); CHECK_EQ(static_cast(0x11223344), t.lwl_3); CHECK_EQ(static_cast(0x11223344), t.lwr_0); CHECK_EQ(static_cast(0xaa112233), t.lwr_1); CHECK_EQ(static_cast(0xaabb1122), t.lwr_2); CHECK_EQ(static_cast(0xaabbcc11), t.lwr_3); CHECK_EQ(static_cast(0x112233aa), t.swl_0); CHECK_EQ(static_cast(0x1122aabb), t.swl_1); CHECK_EQ(static_cast(0x11aabbcc), t.swl_2); CHECK_EQ(static_cast(0xaabbccdd), t.swl_3); CHECK_EQ(static_cast(0xaabbccdd), t.swr_0); CHECK_EQ(static_cast(0xbbccdd44), t.swr_1); CHECK_EQ(static_cast(0xccdd3344), t.swr_2); CHECK_EQ(static_cast(0xdd223344), t.swr_3); } else { CHECK_EQ(static_cast(0x11223344), t.lwl_0); CHECK_EQ(static_cast(0x223344dd), t.lwl_1); CHECK_EQ(static_cast(0x3344ccdd), t.lwl_2); CHECK_EQ(static_cast(0x44bbccdd), t.lwl_3); CHECK_EQ(static_cast(0xaabbcc11), t.lwr_0); CHECK_EQ(static_cast(0xaabb1122), t.lwr_1); CHECK_EQ(static_cast(0xaa112233), t.lwr_2); CHECK_EQ(static_cast(0x11223344), t.lwr_3); CHECK_EQ(static_cast(0xaabbccdd), t.swl_0); CHECK_EQ(static_cast(0x11aabbcc), t.swl_1); CHECK_EQ(static_cast(0x1122aabb), t.swl_2); CHECK_EQ(static_cast(0x112233aa), t.swl_3); CHECK_EQ(static_cast(0xdd223344), t.swr_0); CHECK_EQ(static_cast(0xccdd3344), t.swr_1); CHECK_EQ(static_cast(0xbbccdd44), t.swr_2); CHECK_EQ(static_cast(0xaabbccdd), t.swr_3); } } } TEST(MIPS12) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { int32_t x; int32_t y; int32_t y1; int32_t y2; int32_t y3; int32_t y4; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ mov(t2, fp); // Save frame pointer. __ mov(fp, a0); // Access struct T by fp. __ lw(a4, MemOperand(a0, offsetof(T, y))); __ lw(a7, MemOperand(a0, offsetof(T, y4))); __ addu(a5, a4, a7); __ subu(t0, a4, a7); __ nop(); __ push(a4); // These instructions disappear after opt. __ Pop(); __ addu(a4, a4, a4); __ nop(); __ Pop(); // These instructions disappear after opt. __ push(a7); __ nop(); __ push(a7); // These instructions disappear after opt. __ pop(a7); __ nop(); __ push(a7); __ pop(t0); __ nop(); __ sw(a4, MemOperand(fp, offsetof(T, y))); __ lw(a4, MemOperand(fp, offsetof(T, y))); __ nop(); __ sw(a4, MemOperand(fp, offsetof(T, y))); __ lw(a5, MemOperand(fp, offsetof(T, y))); __ nop(); __ push(a5); __ lw(a5, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a6); __ nop(); __ push(a6); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a7); __ nop(); __ mov(fp, t2); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.x = 1; t.y = 2; t.y1 = 3; t.y2 = 4; t.y3 = 0XBABA; t.y4 = 0xDEDA; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(3, t.y1); } TEST(MIPS13) { // Test Cvt_d_uw and Trunc_uw_d macros. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double cvt_big_out; double cvt_small_out; uint32_t trunc_big_out; uint32_t trunc_small_out; uint32_t cvt_big_in; uint32_t cvt_small_in; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ sw(a4, MemOperand(a0, offsetof(T, cvt_small_in))); __ Cvt_d_uw(f10, a4); __ sdc1(f10, MemOperand(a0, offsetof(T, cvt_small_out))); __ Trunc_uw_d(f10, f10, f4); __ swc1(f10, MemOperand(a0, offsetof(T, trunc_small_out))); __ sw(a4, MemOperand(a0, offsetof(T, cvt_big_in))); __ Cvt_d_uw(f8, a4); __ sdc1(f8, MemOperand(a0, offsetof(T, cvt_big_out))); __ Trunc_uw_d(f8, f8, f4); __ swc1(f8, MemOperand(a0, offsetof(T, trunc_big_out))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.cvt_big_in = 0xFFFFFFFF; t.cvt_small_in = 333; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(t.cvt_big_out, static_cast(t.cvt_big_in)); CHECK_EQ(t.cvt_small_out, static_cast(t.cvt_small_in)); CHECK_EQ(static_cast(t.trunc_big_out), static_cast(t.cvt_big_in)); CHECK_EQ(static_cast(t.trunc_small_out), static_cast(t.cvt_small_in)); } TEST(MIPS14) { // Test round, floor, ceil, trunc, cvt. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); #define ROUND_STRUCT_ELEMENT(x) \ uint32_t x##_isNaN2008; \ int32_t x##_up_out; \ int32_t x##_down_out; \ int32_t neg_##x##_up_out; \ int32_t neg_##x##_down_out; \ uint32_t x##_err1_out; \ uint32_t x##_err2_out; \ uint32_t x##_err3_out; \ uint32_t x##_err4_out; \ int32_t x##_invalid_result; typedef struct { double round_up_in; double round_down_in; double neg_round_up_in; double neg_round_down_in; double err1_in; double err2_in; double err3_in; double err4_in; ROUND_STRUCT_ELEMENT(round) ROUND_STRUCT_ELEMENT(floor) ROUND_STRUCT_ELEMENT(ceil) ROUND_STRUCT_ELEMENT(trunc) ROUND_STRUCT_ELEMENT(cvt) } T; T t; #undef ROUND_STRUCT_ELEMENT MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); // Save FCSR. __ cfc1(a1, FCSR); // Disable FPU exceptions. __ ctc1(zero_reg, FCSR); #define RUN_ROUND_TEST(x) \ __ cfc1(t0, FCSR);\ __ sw(t0, MemOperand(a0, offsetof(T, x##_isNaN2008))); \ __ ldc1(f0, MemOperand(a0, offsetof(T, round_up_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_up_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, round_down_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_down_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, neg_round_up_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, neg_##x##_up_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, neg_round_down_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, neg_##x##_down_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err1_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err1_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err2_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err2_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err3_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err3_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err4_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err4_out))); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_invalid_result))); RUN_ROUND_TEST(round) RUN_ROUND_TEST(floor) RUN_ROUND_TEST(ceil) RUN_ROUND_TEST(trunc) RUN_ROUND_TEST(cvt) // Restore FCSR. __ ctc1(a1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.round_up_in = 123.51; t.round_down_in = 123.49; t.neg_round_up_in = -123.5; t.neg_round_down_in = -123.49; t.err1_in = 123.51; t.err2_in = 1; t.err3_in = static_cast(1) + 0xFFFFFFFF; t.err4_in = NAN; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); #define GET_FPU_ERR(x) (static_cast(x & kFCSRFlagMask)) #define CHECK_NAN2008(x) (x & kFCSRNaN2008FlagMask) #define CHECK_ROUND_RESULT(type) \ CHECK(GET_FPU_ERR(t.type##_err1_out) & kFCSRInexactFlagMask); \ CHECK_EQ(0, GET_FPU_ERR(t.type##_err2_out)); \ CHECK(GET_FPU_ERR(t.type##_err3_out) & kFCSRInvalidOpFlagMask); \ CHECK(GET_FPU_ERR(t.type##_err4_out) & kFCSRInvalidOpFlagMask); \ if (CHECK_NAN2008(t.type##_isNaN2008) && kArchVariant == kMips64r6) { \ CHECK_EQ(static_cast(0), t.type##_invalid_result);\ } else { \ CHECK_EQ(static_cast(kFPUInvalidResult), t.type##_invalid_result);\ } CHECK_ROUND_RESULT(round); CHECK_ROUND_RESULT(floor); CHECK_ROUND_RESULT(ceil); CHECK_ROUND_RESULT(cvt); } TEST(MIPS15) { // Test chaining of label usages within instructions (issue 1644). CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); Assembler assm(isolate, NULL, 0); Label target; __ beq(v0, v1, &target); __ nop(); __ bne(v0, v1, &target); __ nop(); __ bind(&target); __ nop(); } // ----- mips64 tests ----------------------------------------------- TEST(MIPS16) { // Test 64-bit memory loads and stores. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); struct T { int64_t r1; int64_t r2; int64_t r3; int64_t r4; int64_t r5; int64_t r6; int64_t r7; int64_t r8; int64_t r9; int64_t r10; int64_t r11; int64_t r12; uint32_t ui; int32_t si; }; T t; Assembler assm(isolate, NULL, 0); Label L, C; // Basic 32-bit word load/store, with un-signed data. __ lw(a4, MemOperand(a0, offsetof(T, ui))); __ sw(a4, MemOperand(a0, offsetof(T, r1))); // Check that the data got zero-extended into 64-bit a4. __ sd(a4, MemOperand(a0, offsetof(T, r2))); // Basic 32-bit word load/store, with SIGNED data. __ lw(a5, MemOperand(a0, offsetof(T, si))); __ sw(a5, MemOperand(a0, offsetof(T, r3))); // Check that the data got sign-extended into 64-bit a4. __ sd(a5, MemOperand(a0, offsetof(T, r4))); // 32-bit UNSIGNED word load/store, with SIGNED data. __ lwu(a6, MemOperand(a0, offsetof(T, si))); __ sw(a6, MemOperand(a0, offsetof(T, r5))); // Check that the data got zero-extended into 64-bit a4. __ sd(a6, MemOperand(a0, offsetof(T, r6))); // lh with positive data. __ lh(a5, MemOperand(a0, offsetof(T, ui))); __ sw(a5, MemOperand(a0, offsetof(T, r7))); // lh with negative data. __ lh(a6, MemOperand(a0, offsetof(T, si))); __ sw(a6, MemOperand(a0, offsetof(T, r8))); // lhu with negative data. __ lhu(a7, MemOperand(a0, offsetof(T, si))); __ sw(a7, MemOperand(a0, offsetof(T, r9))); // lb with negative data. __ lb(t0, MemOperand(a0, offsetof(T, si))); __ sw(t0, MemOperand(a0, offsetof(T, r10))); // sh writes only 1/2 of word. __ lw(a4, MemOperand(a0, offsetof(T, ui))); __ sh(a4, MemOperand(a0, offsetof(T, r11))); __ lw(a4, MemOperand(a0, offsetof(T, si))); __ sh(a4, MemOperand(a0, offsetof(T, r12))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.ui = 0x44332211; t.si = 0x99aabbcc; t.r1 = 0x5555555555555555; t.r2 = 0x5555555555555555; t.r3 = 0x5555555555555555; t.r4 = 0x5555555555555555; t.r5 = 0x5555555555555555; t.r6 = 0x5555555555555555; t.r7 = 0x5555555555555555; t.r8 = 0x5555555555555555; t.r9 = 0x5555555555555555; t.r10 = 0x5555555555555555; t.r11 = 0x5555555555555555; t.r12 = 0x5555555555555555; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); if (kArchEndian == kLittle) { // Unsigned data, 32 & 64 CHECK_EQ(static_cast(0x5555555544332211L), t.r1); // lw, sw. CHECK_EQ(static_cast(0x0000000044332211L), t.r2); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x5555555599aabbccL), t.r3); // lw, sw. CHECK_EQ(static_cast(0xffffffff99aabbccL), t.r4); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x5555555599aabbccL), t.r5); // lwu, sw. CHECK_EQ(static_cast(0x0000000099aabbccL), t.r6); // sd. // lh with unsigned and signed data. CHECK_EQ(static_cast(0x5555555500002211L), t.r7); // lh, sw. CHECK_EQ(static_cast(0x55555555ffffbbccL), t.r8); // lh, sw. // lhu with signed data. CHECK_EQ(static_cast(0x555555550000bbccL), t.r9); // lhu, sw. // lb with signed data. CHECK_EQ(static_cast(0x55555555ffffffccL), t.r10); // lb, sw. // sh with unsigned and signed data. CHECK_EQ(static_cast(0x5555555555552211L), t.r11); // lw, sh. CHECK_EQ(static_cast(0x555555555555bbccL), t.r12); // lw, sh. } else { // Unsigned data, 32 & 64 CHECK_EQ(static_cast(0x4433221155555555L), t.r1); // lw, sw. CHECK_EQ(static_cast(0x0000000044332211L), t.r2); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x99aabbcc55555555L), t.r3); // lw, sw. CHECK_EQ(static_cast(0xffffffff99aabbccL), t.r4); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x99aabbcc55555555L), t.r5); // lwu, sw. CHECK_EQ(static_cast(0x0000000099aabbccL), t.r6); // sd. // lh with unsigned and signed data. CHECK_EQ(static_cast(0x0000443355555555L), t.r7); // lh, sw. CHECK_EQ(static_cast(0xffff99aa55555555L), t.r8); // lh, sw. // lhu with signed data. CHECK_EQ(static_cast(0x000099aa55555555L), t.r9); // lhu, sw. // lb with signed data. CHECK_EQ(static_cast(0xffffff9955555555L), t.r10); // lb, sw. // sh with unsigned and signed data. CHECK_EQ(static_cast(0x2211555555555555L), t.r11); // lw, sh. CHECK_EQ(static_cast(0xbbcc555555555555L), t.r12); // lw, sh. } } // ----------------------mips64r6 specific tests---------------------- TEST(seleqz_selnez) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { int a; int b; int c; int d; double e; double f; double g; double h; float i; float j; float k; float l; } Test; Test test; // Integer part of test. __ addiu(t1, zero_reg, 1); // t1 = 1 __ seleqz(t3, t1, zero_reg); // t3 = 1 __ sw(t3, MemOperand(a0, offsetof(Test, a))); // a = 1 __ seleqz(t2, t1, t1); // t2 = 0 __ sw(t2, MemOperand(a0, offsetof(Test, b))); // b = 0 __ selnez(t3, t1, zero_reg); // t3 = 1; __ sw(t3, MemOperand(a0, offsetof(Test, c))); // c = 0 __ selnez(t3, t1, t1); // t3 = 1 __ sw(t3, MemOperand(a0, offsetof(Test, d))); // d = 1 // Floating point part of test. __ ldc1(f0, MemOperand(a0, offsetof(Test, e)) ); // src __ ldc1(f2, MemOperand(a0, offsetof(Test, f)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, i)) ); // src __ lwc1(f10, MemOperand(a0, offsetof(Test, j)) ); // test __ seleqz_d(f4, f0, f2); __ selnez_d(f6, f0, f2); __ seleqz_s(f12, f8, f10); __ selnez_s(f14, f8, f10); __ sdc1(f4, MemOperand(a0, offsetof(Test, g)) ); // src __ sdc1(f6, MemOperand(a0, offsetof(Test, h)) ); // src __ swc1(f12, MemOperand(a0, offsetof(Test, k)) ); // src __ swc1(f14, MemOperand(a0, offsetof(Test, l)) ); // src __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.a, 1); CHECK_EQ(test.b, 0); CHECK_EQ(test.c, 0); CHECK_EQ(test.d, 1); const int test_size = 3; const int input_size = 5; double inputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double outputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float inputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float outputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.e = inputs_D[i]; test.f = tests_D[j]; test.i = inputs_S[i]; test.j = tests_S[j]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, outputs_D[i]); CHECK_EQ(test.h, 0); CHECK_EQ(test.k, outputs_S[i]); CHECK_EQ(test.l, 0); test.f = tests_D[j+1]; test.j = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, 0); CHECK_EQ(test.h, outputs_D[i]); CHECK_EQ(test.k, 0); CHECK_EQ(test.l, outputs_S[i]); } } } } TEST(min_max) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); struct TestFloat { double a; double b; double c; double d; float e; float f; float g; float h; }; TestFloat test; const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); const int kTableLength = 13; double inputsa[kTableLength] = {2.0, 3.0, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = {3.0, 2.0, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double outputsdmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double outputsdmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputse[kTableLength] = {2.0, 3.0, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsf[kTableLength] = {3.0, 2.0, 3.0, fnan, 0.0, -0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float outputsfmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float outputsfmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a))); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, b))); __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, e))); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, f))); __ min_d(f10, f4, f8); __ max_d(f12, f4, f8); __ min_s(f14, f2, f6); __ max_s(f16, f2, f6); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, c))); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, d))); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, g))); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, h))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 4; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.e = inputse[i]; test.f = inputsf[i]; CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0); CHECK_EQ(0, memcmp(&test.c, &outputsdmin[i], sizeof(test.c))); CHECK_EQ(0, memcmp(&test.d, &outputsdmax[i], sizeof(test.d))); CHECK_EQ(0, memcmp(&test.g, &outputsfmin[i], sizeof(test.g))); CHECK_EQ(0, memcmp(&test.h, &outputsfmax[i], sizeof(test.h))); } } } TEST(rint_d) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; int fcsr; }TestFloat; TestFloat test; double inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E+308, 6.27463370218383111104242366943E-307, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ ctc1(t0, FCSR); __ rint_d(f8, f4); __ sdc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(sel) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { double dd; double ds; double dt; float fd; float fs; float ft; } Test; Test test; __ ldc1(f0, MemOperand(a0, offsetof(Test, dd)) ); // test __ ldc1(f2, MemOperand(a0, offsetof(Test, ds)) ); // src1 __ ldc1(f4, MemOperand(a0, offsetof(Test, dt)) ); // src2 __ lwc1(f6, MemOperand(a0, offsetof(Test, fd)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, fs)) ); // src1 __ lwc1(f10, MemOperand(a0, offsetof(Test, ft)) ); // src2 __ sel_d(f0, f2, f4); __ sel_s(f6, f8, f10); __ sdc1(f0, MemOperand(a0, offsetof(Test, dd)) ); __ swc1(f6, MemOperand(a0, offsetof(Test, fd)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); const int test_size = 3; const int input_size = 5; double inputs_dt[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double inputs_ds[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; float inputs_ft[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float inputs_fs[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.dt = inputs_dt[i]; test.dd = tests_D[j]; test.ds = inputs_ds[i]; test.ft = inputs_ft[i]; test.fd = tests_S[j]; test.fs = inputs_fs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_ds[i]); CHECK_EQ(test.fd, inputs_fs[i]); test.dd = tests_D[j+1]; test.fd = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_dt[i]); CHECK_EQ(test.fd, inputs_ft[i]); } } } } TEST(rint_s) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; int fcsr; }TestFloat; TestFloat test; float inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E+38, 6.27463370218383111104242366943E-37, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; float* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ rint_s(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(mina_maxa) { if (kArchVariant == kMips64r6) { const int kTableLength = 23; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); struct TestFloat { double a; double b; double resd; double resd1; float c; float d; float resf; float resf1; }; TestFloat test; double inputsa[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = { 4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double resd[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double resd1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputsc[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsd[kTableLength] = {4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, fnan, -0.0, 0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float resf[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float resf1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ lwc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ lwc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ mina_d(f6, f2, f4); __ mina_s(f12, f8, f10); __ maxa_d(f14, f2, f4); __ maxa_s(f16, f8, f10); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, resf)) ); __ sdc1(f6, MemOperand(a0, offsetof(TestFloat, resd)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resf1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resd1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.c = inputsc[i]; test.d = inputsd[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if (i < kTableLength - 1) { CHECK_EQ(test.resd, resd[i]); CHECK_EQ(test.resf, resf[i]); CHECK_EQ(test.resd1, resd1[i]); CHECK_EQ(test.resf1, resf1[i]); } else { CHECK(std::isnan(test.resd)); CHECK(std::isnan(test.resf)); CHECK(std::isnan(test.resd1)); CHECK(std::isnan(test.resf1)); } } } } // ----------------------mips64r2 specific tests---------------------- TEST(trunc_l) { if (kArchVariant == kMips64r2) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; // a trunc result int64_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_l_d(f8, f4); __ trunc_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } } TEST(movz_movn) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { int64_t rt; double a; double b; double bold; double b1; double bold1; float c; float d; float dold; float d1; float dold1; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ld(t0, MemOperand(a0, offsetof(TestFloat, rt))); __ Move(f12, 0.0); __ Move(f10, 0.0); __ Move(f16, 0.0); __ Move(f14, 0.0); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, bold)) ); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, dold)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, bold1)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, dold1)) ); __ movz_s(f10, f6, t0); __ movz_d(f12, f2, t0); __ movn_s(f14, f6, t0); __ movn_d(f16, f2, t0); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, b)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, d1)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, b1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; test.rt = 1; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, test.bold); CHECK_EQ(test.d, test.dold); CHECK_EQ(test.b1, outputs_D[i]); CHECK_EQ(test.d1, outputs_S[i]); test.rt = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); CHECK_EQ(test.b1, test.bold1); CHECK_EQ(test.d1, test.dold1); } } } TEST(movt_movd) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); typedef struct test_float { double srcd; double dstd; double dstdold; double dstd1; double dstdold1; float srcf; float dstf; float dstfold; float dstf1; float dstfold1; int32_t cc; int32_t fcsr; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; double inputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; int condition_flags[8] = {0, 1, 2, 3, 4, 5, 6, 7}; for (int i = 0; i < kTableLength; i++) { test.srcd = inputs_D[i]; test.srcf = inputs_S[i]; for (int j = 0; j< 8; j++) { test.cc = condition_flags[j]; if (test.cc == 0) { test.fcsr = 1 << 23; } else { test.fcsr = 1 << (24+condition_flags[j]); } HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, srcd)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, srcf)) ); __ lw(t1, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t0, FCSR); __ ctc1(t1, FCSR); __ li(t2, 0x0); __ mtc1(t2, f12); __ mtc1(t2, f10); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold)) ); __ movt_s(f12, f4, test.cc); __ movt_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold1)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold1)) ); __ movf_s(f12, f4, test.cc); __ movf_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf1)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd1)) ); __ ctc1(t0, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, outputs_S[i]); CHECK_EQ(test.dstd, outputs_D[i]); CHECK_EQ(test.dstf1, test.dstfold1); CHECK_EQ(test.dstd1, test.dstdold1); test.fcsr = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, test.dstfold); CHECK_EQ(test.dstd, test.dstdold); CHECK_EQ(test.dstf1, outputs_S[i]); CHECK_EQ(test.dstd1, outputs_D[i]); } } } } // ----------------------tests for all archs-------------------------- TEST(cvt_w_d) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; int32_t b; int fcsr; }Test; const int kTableLength = 24; double inputs[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, 2147483653.0 }; double outputs_RN[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RZ[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RP[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RM[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lw(t0, MemOperand(a0, offsetof(Test, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ cvt_w_d(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(Test, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } TEST(trunc_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_w_d(f8, f4); __ trunc_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_w_d(f8, f4); __ round_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_l_d(f8, f4); __ round_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(sub) { const int kTableLength = 12; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; double inputft_D[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; double outputs_D[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; float inputfs_S[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; float inputft_S[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; float outputs_S[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sub_s(f6, f2, f4); __ sub_d(f12, f8, f10); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(sqrt_rsqrt_recip) { const int kTableLength = 4; const double deltaDouble = 2E-15; const float deltaFloat = 2E-7; const float sqrt2_s = sqrt(2); const double sqrt2_d = sqrt(2); CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; float resultS1; float resultS2; double c; double resultD; double resultD1; double resultD2; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 0.0L, 4.0L, 2.0L, 4e-28L }; double outputs_D[kTableLength] = { 0.0L, 2.0L, sqrt2_d, 2e-14L }; float inputs_S[kTableLength] = { 0.0, 4.0, 2.0, 4e-28 }; float outputs_S[kTableLength] = { 0.0, 2.0, sqrt2_s, 2e-14 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ sqrt_s(f6, f2); __ sqrt_d(f12, f8); __ rsqrt_d(f14, f8); __ rsqrt_s(f16, f2); __ recip_d(f18, f8); __ recip_s(f4, f2); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resultS1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resultD1)) ); __ swc1(f4, MemOperand(a0, offsetof(TestFloat, resultS2)) ); __ sdc1(f18, MemOperand(a0, offsetof(TestFloat, resultD2)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { float f1; double d1; test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); if (i != 0) { f1 = test.resultS1 - 1.0F/outputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD1 - 1.0L/outputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); f1 = test.resultS2 - 1.0F/inputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD2 - 1.0L/inputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); } else { CHECK_EQ(test.resultS1, 1.0F/outputs_S[i]); CHECK_EQ(test.resultD1, 1.0L/outputs_D[i]); CHECK_EQ(test.resultS2, 1.0F/inputs_S[i]); CHECK_EQ(test.resultD2, 1.0L/inputs_D[i]); } } } TEST(neg) { const int kTableLength = 2; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; double c; double resultD; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 4.0, -2.0 }; double outputs_D[kTableLength] = { -4.0, 2.0 }; float inputs_S[kTableLength] = { 4.0, -2.0 }; float outputs_S[kTableLength] = { -4.0, 2.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ neg_s(f6, f2); __ neg_d(f12, f8); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
()); F1 f = FUNCTION_CAST(code->entry()); int64_t res = reinterpret_cast( CALL_GENERATED_CODE(isolate, f, 50, 0, 0, 0, 0)); CHECK_EQ(1275L, res); } TEST(MIPS2) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); Label exit, error; // ----- Test all instructions. // Test lui, ori, and addiu, used in the li pseudo-instruction. // This way we can then safely load registers with chosen values. __ ori(a4, zero_reg, 0); __ lui(a4, 0x1234); __ ori(a4, a4, 0); __ ori(a4, a4, 0x0f0f); __ ori(a4, a4, 0xf0f0); __ addiu(a5, a4, 1); __ addiu(a6, a5, -0x10); // Load values in temporary registers. __ li(a4, 0x00000004); __ li(a5, 0x00001234); __ li(a6, 0x12345678); __ li(a7, 0x7fffffff); __ li(t0, 0xfffffffc); __ li(t1, 0xffffedcc); __ li(t2, 0xedcba988); __ li(t3, 0x80000000); // SPECIAL class. __ srl(v0, a6, 8); // 0x00123456 __ sll(v0, v0, 11); // 0x91a2b000 __ sra(v0, v0, 3); // 0xf2345600 __ srav(v0, v0, a4); // 0xff234560 __ sllv(v0, v0, a4); // 0xf2345600 __ srlv(v0, v0, a4); // 0x0f234560 __ Branch(&error, ne, v0, Operand(0x0f234560)); __ nop(); __ addu(v0, a4, a5); // 0x00001238 __ subu(v0, v0, a4); // 0x00001234 __ Branch(&error, ne, v0, Operand(0x00001234)); __ nop(); __ addu(v1, a7, a4); // 32bit addu result is sign-extended into 64bit reg. __ Branch(&error, ne, v1, Operand(0xffffffff80000003)); __ nop(); __ subu(v1, t3, a4); // 0x7ffffffc __ Branch(&error, ne, v1, Operand(0x7ffffffc)); __ nop(); __ and_(v0, a5, a6); // 0x0000000000001230 __ or_(v0, v0, a5); // 0x0000000000001234 __ xor_(v0, v0, a6); // 0x000000001234444c __ nor(v0, v0, a6); // 0xffffffffedcba987 __ Branch(&error, ne, v0, Operand(0xffffffffedcba983)); __ nop(); // Shift both 32bit number to left, to preserve meaning of next comparison. __ dsll32(a7, a7, 0); __ dsll32(t3, t3, 0); __ slt(v0, t3, a7); __ Branch(&error, ne, v0, Operand(0x1)); __ nop(); __ sltu(v0, t3, a7); __ Branch(&error, ne, v0, Operand(zero_reg)); __ nop(); // Restore original values in registers. __ dsrl32(a7, a7, 0); __ dsrl32(t3, t3, 0); // End of SPECIAL class. __ addiu(v0, zero_reg, 0x7421); // 0x00007421 __ addiu(v0, v0, -0x1); // 0x00007420 __ addiu(v0, v0, -0x20); // 0x00007400 __ Branch(&error, ne, v0, Operand(0x00007400)); __ nop(); __ addiu(v1, a7, 0x1); // 0x80000000 - result is sign-extended. __ Branch(&error, ne, v1, Operand(0xffffffff80000000)); __ nop(); __ slti(v0, a5, 0x00002000); // 0x1 __ slti(v0, v0, 0xffff8000); // 0x0 __ Branch(&error, ne, v0, Operand(zero_reg)); __ nop(); __ sltiu(v0, a5, 0x00002000); // 0x1 __ sltiu(v0, v0, 0x00008000); // 0x1 __ Branch(&error, ne, v0, Operand(0x1)); __ nop(); __ andi(v0, a5, 0xf0f0); // 0x00001030 __ ori(v0, v0, 0x8a00); // 0x00009a30 __ xori(v0, v0, 0x83cc); // 0x000019fc __ Branch(&error, ne, v0, Operand(0x000019fc)); __ nop(); __ lui(v1, 0x8123); // Result is sign-extended into 64bit register. __ Branch(&error, ne, v1, Operand(0xffffffff81230000)); __ nop(); // Bit twiddling instructions & conditional moves. // Uses a4-t3 as set above. __ Clz(v0, a4); // 29 __ Clz(v1, a5); // 19 __ addu(v0, v0, v1); // 48 __ Clz(v1, a6); // 3 __ addu(v0, v0, v1); // 51 __ Clz(v1, t3); // 0 __ addu(v0, v0, v1); // 51 __ Branch(&error, ne, v0, Operand(51)); __ Movn(a0, a7, a4); // Move a0<-a7 (a4 is NOT 0). __ Ins(a0, a5, 12, 8); // 0x7ff34fff __ Branch(&error, ne, a0, Operand(0x7ff34fff)); __ Movz(a0, t2, t3); // a0 not updated (t3 is NOT 0). __ Ext(a1, a0, 8, 12); // 0x34f __ Branch(&error, ne, a1, Operand(0x34f)); __ Movz(a0, t2, v1); // a0<-t2, v0 is 0, from 8 instr back. __ Branch(&error, ne, a0, Operand(t2)); // Everything was correctly executed. Load the expected result. __ li(v0, 0x31415926); __ b(&exit); __ nop(); __ bind(&error); // Got an error. Return a wrong result. __ li(v0, 666); __ bind(&exit); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F2 f = FUNCTION_CAST(code->entry()); int64_t res = reinterpret_cast( CALL_GENERATED_CODE(isolate, f, 0xab0, 0xc, 0, 0, 0)); CHECK_EQ(0x31415926L, res); } TEST(MIPS3) { // Test floating point instructions. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double a; double b; double c; double d; double e; double f; double g; double h; double i; float fa; float fb; float fc; float fd; float fe; float ff; float fg; } T; T t; // Create a function that accepts &t, and loads, manipulates, and stores // the doubles t.a ... t.f. MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); Label L, C; // Double precision floating point instructions. __ ldc1(f4, MemOperand(a0, offsetof(T, a)) ); __ ldc1(f6, MemOperand(a0, offsetof(T, b)) ); __ add_d(f8, f4, f6); __ sdc1(f8, MemOperand(a0, offsetof(T, c)) ); // c = a + b. __ mov_d(f10, f8); // c __ neg_d(f12, f6); // -b __ sub_d(f10, f10, f12); __ sdc1(f10, MemOperand(a0, offsetof(T, d)) ); // d = c - (-b). __ sdc1(f4, MemOperand(a0, offsetof(T, b)) ); // b = a. __ li(a4, 120); __ mtc1(a4, f14); __ cvt_d_w(f14, f14); // f14 = 120.0. __ mul_d(f10, f10, f14); __ sdc1(f10, MemOperand(a0, offsetof(T, e)) ); // e = d * 120 = 1.8066e16. __ div_d(f12, f10, f4); __ sdc1(f12, MemOperand(a0, offsetof(T, f)) ); // f = e / a = 120.44. __ sqrt_d(f14, f12); __ sdc1(f14, MemOperand(a0, offsetof(T, g)) ); // g = sqrt(f) = 10.97451593465515908537 if (kArchVariant == kMips64r2) { __ ldc1(f4, MemOperand(a0, offsetof(T, h)) ); __ ldc1(f6, MemOperand(a0, offsetof(T, i)) ); __ madd_d(f14, f6, f4, f6); __ sdc1(f14, MemOperand(a0, offsetof(T, h)) ); } // Single precision floating point instructions. __ lwc1(f4, MemOperand(a0, offsetof(T, fa)) ); __ lwc1(f6, MemOperand(a0, offsetof(T, fb)) ); __ add_s(f8, f4, f6); __ swc1(f8, MemOperand(a0, offsetof(T, fc)) ); // fc = fa + fb. __ neg_s(f10, f6); // -fb __ sub_s(f10, f8, f10); __ swc1(f10, MemOperand(a0, offsetof(T, fd)) ); // fd = fc - (-fb). __ swc1(f4, MemOperand(a0, offsetof(T, fb)) ); // fb = fa. __ li(t0, 120); __ mtc1(t0, f14); __ cvt_s_w(f14, f14); // f14 = 120.0. __ mul_s(f10, f10, f14); __ swc1(f10, MemOperand(a0, offsetof(T, fe)) ); // fe = fd * 120 __ div_s(f12, f10, f4); __ swc1(f12, MemOperand(a0, offsetof(T, ff)) ); // ff = fe / fa __ sqrt_s(f14, f12); __ swc1(f14, MemOperand(a0, offsetof(T, fg)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); // Double test values. t.a = 1.5e14; t.b = 2.75e11; t.c = 0.0; t.d = 0.0; t.e = 0.0; t.f = 0.0; t.h = 1.5; t.i = 2.75; // Single test values. t.fa = 1.5e6; t.fb = 2.75e4; t.fc = 0.0; t.fd = 0.0; t.fe = 0.0; t.ff = 0.0; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); // Expected double results. CHECK_EQ(1.5e14, t.a); CHECK_EQ(1.5e14, t.b); CHECK_EQ(1.50275e14, t.c); CHECK_EQ(1.50550e14, t.d); CHECK_EQ(1.8066e16, t.e); CHECK_EQ(120.44, t.f); CHECK_EQ(10.97451593465515908537, t.g); if (kArchVariant == kMips64r2) { CHECK_EQ(6.875, t.h); } // Expected single results. CHECK_EQ(1.5e6, t.fa); CHECK_EQ(1.5e6, t.fb); CHECK_EQ(1.5275e06, t.fc); CHECK_EQ(1.5550e06, t.fd); CHECK_EQ(1.866e08, t.fe); CHECK_EQ(124.40000152587890625, t.ff); CHECK_EQ(11.1534748077392578125, t.fg); } TEST(MIPS4) { // Test moves between floating point and integer registers. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double a; double b; double c; double d; int64_t high; int64_t low; } T; T t; Assembler assm(isolate, NULL, 0); Label L, C; __ ldc1(f4, MemOperand(a0, offsetof(T, a))); __ ldc1(f5, MemOperand(a0, offsetof(T, b))); // Swap f4 and f5, by using 3 integer registers, a4-a6, // both two 32-bit chunks, and one 64-bit chunk. // mXhc1 is mips32/64-r2 only, not r1, // but we will not support r1 in practice. __ mfc1(a4, f4); __ mfhc1(a5, f4); __ dmfc1(a6, f5); __ mtc1(a4, f5); __ mthc1(a5, f5); __ dmtc1(a6, f4); // Store the swapped f4 and f5 back to memory. __ sdc1(f4, MemOperand(a0, offsetof(T, a))); __ sdc1(f5, MemOperand(a0, offsetof(T, c))); // Test sign extension of move operations from coprocessor. __ ldc1(f4, MemOperand(a0, offsetof(T, d))); __ mfhc1(a4, f4); __ mfc1(a5, f4); __ sd(a4, MemOperand(a0, offsetof(T, high))); __ sd(a5, MemOperand(a0, offsetof(T, low))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.a = 1.5e22; t.b = 2.75e11; t.c = 17.17; t.d = -2.75e11; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(2.75e11, t.a); CHECK_EQ(2.75e11, t.b); CHECK_EQ(1.5e22, t.c); CHECK_EQ(static_cast(0xffffffffc25001d1L), t.high); CHECK_EQ(static_cast(0xffffffffbf800000L), t.low); } TEST(MIPS5) { // Test conversions between doubles and integers. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double a; double b; int i; int j; } T; T t; Assembler assm(isolate, NULL, 0); Label L, C; // Load all structure elements to registers. __ ldc1(f4, MemOperand(a0, offsetof(T, a)) ); __ ldc1(f6, MemOperand(a0, offsetof(T, b)) ); __ lw(a4, MemOperand(a0, offsetof(T, i)) ); __ lw(a5, MemOperand(a0, offsetof(T, j)) ); // Convert double in f4 to int in element i. __ cvt_w_d(f8, f4); __ mfc1(a6, f8); __ sw(a6, MemOperand(a0, offsetof(T, i)) ); // Convert double in f6 to int in element j. __ cvt_w_d(f10, f6); __ mfc1(a7, f10); __ sw(a7, MemOperand(a0, offsetof(T, j)) ); // Convert int in original i (a4) to double in a. __ mtc1(a4, f12); __ cvt_d_w(f0, f12); __ sdc1(f0, MemOperand(a0, offsetof(T, a)) ); // Convert int in original j (a5) to double in b. __ mtc1(a5, f14); __ cvt_d_w(f2, f14); __ sdc1(f2, MemOperand(a0, offsetof(T, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.a = 1.5e4; t.b = 2.75e8; t.i = 12345678; t.j = -100000; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(12345678.0, t.a); CHECK_EQ(-100000.0, t.b); CHECK_EQ(15000, t.i); CHECK_EQ(275000000, t.j); } TEST(MIPS6) { // Test simple memory loads and stores. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { uint32_t ui; int32_t si; int32_t r1; int32_t r2; int32_t r3; int32_t r4; int32_t r5; int32_t r6; } T; T t; Assembler assm(isolate, NULL, 0); Label L, C; // Basic word load/store. __ lw(a4, MemOperand(a0, offsetof(T, ui)) ); __ sw(a4, MemOperand(a0, offsetof(T, r1)) ); // lh with positive data. __ lh(a5, MemOperand(a0, offsetof(T, ui)) ); __ sw(a5, MemOperand(a0, offsetof(T, r2)) ); // lh with negative data. __ lh(a6, MemOperand(a0, offsetof(T, si)) ); __ sw(a6, MemOperand(a0, offsetof(T, r3)) ); // lhu with negative data. __ lhu(a7, MemOperand(a0, offsetof(T, si)) ); __ sw(a7, MemOperand(a0, offsetof(T, r4)) ); // lb with negative data. __ lb(t0, MemOperand(a0, offsetof(T, si)) ); __ sw(t0, MemOperand(a0, offsetof(T, r5)) ); // sh writes only 1/2 of word. __ lui(t1, 0x3333); __ ori(t1, t1, 0x3333); __ sw(t1, MemOperand(a0, offsetof(T, r6)) ); __ lhu(t1, MemOperand(a0, offsetof(T, si)) ); __ sh(t1, MemOperand(a0, offsetof(T, r6)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.ui = 0x11223344; t.si = 0x99aabbcc; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(static_cast(0x11223344), t.r1); if (kArchEndian == kLittle) { CHECK_EQ(static_cast(0x3344), t.r2); CHECK_EQ(static_cast(0xffffbbcc), t.r3); CHECK_EQ(static_cast(0x0000bbcc), t.r4); CHECK_EQ(static_cast(0xffffffcc), t.r5); CHECK_EQ(static_cast(0x3333bbcc), t.r6); } else { CHECK_EQ(static_cast(0x1122), t.r2); CHECK_EQ(static_cast(0xffff99aa), t.r3); CHECK_EQ(static_cast(0x000099aa), t.r4); CHECK_EQ(static_cast(0xffffff99), t.r5); CHECK_EQ(static_cast(0x99aa3333), t.r6); } } TEST(MIPS7) { // Test floating point compare and branch instructions. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double a; double b; double c; double d; double e; double f; int32_t result; } T; T t; // Create a function that accepts &t, and loads, manipulates, and stores // the doubles t.a ... t.f. MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); Label neither_is_nan, less_than, outa_here; __ ldc1(f4, MemOperand(a0, offsetof(T, a)) ); __ ldc1(f6, MemOperand(a0, offsetof(T, b)) ); if (kArchVariant != kMips64r6) { __ c(UN, D, f4, f6); __ bc1f(&neither_is_nan); } else { __ cmp(UN, L, f2, f4, f6); __ bc1eqz(&neither_is_nan, f2); } __ nop(); __ sw(zero_reg, MemOperand(a0, offsetof(T, result)) ); __ Branch(&outa_here); __ bind(&neither_is_nan); if (kArchVariant == kMips64r6) { __ cmp(OLT, L, f2, f6, f4); __ bc1nez(&less_than, f2); } else { __ c(OLT, D, f6, f4, 2); __ bc1t(&less_than, 2); } __ nop(); __ sw(zero_reg, MemOperand(a0, offsetof(T, result)) ); __ Branch(&outa_here); __ bind(&less_than); __ Addu(a4, zero_reg, Operand(1)); __ sw(a4, MemOperand(a0, offsetof(T, result)) ); // Set true. // This test-case should have additional tests. __ bind(&outa_here); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.a = 1.5e14; t.b = 2.75e11; t.c = 2.0; t.d = -4.0; t.e = 0.0; t.f = 0.0; t.result = 0; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(1.5e14, t.a); CHECK_EQ(2.75e11, t.b); CHECK_EQ(1, t.result); } TEST(MIPS8) { if (kArchVariant == kMips64r2) { // Test ROTR and ROTRV instructions. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { int32_t input; int32_t result_rotr_4; int32_t result_rotr_8; int32_t result_rotr_12; int32_t result_rotr_16; int32_t result_rotr_20; int32_t result_rotr_24; int32_t result_rotr_28; int32_t result_rotrv_4; int32_t result_rotrv_8; int32_t result_rotrv_12; int32_t result_rotrv_16; int32_t result_rotrv_20; int32_t result_rotrv_24; int32_t result_rotrv_28; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); // Basic word load. __ lw(a4, MemOperand(a0, offsetof(T, input)) ); // ROTR instruction (called through the Ror macro). __ Ror(a5, a4, 0x0004); __ Ror(a6, a4, 0x0008); __ Ror(a7, a4, 0x000c); __ Ror(t0, a4, 0x0010); __ Ror(t1, a4, 0x0014); __ Ror(t2, a4, 0x0018); __ Ror(t3, a4, 0x001c); // Basic word store. __ sw(a5, MemOperand(a0, offsetof(T, result_rotr_4)) ); __ sw(a6, MemOperand(a0, offsetof(T, result_rotr_8)) ); __ sw(a7, MemOperand(a0, offsetof(T, result_rotr_12)) ); __ sw(t0, MemOperand(a0, offsetof(T, result_rotr_16)) ); __ sw(t1, MemOperand(a0, offsetof(T, result_rotr_20)) ); __ sw(t2, MemOperand(a0, offsetof(T, result_rotr_24)) ); __ sw(t3, MemOperand(a0, offsetof(T, result_rotr_28)) ); // ROTRV instruction (called through the Ror macro). __ li(t3, 0x0004); __ Ror(a5, a4, t3); __ li(t3, 0x0008); __ Ror(a6, a4, t3); __ li(t3, 0x000C); __ Ror(a7, a4, t3); __ li(t3, 0x0010); __ Ror(t0, a4, t3); __ li(t3, 0x0014); __ Ror(t1, a4, t3); __ li(t3, 0x0018); __ Ror(t2, a4, t3); __ li(t3, 0x001C); __ Ror(t3, a4, t3); // Basic word store. __ sw(a5, MemOperand(a0, offsetof(T, result_rotrv_4)) ); __ sw(a6, MemOperand(a0, offsetof(T, result_rotrv_8)) ); __ sw(a7, MemOperand(a0, offsetof(T, result_rotrv_12)) ); __ sw(t0, MemOperand(a0, offsetof(T, result_rotrv_16)) ); __ sw(t1, MemOperand(a0, offsetof(T, result_rotrv_20)) ); __ sw(t2, MemOperand(a0, offsetof(T, result_rotrv_24)) ); __ sw(t3, MemOperand(a0, offsetof(T, result_rotrv_28)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.input = 0x12345678; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0x0, 0, 0, 0); USE(dummy); CHECK_EQ(static_cast(0x81234567), t.result_rotr_4); CHECK_EQ(static_cast(0x78123456), t.result_rotr_8); CHECK_EQ(static_cast(0x67812345), t.result_rotr_12); CHECK_EQ(static_cast(0x56781234), t.result_rotr_16); CHECK_EQ(static_cast(0x45678123), t.result_rotr_20); CHECK_EQ(static_cast(0x34567812), t.result_rotr_24); CHECK_EQ(static_cast(0x23456781), t.result_rotr_28); CHECK_EQ(static_cast(0x81234567), t.result_rotrv_4); CHECK_EQ(static_cast(0x78123456), t.result_rotrv_8); CHECK_EQ(static_cast(0x67812345), t.result_rotrv_12); CHECK_EQ(static_cast(0x56781234), t.result_rotrv_16); CHECK_EQ(static_cast(0x45678123), t.result_rotrv_20); CHECK_EQ(static_cast(0x34567812), t.result_rotrv_24); CHECK_EQ(static_cast(0x23456781), t.result_rotrv_28); } } TEST(MIPS9) { // Test BRANCH improvements. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); Label exit, exit2, exit3; __ Branch(&exit, ge, a0, Operand(zero_reg)); __ Branch(&exit2, ge, a0, Operand(0x00001FFF)); __ Branch(&exit3, ge, a0, Operand(0x0001FFFF)); __ bind(&exit); __ bind(&exit2); __ bind(&exit3); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); } TEST(MIPS10) { // Test conversions between doubles and long integers. // Test hos the long ints map to FP regs pairs. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double a; double a_converted; double b; int32_t dbl_mant; int32_t dbl_exp; int32_t long_hi; int32_t long_lo; int64_t long_as_int64; int32_t b_long_hi; int32_t b_long_lo; int64_t b_long_as_int64; } T; T t; Assembler assm(isolate, NULL, 0); Label L, C; if (kArchVariant == kMips64r2) { // Rewritten for FR=1 FPU mode: // - 32 FP regs of 64-bits each, no odd/even pairs. // - Note that cvt_l_d/cvt_d_l ARE legal in FR=1 mode. // Load all structure elements to registers. __ ldc1(f0, MemOperand(a0, offsetof(T, a))); // Save the raw bits of the double. __ mfc1(a4, f0); __ mfhc1(a5, f0); __ sw(a4, MemOperand(a0, offsetof(T, dbl_mant))); __ sw(a5, MemOperand(a0, offsetof(T, dbl_exp))); // Convert double in f0 to long, save hi/lo parts. __ cvt_l_d(f0, f0); __ mfc1(a4, f0); // f0 LS 32 bits of long. __ mfhc1(a5, f0); // f0 MS 32 bits of long. __ sw(a4, MemOperand(a0, offsetof(T, long_lo))); __ sw(a5, MemOperand(a0, offsetof(T, long_hi))); // Combine the high/low ints, convert back to double. __ dsll32(a6, a5, 0); // Move a5 to high bits of a6. __ or_(a6, a6, a4); __ dmtc1(a6, f1); __ cvt_d_l(f1, f1); __ sdc1(f1, MemOperand(a0, offsetof(T, a_converted))); // Convert the b long integers to double b. __ lw(a4, MemOperand(a0, offsetof(T, b_long_lo))); __ lw(a5, MemOperand(a0, offsetof(T, b_long_hi))); __ mtc1(a4, f8); // f8 LS 32-bits. __ mthc1(a5, f8); // f8 MS 32-bits. __ cvt_d_l(f10, f8); __ sdc1(f10, MemOperand(a0, offsetof(T, b))); // Convert double b back to long-int. __ ldc1(f31, MemOperand(a0, offsetof(T, b))); __ cvt_l_d(f31, f31); __ dmfc1(a7, f31); __ sd(a7, MemOperand(a0, offsetof(T, b_long_as_int64))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.a = 2.147483647e9; // 0x7fffffff -> 0x41DFFFFFFFC00000 as double. t.b_long_hi = 0x000000ff; // 0xFF00FF00FF -> 0x426FE01FE01FE000 as double. t.b_long_lo = 0x00ff00ff; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(static_cast(0x41DFFFFF), t.dbl_exp); CHECK_EQ(static_cast(0xFFC00000), t.dbl_mant); CHECK_EQ(0, t.long_hi); CHECK_EQ(static_cast(0x7fffffff), t.long_lo); CHECK_EQ(2.147483647e9, t.a_converted); // 0xFF00FF00FF -> 1.095233372415e12. CHECK_EQ(1.095233372415e12, t.b); CHECK_EQ(static_cast(0xFF00FF00FF), t.b_long_as_int64); } } TEST(MIPS11) { // Do not run test on MIPS64r6, as these instructions are removed. if (kArchVariant != kMips64r6) { // Test LWL, LWR, SWL and SWR instructions. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { int32_t reg_init; int32_t mem_init; int32_t lwl_0; int32_t lwl_1; int32_t lwl_2; int32_t lwl_3; int32_t lwr_0; int32_t lwr_1; int32_t lwr_2; int32_t lwr_3; int32_t swl_0; int32_t swl_1; int32_t swl_2; int32_t swl_3; int32_t swr_0; int32_t swr_1; int32_t swr_2; int32_t swr_3; } T; T t; Assembler assm(isolate, NULL, 0); // Test all combinations of LWL and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, lwl_0))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a5, MemOperand(a0, offsetof(T, mem_init) + 1)); __ sw(a5, MemOperand(a0, offsetof(T, lwl_1))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a6, MemOperand(a0, offsetof(T, mem_init) + 2)); __ sw(a6, MemOperand(a0, offsetof(T, lwl_2))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a7, MemOperand(a0, offsetof(T, mem_init) + 3)); __ sw(a7, MemOperand(a0, offsetof(T, lwl_3))); // Test all combinations of LWR and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, lwr_0))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a5, MemOperand(a0, offsetof(T, mem_init) + 1)); __ sw(a5, MemOperand(a0, offsetof(T, lwr_1))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a6, MemOperand(a0, offsetof(T, mem_init) + 2)); __ sw(a6, MemOperand(a0, offsetof(T, lwr_2)) ); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a7, MemOperand(a0, offsetof(T, mem_init) + 3)); __ sw(a7, MemOperand(a0, offsetof(T, lwr_3)) ); // Test all combinations of SWL and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, swl_0))); __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ swl(a4, MemOperand(a0, offsetof(T, swl_0))); __ lw(a5, MemOperand(a0, offsetof(T, mem_init))); __ sw(a5, MemOperand(a0, offsetof(T, swl_1))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ swl(a5, MemOperand(a0, offsetof(T, swl_1) + 1)); __ lw(a6, MemOperand(a0, offsetof(T, mem_init))); __ sw(a6, MemOperand(a0, offsetof(T, swl_2))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ swl(a6, MemOperand(a0, offsetof(T, swl_2) + 2)); __ lw(a7, MemOperand(a0, offsetof(T, mem_init))); __ sw(a7, MemOperand(a0, offsetof(T, swl_3))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ swl(a7, MemOperand(a0, offsetof(T, swl_3) + 3)); // Test all combinations of SWR and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, swr_0))); __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ swr(a4, MemOperand(a0, offsetof(T, swr_0))); __ lw(a5, MemOperand(a0, offsetof(T, mem_init))); __ sw(a5, MemOperand(a0, offsetof(T, swr_1))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ swr(a5, MemOperand(a0, offsetof(T, swr_1) + 1)); __ lw(a6, MemOperand(a0, offsetof(T, mem_init))); __ sw(a6, MemOperand(a0, offsetof(T, swr_2))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ swr(a6, MemOperand(a0, offsetof(T, swr_2) + 2)); __ lw(a7, MemOperand(a0, offsetof(T, mem_init))); __ sw(a7, MemOperand(a0, offsetof(T, swr_3))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ swr(a7, MemOperand(a0, offsetof(T, swr_3) + 3)); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.reg_init = 0xaabbccdd; t.mem_init = 0x11223344; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); if (kArchEndian == kLittle) { CHECK_EQ(static_cast(0x44bbccdd), t.lwl_0); CHECK_EQ(static_cast(0x3344ccdd), t.lwl_1); CHECK_EQ(static_cast(0x223344dd), t.lwl_2); CHECK_EQ(static_cast(0x11223344), t.lwl_3); CHECK_EQ(static_cast(0x11223344), t.lwr_0); CHECK_EQ(static_cast(0xaa112233), t.lwr_1); CHECK_EQ(static_cast(0xaabb1122), t.lwr_2); CHECK_EQ(static_cast(0xaabbcc11), t.lwr_3); CHECK_EQ(static_cast(0x112233aa), t.swl_0); CHECK_EQ(static_cast(0x1122aabb), t.swl_1); CHECK_EQ(static_cast(0x11aabbcc), t.swl_2); CHECK_EQ(static_cast(0xaabbccdd), t.swl_3); CHECK_EQ(static_cast(0xaabbccdd), t.swr_0); CHECK_EQ(static_cast(0xbbccdd44), t.swr_1); CHECK_EQ(static_cast(0xccdd3344), t.swr_2); CHECK_EQ(static_cast(0xdd223344), t.swr_3); } else { CHECK_EQ(static_cast(0x11223344), t.lwl_0); CHECK_EQ(static_cast(0x223344dd), t.lwl_1); CHECK_EQ(static_cast(0x3344ccdd), t.lwl_2); CHECK_EQ(static_cast(0x44bbccdd), t.lwl_3); CHECK_EQ(static_cast(0xaabbcc11), t.lwr_0); CHECK_EQ(static_cast(0xaabb1122), t.lwr_1); CHECK_EQ(static_cast(0xaa112233), t.lwr_2); CHECK_EQ(static_cast(0x11223344), t.lwr_3); CHECK_EQ(static_cast(0xaabbccdd), t.swl_0); CHECK_EQ(static_cast(0x11aabbcc), t.swl_1); CHECK_EQ(static_cast(0x1122aabb), t.swl_2); CHECK_EQ(static_cast(0x112233aa), t.swl_3); CHECK_EQ(static_cast(0xdd223344), t.swr_0); CHECK_EQ(static_cast(0xccdd3344), t.swr_1); CHECK_EQ(static_cast(0xbbccdd44), t.swr_2); CHECK_EQ(static_cast(0xaabbccdd), t.swr_3); } } } TEST(MIPS12) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { int32_t x; int32_t y; int32_t y1; int32_t y2; int32_t y3; int32_t y4; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ mov(t2, fp); // Save frame pointer. __ mov(fp, a0); // Access struct T by fp. __ lw(a4, MemOperand(a0, offsetof(T, y))); __ lw(a7, MemOperand(a0, offsetof(T, y4))); __ addu(a5, a4, a7); __ subu(t0, a4, a7); __ nop(); __ push(a4); // These instructions disappear after opt. __ Pop(); __ addu(a4, a4, a4); __ nop(); __ Pop(); // These instructions disappear after opt. __ push(a7); __ nop(); __ push(a7); // These instructions disappear after opt. __ pop(a7); __ nop(); __ push(a7); __ pop(t0); __ nop(); __ sw(a4, MemOperand(fp, offsetof(T, y))); __ lw(a4, MemOperand(fp, offsetof(T, y))); __ nop(); __ sw(a4, MemOperand(fp, offsetof(T, y))); __ lw(a5, MemOperand(fp, offsetof(T, y))); __ nop(); __ push(a5); __ lw(a5, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a6); __ nop(); __ push(a6); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a7); __ nop(); __ mov(fp, t2); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.x = 1; t.y = 2; t.y1 = 3; t.y2 = 4; t.y3 = 0XBABA; t.y4 = 0xDEDA; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(3, t.y1); } TEST(MIPS13) { // Test Cvt_d_uw and Trunc_uw_d macros. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double cvt_big_out; double cvt_small_out; uint32_t trunc_big_out; uint32_t trunc_small_out; uint32_t cvt_big_in; uint32_t cvt_small_in; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ sw(a4, MemOperand(a0, offsetof(T, cvt_small_in))); __ Cvt_d_uw(f10, a4); __ sdc1(f10, MemOperand(a0, offsetof(T, cvt_small_out))); __ Trunc_uw_d(f10, f10, f4); __ swc1(f10, MemOperand(a0, offsetof(T, trunc_small_out))); __ sw(a4, MemOperand(a0, offsetof(T, cvt_big_in))); __ Cvt_d_uw(f8, a4); __ sdc1(f8, MemOperand(a0, offsetof(T, cvt_big_out))); __ Trunc_uw_d(f8, f8, f4); __ swc1(f8, MemOperand(a0, offsetof(T, trunc_big_out))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.cvt_big_in = 0xFFFFFFFF; t.cvt_small_in = 333; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(t.cvt_big_out, static_cast(t.cvt_big_in)); CHECK_EQ(t.cvt_small_out, static_cast(t.cvt_small_in)); CHECK_EQ(static_cast(t.trunc_big_out), static_cast(t.cvt_big_in)); CHECK_EQ(static_cast(t.trunc_small_out), static_cast(t.cvt_small_in)); } TEST(MIPS14) { // Test round, floor, ceil, trunc, cvt. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); #define ROUND_STRUCT_ELEMENT(x) \ uint32_t x##_isNaN2008; \ int32_t x##_up_out; \ int32_t x##_down_out; \ int32_t neg_##x##_up_out; \ int32_t neg_##x##_down_out; \ uint32_t x##_err1_out; \ uint32_t x##_err2_out; \ uint32_t x##_err3_out; \ uint32_t x##_err4_out; \ int32_t x##_invalid_result; typedef struct { double round_up_in; double round_down_in; double neg_round_up_in; double neg_round_down_in; double err1_in; double err2_in; double err3_in; double err4_in; ROUND_STRUCT_ELEMENT(round) ROUND_STRUCT_ELEMENT(floor) ROUND_STRUCT_ELEMENT(ceil) ROUND_STRUCT_ELEMENT(trunc) ROUND_STRUCT_ELEMENT(cvt) } T; T t; #undef ROUND_STRUCT_ELEMENT MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); // Save FCSR. __ cfc1(a1, FCSR); // Disable FPU exceptions. __ ctc1(zero_reg, FCSR); #define RUN_ROUND_TEST(x) \ __ cfc1(t0, FCSR);\ __ sw(t0, MemOperand(a0, offsetof(T, x##_isNaN2008))); \ __ ldc1(f0, MemOperand(a0, offsetof(T, round_up_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_up_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, round_down_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_down_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, neg_round_up_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, neg_##x##_up_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, neg_round_down_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, neg_##x##_down_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err1_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err1_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err2_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err2_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err3_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err3_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err4_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err4_out))); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_invalid_result))); RUN_ROUND_TEST(round) RUN_ROUND_TEST(floor) RUN_ROUND_TEST(ceil) RUN_ROUND_TEST(trunc) RUN_ROUND_TEST(cvt) // Restore FCSR. __ ctc1(a1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.round_up_in = 123.51; t.round_down_in = 123.49; t.neg_round_up_in = -123.5; t.neg_round_down_in = -123.49; t.err1_in = 123.51; t.err2_in = 1; t.err3_in = static_cast(1) + 0xFFFFFFFF; t.err4_in = NAN; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); #define GET_FPU_ERR(x) (static_cast(x & kFCSRFlagMask)) #define CHECK_NAN2008(x) (x & kFCSRNaN2008FlagMask) #define CHECK_ROUND_RESULT(type) \ CHECK(GET_FPU_ERR(t.type##_err1_out) & kFCSRInexactFlagMask); \ CHECK_EQ(0, GET_FPU_ERR(t.type##_err2_out)); \ CHECK(GET_FPU_ERR(t.type##_err3_out) & kFCSRInvalidOpFlagMask); \ CHECK(GET_FPU_ERR(t.type##_err4_out) & kFCSRInvalidOpFlagMask); \ if (CHECK_NAN2008(t.type##_isNaN2008) && kArchVariant == kMips64r6) { \ CHECK_EQ(static_cast(0), t.type##_invalid_result);\ } else { \ CHECK_EQ(static_cast(kFPUInvalidResult), t.type##_invalid_result);\ } CHECK_ROUND_RESULT(round); CHECK_ROUND_RESULT(floor); CHECK_ROUND_RESULT(ceil); CHECK_ROUND_RESULT(cvt); } TEST(MIPS15) { // Test chaining of label usages within instructions (issue 1644). CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); Assembler assm(isolate, NULL, 0); Label target; __ beq(v0, v1, &target); __ nop(); __ bne(v0, v1, &target); __ nop(); __ bind(&target); __ nop(); } // ----- mips64 tests ----------------------------------------------- TEST(MIPS16) { // Test 64-bit memory loads and stores. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); struct T { int64_t r1; int64_t r2; int64_t r3; int64_t r4; int64_t r5; int64_t r6; int64_t r7; int64_t r8; int64_t r9; int64_t r10; int64_t r11; int64_t r12; uint32_t ui; int32_t si; }; T t; Assembler assm(isolate, NULL, 0); Label L, C; // Basic 32-bit word load/store, with un-signed data. __ lw(a4, MemOperand(a0, offsetof(T, ui))); __ sw(a4, MemOperand(a0, offsetof(T, r1))); // Check that the data got zero-extended into 64-bit a4. __ sd(a4, MemOperand(a0, offsetof(T, r2))); // Basic 32-bit word load/store, with SIGNED data. __ lw(a5, MemOperand(a0, offsetof(T, si))); __ sw(a5, MemOperand(a0, offsetof(T, r3))); // Check that the data got sign-extended into 64-bit a4. __ sd(a5, MemOperand(a0, offsetof(T, r4))); // 32-bit UNSIGNED word load/store, with SIGNED data. __ lwu(a6, MemOperand(a0, offsetof(T, si))); __ sw(a6, MemOperand(a0, offsetof(T, r5))); // Check that the data got zero-extended into 64-bit a4. __ sd(a6, MemOperand(a0, offsetof(T, r6))); // lh with positive data. __ lh(a5, MemOperand(a0, offsetof(T, ui))); __ sw(a5, MemOperand(a0, offsetof(T, r7))); // lh with negative data. __ lh(a6, MemOperand(a0, offsetof(T, si))); __ sw(a6, MemOperand(a0, offsetof(T, r8))); // lhu with negative data. __ lhu(a7, MemOperand(a0, offsetof(T, si))); __ sw(a7, MemOperand(a0, offsetof(T, r9))); // lb with negative data. __ lb(t0, MemOperand(a0, offsetof(T, si))); __ sw(t0, MemOperand(a0, offsetof(T, r10))); // sh writes only 1/2 of word. __ lw(a4, MemOperand(a0, offsetof(T, ui))); __ sh(a4, MemOperand(a0, offsetof(T, r11))); __ lw(a4, MemOperand(a0, offsetof(T, si))); __ sh(a4, MemOperand(a0, offsetof(T, r12))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.ui = 0x44332211; t.si = 0x99aabbcc; t.r1 = 0x5555555555555555; t.r2 = 0x5555555555555555; t.r3 = 0x5555555555555555; t.r4 = 0x5555555555555555; t.r5 = 0x5555555555555555; t.r6 = 0x5555555555555555; t.r7 = 0x5555555555555555; t.r8 = 0x5555555555555555; t.r9 = 0x5555555555555555; t.r10 = 0x5555555555555555; t.r11 = 0x5555555555555555; t.r12 = 0x5555555555555555; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); if (kArchEndian == kLittle) { // Unsigned data, 32 & 64 CHECK_EQ(static_cast(0x5555555544332211L), t.r1); // lw, sw. CHECK_EQ(static_cast(0x0000000044332211L), t.r2); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x5555555599aabbccL), t.r3); // lw, sw. CHECK_EQ(static_cast(0xffffffff99aabbccL), t.r4); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x5555555599aabbccL), t.r5); // lwu, sw. CHECK_EQ(static_cast(0x0000000099aabbccL), t.r6); // sd. // lh with unsigned and signed data. CHECK_EQ(static_cast(0x5555555500002211L), t.r7); // lh, sw. CHECK_EQ(static_cast(0x55555555ffffbbccL), t.r8); // lh, sw. // lhu with signed data. CHECK_EQ(static_cast(0x555555550000bbccL), t.r9); // lhu, sw. // lb with signed data. CHECK_EQ(static_cast(0x55555555ffffffccL), t.r10); // lb, sw. // sh with unsigned and signed data. CHECK_EQ(static_cast(0x5555555555552211L), t.r11); // lw, sh. CHECK_EQ(static_cast(0x555555555555bbccL), t.r12); // lw, sh. } else { // Unsigned data, 32 & 64 CHECK_EQ(static_cast(0x4433221155555555L), t.r1); // lw, sw. CHECK_EQ(static_cast(0x0000000044332211L), t.r2); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x99aabbcc55555555L), t.r3); // lw, sw. CHECK_EQ(static_cast(0xffffffff99aabbccL), t.r4); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x99aabbcc55555555L), t.r5); // lwu, sw. CHECK_EQ(static_cast(0x0000000099aabbccL), t.r6); // sd. // lh with unsigned and signed data. CHECK_EQ(static_cast(0x0000443355555555L), t.r7); // lh, sw. CHECK_EQ(static_cast(0xffff99aa55555555L), t.r8); // lh, sw. // lhu with signed data. CHECK_EQ(static_cast(0x000099aa55555555L), t.r9); // lhu, sw. // lb with signed data. CHECK_EQ(static_cast(0xffffff9955555555L), t.r10); // lb, sw. // sh with unsigned and signed data. CHECK_EQ(static_cast(0x2211555555555555L), t.r11); // lw, sh. CHECK_EQ(static_cast(0xbbcc555555555555L), t.r12); // lw, sh. } } // ----------------------mips64r6 specific tests---------------------- TEST(seleqz_selnez) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { int a; int b; int c; int d; double e; double f; double g; double h; float i; float j; float k; float l; } Test; Test test; // Integer part of test. __ addiu(t1, zero_reg, 1); // t1 = 1 __ seleqz(t3, t1, zero_reg); // t3 = 1 __ sw(t3, MemOperand(a0, offsetof(Test, a))); // a = 1 __ seleqz(t2, t1, t1); // t2 = 0 __ sw(t2, MemOperand(a0, offsetof(Test, b))); // b = 0 __ selnez(t3, t1, zero_reg); // t3 = 1; __ sw(t3, MemOperand(a0, offsetof(Test, c))); // c = 0 __ selnez(t3, t1, t1); // t3 = 1 __ sw(t3, MemOperand(a0, offsetof(Test, d))); // d = 1 // Floating point part of test. __ ldc1(f0, MemOperand(a0, offsetof(Test, e)) ); // src __ ldc1(f2, MemOperand(a0, offsetof(Test, f)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, i)) ); // src __ lwc1(f10, MemOperand(a0, offsetof(Test, j)) ); // test __ seleqz_d(f4, f0, f2); __ selnez_d(f6, f0, f2); __ seleqz_s(f12, f8, f10); __ selnez_s(f14, f8, f10); __ sdc1(f4, MemOperand(a0, offsetof(Test, g)) ); // src __ sdc1(f6, MemOperand(a0, offsetof(Test, h)) ); // src __ swc1(f12, MemOperand(a0, offsetof(Test, k)) ); // src __ swc1(f14, MemOperand(a0, offsetof(Test, l)) ); // src __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.a, 1); CHECK_EQ(test.b, 0); CHECK_EQ(test.c, 0); CHECK_EQ(test.d, 1); const int test_size = 3; const int input_size = 5; double inputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double outputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float inputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float outputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.e = inputs_D[i]; test.f = tests_D[j]; test.i = inputs_S[i]; test.j = tests_S[j]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, outputs_D[i]); CHECK_EQ(test.h, 0); CHECK_EQ(test.k, outputs_S[i]); CHECK_EQ(test.l, 0); test.f = tests_D[j+1]; test.j = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, 0); CHECK_EQ(test.h, outputs_D[i]); CHECK_EQ(test.k, 0); CHECK_EQ(test.l, outputs_S[i]); } } } } TEST(min_max) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); struct TestFloat { double a; double b; double c; double d; float e; float f; float g; float h; }; TestFloat test; const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); const int kTableLength = 13; double inputsa[kTableLength] = {2.0, 3.0, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = {3.0, 2.0, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double outputsdmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double outputsdmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputse[kTableLength] = {2.0, 3.0, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsf[kTableLength] = {3.0, 2.0, 3.0, fnan, 0.0, -0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float outputsfmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float outputsfmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a))); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, b))); __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, e))); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, f))); __ min_d(f10, f4, f8); __ max_d(f12, f4, f8); __ min_s(f14, f2, f6); __ max_s(f16, f2, f6); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, c))); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, d))); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, g))); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, h))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 4; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.e = inputse[i]; test.f = inputsf[i]; CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0); CHECK_EQ(0, memcmp(&test.c, &outputsdmin[i], sizeof(test.c))); CHECK_EQ(0, memcmp(&test.d, &outputsdmax[i], sizeof(test.d))); CHECK_EQ(0, memcmp(&test.g, &outputsfmin[i], sizeof(test.g))); CHECK_EQ(0, memcmp(&test.h, &outputsfmax[i], sizeof(test.h))); } } } TEST(rint_d) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; int fcsr; }TestFloat; TestFloat test; double inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E+308, 6.27463370218383111104242366943E-307, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ ctc1(t0, FCSR); __ rint_d(f8, f4); __ sdc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(sel) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { double dd; double ds; double dt; float fd; float fs; float ft; } Test; Test test; __ ldc1(f0, MemOperand(a0, offsetof(Test, dd)) ); // test __ ldc1(f2, MemOperand(a0, offsetof(Test, ds)) ); // src1 __ ldc1(f4, MemOperand(a0, offsetof(Test, dt)) ); // src2 __ lwc1(f6, MemOperand(a0, offsetof(Test, fd)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, fs)) ); // src1 __ lwc1(f10, MemOperand(a0, offsetof(Test, ft)) ); // src2 __ sel_d(f0, f2, f4); __ sel_s(f6, f8, f10); __ sdc1(f0, MemOperand(a0, offsetof(Test, dd)) ); __ swc1(f6, MemOperand(a0, offsetof(Test, fd)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); const int test_size = 3; const int input_size = 5; double inputs_dt[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double inputs_ds[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; float inputs_ft[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float inputs_fs[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.dt = inputs_dt[i]; test.dd = tests_D[j]; test.ds = inputs_ds[i]; test.ft = inputs_ft[i]; test.fd = tests_S[j]; test.fs = inputs_fs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_ds[i]); CHECK_EQ(test.fd, inputs_fs[i]); test.dd = tests_D[j+1]; test.fd = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_dt[i]); CHECK_EQ(test.fd, inputs_ft[i]); } } } } TEST(rint_s) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; int fcsr; }TestFloat; TestFloat test; float inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E+38, 6.27463370218383111104242366943E-37, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; float* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ rint_s(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(mina_maxa) { if (kArchVariant == kMips64r6) { const int kTableLength = 23; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); struct TestFloat { double a; double b; double resd; double resd1; float c; float d; float resf; float resf1; }; TestFloat test; double inputsa[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = { 4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double resd[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double resd1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputsc[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsd[kTableLength] = {4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, fnan, -0.0, 0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float resf[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float resf1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ lwc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ lwc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ mina_d(f6, f2, f4); __ mina_s(f12, f8, f10); __ maxa_d(f14, f2, f4); __ maxa_s(f16, f8, f10); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, resf)) ); __ sdc1(f6, MemOperand(a0, offsetof(TestFloat, resd)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resf1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resd1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.c = inputsc[i]; test.d = inputsd[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if (i < kTableLength - 1) { CHECK_EQ(test.resd, resd[i]); CHECK_EQ(test.resf, resf[i]); CHECK_EQ(test.resd1, resd1[i]); CHECK_EQ(test.resf1, resf1[i]); } else { CHECK(std::isnan(test.resd)); CHECK(std::isnan(test.resf)); CHECK(std::isnan(test.resd1)); CHECK(std::isnan(test.resf1)); } } } } // ----------------------mips64r2 specific tests---------------------- TEST(trunc_l) { if (kArchVariant == kMips64r2) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; // a trunc result int64_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_l_d(f8, f4); __ trunc_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } } TEST(movz_movn) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { int64_t rt; double a; double b; double bold; double b1; double bold1; float c; float d; float dold; float d1; float dold1; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ld(t0, MemOperand(a0, offsetof(TestFloat, rt))); __ Move(f12, 0.0); __ Move(f10, 0.0); __ Move(f16, 0.0); __ Move(f14, 0.0); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, bold)) ); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, dold)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, bold1)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, dold1)) ); __ movz_s(f10, f6, t0); __ movz_d(f12, f2, t0); __ movn_s(f14, f6, t0); __ movn_d(f16, f2, t0); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, b)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, d1)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, b1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; test.rt = 1; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, test.bold); CHECK_EQ(test.d, test.dold); CHECK_EQ(test.b1, outputs_D[i]); CHECK_EQ(test.d1, outputs_S[i]); test.rt = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); CHECK_EQ(test.b1, test.bold1); CHECK_EQ(test.d1, test.dold1); } } } TEST(movt_movd) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); typedef struct test_float { double srcd; double dstd; double dstdold; double dstd1; double dstdold1; float srcf; float dstf; float dstfold; float dstf1; float dstfold1; int32_t cc; int32_t fcsr; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; double inputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; int condition_flags[8] = {0, 1, 2, 3, 4, 5, 6, 7}; for (int i = 0; i < kTableLength; i++) { test.srcd = inputs_D[i]; test.srcf = inputs_S[i]; for (int j = 0; j< 8; j++) { test.cc = condition_flags[j]; if (test.cc == 0) { test.fcsr = 1 << 23; } else { test.fcsr = 1 << (24+condition_flags[j]); } HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, srcd)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, srcf)) ); __ lw(t1, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t0, FCSR); __ ctc1(t1, FCSR); __ li(t2, 0x0); __ mtc1(t2, f12); __ mtc1(t2, f10); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold)) ); __ movt_s(f12, f4, test.cc); __ movt_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold1)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold1)) ); __ movf_s(f12, f4, test.cc); __ movf_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf1)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd1)) ); __ ctc1(t0, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, outputs_S[i]); CHECK_EQ(test.dstd, outputs_D[i]); CHECK_EQ(test.dstf1, test.dstfold1); CHECK_EQ(test.dstd1, test.dstdold1); test.fcsr = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, test.dstfold); CHECK_EQ(test.dstd, test.dstdold); CHECK_EQ(test.dstf1, outputs_S[i]); CHECK_EQ(test.dstd1, outputs_D[i]); } } } } // ----------------------tests for all archs-------------------------- TEST(cvt_w_d) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; int32_t b; int fcsr; }Test; const int kTableLength = 24; double inputs[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, 2147483653.0 }; double outputs_RN[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RZ[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RP[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RM[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lw(t0, MemOperand(a0, offsetof(Test, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ cvt_w_d(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(Test, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } TEST(trunc_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_w_d(f8, f4); __ trunc_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_w_d(f8, f4); __ round_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_l_d(f8, f4); __ round_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(sub) { const int kTableLength = 12; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; double inputft_D[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; double outputs_D[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; float inputfs_S[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; float inputft_S[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; float outputs_S[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sub_s(f6, f2, f4); __ sub_d(f12, f8, f10); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(sqrt_rsqrt_recip) { const int kTableLength = 4; const double deltaDouble = 2E-15; const float deltaFloat = 2E-7; const float sqrt2_s = sqrt(2); const double sqrt2_d = sqrt(2); CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; float resultS1; float resultS2; double c; double resultD; double resultD1; double resultD2; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 0.0L, 4.0L, 2.0L, 4e-28L }; double outputs_D[kTableLength] = { 0.0L, 2.0L, sqrt2_d, 2e-14L }; float inputs_S[kTableLength] = { 0.0, 4.0, 2.0, 4e-28 }; float outputs_S[kTableLength] = { 0.0, 2.0, sqrt2_s, 2e-14 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ sqrt_s(f6, f2); __ sqrt_d(f12, f8); __ rsqrt_d(f14, f8); __ rsqrt_s(f16, f2); __ recip_d(f18, f8); __ recip_s(f4, f2); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resultS1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resultD1)) ); __ swc1(f4, MemOperand(a0, offsetof(TestFloat, resultS2)) ); __ sdc1(f18, MemOperand(a0, offsetof(TestFloat, resultD2)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { float f1; double d1; test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); if (i != 0) { f1 = test.resultS1 - 1.0F/outputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD1 - 1.0L/outputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); f1 = test.resultS2 - 1.0F/inputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD2 - 1.0L/inputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); } else { CHECK_EQ(test.resultS1, 1.0F/outputs_S[i]); CHECK_EQ(test.resultD1, 1.0L/outputs_D[i]); CHECK_EQ(test.resultS2, 1.0F/inputs_S[i]); CHECK_EQ(test.resultD2, 1.0L/inputs_D[i]); } } } TEST(neg) { const int kTableLength = 2; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; double c; double resultD; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 4.0, -2.0 }; double outputs_D[kTableLength] = { -4.0, 2.0 }; float inputs_S[kTableLength] = { 4.0, -2.0 }; float outputs_S[kTableLength] = { -4.0, 2.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ neg_s(f6, f2); __ neg_d(f12, f8); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F2 f = FUNCTION_CAST(code->entry()); int64_t res = reinterpret_cast( CALL_GENERATED_CODE(isolate, f, 0xab0, 0xc, 0, 0, 0)); CHECK_EQ(0x31415926L, res); } TEST(MIPS3) { // Test floating point instructions. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double a; double b; double c; double d; double e; double f; double g; double h; double i; float fa; float fb; float fc; float fd; float fe; float ff; float fg; } T; T t; // Create a function that accepts &t, and loads, manipulates, and stores // the doubles t.a ... t.f. MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); Label L, C; // Double precision floating point instructions. __ ldc1(f4, MemOperand(a0, offsetof(T, a)) ); __ ldc1(f6, MemOperand(a0, offsetof(T, b)) ); __ add_d(f8, f4, f6); __ sdc1(f8, MemOperand(a0, offsetof(T, c)) ); // c = a + b. __ mov_d(f10, f8); // c __ neg_d(f12, f6); // -b __ sub_d(f10, f10, f12); __ sdc1(f10, MemOperand(a0, offsetof(T, d)) ); // d = c - (-b). __ sdc1(f4, MemOperand(a0, offsetof(T, b)) ); // b = a. __ li(a4, 120); __ mtc1(a4, f14); __ cvt_d_w(f14, f14); // f14 = 120.0. __ mul_d(f10, f10, f14); __ sdc1(f10, MemOperand(a0, offsetof(T, e)) ); // e = d * 120 = 1.8066e16. __ div_d(f12, f10, f4); __ sdc1(f12, MemOperand(a0, offsetof(T, f)) ); // f = e / a = 120.44. __ sqrt_d(f14, f12); __ sdc1(f14, MemOperand(a0, offsetof(T, g)) ); // g = sqrt(f) = 10.97451593465515908537 if (kArchVariant == kMips64r2) { __ ldc1(f4, MemOperand(a0, offsetof(T, h)) ); __ ldc1(f6, MemOperand(a0, offsetof(T, i)) ); __ madd_d(f14, f6, f4, f6); __ sdc1(f14, MemOperand(a0, offsetof(T, h)) ); } // Single precision floating point instructions. __ lwc1(f4, MemOperand(a0, offsetof(T, fa)) ); __ lwc1(f6, MemOperand(a0, offsetof(T, fb)) ); __ add_s(f8, f4, f6); __ swc1(f8, MemOperand(a0, offsetof(T, fc)) ); // fc = fa + fb. __ neg_s(f10, f6); // -fb __ sub_s(f10, f8, f10); __ swc1(f10, MemOperand(a0, offsetof(T, fd)) ); // fd = fc - (-fb). __ swc1(f4, MemOperand(a0, offsetof(T, fb)) ); // fb = fa. __ li(t0, 120); __ mtc1(t0, f14); __ cvt_s_w(f14, f14); // f14 = 120.0. __ mul_s(f10, f10, f14); __ swc1(f10, MemOperand(a0, offsetof(T, fe)) ); // fe = fd * 120 __ div_s(f12, f10, f4); __ swc1(f12, MemOperand(a0, offsetof(T, ff)) ); // ff = fe / fa __ sqrt_s(f14, f12); __ swc1(f14, MemOperand(a0, offsetof(T, fg)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); // Double test values. t.a = 1.5e14; t.b = 2.75e11; t.c = 0.0; t.d = 0.0; t.e = 0.0; t.f = 0.0; t.h = 1.5; t.i = 2.75; // Single test values. t.fa = 1.5e6; t.fb = 2.75e4; t.fc = 0.0; t.fd = 0.0; t.fe = 0.0; t.ff = 0.0; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); // Expected double results. CHECK_EQ(1.5e14, t.a); CHECK_EQ(1.5e14, t.b); CHECK_EQ(1.50275e14, t.c); CHECK_EQ(1.50550e14, t.d); CHECK_EQ(1.8066e16, t.e); CHECK_EQ(120.44, t.f); CHECK_EQ(10.97451593465515908537, t.g); if (kArchVariant == kMips64r2) { CHECK_EQ(6.875, t.h); } // Expected single results. CHECK_EQ(1.5e6, t.fa); CHECK_EQ(1.5e6, t.fb); CHECK_EQ(1.5275e06, t.fc); CHECK_EQ(1.5550e06, t.fd); CHECK_EQ(1.866e08, t.fe); CHECK_EQ(124.40000152587890625, t.ff); CHECK_EQ(11.1534748077392578125, t.fg); } TEST(MIPS4) { // Test moves between floating point and integer registers. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double a; double b; double c; double d; int64_t high; int64_t low; } T; T t; Assembler assm(isolate, NULL, 0); Label L, C; __ ldc1(f4, MemOperand(a0, offsetof(T, a))); __ ldc1(f5, MemOperand(a0, offsetof(T, b))); // Swap f4 and f5, by using 3 integer registers, a4-a6, // both two 32-bit chunks, and one 64-bit chunk. // mXhc1 is mips32/64-r2 only, not r1, // but we will not support r1 in practice. __ mfc1(a4, f4); __ mfhc1(a5, f4); __ dmfc1(a6, f5); __ mtc1(a4, f5); __ mthc1(a5, f5); __ dmtc1(a6, f4); // Store the swapped f4 and f5 back to memory. __ sdc1(f4, MemOperand(a0, offsetof(T, a))); __ sdc1(f5, MemOperand(a0, offsetof(T, c))); // Test sign extension of move operations from coprocessor. __ ldc1(f4, MemOperand(a0, offsetof(T, d))); __ mfhc1(a4, f4); __ mfc1(a5, f4); __ sd(a4, MemOperand(a0, offsetof(T, high))); __ sd(a5, MemOperand(a0, offsetof(T, low))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.a = 1.5e22; t.b = 2.75e11; t.c = 17.17; t.d = -2.75e11; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(2.75e11, t.a); CHECK_EQ(2.75e11, t.b); CHECK_EQ(1.5e22, t.c); CHECK_EQ(static_cast(0xffffffffc25001d1L), t.high); CHECK_EQ(static_cast(0xffffffffbf800000L), t.low); } TEST(MIPS5) { // Test conversions between doubles and integers. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double a; double b; int i; int j; } T; T t; Assembler assm(isolate, NULL, 0); Label L, C; // Load all structure elements to registers. __ ldc1(f4, MemOperand(a0, offsetof(T, a)) ); __ ldc1(f6, MemOperand(a0, offsetof(T, b)) ); __ lw(a4, MemOperand(a0, offsetof(T, i)) ); __ lw(a5, MemOperand(a0, offsetof(T, j)) ); // Convert double in f4 to int in element i. __ cvt_w_d(f8, f4); __ mfc1(a6, f8); __ sw(a6, MemOperand(a0, offsetof(T, i)) ); // Convert double in f6 to int in element j. __ cvt_w_d(f10, f6); __ mfc1(a7, f10); __ sw(a7, MemOperand(a0, offsetof(T, j)) ); // Convert int in original i (a4) to double in a. __ mtc1(a4, f12); __ cvt_d_w(f0, f12); __ sdc1(f0, MemOperand(a0, offsetof(T, a)) ); // Convert int in original j (a5) to double in b. __ mtc1(a5, f14); __ cvt_d_w(f2, f14); __ sdc1(f2, MemOperand(a0, offsetof(T, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.a = 1.5e4; t.b = 2.75e8; t.i = 12345678; t.j = -100000; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(12345678.0, t.a); CHECK_EQ(-100000.0, t.b); CHECK_EQ(15000, t.i); CHECK_EQ(275000000, t.j); } TEST(MIPS6) { // Test simple memory loads and stores. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { uint32_t ui; int32_t si; int32_t r1; int32_t r2; int32_t r3; int32_t r4; int32_t r5; int32_t r6; } T; T t; Assembler assm(isolate, NULL, 0); Label L, C; // Basic word load/store. __ lw(a4, MemOperand(a0, offsetof(T, ui)) ); __ sw(a4, MemOperand(a0, offsetof(T, r1)) ); // lh with positive data. __ lh(a5, MemOperand(a0, offsetof(T, ui)) ); __ sw(a5, MemOperand(a0, offsetof(T, r2)) ); // lh with negative data. __ lh(a6, MemOperand(a0, offsetof(T, si)) ); __ sw(a6, MemOperand(a0, offsetof(T, r3)) ); // lhu with negative data. __ lhu(a7, MemOperand(a0, offsetof(T, si)) ); __ sw(a7, MemOperand(a0, offsetof(T, r4)) ); // lb with negative data. __ lb(t0, MemOperand(a0, offsetof(T, si)) ); __ sw(t0, MemOperand(a0, offsetof(T, r5)) ); // sh writes only 1/2 of word. __ lui(t1, 0x3333); __ ori(t1, t1, 0x3333); __ sw(t1, MemOperand(a0, offsetof(T, r6)) ); __ lhu(t1, MemOperand(a0, offsetof(T, si)) ); __ sh(t1, MemOperand(a0, offsetof(T, r6)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.ui = 0x11223344; t.si = 0x99aabbcc; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(static_cast(0x11223344), t.r1); if (kArchEndian == kLittle) { CHECK_EQ(static_cast(0x3344), t.r2); CHECK_EQ(static_cast(0xffffbbcc), t.r3); CHECK_EQ(static_cast(0x0000bbcc), t.r4); CHECK_EQ(static_cast(0xffffffcc), t.r5); CHECK_EQ(static_cast(0x3333bbcc), t.r6); } else { CHECK_EQ(static_cast(0x1122), t.r2); CHECK_EQ(static_cast(0xffff99aa), t.r3); CHECK_EQ(static_cast(0x000099aa), t.r4); CHECK_EQ(static_cast(0xffffff99), t.r5); CHECK_EQ(static_cast(0x99aa3333), t.r6); } } TEST(MIPS7) { // Test floating point compare and branch instructions. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double a; double b; double c; double d; double e; double f; int32_t result; } T; T t; // Create a function that accepts &t, and loads, manipulates, and stores // the doubles t.a ... t.f. MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); Label neither_is_nan, less_than, outa_here; __ ldc1(f4, MemOperand(a0, offsetof(T, a)) ); __ ldc1(f6, MemOperand(a0, offsetof(T, b)) ); if (kArchVariant != kMips64r6) { __ c(UN, D, f4, f6); __ bc1f(&neither_is_nan); } else { __ cmp(UN, L, f2, f4, f6); __ bc1eqz(&neither_is_nan, f2); } __ nop(); __ sw(zero_reg, MemOperand(a0, offsetof(T, result)) ); __ Branch(&outa_here); __ bind(&neither_is_nan); if (kArchVariant == kMips64r6) { __ cmp(OLT, L, f2, f6, f4); __ bc1nez(&less_than, f2); } else { __ c(OLT, D, f6, f4, 2); __ bc1t(&less_than, 2); } __ nop(); __ sw(zero_reg, MemOperand(a0, offsetof(T, result)) ); __ Branch(&outa_here); __ bind(&less_than); __ Addu(a4, zero_reg, Operand(1)); __ sw(a4, MemOperand(a0, offsetof(T, result)) ); // Set true. // This test-case should have additional tests. __ bind(&outa_here); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.a = 1.5e14; t.b = 2.75e11; t.c = 2.0; t.d = -4.0; t.e = 0.0; t.f = 0.0; t.result = 0; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(1.5e14, t.a); CHECK_EQ(2.75e11, t.b); CHECK_EQ(1, t.result); } TEST(MIPS8) { if (kArchVariant == kMips64r2) { // Test ROTR and ROTRV instructions. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { int32_t input; int32_t result_rotr_4; int32_t result_rotr_8; int32_t result_rotr_12; int32_t result_rotr_16; int32_t result_rotr_20; int32_t result_rotr_24; int32_t result_rotr_28; int32_t result_rotrv_4; int32_t result_rotrv_8; int32_t result_rotrv_12; int32_t result_rotrv_16; int32_t result_rotrv_20; int32_t result_rotrv_24; int32_t result_rotrv_28; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); // Basic word load. __ lw(a4, MemOperand(a0, offsetof(T, input)) ); // ROTR instruction (called through the Ror macro). __ Ror(a5, a4, 0x0004); __ Ror(a6, a4, 0x0008); __ Ror(a7, a4, 0x000c); __ Ror(t0, a4, 0x0010); __ Ror(t1, a4, 0x0014); __ Ror(t2, a4, 0x0018); __ Ror(t3, a4, 0x001c); // Basic word store. __ sw(a5, MemOperand(a0, offsetof(T, result_rotr_4)) ); __ sw(a6, MemOperand(a0, offsetof(T, result_rotr_8)) ); __ sw(a7, MemOperand(a0, offsetof(T, result_rotr_12)) ); __ sw(t0, MemOperand(a0, offsetof(T, result_rotr_16)) ); __ sw(t1, MemOperand(a0, offsetof(T, result_rotr_20)) ); __ sw(t2, MemOperand(a0, offsetof(T, result_rotr_24)) ); __ sw(t3, MemOperand(a0, offsetof(T, result_rotr_28)) ); // ROTRV instruction (called through the Ror macro). __ li(t3, 0x0004); __ Ror(a5, a4, t3); __ li(t3, 0x0008); __ Ror(a6, a4, t3); __ li(t3, 0x000C); __ Ror(a7, a4, t3); __ li(t3, 0x0010); __ Ror(t0, a4, t3); __ li(t3, 0x0014); __ Ror(t1, a4, t3); __ li(t3, 0x0018); __ Ror(t2, a4, t3); __ li(t3, 0x001C); __ Ror(t3, a4, t3); // Basic word store. __ sw(a5, MemOperand(a0, offsetof(T, result_rotrv_4)) ); __ sw(a6, MemOperand(a0, offsetof(T, result_rotrv_8)) ); __ sw(a7, MemOperand(a0, offsetof(T, result_rotrv_12)) ); __ sw(t0, MemOperand(a0, offsetof(T, result_rotrv_16)) ); __ sw(t1, MemOperand(a0, offsetof(T, result_rotrv_20)) ); __ sw(t2, MemOperand(a0, offsetof(T, result_rotrv_24)) ); __ sw(t3, MemOperand(a0, offsetof(T, result_rotrv_28)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.input = 0x12345678; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0x0, 0, 0, 0); USE(dummy); CHECK_EQ(static_cast(0x81234567), t.result_rotr_4); CHECK_EQ(static_cast(0x78123456), t.result_rotr_8); CHECK_EQ(static_cast(0x67812345), t.result_rotr_12); CHECK_EQ(static_cast(0x56781234), t.result_rotr_16); CHECK_EQ(static_cast(0x45678123), t.result_rotr_20); CHECK_EQ(static_cast(0x34567812), t.result_rotr_24); CHECK_EQ(static_cast(0x23456781), t.result_rotr_28); CHECK_EQ(static_cast(0x81234567), t.result_rotrv_4); CHECK_EQ(static_cast(0x78123456), t.result_rotrv_8); CHECK_EQ(static_cast(0x67812345), t.result_rotrv_12); CHECK_EQ(static_cast(0x56781234), t.result_rotrv_16); CHECK_EQ(static_cast(0x45678123), t.result_rotrv_20); CHECK_EQ(static_cast(0x34567812), t.result_rotrv_24); CHECK_EQ(static_cast(0x23456781), t.result_rotrv_28); } } TEST(MIPS9) { // Test BRANCH improvements. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); Label exit, exit2, exit3; __ Branch(&exit, ge, a0, Operand(zero_reg)); __ Branch(&exit2, ge, a0, Operand(0x00001FFF)); __ Branch(&exit3, ge, a0, Operand(0x0001FFFF)); __ bind(&exit); __ bind(&exit2); __ bind(&exit3); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); } TEST(MIPS10) { // Test conversions between doubles and long integers. // Test hos the long ints map to FP regs pairs. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double a; double a_converted; double b; int32_t dbl_mant; int32_t dbl_exp; int32_t long_hi; int32_t long_lo; int64_t long_as_int64; int32_t b_long_hi; int32_t b_long_lo; int64_t b_long_as_int64; } T; T t; Assembler assm(isolate, NULL, 0); Label L, C; if (kArchVariant == kMips64r2) { // Rewritten for FR=1 FPU mode: // - 32 FP regs of 64-bits each, no odd/even pairs. // - Note that cvt_l_d/cvt_d_l ARE legal in FR=1 mode. // Load all structure elements to registers. __ ldc1(f0, MemOperand(a0, offsetof(T, a))); // Save the raw bits of the double. __ mfc1(a4, f0); __ mfhc1(a5, f0); __ sw(a4, MemOperand(a0, offsetof(T, dbl_mant))); __ sw(a5, MemOperand(a0, offsetof(T, dbl_exp))); // Convert double in f0 to long, save hi/lo parts. __ cvt_l_d(f0, f0); __ mfc1(a4, f0); // f0 LS 32 bits of long. __ mfhc1(a5, f0); // f0 MS 32 bits of long. __ sw(a4, MemOperand(a0, offsetof(T, long_lo))); __ sw(a5, MemOperand(a0, offsetof(T, long_hi))); // Combine the high/low ints, convert back to double. __ dsll32(a6, a5, 0); // Move a5 to high bits of a6. __ or_(a6, a6, a4); __ dmtc1(a6, f1); __ cvt_d_l(f1, f1); __ sdc1(f1, MemOperand(a0, offsetof(T, a_converted))); // Convert the b long integers to double b. __ lw(a4, MemOperand(a0, offsetof(T, b_long_lo))); __ lw(a5, MemOperand(a0, offsetof(T, b_long_hi))); __ mtc1(a4, f8); // f8 LS 32-bits. __ mthc1(a5, f8); // f8 MS 32-bits. __ cvt_d_l(f10, f8); __ sdc1(f10, MemOperand(a0, offsetof(T, b))); // Convert double b back to long-int. __ ldc1(f31, MemOperand(a0, offsetof(T, b))); __ cvt_l_d(f31, f31); __ dmfc1(a7, f31); __ sd(a7, MemOperand(a0, offsetof(T, b_long_as_int64))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.a = 2.147483647e9; // 0x7fffffff -> 0x41DFFFFFFFC00000 as double. t.b_long_hi = 0x000000ff; // 0xFF00FF00FF -> 0x426FE01FE01FE000 as double. t.b_long_lo = 0x00ff00ff; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(static_cast(0x41DFFFFF), t.dbl_exp); CHECK_EQ(static_cast(0xFFC00000), t.dbl_mant); CHECK_EQ(0, t.long_hi); CHECK_EQ(static_cast(0x7fffffff), t.long_lo); CHECK_EQ(2.147483647e9, t.a_converted); // 0xFF00FF00FF -> 1.095233372415e12. CHECK_EQ(1.095233372415e12, t.b); CHECK_EQ(static_cast(0xFF00FF00FF), t.b_long_as_int64); } } TEST(MIPS11) { // Do not run test on MIPS64r6, as these instructions are removed. if (kArchVariant != kMips64r6) { // Test LWL, LWR, SWL and SWR instructions. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { int32_t reg_init; int32_t mem_init; int32_t lwl_0; int32_t lwl_1; int32_t lwl_2; int32_t lwl_3; int32_t lwr_0; int32_t lwr_1; int32_t lwr_2; int32_t lwr_3; int32_t swl_0; int32_t swl_1; int32_t swl_2; int32_t swl_3; int32_t swr_0; int32_t swr_1; int32_t swr_2; int32_t swr_3; } T; T t; Assembler assm(isolate, NULL, 0); // Test all combinations of LWL and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, lwl_0))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a5, MemOperand(a0, offsetof(T, mem_init) + 1)); __ sw(a5, MemOperand(a0, offsetof(T, lwl_1))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a6, MemOperand(a0, offsetof(T, mem_init) + 2)); __ sw(a6, MemOperand(a0, offsetof(T, lwl_2))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a7, MemOperand(a0, offsetof(T, mem_init) + 3)); __ sw(a7, MemOperand(a0, offsetof(T, lwl_3))); // Test all combinations of LWR and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, lwr_0))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a5, MemOperand(a0, offsetof(T, mem_init) + 1)); __ sw(a5, MemOperand(a0, offsetof(T, lwr_1))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a6, MemOperand(a0, offsetof(T, mem_init) + 2)); __ sw(a6, MemOperand(a0, offsetof(T, lwr_2)) ); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a7, MemOperand(a0, offsetof(T, mem_init) + 3)); __ sw(a7, MemOperand(a0, offsetof(T, lwr_3)) ); // Test all combinations of SWL and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, swl_0))); __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ swl(a4, MemOperand(a0, offsetof(T, swl_0))); __ lw(a5, MemOperand(a0, offsetof(T, mem_init))); __ sw(a5, MemOperand(a0, offsetof(T, swl_1))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ swl(a5, MemOperand(a0, offsetof(T, swl_1) + 1)); __ lw(a6, MemOperand(a0, offsetof(T, mem_init))); __ sw(a6, MemOperand(a0, offsetof(T, swl_2))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ swl(a6, MemOperand(a0, offsetof(T, swl_2) + 2)); __ lw(a7, MemOperand(a0, offsetof(T, mem_init))); __ sw(a7, MemOperand(a0, offsetof(T, swl_3))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ swl(a7, MemOperand(a0, offsetof(T, swl_3) + 3)); // Test all combinations of SWR and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, swr_0))); __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ swr(a4, MemOperand(a0, offsetof(T, swr_0))); __ lw(a5, MemOperand(a0, offsetof(T, mem_init))); __ sw(a5, MemOperand(a0, offsetof(T, swr_1))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ swr(a5, MemOperand(a0, offsetof(T, swr_1) + 1)); __ lw(a6, MemOperand(a0, offsetof(T, mem_init))); __ sw(a6, MemOperand(a0, offsetof(T, swr_2))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ swr(a6, MemOperand(a0, offsetof(T, swr_2) + 2)); __ lw(a7, MemOperand(a0, offsetof(T, mem_init))); __ sw(a7, MemOperand(a0, offsetof(T, swr_3))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ swr(a7, MemOperand(a0, offsetof(T, swr_3) + 3)); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.reg_init = 0xaabbccdd; t.mem_init = 0x11223344; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); if (kArchEndian == kLittle) { CHECK_EQ(static_cast(0x44bbccdd), t.lwl_0); CHECK_EQ(static_cast(0x3344ccdd), t.lwl_1); CHECK_EQ(static_cast(0x223344dd), t.lwl_2); CHECK_EQ(static_cast(0x11223344), t.lwl_3); CHECK_EQ(static_cast(0x11223344), t.lwr_0); CHECK_EQ(static_cast(0xaa112233), t.lwr_1); CHECK_EQ(static_cast(0xaabb1122), t.lwr_2); CHECK_EQ(static_cast(0xaabbcc11), t.lwr_3); CHECK_EQ(static_cast(0x112233aa), t.swl_0); CHECK_EQ(static_cast(0x1122aabb), t.swl_1); CHECK_EQ(static_cast(0x11aabbcc), t.swl_2); CHECK_EQ(static_cast(0xaabbccdd), t.swl_3); CHECK_EQ(static_cast(0xaabbccdd), t.swr_0); CHECK_EQ(static_cast(0xbbccdd44), t.swr_1); CHECK_EQ(static_cast(0xccdd3344), t.swr_2); CHECK_EQ(static_cast(0xdd223344), t.swr_3); } else { CHECK_EQ(static_cast(0x11223344), t.lwl_0); CHECK_EQ(static_cast(0x223344dd), t.lwl_1); CHECK_EQ(static_cast(0x3344ccdd), t.lwl_2); CHECK_EQ(static_cast(0x44bbccdd), t.lwl_3); CHECK_EQ(static_cast(0xaabbcc11), t.lwr_0); CHECK_EQ(static_cast(0xaabb1122), t.lwr_1); CHECK_EQ(static_cast(0xaa112233), t.lwr_2); CHECK_EQ(static_cast(0x11223344), t.lwr_3); CHECK_EQ(static_cast(0xaabbccdd), t.swl_0); CHECK_EQ(static_cast(0x11aabbcc), t.swl_1); CHECK_EQ(static_cast(0x1122aabb), t.swl_2); CHECK_EQ(static_cast(0x112233aa), t.swl_3); CHECK_EQ(static_cast(0xdd223344), t.swr_0); CHECK_EQ(static_cast(0xccdd3344), t.swr_1); CHECK_EQ(static_cast(0xbbccdd44), t.swr_2); CHECK_EQ(static_cast(0xaabbccdd), t.swr_3); } } } TEST(MIPS12) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { int32_t x; int32_t y; int32_t y1; int32_t y2; int32_t y3; int32_t y4; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ mov(t2, fp); // Save frame pointer. __ mov(fp, a0); // Access struct T by fp. __ lw(a4, MemOperand(a0, offsetof(T, y))); __ lw(a7, MemOperand(a0, offsetof(T, y4))); __ addu(a5, a4, a7); __ subu(t0, a4, a7); __ nop(); __ push(a4); // These instructions disappear after opt. __ Pop(); __ addu(a4, a4, a4); __ nop(); __ Pop(); // These instructions disappear after opt. __ push(a7); __ nop(); __ push(a7); // These instructions disappear after opt. __ pop(a7); __ nop(); __ push(a7); __ pop(t0); __ nop(); __ sw(a4, MemOperand(fp, offsetof(T, y))); __ lw(a4, MemOperand(fp, offsetof(T, y))); __ nop(); __ sw(a4, MemOperand(fp, offsetof(T, y))); __ lw(a5, MemOperand(fp, offsetof(T, y))); __ nop(); __ push(a5); __ lw(a5, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a6); __ nop(); __ push(a6); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a7); __ nop(); __ mov(fp, t2); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.x = 1; t.y = 2; t.y1 = 3; t.y2 = 4; t.y3 = 0XBABA; t.y4 = 0xDEDA; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(3, t.y1); } TEST(MIPS13) { // Test Cvt_d_uw and Trunc_uw_d macros. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double cvt_big_out; double cvt_small_out; uint32_t trunc_big_out; uint32_t trunc_small_out; uint32_t cvt_big_in; uint32_t cvt_small_in; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ sw(a4, MemOperand(a0, offsetof(T, cvt_small_in))); __ Cvt_d_uw(f10, a4); __ sdc1(f10, MemOperand(a0, offsetof(T, cvt_small_out))); __ Trunc_uw_d(f10, f10, f4); __ swc1(f10, MemOperand(a0, offsetof(T, trunc_small_out))); __ sw(a4, MemOperand(a0, offsetof(T, cvt_big_in))); __ Cvt_d_uw(f8, a4); __ sdc1(f8, MemOperand(a0, offsetof(T, cvt_big_out))); __ Trunc_uw_d(f8, f8, f4); __ swc1(f8, MemOperand(a0, offsetof(T, trunc_big_out))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.cvt_big_in = 0xFFFFFFFF; t.cvt_small_in = 333; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(t.cvt_big_out, static_cast(t.cvt_big_in)); CHECK_EQ(t.cvt_small_out, static_cast(t.cvt_small_in)); CHECK_EQ(static_cast(t.trunc_big_out), static_cast(t.cvt_big_in)); CHECK_EQ(static_cast(t.trunc_small_out), static_cast(t.cvt_small_in)); } TEST(MIPS14) { // Test round, floor, ceil, trunc, cvt. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); #define ROUND_STRUCT_ELEMENT(x) \ uint32_t x##_isNaN2008; \ int32_t x##_up_out; \ int32_t x##_down_out; \ int32_t neg_##x##_up_out; \ int32_t neg_##x##_down_out; \ uint32_t x##_err1_out; \ uint32_t x##_err2_out; \ uint32_t x##_err3_out; \ uint32_t x##_err4_out; \ int32_t x##_invalid_result; typedef struct { double round_up_in; double round_down_in; double neg_round_up_in; double neg_round_down_in; double err1_in; double err2_in; double err3_in; double err4_in; ROUND_STRUCT_ELEMENT(round) ROUND_STRUCT_ELEMENT(floor) ROUND_STRUCT_ELEMENT(ceil) ROUND_STRUCT_ELEMENT(trunc) ROUND_STRUCT_ELEMENT(cvt) } T; T t; #undef ROUND_STRUCT_ELEMENT MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); // Save FCSR. __ cfc1(a1, FCSR); // Disable FPU exceptions. __ ctc1(zero_reg, FCSR); #define RUN_ROUND_TEST(x) \ __ cfc1(t0, FCSR);\ __ sw(t0, MemOperand(a0, offsetof(T, x##_isNaN2008))); \ __ ldc1(f0, MemOperand(a0, offsetof(T, round_up_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_up_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, round_down_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_down_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, neg_round_up_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, neg_##x##_up_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, neg_round_down_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, neg_##x##_down_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err1_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err1_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err2_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err2_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err3_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err3_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err4_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err4_out))); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_invalid_result))); RUN_ROUND_TEST(round) RUN_ROUND_TEST(floor) RUN_ROUND_TEST(ceil) RUN_ROUND_TEST(trunc) RUN_ROUND_TEST(cvt) // Restore FCSR. __ ctc1(a1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.round_up_in = 123.51; t.round_down_in = 123.49; t.neg_round_up_in = -123.5; t.neg_round_down_in = -123.49; t.err1_in = 123.51; t.err2_in = 1; t.err3_in = static_cast(1) + 0xFFFFFFFF; t.err4_in = NAN; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); #define GET_FPU_ERR(x) (static_cast(x & kFCSRFlagMask)) #define CHECK_NAN2008(x) (x & kFCSRNaN2008FlagMask) #define CHECK_ROUND_RESULT(type) \ CHECK(GET_FPU_ERR(t.type##_err1_out) & kFCSRInexactFlagMask); \ CHECK_EQ(0, GET_FPU_ERR(t.type##_err2_out)); \ CHECK(GET_FPU_ERR(t.type##_err3_out) & kFCSRInvalidOpFlagMask); \ CHECK(GET_FPU_ERR(t.type##_err4_out) & kFCSRInvalidOpFlagMask); \ if (CHECK_NAN2008(t.type##_isNaN2008) && kArchVariant == kMips64r6) { \ CHECK_EQ(static_cast(0), t.type##_invalid_result);\ } else { \ CHECK_EQ(static_cast(kFPUInvalidResult), t.type##_invalid_result);\ } CHECK_ROUND_RESULT(round); CHECK_ROUND_RESULT(floor); CHECK_ROUND_RESULT(ceil); CHECK_ROUND_RESULT(cvt); } TEST(MIPS15) { // Test chaining of label usages within instructions (issue 1644). CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); Assembler assm(isolate, NULL, 0); Label target; __ beq(v0, v1, &target); __ nop(); __ bne(v0, v1, &target); __ nop(); __ bind(&target); __ nop(); } // ----- mips64 tests ----------------------------------------------- TEST(MIPS16) { // Test 64-bit memory loads and stores. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); struct T { int64_t r1; int64_t r2; int64_t r3; int64_t r4; int64_t r5; int64_t r6; int64_t r7; int64_t r8; int64_t r9; int64_t r10; int64_t r11; int64_t r12; uint32_t ui; int32_t si; }; T t; Assembler assm(isolate, NULL, 0); Label L, C; // Basic 32-bit word load/store, with un-signed data. __ lw(a4, MemOperand(a0, offsetof(T, ui))); __ sw(a4, MemOperand(a0, offsetof(T, r1))); // Check that the data got zero-extended into 64-bit a4. __ sd(a4, MemOperand(a0, offsetof(T, r2))); // Basic 32-bit word load/store, with SIGNED data. __ lw(a5, MemOperand(a0, offsetof(T, si))); __ sw(a5, MemOperand(a0, offsetof(T, r3))); // Check that the data got sign-extended into 64-bit a4. __ sd(a5, MemOperand(a0, offsetof(T, r4))); // 32-bit UNSIGNED word load/store, with SIGNED data. __ lwu(a6, MemOperand(a0, offsetof(T, si))); __ sw(a6, MemOperand(a0, offsetof(T, r5))); // Check that the data got zero-extended into 64-bit a4. __ sd(a6, MemOperand(a0, offsetof(T, r6))); // lh with positive data. __ lh(a5, MemOperand(a0, offsetof(T, ui))); __ sw(a5, MemOperand(a0, offsetof(T, r7))); // lh with negative data. __ lh(a6, MemOperand(a0, offsetof(T, si))); __ sw(a6, MemOperand(a0, offsetof(T, r8))); // lhu with negative data. __ lhu(a7, MemOperand(a0, offsetof(T, si))); __ sw(a7, MemOperand(a0, offsetof(T, r9))); // lb with negative data. __ lb(t0, MemOperand(a0, offsetof(T, si))); __ sw(t0, MemOperand(a0, offsetof(T, r10))); // sh writes only 1/2 of word. __ lw(a4, MemOperand(a0, offsetof(T, ui))); __ sh(a4, MemOperand(a0, offsetof(T, r11))); __ lw(a4, MemOperand(a0, offsetof(T, si))); __ sh(a4, MemOperand(a0, offsetof(T, r12))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.ui = 0x44332211; t.si = 0x99aabbcc; t.r1 = 0x5555555555555555; t.r2 = 0x5555555555555555; t.r3 = 0x5555555555555555; t.r4 = 0x5555555555555555; t.r5 = 0x5555555555555555; t.r6 = 0x5555555555555555; t.r7 = 0x5555555555555555; t.r8 = 0x5555555555555555; t.r9 = 0x5555555555555555; t.r10 = 0x5555555555555555; t.r11 = 0x5555555555555555; t.r12 = 0x5555555555555555; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); if (kArchEndian == kLittle) { // Unsigned data, 32 & 64 CHECK_EQ(static_cast(0x5555555544332211L), t.r1); // lw, sw. CHECK_EQ(static_cast(0x0000000044332211L), t.r2); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x5555555599aabbccL), t.r3); // lw, sw. CHECK_EQ(static_cast(0xffffffff99aabbccL), t.r4); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x5555555599aabbccL), t.r5); // lwu, sw. CHECK_EQ(static_cast(0x0000000099aabbccL), t.r6); // sd. // lh with unsigned and signed data. CHECK_EQ(static_cast(0x5555555500002211L), t.r7); // lh, sw. CHECK_EQ(static_cast(0x55555555ffffbbccL), t.r8); // lh, sw. // lhu with signed data. CHECK_EQ(static_cast(0x555555550000bbccL), t.r9); // lhu, sw. // lb with signed data. CHECK_EQ(static_cast(0x55555555ffffffccL), t.r10); // lb, sw. // sh with unsigned and signed data. CHECK_EQ(static_cast(0x5555555555552211L), t.r11); // lw, sh. CHECK_EQ(static_cast(0x555555555555bbccL), t.r12); // lw, sh. } else { // Unsigned data, 32 & 64 CHECK_EQ(static_cast(0x4433221155555555L), t.r1); // lw, sw. CHECK_EQ(static_cast(0x0000000044332211L), t.r2); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x99aabbcc55555555L), t.r3); // lw, sw. CHECK_EQ(static_cast(0xffffffff99aabbccL), t.r4); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x99aabbcc55555555L), t.r5); // lwu, sw. CHECK_EQ(static_cast(0x0000000099aabbccL), t.r6); // sd. // lh with unsigned and signed data. CHECK_EQ(static_cast(0x0000443355555555L), t.r7); // lh, sw. CHECK_EQ(static_cast(0xffff99aa55555555L), t.r8); // lh, sw. // lhu with signed data. CHECK_EQ(static_cast(0x000099aa55555555L), t.r9); // lhu, sw. // lb with signed data. CHECK_EQ(static_cast(0xffffff9955555555L), t.r10); // lb, sw. // sh with unsigned and signed data. CHECK_EQ(static_cast(0x2211555555555555L), t.r11); // lw, sh. CHECK_EQ(static_cast(0xbbcc555555555555L), t.r12); // lw, sh. } } // ----------------------mips64r6 specific tests---------------------- TEST(seleqz_selnez) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { int a; int b; int c; int d; double e; double f; double g; double h; float i; float j; float k; float l; } Test; Test test; // Integer part of test. __ addiu(t1, zero_reg, 1); // t1 = 1 __ seleqz(t3, t1, zero_reg); // t3 = 1 __ sw(t3, MemOperand(a0, offsetof(Test, a))); // a = 1 __ seleqz(t2, t1, t1); // t2 = 0 __ sw(t2, MemOperand(a0, offsetof(Test, b))); // b = 0 __ selnez(t3, t1, zero_reg); // t3 = 1; __ sw(t3, MemOperand(a0, offsetof(Test, c))); // c = 0 __ selnez(t3, t1, t1); // t3 = 1 __ sw(t3, MemOperand(a0, offsetof(Test, d))); // d = 1 // Floating point part of test. __ ldc1(f0, MemOperand(a0, offsetof(Test, e)) ); // src __ ldc1(f2, MemOperand(a0, offsetof(Test, f)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, i)) ); // src __ lwc1(f10, MemOperand(a0, offsetof(Test, j)) ); // test __ seleqz_d(f4, f0, f2); __ selnez_d(f6, f0, f2); __ seleqz_s(f12, f8, f10); __ selnez_s(f14, f8, f10); __ sdc1(f4, MemOperand(a0, offsetof(Test, g)) ); // src __ sdc1(f6, MemOperand(a0, offsetof(Test, h)) ); // src __ swc1(f12, MemOperand(a0, offsetof(Test, k)) ); // src __ swc1(f14, MemOperand(a0, offsetof(Test, l)) ); // src __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.a, 1); CHECK_EQ(test.b, 0); CHECK_EQ(test.c, 0); CHECK_EQ(test.d, 1); const int test_size = 3; const int input_size = 5; double inputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double outputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float inputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float outputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.e = inputs_D[i]; test.f = tests_D[j]; test.i = inputs_S[i]; test.j = tests_S[j]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, outputs_D[i]); CHECK_EQ(test.h, 0); CHECK_EQ(test.k, outputs_S[i]); CHECK_EQ(test.l, 0); test.f = tests_D[j+1]; test.j = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, 0); CHECK_EQ(test.h, outputs_D[i]); CHECK_EQ(test.k, 0); CHECK_EQ(test.l, outputs_S[i]); } } } } TEST(min_max) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); struct TestFloat { double a; double b; double c; double d; float e; float f; float g; float h; }; TestFloat test; const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); const int kTableLength = 13; double inputsa[kTableLength] = {2.0, 3.0, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = {3.0, 2.0, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double outputsdmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double outputsdmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputse[kTableLength] = {2.0, 3.0, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsf[kTableLength] = {3.0, 2.0, 3.0, fnan, 0.0, -0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float outputsfmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float outputsfmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a))); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, b))); __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, e))); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, f))); __ min_d(f10, f4, f8); __ max_d(f12, f4, f8); __ min_s(f14, f2, f6); __ max_s(f16, f2, f6); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, c))); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, d))); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, g))); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, h))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 4; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.e = inputse[i]; test.f = inputsf[i]; CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0); CHECK_EQ(0, memcmp(&test.c, &outputsdmin[i], sizeof(test.c))); CHECK_EQ(0, memcmp(&test.d, &outputsdmax[i], sizeof(test.d))); CHECK_EQ(0, memcmp(&test.g, &outputsfmin[i], sizeof(test.g))); CHECK_EQ(0, memcmp(&test.h, &outputsfmax[i], sizeof(test.h))); } } } TEST(rint_d) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; int fcsr; }TestFloat; TestFloat test; double inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E+308, 6.27463370218383111104242366943E-307, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ ctc1(t0, FCSR); __ rint_d(f8, f4); __ sdc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(sel) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { double dd; double ds; double dt; float fd; float fs; float ft; } Test; Test test; __ ldc1(f0, MemOperand(a0, offsetof(Test, dd)) ); // test __ ldc1(f2, MemOperand(a0, offsetof(Test, ds)) ); // src1 __ ldc1(f4, MemOperand(a0, offsetof(Test, dt)) ); // src2 __ lwc1(f6, MemOperand(a0, offsetof(Test, fd)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, fs)) ); // src1 __ lwc1(f10, MemOperand(a0, offsetof(Test, ft)) ); // src2 __ sel_d(f0, f2, f4); __ sel_s(f6, f8, f10); __ sdc1(f0, MemOperand(a0, offsetof(Test, dd)) ); __ swc1(f6, MemOperand(a0, offsetof(Test, fd)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); const int test_size = 3; const int input_size = 5; double inputs_dt[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double inputs_ds[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; float inputs_ft[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float inputs_fs[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.dt = inputs_dt[i]; test.dd = tests_D[j]; test.ds = inputs_ds[i]; test.ft = inputs_ft[i]; test.fd = tests_S[j]; test.fs = inputs_fs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_ds[i]); CHECK_EQ(test.fd, inputs_fs[i]); test.dd = tests_D[j+1]; test.fd = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_dt[i]); CHECK_EQ(test.fd, inputs_ft[i]); } } } } TEST(rint_s) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; int fcsr; }TestFloat; TestFloat test; float inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E+38, 6.27463370218383111104242366943E-37, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; float* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ rint_s(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(mina_maxa) { if (kArchVariant == kMips64r6) { const int kTableLength = 23; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); struct TestFloat { double a; double b; double resd; double resd1; float c; float d; float resf; float resf1; }; TestFloat test; double inputsa[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = { 4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double resd[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double resd1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputsc[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsd[kTableLength] = {4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, fnan, -0.0, 0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float resf[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float resf1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ lwc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ lwc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ mina_d(f6, f2, f4); __ mina_s(f12, f8, f10); __ maxa_d(f14, f2, f4); __ maxa_s(f16, f8, f10); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, resf)) ); __ sdc1(f6, MemOperand(a0, offsetof(TestFloat, resd)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resf1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resd1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.c = inputsc[i]; test.d = inputsd[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if (i < kTableLength - 1) { CHECK_EQ(test.resd, resd[i]); CHECK_EQ(test.resf, resf[i]); CHECK_EQ(test.resd1, resd1[i]); CHECK_EQ(test.resf1, resf1[i]); } else { CHECK(std::isnan(test.resd)); CHECK(std::isnan(test.resf)); CHECK(std::isnan(test.resd1)); CHECK(std::isnan(test.resf1)); } } } } // ----------------------mips64r2 specific tests---------------------- TEST(trunc_l) { if (kArchVariant == kMips64r2) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; // a trunc result int64_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_l_d(f8, f4); __ trunc_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } } TEST(movz_movn) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { int64_t rt; double a; double b; double bold; double b1; double bold1; float c; float d; float dold; float d1; float dold1; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ld(t0, MemOperand(a0, offsetof(TestFloat, rt))); __ Move(f12, 0.0); __ Move(f10, 0.0); __ Move(f16, 0.0); __ Move(f14, 0.0); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, bold)) ); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, dold)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, bold1)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, dold1)) ); __ movz_s(f10, f6, t0); __ movz_d(f12, f2, t0); __ movn_s(f14, f6, t0); __ movn_d(f16, f2, t0); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, b)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, d1)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, b1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; test.rt = 1; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, test.bold); CHECK_EQ(test.d, test.dold); CHECK_EQ(test.b1, outputs_D[i]); CHECK_EQ(test.d1, outputs_S[i]); test.rt = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); CHECK_EQ(test.b1, test.bold1); CHECK_EQ(test.d1, test.dold1); } } } TEST(movt_movd) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); typedef struct test_float { double srcd; double dstd; double dstdold; double dstd1; double dstdold1; float srcf; float dstf; float dstfold; float dstf1; float dstfold1; int32_t cc; int32_t fcsr; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; double inputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; int condition_flags[8] = {0, 1, 2, 3, 4, 5, 6, 7}; for (int i = 0; i < kTableLength; i++) { test.srcd = inputs_D[i]; test.srcf = inputs_S[i]; for (int j = 0; j< 8; j++) { test.cc = condition_flags[j]; if (test.cc == 0) { test.fcsr = 1 << 23; } else { test.fcsr = 1 << (24+condition_flags[j]); } HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, srcd)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, srcf)) ); __ lw(t1, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t0, FCSR); __ ctc1(t1, FCSR); __ li(t2, 0x0); __ mtc1(t2, f12); __ mtc1(t2, f10); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold)) ); __ movt_s(f12, f4, test.cc); __ movt_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold1)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold1)) ); __ movf_s(f12, f4, test.cc); __ movf_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf1)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd1)) ); __ ctc1(t0, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, outputs_S[i]); CHECK_EQ(test.dstd, outputs_D[i]); CHECK_EQ(test.dstf1, test.dstfold1); CHECK_EQ(test.dstd1, test.dstdold1); test.fcsr = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, test.dstfold); CHECK_EQ(test.dstd, test.dstdold); CHECK_EQ(test.dstf1, outputs_S[i]); CHECK_EQ(test.dstd1, outputs_D[i]); } } } } // ----------------------tests for all archs-------------------------- TEST(cvt_w_d) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; int32_t b; int fcsr; }Test; const int kTableLength = 24; double inputs[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, 2147483653.0 }; double outputs_RN[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RZ[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RP[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RM[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lw(t0, MemOperand(a0, offsetof(Test, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ cvt_w_d(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(Test, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } TEST(trunc_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_w_d(f8, f4); __ trunc_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_w_d(f8, f4); __ round_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_l_d(f8, f4); __ round_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(sub) { const int kTableLength = 12; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; double inputft_D[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; double outputs_D[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; float inputfs_S[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; float inputft_S[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; float outputs_S[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sub_s(f6, f2, f4); __ sub_d(f12, f8, f10); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(sqrt_rsqrt_recip) { const int kTableLength = 4; const double deltaDouble = 2E-15; const float deltaFloat = 2E-7; const float sqrt2_s = sqrt(2); const double sqrt2_d = sqrt(2); CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; float resultS1; float resultS2; double c; double resultD; double resultD1; double resultD2; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 0.0L, 4.0L, 2.0L, 4e-28L }; double outputs_D[kTableLength] = { 0.0L, 2.0L, sqrt2_d, 2e-14L }; float inputs_S[kTableLength] = { 0.0, 4.0, 2.0, 4e-28 }; float outputs_S[kTableLength] = { 0.0, 2.0, sqrt2_s, 2e-14 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ sqrt_s(f6, f2); __ sqrt_d(f12, f8); __ rsqrt_d(f14, f8); __ rsqrt_s(f16, f2); __ recip_d(f18, f8); __ recip_s(f4, f2); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resultS1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resultD1)) ); __ swc1(f4, MemOperand(a0, offsetof(TestFloat, resultS2)) ); __ sdc1(f18, MemOperand(a0, offsetof(TestFloat, resultD2)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { float f1; double d1; test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); if (i != 0) { f1 = test.resultS1 - 1.0F/outputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD1 - 1.0L/outputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); f1 = test.resultS2 - 1.0F/inputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD2 - 1.0L/inputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); } else { CHECK_EQ(test.resultS1, 1.0F/outputs_S[i]); CHECK_EQ(test.resultD1, 1.0L/outputs_D[i]); CHECK_EQ(test.resultS2, 1.0F/inputs_S[i]); CHECK_EQ(test.resultD2, 1.0L/inputs_D[i]); } } } TEST(neg) { const int kTableLength = 2; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; double c; double resultD; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 4.0, -2.0 }; double outputs_D[kTableLength] = { -4.0, 2.0 }; float inputs_S[kTableLength] = { 4.0, -2.0 }; float outputs_S[kTableLength] = { -4.0, 2.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ neg_s(f6, f2); __ neg_d(f12, f8); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
()); F2 f = FUNCTION_CAST(code->entry()); int64_t res = reinterpret_cast( CALL_GENERATED_CODE(isolate, f, 0xab0, 0xc, 0, 0, 0)); CHECK_EQ(0x31415926L, res); } TEST(MIPS3) { // Test floating point instructions. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double a; double b; double c; double d; double e; double f; double g; double h; double i; float fa; float fb; float fc; float fd; float fe; float ff; float fg; } T; T t; // Create a function that accepts &t, and loads, manipulates, and stores // the doubles t.a ... t.f. MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); Label L, C; // Double precision floating point instructions. __ ldc1(f4, MemOperand(a0, offsetof(T, a)) ); __ ldc1(f6, MemOperand(a0, offsetof(T, b)) ); __ add_d(f8, f4, f6); __ sdc1(f8, MemOperand(a0, offsetof(T, c)) ); // c = a + b. __ mov_d(f10, f8); // c __ neg_d(f12, f6); // -b __ sub_d(f10, f10, f12); __ sdc1(f10, MemOperand(a0, offsetof(T, d)) ); // d = c - (-b). __ sdc1(f4, MemOperand(a0, offsetof(T, b)) ); // b = a. __ li(a4, 120); __ mtc1(a4, f14); __ cvt_d_w(f14, f14); // f14 = 120.0. __ mul_d(f10, f10, f14); __ sdc1(f10, MemOperand(a0, offsetof(T, e)) ); // e = d * 120 = 1.8066e16. __ div_d(f12, f10, f4); __ sdc1(f12, MemOperand(a0, offsetof(T, f)) ); // f = e / a = 120.44. __ sqrt_d(f14, f12); __ sdc1(f14, MemOperand(a0, offsetof(T, g)) ); // g = sqrt(f) = 10.97451593465515908537 if (kArchVariant == kMips64r2) { __ ldc1(f4, MemOperand(a0, offsetof(T, h)) ); __ ldc1(f6, MemOperand(a0, offsetof(T, i)) ); __ madd_d(f14, f6, f4, f6); __ sdc1(f14, MemOperand(a0, offsetof(T, h)) ); } // Single precision floating point instructions. __ lwc1(f4, MemOperand(a0, offsetof(T, fa)) ); __ lwc1(f6, MemOperand(a0, offsetof(T, fb)) ); __ add_s(f8, f4, f6); __ swc1(f8, MemOperand(a0, offsetof(T, fc)) ); // fc = fa + fb. __ neg_s(f10, f6); // -fb __ sub_s(f10, f8, f10); __ swc1(f10, MemOperand(a0, offsetof(T, fd)) ); // fd = fc - (-fb). __ swc1(f4, MemOperand(a0, offsetof(T, fb)) ); // fb = fa. __ li(t0, 120); __ mtc1(t0, f14); __ cvt_s_w(f14, f14); // f14 = 120.0. __ mul_s(f10, f10, f14); __ swc1(f10, MemOperand(a0, offsetof(T, fe)) ); // fe = fd * 120 __ div_s(f12, f10, f4); __ swc1(f12, MemOperand(a0, offsetof(T, ff)) ); // ff = fe / fa __ sqrt_s(f14, f12); __ swc1(f14, MemOperand(a0, offsetof(T, fg)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); // Double test values. t.a = 1.5e14; t.b = 2.75e11; t.c = 0.0; t.d = 0.0; t.e = 0.0; t.f = 0.0; t.h = 1.5; t.i = 2.75; // Single test values. t.fa = 1.5e6; t.fb = 2.75e4; t.fc = 0.0; t.fd = 0.0; t.fe = 0.0; t.ff = 0.0; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); // Expected double results. CHECK_EQ(1.5e14, t.a); CHECK_EQ(1.5e14, t.b); CHECK_EQ(1.50275e14, t.c); CHECK_EQ(1.50550e14, t.d); CHECK_EQ(1.8066e16, t.e); CHECK_EQ(120.44, t.f); CHECK_EQ(10.97451593465515908537, t.g); if (kArchVariant == kMips64r2) { CHECK_EQ(6.875, t.h); } // Expected single results. CHECK_EQ(1.5e6, t.fa); CHECK_EQ(1.5e6, t.fb); CHECK_EQ(1.5275e06, t.fc); CHECK_EQ(1.5550e06, t.fd); CHECK_EQ(1.866e08, t.fe); CHECK_EQ(124.40000152587890625, t.ff); CHECK_EQ(11.1534748077392578125, t.fg); } TEST(MIPS4) { // Test moves between floating point and integer registers. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double a; double b; double c; double d; int64_t high; int64_t low; } T; T t; Assembler assm(isolate, NULL, 0); Label L, C; __ ldc1(f4, MemOperand(a0, offsetof(T, a))); __ ldc1(f5, MemOperand(a0, offsetof(T, b))); // Swap f4 and f5, by using 3 integer registers, a4-a6, // both two 32-bit chunks, and one 64-bit chunk. // mXhc1 is mips32/64-r2 only, not r1, // but we will not support r1 in practice. __ mfc1(a4, f4); __ mfhc1(a5, f4); __ dmfc1(a6, f5); __ mtc1(a4, f5); __ mthc1(a5, f5); __ dmtc1(a6, f4); // Store the swapped f4 and f5 back to memory. __ sdc1(f4, MemOperand(a0, offsetof(T, a))); __ sdc1(f5, MemOperand(a0, offsetof(T, c))); // Test sign extension of move operations from coprocessor. __ ldc1(f4, MemOperand(a0, offsetof(T, d))); __ mfhc1(a4, f4); __ mfc1(a5, f4); __ sd(a4, MemOperand(a0, offsetof(T, high))); __ sd(a5, MemOperand(a0, offsetof(T, low))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.a = 1.5e22; t.b = 2.75e11; t.c = 17.17; t.d = -2.75e11; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(2.75e11, t.a); CHECK_EQ(2.75e11, t.b); CHECK_EQ(1.5e22, t.c); CHECK_EQ(static_cast(0xffffffffc25001d1L), t.high); CHECK_EQ(static_cast(0xffffffffbf800000L), t.low); } TEST(MIPS5) { // Test conversions between doubles and integers. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double a; double b; int i; int j; } T; T t; Assembler assm(isolate, NULL, 0); Label L, C; // Load all structure elements to registers. __ ldc1(f4, MemOperand(a0, offsetof(T, a)) ); __ ldc1(f6, MemOperand(a0, offsetof(T, b)) ); __ lw(a4, MemOperand(a0, offsetof(T, i)) ); __ lw(a5, MemOperand(a0, offsetof(T, j)) ); // Convert double in f4 to int in element i. __ cvt_w_d(f8, f4); __ mfc1(a6, f8); __ sw(a6, MemOperand(a0, offsetof(T, i)) ); // Convert double in f6 to int in element j. __ cvt_w_d(f10, f6); __ mfc1(a7, f10); __ sw(a7, MemOperand(a0, offsetof(T, j)) ); // Convert int in original i (a4) to double in a. __ mtc1(a4, f12); __ cvt_d_w(f0, f12); __ sdc1(f0, MemOperand(a0, offsetof(T, a)) ); // Convert int in original j (a5) to double in b. __ mtc1(a5, f14); __ cvt_d_w(f2, f14); __ sdc1(f2, MemOperand(a0, offsetof(T, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.a = 1.5e4; t.b = 2.75e8; t.i = 12345678; t.j = -100000; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(12345678.0, t.a); CHECK_EQ(-100000.0, t.b); CHECK_EQ(15000, t.i); CHECK_EQ(275000000, t.j); } TEST(MIPS6) { // Test simple memory loads and stores. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { uint32_t ui; int32_t si; int32_t r1; int32_t r2; int32_t r3; int32_t r4; int32_t r5; int32_t r6; } T; T t; Assembler assm(isolate, NULL, 0); Label L, C; // Basic word load/store. __ lw(a4, MemOperand(a0, offsetof(T, ui)) ); __ sw(a4, MemOperand(a0, offsetof(T, r1)) ); // lh with positive data. __ lh(a5, MemOperand(a0, offsetof(T, ui)) ); __ sw(a5, MemOperand(a0, offsetof(T, r2)) ); // lh with negative data. __ lh(a6, MemOperand(a0, offsetof(T, si)) ); __ sw(a6, MemOperand(a0, offsetof(T, r3)) ); // lhu with negative data. __ lhu(a7, MemOperand(a0, offsetof(T, si)) ); __ sw(a7, MemOperand(a0, offsetof(T, r4)) ); // lb with negative data. __ lb(t0, MemOperand(a0, offsetof(T, si)) ); __ sw(t0, MemOperand(a0, offsetof(T, r5)) ); // sh writes only 1/2 of word. __ lui(t1, 0x3333); __ ori(t1, t1, 0x3333); __ sw(t1, MemOperand(a0, offsetof(T, r6)) ); __ lhu(t1, MemOperand(a0, offsetof(T, si)) ); __ sh(t1, MemOperand(a0, offsetof(T, r6)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.ui = 0x11223344; t.si = 0x99aabbcc; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(static_cast(0x11223344), t.r1); if (kArchEndian == kLittle) { CHECK_EQ(static_cast(0x3344), t.r2); CHECK_EQ(static_cast(0xffffbbcc), t.r3); CHECK_EQ(static_cast(0x0000bbcc), t.r4); CHECK_EQ(static_cast(0xffffffcc), t.r5); CHECK_EQ(static_cast(0x3333bbcc), t.r6); } else { CHECK_EQ(static_cast(0x1122), t.r2); CHECK_EQ(static_cast(0xffff99aa), t.r3); CHECK_EQ(static_cast(0x000099aa), t.r4); CHECK_EQ(static_cast(0xffffff99), t.r5); CHECK_EQ(static_cast(0x99aa3333), t.r6); } } TEST(MIPS7) { // Test floating point compare and branch instructions. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double a; double b; double c; double d; double e; double f; int32_t result; } T; T t; // Create a function that accepts &t, and loads, manipulates, and stores // the doubles t.a ... t.f. MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); Label neither_is_nan, less_than, outa_here; __ ldc1(f4, MemOperand(a0, offsetof(T, a)) ); __ ldc1(f6, MemOperand(a0, offsetof(T, b)) ); if (kArchVariant != kMips64r6) { __ c(UN, D, f4, f6); __ bc1f(&neither_is_nan); } else { __ cmp(UN, L, f2, f4, f6); __ bc1eqz(&neither_is_nan, f2); } __ nop(); __ sw(zero_reg, MemOperand(a0, offsetof(T, result)) ); __ Branch(&outa_here); __ bind(&neither_is_nan); if (kArchVariant == kMips64r6) { __ cmp(OLT, L, f2, f6, f4); __ bc1nez(&less_than, f2); } else { __ c(OLT, D, f6, f4, 2); __ bc1t(&less_than, 2); } __ nop(); __ sw(zero_reg, MemOperand(a0, offsetof(T, result)) ); __ Branch(&outa_here); __ bind(&less_than); __ Addu(a4, zero_reg, Operand(1)); __ sw(a4, MemOperand(a0, offsetof(T, result)) ); // Set true. // This test-case should have additional tests. __ bind(&outa_here); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.a = 1.5e14; t.b = 2.75e11; t.c = 2.0; t.d = -4.0; t.e = 0.0; t.f = 0.0; t.result = 0; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(1.5e14, t.a); CHECK_EQ(2.75e11, t.b); CHECK_EQ(1, t.result); } TEST(MIPS8) { if (kArchVariant == kMips64r2) { // Test ROTR and ROTRV instructions. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { int32_t input; int32_t result_rotr_4; int32_t result_rotr_8; int32_t result_rotr_12; int32_t result_rotr_16; int32_t result_rotr_20; int32_t result_rotr_24; int32_t result_rotr_28; int32_t result_rotrv_4; int32_t result_rotrv_8; int32_t result_rotrv_12; int32_t result_rotrv_16; int32_t result_rotrv_20; int32_t result_rotrv_24; int32_t result_rotrv_28; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); // Basic word load. __ lw(a4, MemOperand(a0, offsetof(T, input)) ); // ROTR instruction (called through the Ror macro). __ Ror(a5, a4, 0x0004); __ Ror(a6, a4, 0x0008); __ Ror(a7, a4, 0x000c); __ Ror(t0, a4, 0x0010); __ Ror(t1, a4, 0x0014); __ Ror(t2, a4, 0x0018); __ Ror(t3, a4, 0x001c); // Basic word store. __ sw(a5, MemOperand(a0, offsetof(T, result_rotr_4)) ); __ sw(a6, MemOperand(a0, offsetof(T, result_rotr_8)) ); __ sw(a7, MemOperand(a0, offsetof(T, result_rotr_12)) ); __ sw(t0, MemOperand(a0, offsetof(T, result_rotr_16)) ); __ sw(t1, MemOperand(a0, offsetof(T, result_rotr_20)) ); __ sw(t2, MemOperand(a0, offsetof(T, result_rotr_24)) ); __ sw(t3, MemOperand(a0, offsetof(T, result_rotr_28)) ); // ROTRV instruction (called through the Ror macro). __ li(t3, 0x0004); __ Ror(a5, a4, t3); __ li(t3, 0x0008); __ Ror(a6, a4, t3); __ li(t3, 0x000C); __ Ror(a7, a4, t3); __ li(t3, 0x0010); __ Ror(t0, a4, t3); __ li(t3, 0x0014); __ Ror(t1, a4, t3); __ li(t3, 0x0018); __ Ror(t2, a4, t3); __ li(t3, 0x001C); __ Ror(t3, a4, t3); // Basic word store. __ sw(a5, MemOperand(a0, offsetof(T, result_rotrv_4)) ); __ sw(a6, MemOperand(a0, offsetof(T, result_rotrv_8)) ); __ sw(a7, MemOperand(a0, offsetof(T, result_rotrv_12)) ); __ sw(t0, MemOperand(a0, offsetof(T, result_rotrv_16)) ); __ sw(t1, MemOperand(a0, offsetof(T, result_rotrv_20)) ); __ sw(t2, MemOperand(a0, offsetof(T, result_rotrv_24)) ); __ sw(t3, MemOperand(a0, offsetof(T, result_rotrv_28)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.input = 0x12345678; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0x0, 0, 0, 0); USE(dummy); CHECK_EQ(static_cast(0x81234567), t.result_rotr_4); CHECK_EQ(static_cast(0x78123456), t.result_rotr_8); CHECK_EQ(static_cast(0x67812345), t.result_rotr_12); CHECK_EQ(static_cast(0x56781234), t.result_rotr_16); CHECK_EQ(static_cast(0x45678123), t.result_rotr_20); CHECK_EQ(static_cast(0x34567812), t.result_rotr_24); CHECK_EQ(static_cast(0x23456781), t.result_rotr_28); CHECK_EQ(static_cast(0x81234567), t.result_rotrv_4); CHECK_EQ(static_cast(0x78123456), t.result_rotrv_8); CHECK_EQ(static_cast(0x67812345), t.result_rotrv_12); CHECK_EQ(static_cast(0x56781234), t.result_rotrv_16); CHECK_EQ(static_cast(0x45678123), t.result_rotrv_20); CHECK_EQ(static_cast(0x34567812), t.result_rotrv_24); CHECK_EQ(static_cast(0x23456781), t.result_rotrv_28); } } TEST(MIPS9) { // Test BRANCH improvements. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); Label exit, exit2, exit3; __ Branch(&exit, ge, a0, Operand(zero_reg)); __ Branch(&exit2, ge, a0, Operand(0x00001FFF)); __ Branch(&exit3, ge, a0, Operand(0x0001FFFF)); __ bind(&exit); __ bind(&exit2); __ bind(&exit3); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); } TEST(MIPS10) { // Test conversions between doubles and long integers. // Test hos the long ints map to FP regs pairs. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double a; double a_converted; double b; int32_t dbl_mant; int32_t dbl_exp; int32_t long_hi; int32_t long_lo; int64_t long_as_int64; int32_t b_long_hi; int32_t b_long_lo; int64_t b_long_as_int64; } T; T t; Assembler assm(isolate, NULL, 0); Label L, C; if (kArchVariant == kMips64r2) { // Rewritten for FR=1 FPU mode: // - 32 FP regs of 64-bits each, no odd/even pairs. // - Note that cvt_l_d/cvt_d_l ARE legal in FR=1 mode. // Load all structure elements to registers. __ ldc1(f0, MemOperand(a0, offsetof(T, a))); // Save the raw bits of the double. __ mfc1(a4, f0); __ mfhc1(a5, f0); __ sw(a4, MemOperand(a0, offsetof(T, dbl_mant))); __ sw(a5, MemOperand(a0, offsetof(T, dbl_exp))); // Convert double in f0 to long, save hi/lo parts. __ cvt_l_d(f0, f0); __ mfc1(a4, f0); // f0 LS 32 bits of long. __ mfhc1(a5, f0); // f0 MS 32 bits of long. __ sw(a4, MemOperand(a0, offsetof(T, long_lo))); __ sw(a5, MemOperand(a0, offsetof(T, long_hi))); // Combine the high/low ints, convert back to double. __ dsll32(a6, a5, 0); // Move a5 to high bits of a6. __ or_(a6, a6, a4); __ dmtc1(a6, f1); __ cvt_d_l(f1, f1); __ sdc1(f1, MemOperand(a0, offsetof(T, a_converted))); // Convert the b long integers to double b. __ lw(a4, MemOperand(a0, offsetof(T, b_long_lo))); __ lw(a5, MemOperand(a0, offsetof(T, b_long_hi))); __ mtc1(a4, f8); // f8 LS 32-bits. __ mthc1(a5, f8); // f8 MS 32-bits. __ cvt_d_l(f10, f8); __ sdc1(f10, MemOperand(a0, offsetof(T, b))); // Convert double b back to long-int. __ ldc1(f31, MemOperand(a0, offsetof(T, b))); __ cvt_l_d(f31, f31); __ dmfc1(a7, f31); __ sd(a7, MemOperand(a0, offsetof(T, b_long_as_int64))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.a = 2.147483647e9; // 0x7fffffff -> 0x41DFFFFFFFC00000 as double. t.b_long_hi = 0x000000ff; // 0xFF00FF00FF -> 0x426FE01FE01FE000 as double. t.b_long_lo = 0x00ff00ff; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(static_cast(0x41DFFFFF), t.dbl_exp); CHECK_EQ(static_cast(0xFFC00000), t.dbl_mant); CHECK_EQ(0, t.long_hi); CHECK_EQ(static_cast(0x7fffffff), t.long_lo); CHECK_EQ(2.147483647e9, t.a_converted); // 0xFF00FF00FF -> 1.095233372415e12. CHECK_EQ(1.095233372415e12, t.b); CHECK_EQ(static_cast(0xFF00FF00FF), t.b_long_as_int64); } } TEST(MIPS11) { // Do not run test on MIPS64r6, as these instructions are removed. if (kArchVariant != kMips64r6) { // Test LWL, LWR, SWL and SWR instructions. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { int32_t reg_init; int32_t mem_init; int32_t lwl_0; int32_t lwl_1; int32_t lwl_2; int32_t lwl_3; int32_t lwr_0; int32_t lwr_1; int32_t lwr_2; int32_t lwr_3; int32_t swl_0; int32_t swl_1; int32_t swl_2; int32_t swl_3; int32_t swr_0; int32_t swr_1; int32_t swr_2; int32_t swr_3; } T; T t; Assembler assm(isolate, NULL, 0); // Test all combinations of LWL and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, lwl_0))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a5, MemOperand(a0, offsetof(T, mem_init) + 1)); __ sw(a5, MemOperand(a0, offsetof(T, lwl_1))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a6, MemOperand(a0, offsetof(T, mem_init) + 2)); __ sw(a6, MemOperand(a0, offsetof(T, lwl_2))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a7, MemOperand(a0, offsetof(T, mem_init) + 3)); __ sw(a7, MemOperand(a0, offsetof(T, lwl_3))); // Test all combinations of LWR and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, lwr_0))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a5, MemOperand(a0, offsetof(T, mem_init) + 1)); __ sw(a5, MemOperand(a0, offsetof(T, lwr_1))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a6, MemOperand(a0, offsetof(T, mem_init) + 2)); __ sw(a6, MemOperand(a0, offsetof(T, lwr_2)) ); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a7, MemOperand(a0, offsetof(T, mem_init) + 3)); __ sw(a7, MemOperand(a0, offsetof(T, lwr_3)) ); // Test all combinations of SWL and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, swl_0))); __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ swl(a4, MemOperand(a0, offsetof(T, swl_0))); __ lw(a5, MemOperand(a0, offsetof(T, mem_init))); __ sw(a5, MemOperand(a0, offsetof(T, swl_1))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ swl(a5, MemOperand(a0, offsetof(T, swl_1) + 1)); __ lw(a6, MemOperand(a0, offsetof(T, mem_init))); __ sw(a6, MemOperand(a0, offsetof(T, swl_2))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ swl(a6, MemOperand(a0, offsetof(T, swl_2) + 2)); __ lw(a7, MemOperand(a0, offsetof(T, mem_init))); __ sw(a7, MemOperand(a0, offsetof(T, swl_3))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ swl(a7, MemOperand(a0, offsetof(T, swl_3) + 3)); // Test all combinations of SWR and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, swr_0))); __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ swr(a4, MemOperand(a0, offsetof(T, swr_0))); __ lw(a5, MemOperand(a0, offsetof(T, mem_init))); __ sw(a5, MemOperand(a0, offsetof(T, swr_1))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ swr(a5, MemOperand(a0, offsetof(T, swr_1) + 1)); __ lw(a6, MemOperand(a0, offsetof(T, mem_init))); __ sw(a6, MemOperand(a0, offsetof(T, swr_2))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ swr(a6, MemOperand(a0, offsetof(T, swr_2) + 2)); __ lw(a7, MemOperand(a0, offsetof(T, mem_init))); __ sw(a7, MemOperand(a0, offsetof(T, swr_3))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ swr(a7, MemOperand(a0, offsetof(T, swr_3) + 3)); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.reg_init = 0xaabbccdd; t.mem_init = 0x11223344; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); if (kArchEndian == kLittle) { CHECK_EQ(static_cast(0x44bbccdd), t.lwl_0); CHECK_EQ(static_cast(0x3344ccdd), t.lwl_1); CHECK_EQ(static_cast(0x223344dd), t.lwl_2); CHECK_EQ(static_cast(0x11223344), t.lwl_3); CHECK_EQ(static_cast(0x11223344), t.lwr_0); CHECK_EQ(static_cast(0xaa112233), t.lwr_1); CHECK_EQ(static_cast(0xaabb1122), t.lwr_2); CHECK_EQ(static_cast(0xaabbcc11), t.lwr_3); CHECK_EQ(static_cast(0x112233aa), t.swl_0); CHECK_EQ(static_cast(0x1122aabb), t.swl_1); CHECK_EQ(static_cast(0x11aabbcc), t.swl_2); CHECK_EQ(static_cast(0xaabbccdd), t.swl_3); CHECK_EQ(static_cast(0xaabbccdd), t.swr_0); CHECK_EQ(static_cast(0xbbccdd44), t.swr_1); CHECK_EQ(static_cast(0xccdd3344), t.swr_2); CHECK_EQ(static_cast(0xdd223344), t.swr_3); } else { CHECK_EQ(static_cast(0x11223344), t.lwl_0); CHECK_EQ(static_cast(0x223344dd), t.lwl_1); CHECK_EQ(static_cast(0x3344ccdd), t.lwl_2); CHECK_EQ(static_cast(0x44bbccdd), t.lwl_3); CHECK_EQ(static_cast(0xaabbcc11), t.lwr_0); CHECK_EQ(static_cast(0xaabb1122), t.lwr_1); CHECK_EQ(static_cast(0xaa112233), t.lwr_2); CHECK_EQ(static_cast(0x11223344), t.lwr_3); CHECK_EQ(static_cast(0xaabbccdd), t.swl_0); CHECK_EQ(static_cast(0x11aabbcc), t.swl_1); CHECK_EQ(static_cast(0x1122aabb), t.swl_2); CHECK_EQ(static_cast(0x112233aa), t.swl_3); CHECK_EQ(static_cast(0xdd223344), t.swr_0); CHECK_EQ(static_cast(0xccdd3344), t.swr_1); CHECK_EQ(static_cast(0xbbccdd44), t.swr_2); CHECK_EQ(static_cast(0xaabbccdd), t.swr_3); } } } TEST(MIPS12) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { int32_t x; int32_t y; int32_t y1; int32_t y2; int32_t y3; int32_t y4; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ mov(t2, fp); // Save frame pointer. __ mov(fp, a0); // Access struct T by fp. __ lw(a4, MemOperand(a0, offsetof(T, y))); __ lw(a7, MemOperand(a0, offsetof(T, y4))); __ addu(a5, a4, a7); __ subu(t0, a4, a7); __ nop(); __ push(a4); // These instructions disappear after opt. __ Pop(); __ addu(a4, a4, a4); __ nop(); __ Pop(); // These instructions disappear after opt. __ push(a7); __ nop(); __ push(a7); // These instructions disappear after opt. __ pop(a7); __ nop(); __ push(a7); __ pop(t0); __ nop(); __ sw(a4, MemOperand(fp, offsetof(T, y))); __ lw(a4, MemOperand(fp, offsetof(T, y))); __ nop(); __ sw(a4, MemOperand(fp, offsetof(T, y))); __ lw(a5, MemOperand(fp, offsetof(T, y))); __ nop(); __ push(a5); __ lw(a5, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a6); __ nop(); __ push(a6); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a7); __ nop(); __ mov(fp, t2); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.x = 1; t.y = 2; t.y1 = 3; t.y2 = 4; t.y3 = 0XBABA; t.y4 = 0xDEDA; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(3, t.y1); } TEST(MIPS13) { // Test Cvt_d_uw and Trunc_uw_d macros. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double cvt_big_out; double cvt_small_out; uint32_t trunc_big_out; uint32_t trunc_small_out; uint32_t cvt_big_in; uint32_t cvt_small_in; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ sw(a4, MemOperand(a0, offsetof(T, cvt_small_in))); __ Cvt_d_uw(f10, a4); __ sdc1(f10, MemOperand(a0, offsetof(T, cvt_small_out))); __ Trunc_uw_d(f10, f10, f4); __ swc1(f10, MemOperand(a0, offsetof(T, trunc_small_out))); __ sw(a4, MemOperand(a0, offsetof(T, cvt_big_in))); __ Cvt_d_uw(f8, a4); __ sdc1(f8, MemOperand(a0, offsetof(T, cvt_big_out))); __ Trunc_uw_d(f8, f8, f4); __ swc1(f8, MemOperand(a0, offsetof(T, trunc_big_out))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.cvt_big_in = 0xFFFFFFFF; t.cvt_small_in = 333; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(t.cvt_big_out, static_cast(t.cvt_big_in)); CHECK_EQ(t.cvt_small_out, static_cast(t.cvt_small_in)); CHECK_EQ(static_cast(t.trunc_big_out), static_cast(t.cvt_big_in)); CHECK_EQ(static_cast(t.trunc_small_out), static_cast(t.cvt_small_in)); } TEST(MIPS14) { // Test round, floor, ceil, trunc, cvt. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); #define ROUND_STRUCT_ELEMENT(x) \ uint32_t x##_isNaN2008; \ int32_t x##_up_out; \ int32_t x##_down_out; \ int32_t neg_##x##_up_out; \ int32_t neg_##x##_down_out; \ uint32_t x##_err1_out; \ uint32_t x##_err2_out; \ uint32_t x##_err3_out; \ uint32_t x##_err4_out; \ int32_t x##_invalid_result; typedef struct { double round_up_in; double round_down_in; double neg_round_up_in; double neg_round_down_in; double err1_in; double err2_in; double err3_in; double err4_in; ROUND_STRUCT_ELEMENT(round) ROUND_STRUCT_ELEMENT(floor) ROUND_STRUCT_ELEMENT(ceil) ROUND_STRUCT_ELEMENT(trunc) ROUND_STRUCT_ELEMENT(cvt) } T; T t; #undef ROUND_STRUCT_ELEMENT MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); // Save FCSR. __ cfc1(a1, FCSR); // Disable FPU exceptions. __ ctc1(zero_reg, FCSR); #define RUN_ROUND_TEST(x) \ __ cfc1(t0, FCSR);\ __ sw(t0, MemOperand(a0, offsetof(T, x##_isNaN2008))); \ __ ldc1(f0, MemOperand(a0, offsetof(T, round_up_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_up_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, round_down_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_down_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, neg_round_up_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, neg_##x##_up_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, neg_round_down_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, neg_##x##_down_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err1_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err1_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err2_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err2_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err3_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err3_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err4_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err4_out))); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_invalid_result))); RUN_ROUND_TEST(round) RUN_ROUND_TEST(floor) RUN_ROUND_TEST(ceil) RUN_ROUND_TEST(trunc) RUN_ROUND_TEST(cvt) // Restore FCSR. __ ctc1(a1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.round_up_in = 123.51; t.round_down_in = 123.49; t.neg_round_up_in = -123.5; t.neg_round_down_in = -123.49; t.err1_in = 123.51; t.err2_in = 1; t.err3_in = static_cast(1) + 0xFFFFFFFF; t.err4_in = NAN; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); #define GET_FPU_ERR(x) (static_cast(x & kFCSRFlagMask)) #define CHECK_NAN2008(x) (x & kFCSRNaN2008FlagMask) #define CHECK_ROUND_RESULT(type) \ CHECK(GET_FPU_ERR(t.type##_err1_out) & kFCSRInexactFlagMask); \ CHECK_EQ(0, GET_FPU_ERR(t.type##_err2_out)); \ CHECK(GET_FPU_ERR(t.type##_err3_out) & kFCSRInvalidOpFlagMask); \ CHECK(GET_FPU_ERR(t.type##_err4_out) & kFCSRInvalidOpFlagMask); \ if (CHECK_NAN2008(t.type##_isNaN2008) && kArchVariant == kMips64r6) { \ CHECK_EQ(static_cast(0), t.type##_invalid_result);\ } else { \ CHECK_EQ(static_cast(kFPUInvalidResult), t.type##_invalid_result);\ } CHECK_ROUND_RESULT(round); CHECK_ROUND_RESULT(floor); CHECK_ROUND_RESULT(ceil); CHECK_ROUND_RESULT(cvt); } TEST(MIPS15) { // Test chaining of label usages within instructions (issue 1644). CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); Assembler assm(isolate, NULL, 0); Label target; __ beq(v0, v1, &target); __ nop(); __ bne(v0, v1, &target); __ nop(); __ bind(&target); __ nop(); } // ----- mips64 tests ----------------------------------------------- TEST(MIPS16) { // Test 64-bit memory loads and stores. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); struct T { int64_t r1; int64_t r2; int64_t r3; int64_t r4; int64_t r5; int64_t r6; int64_t r7; int64_t r8; int64_t r9; int64_t r10; int64_t r11; int64_t r12; uint32_t ui; int32_t si; }; T t; Assembler assm(isolate, NULL, 0); Label L, C; // Basic 32-bit word load/store, with un-signed data. __ lw(a4, MemOperand(a0, offsetof(T, ui))); __ sw(a4, MemOperand(a0, offsetof(T, r1))); // Check that the data got zero-extended into 64-bit a4. __ sd(a4, MemOperand(a0, offsetof(T, r2))); // Basic 32-bit word load/store, with SIGNED data. __ lw(a5, MemOperand(a0, offsetof(T, si))); __ sw(a5, MemOperand(a0, offsetof(T, r3))); // Check that the data got sign-extended into 64-bit a4. __ sd(a5, MemOperand(a0, offsetof(T, r4))); // 32-bit UNSIGNED word load/store, with SIGNED data. __ lwu(a6, MemOperand(a0, offsetof(T, si))); __ sw(a6, MemOperand(a0, offsetof(T, r5))); // Check that the data got zero-extended into 64-bit a4. __ sd(a6, MemOperand(a0, offsetof(T, r6))); // lh with positive data. __ lh(a5, MemOperand(a0, offsetof(T, ui))); __ sw(a5, MemOperand(a0, offsetof(T, r7))); // lh with negative data. __ lh(a6, MemOperand(a0, offsetof(T, si))); __ sw(a6, MemOperand(a0, offsetof(T, r8))); // lhu with negative data. __ lhu(a7, MemOperand(a0, offsetof(T, si))); __ sw(a7, MemOperand(a0, offsetof(T, r9))); // lb with negative data. __ lb(t0, MemOperand(a0, offsetof(T, si))); __ sw(t0, MemOperand(a0, offsetof(T, r10))); // sh writes only 1/2 of word. __ lw(a4, MemOperand(a0, offsetof(T, ui))); __ sh(a4, MemOperand(a0, offsetof(T, r11))); __ lw(a4, MemOperand(a0, offsetof(T, si))); __ sh(a4, MemOperand(a0, offsetof(T, r12))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.ui = 0x44332211; t.si = 0x99aabbcc; t.r1 = 0x5555555555555555; t.r2 = 0x5555555555555555; t.r3 = 0x5555555555555555; t.r4 = 0x5555555555555555; t.r5 = 0x5555555555555555; t.r6 = 0x5555555555555555; t.r7 = 0x5555555555555555; t.r8 = 0x5555555555555555; t.r9 = 0x5555555555555555; t.r10 = 0x5555555555555555; t.r11 = 0x5555555555555555; t.r12 = 0x5555555555555555; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); if (kArchEndian == kLittle) { // Unsigned data, 32 & 64 CHECK_EQ(static_cast(0x5555555544332211L), t.r1); // lw, sw. CHECK_EQ(static_cast(0x0000000044332211L), t.r2); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x5555555599aabbccL), t.r3); // lw, sw. CHECK_EQ(static_cast(0xffffffff99aabbccL), t.r4); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x5555555599aabbccL), t.r5); // lwu, sw. CHECK_EQ(static_cast(0x0000000099aabbccL), t.r6); // sd. // lh with unsigned and signed data. CHECK_EQ(static_cast(0x5555555500002211L), t.r7); // lh, sw. CHECK_EQ(static_cast(0x55555555ffffbbccL), t.r8); // lh, sw. // lhu with signed data. CHECK_EQ(static_cast(0x555555550000bbccL), t.r9); // lhu, sw. // lb with signed data. CHECK_EQ(static_cast(0x55555555ffffffccL), t.r10); // lb, sw. // sh with unsigned and signed data. CHECK_EQ(static_cast(0x5555555555552211L), t.r11); // lw, sh. CHECK_EQ(static_cast(0x555555555555bbccL), t.r12); // lw, sh. } else { // Unsigned data, 32 & 64 CHECK_EQ(static_cast(0x4433221155555555L), t.r1); // lw, sw. CHECK_EQ(static_cast(0x0000000044332211L), t.r2); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x99aabbcc55555555L), t.r3); // lw, sw. CHECK_EQ(static_cast(0xffffffff99aabbccL), t.r4); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x99aabbcc55555555L), t.r5); // lwu, sw. CHECK_EQ(static_cast(0x0000000099aabbccL), t.r6); // sd. // lh with unsigned and signed data. CHECK_EQ(static_cast(0x0000443355555555L), t.r7); // lh, sw. CHECK_EQ(static_cast(0xffff99aa55555555L), t.r8); // lh, sw. // lhu with signed data. CHECK_EQ(static_cast(0x000099aa55555555L), t.r9); // lhu, sw. // lb with signed data. CHECK_EQ(static_cast(0xffffff9955555555L), t.r10); // lb, sw. // sh with unsigned and signed data. CHECK_EQ(static_cast(0x2211555555555555L), t.r11); // lw, sh. CHECK_EQ(static_cast(0xbbcc555555555555L), t.r12); // lw, sh. } } // ----------------------mips64r6 specific tests---------------------- TEST(seleqz_selnez) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { int a; int b; int c; int d; double e; double f; double g; double h; float i; float j; float k; float l; } Test; Test test; // Integer part of test. __ addiu(t1, zero_reg, 1); // t1 = 1 __ seleqz(t3, t1, zero_reg); // t3 = 1 __ sw(t3, MemOperand(a0, offsetof(Test, a))); // a = 1 __ seleqz(t2, t1, t1); // t2 = 0 __ sw(t2, MemOperand(a0, offsetof(Test, b))); // b = 0 __ selnez(t3, t1, zero_reg); // t3 = 1; __ sw(t3, MemOperand(a0, offsetof(Test, c))); // c = 0 __ selnez(t3, t1, t1); // t3 = 1 __ sw(t3, MemOperand(a0, offsetof(Test, d))); // d = 1 // Floating point part of test. __ ldc1(f0, MemOperand(a0, offsetof(Test, e)) ); // src __ ldc1(f2, MemOperand(a0, offsetof(Test, f)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, i)) ); // src __ lwc1(f10, MemOperand(a0, offsetof(Test, j)) ); // test __ seleqz_d(f4, f0, f2); __ selnez_d(f6, f0, f2); __ seleqz_s(f12, f8, f10); __ selnez_s(f14, f8, f10); __ sdc1(f4, MemOperand(a0, offsetof(Test, g)) ); // src __ sdc1(f6, MemOperand(a0, offsetof(Test, h)) ); // src __ swc1(f12, MemOperand(a0, offsetof(Test, k)) ); // src __ swc1(f14, MemOperand(a0, offsetof(Test, l)) ); // src __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.a, 1); CHECK_EQ(test.b, 0); CHECK_EQ(test.c, 0); CHECK_EQ(test.d, 1); const int test_size = 3; const int input_size = 5; double inputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double outputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float inputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float outputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.e = inputs_D[i]; test.f = tests_D[j]; test.i = inputs_S[i]; test.j = tests_S[j]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, outputs_D[i]); CHECK_EQ(test.h, 0); CHECK_EQ(test.k, outputs_S[i]); CHECK_EQ(test.l, 0); test.f = tests_D[j+1]; test.j = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, 0); CHECK_EQ(test.h, outputs_D[i]); CHECK_EQ(test.k, 0); CHECK_EQ(test.l, outputs_S[i]); } } } } TEST(min_max) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); struct TestFloat { double a; double b; double c; double d; float e; float f; float g; float h; }; TestFloat test; const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); const int kTableLength = 13; double inputsa[kTableLength] = {2.0, 3.0, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = {3.0, 2.0, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double outputsdmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double outputsdmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputse[kTableLength] = {2.0, 3.0, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsf[kTableLength] = {3.0, 2.0, 3.0, fnan, 0.0, -0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float outputsfmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float outputsfmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a))); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, b))); __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, e))); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, f))); __ min_d(f10, f4, f8); __ max_d(f12, f4, f8); __ min_s(f14, f2, f6); __ max_s(f16, f2, f6); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, c))); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, d))); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, g))); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, h))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 4; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.e = inputse[i]; test.f = inputsf[i]; CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0); CHECK_EQ(0, memcmp(&test.c, &outputsdmin[i], sizeof(test.c))); CHECK_EQ(0, memcmp(&test.d, &outputsdmax[i], sizeof(test.d))); CHECK_EQ(0, memcmp(&test.g, &outputsfmin[i], sizeof(test.g))); CHECK_EQ(0, memcmp(&test.h, &outputsfmax[i], sizeof(test.h))); } } } TEST(rint_d) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; int fcsr; }TestFloat; TestFloat test; double inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E+308, 6.27463370218383111104242366943E-307, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ ctc1(t0, FCSR); __ rint_d(f8, f4); __ sdc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(sel) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { double dd; double ds; double dt; float fd; float fs; float ft; } Test; Test test; __ ldc1(f0, MemOperand(a0, offsetof(Test, dd)) ); // test __ ldc1(f2, MemOperand(a0, offsetof(Test, ds)) ); // src1 __ ldc1(f4, MemOperand(a0, offsetof(Test, dt)) ); // src2 __ lwc1(f6, MemOperand(a0, offsetof(Test, fd)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, fs)) ); // src1 __ lwc1(f10, MemOperand(a0, offsetof(Test, ft)) ); // src2 __ sel_d(f0, f2, f4); __ sel_s(f6, f8, f10); __ sdc1(f0, MemOperand(a0, offsetof(Test, dd)) ); __ swc1(f6, MemOperand(a0, offsetof(Test, fd)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); const int test_size = 3; const int input_size = 5; double inputs_dt[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double inputs_ds[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; float inputs_ft[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float inputs_fs[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.dt = inputs_dt[i]; test.dd = tests_D[j]; test.ds = inputs_ds[i]; test.ft = inputs_ft[i]; test.fd = tests_S[j]; test.fs = inputs_fs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_ds[i]); CHECK_EQ(test.fd, inputs_fs[i]); test.dd = tests_D[j+1]; test.fd = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_dt[i]); CHECK_EQ(test.fd, inputs_ft[i]); } } } } TEST(rint_s) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; int fcsr; }TestFloat; TestFloat test; float inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E+38, 6.27463370218383111104242366943E-37, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; float* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ rint_s(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(mina_maxa) { if (kArchVariant == kMips64r6) { const int kTableLength = 23; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); struct TestFloat { double a; double b; double resd; double resd1; float c; float d; float resf; float resf1; }; TestFloat test; double inputsa[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = { 4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double resd[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double resd1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputsc[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsd[kTableLength] = {4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, fnan, -0.0, 0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float resf[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float resf1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ lwc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ lwc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ mina_d(f6, f2, f4); __ mina_s(f12, f8, f10); __ maxa_d(f14, f2, f4); __ maxa_s(f16, f8, f10); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, resf)) ); __ sdc1(f6, MemOperand(a0, offsetof(TestFloat, resd)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resf1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resd1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.c = inputsc[i]; test.d = inputsd[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if (i < kTableLength - 1) { CHECK_EQ(test.resd, resd[i]); CHECK_EQ(test.resf, resf[i]); CHECK_EQ(test.resd1, resd1[i]); CHECK_EQ(test.resf1, resf1[i]); } else { CHECK(std::isnan(test.resd)); CHECK(std::isnan(test.resf)); CHECK(std::isnan(test.resd1)); CHECK(std::isnan(test.resf1)); } } } } // ----------------------mips64r2 specific tests---------------------- TEST(trunc_l) { if (kArchVariant == kMips64r2) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; // a trunc result int64_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_l_d(f8, f4); __ trunc_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } } TEST(movz_movn) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { int64_t rt; double a; double b; double bold; double b1; double bold1; float c; float d; float dold; float d1; float dold1; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ld(t0, MemOperand(a0, offsetof(TestFloat, rt))); __ Move(f12, 0.0); __ Move(f10, 0.0); __ Move(f16, 0.0); __ Move(f14, 0.0); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, bold)) ); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, dold)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, bold1)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, dold1)) ); __ movz_s(f10, f6, t0); __ movz_d(f12, f2, t0); __ movn_s(f14, f6, t0); __ movn_d(f16, f2, t0); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, b)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, d1)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, b1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; test.rt = 1; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, test.bold); CHECK_EQ(test.d, test.dold); CHECK_EQ(test.b1, outputs_D[i]); CHECK_EQ(test.d1, outputs_S[i]); test.rt = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); CHECK_EQ(test.b1, test.bold1); CHECK_EQ(test.d1, test.dold1); } } } TEST(movt_movd) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); typedef struct test_float { double srcd; double dstd; double dstdold; double dstd1; double dstdold1; float srcf; float dstf; float dstfold; float dstf1; float dstfold1; int32_t cc; int32_t fcsr; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; double inputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; int condition_flags[8] = {0, 1, 2, 3, 4, 5, 6, 7}; for (int i = 0; i < kTableLength; i++) { test.srcd = inputs_D[i]; test.srcf = inputs_S[i]; for (int j = 0; j< 8; j++) { test.cc = condition_flags[j]; if (test.cc == 0) { test.fcsr = 1 << 23; } else { test.fcsr = 1 << (24+condition_flags[j]); } HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, srcd)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, srcf)) ); __ lw(t1, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t0, FCSR); __ ctc1(t1, FCSR); __ li(t2, 0x0); __ mtc1(t2, f12); __ mtc1(t2, f10); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold)) ); __ movt_s(f12, f4, test.cc); __ movt_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold1)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold1)) ); __ movf_s(f12, f4, test.cc); __ movf_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf1)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd1)) ); __ ctc1(t0, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, outputs_S[i]); CHECK_EQ(test.dstd, outputs_D[i]); CHECK_EQ(test.dstf1, test.dstfold1); CHECK_EQ(test.dstd1, test.dstdold1); test.fcsr = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, test.dstfold); CHECK_EQ(test.dstd, test.dstdold); CHECK_EQ(test.dstf1, outputs_S[i]); CHECK_EQ(test.dstd1, outputs_D[i]); } } } } // ----------------------tests for all archs-------------------------- TEST(cvt_w_d) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; int32_t b; int fcsr; }Test; const int kTableLength = 24; double inputs[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, 2147483653.0 }; double outputs_RN[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RZ[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RP[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RM[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lw(t0, MemOperand(a0, offsetof(Test, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ cvt_w_d(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(Test, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } TEST(trunc_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_w_d(f8, f4); __ trunc_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_w_d(f8, f4); __ round_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_l_d(f8, f4); __ round_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(sub) { const int kTableLength = 12; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; double inputft_D[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; double outputs_D[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; float inputfs_S[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; float inputft_S[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; float outputs_S[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sub_s(f6, f2, f4); __ sub_d(f12, f8, f10); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(sqrt_rsqrt_recip) { const int kTableLength = 4; const double deltaDouble = 2E-15; const float deltaFloat = 2E-7; const float sqrt2_s = sqrt(2); const double sqrt2_d = sqrt(2); CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; float resultS1; float resultS2; double c; double resultD; double resultD1; double resultD2; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 0.0L, 4.0L, 2.0L, 4e-28L }; double outputs_D[kTableLength] = { 0.0L, 2.0L, sqrt2_d, 2e-14L }; float inputs_S[kTableLength] = { 0.0, 4.0, 2.0, 4e-28 }; float outputs_S[kTableLength] = { 0.0, 2.0, sqrt2_s, 2e-14 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ sqrt_s(f6, f2); __ sqrt_d(f12, f8); __ rsqrt_d(f14, f8); __ rsqrt_s(f16, f2); __ recip_d(f18, f8); __ recip_s(f4, f2); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resultS1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resultD1)) ); __ swc1(f4, MemOperand(a0, offsetof(TestFloat, resultS2)) ); __ sdc1(f18, MemOperand(a0, offsetof(TestFloat, resultD2)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { float f1; double d1; test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); if (i != 0) { f1 = test.resultS1 - 1.0F/outputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD1 - 1.0L/outputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); f1 = test.resultS2 - 1.0F/inputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD2 - 1.0L/inputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); } else { CHECK_EQ(test.resultS1, 1.0F/outputs_S[i]); CHECK_EQ(test.resultD1, 1.0L/outputs_D[i]); CHECK_EQ(test.resultS2, 1.0F/inputs_S[i]); CHECK_EQ(test.resultD2, 1.0L/inputs_D[i]); } } } TEST(neg) { const int kTableLength = 2; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; double c; double resultD; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 4.0, -2.0 }; double outputs_D[kTableLength] = { -4.0, 2.0 }; float inputs_S[kTableLength] = { 4.0, -2.0 }; float outputs_S[kTableLength] = { -4.0, 2.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ neg_s(f6, f2); __ neg_d(f12, f8); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); // Double test values. t.a = 1.5e14; t.b = 2.75e11; t.c = 0.0; t.d = 0.0; t.e = 0.0; t.f = 0.0; t.h = 1.5; t.i = 2.75; // Single test values. t.fa = 1.5e6; t.fb = 2.75e4; t.fc = 0.0; t.fd = 0.0; t.fe = 0.0; t.ff = 0.0; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); // Expected double results. CHECK_EQ(1.5e14, t.a); CHECK_EQ(1.5e14, t.b); CHECK_EQ(1.50275e14, t.c); CHECK_EQ(1.50550e14, t.d); CHECK_EQ(1.8066e16, t.e); CHECK_EQ(120.44, t.f); CHECK_EQ(10.97451593465515908537, t.g); if (kArchVariant == kMips64r2) { CHECK_EQ(6.875, t.h); } // Expected single results. CHECK_EQ(1.5e6, t.fa); CHECK_EQ(1.5e6, t.fb); CHECK_EQ(1.5275e06, t.fc); CHECK_EQ(1.5550e06, t.fd); CHECK_EQ(1.866e08, t.fe); CHECK_EQ(124.40000152587890625, t.ff); CHECK_EQ(11.1534748077392578125, t.fg); } TEST(MIPS4) { // Test moves between floating point and integer registers. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double a; double b; double c; double d; int64_t high; int64_t low; } T; T t; Assembler assm(isolate, NULL, 0); Label L, C; __ ldc1(f4, MemOperand(a0, offsetof(T, a))); __ ldc1(f5, MemOperand(a0, offsetof(T, b))); // Swap f4 and f5, by using 3 integer registers, a4-a6, // both two 32-bit chunks, and one 64-bit chunk. // mXhc1 is mips32/64-r2 only, not r1, // but we will not support r1 in practice. __ mfc1(a4, f4); __ mfhc1(a5, f4); __ dmfc1(a6, f5); __ mtc1(a4, f5); __ mthc1(a5, f5); __ dmtc1(a6, f4); // Store the swapped f4 and f5 back to memory. __ sdc1(f4, MemOperand(a0, offsetof(T, a))); __ sdc1(f5, MemOperand(a0, offsetof(T, c))); // Test sign extension of move operations from coprocessor. __ ldc1(f4, MemOperand(a0, offsetof(T, d))); __ mfhc1(a4, f4); __ mfc1(a5, f4); __ sd(a4, MemOperand(a0, offsetof(T, high))); __ sd(a5, MemOperand(a0, offsetof(T, low))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.a = 1.5e22; t.b = 2.75e11; t.c = 17.17; t.d = -2.75e11; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(2.75e11, t.a); CHECK_EQ(2.75e11, t.b); CHECK_EQ(1.5e22, t.c); CHECK_EQ(static_cast(0xffffffffc25001d1L), t.high); CHECK_EQ(static_cast(0xffffffffbf800000L), t.low); } TEST(MIPS5) { // Test conversions between doubles and integers. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double a; double b; int i; int j; } T; T t; Assembler assm(isolate, NULL, 0); Label L, C; // Load all structure elements to registers. __ ldc1(f4, MemOperand(a0, offsetof(T, a)) ); __ ldc1(f6, MemOperand(a0, offsetof(T, b)) ); __ lw(a4, MemOperand(a0, offsetof(T, i)) ); __ lw(a5, MemOperand(a0, offsetof(T, j)) ); // Convert double in f4 to int in element i. __ cvt_w_d(f8, f4); __ mfc1(a6, f8); __ sw(a6, MemOperand(a0, offsetof(T, i)) ); // Convert double in f6 to int in element j. __ cvt_w_d(f10, f6); __ mfc1(a7, f10); __ sw(a7, MemOperand(a0, offsetof(T, j)) ); // Convert int in original i (a4) to double in a. __ mtc1(a4, f12); __ cvt_d_w(f0, f12); __ sdc1(f0, MemOperand(a0, offsetof(T, a)) ); // Convert int in original j (a5) to double in b. __ mtc1(a5, f14); __ cvt_d_w(f2, f14); __ sdc1(f2, MemOperand(a0, offsetof(T, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.a = 1.5e4; t.b = 2.75e8; t.i = 12345678; t.j = -100000; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(12345678.0, t.a); CHECK_EQ(-100000.0, t.b); CHECK_EQ(15000, t.i); CHECK_EQ(275000000, t.j); } TEST(MIPS6) { // Test simple memory loads and stores. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { uint32_t ui; int32_t si; int32_t r1; int32_t r2; int32_t r3; int32_t r4; int32_t r5; int32_t r6; } T; T t; Assembler assm(isolate, NULL, 0); Label L, C; // Basic word load/store. __ lw(a4, MemOperand(a0, offsetof(T, ui)) ); __ sw(a4, MemOperand(a0, offsetof(T, r1)) ); // lh with positive data. __ lh(a5, MemOperand(a0, offsetof(T, ui)) ); __ sw(a5, MemOperand(a0, offsetof(T, r2)) ); // lh with negative data. __ lh(a6, MemOperand(a0, offsetof(T, si)) ); __ sw(a6, MemOperand(a0, offsetof(T, r3)) ); // lhu with negative data. __ lhu(a7, MemOperand(a0, offsetof(T, si)) ); __ sw(a7, MemOperand(a0, offsetof(T, r4)) ); // lb with negative data. __ lb(t0, MemOperand(a0, offsetof(T, si)) ); __ sw(t0, MemOperand(a0, offsetof(T, r5)) ); // sh writes only 1/2 of word. __ lui(t1, 0x3333); __ ori(t1, t1, 0x3333); __ sw(t1, MemOperand(a0, offsetof(T, r6)) ); __ lhu(t1, MemOperand(a0, offsetof(T, si)) ); __ sh(t1, MemOperand(a0, offsetof(T, r6)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.ui = 0x11223344; t.si = 0x99aabbcc; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(static_cast(0x11223344), t.r1); if (kArchEndian == kLittle) { CHECK_EQ(static_cast(0x3344), t.r2); CHECK_EQ(static_cast(0xffffbbcc), t.r3); CHECK_EQ(static_cast(0x0000bbcc), t.r4); CHECK_EQ(static_cast(0xffffffcc), t.r5); CHECK_EQ(static_cast(0x3333bbcc), t.r6); } else { CHECK_EQ(static_cast(0x1122), t.r2); CHECK_EQ(static_cast(0xffff99aa), t.r3); CHECK_EQ(static_cast(0x000099aa), t.r4); CHECK_EQ(static_cast(0xffffff99), t.r5); CHECK_EQ(static_cast(0x99aa3333), t.r6); } } TEST(MIPS7) { // Test floating point compare and branch instructions. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double a; double b; double c; double d; double e; double f; int32_t result; } T; T t; // Create a function that accepts &t, and loads, manipulates, and stores // the doubles t.a ... t.f. MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); Label neither_is_nan, less_than, outa_here; __ ldc1(f4, MemOperand(a0, offsetof(T, a)) ); __ ldc1(f6, MemOperand(a0, offsetof(T, b)) ); if (kArchVariant != kMips64r6) { __ c(UN, D, f4, f6); __ bc1f(&neither_is_nan); } else { __ cmp(UN, L, f2, f4, f6); __ bc1eqz(&neither_is_nan, f2); } __ nop(); __ sw(zero_reg, MemOperand(a0, offsetof(T, result)) ); __ Branch(&outa_here); __ bind(&neither_is_nan); if (kArchVariant == kMips64r6) { __ cmp(OLT, L, f2, f6, f4); __ bc1nez(&less_than, f2); } else { __ c(OLT, D, f6, f4, 2); __ bc1t(&less_than, 2); } __ nop(); __ sw(zero_reg, MemOperand(a0, offsetof(T, result)) ); __ Branch(&outa_here); __ bind(&less_than); __ Addu(a4, zero_reg, Operand(1)); __ sw(a4, MemOperand(a0, offsetof(T, result)) ); // Set true. // This test-case should have additional tests. __ bind(&outa_here); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.a = 1.5e14; t.b = 2.75e11; t.c = 2.0; t.d = -4.0; t.e = 0.0; t.f = 0.0; t.result = 0; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(1.5e14, t.a); CHECK_EQ(2.75e11, t.b); CHECK_EQ(1, t.result); } TEST(MIPS8) { if (kArchVariant == kMips64r2) { // Test ROTR and ROTRV instructions. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { int32_t input; int32_t result_rotr_4; int32_t result_rotr_8; int32_t result_rotr_12; int32_t result_rotr_16; int32_t result_rotr_20; int32_t result_rotr_24; int32_t result_rotr_28; int32_t result_rotrv_4; int32_t result_rotrv_8; int32_t result_rotrv_12; int32_t result_rotrv_16; int32_t result_rotrv_20; int32_t result_rotrv_24; int32_t result_rotrv_28; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); // Basic word load. __ lw(a4, MemOperand(a0, offsetof(T, input)) ); // ROTR instruction (called through the Ror macro). __ Ror(a5, a4, 0x0004); __ Ror(a6, a4, 0x0008); __ Ror(a7, a4, 0x000c); __ Ror(t0, a4, 0x0010); __ Ror(t1, a4, 0x0014); __ Ror(t2, a4, 0x0018); __ Ror(t3, a4, 0x001c); // Basic word store. __ sw(a5, MemOperand(a0, offsetof(T, result_rotr_4)) ); __ sw(a6, MemOperand(a0, offsetof(T, result_rotr_8)) ); __ sw(a7, MemOperand(a0, offsetof(T, result_rotr_12)) ); __ sw(t0, MemOperand(a0, offsetof(T, result_rotr_16)) ); __ sw(t1, MemOperand(a0, offsetof(T, result_rotr_20)) ); __ sw(t2, MemOperand(a0, offsetof(T, result_rotr_24)) ); __ sw(t3, MemOperand(a0, offsetof(T, result_rotr_28)) ); // ROTRV instruction (called through the Ror macro). __ li(t3, 0x0004); __ Ror(a5, a4, t3); __ li(t3, 0x0008); __ Ror(a6, a4, t3); __ li(t3, 0x000C); __ Ror(a7, a4, t3); __ li(t3, 0x0010); __ Ror(t0, a4, t3); __ li(t3, 0x0014); __ Ror(t1, a4, t3); __ li(t3, 0x0018); __ Ror(t2, a4, t3); __ li(t3, 0x001C); __ Ror(t3, a4, t3); // Basic word store. __ sw(a5, MemOperand(a0, offsetof(T, result_rotrv_4)) ); __ sw(a6, MemOperand(a0, offsetof(T, result_rotrv_8)) ); __ sw(a7, MemOperand(a0, offsetof(T, result_rotrv_12)) ); __ sw(t0, MemOperand(a0, offsetof(T, result_rotrv_16)) ); __ sw(t1, MemOperand(a0, offsetof(T, result_rotrv_20)) ); __ sw(t2, MemOperand(a0, offsetof(T, result_rotrv_24)) ); __ sw(t3, MemOperand(a0, offsetof(T, result_rotrv_28)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.input = 0x12345678; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0x0, 0, 0, 0); USE(dummy); CHECK_EQ(static_cast(0x81234567), t.result_rotr_4); CHECK_EQ(static_cast(0x78123456), t.result_rotr_8); CHECK_EQ(static_cast(0x67812345), t.result_rotr_12); CHECK_EQ(static_cast(0x56781234), t.result_rotr_16); CHECK_EQ(static_cast(0x45678123), t.result_rotr_20); CHECK_EQ(static_cast(0x34567812), t.result_rotr_24); CHECK_EQ(static_cast(0x23456781), t.result_rotr_28); CHECK_EQ(static_cast(0x81234567), t.result_rotrv_4); CHECK_EQ(static_cast(0x78123456), t.result_rotrv_8); CHECK_EQ(static_cast(0x67812345), t.result_rotrv_12); CHECK_EQ(static_cast(0x56781234), t.result_rotrv_16); CHECK_EQ(static_cast(0x45678123), t.result_rotrv_20); CHECK_EQ(static_cast(0x34567812), t.result_rotrv_24); CHECK_EQ(static_cast(0x23456781), t.result_rotrv_28); } } TEST(MIPS9) { // Test BRANCH improvements. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); Label exit, exit2, exit3; __ Branch(&exit, ge, a0, Operand(zero_reg)); __ Branch(&exit2, ge, a0, Operand(0x00001FFF)); __ Branch(&exit3, ge, a0, Operand(0x0001FFFF)); __ bind(&exit); __ bind(&exit2); __ bind(&exit3); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); } TEST(MIPS10) { // Test conversions between doubles and long integers. // Test hos the long ints map to FP regs pairs. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double a; double a_converted; double b; int32_t dbl_mant; int32_t dbl_exp; int32_t long_hi; int32_t long_lo; int64_t long_as_int64; int32_t b_long_hi; int32_t b_long_lo; int64_t b_long_as_int64; } T; T t; Assembler assm(isolate, NULL, 0); Label L, C; if (kArchVariant == kMips64r2) { // Rewritten for FR=1 FPU mode: // - 32 FP regs of 64-bits each, no odd/even pairs. // - Note that cvt_l_d/cvt_d_l ARE legal in FR=1 mode. // Load all structure elements to registers. __ ldc1(f0, MemOperand(a0, offsetof(T, a))); // Save the raw bits of the double. __ mfc1(a4, f0); __ mfhc1(a5, f0); __ sw(a4, MemOperand(a0, offsetof(T, dbl_mant))); __ sw(a5, MemOperand(a0, offsetof(T, dbl_exp))); // Convert double in f0 to long, save hi/lo parts. __ cvt_l_d(f0, f0); __ mfc1(a4, f0); // f0 LS 32 bits of long. __ mfhc1(a5, f0); // f0 MS 32 bits of long. __ sw(a4, MemOperand(a0, offsetof(T, long_lo))); __ sw(a5, MemOperand(a0, offsetof(T, long_hi))); // Combine the high/low ints, convert back to double. __ dsll32(a6, a5, 0); // Move a5 to high bits of a6. __ or_(a6, a6, a4); __ dmtc1(a6, f1); __ cvt_d_l(f1, f1); __ sdc1(f1, MemOperand(a0, offsetof(T, a_converted))); // Convert the b long integers to double b. __ lw(a4, MemOperand(a0, offsetof(T, b_long_lo))); __ lw(a5, MemOperand(a0, offsetof(T, b_long_hi))); __ mtc1(a4, f8); // f8 LS 32-bits. __ mthc1(a5, f8); // f8 MS 32-bits. __ cvt_d_l(f10, f8); __ sdc1(f10, MemOperand(a0, offsetof(T, b))); // Convert double b back to long-int. __ ldc1(f31, MemOperand(a0, offsetof(T, b))); __ cvt_l_d(f31, f31); __ dmfc1(a7, f31); __ sd(a7, MemOperand(a0, offsetof(T, b_long_as_int64))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.a = 2.147483647e9; // 0x7fffffff -> 0x41DFFFFFFFC00000 as double. t.b_long_hi = 0x000000ff; // 0xFF00FF00FF -> 0x426FE01FE01FE000 as double. t.b_long_lo = 0x00ff00ff; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(static_cast(0x41DFFFFF), t.dbl_exp); CHECK_EQ(static_cast(0xFFC00000), t.dbl_mant); CHECK_EQ(0, t.long_hi); CHECK_EQ(static_cast(0x7fffffff), t.long_lo); CHECK_EQ(2.147483647e9, t.a_converted); // 0xFF00FF00FF -> 1.095233372415e12. CHECK_EQ(1.095233372415e12, t.b); CHECK_EQ(static_cast(0xFF00FF00FF), t.b_long_as_int64); } } TEST(MIPS11) { // Do not run test on MIPS64r6, as these instructions are removed. if (kArchVariant != kMips64r6) { // Test LWL, LWR, SWL and SWR instructions. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { int32_t reg_init; int32_t mem_init; int32_t lwl_0; int32_t lwl_1; int32_t lwl_2; int32_t lwl_3; int32_t lwr_0; int32_t lwr_1; int32_t lwr_2; int32_t lwr_3; int32_t swl_0; int32_t swl_1; int32_t swl_2; int32_t swl_3; int32_t swr_0; int32_t swr_1; int32_t swr_2; int32_t swr_3; } T; T t; Assembler assm(isolate, NULL, 0); // Test all combinations of LWL and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, lwl_0))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a5, MemOperand(a0, offsetof(T, mem_init) + 1)); __ sw(a5, MemOperand(a0, offsetof(T, lwl_1))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a6, MemOperand(a0, offsetof(T, mem_init) + 2)); __ sw(a6, MemOperand(a0, offsetof(T, lwl_2))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a7, MemOperand(a0, offsetof(T, mem_init) + 3)); __ sw(a7, MemOperand(a0, offsetof(T, lwl_3))); // Test all combinations of LWR and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, lwr_0))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a5, MemOperand(a0, offsetof(T, mem_init) + 1)); __ sw(a5, MemOperand(a0, offsetof(T, lwr_1))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a6, MemOperand(a0, offsetof(T, mem_init) + 2)); __ sw(a6, MemOperand(a0, offsetof(T, lwr_2)) ); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a7, MemOperand(a0, offsetof(T, mem_init) + 3)); __ sw(a7, MemOperand(a0, offsetof(T, lwr_3)) ); // Test all combinations of SWL and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, swl_0))); __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ swl(a4, MemOperand(a0, offsetof(T, swl_0))); __ lw(a5, MemOperand(a0, offsetof(T, mem_init))); __ sw(a5, MemOperand(a0, offsetof(T, swl_1))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ swl(a5, MemOperand(a0, offsetof(T, swl_1) + 1)); __ lw(a6, MemOperand(a0, offsetof(T, mem_init))); __ sw(a6, MemOperand(a0, offsetof(T, swl_2))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ swl(a6, MemOperand(a0, offsetof(T, swl_2) + 2)); __ lw(a7, MemOperand(a0, offsetof(T, mem_init))); __ sw(a7, MemOperand(a0, offsetof(T, swl_3))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ swl(a7, MemOperand(a0, offsetof(T, swl_3) + 3)); // Test all combinations of SWR and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, swr_0))); __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ swr(a4, MemOperand(a0, offsetof(T, swr_0))); __ lw(a5, MemOperand(a0, offsetof(T, mem_init))); __ sw(a5, MemOperand(a0, offsetof(T, swr_1))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ swr(a5, MemOperand(a0, offsetof(T, swr_1) + 1)); __ lw(a6, MemOperand(a0, offsetof(T, mem_init))); __ sw(a6, MemOperand(a0, offsetof(T, swr_2))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ swr(a6, MemOperand(a0, offsetof(T, swr_2) + 2)); __ lw(a7, MemOperand(a0, offsetof(T, mem_init))); __ sw(a7, MemOperand(a0, offsetof(T, swr_3))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ swr(a7, MemOperand(a0, offsetof(T, swr_3) + 3)); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.reg_init = 0xaabbccdd; t.mem_init = 0x11223344; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); if (kArchEndian == kLittle) { CHECK_EQ(static_cast(0x44bbccdd), t.lwl_0); CHECK_EQ(static_cast(0x3344ccdd), t.lwl_1); CHECK_EQ(static_cast(0x223344dd), t.lwl_2); CHECK_EQ(static_cast(0x11223344), t.lwl_3); CHECK_EQ(static_cast(0x11223344), t.lwr_0); CHECK_EQ(static_cast(0xaa112233), t.lwr_1); CHECK_EQ(static_cast(0xaabb1122), t.lwr_2); CHECK_EQ(static_cast(0xaabbcc11), t.lwr_3); CHECK_EQ(static_cast(0x112233aa), t.swl_0); CHECK_EQ(static_cast(0x1122aabb), t.swl_1); CHECK_EQ(static_cast(0x11aabbcc), t.swl_2); CHECK_EQ(static_cast(0xaabbccdd), t.swl_3); CHECK_EQ(static_cast(0xaabbccdd), t.swr_0); CHECK_EQ(static_cast(0xbbccdd44), t.swr_1); CHECK_EQ(static_cast(0xccdd3344), t.swr_2); CHECK_EQ(static_cast(0xdd223344), t.swr_3); } else { CHECK_EQ(static_cast(0x11223344), t.lwl_0); CHECK_EQ(static_cast(0x223344dd), t.lwl_1); CHECK_EQ(static_cast(0x3344ccdd), t.lwl_2); CHECK_EQ(static_cast(0x44bbccdd), t.lwl_3); CHECK_EQ(static_cast(0xaabbcc11), t.lwr_0); CHECK_EQ(static_cast(0xaabb1122), t.lwr_1); CHECK_EQ(static_cast(0xaa112233), t.lwr_2); CHECK_EQ(static_cast(0x11223344), t.lwr_3); CHECK_EQ(static_cast(0xaabbccdd), t.swl_0); CHECK_EQ(static_cast(0x11aabbcc), t.swl_1); CHECK_EQ(static_cast(0x1122aabb), t.swl_2); CHECK_EQ(static_cast(0x112233aa), t.swl_3); CHECK_EQ(static_cast(0xdd223344), t.swr_0); CHECK_EQ(static_cast(0xccdd3344), t.swr_1); CHECK_EQ(static_cast(0xbbccdd44), t.swr_2); CHECK_EQ(static_cast(0xaabbccdd), t.swr_3); } } } TEST(MIPS12) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { int32_t x; int32_t y; int32_t y1; int32_t y2; int32_t y3; int32_t y4; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ mov(t2, fp); // Save frame pointer. __ mov(fp, a0); // Access struct T by fp. __ lw(a4, MemOperand(a0, offsetof(T, y))); __ lw(a7, MemOperand(a0, offsetof(T, y4))); __ addu(a5, a4, a7); __ subu(t0, a4, a7); __ nop(); __ push(a4); // These instructions disappear after opt. __ Pop(); __ addu(a4, a4, a4); __ nop(); __ Pop(); // These instructions disappear after opt. __ push(a7); __ nop(); __ push(a7); // These instructions disappear after opt. __ pop(a7); __ nop(); __ push(a7); __ pop(t0); __ nop(); __ sw(a4, MemOperand(fp, offsetof(T, y))); __ lw(a4, MemOperand(fp, offsetof(T, y))); __ nop(); __ sw(a4, MemOperand(fp, offsetof(T, y))); __ lw(a5, MemOperand(fp, offsetof(T, y))); __ nop(); __ push(a5); __ lw(a5, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a6); __ nop(); __ push(a6); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a7); __ nop(); __ mov(fp, t2); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.x = 1; t.y = 2; t.y1 = 3; t.y2 = 4; t.y3 = 0XBABA; t.y4 = 0xDEDA; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(3, t.y1); } TEST(MIPS13) { // Test Cvt_d_uw and Trunc_uw_d macros. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double cvt_big_out; double cvt_small_out; uint32_t trunc_big_out; uint32_t trunc_small_out; uint32_t cvt_big_in; uint32_t cvt_small_in; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ sw(a4, MemOperand(a0, offsetof(T, cvt_small_in))); __ Cvt_d_uw(f10, a4); __ sdc1(f10, MemOperand(a0, offsetof(T, cvt_small_out))); __ Trunc_uw_d(f10, f10, f4); __ swc1(f10, MemOperand(a0, offsetof(T, trunc_small_out))); __ sw(a4, MemOperand(a0, offsetof(T, cvt_big_in))); __ Cvt_d_uw(f8, a4); __ sdc1(f8, MemOperand(a0, offsetof(T, cvt_big_out))); __ Trunc_uw_d(f8, f8, f4); __ swc1(f8, MemOperand(a0, offsetof(T, trunc_big_out))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.cvt_big_in = 0xFFFFFFFF; t.cvt_small_in = 333; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(t.cvt_big_out, static_cast(t.cvt_big_in)); CHECK_EQ(t.cvt_small_out, static_cast(t.cvt_small_in)); CHECK_EQ(static_cast(t.trunc_big_out), static_cast(t.cvt_big_in)); CHECK_EQ(static_cast(t.trunc_small_out), static_cast(t.cvt_small_in)); } TEST(MIPS14) { // Test round, floor, ceil, trunc, cvt. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); #define ROUND_STRUCT_ELEMENT(x) \ uint32_t x##_isNaN2008; \ int32_t x##_up_out; \ int32_t x##_down_out; \ int32_t neg_##x##_up_out; \ int32_t neg_##x##_down_out; \ uint32_t x##_err1_out; \ uint32_t x##_err2_out; \ uint32_t x##_err3_out; \ uint32_t x##_err4_out; \ int32_t x##_invalid_result; typedef struct { double round_up_in; double round_down_in; double neg_round_up_in; double neg_round_down_in; double err1_in; double err2_in; double err3_in; double err4_in; ROUND_STRUCT_ELEMENT(round) ROUND_STRUCT_ELEMENT(floor) ROUND_STRUCT_ELEMENT(ceil) ROUND_STRUCT_ELEMENT(trunc) ROUND_STRUCT_ELEMENT(cvt) } T; T t; #undef ROUND_STRUCT_ELEMENT MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); // Save FCSR. __ cfc1(a1, FCSR); // Disable FPU exceptions. __ ctc1(zero_reg, FCSR); #define RUN_ROUND_TEST(x) \ __ cfc1(t0, FCSR);\ __ sw(t0, MemOperand(a0, offsetof(T, x##_isNaN2008))); \ __ ldc1(f0, MemOperand(a0, offsetof(T, round_up_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_up_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, round_down_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_down_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, neg_round_up_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, neg_##x##_up_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, neg_round_down_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, neg_##x##_down_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err1_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err1_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err2_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err2_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err3_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err3_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err4_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err4_out))); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_invalid_result))); RUN_ROUND_TEST(round) RUN_ROUND_TEST(floor) RUN_ROUND_TEST(ceil) RUN_ROUND_TEST(trunc) RUN_ROUND_TEST(cvt) // Restore FCSR. __ ctc1(a1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.round_up_in = 123.51; t.round_down_in = 123.49; t.neg_round_up_in = -123.5; t.neg_round_down_in = -123.49; t.err1_in = 123.51; t.err2_in = 1; t.err3_in = static_cast(1) + 0xFFFFFFFF; t.err4_in = NAN; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); #define GET_FPU_ERR(x) (static_cast(x & kFCSRFlagMask)) #define CHECK_NAN2008(x) (x & kFCSRNaN2008FlagMask) #define CHECK_ROUND_RESULT(type) \ CHECK(GET_FPU_ERR(t.type##_err1_out) & kFCSRInexactFlagMask); \ CHECK_EQ(0, GET_FPU_ERR(t.type##_err2_out)); \ CHECK(GET_FPU_ERR(t.type##_err3_out) & kFCSRInvalidOpFlagMask); \ CHECK(GET_FPU_ERR(t.type##_err4_out) & kFCSRInvalidOpFlagMask); \ if (CHECK_NAN2008(t.type##_isNaN2008) && kArchVariant == kMips64r6) { \ CHECK_EQ(static_cast(0), t.type##_invalid_result);\ } else { \ CHECK_EQ(static_cast(kFPUInvalidResult), t.type##_invalid_result);\ } CHECK_ROUND_RESULT(round); CHECK_ROUND_RESULT(floor); CHECK_ROUND_RESULT(ceil); CHECK_ROUND_RESULT(cvt); } TEST(MIPS15) { // Test chaining of label usages within instructions (issue 1644). CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); Assembler assm(isolate, NULL, 0); Label target; __ beq(v0, v1, &target); __ nop(); __ bne(v0, v1, &target); __ nop(); __ bind(&target); __ nop(); } // ----- mips64 tests ----------------------------------------------- TEST(MIPS16) { // Test 64-bit memory loads and stores. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); struct T { int64_t r1; int64_t r2; int64_t r3; int64_t r4; int64_t r5; int64_t r6; int64_t r7; int64_t r8; int64_t r9; int64_t r10; int64_t r11; int64_t r12; uint32_t ui; int32_t si; }; T t; Assembler assm(isolate, NULL, 0); Label L, C; // Basic 32-bit word load/store, with un-signed data. __ lw(a4, MemOperand(a0, offsetof(T, ui))); __ sw(a4, MemOperand(a0, offsetof(T, r1))); // Check that the data got zero-extended into 64-bit a4. __ sd(a4, MemOperand(a0, offsetof(T, r2))); // Basic 32-bit word load/store, with SIGNED data. __ lw(a5, MemOperand(a0, offsetof(T, si))); __ sw(a5, MemOperand(a0, offsetof(T, r3))); // Check that the data got sign-extended into 64-bit a4. __ sd(a5, MemOperand(a0, offsetof(T, r4))); // 32-bit UNSIGNED word load/store, with SIGNED data. __ lwu(a6, MemOperand(a0, offsetof(T, si))); __ sw(a6, MemOperand(a0, offsetof(T, r5))); // Check that the data got zero-extended into 64-bit a4. __ sd(a6, MemOperand(a0, offsetof(T, r6))); // lh with positive data. __ lh(a5, MemOperand(a0, offsetof(T, ui))); __ sw(a5, MemOperand(a0, offsetof(T, r7))); // lh with negative data. __ lh(a6, MemOperand(a0, offsetof(T, si))); __ sw(a6, MemOperand(a0, offsetof(T, r8))); // lhu with negative data. __ lhu(a7, MemOperand(a0, offsetof(T, si))); __ sw(a7, MemOperand(a0, offsetof(T, r9))); // lb with negative data. __ lb(t0, MemOperand(a0, offsetof(T, si))); __ sw(t0, MemOperand(a0, offsetof(T, r10))); // sh writes only 1/2 of word. __ lw(a4, MemOperand(a0, offsetof(T, ui))); __ sh(a4, MemOperand(a0, offsetof(T, r11))); __ lw(a4, MemOperand(a0, offsetof(T, si))); __ sh(a4, MemOperand(a0, offsetof(T, r12))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.ui = 0x44332211; t.si = 0x99aabbcc; t.r1 = 0x5555555555555555; t.r2 = 0x5555555555555555; t.r3 = 0x5555555555555555; t.r4 = 0x5555555555555555; t.r5 = 0x5555555555555555; t.r6 = 0x5555555555555555; t.r7 = 0x5555555555555555; t.r8 = 0x5555555555555555; t.r9 = 0x5555555555555555; t.r10 = 0x5555555555555555; t.r11 = 0x5555555555555555; t.r12 = 0x5555555555555555; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); if (kArchEndian == kLittle) { // Unsigned data, 32 & 64 CHECK_EQ(static_cast(0x5555555544332211L), t.r1); // lw, sw. CHECK_EQ(static_cast(0x0000000044332211L), t.r2); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x5555555599aabbccL), t.r3); // lw, sw. CHECK_EQ(static_cast(0xffffffff99aabbccL), t.r4); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x5555555599aabbccL), t.r5); // lwu, sw. CHECK_EQ(static_cast(0x0000000099aabbccL), t.r6); // sd. // lh with unsigned and signed data. CHECK_EQ(static_cast(0x5555555500002211L), t.r7); // lh, sw. CHECK_EQ(static_cast(0x55555555ffffbbccL), t.r8); // lh, sw. // lhu with signed data. CHECK_EQ(static_cast(0x555555550000bbccL), t.r9); // lhu, sw. // lb with signed data. CHECK_EQ(static_cast(0x55555555ffffffccL), t.r10); // lb, sw. // sh with unsigned and signed data. CHECK_EQ(static_cast(0x5555555555552211L), t.r11); // lw, sh. CHECK_EQ(static_cast(0x555555555555bbccL), t.r12); // lw, sh. } else { // Unsigned data, 32 & 64 CHECK_EQ(static_cast(0x4433221155555555L), t.r1); // lw, sw. CHECK_EQ(static_cast(0x0000000044332211L), t.r2); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x99aabbcc55555555L), t.r3); // lw, sw. CHECK_EQ(static_cast(0xffffffff99aabbccL), t.r4); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x99aabbcc55555555L), t.r5); // lwu, sw. CHECK_EQ(static_cast(0x0000000099aabbccL), t.r6); // sd. // lh with unsigned and signed data. CHECK_EQ(static_cast(0x0000443355555555L), t.r7); // lh, sw. CHECK_EQ(static_cast(0xffff99aa55555555L), t.r8); // lh, sw. // lhu with signed data. CHECK_EQ(static_cast(0x000099aa55555555L), t.r9); // lhu, sw. // lb with signed data. CHECK_EQ(static_cast(0xffffff9955555555L), t.r10); // lb, sw. // sh with unsigned and signed data. CHECK_EQ(static_cast(0x2211555555555555L), t.r11); // lw, sh. CHECK_EQ(static_cast(0xbbcc555555555555L), t.r12); // lw, sh. } } // ----------------------mips64r6 specific tests---------------------- TEST(seleqz_selnez) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { int a; int b; int c; int d; double e; double f; double g; double h; float i; float j; float k; float l; } Test; Test test; // Integer part of test. __ addiu(t1, zero_reg, 1); // t1 = 1 __ seleqz(t3, t1, zero_reg); // t3 = 1 __ sw(t3, MemOperand(a0, offsetof(Test, a))); // a = 1 __ seleqz(t2, t1, t1); // t2 = 0 __ sw(t2, MemOperand(a0, offsetof(Test, b))); // b = 0 __ selnez(t3, t1, zero_reg); // t3 = 1; __ sw(t3, MemOperand(a0, offsetof(Test, c))); // c = 0 __ selnez(t3, t1, t1); // t3 = 1 __ sw(t3, MemOperand(a0, offsetof(Test, d))); // d = 1 // Floating point part of test. __ ldc1(f0, MemOperand(a0, offsetof(Test, e)) ); // src __ ldc1(f2, MemOperand(a0, offsetof(Test, f)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, i)) ); // src __ lwc1(f10, MemOperand(a0, offsetof(Test, j)) ); // test __ seleqz_d(f4, f0, f2); __ selnez_d(f6, f0, f2); __ seleqz_s(f12, f8, f10); __ selnez_s(f14, f8, f10); __ sdc1(f4, MemOperand(a0, offsetof(Test, g)) ); // src __ sdc1(f6, MemOperand(a0, offsetof(Test, h)) ); // src __ swc1(f12, MemOperand(a0, offsetof(Test, k)) ); // src __ swc1(f14, MemOperand(a0, offsetof(Test, l)) ); // src __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.a, 1); CHECK_EQ(test.b, 0); CHECK_EQ(test.c, 0); CHECK_EQ(test.d, 1); const int test_size = 3; const int input_size = 5; double inputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double outputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float inputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float outputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.e = inputs_D[i]; test.f = tests_D[j]; test.i = inputs_S[i]; test.j = tests_S[j]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, outputs_D[i]); CHECK_EQ(test.h, 0); CHECK_EQ(test.k, outputs_S[i]); CHECK_EQ(test.l, 0); test.f = tests_D[j+1]; test.j = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, 0); CHECK_EQ(test.h, outputs_D[i]); CHECK_EQ(test.k, 0); CHECK_EQ(test.l, outputs_S[i]); } } } } TEST(min_max) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); struct TestFloat { double a; double b; double c; double d; float e; float f; float g; float h; }; TestFloat test; const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); const int kTableLength = 13; double inputsa[kTableLength] = {2.0, 3.0, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = {3.0, 2.0, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double outputsdmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double outputsdmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputse[kTableLength] = {2.0, 3.0, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsf[kTableLength] = {3.0, 2.0, 3.0, fnan, 0.0, -0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float outputsfmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float outputsfmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a))); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, b))); __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, e))); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, f))); __ min_d(f10, f4, f8); __ max_d(f12, f4, f8); __ min_s(f14, f2, f6); __ max_s(f16, f2, f6); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, c))); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, d))); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, g))); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, h))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 4; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.e = inputse[i]; test.f = inputsf[i]; CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0); CHECK_EQ(0, memcmp(&test.c, &outputsdmin[i], sizeof(test.c))); CHECK_EQ(0, memcmp(&test.d, &outputsdmax[i], sizeof(test.d))); CHECK_EQ(0, memcmp(&test.g, &outputsfmin[i], sizeof(test.g))); CHECK_EQ(0, memcmp(&test.h, &outputsfmax[i], sizeof(test.h))); } } } TEST(rint_d) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; int fcsr; }TestFloat; TestFloat test; double inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E+308, 6.27463370218383111104242366943E-307, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ ctc1(t0, FCSR); __ rint_d(f8, f4); __ sdc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(sel) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { double dd; double ds; double dt; float fd; float fs; float ft; } Test; Test test; __ ldc1(f0, MemOperand(a0, offsetof(Test, dd)) ); // test __ ldc1(f2, MemOperand(a0, offsetof(Test, ds)) ); // src1 __ ldc1(f4, MemOperand(a0, offsetof(Test, dt)) ); // src2 __ lwc1(f6, MemOperand(a0, offsetof(Test, fd)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, fs)) ); // src1 __ lwc1(f10, MemOperand(a0, offsetof(Test, ft)) ); // src2 __ sel_d(f0, f2, f4); __ sel_s(f6, f8, f10); __ sdc1(f0, MemOperand(a0, offsetof(Test, dd)) ); __ swc1(f6, MemOperand(a0, offsetof(Test, fd)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); const int test_size = 3; const int input_size = 5; double inputs_dt[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double inputs_ds[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; float inputs_ft[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float inputs_fs[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.dt = inputs_dt[i]; test.dd = tests_D[j]; test.ds = inputs_ds[i]; test.ft = inputs_ft[i]; test.fd = tests_S[j]; test.fs = inputs_fs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_ds[i]); CHECK_EQ(test.fd, inputs_fs[i]); test.dd = tests_D[j+1]; test.fd = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_dt[i]); CHECK_EQ(test.fd, inputs_ft[i]); } } } } TEST(rint_s) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; int fcsr; }TestFloat; TestFloat test; float inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E+38, 6.27463370218383111104242366943E-37, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; float* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ rint_s(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(mina_maxa) { if (kArchVariant == kMips64r6) { const int kTableLength = 23; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); struct TestFloat { double a; double b; double resd; double resd1; float c; float d; float resf; float resf1; }; TestFloat test; double inputsa[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = { 4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double resd[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double resd1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputsc[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsd[kTableLength] = {4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, fnan, -0.0, 0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float resf[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float resf1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ lwc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ lwc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ mina_d(f6, f2, f4); __ mina_s(f12, f8, f10); __ maxa_d(f14, f2, f4); __ maxa_s(f16, f8, f10); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, resf)) ); __ sdc1(f6, MemOperand(a0, offsetof(TestFloat, resd)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resf1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resd1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.c = inputsc[i]; test.d = inputsd[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if (i < kTableLength - 1) { CHECK_EQ(test.resd, resd[i]); CHECK_EQ(test.resf, resf[i]); CHECK_EQ(test.resd1, resd1[i]); CHECK_EQ(test.resf1, resf1[i]); } else { CHECK(std::isnan(test.resd)); CHECK(std::isnan(test.resf)); CHECK(std::isnan(test.resd1)); CHECK(std::isnan(test.resf1)); } } } } // ----------------------mips64r2 specific tests---------------------- TEST(trunc_l) { if (kArchVariant == kMips64r2) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; // a trunc result int64_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_l_d(f8, f4); __ trunc_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } } TEST(movz_movn) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { int64_t rt; double a; double b; double bold; double b1; double bold1; float c; float d; float dold; float d1; float dold1; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ld(t0, MemOperand(a0, offsetof(TestFloat, rt))); __ Move(f12, 0.0); __ Move(f10, 0.0); __ Move(f16, 0.0); __ Move(f14, 0.0); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, bold)) ); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, dold)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, bold1)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, dold1)) ); __ movz_s(f10, f6, t0); __ movz_d(f12, f2, t0); __ movn_s(f14, f6, t0); __ movn_d(f16, f2, t0); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, b)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, d1)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, b1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; test.rt = 1; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, test.bold); CHECK_EQ(test.d, test.dold); CHECK_EQ(test.b1, outputs_D[i]); CHECK_EQ(test.d1, outputs_S[i]); test.rt = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); CHECK_EQ(test.b1, test.bold1); CHECK_EQ(test.d1, test.dold1); } } } TEST(movt_movd) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); typedef struct test_float { double srcd; double dstd; double dstdold; double dstd1; double dstdold1; float srcf; float dstf; float dstfold; float dstf1; float dstfold1; int32_t cc; int32_t fcsr; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; double inputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; int condition_flags[8] = {0, 1, 2, 3, 4, 5, 6, 7}; for (int i = 0; i < kTableLength; i++) { test.srcd = inputs_D[i]; test.srcf = inputs_S[i]; for (int j = 0; j< 8; j++) { test.cc = condition_flags[j]; if (test.cc == 0) { test.fcsr = 1 << 23; } else { test.fcsr = 1 << (24+condition_flags[j]); } HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, srcd)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, srcf)) ); __ lw(t1, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t0, FCSR); __ ctc1(t1, FCSR); __ li(t2, 0x0); __ mtc1(t2, f12); __ mtc1(t2, f10); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold)) ); __ movt_s(f12, f4, test.cc); __ movt_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold1)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold1)) ); __ movf_s(f12, f4, test.cc); __ movf_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf1)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd1)) ); __ ctc1(t0, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, outputs_S[i]); CHECK_EQ(test.dstd, outputs_D[i]); CHECK_EQ(test.dstf1, test.dstfold1); CHECK_EQ(test.dstd1, test.dstdold1); test.fcsr = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, test.dstfold); CHECK_EQ(test.dstd, test.dstdold); CHECK_EQ(test.dstf1, outputs_S[i]); CHECK_EQ(test.dstd1, outputs_D[i]); } } } } // ----------------------tests for all archs-------------------------- TEST(cvt_w_d) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; int32_t b; int fcsr; }Test; const int kTableLength = 24; double inputs[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, 2147483653.0 }; double outputs_RN[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RZ[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RP[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RM[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lw(t0, MemOperand(a0, offsetof(Test, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ cvt_w_d(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(Test, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } TEST(trunc_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_w_d(f8, f4); __ trunc_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_w_d(f8, f4); __ round_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_l_d(f8, f4); __ round_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(sub) { const int kTableLength = 12; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; double inputft_D[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; double outputs_D[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; float inputfs_S[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; float inputft_S[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; float outputs_S[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sub_s(f6, f2, f4); __ sub_d(f12, f8, f10); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(sqrt_rsqrt_recip) { const int kTableLength = 4; const double deltaDouble = 2E-15; const float deltaFloat = 2E-7; const float sqrt2_s = sqrt(2); const double sqrt2_d = sqrt(2); CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; float resultS1; float resultS2; double c; double resultD; double resultD1; double resultD2; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 0.0L, 4.0L, 2.0L, 4e-28L }; double outputs_D[kTableLength] = { 0.0L, 2.0L, sqrt2_d, 2e-14L }; float inputs_S[kTableLength] = { 0.0, 4.0, 2.0, 4e-28 }; float outputs_S[kTableLength] = { 0.0, 2.0, sqrt2_s, 2e-14 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ sqrt_s(f6, f2); __ sqrt_d(f12, f8); __ rsqrt_d(f14, f8); __ rsqrt_s(f16, f2); __ recip_d(f18, f8); __ recip_s(f4, f2); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resultS1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resultD1)) ); __ swc1(f4, MemOperand(a0, offsetof(TestFloat, resultS2)) ); __ sdc1(f18, MemOperand(a0, offsetof(TestFloat, resultD2)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { float f1; double d1; test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); if (i != 0) { f1 = test.resultS1 - 1.0F/outputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD1 - 1.0L/outputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); f1 = test.resultS2 - 1.0F/inputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD2 - 1.0L/inputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); } else { CHECK_EQ(test.resultS1, 1.0F/outputs_S[i]); CHECK_EQ(test.resultD1, 1.0L/outputs_D[i]); CHECK_EQ(test.resultS2, 1.0F/inputs_S[i]); CHECK_EQ(test.resultD2, 1.0L/inputs_D[i]); } } } TEST(neg) { const int kTableLength = 2; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; double c; double resultD; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 4.0, -2.0 }; double outputs_D[kTableLength] = { -4.0, 2.0 }; float inputs_S[kTableLength] = { 4.0, -2.0 }; float outputs_S[kTableLength] = { -4.0, 2.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ neg_s(f6, f2); __ neg_d(f12, f8); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
()); F3 f = FUNCTION_CAST(code->entry()); // Double test values. t.a = 1.5e14; t.b = 2.75e11; t.c = 0.0; t.d = 0.0; t.e = 0.0; t.f = 0.0; t.h = 1.5; t.i = 2.75; // Single test values. t.fa = 1.5e6; t.fb = 2.75e4; t.fc = 0.0; t.fd = 0.0; t.fe = 0.0; t.ff = 0.0; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); // Expected double results. CHECK_EQ(1.5e14, t.a); CHECK_EQ(1.5e14, t.b); CHECK_EQ(1.50275e14, t.c); CHECK_EQ(1.50550e14, t.d); CHECK_EQ(1.8066e16, t.e); CHECK_EQ(120.44, t.f); CHECK_EQ(10.97451593465515908537, t.g); if (kArchVariant == kMips64r2) { CHECK_EQ(6.875, t.h); } // Expected single results. CHECK_EQ(1.5e6, t.fa); CHECK_EQ(1.5e6, t.fb); CHECK_EQ(1.5275e06, t.fc); CHECK_EQ(1.5550e06, t.fd); CHECK_EQ(1.866e08, t.fe); CHECK_EQ(124.40000152587890625, t.ff); CHECK_EQ(11.1534748077392578125, t.fg); } TEST(MIPS4) { // Test moves between floating point and integer registers. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double a; double b; double c; double d; int64_t high; int64_t low; } T; T t; Assembler assm(isolate, NULL, 0); Label L, C; __ ldc1(f4, MemOperand(a0, offsetof(T, a))); __ ldc1(f5, MemOperand(a0, offsetof(T, b))); // Swap f4 and f5, by using 3 integer registers, a4-a6, // both two 32-bit chunks, and one 64-bit chunk. // mXhc1 is mips32/64-r2 only, not r1, // but we will not support r1 in practice. __ mfc1(a4, f4); __ mfhc1(a5, f4); __ dmfc1(a6, f5); __ mtc1(a4, f5); __ mthc1(a5, f5); __ dmtc1(a6, f4); // Store the swapped f4 and f5 back to memory. __ sdc1(f4, MemOperand(a0, offsetof(T, a))); __ sdc1(f5, MemOperand(a0, offsetof(T, c))); // Test sign extension of move operations from coprocessor. __ ldc1(f4, MemOperand(a0, offsetof(T, d))); __ mfhc1(a4, f4); __ mfc1(a5, f4); __ sd(a4, MemOperand(a0, offsetof(T, high))); __ sd(a5, MemOperand(a0, offsetof(T, low))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.a = 1.5e22; t.b = 2.75e11; t.c = 17.17; t.d = -2.75e11; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(2.75e11, t.a); CHECK_EQ(2.75e11, t.b); CHECK_EQ(1.5e22, t.c); CHECK_EQ(static_cast(0xffffffffc25001d1L), t.high); CHECK_EQ(static_cast(0xffffffffbf800000L), t.low); } TEST(MIPS5) { // Test conversions between doubles and integers. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double a; double b; int i; int j; } T; T t; Assembler assm(isolate, NULL, 0); Label L, C; // Load all structure elements to registers. __ ldc1(f4, MemOperand(a0, offsetof(T, a)) ); __ ldc1(f6, MemOperand(a0, offsetof(T, b)) ); __ lw(a4, MemOperand(a0, offsetof(T, i)) ); __ lw(a5, MemOperand(a0, offsetof(T, j)) ); // Convert double in f4 to int in element i. __ cvt_w_d(f8, f4); __ mfc1(a6, f8); __ sw(a6, MemOperand(a0, offsetof(T, i)) ); // Convert double in f6 to int in element j. __ cvt_w_d(f10, f6); __ mfc1(a7, f10); __ sw(a7, MemOperand(a0, offsetof(T, j)) ); // Convert int in original i (a4) to double in a. __ mtc1(a4, f12); __ cvt_d_w(f0, f12); __ sdc1(f0, MemOperand(a0, offsetof(T, a)) ); // Convert int in original j (a5) to double in b. __ mtc1(a5, f14); __ cvt_d_w(f2, f14); __ sdc1(f2, MemOperand(a0, offsetof(T, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.a = 1.5e4; t.b = 2.75e8; t.i = 12345678; t.j = -100000; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(12345678.0, t.a); CHECK_EQ(-100000.0, t.b); CHECK_EQ(15000, t.i); CHECK_EQ(275000000, t.j); } TEST(MIPS6) { // Test simple memory loads and stores. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { uint32_t ui; int32_t si; int32_t r1; int32_t r2; int32_t r3; int32_t r4; int32_t r5; int32_t r6; } T; T t; Assembler assm(isolate, NULL, 0); Label L, C; // Basic word load/store. __ lw(a4, MemOperand(a0, offsetof(T, ui)) ); __ sw(a4, MemOperand(a0, offsetof(T, r1)) ); // lh with positive data. __ lh(a5, MemOperand(a0, offsetof(T, ui)) ); __ sw(a5, MemOperand(a0, offsetof(T, r2)) ); // lh with negative data. __ lh(a6, MemOperand(a0, offsetof(T, si)) ); __ sw(a6, MemOperand(a0, offsetof(T, r3)) ); // lhu with negative data. __ lhu(a7, MemOperand(a0, offsetof(T, si)) ); __ sw(a7, MemOperand(a0, offsetof(T, r4)) ); // lb with negative data. __ lb(t0, MemOperand(a0, offsetof(T, si)) ); __ sw(t0, MemOperand(a0, offsetof(T, r5)) ); // sh writes only 1/2 of word. __ lui(t1, 0x3333); __ ori(t1, t1, 0x3333); __ sw(t1, MemOperand(a0, offsetof(T, r6)) ); __ lhu(t1, MemOperand(a0, offsetof(T, si)) ); __ sh(t1, MemOperand(a0, offsetof(T, r6)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.ui = 0x11223344; t.si = 0x99aabbcc; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(static_cast(0x11223344), t.r1); if (kArchEndian == kLittle) { CHECK_EQ(static_cast(0x3344), t.r2); CHECK_EQ(static_cast(0xffffbbcc), t.r3); CHECK_EQ(static_cast(0x0000bbcc), t.r4); CHECK_EQ(static_cast(0xffffffcc), t.r5); CHECK_EQ(static_cast(0x3333bbcc), t.r6); } else { CHECK_EQ(static_cast(0x1122), t.r2); CHECK_EQ(static_cast(0xffff99aa), t.r3); CHECK_EQ(static_cast(0x000099aa), t.r4); CHECK_EQ(static_cast(0xffffff99), t.r5); CHECK_EQ(static_cast(0x99aa3333), t.r6); } } TEST(MIPS7) { // Test floating point compare and branch instructions. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double a; double b; double c; double d; double e; double f; int32_t result; } T; T t; // Create a function that accepts &t, and loads, manipulates, and stores // the doubles t.a ... t.f. MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); Label neither_is_nan, less_than, outa_here; __ ldc1(f4, MemOperand(a0, offsetof(T, a)) ); __ ldc1(f6, MemOperand(a0, offsetof(T, b)) ); if (kArchVariant != kMips64r6) { __ c(UN, D, f4, f6); __ bc1f(&neither_is_nan); } else { __ cmp(UN, L, f2, f4, f6); __ bc1eqz(&neither_is_nan, f2); } __ nop(); __ sw(zero_reg, MemOperand(a0, offsetof(T, result)) ); __ Branch(&outa_here); __ bind(&neither_is_nan); if (kArchVariant == kMips64r6) { __ cmp(OLT, L, f2, f6, f4); __ bc1nez(&less_than, f2); } else { __ c(OLT, D, f6, f4, 2); __ bc1t(&less_than, 2); } __ nop(); __ sw(zero_reg, MemOperand(a0, offsetof(T, result)) ); __ Branch(&outa_here); __ bind(&less_than); __ Addu(a4, zero_reg, Operand(1)); __ sw(a4, MemOperand(a0, offsetof(T, result)) ); // Set true. // This test-case should have additional tests. __ bind(&outa_here); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.a = 1.5e14; t.b = 2.75e11; t.c = 2.0; t.d = -4.0; t.e = 0.0; t.f = 0.0; t.result = 0; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(1.5e14, t.a); CHECK_EQ(2.75e11, t.b); CHECK_EQ(1, t.result); } TEST(MIPS8) { if (kArchVariant == kMips64r2) { // Test ROTR and ROTRV instructions. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { int32_t input; int32_t result_rotr_4; int32_t result_rotr_8; int32_t result_rotr_12; int32_t result_rotr_16; int32_t result_rotr_20; int32_t result_rotr_24; int32_t result_rotr_28; int32_t result_rotrv_4; int32_t result_rotrv_8; int32_t result_rotrv_12; int32_t result_rotrv_16; int32_t result_rotrv_20; int32_t result_rotrv_24; int32_t result_rotrv_28; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); // Basic word load. __ lw(a4, MemOperand(a0, offsetof(T, input)) ); // ROTR instruction (called through the Ror macro). __ Ror(a5, a4, 0x0004); __ Ror(a6, a4, 0x0008); __ Ror(a7, a4, 0x000c); __ Ror(t0, a4, 0x0010); __ Ror(t1, a4, 0x0014); __ Ror(t2, a4, 0x0018); __ Ror(t3, a4, 0x001c); // Basic word store. __ sw(a5, MemOperand(a0, offsetof(T, result_rotr_4)) ); __ sw(a6, MemOperand(a0, offsetof(T, result_rotr_8)) ); __ sw(a7, MemOperand(a0, offsetof(T, result_rotr_12)) ); __ sw(t0, MemOperand(a0, offsetof(T, result_rotr_16)) ); __ sw(t1, MemOperand(a0, offsetof(T, result_rotr_20)) ); __ sw(t2, MemOperand(a0, offsetof(T, result_rotr_24)) ); __ sw(t3, MemOperand(a0, offsetof(T, result_rotr_28)) ); // ROTRV instruction (called through the Ror macro). __ li(t3, 0x0004); __ Ror(a5, a4, t3); __ li(t3, 0x0008); __ Ror(a6, a4, t3); __ li(t3, 0x000C); __ Ror(a7, a4, t3); __ li(t3, 0x0010); __ Ror(t0, a4, t3); __ li(t3, 0x0014); __ Ror(t1, a4, t3); __ li(t3, 0x0018); __ Ror(t2, a4, t3); __ li(t3, 0x001C); __ Ror(t3, a4, t3); // Basic word store. __ sw(a5, MemOperand(a0, offsetof(T, result_rotrv_4)) ); __ sw(a6, MemOperand(a0, offsetof(T, result_rotrv_8)) ); __ sw(a7, MemOperand(a0, offsetof(T, result_rotrv_12)) ); __ sw(t0, MemOperand(a0, offsetof(T, result_rotrv_16)) ); __ sw(t1, MemOperand(a0, offsetof(T, result_rotrv_20)) ); __ sw(t2, MemOperand(a0, offsetof(T, result_rotrv_24)) ); __ sw(t3, MemOperand(a0, offsetof(T, result_rotrv_28)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.input = 0x12345678; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0x0, 0, 0, 0); USE(dummy); CHECK_EQ(static_cast(0x81234567), t.result_rotr_4); CHECK_EQ(static_cast(0x78123456), t.result_rotr_8); CHECK_EQ(static_cast(0x67812345), t.result_rotr_12); CHECK_EQ(static_cast(0x56781234), t.result_rotr_16); CHECK_EQ(static_cast(0x45678123), t.result_rotr_20); CHECK_EQ(static_cast(0x34567812), t.result_rotr_24); CHECK_EQ(static_cast(0x23456781), t.result_rotr_28); CHECK_EQ(static_cast(0x81234567), t.result_rotrv_4); CHECK_EQ(static_cast(0x78123456), t.result_rotrv_8); CHECK_EQ(static_cast(0x67812345), t.result_rotrv_12); CHECK_EQ(static_cast(0x56781234), t.result_rotrv_16); CHECK_EQ(static_cast(0x45678123), t.result_rotrv_20); CHECK_EQ(static_cast(0x34567812), t.result_rotrv_24); CHECK_EQ(static_cast(0x23456781), t.result_rotrv_28); } } TEST(MIPS9) { // Test BRANCH improvements. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); Label exit, exit2, exit3; __ Branch(&exit, ge, a0, Operand(zero_reg)); __ Branch(&exit2, ge, a0, Operand(0x00001FFF)); __ Branch(&exit3, ge, a0, Operand(0x0001FFFF)); __ bind(&exit); __ bind(&exit2); __ bind(&exit3); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); } TEST(MIPS10) { // Test conversions between doubles and long integers. // Test hos the long ints map to FP regs pairs. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double a; double a_converted; double b; int32_t dbl_mant; int32_t dbl_exp; int32_t long_hi; int32_t long_lo; int64_t long_as_int64; int32_t b_long_hi; int32_t b_long_lo; int64_t b_long_as_int64; } T; T t; Assembler assm(isolate, NULL, 0); Label L, C; if (kArchVariant == kMips64r2) { // Rewritten for FR=1 FPU mode: // - 32 FP regs of 64-bits each, no odd/even pairs. // - Note that cvt_l_d/cvt_d_l ARE legal in FR=1 mode. // Load all structure elements to registers. __ ldc1(f0, MemOperand(a0, offsetof(T, a))); // Save the raw bits of the double. __ mfc1(a4, f0); __ mfhc1(a5, f0); __ sw(a4, MemOperand(a0, offsetof(T, dbl_mant))); __ sw(a5, MemOperand(a0, offsetof(T, dbl_exp))); // Convert double in f0 to long, save hi/lo parts. __ cvt_l_d(f0, f0); __ mfc1(a4, f0); // f0 LS 32 bits of long. __ mfhc1(a5, f0); // f0 MS 32 bits of long. __ sw(a4, MemOperand(a0, offsetof(T, long_lo))); __ sw(a5, MemOperand(a0, offsetof(T, long_hi))); // Combine the high/low ints, convert back to double. __ dsll32(a6, a5, 0); // Move a5 to high bits of a6. __ or_(a6, a6, a4); __ dmtc1(a6, f1); __ cvt_d_l(f1, f1); __ sdc1(f1, MemOperand(a0, offsetof(T, a_converted))); // Convert the b long integers to double b. __ lw(a4, MemOperand(a0, offsetof(T, b_long_lo))); __ lw(a5, MemOperand(a0, offsetof(T, b_long_hi))); __ mtc1(a4, f8); // f8 LS 32-bits. __ mthc1(a5, f8); // f8 MS 32-bits. __ cvt_d_l(f10, f8); __ sdc1(f10, MemOperand(a0, offsetof(T, b))); // Convert double b back to long-int. __ ldc1(f31, MemOperand(a0, offsetof(T, b))); __ cvt_l_d(f31, f31); __ dmfc1(a7, f31); __ sd(a7, MemOperand(a0, offsetof(T, b_long_as_int64))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.a = 2.147483647e9; // 0x7fffffff -> 0x41DFFFFFFFC00000 as double. t.b_long_hi = 0x000000ff; // 0xFF00FF00FF -> 0x426FE01FE01FE000 as double. t.b_long_lo = 0x00ff00ff; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(static_cast(0x41DFFFFF), t.dbl_exp); CHECK_EQ(static_cast(0xFFC00000), t.dbl_mant); CHECK_EQ(0, t.long_hi); CHECK_EQ(static_cast(0x7fffffff), t.long_lo); CHECK_EQ(2.147483647e9, t.a_converted); // 0xFF00FF00FF -> 1.095233372415e12. CHECK_EQ(1.095233372415e12, t.b); CHECK_EQ(static_cast(0xFF00FF00FF), t.b_long_as_int64); } } TEST(MIPS11) { // Do not run test on MIPS64r6, as these instructions are removed. if (kArchVariant != kMips64r6) { // Test LWL, LWR, SWL and SWR instructions. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { int32_t reg_init; int32_t mem_init; int32_t lwl_0; int32_t lwl_1; int32_t lwl_2; int32_t lwl_3; int32_t lwr_0; int32_t lwr_1; int32_t lwr_2; int32_t lwr_3; int32_t swl_0; int32_t swl_1; int32_t swl_2; int32_t swl_3; int32_t swr_0; int32_t swr_1; int32_t swr_2; int32_t swr_3; } T; T t; Assembler assm(isolate, NULL, 0); // Test all combinations of LWL and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, lwl_0))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a5, MemOperand(a0, offsetof(T, mem_init) + 1)); __ sw(a5, MemOperand(a0, offsetof(T, lwl_1))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a6, MemOperand(a0, offsetof(T, mem_init) + 2)); __ sw(a6, MemOperand(a0, offsetof(T, lwl_2))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a7, MemOperand(a0, offsetof(T, mem_init) + 3)); __ sw(a7, MemOperand(a0, offsetof(T, lwl_3))); // Test all combinations of LWR and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, lwr_0))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a5, MemOperand(a0, offsetof(T, mem_init) + 1)); __ sw(a5, MemOperand(a0, offsetof(T, lwr_1))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a6, MemOperand(a0, offsetof(T, mem_init) + 2)); __ sw(a6, MemOperand(a0, offsetof(T, lwr_2)) ); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a7, MemOperand(a0, offsetof(T, mem_init) + 3)); __ sw(a7, MemOperand(a0, offsetof(T, lwr_3)) ); // Test all combinations of SWL and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, swl_0))); __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ swl(a4, MemOperand(a0, offsetof(T, swl_0))); __ lw(a5, MemOperand(a0, offsetof(T, mem_init))); __ sw(a5, MemOperand(a0, offsetof(T, swl_1))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ swl(a5, MemOperand(a0, offsetof(T, swl_1) + 1)); __ lw(a6, MemOperand(a0, offsetof(T, mem_init))); __ sw(a6, MemOperand(a0, offsetof(T, swl_2))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ swl(a6, MemOperand(a0, offsetof(T, swl_2) + 2)); __ lw(a7, MemOperand(a0, offsetof(T, mem_init))); __ sw(a7, MemOperand(a0, offsetof(T, swl_3))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ swl(a7, MemOperand(a0, offsetof(T, swl_3) + 3)); // Test all combinations of SWR and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, swr_0))); __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ swr(a4, MemOperand(a0, offsetof(T, swr_0))); __ lw(a5, MemOperand(a0, offsetof(T, mem_init))); __ sw(a5, MemOperand(a0, offsetof(T, swr_1))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ swr(a5, MemOperand(a0, offsetof(T, swr_1) + 1)); __ lw(a6, MemOperand(a0, offsetof(T, mem_init))); __ sw(a6, MemOperand(a0, offsetof(T, swr_2))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ swr(a6, MemOperand(a0, offsetof(T, swr_2) + 2)); __ lw(a7, MemOperand(a0, offsetof(T, mem_init))); __ sw(a7, MemOperand(a0, offsetof(T, swr_3))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ swr(a7, MemOperand(a0, offsetof(T, swr_3) + 3)); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.reg_init = 0xaabbccdd; t.mem_init = 0x11223344; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); if (kArchEndian == kLittle) { CHECK_EQ(static_cast(0x44bbccdd), t.lwl_0); CHECK_EQ(static_cast(0x3344ccdd), t.lwl_1); CHECK_EQ(static_cast(0x223344dd), t.lwl_2); CHECK_EQ(static_cast(0x11223344), t.lwl_3); CHECK_EQ(static_cast(0x11223344), t.lwr_0); CHECK_EQ(static_cast(0xaa112233), t.lwr_1); CHECK_EQ(static_cast(0xaabb1122), t.lwr_2); CHECK_EQ(static_cast(0xaabbcc11), t.lwr_3); CHECK_EQ(static_cast(0x112233aa), t.swl_0); CHECK_EQ(static_cast(0x1122aabb), t.swl_1); CHECK_EQ(static_cast(0x11aabbcc), t.swl_2); CHECK_EQ(static_cast(0xaabbccdd), t.swl_3); CHECK_EQ(static_cast(0xaabbccdd), t.swr_0); CHECK_EQ(static_cast(0xbbccdd44), t.swr_1); CHECK_EQ(static_cast(0xccdd3344), t.swr_2); CHECK_EQ(static_cast(0xdd223344), t.swr_3); } else { CHECK_EQ(static_cast(0x11223344), t.lwl_0); CHECK_EQ(static_cast(0x223344dd), t.lwl_1); CHECK_EQ(static_cast(0x3344ccdd), t.lwl_2); CHECK_EQ(static_cast(0x44bbccdd), t.lwl_3); CHECK_EQ(static_cast(0xaabbcc11), t.lwr_0); CHECK_EQ(static_cast(0xaabb1122), t.lwr_1); CHECK_EQ(static_cast(0xaa112233), t.lwr_2); CHECK_EQ(static_cast(0x11223344), t.lwr_3); CHECK_EQ(static_cast(0xaabbccdd), t.swl_0); CHECK_EQ(static_cast(0x11aabbcc), t.swl_1); CHECK_EQ(static_cast(0x1122aabb), t.swl_2); CHECK_EQ(static_cast(0x112233aa), t.swl_3); CHECK_EQ(static_cast(0xdd223344), t.swr_0); CHECK_EQ(static_cast(0xccdd3344), t.swr_1); CHECK_EQ(static_cast(0xbbccdd44), t.swr_2); CHECK_EQ(static_cast(0xaabbccdd), t.swr_3); } } } TEST(MIPS12) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { int32_t x; int32_t y; int32_t y1; int32_t y2; int32_t y3; int32_t y4; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ mov(t2, fp); // Save frame pointer. __ mov(fp, a0); // Access struct T by fp. __ lw(a4, MemOperand(a0, offsetof(T, y))); __ lw(a7, MemOperand(a0, offsetof(T, y4))); __ addu(a5, a4, a7); __ subu(t0, a4, a7); __ nop(); __ push(a4); // These instructions disappear after opt. __ Pop(); __ addu(a4, a4, a4); __ nop(); __ Pop(); // These instructions disappear after opt. __ push(a7); __ nop(); __ push(a7); // These instructions disappear after opt. __ pop(a7); __ nop(); __ push(a7); __ pop(t0); __ nop(); __ sw(a4, MemOperand(fp, offsetof(T, y))); __ lw(a4, MemOperand(fp, offsetof(T, y))); __ nop(); __ sw(a4, MemOperand(fp, offsetof(T, y))); __ lw(a5, MemOperand(fp, offsetof(T, y))); __ nop(); __ push(a5); __ lw(a5, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a6); __ nop(); __ push(a6); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a7); __ nop(); __ mov(fp, t2); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.x = 1; t.y = 2; t.y1 = 3; t.y2 = 4; t.y3 = 0XBABA; t.y4 = 0xDEDA; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(3, t.y1); } TEST(MIPS13) { // Test Cvt_d_uw and Trunc_uw_d macros. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double cvt_big_out; double cvt_small_out; uint32_t trunc_big_out; uint32_t trunc_small_out; uint32_t cvt_big_in; uint32_t cvt_small_in; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ sw(a4, MemOperand(a0, offsetof(T, cvt_small_in))); __ Cvt_d_uw(f10, a4); __ sdc1(f10, MemOperand(a0, offsetof(T, cvt_small_out))); __ Trunc_uw_d(f10, f10, f4); __ swc1(f10, MemOperand(a0, offsetof(T, trunc_small_out))); __ sw(a4, MemOperand(a0, offsetof(T, cvt_big_in))); __ Cvt_d_uw(f8, a4); __ sdc1(f8, MemOperand(a0, offsetof(T, cvt_big_out))); __ Trunc_uw_d(f8, f8, f4); __ swc1(f8, MemOperand(a0, offsetof(T, trunc_big_out))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.cvt_big_in = 0xFFFFFFFF; t.cvt_small_in = 333; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(t.cvt_big_out, static_cast(t.cvt_big_in)); CHECK_EQ(t.cvt_small_out, static_cast(t.cvt_small_in)); CHECK_EQ(static_cast(t.trunc_big_out), static_cast(t.cvt_big_in)); CHECK_EQ(static_cast(t.trunc_small_out), static_cast(t.cvt_small_in)); } TEST(MIPS14) { // Test round, floor, ceil, trunc, cvt. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); #define ROUND_STRUCT_ELEMENT(x) \ uint32_t x##_isNaN2008; \ int32_t x##_up_out; \ int32_t x##_down_out; \ int32_t neg_##x##_up_out; \ int32_t neg_##x##_down_out; \ uint32_t x##_err1_out; \ uint32_t x##_err2_out; \ uint32_t x##_err3_out; \ uint32_t x##_err4_out; \ int32_t x##_invalid_result; typedef struct { double round_up_in; double round_down_in; double neg_round_up_in; double neg_round_down_in; double err1_in; double err2_in; double err3_in; double err4_in; ROUND_STRUCT_ELEMENT(round) ROUND_STRUCT_ELEMENT(floor) ROUND_STRUCT_ELEMENT(ceil) ROUND_STRUCT_ELEMENT(trunc) ROUND_STRUCT_ELEMENT(cvt) } T; T t; #undef ROUND_STRUCT_ELEMENT MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); // Save FCSR. __ cfc1(a1, FCSR); // Disable FPU exceptions. __ ctc1(zero_reg, FCSR); #define RUN_ROUND_TEST(x) \ __ cfc1(t0, FCSR);\ __ sw(t0, MemOperand(a0, offsetof(T, x##_isNaN2008))); \ __ ldc1(f0, MemOperand(a0, offsetof(T, round_up_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_up_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, round_down_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_down_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, neg_round_up_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, neg_##x##_up_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, neg_round_down_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, neg_##x##_down_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err1_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err1_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err2_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err2_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err3_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err3_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err4_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err4_out))); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_invalid_result))); RUN_ROUND_TEST(round) RUN_ROUND_TEST(floor) RUN_ROUND_TEST(ceil) RUN_ROUND_TEST(trunc) RUN_ROUND_TEST(cvt) // Restore FCSR. __ ctc1(a1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.round_up_in = 123.51; t.round_down_in = 123.49; t.neg_round_up_in = -123.5; t.neg_round_down_in = -123.49; t.err1_in = 123.51; t.err2_in = 1; t.err3_in = static_cast(1) + 0xFFFFFFFF; t.err4_in = NAN; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); #define GET_FPU_ERR(x) (static_cast(x & kFCSRFlagMask)) #define CHECK_NAN2008(x) (x & kFCSRNaN2008FlagMask) #define CHECK_ROUND_RESULT(type) \ CHECK(GET_FPU_ERR(t.type##_err1_out) & kFCSRInexactFlagMask); \ CHECK_EQ(0, GET_FPU_ERR(t.type##_err2_out)); \ CHECK(GET_FPU_ERR(t.type##_err3_out) & kFCSRInvalidOpFlagMask); \ CHECK(GET_FPU_ERR(t.type##_err4_out) & kFCSRInvalidOpFlagMask); \ if (CHECK_NAN2008(t.type##_isNaN2008) && kArchVariant == kMips64r6) { \ CHECK_EQ(static_cast(0), t.type##_invalid_result);\ } else { \ CHECK_EQ(static_cast(kFPUInvalidResult), t.type##_invalid_result);\ } CHECK_ROUND_RESULT(round); CHECK_ROUND_RESULT(floor); CHECK_ROUND_RESULT(ceil); CHECK_ROUND_RESULT(cvt); } TEST(MIPS15) { // Test chaining of label usages within instructions (issue 1644). CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); Assembler assm(isolate, NULL, 0); Label target; __ beq(v0, v1, &target); __ nop(); __ bne(v0, v1, &target); __ nop(); __ bind(&target); __ nop(); } // ----- mips64 tests ----------------------------------------------- TEST(MIPS16) { // Test 64-bit memory loads and stores. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); struct T { int64_t r1; int64_t r2; int64_t r3; int64_t r4; int64_t r5; int64_t r6; int64_t r7; int64_t r8; int64_t r9; int64_t r10; int64_t r11; int64_t r12; uint32_t ui; int32_t si; }; T t; Assembler assm(isolate, NULL, 0); Label L, C; // Basic 32-bit word load/store, with un-signed data. __ lw(a4, MemOperand(a0, offsetof(T, ui))); __ sw(a4, MemOperand(a0, offsetof(T, r1))); // Check that the data got zero-extended into 64-bit a4. __ sd(a4, MemOperand(a0, offsetof(T, r2))); // Basic 32-bit word load/store, with SIGNED data. __ lw(a5, MemOperand(a0, offsetof(T, si))); __ sw(a5, MemOperand(a0, offsetof(T, r3))); // Check that the data got sign-extended into 64-bit a4. __ sd(a5, MemOperand(a0, offsetof(T, r4))); // 32-bit UNSIGNED word load/store, with SIGNED data. __ lwu(a6, MemOperand(a0, offsetof(T, si))); __ sw(a6, MemOperand(a0, offsetof(T, r5))); // Check that the data got zero-extended into 64-bit a4. __ sd(a6, MemOperand(a0, offsetof(T, r6))); // lh with positive data. __ lh(a5, MemOperand(a0, offsetof(T, ui))); __ sw(a5, MemOperand(a0, offsetof(T, r7))); // lh with negative data. __ lh(a6, MemOperand(a0, offsetof(T, si))); __ sw(a6, MemOperand(a0, offsetof(T, r8))); // lhu with negative data. __ lhu(a7, MemOperand(a0, offsetof(T, si))); __ sw(a7, MemOperand(a0, offsetof(T, r9))); // lb with negative data. __ lb(t0, MemOperand(a0, offsetof(T, si))); __ sw(t0, MemOperand(a0, offsetof(T, r10))); // sh writes only 1/2 of word. __ lw(a4, MemOperand(a0, offsetof(T, ui))); __ sh(a4, MemOperand(a0, offsetof(T, r11))); __ lw(a4, MemOperand(a0, offsetof(T, si))); __ sh(a4, MemOperand(a0, offsetof(T, r12))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.ui = 0x44332211; t.si = 0x99aabbcc; t.r1 = 0x5555555555555555; t.r2 = 0x5555555555555555; t.r3 = 0x5555555555555555; t.r4 = 0x5555555555555555; t.r5 = 0x5555555555555555; t.r6 = 0x5555555555555555; t.r7 = 0x5555555555555555; t.r8 = 0x5555555555555555; t.r9 = 0x5555555555555555; t.r10 = 0x5555555555555555; t.r11 = 0x5555555555555555; t.r12 = 0x5555555555555555; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); if (kArchEndian == kLittle) { // Unsigned data, 32 & 64 CHECK_EQ(static_cast(0x5555555544332211L), t.r1); // lw, sw. CHECK_EQ(static_cast(0x0000000044332211L), t.r2); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x5555555599aabbccL), t.r3); // lw, sw. CHECK_EQ(static_cast(0xffffffff99aabbccL), t.r4); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x5555555599aabbccL), t.r5); // lwu, sw. CHECK_EQ(static_cast(0x0000000099aabbccL), t.r6); // sd. // lh with unsigned and signed data. CHECK_EQ(static_cast(0x5555555500002211L), t.r7); // lh, sw. CHECK_EQ(static_cast(0x55555555ffffbbccL), t.r8); // lh, sw. // lhu with signed data. CHECK_EQ(static_cast(0x555555550000bbccL), t.r9); // lhu, sw. // lb with signed data. CHECK_EQ(static_cast(0x55555555ffffffccL), t.r10); // lb, sw. // sh with unsigned and signed data. CHECK_EQ(static_cast(0x5555555555552211L), t.r11); // lw, sh. CHECK_EQ(static_cast(0x555555555555bbccL), t.r12); // lw, sh. } else { // Unsigned data, 32 & 64 CHECK_EQ(static_cast(0x4433221155555555L), t.r1); // lw, sw. CHECK_EQ(static_cast(0x0000000044332211L), t.r2); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x99aabbcc55555555L), t.r3); // lw, sw. CHECK_EQ(static_cast(0xffffffff99aabbccL), t.r4); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x99aabbcc55555555L), t.r5); // lwu, sw. CHECK_EQ(static_cast(0x0000000099aabbccL), t.r6); // sd. // lh with unsigned and signed data. CHECK_EQ(static_cast(0x0000443355555555L), t.r7); // lh, sw. CHECK_EQ(static_cast(0xffff99aa55555555L), t.r8); // lh, sw. // lhu with signed data. CHECK_EQ(static_cast(0x000099aa55555555L), t.r9); // lhu, sw. // lb with signed data. CHECK_EQ(static_cast(0xffffff9955555555L), t.r10); // lb, sw. // sh with unsigned and signed data. CHECK_EQ(static_cast(0x2211555555555555L), t.r11); // lw, sh. CHECK_EQ(static_cast(0xbbcc555555555555L), t.r12); // lw, sh. } } // ----------------------mips64r6 specific tests---------------------- TEST(seleqz_selnez) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { int a; int b; int c; int d; double e; double f; double g; double h; float i; float j; float k; float l; } Test; Test test; // Integer part of test. __ addiu(t1, zero_reg, 1); // t1 = 1 __ seleqz(t3, t1, zero_reg); // t3 = 1 __ sw(t3, MemOperand(a0, offsetof(Test, a))); // a = 1 __ seleqz(t2, t1, t1); // t2 = 0 __ sw(t2, MemOperand(a0, offsetof(Test, b))); // b = 0 __ selnez(t3, t1, zero_reg); // t3 = 1; __ sw(t3, MemOperand(a0, offsetof(Test, c))); // c = 0 __ selnez(t3, t1, t1); // t3 = 1 __ sw(t3, MemOperand(a0, offsetof(Test, d))); // d = 1 // Floating point part of test. __ ldc1(f0, MemOperand(a0, offsetof(Test, e)) ); // src __ ldc1(f2, MemOperand(a0, offsetof(Test, f)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, i)) ); // src __ lwc1(f10, MemOperand(a0, offsetof(Test, j)) ); // test __ seleqz_d(f4, f0, f2); __ selnez_d(f6, f0, f2); __ seleqz_s(f12, f8, f10); __ selnez_s(f14, f8, f10); __ sdc1(f4, MemOperand(a0, offsetof(Test, g)) ); // src __ sdc1(f6, MemOperand(a0, offsetof(Test, h)) ); // src __ swc1(f12, MemOperand(a0, offsetof(Test, k)) ); // src __ swc1(f14, MemOperand(a0, offsetof(Test, l)) ); // src __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.a, 1); CHECK_EQ(test.b, 0); CHECK_EQ(test.c, 0); CHECK_EQ(test.d, 1); const int test_size = 3; const int input_size = 5; double inputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double outputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float inputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float outputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.e = inputs_D[i]; test.f = tests_D[j]; test.i = inputs_S[i]; test.j = tests_S[j]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, outputs_D[i]); CHECK_EQ(test.h, 0); CHECK_EQ(test.k, outputs_S[i]); CHECK_EQ(test.l, 0); test.f = tests_D[j+1]; test.j = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, 0); CHECK_EQ(test.h, outputs_D[i]); CHECK_EQ(test.k, 0); CHECK_EQ(test.l, outputs_S[i]); } } } } TEST(min_max) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); struct TestFloat { double a; double b; double c; double d; float e; float f; float g; float h; }; TestFloat test; const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); const int kTableLength = 13; double inputsa[kTableLength] = {2.0, 3.0, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = {3.0, 2.0, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double outputsdmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double outputsdmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputse[kTableLength] = {2.0, 3.0, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsf[kTableLength] = {3.0, 2.0, 3.0, fnan, 0.0, -0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float outputsfmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float outputsfmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a))); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, b))); __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, e))); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, f))); __ min_d(f10, f4, f8); __ max_d(f12, f4, f8); __ min_s(f14, f2, f6); __ max_s(f16, f2, f6); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, c))); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, d))); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, g))); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, h))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 4; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.e = inputse[i]; test.f = inputsf[i]; CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0); CHECK_EQ(0, memcmp(&test.c, &outputsdmin[i], sizeof(test.c))); CHECK_EQ(0, memcmp(&test.d, &outputsdmax[i], sizeof(test.d))); CHECK_EQ(0, memcmp(&test.g, &outputsfmin[i], sizeof(test.g))); CHECK_EQ(0, memcmp(&test.h, &outputsfmax[i], sizeof(test.h))); } } } TEST(rint_d) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; int fcsr; }TestFloat; TestFloat test; double inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E+308, 6.27463370218383111104242366943E-307, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ ctc1(t0, FCSR); __ rint_d(f8, f4); __ sdc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(sel) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { double dd; double ds; double dt; float fd; float fs; float ft; } Test; Test test; __ ldc1(f0, MemOperand(a0, offsetof(Test, dd)) ); // test __ ldc1(f2, MemOperand(a0, offsetof(Test, ds)) ); // src1 __ ldc1(f4, MemOperand(a0, offsetof(Test, dt)) ); // src2 __ lwc1(f6, MemOperand(a0, offsetof(Test, fd)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, fs)) ); // src1 __ lwc1(f10, MemOperand(a0, offsetof(Test, ft)) ); // src2 __ sel_d(f0, f2, f4); __ sel_s(f6, f8, f10); __ sdc1(f0, MemOperand(a0, offsetof(Test, dd)) ); __ swc1(f6, MemOperand(a0, offsetof(Test, fd)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); const int test_size = 3; const int input_size = 5; double inputs_dt[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double inputs_ds[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; float inputs_ft[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float inputs_fs[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.dt = inputs_dt[i]; test.dd = tests_D[j]; test.ds = inputs_ds[i]; test.ft = inputs_ft[i]; test.fd = tests_S[j]; test.fs = inputs_fs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_ds[i]); CHECK_EQ(test.fd, inputs_fs[i]); test.dd = tests_D[j+1]; test.fd = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_dt[i]); CHECK_EQ(test.fd, inputs_ft[i]); } } } } TEST(rint_s) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; int fcsr; }TestFloat; TestFloat test; float inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E+38, 6.27463370218383111104242366943E-37, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; float* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ rint_s(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(mina_maxa) { if (kArchVariant == kMips64r6) { const int kTableLength = 23; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); struct TestFloat { double a; double b; double resd; double resd1; float c; float d; float resf; float resf1; }; TestFloat test; double inputsa[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = { 4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double resd[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double resd1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputsc[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsd[kTableLength] = {4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, fnan, -0.0, 0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float resf[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float resf1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ lwc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ lwc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ mina_d(f6, f2, f4); __ mina_s(f12, f8, f10); __ maxa_d(f14, f2, f4); __ maxa_s(f16, f8, f10); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, resf)) ); __ sdc1(f6, MemOperand(a0, offsetof(TestFloat, resd)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resf1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resd1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.c = inputsc[i]; test.d = inputsd[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if (i < kTableLength - 1) { CHECK_EQ(test.resd, resd[i]); CHECK_EQ(test.resf, resf[i]); CHECK_EQ(test.resd1, resd1[i]); CHECK_EQ(test.resf1, resf1[i]); } else { CHECK(std::isnan(test.resd)); CHECK(std::isnan(test.resf)); CHECK(std::isnan(test.resd1)); CHECK(std::isnan(test.resf1)); } } } } // ----------------------mips64r2 specific tests---------------------- TEST(trunc_l) { if (kArchVariant == kMips64r2) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; // a trunc result int64_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_l_d(f8, f4); __ trunc_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } } TEST(movz_movn) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { int64_t rt; double a; double b; double bold; double b1; double bold1; float c; float d; float dold; float d1; float dold1; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ld(t0, MemOperand(a0, offsetof(TestFloat, rt))); __ Move(f12, 0.0); __ Move(f10, 0.0); __ Move(f16, 0.0); __ Move(f14, 0.0); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, bold)) ); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, dold)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, bold1)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, dold1)) ); __ movz_s(f10, f6, t0); __ movz_d(f12, f2, t0); __ movn_s(f14, f6, t0); __ movn_d(f16, f2, t0); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, b)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, d1)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, b1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; test.rt = 1; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, test.bold); CHECK_EQ(test.d, test.dold); CHECK_EQ(test.b1, outputs_D[i]); CHECK_EQ(test.d1, outputs_S[i]); test.rt = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); CHECK_EQ(test.b1, test.bold1); CHECK_EQ(test.d1, test.dold1); } } } TEST(movt_movd) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); typedef struct test_float { double srcd; double dstd; double dstdold; double dstd1; double dstdold1; float srcf; float dstf; float dstfold; float dstf1; float dstfold1; int32_t cc; int32_t fcsr; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; double inputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; int condition_flags[8] = {0, 1, 2, 3, 4, 5, 6, 7}; for (int i = 0; i < kTableLength; i++) { test.srcd = inputs_D[i]; test.srcf = inputs_S[i]; for (int j = 0; j< 8; j++) { test.cc = condition_flags[j]; if (test.cc == 0) { test.fcsr = 1 << 23; } else { test.fcsr = 1 << (24+condition_flags[j]); } HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, srcd)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, srcf)) ); __ lw(t1, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t0, FCSR); __ ctc1(t1, FCSR); __ li(t2, 0x0); __ mtc1(t2, f12); __ mtc1(t2, f10); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold)) ); __ movt_s(f12, f4, test.cc); __ movt_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold1)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold1)) ); __ movf_s(f12, f4, test.cc); __ movf_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf1)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd1)) ); __ ctc1(t0, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, outputs_S[i]); CHECK_EQ(test.dstd, outputs_D[i]); CHECK_EQ(test.dstf1, test.dstfold1); CHECK_EQ(test.dstd1, test.dstdold1); test.fcsr = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, test.dstfold); CHECK_EQ(test.dstd, test.dstdold); CHECK_EQ(test.dstf1, outputs_S[i]); CHECK_EQ(test.dstd1, outputs_D[i]); } } } } // ----------------------tests for all archs-------------------------- TEST(cvt_w_d) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; int32_t b; int fcsr; }Test; const int kTableLength = 24; double inputs[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, 2147483653.0 }; double outputs_RN[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RZ[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RP[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RM[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lw(t0, MemOperand(a0, offsetof(Test, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ cvt_w_d(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(Test, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } TEST(trunc_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_w_d(f8, f4); __ trunc_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_w_d(f8, f4); __ round_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_l_d(f8, f4); __ round_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(sub) { const int kTableLength = 12; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; double inputft_D[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; double outputs_D[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; float inputfs_S[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; float inputft_S[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; float outputs_S[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sub_s(f6, f2, f4); __ sub_d(f12, f8, f10); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(sqrt_rsqrt_recip) { const int kTableLength = 4; const double deltaDouble = 2E-15; const float deltaFloat = 2E-7; const float sqrt2_s = sqrt(2); const double sqrt2_d = sqrt(2); CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; float resultS1; float resultS2; double c; double resultD; double resultD1; double resultD2; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 0.0L, 4.0L, 2.0L, 4e-28L }; double outputs_D[kTableLength] = { 0.0L, 2.0L, sqrt2_d, 2e-14L }; float inputs_S[kTableLength] = { 0.0, 4.0, 2.0, 4e-28 }; float outputs_S[kTableLength] = { 0.0, 2.0, sqrt2_s, 2e-14 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ sqrt_s(f6, f2); __ sqrt_d(f12, f8); __ rsqrt_d(f14, f8); __ rsqrt_s(f16, f2); __ recip_d(f18, f8); __ recip_s(f4, f2); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resultS1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resultD1)) ); __ swc1(f4, MemOperand(a0, offsetof(TestFloat, resultS2)) ); __ sdc1(f18, MemOperand(a0, offsetof(TestFloat, resultD2)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { float f1; double d1; test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); if (i != 0) { f1 = test.resultS1 - 1.0F/outputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD1 - 1.0L/outputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); f1 = test.resultS2 - 1.0F/inputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD2 - 1.0L/inputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); } else { CHECK_EQ(test.resultS1, 1.0F/outputs_S[i]); CHECK_EQ(test.resultD1, 1.0L/outputs_D[i]); CHECK_EQ(test.resultS2, 1.0F/inputs_S[i]); CHECK_EQ(test.resultD2, 1.0L/inputs_D[i]); } } } TEST(neg) { const int kTableLength = 2; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; double c; double resultD; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 4.0, -2.0 }; double outputs_D[kTableLength] = { -4.0, 2.0 }; float inputs_S[kTableLength] = { 4.0, -2.0 }; float outputs_S[kTableLength] = { -4.0, 2.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ neg_s(f6, f2); __ neg_d(f12, f8); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.a = 1.5e22; t.b = 2.75e11; t.c = 17.17; t.d = -2.75e11; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(2.75e11, t.a); CHECK_EQ(2.75e11, t.b); CHECK_EQ(1.5e22, t.c); CHECK_EQ(static_cast(0xffffffffc25001d1L), t.high); CHECK_EQ(static_cast(0xffffffffbf800000L), t.low); } TEST(MIPS5) { // Test conversions between doubles and integers. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double a; double b; int i; int j; } T; T t; Assembler assm(isolate, NULL, 0); Label L, C; // Load all structure elements to registers. __ ldc1(f4, MemOperand(a0, offsetof(T, a)) ); __ ldc1(f6, MemOperand(a0, offsetof(T, b)) ); __ lw(a4, MemOperand(a0, offsetof(T, i)) ); __ lw(a5, MemOperand(a0, offsetof(T, j)) ); // Convert double in f4 to int in element i. __ cvt_w_d(f8, f4); __ mfc1(a6, f8); __ sw(a6, MemOperand(a0, offsetof(T, i)) ); // Convert double in f6 to int in element j. __ cvt_w_d(f10, f6); __ mfc1(a7, f10); __ sw(a7, MemOperand(a0, offsetof(T, j)) ); // Convert int in original i (a4) to double in a. __ mtc1(a4, f12); __ cvt_d_w(f0, f12); __ sdc1(f0, MemOperand(a0, offsetof(T, a)) ); // Convert int in original j (a5) to double in b. __ mtc1(a5, f14); __ cvt_d_w(f2, f14); __ sdc1(f2, MemOperand(a0, offsetof(T, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.a = 1.5e4; t.b = 2.75e8; t.i = 12345678; t.j = -100000; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(12345678.0, t.a); CHECK_EQ(-100000.0, t.b); CHECK_EQ(15000, t.i); CHECK_EQ(275000000, t.j); } TEST(MIPS6) { // Test simple memory loads and stores. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { uint32_t ui; int32_t si; int32_t r1; int32_t r2; int32_t r3; int32_t r4; int32_t r5; int32_t r6; } T; T t; Assembler assm(isolate, NULL, 0); Label L, C; // Basic word load/store. __ lw(a4, MemOperand(a0, offsetof(T, ui)) ); __ sw(a4, MemOperand(a0, offsetof(T, r1)) ); // lh with positive data. __ lh(a5, MemOperand(a0, offsetof(T, ui)) ); __ sw(a5, MemOperand(a0, offsetof(T, r2)) ); // lh with negative data. __ lh(a6, MemOperand(a0, offsetof(T, si)) ); __ sw(a6, MemOperand(a0, offsetof(T, r3)) ); // lhu with negative data. __ lhu(a7, MemOperand(a0, offsetof(T, si)) ); __ sw(a7, MemOperand(a0, offsetof(T, r4)) ); // lb with negative data. __ lb(t0, MemOperand(a0, offsetof(T, si)) ); __ sw(t0, MemOperand(a0, offsetof(T, r5)) ); // sh writes only 1/2 of word. __ lui(t1, 0x3333); __ ori(t1, t1, 0x3333); __ sw(t1, MemOperand(a0, offsetof(T, r6)) ); __ lhu(t1, MemOperand(a0, offsetof(T, si)) ); __ sh(t1, MemOperand(a0, offsetof(T, r6)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.ui = 0x11223344; t.si = 0x99aabbcc; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(static_cast(0x11223344), t.r1); if (kArchEndian == kLittle) { CHECK_EQ(static_cast(0x3344), t.r2); CHECK_EQ(static_cast(0xffffbbcc), t.r3); CHECK_EQ(static_cast(0x0000bbcc), t.r4); CHECK_EQ(static_cast(0xffffffcc), t.r5); CHECK_EQ(static_cast(0x3333bbcc), t.r6); } else { CHECK_EQ(static_cast(0x1122), t.r2); CHECK_EQ(static_cast(0xffff99aa), t.r3); CHECK_EQ(static_cast(0x000099aa), t.r4); CHECK_EQ(static_cast(0xffffff99), t.r5); CHECK_EQ(static_cast(0x99aa3333), t.r6); } } TEST(MIPS7) { // Test floating point compare and branch instructions. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double a; double b; double c; double d; double e; double f; int32_t result; } T; T t; // Create a function that accepts &t, and loads, manipulates, and stores // the doubles t.a ... t.f. MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); Label neither_is_nan, less_than, outa_here; __ ldc1(f4, MemOperand(a0, offsetof(T, a)) ); __ ldc1(f6, MemOperand(a0, offsetof(T, b)) ); if (kArchVariant != kMips64r6) { __ c(UN, D, f4, f6); __ bc1f(&neither_is_nan); } else { __ cmp(UN, L, f2, f4, f6); __ bc1eqz(&neither_is_nan, f2); } __ nop(); __ sw(zero_reg, MemOperand(a0, offsetof(T, result)) ); __ Branch(&outa_here); __ bind(&neither_is_nan); if (kArchVariant == kMips64r6) { __ cmp(OLT, L, f2, f6, f4); __ bc1nez(&less_than, f2); } else { __ c(OLT, D, f6, f4, 2); __ bc1t(&less_than, 2); } __ nop(); __ sw(zero_reg, MemOperand(a0, offsetof(T, result)) ); __ Branch(&outa_here); __ bind(&less_than); __ Addu(a4, zero_reg, Operand(1)); __ sw(a4, MemOperand(a0, offsetof(T, result)) ); // Set true. // This test-case should have additional tests. __ bind(&outa_here); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.a = 1.5e14; t.b = 2.75e11; t.c = 2.0; t.d = -4.0; t.e = 0.0; t.f = 0.0; t.result = 0; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(1.5e14, t.a); CHECK_EQ(2.75e11, t.b); CHECK_EQ(1, t.result); } TEST(MIPS8) { if (kArchVariant == kMips64r2) { // Test ROTR and ROTRV instructions. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { int32_t input; int32_t result_rotr_4; int32_t result_rotr_8; int32_t result_rotr_12; int32_t result_rotr_16; int32_t result_rotr_20; int32_t result_rotr_24; int32_t result_rotr_28; int32_t result_rotrv_4; int32_t result_rotrv_8; int32_t result_rotrv_12; int32_t result_rotrv_16; int32_t result_rotrv_20; int32_t result_rotrv_24; int32_t result_rotrv_28; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); // Basic word load. __ lw(a4, MemOperand(a0, offsetof(T, input)) ); // ROTR instruction (called through the Ror macro). __ Ror(a5, a4, 0x0004); __ Ror(a6, a4, 0x0008); __ Ror(a7, a4, 0x000c); __ Ror(t0, a4, 0x0010); __ Ror(t1, a4, 0x0014); __ Ror(t2, a4, 0x0018); __ Ror(t3, a4, 0x001c); // Basic word store. __ sw(a5, MemOperand(a0, offsetof(T, result_rotr_4)) ); __ sw(a6, MemOperand(a0, offsetof(T, result_rotr_8)) ); __ sw(a7, MemOperand(a0, offsetof(T, result_rotr_12)) ); __ sw(t0, MemOperand(a0, offsetof(T, result_rotr_16)) ); __ sw(t1, MemOperand(a0, offsetof(T, result_rotr_20)) ); __ sw(t2, MemOperand(a0, offsetof(T, result_rotr_24)) ); __ sw(t3, MemOperand(a0, offsetof(T, result_rotr_28)) ); // ROTRV instruction (called through the Ror macro). __ li(t3, 0x0004); __ Ror(a5, a4, t3); __ li(t3, 0x0008); __ Ror(a6, a4, t3); __ li(t3, 0x000C); __ Ror(a7, a4, t3); __ li(t3, 0x0010); __ Ror(t0, a4, t3); __ li(t3, 0x0014); __ Ror(t1, a4, t3); __ li(t3, 0x0018); __ Ror(t2, a4, t3); __ li(t3, 0x001C); __ Ror(t3, a4, t3); // Basic word store. __ sw(a5, MemOperand(a0, offsetof(T, result_rotrv_4)) ); __ sw(a6, MemOperand(a0, offsetof(T, result_rotrv_8)) ); __ sw(a7, MemOperand(a0, offsetof(T, result_rotrv_12)) ); __ sw(t0, MemOperand(a0, offsetof(T, result_rotrv_16)) ); __ sw(t1, MemOperand(a0, offsetof(T, result_rotrv_20)) ); __ sw(t2, MemOperand(a0, offsetof(T, result_rotrv_24)) ); __ sw(t3, MemOperand(a0, offsetof(T, result_rotrv_28)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.input = 0x12345678; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0x0, 0, 0, 0); USE(dummy); CHECK_EQ(static_cast(0x81234567), t.result_rotr_4); CHECK_EQ(static_cast(0x78123456), t.result_rotr_8); CHECK_EQ(static_cast(0x67812345), t.result_rotr_12); CHECK_EQ(static_cast(0x56781234), t.result_rotr_16); CHECK_EQ(static_cast(0x45678123), t.result_rotr_20); CHECK_EQ(static_cast(0x34567812), t.result_rotr_24); CHECK_EQ(static_cast(0x23456781), t.result_rotr_28); CHECK_EQ(static_cast(0x81234567), t.result_rotrv_4); CHECK_EQ(static_cast(0x78123456), t.result_rotrv_8); CHECK_EQ(static_cast(0x67812345), t.result_rotrv_12); CHECK_EQ(static_cast(0x56781234), t.result_rotrv_16); CHECK_EQ(static_cast(0x45678123), t.result_rotrv_20); CHECK_EQ(static_cast(0x34567812), t.result_rotrv_24); CHECK_EQ(static_cast(0x23456781), t.result_rotrv_28); } } TEST(MIPS9) { // Test BRANCH improvements. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); Label exit, exit2, exit3; __ Branch(&exit, ge, a0, Operand(zero_reg)); __ Branch(&exit2, ge, a0, Operand(0x00001FFF)); __ Branch(&exit3, ge, a0, Operand(0x0001FFFF)); __ bind(&exit); __ bind(&exit2); __ bind(&exit3); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); } TEST(MIPS10) { // Test conversions between doubles and long integers. // Test hos the long ints map to FP regs pairs. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double a; double a_converted; double b; int32_t dbl_mant; int32_t dbl_exp; int32_t long_hi; int32_t long_lo; int64_t long_as_int64; int32_t b_long_hi; int32_t b_long_lo; int64_t b_long_as_int64; } T; T t; Assembler assm(isolate, NULL, 0); Label L, C; if (kArchVariant == kMips64r2) { // Rewritten for FR=1 FPU mode: // - 32 FP regs of 64-bits each, no odd/even pairs. // - Note that cvt_l_d/cvt_d_l ARE legal in FR=1 mode. // Load all structure elements to registers. __ ldc1(f0, MemOperand(a0, offsetof(T, a))); // Save the raw bits of the double. __ mfc1(a4, f0); __ mfhc1(a5, f0); __ sw(a4, MemOperand(a0, offsetof(T, dbl_mant))); __ sw(a5, MemOperand(a0, offsetof(T, dbl_exp))); // Convert double in f0 to long, save hi/lo parts. __ cvt_l_d(f0, f0); __ mfc1(a4, f0); // f0 LS 32 bits of long. __ mfhc1(a5, f0); // f0 MS 32 bits of long. __ sw(a4, MemOperand(a0, offsetof(T, long_lo))); __ sw(a5, MemOperand(a0, offsetof(T, long_hi))); // Combine the high/low ints, convert back to double. __ dsll32(a6, a5, 0); // Move a5 to high bits of a6. __ or_(a6, a6, a4); __ dmtc1(a6, f1); __ cvt_d_l(f1, f1); __ sdc1(f1, MemOperand(a0, offsetof(T, a_converted))); // Convert the b long integers to double b. __ lw(a4, MemOperand(a0, offsetof(T, b_long_lo))); __ lw(a5, MemOperand(a0, offsetof(T, b_long_hi))); __ mtc1(a4, f8); // f8 LS 32-bits. __ mthc1(a5, f8); // f8 MS 32-bits. __ cvt_d_l(f10, f8); __ sdc1(f10, MemOperand(a0, offsetof(T, b))); // Convert double b back to long-int. __ ldc1(f31, MemOperand(a0, offsetof(T, b))); __ cvt_l_d(f31, f31); __ dmfc1(a7, f31); __ sd(a7, MemOperand(a0, offsetof(T, b_long_as_int64))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.a = 2.147483647e9; // 0x7fffffff -> 0x41DFFFFFFFC00000 as double. t.b_long_hi = 0x000000ff; // 0xFF00FF00FF -> 0x426FE01FE01FE000 as double. t.b_long_lo = 0x00ff00ff; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(static_cast(0x41DFFFFF), t.dbl_exp); CHECK_EQ(static_cast(0xFFC00000), t.dbl_mant); CHECK_EQ(0, t.long_hi); CHECK_EQ(static_cast(0x7fffffff), t.long_lo); CHECK_EQ(2.147483647e9, t.a_converted); // 0xFF00FF00FF -> 1.095233372415e12. CHECK_EQ(1.095233372415e12, t.b); CHECK_EQ(static_cast(0xFF00FF00FF), t.b_long_as_int64); } } TEST(MIPS11) { // Do not run test on MIPS64r6, as these instructions are removed. if (kArchVariant != kMips64r6) { // Test LWL, LWR, SWL and SWR instructions. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { int32_t reg_init; int32_t mem_init; int32_t lwl_0; int32_t lwl_1; int32_t lwl_2; int32_t lwl_3; int32_t lwr_0; int32_t lwr_1; int32_t lwr_2; int32_t lwr_3; int32_t swl_0; int32_t swl_1; int32_t swl_2; int32_t swl_3; int32_t swr_0; int32_t swr_1; int32_t swr_2; int32_t swr_3; } T; T t; Assembler assm(isolate, NULL, 0); // Test all combinations of LWL and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, lwl_0))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a5, MemOperand(a0, offsetof(T, mem_init) + 1)); __ sw(a5, MemOperand(a0, offsetof(T, lwl_1))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a6, MemOperand(a0, offsetof(T, mem_init) + 2)); __ sw(a6, MemOperand(a0, offsetof(T, lwl_2))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a7, MemOperand(a0, offsetof(T, mem_init) + 3)); __ sw(a7, MemOperand(a0, offsetof(T, lwl_3))); // Test all combinations of LWR and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, lwr_0))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a5, MemOperand(a0, offsetof(T, mem_init) + 1)); __ sw(a5, MemOperand(a0, offsetof(T, lwr_1))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a6, MemOperand(a0, offsetof(T, mem_init) + 2)); __ sw(a6, MemOperand(a0, offsetof(T, lwr_2)) ); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a7, MemOperand(a0, offsetof(T, mem_init) + 3)); __ sw(a7, MemOperand(a0, offsetof(T, lwr_3)) ); // Test all combinations of SWL and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, swl_0))); __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ swl(a4, MemOperand(a0, offsetof(T, swl_0))); __ lw(a5, MemOperand(a0, offsetof(T, mem_init))); __ sw(a5, MemOperand(a0, offsetof(T, swl_1))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ swl(a5, MemOperand(a0, offsetof(T, swl_1) + 1)); __ lw(a6, MemOperand(a0, offsetof(T, mem_init))); __ sw(a6, MemOperand(a0, offsetof(T, swl_2))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ swl(a6, MemOperand(a0, offsetof(T, swl_2) + 2)); __ lw(a7, MemOperand(a0, offsetof(T, mem_init))); __ sw(a7, MemOperand(a0, offsetof(T, swl_3))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ swl(a7, MemOperand(a0, offsetof(T, swl_3) + 3)); // Test all combinations of SWR and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, swr_0))); __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ swr(a4, MemOperand(a0, offsetof(T, swr_0))); __ lw(a5, MemOperand(a0, offsetof(T, mem_init))); __ sw(a5, MemOperand(a0, offsetof(T, swr_1))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ swr(a5, MemOperand(a0, offsetof(T, swr_1) + 1)); __ lw(a6, MemOperand(a0, offsetof(T, mem_init))); __ sw(a6, MemOperand(a0, offsetof(T, swr_2))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ swr(a6, MemOperand(a0, offsetof(T, swr_2) + 2)); __ lw(a7, MemOperand(a0, offsetof(T, mem_init))); __ sw(a7, MemOperand(a0, offsetof(T, swr_3))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ swr(a7, MemOperand(a0, offsetof(T, swr_3) + 3)); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.reg_init = 0xaabbccdd; t.mem_init = 0x11223344; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); if (kArchEndian == kLittle) { CHECK_EQ(static_cast(0x44bbccdd), t.lwl_0); CHECK_EQ(static_cast(0x3344ccdd), t.lwl_1); CHECK_EQ(static_cast(0x223344dd), t.lwl_2); CHECK_EQ(static_cast(0x11223344), t.lwl_3); CHECK_EQ(static_cast(0x11223344), t.lwr_0); CHECK_EQ(static_cast(0xaa112233), t.lwr_1); CHECK_EQ(static_cast(0xaabb1122), t.lwr_2); CHECK_EQ(static_cast(0xaabbcc11), t.lwr_3); CHECK_EQ(static_cast(0x112233aa), t.swl_0); CHECK_EQ(static_cast(0x1122aabb), t.swl_1); CHECK_EQ(static_cast(0x11aabbcc), t.swl_2); CHECK_EQ(static_cast(0xaabbccdd), t.swl_3); CHECK_EQ(static_cast(0xaabbccdd), t.swr_0); CHECK_EQ(static_cast(0xbbccdd44), t.swr_1); CHECK_EQ(static_cast(0xccdd3344), t.swr_2); CHECK_EQ(static_cast(0xdd223344), t.swr_3); } else { CHECK_EQ(static_cast(0x11223344), t.lwl_0); CHECK_EQ(static_cast(0x223344dd), t.lwl_1); CHECK_EQ(static_cast(0x3344ccdd), t.lwl_2); CHECK_EQ(static_cast(0x44bbccdd), t.lwl_3); CHECK_EQ(static_cast(0xaabbcc11), t.lwr_0); CHECK_EQ(static_cast(0xaabb1122), t.lwr_1); CHECK_EQ(static_cast(0xaa112233), t.lwr_2); CHECK_EQ(static_cast(0x11223344), t.lwr_3); CHECK_EQ(static_cast(0xaabbccdd), t.swl_0); CHECK_EQ(static_cast(0x11aabbcc), t.swl_1); CHECK_EQ(static_cast(0x1122aabb), t.swl_2); CHECK_EQ(static_cast(0x112233aa), t.swl_3); CHECK_EQ(static_cast(0xdd223344), t.swr_0); CHECK_EQ(static_cast(0xccdd3344), t.swr_1); CHECK_EQ(static_cast(0xbbccdd44), t.swr_2); CHECK_EQ(static_cast(0xaabbccdd), t.swr_3); } } } TEST(MIPS12) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { int32_t x; int32_t y; int32_t y1; int32_t y2; int32_t y3; int32_t y4; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ mov(t2, fp); // Save frame pointer. __ mov(fp, a0); // Access struct T by fp. __ lw(a4, MemOperand(a0, offsetof(T, y))); __ lw(a7, MemOperand(a0, offsetof(T, y4))); __ addu(a5, a4, a7); __ subu(t0, a4, a7); __ nop(); __ push(a4); // These instructions disappear after opt. __ Pop(); __ addu(a4, a4, a4); __ nop(); __ Pop(); // These instructions disappear after opt. __ push(a7); __ nop(); __ push(a7); // These instructions disappear after opt. __ pop(a7); __ nop(); __ push(a7); __ pop(t0); __ nop(); __ sw(a4, MemOperand(fp, offsetof(T, y))); __ lw(a4, MemOperand(fp, offsetof(T, y))); __ nop(); __ sw(a4, MemOperand(fp, offsetof(T, y))); __ lw(a5, MemOperand(fp, offsetof(T, y))); __ nop(); __ push(a5); __ lw(a5, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a6); __ nop(); __ push(a6); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a7); __ nop(); __ mov(fp, t2); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.x = 1; t.y = 2; t.y1 = 3; t.y2 = 4; t.y3 = 0XBABA; t.y4 = 0xDEDA; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(3, t.y1); } TEST(MIPS13) { // Test Cvt_d_uw and Trunc_uw_d macros. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double cvt_big_out; double cvt_small_out; uint32_t trunc_big_out; uint32_t trunc_small_out; uint32_t cvt_big_in; uint32_t cvt_small_in; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ sw(a4, MemOperand(a0, offsetof(T, cvt_small_in))); __ Cvt_d_uw(f10, a4); __ sdc1(f10, MemOperand(a0, offsetof(T, cvt_small_out))); __ Trunc_uw_d(f10, f10, f4); __ swc1(f10, MemOperand(a0, offsetof(T, trunc_small_out))); __ sw(a4, MemOperand(a0, offsetof(T, cvt_big_in))); __ Cvt_d_uw(f8, a4); __ sdc1(f8, MemOperand(a0, offsetof(T, cvt_big_out))); __ Trunc_uw_d(f8, f8, f4); __ swc1(f8, MemOperand(a0, offsetof(T, trunc_big_out))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.cvt_big_in = 0xFFFFFFFF; t.cvt_small_in = 333; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(t.cvt_big_out, static_cast(t.cvt_big_in)); CHECK_EQ(t.cvt_small_out, static_cast(t.cvt_small_in)); CHECK_EQ(static_cast(t.trunc_big_out), static_cast(t.cvt_big_in)); CHECK_EQ(static_cast(t.trunc_small_out), static_cast(t.cvt_small_in)); } TEST(MIPS14) { // Test round, floor, ceil, trunc, cvt. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); #define ROUND_STRUCT_ELEMENT(x) \ uint32_t x##_isNaN2008; \ int32_t x##_up_out; \ int32_t x##_down_out; \ int32_t neg_##x##_up_out; \ int32_t neg_##x##_down_out; \ uint32_t x##_err1_out; \ uint32_t x##_err2_out; \ uint32_t x##_err3_out; \ uint32_t x##_err4_out; \ int32_t x##_invalid_result; typedef struct { double round_up_in; double round_down_in; double neg_round_up_in; double neg_round_down_in; double err1_in; double err2_in; double err3_in; double err4_in; ROUND_STRUCT_ELEMENT(round) ROUND_STRUCT_ELEMENT(floor) ROUND_STRUCT_ELEMENT(ceil) ROUND_STRUCT_ELEMENT(trunc) ROUND_STRUCT_ELEMENT(cvt) } T; T t; #undef ROUND_STRUCT_ELEMENT MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); // Save FCSR. __ cfc1(a1, FCSR); // Disable FPU exceptions. __ ctc1(zero_reg, FCSR); #define RUN_ROUND_TEST(x) \ __ cfc1(t0, FCSR);\ __ sw(t0, MemOperand(a0, offsetof(T, x##_isNaN2008))); \ __ ldc1(f0, MemOperand(a0, offsetof(T, round_up_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_up_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, round_down_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_down_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, neg_round_up_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, neg_##x##_up_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, neg_round_down_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, neg_##x##_down_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err1_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err1_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err2_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err2_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err3_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err3_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err4_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err4_out))); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_invalid_result))); RUN_ROUND_TEST(round) RUN_ROUND_TEST(floor) RUN_ROUND_TEST(ceil) RUN_ROUND_TEST(trunc) RUN_ROUND_TEST(cvt) // Restore FCSR. __ ctc1(a1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.round_up_in = 123.51; t.round_down_in = 123.49; t.neg_round_up_in = -123.5; t.neg_round_down_in = -123.49; t.err1_in = 123.51; t.err2_in = 1; t.err3_in = static_cast(1) + 0xFFFFFFFF; t.err4_in = NAN; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); #define GET_FPU_ERR(x) (static_cast(x & kFCSRFlagMask)) #define CHECK_NAN2008(x) (x & kFCSRNaN2008FlagMask) #define CHECK_ROUND_RESULT(type) \ CHECK(GET_FPU_ERR(t.type##_err1_out) & kFCSRInexactFlagMask); \ CHECK_EQ(0, GET_FPU_ERR(t.type##_err2_out)); \ CHECK(GET_FPU_ERR(t.type##_err3_out) & kFCSRInvalidOpFlagMask); \ CHECK(GET_FPU_ERR(t.type##_err4_out) & kFCSRInvalidOpFlagMask); \ if (CHECK_NAN2008(t.type##_isNaN2008) && kArchVariant == kMips64r6) { \ CHECK_EQ(static_cast(0), t.type##_invalid_result);\ } else { \ CHECK_EQ(static_cast(kFPUInvalidResult), t.type##_invalid_result);\ } CHECK_ROUND_RESULT(round); CHECK_ROUND_RESULT(floor); CHECK_ROUND_RESULT(ceil); CHECK_ROUND_RESULT(cvt); } TEST(MIPS15) { // Test chaining of label usages within instructions (issue 1644). CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); Assembler assm(isolate, NULL, 0); Label target; __ beq(v0, v1, &target); __ nop(); __ bne(v0, v1, &target); __ nop(); __ bind(&target); __ nop(); } // ----- mips64 tests ----------------------------------------------- TEST(MIPS16) { // Test 64-bit memory loads and stores. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); struct T { int64_t r1; int64_t r2; int64_t r3; int64_t r4; int64_t r5; int64_t r6; int64_t r7; int64_t r8; int64_t r9; int64_t r10; int64_t r11; int64_t r12; uint32_t ui; int32_t si; }; T t; Assembler assm(isolate, NULL, 0); Label L, C; // Basic 32-bit word load/store, with un-signed data. __ lw(a4, MemOperand(a0, offsetof(T, ui))); __ sw(a4, MemOperand(a0, offsetof(T, r1))); // Check that the data got zero-extended into 64-bit a4. __ sd(a4, MemOperand(a0, offsetof(T, r2))); // Basic 32-bit word load/store, with SIGNED data. __ lw(a5, MemOperand(a0, offsetof(T, si))); __ sw(a5, MemOperand(a0, offsetof(T, r3))); // Check that the data got sign-extended into 64-bit a4. __ sd(a5, MemOperand(a0, offsetof(T, r4))); // 32-bit UNSIGNED word load/store, with SIGNED data. __ lwu(a6, MemOperand(a0, offsetof(T, si))); __ sw(a6, MemOperand(a0, offsetof(T, r5))); // Check that the data got zero-extended into 64-bit a4. __ sd(a6, MemOperand(a0, offsetof(T, r6))); // lh with positive data. __ lh(a5, MemOperand(a0, offsetof(T, ui))); __ sw(a5, MemOperand(a0, offsetof(T, r7))); // lh with negative data. __ lh(a6, MemOperand(a0, offsetof(T, si))); __ sw(a6, MemOperand(a0, offsetof(T, r8))); // lhu with negative data. __ lhu(a7, MemOperand(a0, offsetof(T, si))); __ sw(a7, MemOperand(a0, offsetof(T, r9))); // lb with negative data. __ lb(t0, MemOperand(a0, offsetof(T, si))); __ sw(t0, MemOperand(a0, offsetof(T, r10))); // sh writes only 1/2 of word. __ lw(a4, MemOperand(a0, offsetof(T, ui))); __ sh(a4, MemOperand(a0, offsetof(T, r11))); __ lw(a4, MemOperand(a0, offsetof(T, si))); __ sh(a4, MemOperand(a0, offsetof(T, r12))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.ui = 0x44332211; t.si = 0x99aabbcc; t.r1 = 0x5555555555555555; t.r2 = 0x5555555555555555; t.r3 = 0x5555555555555555; t.r4 = 0x5555555555555555; t.r5 = 0x5555555555555555; t.r6 = 0x5555555555555555; t.r7 = 0x5555555555555555; t.r8 = 0x5555555555555555; t.r9 = 0x5555555555555555; t.r10 = 0x5555555555555555; t.r11 = 0x5555555555555555; t.r12 = 0x5555555555555555; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); if (kArchEndian == kLittle) { // Unsigned data, 32 & 64 CHECK_EQ(static_cast(0x5555555544332211L), t.r1); // lw, sw. CHECK_EQ(static_cast(0x0000000044332211L), t.r2); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x5555555599aabbccL), t.r3); // lw, sw. CHECK_EQ(static_cast(0xffffffff99aabbccL), t.r4); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x5555555599aabbccL), t.r5); // lwu, sw. CHECK_EQ(static_cast(0x0000000099aabbccL), t.r6); // sd. // lh with unsigned and signed data. CHECK_EQ(static_cast(0x5555555500002211L), t.r7); // lh, sw. CHECK_EQ(static_cast(0x55555555ffffbbccL), t.r8); // lh, sw. // lhu with signed data. CHECK_EQ(static_cast(0x555555550000bbccL), t.r9); // lhu, sw. // lb with signed data. CHECK_EQ(static_cast(0x55555555ffffffccL), t.r10); // lb, sw. // sh with unsigned and signed data. CHECK_EQ(static_cast(0x5555555555552211L), t.r11); // lw, sh. CHECK_EQ(static_cast(0x555555555555bbccL), t.r12); // lw, sh. } else { // Unsigned data, 32 & 64 CHECK_EQ(static_cast(0x4433221155555555L), t.r1); // lw, sw. CHECK_EQ(static_cast(0x0000000044332211L), t.r2); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x99aabbcc55555555L), t.r3); // lw, sw. CHECK_EQ(static_cast(0xffffffff99aabbccL), t.r4); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x99aabbcc55555555L), t.r5); // lwu, sw. CHECK_EQ(static_cast(0x0000000099aabbccL), t.r6); // sd. // lh with unsigned and signed data. CHECK_EQ(static_cast(0x0000443355555555L), t.r7); // lh, sw. CHECK_EQ(static_cast(0xffff99aa55555555L), t.r8); // lh, sw. // lhu with signed data. CHECK_EQ(static_cast(0x000099aa55555555L), t.r9); // lhu, sw. // lb with signed data. CHECK_EQ(static_cast(0xffffff9955555555L), t.r10); // lb, sw. // sh with unsigned and signed data. CHECK_EQ(static_cast(0x2211555555555555L), t.r11); // lw, sh. CHECK_EQ(static_cast(0xbbcc555555555555L), t.r12); // lw, sh. } } // ----------------------mips64r6 specific tests---------------------- TEST(seleqz_selnez) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { int a; int b; int c; int d; double e; double f; double g; double h; float i; float j; float k; float l; } Test; Test test; // Integer part of test. __ addiu(t1, zero_reg, 1); // t1 = 1 __ seleqz(t3, t1, zero_reg); // t3 = 1 __ sw(t3, MemOperand(a0, offsetof(Test, a))); // a = 1 __ seleqz(t2, t1, t1); // t2 = 0 __ sw(t2, MemOperand(a0, offsetof(Test, b))); // b = 0 __ selnez(t3, t1, zero_reg); // t3 = 1; __ sw(t3, MemOperand(a0, offsetof(Test, c))); // c = 0 __ selnez(t3, t1, t1); // t3 = 1 __ sw(t3, MemOperand(a0, offsetof(Test, d))); // d = 1 // Floating point part of test. __ ldc1(f0, MemOperand(a0, offsetof(Test, e)) ); // src __ ldc1(f2, MemOperand(a0, offsetof(Test, f)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, i)) ); // src __ lwc1(f10, MemOperand(a0, offsetof(Test, j)) ); // test __ seleqz_d(f4, f0, f2); __ selnez_d(f6, f0, f2); __ seleqz_s(f12, f8, f10); __ selnez_s(f14, f8, f10); __ sdc1(f4, MemOperand(a0, offsetof(Test, g)) ); // src __ sdc1(f6, MemOperand(a0, offsetof(Test, h)) ); // src __ swc1(f12, MemOperand(a0, offsetof(Test, k)) ); // src __ swc1(f14, MemOperand(a0, offsetof(Test, l)) ); // src __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.a, 1); CHECK_EQ(test.b, 0); CHECK_EQ(test.c, 0); CHECK_EQ(test.d, 1); const int test_size = 3; const int input_size = 5; double inputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double outputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float inputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float outputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.e = inputs_D[i]; test.f = tests_D[j]; test.i = inputs_S[i]; test.j = tests_S[j]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, outputs_D[i]); CHECK_EQ(test.h, 0); CHECK_EQ(test.k, outputs_S[i]); CHECK_EQ(test.l, 0); test.f = tests_D[j+1]; test.j = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, 0); CHECK_EQ(test.h, outputs_D[i]); CHECK_EQ(test.k, 0); CHECK_EQ(test.l, outputs_S[i]); } } } } TEST(min_max) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); struct TestFloat { double a; double b; double c; double d; float e; float f; float g; float h; }; TestFloat test; const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); const int kTableLength = 13; double inputsa[kTableLength] = {2.0, 3.0, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = {3.0, 2.0, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double outputsdmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double outputsdmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputse[kTableLength] = {2.0, 3.0, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsf[kTableLength] = {3.0, 2.0, 3.0, fnan, 0.0, -0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float outputsfmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float outputsfmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a))); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, b))); __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, e))); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, f))); __ min_d(f10, f4, f8); __ max_d(f12, f4, f8); __ min_s(f14, f2, f6); __ max_s(f16, f2, f6); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, c))); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, d))); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, g))); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, h))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 4; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.e = inputse[i]; test.f = inputsf[i]; CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0); CHECK_EQ(0, memcmp(&test.c, &outputsdmin[i], sizeof(test.c))); CHECK_EQ(0, memcmp(&test.d, &outputsdmax[i], sizeof(test.d))); CHECK_EQ(0, memcmp(&test.g, &outputsfmin[i], sizeof(test.g))); CHECK_EQ(0, memcmp(&test.h, &outputsfmax[i], sizeof(test.h))); } } } TEST(rint_d) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; int fcsr; }TestFloat; TestFloat test; double inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E+308, 6.27463370218383111104242366943E-307, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ ctc1(t0, FCSR); __ rint_d(f8, f4); __ sdc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(sel) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { double dd; double ds; double dt; float fd; float fs; float ft; } Test; Test test; __ ldc1(f0, MemOperand(a0, offsetof(Test, dd)) ); // test __ ldc1(f2, MemOperand(a0, offsetof(Test, ds)) ); // src1 __ ldc1(f4, MemOperand(a0, offsetof(Test, dt)) ); // src2 __ lwc1(f6, MemOperand(a0, offsetof(Test, fd)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, fs)) ); // src1 __ lwc1(f10, MemOperand(a0, offsetof(Test, ft)) ); // src2 __ sel_d(f0, f2, f4); __ sel_s(f6, f8, f10); __ sdc1(f0, MemOperand(a0, offsetof(Test, dd)) ); __ swc1(f6, MemOperand(a0, offsetof(Test, fd)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); const int test_size = 3; const int input_size = 5; double inputs_dt[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double inputs_ds[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; float inputs_ft[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float inputs_fs[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.dt = inputs_dt[i]; test.dd = tests_D[j]; test.ds = inputs_ds[i]; test.ft = inputs_ft[i]; test.fd = tests_S[j]; test.fs = inputs_fs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_ds[i]); CHECK_EQ(test.fd, inputs_fs[i]); test.dd = tests_D[j+1]; test.fd = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_dt[i]); CHECK_EQ(test.fd, inputs_ft[i]); } } } } TEST(rint_s) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; int fcsr; }TestFloat; TestFloat test; float inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E+38, 6.27463370218383111104242366943E-37, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; float* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ rint_s(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(mina_maxa) { if (kArchVariant == kMips64r6) { const int kTableLength = 23; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); struct TestFloat { double a; double b; double resd; double resd1; float c; float d; float resf; float resf1; }; TestFloat test; double inputsa[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = { 4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double resd[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double resd1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputsc[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsd[kTableLength] = {4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, fnan, -0.0, 0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float resf[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float resf1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ lwc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ lwc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ mina_d(f6, f2, f4); __ mina_s(f12, f8, f10); __ maxa_d(f14, f2, f4); __ maxa_s(f16, f8, f10); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, resf)) ); __ sdc1(f6, MemOperand(a0, offsetof(TestFloat, resd)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resf1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resd1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.c = inputsc[i]; test.d = inputsd[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if (i < kTableLength - 1) { CHECK_EQ(test.resd, resd[i]); CHECK_EQ(test.resf, resf[i]); CHECK_EQ(test.resd1, resd1[i]); CHECK_EQ(test.resf1, resf1[i]); } else { CHECK(std::isnan(test.resd)); CHECK(std::isnan(test.resf)); CHECK(std::isnan(test.resd1)); CHECK(std::isnan(test.resf1)); } } } } // ----------------------mips64r2 specific tests---------------------- TEST(trunc_l) { if (kArchVariant == kMips64r2) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; // a trunc result int64_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_l_d(f8, f4); __ trunc_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } } TEST(movz_movn) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { int64_t rt; double a; double b; double bold; double b1; double bold1; float c; float d; float dold; float d1; float dold1; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ld(t0, MemOperand(a0, offsetof(TestFloat, rt))); __ Move(f12, 0.0); __ Move(f10, 0.0); __ Move(f16, 0.0); __ Move(f14, 0.0); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, bold)) ); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, dold)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, bold1)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, dold1)) ); __ movz_s(f10, f6, t0); __ movz_d(f12, f2, t0); __ movn_s(f14, f6, t0); __ movn_d(f16, f2, t0); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, b)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, d1)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, b1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; test.rt = 1; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, test.bold); CHECK_EQ(test.d, test.dold); CHECK_EQ(test.b1, outputs_D[i]); CHECK_EQ(test.d1, outputs_S[i]); test.rt = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); CHECK_EQ(test.b1, test.bold1); CHECK_EQ(test.d1, test.dold1); } } } TEST(movt_movd) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); typedef struct test_float { double srcd; double dstd; double dstdold; double dstd1; double dstdold1; float srcf; float dstf; float dstfold; float dstf1; float dstfold1; int32_t cc; int32_t fcsr; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; double inputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; int condition_flags[8] = {0, 1, 2, 3, 4, 5, 6, 7}; for (int i = 0; i < kTableLength; i++) { test.srcd = inputs_D[i]; test.srcf = inputs_S[i]; for (int j = 0; j< 8; j++) { test.cc = condition_flags[j]; if (test.cc == 0) { test.fcsr = 1 << 23; } else { test.fcsr = 1 << (24+condition_flags[j]); } HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, srcd)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, srcf)) ); __ lw(t1, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t0, FCSR); __ ctc1(t1, FCSR); __ li(t2, 0x0); __ mtc1(t2, f12); __ mtc1(t2, f10); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold)) ); __ movt_s(f12, f4, test.cc); __ movt_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold1)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold1)) ); __ movf_s(f12, f4, test.cc); __ movf_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf1)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd1)) ); __ ctc1(t0, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, outputs_S[i]); CHECK_EQ(test.dstd, outputs_D[i]); CHECK_EQ(test.dstf1, test.dstfold1); CHECK_EQ(test.dstd1, test.dstdold1); test.fcsr = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, test.dstfold); CHECK_EQ(test.dstd, test.dstdold); CHECK_EQ(test.dstf1, outputs_S[i]); CHECK_EQ(test.dstd1, outputs_D[i]); } } } } // ----------------------tests for all archs-------------------------- TEST(cvt_w_d) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; int32_t b; int fcsr; }Test; const int kTableLength = 24; double inputs[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, 2147483653.0 }; double outputs_RN[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RZ[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RP[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RM[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lw(t0, MemOperand(a0, offsetof(Test, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ cvt_w_d(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(Test, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } TEST(trunc_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_w_d(f8, f4); __ trunc_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_w_d(f8, f4); __ round_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_l_d(f8, f4); __ round_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(sub) { const int kTableLength = 12; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; double inputft_D[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; double outputs_D[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; float inputfs_S[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; float inputft_S[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; float outputs_S[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sub_s(f6, f2, f4); __ sub_d(f12, f8, f10); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(sqrt_rsqrt_recip) { const int kTableLength = 4; const double deltaDouble = 2E-15; const float deltaFloat = 2E-7; const float sqrt2_s = sqrt(2); const double sqrt2_d = sqrt(2); CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; float resultS1; float resultS2; double c; double resultD; double resultD1; double resultD2; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 0.0L, 4.0L, 2.0L, 4e-28L }; double outputs_D[kTableLength] = { 0.0L, 2.0L, sqrt2_d, 2e-14L }; float inputs_S[kTableLength] = { 0.0, 4.0, 2.0, 4e-28 }; float outputs_S[kTableLength] = { 0.0, 2.0, sqrt2_s, 2e-14 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ sqrt_s(f6, f2); __ sqrt_d(f12, f8); __ rsqrt_d(f14, f8); __ rsqrt_s(f16, f2); __ recip_d(f18, f8); __ recip_s(f4, f2); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resultS1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resultD1)) ); __ swc1(f4, MemOperand(a0, offsetof(TestFloat, resultS2)) ); __ sdc1(f18, MemOperand(a0, offsetof(TestFloat, resultD2)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { float f1; double d1; test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); if (i != 0) { f1 = test.resultS1 - 1.0F/outputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD1 - 1.0L/outputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); f1 = test.resultS2 - 1.0F/inputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD2 - 1.0L/inputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); } else { CHECK_EQ(test.resultS1, 1.0F/outputs_S[i]); CHECK_EQ(test.resultD1, 1.0L/outputs_D[i]); CHECK_EQ(test.resultS2, 1.0F/inputs_S[i]); CHECK_EQ(test.resultD2, 1.0L/inputs_D[i]); } } } TEST(neg) { const int kTableLength = 2; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; double c; double resultD; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 4.0, -2.0 }; double outputs_D[kTableLength] = { -4.0, 2.0 }; float inputs_S[kTableLength] = { 4.0, -2.0 }; float outputs_S[kTableLength] = { -4.0, 2.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ neg_s(f6, f2); __ neg_d(f12, f8); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
()); F3 f = FUNCTION_CAST(code->entry()); t.a = 1.5e22; t.b = 2.75e11; t.c = 17.17; t.d = -2.75e11; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(2.75e11, t.a); CHECK_EQ(2.75e11, t.b); CHECK_EQ(1.5e22, t.c); CHECK_EQ(static_cast(0xffffffffc25001d1L), t.high); CHECK_EQ(static_cast(0xffffffffbf800000L), t.low); } TEST(MIPS5) { // Test conversions between doubles and integers. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double a; double b; int i; int j; } T; T t; Assembler assm(isolate, NULL, 0); Label L, C; // Load all structure elements to registers. __ ldc1(f4, MemOperand(a0, offsetof(T, a)) ); __ ldc1(f6, MemOperand(a0, offsetof(T, b)) ); __ lw(a4, MemOperand(a0, offsetof(T, i)) ); __ lw(a5, MemOperand(a0, offsetof(T, j)) ); // Convert double in f4 to int in element i. __ cvt_w_d(f8, f4); __ mfc1(a6, f8); __ sw(a6, MemOperand(a0, offsetof(T, i)) ); // Convert double in f6 to int in element j. __ cvt_w_d(f10, f6); __ mfc1(a7, f10); __ sw(a7, MemOperand(a0, offsetof(T, j)) ); // Convert int in original i (a4) to double in a. __ mtc1(a4, f12); __ cvt_d_w(f0, f12); __ sdc1(f0, MemOperand(a0, offsetof(T, a)) ); // Convert int in original j (a5) to double in b. __ mtc1(a5, f14); __ cvt_d_w(f2, f14); __ sdc1(f2, MemOperand(a0, offsetof(T, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.a = 1.5e4; t.b = 2.75e8; t.i = 12345678; t.j = -100000; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(12345678.0, t.a); CHECK_EQ(-100000.0, t.b); CHECK_EQ(15000, t.i); CHECK_EQ(275000000, t.j); } TEST(MIPS6) { // Test simple memory loads and stores. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { uint32_t ui; int32_t si; int32_t r1; int32_t r2; int32_t r3; int32_t r4; int32_t r5; int32_t r6; } T; T t; Assembler assm(isolate, NULL, 0); Label L, C; // Basic word load/store. __ lw(a4, MemOperand(a0, offsetof(T, ui)) ); __ sw(a4, MemOperand(a0, offsetof(T, r1)) ); // lh with positive data. __ lh(a5, MemOperand(a0, offsetof(T, ui)) ); __ sw(a5, MemOperand(a0, offsetof(T, r2)) ); // lh with negative data. __ lh(a6, MemOperand(a0, offsetof(T, si)) ); __ sw(a6, MemOperand(a0, offsetof(T, r3)) ); // lhu with negative data. __ lhu(a7, MemOperand(a0, offsetof(T, si)) ); __ sw(a7, MemOperand(a0, offsetof(T, r4)) ); // lb with negative data. __ lb(t0, MemOperand(a0, offsetof(T, si)) ); __ sw(t0, MemOperand(a0, offsetof(T, r5)) ); // sh writes only 1/2 of word. __ lui(t1, 0x3333); __ ori(t1, t1, 0x3333); __ sw(t1, MemOperand(a0, offsetof(T, r6)) ); __ lhu(t1, MemOperand(a0, offsetof(T, si)) ); __ sh(t1, MemOperand(a0, offsetof(T, r6)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.ui = 0x11223344; t.si = 0x99aabbcc; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(static_cast(0x11223344), t.r1); if (kArchEndian == kLittle) { CHECK_EQ(static_cast(0x3344), t.r2); CHECK_EQ(static_cast(0xffffbbcc), t.r3); CHECK_EQ(static_cast(0x0000bbcc), t.r4); CHECK_EQ(static_cast(0xffffffcc), t.r5); CHECK_EQ(static_cast(0x3333bbcc), t.r6); } else { CHECK_EQ(static_cast(0x1122), t.r2); CHECK_EQ(static_cast(0xffff99aa), t.r3); CHECK_EQ(static_cast(0x000099aa), t.r4); CHECK_EQ(static_cast(0xffffff99), t.r5); CHECK_EQ(static_cast(0x99aa3333), t.r6); } } TEST(MIPS7) { // Test floating point compare and branch instructions. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double a; double b; double c; double d; double e; double f; int32_t result; } T; T t; // Create a function that accepts &t, and loads, manipulates, and stores // the doubles t.a ... t.f. MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); Label neither_is_nan, less_than, outa_here; __ ldc1(f4, MemOperand(a0, offsetof(T, a)) ); __ ldc1(f6, MemOperand(a0, offsetof(T, b)) ); if (kArchVariant != kMips64r6) { __ c(UN, D, f4, f6); __ bc1f(&neither_is_nan); } else { __ cmp(UN, L, f2, f4, f6); __ bc1eqz(&neither_is_nan, f2); } __ nop(); __ sw(zero_reg, MemOperand(a0, offsetof(T, result)) ); __ Branch(&outa_here); __ bind(&neither_is_nan); if (kArchVariant == kMips64r6) { __ cmp(OLT, L, f2, f6, f4); __ bc1nez(&less_than, f2); } else { __ c(OLT, D, f6, f4, 2); __ bc1t(&less_than, 2); } __ nop(); __ sw(zero_reg, MemOperand(a0, offsetof(T, result)) ); __ Branch(&outa_here); __ bind(&less_than); __ Addu(a4, zero_reg, Operand(1)); __ sw(a4, MemOperand(a0, offsetof(T, result)) ); // Set true. // This test-case should have additional tests. __ bind(&outa_here); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.a = 1.5e14; t.b = 2.75e11; t.c = 2.0; t.d = -4.0; t.e = 0.0; t.f = 0.0; t.result = 0; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(1.5e14, t.a); CHECK_EQ(2.75e11, t.b); CHECK_EQ(1, t.result); } TEST(MIPS8) { if (kArchVariant == kMips64r2) { // Test ROTR and ROTRV instructions. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { int32_t input; int32_t result_rotr_4; int32_t result_rotr_8; int32_t result_rotr_12; int32_t result_rotr_16; int32_t result_rotr_20; int32_t result_rotr_24; int32_t result_rotr_28; int32_t result_rotrv_4; int32_t result_rotrv_8; int32_t result_rotrv_12; int32_t result_rotrv_16; int32_t result_rotrv_20; int32_t result_rotrv_24; int32_t result_rotrv_28; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); // Basic word load. __ lw(a4, MemOperand(a0, offsetof(T, input)) ); // ROTR instruction (called through the Ror macro). __ Ror(a5, a4, 0x0004); __ Ror(a6, a4, 0x0008); __ Ror(a7, a4, 0x000c); __ Ror(t0, a4, 0x0010); __ Ror(t1, a4, 0x0014); __ Ror(t2, a4, 0x0018); __ Ror(t3, a4, 0x001c); // Basic word store. __ sw(a5, MemOperand(a0, offsetof(T, result_rotr_4)) ); __ sw(a6, MemOperand(a0, offsetof(T, result_rotr_8)) ); __ sw(a7, MemOperand(a0, offsetof(T, result_rotr_12)) ); __ sw(t0, MemOperand(a0, offsetof(T, result_rotr_16)) ); __ sw(t1, MemOperand(a0, offsetof(T, result_rotr_20)) ); __ sw(t2, MemOperand(a0, offsetof(T, result_rotr_24)) ); __ sw(t3, MemOperand(a0, offsetof(T, result_rotr_28)) ); // ROTRV instruction (called through the Ror macro). __ li(t3, 0x0004); __ Ror(a5, a4, t3); __ li(t3, 0x0008); __ Ror(a6, a4, t3); __ li(t3, 0x000C); __ Ror(a7, a4, t3); __ li(t3, 0x0010); __ Ror(t0, a4, t3); __ li(t3, 0x0014); __ Ror(t1, a4, t3); __ li(t3, 0x0018); __ Ror(t2, a4, t3); __ li(t3, 0x001C); __ Ror(t3, a4, t3); // Basic word store. __ sw(a5, MemOperand(a0, offsetof(T, result_rotrv_4)) ); __ sw(a6, MemOperand(a0, offsetof(T, result_rotrv_8)) ); __ sw(a7, MemOperand(a0, offsetof(T, result_rotrv_12)) ); __ sw(t0, MemOperand(a0, offsetof(T, result_rotrv_16)) ); __ sw(t1, MemOperand(a0, offsetof(T, result_rotrv_20)) ); __ sw(t2, MemOperand(a0, offsetof(T, result_rotrv_24)) ); __ sw(t3, MemOperand(a0, offsetof(T, result_rotrv_28)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.input = 0x12345678; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0x0, 0, 0, 0); USE(dummy); CHECK_EQ(static_cast(0x81234567), t.result_rotr_4); CHECK_EQ(static_cast(0x78123456), t.result_rotr_8); CHECK_EQ(static_cast(0x67812345), t.result_rotr_12); CHECK_EQ(static_cast(0x56781234), t.result_rotr_16); CHECK_EQ(static_cast(0x45678123), t.result_rotr_20); CHECK_EQ(static_cast(0x34567812), t.result_rotr_24); CHECK_EQ(static_cast(0x23456781), t.result_rotr_28); CHECK_EQ(static_cast(0x81234567), t.result_rotrv_4); CHECK_EQ(static_cast(0x78123456), t.result_rotrv_8); CHECK_EQ(static_cast(0x67812345), t.result_rotrv_12); CHECK_EQ(static_cast(0x56781234), t.result_rotrv_16); CHECK_EQ(static_cast(0x45678123), t.result_rotrv_20); CHECK_EQ(static_cast(0x34567812), t.result_rotrv_24); CHECK_EQ(static_cast(0x23456781), t.result_rotrv_28); } } TEST(MIPS9) { // Test BRANCH improvements. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); Label exit, exit2, exit3; __ Branch(&exit, ge, a0, Operand(zero_reg)); __ Branch(&exit2, ge, a0, Operand(0x00001FFF)); __ Branch(&exit3, ge, a0, Operand(0x0001FFFF)); __ bind(&exit); __ bind(&exit2); __ bind(&exit3); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); } TEST(MIPS10) { // Test conversions between doubles and long integers. // Test hos the long ints map to FP regs pairs. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double a; double a_converted; double b; int32_t dbl_mant; int32_t dbl_exp; int32_t long_hi; int32_t long_lo; int64_t long_as_int64; int32_t b_long_hi; int32_t b_long_lo; int64_t b_long_as_int64; } T; T t; Assembler assm(isolate, NULL, 0); Label L, C; if (kArchVariant == kMips64r2) { // Rewritten for FR=1 FPU mode: // - 32 FP regs of 64-bits each, no odd/even pairs. // - Note that cvt_l_d/cvt_d_l ARE legal in FR=1 mode. // Load all structure elements to registers. __ ldc1(f0, MemOperand(a0, offsetof(T, a))); // Save the raw bits of the double. __ mfc1(a4, f0); __ mfhc1(a5, f0); __ sw(a4, MemOperand(a0, offsetof(T, dbl_mant))); __ sw(a5, MemOperand(a0, offsetof(T, dbl_exp))); // Convert double in f0 to long, save hi/lo parts. __ cvt_l_d(f0, f0); __ mfc1(a4, f0); // f0 LS 32 bits of long. __ mfhc1(a5, f0); // f0 MS 32 bits of long. __ sw(a4, MemOperand(a0, offsetof(T, long_lo))); __ sw(a5, MemOperand(a0, offsetof(T, long_hi))); // Combine the high/low ints, convert back to double. __ dsll32(a6, a5, 0); // Move a5 to high bits of a6. __ or_(a6, a6, a4); __ dmtc1(a6, f1); __ cvt_d_l(f1, f1); __ sdc1(f1, MemOperand(a0, offsetof(T, a_converted))); // Convert the b long integers to double b. __ lw(a4, MemOperand(a0, offsetof(T, b_long_lo))); __ lw(a5, MemOperand(a0, offsetof(T, b_long_hi))); __ mtc1(a4, f8); // f8 LS 32-bits. __ mthc1(a5, f8); // f8 MS 32-bits. __ cvt_d_l(f10, f8); __ sdc1(f10, MemOperand(a0, offsetof(T, b))); // Convert double b back to long-int. __ ldc1(f31, MemOperand(a0, offsetof(T, b))); __ cvt_l_d(f31, f31); __ dmfc1(a7, f31); __ sd(a7, MemOperand(a0, offsetof(T, b_long_as_int64))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.a = 2.147483647e9; // 0x7fffffff -> 0x41DFFFFFFFC00000 as double. t.b_long_hi = 0x000000ff; // 0xFF00FF00FF -> 0x426FE01FE01FE000 as double. t.b_long_lo = 0x00ff00ff; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(static_cast(0x41DFFFFF), t.dbl_exp); CHECK_EQ(static_cast(0xFFC00000), t.dbl_mant); CHECK_EQ(0, t.long_hi); CHECK_EQ(static_cast(0x7fffffff), t.long_lo); CHECK_EQ(2.147483647e9, t.a_converted); // 0xFF00FF00FF -> 1.095233372415e12. CHECK_EQ(1.095233372415e12, t.b); CHECK_EQ(static_cast(0xFF00FF00FF), t.b_long_as_int64); } } TEST(MIPS11) { // Do not run test on MIPS64r6, as these instructions are removed. if (kArchVariant != kMips64r6) { // Test LWL, LWR, SWL and SWR instructions. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { int32_t reg_init; int32_t mem_init; int32_t lwl_0; int32_t lwl_1; int32_t lwl_2; int32_t lwl_3; int32_t lwr_0; int32_t lwr_1; int32_t lwr_2; int32_t lwr_3; int32_t swl_0; int32_t swl_1; int32_t swl_2; int32_t swl_3; int32_t swr_0; int32_t swr_1; int32_t swr_2; int32_t swr_3; } T; T t; Assembler assm(isolate, NULL, 0); // Test all combinations of LWL and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, lwl_0))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a5, MemOperand(a0, offsetof(T, mem_init) + 1)); __ sw(a5, MemOperand(a0, offsetof(T, lwl_1))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a6, MemOperand(a0, offsetof(T, mem_init) + 2)); __ sw(a6, MemOperand(a0, offsetof(T, lwl_2))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a7, MemOperand(a0, offsetof(T, mem_init) + 3)); __ sw(a7, MemOperand(a0, offsetof(T, lwl_3))); // Test all combinations of LWR and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, lwr_0))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a5, MemOperand(a0, offsetof(T, mem_init) + 1)); __ sw(a5, MemOperand(a0, offsetof(T, lwr_1))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a6, MemOperand(a0, offsetof(T, mem_init) + 2)); __ sw(a6, MemOperand(a0, offsetof(T, lwr_2)) ); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a7, MemOperand(a0, offsetof(T, mem_init) + 3)); __ sw(a7, MemOperand(a0, offsetof(T, lwr_3)) ); // Test all combinations of SWL and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, swl_0))); __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ swl(a4, MemOperand(a0, offsetof(T, swl_0))); __ lw(a5, MemOperand(a0, offsetof(T, mem_init))); __ sw(a5, MemOperand(a0, offsetof(T, swl_1))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ swl(a5, MemOperand(a0, offsetof(T, swl_1) + 1)); __ lw(a6, MemOperand(a0, offsetof(T, mem_init))); __ sw(a6, MemOperand(a0, offsetof(T, swl_2))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ swl(a6, MemOperand(a0, offsetof(T, swl_2) + 2)); __ lw(a7, MemOperand(a0, offsetof(T, mem_init))); __ sw(a7, MemOperand(a0, offsetof(T, swl_3))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ swl(a7, MemOperand(a0, offsetof(T, swl_3) + 3)); // Test all combinations of SWR and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, swr_0))); __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ swr(a4, MemOperand(a0, offsetof(T, swr_0))); __ lw(a5, MemOperand(a0, offsetof(T, mem_init))); __ sw(a5, MemOperand(a0, offsetof(T, swr_1))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ swr(a5, MemOperand(a0, offsetof(T, swr_1) + 1)); __ lw(a6, MemOperand(a0, offsetof(T, mem_init))); __ sw(a6, MemOperand(a0, offsetof(T, swr_2))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ swr(a6, MemOperand(a0, offsetof(T, swr_2) + 2)); __ lw(a7, MemOperand(a0, offsetof(T, mem_init))); __ sw(a7, MemOperand(a0, offsetof(T, swr_3))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ swr(a7, MemOperand(a0, offsetof(T, swr_3) + 3)); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.reg_init = 0xaabbccdd; t.mem_init = 0x11223344; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); if (kArchEndian == kLittle) { CHECK_EQ(static_cast(0x44bbccdd), t.lwl_0); CHECK_EQ(static_cast(0x3344ccdd), t.lwl_1); CHECK_EQ(static_cast(0x223344dd), t.lwl_2); CHECK_EQ(static_cast(0x11223344), t.lwl_3); CHECK_EQ(static_cast(0x11223344), t.lwr_0); CHECK_EQ(static_cast(0xaa112233), t.lwr_1); CHECK_EQ(static_cast(0xaabb1122), t.lwr_2); CHECK_EQ(static_cast(0xaabbcc11), t.lwr_3); CHECK_EQ(static_cast(0x112233aa), t.swl_0); CHECK_EQ(static_cast(0x1122aabb), t.swl_1); CHECK_EQ(static_cast(0x11aabbcc), t.swl_2); CHECK_EQ(static_cast(0xaabbccdd), t.swl_3); CHECK_EQ(static_cast(0xaabbccdd), t.swr_0); CHECK_EQ(static_cast(0xbbccdd44), t.swr_1); CHECK_EQ(static_cast(0xccdd3344), t.swr_2); CHECK_EQ(static_cast(0xdd223344), t.swr_3); } else { CHECK_EQ(static_cast(0x11223344), t.lwl_0); CHECK_EQ(static_cast(0x223344dd), t.lwl_1); CHECK_EQ(static_cast(0x3344ccdd), t.lwl_2); CHECK_EQ(static_cast(0x44bbccdd), t.lwl_3); CHECK_EQ(static_cast(0xaabbcc11), t.lwr_0); CHECK_EQ(static_cast(0xaabb1122), t.lwr_1); CHECK_EQ(static_cast(0xaa112233), t.lwr_2); CHECK_EQ(static_cast(0x11223344), t.lwr_3); CHECK_EQ(static_cast(0xaabbccdd), t.swl_0); CHECK_EQ(static_cast(0x11aabbcc), t.swl_1); CHECK_EQ(static_cast(0x1122aabb), t.swl_2); CHECK_EQ(static_cast(0x112233aa), t.swl_3); CHECK_EQ(static_cast(0xdd223344), t.swr_0); CHECK_EQ(static_cast(0xccdd3344), t.swr_1); CHECK_EQ(static_cast(0xbbccdd44), t.swr_2); CHECK_EQ(static_cast(0xaabbccdd), t.swr_3); } } } TEST(MIPS12) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { int32_t x; int32_t y; int32_t y1; int32_t y2; int32_t y3; int32_t y4; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ mov(t2, fp); // Save frame pointer. __ mov(fp, a0); // Access struct T by fp. __ lw(a4, MemOperand(a0, offsetof(T, y))); __ lw(a7, MemOperand(a0, offsetof(T, y4))); __ addu(a5, a4, a7); __ subu(t0, a4, a7); __ nop(); __ push(a4); // These instructions disappear after opt. __ Pop(); __ addu(a4, a4, a4); __ nop(); __ Pop(); // These instructions disappear after opt. __ push(a7); __ nop(); __ push(a7); // These instructions disappear after opt. __ pop(a7); __ nop(); __ push(a7); __ pop(t0); __ nop(); __ sw(a4, MemOperand(fp, offsetof(T, y))); __ lw(a4, MemOperand(fp, offsetof(T, y))); __ nop(); __ sw(a4, MemOperand(fp, offsetof(T, y))); __ lw(a5, MemOperand(fp, offsetof(T, y))); __ nop(); __ push(a5); __ lw(a5, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a6); __ nop(); __ push(a6); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a7); __ nop(); __ mov(fp, t2); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.x = 1; t.y = 2; t.y1 = 3; t.y2 = 4; t.y3 = 0XBABA; t.y4 = 0xDEDA; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(3, t.y1); } TEST(MIPS13) { // Test Cvt_d_uw and Trunc_uw_d macros. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double cvt_big_out; double cvt_small_out; uint32_t trunc_big_out; uint32_t trunc_small_out; uint32_t cvt_big_in; uint32_t cvt_small_in; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ sw(a4, MemOperand(a0, offsetof(T, cvt_small_in))); __ Cvt_d_uw(f10, a4); __ sdc1(f10, MemOperand(a0, offsetof(T, cvt_small_out))); __ Trunc_uw_d(f10, f10, f4); __ swc1(f10, MemOperand(a0, offsetof(T, trunc_small_out))); __ sw(a4, MemOperand(a0, offsetof(T, cvt_big_in))); __ Cvt_d_uw(f8, a4); __ sdc1(f8, MemOperand(a0, offsetof(T, cvt_big_out))); __ Trunc_uw_d(f8, f8, f4); __ swc1(f8, MemOperand(a0, offsetof(T, trunc_big_out))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.cvt_big_in = 0xFFFFFFFF; t.cvt_small_in = 333; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(t.cvt_big_out, static_cast(t.cvt_big_in)); CHECK_EQ(t.cvt_small_out, static_cast(t.cvt_small_in)); CHECK_EQ(static_cast(t.trunc_big_out), static_cast(t.cvt_big_in)); CHECK_EQ(static_cast(t.trunc_small_out), static_cast(t.cvt_small_in)); } TEST(MIPS14) { // Test round, floor, ceil, trunc, cvt. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); #define ROUND_STRUCT_ELEMENT(x) \ uint32_t x##_isNaN2008; \ int32_t x##_up_out; \ int32_t x##_down_out; \ int32_t neg_##x##_up_out; \ int32_t neg_##x##_down_out; \ uint32_t x##_err1_out; \ uint32_t x##_err2_out; \ uint32_t x##_err3_out; \ uint32_t x##_err4_out; \ int32_t x##_invalid_result; typedef struct { double round_up_in; double round_down_in; double neg_round_up_in; double neg_round_down_in; double err1_in; double err2_in; double err3_in; double err4_in; ROUND_STRUCT_ELEMENT(round) ROUND_STRUCT_ELEMENT(floor) ROUND_STRUCT_ELEMENT(ceil) ROUND_STRUCT_ELEMENT(trunc) ROUND_STRUCT_ELEMENT(cvt) } T; T t; #undef ROUND_STRUCT_ELEMENT MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); // Save FCSR. __ cfc1(a1, FCSR); // Disable FPU exceptions. __ ctc1(zero_reg, FCSR); #define RUN_ROUND_TEST(x) \ __ cfc1(t0, FCSR);\ __ sw(t0, MemOperand(a0, offsetof(T, x##_isNaN2008))); \ __ ldc1(f0, MemOperand(a0, offsetof(T, round_up_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_up_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, round_down_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_down_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, neg_round_up_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, neg_##x##_up_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, neg_round_down_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, neg_##x##_down_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err1_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err1_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err2_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err2_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err3_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err3_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err4_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err4_out))); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_invalid_result))); RUN_ROUND_TEST(round) RUN_ROUND_TEST(floor) RUN_ROUND_TEST(ceil) RUN_ROUND_TEST(trunc) RUN_ROUND_TEST(cvt) // Restore FCSR. __ ctc1(a1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.round_up_in = 123.51; t.round_down_in = 123.49; t.neg_round_up_in = -123.5; t.neg_round_down_in = -123.49; t.err1_in = 123.51; t.err2_in = 1; t.err3_in = static_cast(1) + 0xFFFFFFFF; t.err4_in = NAN; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); #define GET_FPU_ERR(x) (static_cast(x & kFCSRFlagMask)) #define CHECK_NAN2008(x) (x & kFCSRNaN2008FlagMask) #define CHECK_ROUND_RESULT(type) \ CHECK(GET_FPU_ERR(t.type##_err1_out) & kFCSRInexactFlagMask); \ CHECK_EQ(0, GET_FPU_ERR(t.type##_err2_out)); \ CHECK(GET_FPU_ERR(t.type##_err3_out) & kFCSRInvalidOpFlagMask); \ CHECK(GET_FPU_ERR(t.type##_err4_out) & kFCSRInvalidOpFlagMask); \ if (CHECK_NAN2008(t.type##_isNaN2008) && kArchVariant == kMips64r6) { \ CHECK_EQ(static_cast(0), t.type##_invalid_result);\ } else { \ CHECK_EQ(static_cast(kFPUInvalidResult), t.type##_invalid_result);\ } CHECK_ROUND_RESULT(round); CHECK_ROUND_RESULT(floor); CHECK_ROUND_RESULT(ceil); CHECK_ROUND_RESULT(cvt); } TEST(MIPS15) { // Test chaining of label usages within instructions (issue 1644). CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); Assembler assm(isolate, NULL, 0); Label target; __ beq(v0, v1, &target); __ nop(); __ bne(v0, v1, &target); __ nop(); __ bind(&target); __ nop(); } // ----- mips64 tests ----------------------------------------------- TEST(MIPS16) { // Test 64-bit memory loads and stores. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); struct T { int64_t r1; int64_t r2; int64_t r3; int64_t r4; int64_t r5; int64_t r6; int64_t r7; int64_t r8; int64_t r9; int64_t r10; int64_t r11; int64_t r12; uint32_t ui; int32_t si; }; T t; Assembler assm(isolate, NULL, 0); Label L, C; // Basic 32-bit word load/store, with un-signed data. __ lw(a4, MemOperand(a0, offsetof(T, ui))); __ sw(a4, MemOperand(a0, offsetof(T, r1))); // Check that the data got zero-extended into 64-bit a4. __ sd(a4, MemOperand(a0, offsetof(T, r2))); // Basic 32-bit word load/store, with SIGNED data. __ lw(a5, MemOperand(a0, offsetof(T, si))); __ sw(a5, MemOperand(a0, offsetof(T, r3))); // Check that the data got sign-extended into 64-bit a4. __ sd(a5, MemOperand(a0, offsetof(T, r4))); // 32-bit UNSIGNED word load/store, with SIGNED data. __ lwu(a6, MemOperand(a0, offsetof(T, si))); __ sw(a6, MemOperand(a0, offsetof(T, r5))); // Check that the data got zero-extended into 64-bit a4. __ sd(a6, MemOperand(a0, offsetof(T, r6))); // lh with positive data. __ lh(a5, MemOperand(a0, offsetof(T, ui))); __ sw(a5, MemOperand(a0, offsetof(T, r7))); // lh with negative data. __ lh(a6, MemOperand(a0, offsetof(T, si))); __ sw(a6, MemOperand(a0, offsetof(T, r8))); // lhu with negative data. __ lhu(a7, MemOperand(a0, offsetof(T, si))); __ sw(a7, MemOperand(a0, offsetof(T, r9))); // lb with negative data. __ lb(t0, MemOperand(a0, offsetof(T, si))); __ sw(t0, MemOperand(a0, offsetof(T, r10))); // sh writes only 1/2 of word. __ lw(a4, MemOperand(a0, offsetof(T, ui))); __ sh(a4, MemOperand(a0, offsetof(T, r11))); __ lw(a4, MemOperand(a0, offsetof(T, si))); __ sh(a4, MemOperand(a0, offsetof(T, r12))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.ui = 0x44332211; t.si = 0x99aabbcc; t.r1 = 0x5555555555555555; t.r2 = 0x5555555555555555; t.r3 = 0x5555555555555555; t.r4 = 0x5555555555555555; t.r5 = 0x5555555555555555; t.r6 = 0x5555555555555555; t.r7 = 0x5555555555555555; t.r8 = 0x5555555555555555; t.r9 = 0x5555555555555555; t.r10 = 0x5555555555555555; t.r11 = 0x5555555555555555; t.r12 = 0x5555555555555555; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); if (kArchEndian == kLittle) { // Unsigned data, 32 & 64 CHECK_EQ(static_cast(0x5555555544332211L), t.r1); // lw, sw. CHECK_EQ(static_cast(0x0000000044332211L), t.r2); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x5555555599aabbccL), t.r3); // lw, sw. CHECK_EQ(static_cast(0xffffffff99aabbccL), t.r4); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x5555555599aabbccL), t.r5); // lwu, sw. CHECK_EQ(static_cast(0x0000000099aabbccL), t.r6); // sd. // lh with unsigned and signed data. CHECK_EQ(static_cast(0x5555555500002211L), t.r7); // lh, sw. CHECK_EQ(static_cast(0x55555555ffffbbccL), t.r8); // lh, sw. // lhu with signed data. CHECK_EQ(static_cast(0x555555550000bbccL), t.r9); // lhu, sw. // lb with signed data. CHECK_EQ(static_cast(0x55555555ffffffccL), t.r10); // lb, sw. // sh with unsigned and signed data. CHECK_EQ(static_cast(0x5555555555552211L), t.r11); // lw, sh. CHECK_EQ(static_cast(0x555555555555bbccL), t.r12); // lw, sh. } else { // Unsigned data, 32 & 64 CHECK_EQ(static_cast(0x4433221155555555L), t.r1); // lw, sw. CHECK_EQ(static_cast(0x0000000044332211L), t.r2); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x99aabbcc55555555L), t.r3); // lw, sw. CHECK_EQ(static_cast(0xffffffff99aabbccL), t.r4); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x99aabbcc55555555L), t.r5); // lwu, sw. CHECK_EQ(static_cast(0x0000000099aabbccL), t.r6); // sd. // lh with unsigned and signed data. CHECK_EQ(static_cast(0x0000443355555555L), t.r7); // lh, sw. CHECK_EQ(static_cast(0xffff99aa55555555L), t.r8); // lh, sw. // lhu with signed data. CHECK_EQ(static_cast(0x000099aa55555555L), t.r9); // lhu, sw. // lb with signed data. CHECK_EQ(static_cast(0xffffff9955555555L), t.r10); // lb, sw. // sh with unsigned and signed data. CHECK_EQ(static_cast(0x2211555555555555L), t.r11); // lw, sh. CHECK_EQ(static_cast(0xbbcc555555555555L), t.r12); // lw, sh. } } // ----------------------mips64r6 specific tests---------------------- TEST(seleqz_selnez) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { int a; int b; int c; int d; double e; double f; double g; double h; float i; float j; float k; float l; } Test; Test test; // Integer part of test. __ addiu(t1, zero_reg, 1); // t1 = 1 __ seleqz(t3, t1, zero_reg); // t3 = 1 __ sw(t3, MemOperand(a0, offsetof(Test, a))); // a = 1 __ seleqz(t2, t1, t1); // t2 = 0 __ sw(t2, MemOperand(a0, offsetof(Test, b))); // b = 0 __ selnez(t3, t1, zero_reg); // t3 = 1; __ sw(t3, MemOperand(a0, offsetof(Test, c))); // c = 0 __ selnez(t3, t1, t1); // t3 = 1 __ sw(t3, MemOperand(a0, offsetof(Test, d))); // d = 1 // Floating point part of test. __ ldc1(f0, MemOperand(a0, offsetof(Test, e)) ); // src __ ldc1(f2, MemOperand(a0, offsetof(Test, f)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, i)) ); // src __ lwc1(f10, MemOperand(a0, offsetof(Test, j)) ); // test __ seleqz_d(f4, f0, f2); __ selnez_d(f6, f0, f2); __ seleqz_s(f12, f8, f10); __ selnez_s(f14, f8, f10); __ sdc1(f4, MemOperand(a0, offsetof(Test, g)) ); // src __ sdc1(f6, MemOperand(a0, offsetof(Test, h)) ); // src __ swc1(f12, MemOperand(a0, offsetof(Test, k)) ); // src __ swc1(f14, MemOperand(a0, offsetof(Test, l)) ); // src __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.a, 1); CHECK_EQ(test.b, 0); CHECK_EQ(test.c, 0); CHECK_EQ(test.d, 1); const int test_size = 3; const int input_size = 5; double inputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double outputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float inputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float outputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.e = inputs_D[i]; test.f = tests_D[j]; test.i = inputs_S[i]; test.j = tests_S[j]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, outputs_D[i]); CHECK_EQ(test.h, 0); CHECK_EQ(test.k, outputs_S[i]); CHECK_EQ(test.l, 0); test.f = tests_D[j+1]; test.j = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, 0); CHECK_EQ(test.h, outputs_D[i]); CHECK_EQ(test.k, 0); CHECK_EQ(test.l, outputs_S[i]); } } } } TEST(min_max) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); struct TestFloat { double a; double b; double c; double d; float e; float f; float g; float h; }; TestFloat test; const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); const int kTableLength = 13; double inputsa[kTableLength] = {2.0, 3.0, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = {3.0, 2.0, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double outputsdmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double outputsdmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputse[kTableLength] = {2.0, 3.0, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsf[kTableLength] = {3.0, 2.0, 3.0, fnan, 0.0, -0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float outputsfmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float outputsfmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a))); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, b))); __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, e))); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, f))); __ min_d(f10, f4, f8); __ max_d(f12, f4, f8); __ min_s(f14, f2, f6); __ max_s(f16, f2, f6); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, c))); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, d))); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, g))); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, h))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 4; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.e = inputse[i]; test.f = inputsf[i]; CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0); CHECK_EQ(0, memcmp(&test.c, &outputsdmin[i], sizeof(test.c))); CHECK_EQ(0, memcmp(&test.d, &outputsdmax[i], sizeof(test.d))); CHECK_EQ(0, memcmp(&test.g, &outputsfmin[i], sizeof(test.g))); CHECK_EQ(0, memcmp(&test.h, &outputsfmax[i], sizeof(test.h))); } } } TEST(rint_d) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; int fcsr; }TestFloat; TestFloat test; double inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E+308, 6.27463370218383111104242366943E-307, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ ctc1(t0, FCSR); __ rint_d(f8, f4); __ sdc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(sel) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { double dd; double ds; double dt; float fd; float fs; float ft; } Test; Test test; __ ldc1(f0, MemOperand(a0, offsetof(Test, dd)) ); // test __ ldc1(f2, MemOperand(a0, offsetof(Test, ds)) ); // src1 __ ldc1(f4, MemOperand(a0, offsetof(Test, dt)) ); // src2 __ lwc1(f6, MemOperand(a0, offsetof(Test, fd)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, fs)) ); // src1 __ lwc1(f10, MemOperand(a0, offsetof(Test, ft)) ); // src2 __ sel_d(f0, f2, f4); __ sel_s(f6, f8, f10); __ sdc1(f0, MemOperand(a0, offsetof(Test, dd)) ); __ swc1(f6, MemOperand(a0, offsetof(Test, fd)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); const int test_size = 3; const int input_size = 5; double inputs_dt[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double inputs_ds[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; float inputs_ft[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float inputs_fs[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.dt = inputs_dt[i]; test.dd = tests_D[j]; test.ds = inputs_ds[i]; test.ft = inputs_ft[i]; test.fd = tests_S[j]; test.fs = inputs_fs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_ds[i]); CHECK_EQ(test.fd, inputs_fs[i]); test.dd = tests_D[j+1]; test.fd = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_dt[i]); CHECK_EQ(test.fd, inputs_ft[i]); } } } } TEST(rint_s) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; int fcsr; }TestFloat; TestFloat test; float inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E+38, 6.27463370218383111104242366943E-37, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; float* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ rint_s(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(mina_maxa) { if (kArchVariant == kMips64r6) { const int kTableLength = 23; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); struct TestFloat { double a; double b; double resd; double resd1; float c; float d; float resf; float resf1; }; TestFloat test; double inputsa[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = { 4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double resd[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double resd1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputsc[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsd[kTableLength] = {4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, fnan, -0.0, 0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float resf[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float resf1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ lwc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ lwc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ mina_d(f6, f2, f4); __ mina_s(f12, f8, f10); __ maxa_d(f14, f2, f4); __ maxa_s(f16, f8, f10); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, resf)) ); __ sdc1(f6, MemOperand(a0, offsetof(TestFloat, resd)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resf1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resd1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.c = inputsc[i]; test.d = inputsd[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if (i < kTableLength - 1) { CHECK_EQ(test.resd, resd[i]); CHECK_EQ(test.resf, resf[i]); CHECK_EQ(test.resd1, resd1[i]); CHECK_EQ(test.resf1, resf1[i]); } else { CHECK(std::isnan(test.resd)); CHECK(std::isnan(test.resf)); CHECK(std::isnan(test.resd1)); CHECK(std::isnan(test.resf1)); } } } } // ----------------------mips64r2 specific tests---------------------- TEST(trunc_l) { if (kArchVariant == kMips64r2) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; // a trunc result int64_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_l_d(f8, f4); __ trunc_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } } TEST(movz_movn) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { int64_t rt; double a; double b; double bold; double b1; double bold1; float c; float d; float dold; float d1; float dold1; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ld(t0, MemOperand(a0, offsetof(TestFloat, rt))); __ Move(f12, 0.0); __ Move(f10, 0.0); __ Move(f16, 0.0); __ Move(f14, 0.0); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, bold)) ); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, dold)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, bold1)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, dold1)) ); __ movz_s(f10, f6, t0); __ movz_d(f12, f2, t0); __ movn_s(f14, f6, t0); __ movn_d(f16, f2, t0); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, b)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, d1)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, b1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; test.rt = 1; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, test.bold); CHECK_EQ(test.d, test.dold); CHECK_EQ(test.b1, outputs_D[i]); CHECK_EQ(test.d1, outputs_S[i]); test.rt = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); CHECK_EQ(test.b1, test.bold1); CHECK_EQ(test.d1, test.dold1); } } } TEST(movt_movd) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); typedef struct test_float { double srcd; double dstd; double dstdold; double dstd1; double dstdold1; float srcf; float dstf; float dstfold; float dstf1; float dstfold1; int32_t cc; int32_t fcsr; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; double inputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; int condition_flags[8] = {0, 1, 2, 3, 4, 5, 6, 7}; for (int i = 0; i < kTableLength; i++) { test.srcd = inputs_D[i]; test.srcf = inputs_S[i]; for (int j = 0; j< 8; j++) { test.cc = condition_flags[j]; if (test.cc == 0) { test.fcsr = 1 << 23; } else { test.fcsr = 1 << (24+condition_flags[j]); } HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, srcd)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, srcf)) ); __ lw(t1, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t0, FCSR); __ ctc1(t1, FCSR); __ li(t2, 0x0); __ mtc1(t2, f12); __ mtc1(t2, f10); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold)) ); __ movt_s(f12, f4, test.cc); __ movt_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold1)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold1)) ); __ movf_s(f12, f4, test.cc); __ movf_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf1)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd1)) ); __ ctc1(t0, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, outputs_S[i]); CHECK_EQ(test.dstd, outputs_D[i]); CHECK_EQ(test.dstf1, test.dstfold1); CHECK_EQ(test.dstd1, test.dstdold1); test.fcsr = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, test.dstfold); CHECK_EQ(test.dstd, test.dstdold); CHECK_EQ(test.dstf1, outputs_S[i]); CHECK_EQ(test.dstd1, outputs_D[i]); } } } } // ----------------------tests for all archs-------------------------- TEST(cvt_w_d) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; int32_t b; int fcsr; }Test; const int kTableLength = 24; double inputs[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, 2147483653.0 }; double outputs_RN[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RZ[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RP[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RM[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lw(t0, MemOperand(a0, offsetof(Test, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ cvt_w_d(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(Test, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } TEST(trunc_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_w_d(f8, f4); __ trunc_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_w_d(f8, f4); __ round_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_l_d(f8, f4); __ round_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(sub) { const int kTableLength = 12; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; double inputft_D[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; double outputs_D[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; float inputfs_S[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; float inputft_S[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; float outputs_S[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sub_s(f6, f2, f4); __ sub_d(f12, f8, f10); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(sqrt_rsqrt_recip) { const int kTableLength = 4; const double deltaDouble = 2E-15; const float deltaFloat = 2E-7; const float sqrt2_s = sqrt(2); const double sqrt2_d = sqrt(2); CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; float resultS1; float resultS2; double c; double resultD; double resultD1; double resultD2; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 0.0L, 4.0L, 2.0L, 4e-28L }; double outputs_D[kTableLength] = { 0.0L, 2.0L, sqrt2_d, 2e-14L }; float inputs_S[kTableLength] = { 0.0, 4.0, 2.0, 4e-28 }; float outputs_S[kTableLength] = { 0.0, 2.0, sqrt2_s, 2e-14 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ sqrt_s(f6, f2); __ sqrt_d(f12, f8); __ rsqrt_d(f14, f8); __ rsqrt_s(f16, f2); __ recip_d(f18, f8); __ recip_s(f4, f2); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resultS1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resultD1)) ); __ swc1(f4, MemOperand(a0, offsetof(TestFloat, resultS2)) ); __ sdc1(f18, MemOperand(a0, offsetof(TestFloat, resultD2)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { float f1; double d1; test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); if (i != 0) { f1 = test.resultS1 - 1.0F/outputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD1 - 1.0L/outputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); f1 = test.resultS2 - 1.0F/inputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD2 - 1.0L/inputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); } else { CHECK_EQ(test.resultS1, 1.0F/outputs_S[i]); CHECK_EQ(test.resultD1, 1.0L/outputs_D[i]); CHECK_EQ(test.resultS2, 1.0F/inputs_S[i]); CHECK_EQ(test.resultD2, 1.0L/inputs_D[i]); } } } TEST(neg) { const int kTableLength = 2; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; double c; double resultD; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 4.0, -2.0 }; double outputs_D[kTableLength] = { -4.0, 2.0 }; float inputs_S[kTableLength] = { 4.0, -2.0 }; float outputs_S[kTableLength] = { -4.0, 2.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ neg_s(f6, f2); __ neg_d(f12, f8); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.a = 1.5e4; t.b = 2.75e8; t.i = 12345678; t.j = -100000; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(12345678.0, t.a); CHECK_EQ(-100000.0, t.b); CHECK_EQ(15000, t.i); CHECK_EQ(275000000, t.j); } TEST(MIPS6) { // Test simple memory loads and stores. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { uint32_t ui; int32_t si; int32_t r1; int32_t r2; int32_t r3; int32_t r4; int32_t r5; int32_t r6; } T; T t; Assembler assm(isolate, NULL, 0); Label L, C; // Basic word load/store. __ lw(a4, MemOperand(a0, offsetof(T, ui)) ); __ sw(a4, MemOperand(a0, offsetof(T, r1)) ); // lh with positive data. __ lh(a5, MemOperand(a0, offsetof(T, ui)) ); __ sw(a5, MemOperand(a0, offsetof(T, r2)) ); // lh with negative data. __ lh(a6, MemOperand(a0, offsetof(T, si)) ); __ sw(a6, MemOperand(a0, offsetof(T, r3)) ); // lhu with negative data. __ lhu(a7, MemOperand(a0, offsetof(T, si)) ); __ sw(a7, MemOperand(a0, offsetof(T, r4)) ); // lb with negative data. __ lb(t0, MemOperand(a0, offsetof(T, si)) ); __ sw(t0, MemOperand(a0, offsetof(T, r5)) ); // sh writes only 1/2 of word. __ lui(t1, 0x3333); __ ori(t1, t1, 0x3333); __ sw(t1, MemOperand(a0, offsetof(T, r6)) ); __ lhu(t1, MemOperand(a0, offsetof(T, si)) ); __ sh(t1, MemOperand(a0, offsetof(T, r6)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.ui = 0x11223344; t.si = 0x99aabbcc; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(static_cast(0x11223344), t.r1); if (kArchEndian == kLittle) { CHECK_EQ(static_cast(0x3344), t.r2); CHECK_EQ(static_cast(0xffffbbcc), t.r3); CHECK_EQ(static_cast(0x0000bbcc), t.r4); CHECK_EQ(static_cast(0xffffffcc), t.r5); CHECK_EQ(static_cast(0x3333bbcc), t.r6); } else { CHECK_EQ(static_cast(0x1122), t.r2); CHECK_EQ(static_cast(0xffff99aa), t.r3); CHECK_EQ(static_cast(0x000099aa), t.r4); CHECK_EQ(static_cast(0xffffff99), t.r5); CHECK_EQ(static_cast(0x99aa3333), t.r6); } } TEST(MIPS7) { // Test floating point compare and branch instructions. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double a; double b; double c; double d; double e; double f; int32_t result; } T; T t; // Create a function that accepts &t, and loads, manipulates, and stores // the doubles t.a ... t.f. MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); Label neither_is_nan, less_than, outa_here; __ ldc1(f4, MemOperand(a0, offsetof(T, a)) ); __ ldc1(f6, MemOperand(a0, offsetof(T, b)) ); if (kArchVariant != kMips64r6) { __ c(UN, D, f4, f6); __ bc1f(&neither_is_nan); } else { __ cmp(UN, L, f2, f4, f6); __ bc1eqz(&neither_is_nan, f2); } __ nop(); __ sw(zero_reg, MemOperand(a0, offsetof(T, result)) ); __ Branch(&outa_here); __ bind(&neither_is_nan); if (kArchVariant == kMips64r6) { __ cmp(OLT, L, f2, f6, f4); __ bc1nez(&less_than, f2); } else { __ c(OLT, D, f6, f4, 2); __ bc1t(&less_than, 2); } __ nop(); __ sw(zero_reg, MemOperand(a0, offsetof(T, result)) ); __ Branch(&outa_here); __ bind(&less_than); __ Addu(a4, zero_reg, Operand(1)); __ sw(a4, MemOperand(a0, offsetof(T, result)) ); // Set true. // This test-case should have additional tests. __ bind(&outa_here); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.a = 1.5e14; t.b = 2.75e11; t.c = 2.0; t.d = -4.0; t.e = 0.0; t.f = 0.0; t.result = 0; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(1.5e14, t.a); CHECK_EQ(2.75e11, t.b); CHECK_EQ(1, t.result); } TEST(MIPS8) { if (kArchVariant == kMips64r2) { // Test ROTR and ROTRV instructions. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { int32_t input; int32_t result_rotr_4; int32_t result_rotr_8; int32_t result_rotr_12; int32_t result_rotr_16; int32_t result_rotr_20; int32_t result_rotr_24; int32_t result_rotr_28; int32_t result_rotrv_4; int32_t result_rotrv_8; int32_t result_rotrv_12; int32_t result_rotrv_16; int32_t result_rotrv_20; int32_t result_rotrv_24; int32_t result_rotrv_28; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); // Basic word load. __ lw(a4, MemOperand(a0, offsetof(T, input)) ); // ROTR instruction (called through the Ror macro). __ Ror(a5, a4, 0x0004); __ Ror(a6, a4, 0x0008); __ Ror(a7, a4, 0x000c); __ Ror(t0, a4, 0x0010); __ Ror(t1, a4, 0x0014); __ Ror(t2, a4, 0x0018); __ Ror(t3, a4, 0x001c); // Basic word store. __ sw(a5, MemOperand(a0, offsetof(T, result_rotr_4)) ); __ sw(a6, MemOperand(a0, offsetof(T, result_rotr_8)) ); __ sw(a7, MemOperand(a0, offsetof(T, result_rotr_12)) ); __ sw(t0, MemOperand(a0, offsetof(T, result_rotr_16)) ); __ sw(t1, MemOperand(a0, offsetof(T, result_rotr_20)) ); __ sw(t2, MemOperand(a0, offsetof(T, result_rotr_24)) ); __ sw(t3, MemOperand(a0, offsetof(T, result_rotr_28)) ); // ROTRV instruction (called through the Ror macro). __ li(t3, 0x0004); __ Ror(a5, a4, t3); __ li(t3, 0x0008); __ Ror(a6, a4, t3); __ li(t3, 0x000C); __ Ror(a7, a4, t3); __ li(t3, 0x0010); __ Ror(t0, a4, t3); __ li(t3, 0x0014); __ Ror(t1, a4, t3); __ li(t3, 0x0018); __ Ror(t2, a4, t3); __ li(t3, 0x001C); __ Ror(t3, a4, t3); // Basic word store. __ sw(a5, MemOperand(a0, offsetof(T, result_rotrv_4)) ); __ sw(a6, MemOperand(a0, offsetof(T, result_rotrv_8)) ); __ sw(a7, MemOperand(a0, offsetof(T, result_rotrv_12)) ); __ sw(t0, MemOperand(a0, offsetof(T, result_rotrv_16)) ); __ sw(t1, MemOperand(a0, offsetof(T, result_rotrv_20)) ); __ sw(t2, MemOperand(a0, offsetof(T, result_rotrv_24)) ); __ sw(t3, MemOperand(a0, offsetof(T, result_rotrv_28)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.input = 0x12345678; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0x0, 0, 0, 0); USE(dummy); CHECK_EQ(static_cast(0x81234567), t.result_rotr_4); CHECK_EQ(static_cast(0x78123456), t.result_rotr_8); CHECK_EQ(static_cast(0x67812345), t.result_rotr_12); CHECK_EQ(static_cast(0x56781234), t.result_rotr_16); CHECK_EQ(static_cast(0x45678123), t.result_rotr_20); CHECK_EQ(static_cast(0x34567812), t.result_rotr_24); CHECK_EQ(static_cast(0x23456781), t.result_rotr_28); CHECK_EQ(static_cast(0x81234567), t.result_rotrv_4); CHECK_EQ(static_cast(0x78123456), t.result_rotrv_8); CHECK_EQ(static_cast(0x67812345), t.result_rotrv_12); CHECK_EQ(static_cast(0x56781234), t.result_rotrv_16); CHECK_EQ(static_cast(0x45678123), t.result_rotrv_20); CHECK_EQ(static_cast(0x34567812), t.result_rotrv_24); CHECK_EQ(static_cast(0x23456781), t.result_rotrv_28); } } TEST(MIPS9) { // Test BRANCH improvements. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); Label exit, exit2, exit3; __ Branch(&exit, ge, a0, Operand(zero_reg)); __ Branch(&exit2, ge, a0, Operand(0x00001FFF)); __ Branch(&exit3, ge, a0, Operand(0x0001FFFF)); __ bind(&exit); __ bind(&exit2); __ bind(&exit3); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); } TEST(MIPS10) { // Test conversions between doubles and long integers. // Test hos the long ints map to FP regs pairs. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double a; double a_converted; double b; int32_t dbl_mant; int32_t dbl_exp; int32_t long_hi; int32_t long_lo; int64_t long_as_int64; int32_t b_long_hi; int32_t b_long_lo; int64_t b_long_as_int64; } T; T t; Assembler assm(isolate, NULL, 0); Label L, C; if (kArchVariant == kMips64r2) { // Rewritten for FR=1 FPU mode: // - 32 FP regs of 64-bits each, no odd/even pairs. // - Note that cvt_l_d/cvt_d_l ARE legal in FR=1 mode. // Load all structure elements to registers. __ ldc1(f0, MemOperand(a0, offsetof(T, a))); // Save the raw bits of the double. __ mfc1(a4, f0); __ mfhc1(a5, f0); __ sw(a4, MemOperand(a0, offsetof(T, dbl_mant))); __ sw(a5, MemOperand(a0, offsetof(T, dbl_exp))); // Convert double in f0 to long, save hi/lo parts. __ cvt_l_d(f0, f0); __ mfc1(a4, f0); // f0 LS 32 bits of long. __ mfhc1(a5, f0); // f0 MS 32 bits of long. __ sw(a4, MemOperand(a0, offsetof(T, long_lo))); __ sw(a5, MemOperand(a0, offsetof(T, long_hi))); // Combine the high/low ints, convert back to double. __ dsll32(a6, a5, 0); // Move a5 to high bits of a6. __ or_(a6, a6, a4); __ dmtc1(a6, f1); __ cvt_d_l(f1, f1); __ sdc1(f1, MemOperand(a0, offsetof(T, a_converted))); // Convert the b long integers to double b. __ lw(a4, MemOperand(a0, offsetof(T, b_long_lo))); __ lw(a5, MemOperand(a0, offsetof(T, b_long_hi))); __ mtc1(a4, f8); // f8 LS 32-bits. __ mthc1(a5, f8); // f8 MS 32-bits. __ cvt_d_l(f10, f8); __ sdc1(f10, MemOperand(a0, offsetof(T, b))); // Convert double b back to long-int. __ ldc1(f31, MemOperand(a0, offsetof(T, b))); __ cvt_l_d(f31, f31); __ dmfc1(a7, f31); __ sd(a7, MemOperand(a0, offsetof(T, b_long_as_int64))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.a = 2.147483647e9; // 0x7fffffff -> 0x41DFFFFFFFC00000 as double. t.b_long_hi = 0x000000ff; // 0xFF00FF00FF -> 0x426FE01FE01FE000 as double. t.b_long_lo = 0x00ff00ff; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(static_cast(0x41DFFFFF), t.dbl_exp); CHECK_EQ(static_cast(0xFFC00000), t.dbl_mant); CHECK_EQ(0, t.long_hi); CHECK_EQ(static_cast(0x7fffffff), t.long_lo); CHECK_EQ(2.147483647e9, t.a_converted); // 0xFF00FF00FF -> 1.095233372415e12. CHECK_EQ(1.095233372415e12, t.b); CHECK_EQ(static_cast(0xFF00FF00FF), t.b_long_as_int64); } } TEST(MIPS11) { // Do not run test on MIPS64r6, as these instructions are removed. if (kArchVariant != kMips64r6) { // Test LWL, LWR, SWL and SWR instructions. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { int32_t reg_init; int32_t mem_init; int32_t lwl_0; int32_t lwl_1; int32_t lwl_2; int32_t lwl_3; int32_t lwr_0; int32_t lwr_1; int32_t lwr_2; int32_t lwr_3; int32_t swl_0; int32_t swl_1; int32_t swl_2; int32_t swl_3; int32_t swr_0; int32_t swr_1; int32_t swr_2; int32_t swr_3; } T; T t; Assembler assm(isolate, NULL, 0); // Test all combinations of LWL and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, lwl_0))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a5, MemOperand(a0, offsetof(T, mem_init) + 1)); __ sw(a5, MemOperand(a0, offsetof(T, lwl_1))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a6, MemOperand(a0, offsetof(T, mem_init) + 2)); __ sw(a6, MemOperand(a0, offsetof(T, lwl_2))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a7, MemOperand(a0, offsetof(T, mem_init) + 3)); __ sw(a7, MemOperand(a0, offsetof(T, lwl_3))); // Test all combinations of LWR and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, lwr_0))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a5, MemOperand(a0, offsetof(T, mem_init) + 1)); __ sw(a5, MemOperand(a0, offsetof(T, lwr_1))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a6, MemOperand(a0, offsetof(T, mem_init) + 2)); __ sw(a6, MemOperand(a0, offsetof(T, lwr_2)) ); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a7, MemOperand(a0, offsetof(T, mem_init) + 3)); __ sw(a7, MemOperand(a0, offsetof(T, lwr_3)) ); // Test all combinations of SWL and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, swl_0))); __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ swl(a4, MemOperand(a0, offsetof(T, swl_0))); __ lw(a5, MemOperand(a0, offsetof(T, mem_init))); __ sw(a5, MemOperand(a0, offsetof(T, swl_1))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ swl(a5, MemOperand(a0, offsetof(T, swl_1) + 1)); __ lw(a6, MemOperand(a0, offsetof(T, mem_init))); __ sw(a6, MemOperand(a0, offsetof(T, swl_2))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ swl(a6, MemOperand(a0, offsetof(T, swl_2) + 2)); __ lw(a7, MemOperand(a0, offsetof(T, mem_init))); __ sw(a7, MemOperand(a0, offsetof(T, swl_3))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ swl(a7, MemOperand(a0, offsetof(T, swl_3) + 3)); // Test all combinations of SWR and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, swr_0))); __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ swr(a4, MemOperand(a0, offsetof(T, swr_0))); __ lw(a5, MemOperand(a0, offsetof(T, mem_init))); __ sw(a5, MemOperand(a0, offsetof(T, swr_1))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ swr(a5, MemOperand(a0, offsetof(T, swr_1) + 1)); __ lw(a6, MemOperand(a0, offsetof(T, mem_init))); __ sw(a6, MemOperand(a0, offsetof(T, swr_2))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ swr(a6, MemOperand(a0, offsetof(T, swr_2) + 2)); __ lw(a7, MemOperand(a0, offsetof(T, mem_init))); __ sw(a7, MemOperand(a0, offsetof(T, swr_3))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ swr(a7, MemOperand(a0, offsetof(T, swr_3) + 3)); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.reg_init = 0xaabbccdd; t.mem_init = 0x11223344; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); if (kArchEndian == kLittle) { CHECK_EQ(static_cast(0x44bbccdd), t.lwl_0); CHECK_EQ(static_cast(0x3344ccdd), t.lwl_1); CHECK_EQ(static_cast(0x223344dd), t.lwl_2); CHECK_EQ(static_cast(0x11223344), t.lwl_3); CHECK_EQ(static_cast(0x11223344), t.lwr_0); CHECK_EQ(static_cast(0xaa112233), t.lwr_1); CHECK_EQ(static_cast(0xaabb1122), t.lwr_2); CHECK_EQ(static_cast(0xaabbcc11), t.lwr_3); CHECK_EQ(static_cast(0x112233aa), t.swl_0); CHECK_EQ(static_cast(0x1122aabb), t.swl_1); CHECK_EQ(static_cast(0x11aabbcc), t.swl_2); CHECK_EQ(static_cast(0xaabbccdd), t.swl_3); CHECK_EQ(static_cast(0xaabbccdd), t.swr_0); CHECK_EQ(static_cast(0xbbccdd44), t.swr_1); CHECK_EQ(static_cast(0xccdd3344), t.swr_2); CHECK_EQ(static_cast(0xdd223344), t.swr_3); } else { CHECK_EQ(static_cast(0x11223344), t.lwl_0); CHECK_EQ(static_cast(0x223344dd), t.lwl_1); CHECK_EQ(static_cast(0x3344ccdd), t.lwl_2); CHECK_EQ(static_cast(0x44bbccdd), t.lwl_3); CHECK_EQ(static_cast(0xaabbcc11), t.lwr_0); CHECK_EQ(static_cast(0xaabb1122), t.lwr_1); CHECK_EQ(static_cast(0xaa112233), t.lwr_2); CHECK_EQ(static_cast(0x11223344), t.lwr_3); CHECK_EQ(static_cast(0xaabbccdd), t.swl_0); CHECK_EQ(static_cast(0x11aabbcc), t.swl_1); CHECK_EQ(static_cast(0x1122aabb), t.swl_2); CHECK_EQ(static_cast(0x112233aa), t.swl_3); CHECK_EQ(static_cast(0xdd223344), t.swr_0); CHECK_EQ(static_cast(0xccdd3344), t.swr_1); CHECK_EQ(static_cast(0xbbccdd44), t.swr_2); CHECK_EQ(static_cast(0xaabbccdd), t.swr_3); } } } TEST(MIPS12) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { int32_t x; int32_t y; int32_t y1; int32_t y2; int32_t y3; int32_t y4; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ mov(t2, fp); // Save frame pointer. __ mov(fp, a0); // Access struct T by fp. __ lw(a4, MemOperand(a0, offsetof(T, y))); __ lw(a7, MemOperand(a0, offsetof(T, y4))); __ addu(a5, a4, a7); __ subu(t0, a4, a7); __ nop(); __ push(a4); // These instructions disappear after opt. __ Pop(); __ addu(a4, a4, a4); __ nop(); __ Pop(); // These instructions disappear after opt. __ push(a7); __ nop(); __ push(a7); // These instructions disappear after opt. __ pop(a7); __ nop(); __ push(a7); __ pop(t0); __ nop(); __ sw(a4, MemOperand(fp, offsetof(T, y))); __ lw(a4, MemOperand(fp, offsetof(T, y))); __ nop(); __ sw(a4, MemOperand(fp, offsetof(T, y))); __ lw(a5, MemOperand(fp, offsetof(T, y))); __ nop(); __ push(a5); __ lw(a5, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a6); __ nop(); __ push(a6); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a7); __ nop(); __ mov(fp, t2); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.x = 1; t.y = 2; t.y1 = 3; t.y2 = 4; t.y3 = 0XBABA; t.y4 = 0xDEDA; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(3, t.y1); } TEST(MIPS13) { // Test Cvt_d_uw and Trunc_uw_d macros. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double cvt_big_out; double cvt_small_out; uint32_t trunc_big_out; uint32_t trunc_small_out; uint32_t cvt_big_in; uint32_t cvt_small_in; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ sw(a4, MemOperand(a0, offsetof(T, cvt_small_in))); __ Cvt_d_uw(f10, a4); __ sdc1(f10, MemOperand(a0, offsetof(T, cvt_small_out))); __ Trunc_uw_d(f10, f10, f4); __ swc1(f10, MemOperand(a0, offsetof(T, trunc_small_out))); __ sw(a4, MemOperand(a0, offsetof(T, cvt_big_in))); __ Cvt_d_uw(f8, a4); __ sdc1(f8, MemOperand(a0, offsetof(T, cvt_big_out))); __ Trunc_uw_d(f8, f8, f4); __ swc1(f8, MemOperand(a0, offsetof(T, trunc_big_out))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.cvt_big_in = 0xFFFFFFFF; t.cvt_small_in = 333; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(t.cvt_big_out, static_cast(t.cvt_big_in)); CHECK_EQ(t.cvt_small_out, static_cast(t.cvt_small_in)); CHECK_EQ(static_cast(t.trunc_big_out), static_cast(t.cvt_big_in)); CHECK_EQ(static_cast(t.trunc_small_out), static_cast(t.cvt_small_in)); } TEST(MIPS14) { // Test round, floor, ceil, trunc, cvt. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); #define ROUND_STRUCT_ELEMENT(x) \ uint32_t x##_isNaN2008; \ int32_t x##_up_out; \ int32_t x##_down_out; \ int32_t neg_##x##_up_out; \ int32_t neg_##x##_down_out; \ uint32_t x##_err1_out; \ uint32_t x##_err2_out; \ uint32_t x##_err3_out; \ uint32_t x##_err4_out; \ int32_t x##_invalid_result; typedef struct { double round_up_in; double round_down_in; double neg_round_up_in; double neg_round_down_in; double err1_in; double err2_in; double err3_in; double err4_in; ROUND_STRUCT_ELEMENT(round) ROUND_STRUCT_ELEMENT(floor) ROUND_STRUCT_ELEMENT(ceil) ROUND_STRUCT_ELEMENT(trunc) ROUND_STRUCT_ELEMENT(cvt) } T; T t; #undef ROUND_STRUCT_ELEMENT MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); // Save FCSR. __ cfc1(a1, FCSR); // Disable FPU exceptions. __ ctc1(zero_reg, FCSR); #define RUN_ROUND_TEST(x) \ __ cfc1(t0, FCSR);\ __ sw(t0, MemOperand(a0, offsetof(T, x##_isNaN2008))); \ __ ldc1(f0, MemOperand(a0, offsetof(T, round_up_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_up_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, round_down_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_down_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, neg_round_up_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, neg_##x##_up_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, neg_round_down_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, neg_##x##_down_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err1_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err1_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err2_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err2_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err3_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err3_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err4_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err4_out))); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_invalid_result))); RUN_ROUND_TEST(round) RUN_ROUND_TEST(floor) RUN_ROUND_TEST(ceil) RUN_ROUND_TEST(trunc) RUN_ROUND_TEST(cvt) // Restore FCSR. __ ctc1(a1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.round_up_in = 123.51; t.round_down_in = 123.49; t.neg_round_up_in = -123.5; t.neg_round_down_in = -123.49; t.err1_in = 123.51; t.err2_in = 1; t.err3_in = static_cast(1) + 0xFFFFFFFF; t.err4_in = NAN; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); #define GET_FPU_ERR(x) (static_cast(x & kFCSRFlagMask)) #define CHECK_NAN2008(x) (x & kFCSRNaN2008FlagMask) #define CHECK_ROUND_RESULT(type) \ CHECK(GET_FPU_ERR(t.type##_err1_out) & kFCSRInexactFlagMask); \ CHECK_EQ(0, GET_FPU_ERR(t.type##_err2_out)); \ CHECK(GET_FPU_ERR(t.type##_err3_out) & kFCSRInvalidOpFlagMask); \ CHECK(GET_FPU_ERR(t.type##_err4_out) & kFCSRInvalidOpFlagMask); \ if (CHECK_NAN2008(t.type##_isNaN2008) && kArchVariant == kMips64r6) { \ CHECK_EQ(static_cast(0), t.type##_invalid_result);\ } else { \ CHECK_EQ(static_cast(kFPUInvalidResult), t.type##_invalid_result);\ } CHECK_ROUND_RESULT(round); CHECK_ROUND_RESULT(floor); CHECK_ROUND_RESULT(ceil); CHECK_ROUND_RESULT(cvt); } TEST(MIPS15) { // Test chaining of label usages within instructions (issue 1644). CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); Assembler assm(isolate, NULL, 0); Label target; __ beq(v0, v1, &target); __ nop(); __ bne(v0, v1, &target); __ nop(); __ bind(&target); __ nop(); } // ----- mips64 tests ----------------------------------------------- TEST(MIPS16) { // Test 64-bit memory loads and stores. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); struct T { int64_t r1; int64_t r2; int64_t r3; int64_t r4; int64_t r5; int64_t r6; int64_t r7; int64_t r8; int64_t r9; int64_t r10; int64_t r11; int64_t r12; uint32_t ui; int32_t si; }; T t; Assembler assm(isolate, NULL, 0); Label L, C; // Basic 32-bit word load/store, with un-signed data. __ lw(a4, MemOperand(a0, offsetof(T, ui))); __ sw(a4, MemOperand(a0, offsetof(T, r1))); // Check that the data got zero-extended into 64-bit a4. __ sd(a4, MemOperand(a0, offsetof(T, r2))); // Basic 32-bit word load/store, with SIGNED data. __ lw(a5, MemOperand(a0, offsetof(T, si))); __ sw(a5, MemOperand(a0, offsetof(T, r3))); // Check that the data got sign-extended into 64-bit a4. __ sd(a5, MemOperand(a0, offsetof(T, r4))); // 32-bit UNSIGNED word load/store, with SIGNED data. __ lwu(a6, MemOperand(a0, offsetof(T, si))); __ sw(a6, MemOperand(a0, offsetof(T, r5))); // Check that the data got zero-extended into 64-bit a4. __ sd(a6, MemOperand(a0, offsetof(T, r6))); // lh with positive data. __ lh(a5, MemOperand(a0, offsetof(T, ui))); __ sw(a5, MemOperand(a0, offsetof(T, r7))); // lh with negative data. __ lh(a6, MemOperand(a0, offsetof(T, si))); __ sw(a6, MemOperand(a0, offsetof(T, r8))); // lhu with negative data. __ lhu(a7, MemOperand(a0, offsetof(T, si))); __ sw(a7, MemOperand(a0, offsetof(T, r9))); // lb with negative data. __ lb(t0, MemOperand(a0, offsetof(T, si))); __ sw(t0, MemOperand(a0, offsetof(T, r10))); // sh writes only 1/2 of word. __ lw(a4, MemOperand(a0, offsetof(T, ui))); __ sh(a4, MemOperand(a0, offsetof(T, r11))); __ lw(a4, MemOperand(a0, offsetof(T, si))); __ sh(a4, MemOperand(a0, offsetof(T, r12))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.ui = 0x44332211; t.si = 0x99aabbcc; t.r1 = 0x5555555555555555; t.r2 = 0x5555555555555555; t.r3 = 0x5555555555555555; t.r4 = 0x5555555555555555; t.r5 = 0x5555555555555555; t.r6 = 0x5555555555555555; t.r7 = 0x5555555555555555; t.r8 = 0x5555555555555555; t.r9 = 0x5555555555555555; t.r10 = 0x5555555555555555; t.r11 = 0x5555555555555555; t.r12 = 0x5555555555555555; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); if (kArchEndian == kLittle) { // Unsigned data, 32 & 64 CHECK_EQ(static_cast(0x5555555544332211L), t.r1); // lw, sw. CHECK_EQ(static_cast(0x0000000044332211L), t.r2); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x5555555599aabbccL), t.r3); // lw, sw. CHECK_EQ(static_cast(0xffffffff99aabbccL), t.r4); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x5555555599aabbccL), t.r5); // lwu, sw. CHECK_EQ(static_cast(0x0000000099aabbccL), t.r6); // sd. // lh with unsigned and signed data. CHECK_EQ(static_cast(0x5555555500002211L), t.r7); // lh, sw. CHECK_EQ(static_cast(0x55555555ffffbbccL), t.r8); // lh, sw. // lhu with signed data. CHECK_EQ(static_cast(0x555555550000bbccL), t.r9); // lhu, sw. // lb with signed data. CHECK_EQ(static_cast(0x55555555ffffffccL), t.r10); // lb, sw. // sh with unsigned and signed data. CHECK_EQ(static_cast(0x5555555555552211L), t.r11); // lw, sh. CHECK_EQ(static_cast(0x555555555555bbccL), t.r12); // lw, sh. } else { // Unsigned data, 32 & 64 CHECK_EQ(static_cast(0x4433221155555555L), t.r1); // lw, sw. CHECK_EQ(static_cast(0x0000000044332211L), t.r2); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x99aabbcc55555555L), t.r3); // lw, sw. CHECK_EQ(static_cast(0xffffffff99aabbccL), t.r4); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x99aabbcc55555555L), t.r5); // lwu, sw. CHECK_EQ(static_cast(0x0000000099aabbccL), t.r6); // sd. // lh with unsigned and signed data. CHECK_EQ(static_cast(0x0000443355555555L), t.r7); // lh, sw. CHECK_EQ(static_cast(0xffff99aa55555555L), t.r8); // lh, sw. // lhu with signed data. CHECK_EQ(static_cast(0x000099aa55555555L), t.r9); // lhu, sw. // lb with signed data. CHECK_EQ(static_cast(0xffffff9955555555L), t.r10); // lb, sw. // sh with unsigned and signed data. CHECK_EQ(static_cast(0x2211555555555555L), t.r11); // lw, sh. CHECK_EQ(static_cast(0xbbcc555555555555L), t.r12); // lw, sh. } } // ----------------------mips64r6 specific tests---------------------- TEST(seleqz_selnez) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { int a; int b; int c; int d; double e; double f; double g; double h; float i; float j; float k; float l; } Test; Test test; // Integer part of test. __ addiu(t1, zero_reg, 1); // t1 = 1 __ seleqz(t3, t1, zero_reg); // t3 = 1 __ sw(t3, MemOperand(a0, offsetof(Test, a))); // a = 1 __ seleqz(t2, t1, t1); // t2 = 0 __ sw(t2, MemOperand(a0, offsetof(Test, b))); // b = 0 __ selnez(t3, t1, zero_reg); // t3 = 1; __ sw(t3, MemOperand(a0, offsetof(Test, c))); // c = 0 __ selnez(t3, t1, t1); // t3 = 1 __ sw(t3, MemOperand(a0, offsetof(Test, d))); // d = 1 // Floating point part of test. __ ldc1(f0, MemOperand(a0, offsetof(Test, e)) ); // src __ ldc1(f2, MemOperand(a0, offsetof(Test, f)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, i)) ); // src __ lwc1(f10, MemOperand(a0, offsetof(Test, j)) ); // test __ seleqz_d(f4, f0, f2); __ selnez_d(f6, f0, f2); __ seleqz_s(f12, f8, f10); __ selnez_s(f14, f8, f10); __ sdc1(f4, MemOperand(a0, offsetof(Test, g)) ); // src __ sdc1(f6, MemOperand(a0, offsetof(Test, h)) ); // src __ swc1(f12, MemOperand(a0, offsetof(Test, k)) ); // src __ swc1(f14, MemOperand(a0, offsetof(Test, l)) ); // src __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.a, 1); CHECK_EQ(test.b, 0); CHECK_EQ(test.c, 0); CHECK_EQ(test.d, 1); const int test_size = 3; const int input_size = 5; double inputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double outputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float inputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float outputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.e = inputs_D[i]; test.f = tests_D[j]; test.i = inputs_S[i]; test.j = tests_S[j]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, outputs_D[i]); CHECK_EQ(test.h, 0); CHECK_EQ(test.k, outputs_S[i]); CHECK_EQ(test.l, 0); test.f = tests_D[j+1]; test.j = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, 0); CHECK_EQ(test.h, outputs_D[i]); CHECK_EQ(test.k, 0); CHECK_EQ(test.l, outputs_S[i]); } } } } TEST(min_max) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); struct TestFloat { double a; double b; double c; double d; float e; float f; float g; float h; }; TestFloat test; const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); const int kTableLength = 13; double inputsa[kTableLength] = {2.0, 3.0, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = {3.0, 2.0, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double outputsdmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double outputsdmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputse[kTableLength] = {2.0, 3.0, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsf[kTableLength] = {3.0, 2.0, 3.0, fnan, 0.0, -0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float outputsfmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float outputsfmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a))); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, b))); __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, e))); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, f))); __ min_d(f10, f4, f8); __ max_d(f12, f4, f8); __ min_s(f14, f2, f6); __ max_s(f16, f2, f6); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, c))); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, d))); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, g))); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, h))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 4; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.e = inputse[i]; test.f = inputsf[i]; CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0); CHECK_EQ(0, memcmp(&test.c, &outputsdmin[i], sizeof(test.c))); CHECK_EQ(0, memcmp(&test.d, &outputsdmax[i], sizeof(test.d))); CHECK_EQ(0, memcmp(&test.g, &outputsfmin[i], sizeof(test.g))); CHECK_EQ(0, memcmp(&test.h, &outputsfmax[i], sizeof(test.h))); } } } TEST(rint_d) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; int fcsr; }TestFloat; TestFloat test; double inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E+308, 6.27463370218383111104242366943E-307, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ ctc1(t0, FCSR); __ rint_d(f8, f4); __ sdc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(sel) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { double dd; double ds; double dt; float fd; float fs; float ft; } Test; Test test; __ ldc1(f0, MemOperand(a0, offsetof(Test, dd)) ); // test __ ldc1(f2, MemOperand(a0, offsetof(Test, ds)) ); // src1 __ ldc1(f4, MemOperand(a0, offsetof(Test, dt)) ); // src2 __ lwc1(f6, MemOperand(a0, offsetof(Test, fd)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, fs)) ); // src1 __ lwc1(f10, MemOperand(a0, offsetof(Test, ft)) ); // src2 __ sel_d(f0, f2, f4); __ sel_s(f6, f8, f10); __ sdc1(f0, MemOperand(a0, offsetof(Test, dd)) ); __ swc1(f6, MemOperand(a0, offsetof(Test, fd)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); const int test_size = 3; const int input_size = 5; double inputs_dt[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double inputs_ds[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; float inputs_ft[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float inputs_fs[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.dt = inputs_dt[i]; test.dd = tests_D[j]; test.ds = inputs_ds[i]; test.ft = inputs_ft[i]; test.fd = tests_S[j]; test.fs = inputs_fs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_ds[i]); CHECK_EQ(test.fd, inputs_fs[i]); test.dd = tests_D[j+1]; test.fd = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_dt[i]); CHECK_EQ(test.fd, inputs_ft[i]); } } } } TEST(rint_s) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; int fcsr; }TestFloat; TestFloat test; float inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E+38, 6.27463370218383111104242366943E-37, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; float* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ rint_s(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(mina_maxa) { if (kArchVariant == kMips64r6) { const int kTableLength = 23; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); struct TestFloat { double a; double b; double resd; double resd1; float c; float d; float resf; float resf1; }; TestFloat test; double inputsa[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = { 4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double resd[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double resd1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputsc[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsd[kTableLength] = {4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, fnan, -0.0, 0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float resf[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float resf1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ lwc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ lwc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ mina_d(f6, f2, f4); __ mina_s(f12, f8, f10); __ maxa_d(f14, f2, f4); __ maxa_s(f16, f8, f10); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, resf)) ); __ sdc1(f6, MemOperand(a0, offsetof(TestFloat, resd)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resf1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resd1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.c = inputsc[i]; test.d = inputsd[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if (i < kTableLength - 1) { CHECK_EQ(test.resd, resd[i]); CHECK_EQ(test.resf, resf[i]); CHECK_EQ(test.resd1, resd1[i]); CHECK_EQ(test.resf1, resf1[i]); } else { CHECK(std::isnan(test.resd)); CHECK(std::isnan(test.resf)); CHECK(std::isnan(test.resd1)); CHECK(std::isnan(test.resf1)); } } } } // ----------------------mips64r2 specific tests---------------------- TEST(trunc_l) { if (kArchVariant == kMips64r2) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; // a trunc result int64_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_l_d(f8, f4); __ trunc_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } } TEST(movz_movn) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { int64_t rt; double a; double b; double bold; double b1; double bold1; float c; float d; float dold; float d1; float dold1; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ld(t0, MemOperand(a0, offsetof(TestFloat, rt))); __ Move(f12, 0.0); __ Move(f10, 0.0); __ Move(f16, 0.0); __ Move(f14, 0.0); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, bold)) ); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, dold)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, bold1)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, dold1)) ); __ movz_s(f10, f6, t0); __ movz_d(f12, f2, t0); __ movn_s(f14, f6, t0); __ movn_d(f16, f2, t0); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, b)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, d1)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, b1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; test.rt = 1; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, test.bold); CHECK_EQ(test.d, test.dold); CHECK_EQ(test.b1, outputs_D[i]); CHECK_EQ(test.d1, outputs_S[i]); test.rt = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); CHECK_EQ(test.b1, test.bold1); CHECK_EQ(test.d1, test.dold1); } } } TEST(movt_movd) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); typedef struct test_float { double srcd; double dstd; double dstdold; double dstd1; double dstdold1; float srcf; float dstf; float dstfold; float dstf1; float dstfold1; int32_t cc; int32_t fcsr; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; double inputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; int condition_flags[8] = {0, 1, 2, 3, 4, 5, 6, 7}; for (int i = 0; i < kTableLength; i++) { test.srcd = inputs_D[i]; test.srcf = inputs_S[i]; for (int j = 0; j< 8; j++) { test.cc = condition_flags[j]; if (test.cc == 0) { test.fcsr = 1 << 23; } else { test.fcsr = 1 << (24+condition_flags[j]); } HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, srcd)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, srcf)) ); __ lw(t1, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t0, FCSR); __ ctc1(t1, FCSR); __ li(t2, 0x0); __ mtc1(t2, f12); __ mtc1(t2, f10); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold)) ); __ movt_s(f12, f4, test.cc); __ movt_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold1)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold1)) ); __ movf_s(f12, f4, test.cc); __ movf_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf1)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd1)) ); __ ctc1(t0, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, outputs_S[i]); CHECK_EQ(test.dstd, outputs_D[i]); CHECK_EQ(test.dstf1, test.dstfold1); CHECK_EQ(test.dstd1, test.dstdold1); test.fcsr = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, test.dstfold); CHECK_EQ(test.dstd, test.dstdold); CHECK_EQ(test.dstf1, outputs_S[i]); CHECK_EQ(test.dstd1, outputs_D[i]); } } } } // ----------------------tests for all archs-------------------------- TEST(cvt_w_d) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; int32_t b; int fcsr; }Test; const int kTableLength = 24; double inputs[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, 2147483653.0 }; double outputs_RN[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RZ[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RP[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RM[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lw(t0, MemOperand(a0, offsetof(Test, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ cvt_w_d(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(Test, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } TEST(trunc_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_w_d(f8, f4); __ trunc_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_w_d(f8, f4); __ round_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_l_d(f8, f4); __ round_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(sub) { const int kTableLength = 12; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; double inputft_D[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; double outputs_D[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; float inputfs_S[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; float inputft_S[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; float outputs_S[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sub_s(f6, f2, f4); __ sub_d(f12, f8, f10); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(sqrt_rsqrt_recip) { const int kTableLength = 4; const double deltaDouble = 2E-15; const float deltaFloat = 2E-7; const float sqrt2_s = sqrt(2); const double sqrt2_d = sqrt(2); CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; float resultS1; float resultS2; double c; double resultD; double resultD1; double resultD2; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 0.0L, 4.0L, 2.0L, 4e-28L }; double outputs_D[kTableLength] = { 0.0L, 2.0L, sqrt2_d, 2e-14L }; float inputs_S[kTableLength] = { 0.0, 4.0, 2.0, 4e-28 }; float outputs_S[kTableLength] = { 0.0, 2.0, sqrt2_s, 2e-14 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ sqrt_s(f6, f2); __ sqrt_d(f12, f8); __ rsqrt_d(f14, f8); __ rsqrt_s(f16, f2); __ recip_d(f18, f8); __ recip_s(f4, f2); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resultS1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resultD1)) ); __ swc1(f4, MemOperand(a0, offsetof(TestFloat, resultS2)) ); __ sdc1(f18, MemOperand(a0, offsetof(TestFloat, resultD2)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { float f1; double d1; test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); if (i != 0) { f1 = test.resultS1 - 1.0F/outputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD1 - 1.0L/outputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); f1 = test.resultS2 - 1.0F/inputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD2 - 1.0L/inputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); } else { CHECK_EQ(test.resultS1, 1.0F/outputs_S[i]); CHECK_EQ(test.resultD1, 1.0L/outputs_D[i]); CHECK_EQ(test.resultS2, 1.0F/inputs_S[i]); CHECK_EQ(test.resultD2, 1.0L/inputs_D[i]); } } } TEST(neg) { const int kTableLength = 2; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; double c; double resultD; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 4.0, -2.0 }; double outputs_D[kTableLength] = { -4.0, 2.0 }; float inputs_S[kTableLength] = { 4.0, -2.0 }; float outputs_S[kTableLength] = { -4.0, 2.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ neg_s(f6, f2); __ neg_d(f12, f8); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
()); F3 f = FUNCTION_CAST(code->entry()); t.a = 1.5e4; t.b = 2.75e8; t.i = 12345678; t.j = -100000; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(12345678.0, t.a); CHECK_EQ(-100000.0, t.b); CHECK_EQ(15000, t.i); CHECK_EQ(275000000, t.j); } TEST(MIPS6) { // Test simple memory loads and stores. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { uint32_t ui; int32_t si; int32_t r1; int32_t r2; int32_t r3; int32_t r4; int32_t r5; int32_t r6; } T; T t; Assembler assm(isolate, NULL, 0); Label L, C; // Basic word load/store. __ lw(a4, MemOperand(a0, offsetof(T, ui)) ); __ sw(a4, MemOperand(a0, offsetof(T, r1)) ); // lh with positive data. __ lh(a5, MemOperand(a0, offsetof(T, ui)) ); __ sw(a5, MemOperand(a0, offsetof(T, r2)) ); // lh with negative data. __ lh(a6, MemOperand(a0, offsetof(T, si)) ); __ sw(a6, MemOperand(a0, offsetof(T, r3)) ); // lhu with negative data. __ lhu(a7, MemOperand(a0, offsetof(T, si)) ); __ sw(a7, MemOperand(a0, offsetof(T, r4)) ); // lb with negative data. __ lb(t0, MemOperand(a0, offsetof(T, si)) ); __ sw(t0, MemOperand(a0, offsetof(T, r5)) ); // sh writes only 1/2 of word. __ lui(t1, 0x3333); __ ori(t1, t1, 0x3333); __ sw(t1, MemOperand(a0, offsetof(T, r6)) ); __ lhu(t1, MemOperand(a0, offsetof(T, si)) ); __ sh(t1, MemOperand(a0, offsetof(T, r6)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.ui = 0x11223344; t.si = 0x99aabbcc; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(static_cast(0x11223344), t.r1); if (kArchEndian == kLittle) { CHECK_EQ(static_cast(0x3344), t.r2); CHECK_EQ(static_cast(0xffffbbcc), t.r3); CHECK_EQ(static_cast(0x0000bbcc), t.r4); CHECK_EQ(static_cast(0xffffffcc), t.r5); CHECK_EQ(static_cast(0x3333bbcc), t.r6); } else { CHECK_EQ(static_cast(0x1122), t.r2); CHECK_EQ(static_cast(0xffff99aa), t.r3); CHECK_EQ(static_cast(0x000099aa), t.r4); CHECK_EQ(static_cast(0xffffff99), t.r5); CHECK_EQ(static_cast(0x99aa3333), t.r6); } } TEST(MIPS7) { // Test floating point compare and branch instructions. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double a; double b; double c; double d; double e; double f; int32_t result; } T; T t; // Create a function that accepts &t, and loads, manipulates, and stores // the doubles t.a ... t.f. MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); Label neither_is_nan, less_than, outa_here; __ ldc1(f4, MemOperand(a0, offsetof(T, a)) ); __ ldc1(f6, MemOperand(a0, offsetof(T, b)) ); if (kArchVariant != kMips64r6) { __ c(UN, D, f4, f6); __ bc1f(&neither_is_nan); } else { __ cmp(UN, L, f2, f4, f6); __ bc1eqz(&neither_is_nan, f2); } __ nop(); __ sw(zero_reg, MemOperand(a0, offsetof(T, result)) ); __ Branch(&outa_here); __ bind(&neither_is_nan); if (kArchVariant == kMips64r6) { __ cmp(OLT, L, f2, f6, f4); __ bc1nez(&less_than, f2); } else { __ c(OLT, D, f6, f4, 2); __ bc1t(&less_than, 2); } __ nop(); __ sw(zero_reg, MemOperand(a0, offsetof(T, result)) ); __ Branch(&outa_here); __ bind(&less_than); __ Addu(a4, zero_reg, Operand(1)); __ sw(a4, MemOperand(a0, offsetof(T, result)) ); // Set true. // This test-case should have additional tests. __ bind(&outa_here); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.a = 1.5e14; t.b = 2.75e11; t.c = 2.0; t.d = -4.0; t.e = 0.0; t.f = 0.0; t.result = 0; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(1.5e14, t.a); CHECK_EQ(2.75e11, t.b); CHECK_EQ(1, t.result); } TEST(MIPS8) { if (kArchVariant == kMips64r2) { // Test ROTR and ROTRV instructions. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { int32_t input; int32_t result_rotr_4; int32_t result_rotr_8; int32_t result_rotr_12; int32_t result_rotr_16; int32_t result_rotr_20; int32_t result_rotr_24; int32_t result_rotr_28; int32_t result_rotrv_4; int32_t result_rotrv_8; int32_t result_rotrv_12; int32_t result_rotrv_16; int32_t result_rotrv_20; int32_t result_rotrv_24; int32_t result_rotrv_28; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); // Basic word load. __ lw(a4, MemOperand(a0, offsetof(T, input)) ); // ROTR instruction (called through the Ror macro). __ Ror(a5, a4, 0x0004); __ Ror(a6, a4, 0x0008); __ Ror(a7, a4, 0x000c); __ Ror(t0, a4, 0x0010); __ Ror(t1, a4, 0x0014); __ Ror(t2, a4, 0x0018); __ Ror(t3, a4, 0x001c); // Basic word store. __ sw(a5, MemOperand(a0, offsetof(T, result_rotr_4)) ); __ sw(a6, MemOperand(a0, offsetof(T, result_rotr_8)) ); __ sw(a7, MemOperand(a0, offsetof(T, result_rotr_12)) ); __ sw(t0, MemOperand(a0, offsetof(T, result_rotr_16)) ); __ sw(t1, MemOperand(a0, offsetof(T, result_rotr_20)) ); __ sw(t2, MemOperand(a0, offsetof(T, result_rotr_24)) ); __ sw(t3, MemOperand(a0, offsetof(T, result_rotr_28)) ); // ROTRV instruction (called through the Ror macro). __ li(t3, 0x0004); __ Ror(a5, a4, t3); __ li(t3, 0x0008); __ Ror(a6, a4, t3); __ li(t3, 0x000C); __ Ror(a7, a4, t3); __ li(t3, 0x0010); __ Ror(t0, a4, t3); __ li(t3, 0x0014); __ Ror(t1, a4, t3); __ li(t3, 0x0018); __ Ror(t2, a4, t3); __ li(t3, 0x001C); __ Ror(t3, a4, t3); // Basic word store. __ sw(a5, MemOperand(a0, offsetof(T, result_rotrv_4)) ); __ sw(a6, MemOperand(a0, offsetof(T, result_rotrv_8)) ); __ sw(a7, MemOperand(a0, offsetof(T, result_rotrv_12)) ); __ sw(t0, MemOperand(a0, offsetof(T, result_rotrv_16)) ); __ sw(t1, MemOperand(a0, offsetof(T, result_rotrv_20)) ); __ sw(t2, MemOperand(a0, offsetof(T, result_rotrv_24)) ); __ sw(t3, MemOperand(a0, offsetof(T, result_rotrv_28)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.input = 0x12345678; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0x0, 0, 0, 0); USE(dummy); CHECK_EQ(static_cast(0x81234567), t.result_rotr_4); CHECK_EQ(static_cast(0x78123456), t.result_rotr_8); CHECK_EQ(static_cast(0x67812345), t.result_rotr_12); CHECK_EQ(static_cast(0x56781234), t.result_rotr_16); CHECK_EQ(static_cast(0x45678123), t.result_rotr_20); CHECK_EQ(static_cast(0x34567812), t.result_rotr_24); CHECK_EQ(static_cast(0x23456781), t.result_rotr_28); CHECK_EQ(static_cast(0x81234567), t.result_rotrv_4); CHECK_EQ(static_cast(0x78123456), t.result_rotrv_8); CHECK_EQ(static_cast(0x67812345), t.result_rotrv_12); CHECK_EQ(static_cast(0x56781234), t.result_rotrv_16); CHECK_EQ(static_cast(0x45678123), t.result_rotrv_20); CHECK_EQ(static_cast(0x34567812), t.result_rotrv_24); CHECK_EQ(static_cast(0x23456781), t.result_rotrv_28); } } TEST(MIPS9) { // Test BRANCH improvements. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); Label exit, exit2, exit3; __ Branch(&exit, ge, a0, Operand(zero_reg)); __ Branch(&exit2, ge, a0, Operand(0x00001FFF)); __ Branch(&exit3, ge, a0, Operand(0x0001FFFF)); __ bind(&exit); __ bind(&exit2); __ bind(&exit3); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); } TEST(MIPS10) { // Test conversions between doubles and long integers. // Test hos the long ints map to FP regs pairs. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double a; double a_converted; double b; int32_t dbl_mant; int32_t dbl_exp; int32_t long_hi; int32_t long_lo; int64_t long_as_int64; int32_t b_long_hi; int32_t b_long_lo; int64_t b_long_as_int64; } T; T t; Assembler assm(isolate, NULL, 0); Label L, C; if (kArchVariant == kMips64r2) { // Rewritten for FR=1 FPU mode: // - 32 FP regs of 64-bits each, no odd/even pairs. // - Note that cvt_l_d/cvt_d_l ARE legal in FR=1 mode. // Load all structure elements to registers. __ ldc1(f0, MemOperand(a0, offsetof(T, a))); // Save the raw bits of the double. __ mfc1(a4, f0); __ mfhc1(a5, f0); __ sw(a4, MemOperand(a0, offsetof(T, dbl_mant))); __ sw(a5, MemOperand(a0, offsetof(T, dbl_exp))); // Convert double in f0 to long, save hi/lo parts. __ cvt_l_d(f0, f0); __ mfc1(a4, f0); // f0 LS 32 bits of long. __ mfhc1(a5, f0); // f0 MS 32 bits of long. __ sw(a4, MemOperand(a0, offsetof(T, long_lo))); __ sw(a5, MemOperand(a0, offsetof(T, long_hi))); // Combine the high/low ints, convert back to double. __ dsll32(a6, a5, 0); // Move a5 to high bits of a6. __ or_(a6, a6, a4); __ dmtc1(a6, f1); __ cvt_d_l(f1, f1); __ sdc1(f1, MemOperand(a0, offsetof(T, a_converted))); // Convert the b long integers to double b. __ lw(a4, MemOperand(a0, offsetof(T, b_long_lo))); __ lw(a5, MemOperand(a0, offsetof(T, b_long_hi))); __ mtc1(a4, f8); // f8 LS 32-bits. __ mthc1(a5, f8); // f8 MS 32-bits. __ cvt_d_l(f10, f8); __ sdc1(f10, MemOperand(a0, offsetof(T, b))); // Convert double b back to long-int. __ ldc1(f31, MemOperand(a0, offsetof(T, b))); __ cvt_l_d(f31, f31); __ dmfc1(a7, f31); __ sd(a7, MemOperand(a0, offsetof(T, b_long_as_int64))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.a = 2.147483647e9; // 0x7fffffff -> 0x41DFFFFFFFC00000 as double. t.b_long_hi = 0x000000ff; // 0xFF00FF00FF -> 0x426FE01FE01FE000 as double. t.b_long_lo = 0x00ff00ff; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(static_cast(0x41DFFFFF), t.dbl_exp); CHECK_EQ(static_cast(0xFFC00000), t.dbl_mant); CHECK_EQ(0, t.long_hi); CHECK_EQ(static_cast(0x7fffffff), t.long_lo); CHECK_EQ(2.147483647e9, t.a_converted); // 0xFF00FF00FF -> 1.095233372415e12. CHECK_EQ(1.095233372415e12, t.b); CHECK_EQ(static_cast(0xFF00FF00FF), t.b_long_as_int64); } } TEST(MIPS11) { // Do not run test on MIPS64r6, as these instructions are removed. if (kArchVariant != kMips64r6) { // Test LWL, LWR, SWL and SWR instructions. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { int32_t reg_init; int32_t mem_init; int32_t lwl_0; int32_t lwl_1; int32_t lwl_2; int32_t lwl_3; int32_t lwr_0; int32_t lwr_1; int32_t lwr_2; int32_t lwr_3; int32_t swl_0; int32_t swl_1; int32_t swl_2; int32_t swl_3; int32_t swr_0; int32_t swr_1; int32_t swr_2; int32_t swr_3; } T; T t; Assembler assm(isolate, NULL, 0); // Test all combinations of LWL and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, lwl_0))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a5, MemOperand(a0, offsetof(T, mem_init) + 1)); __ sw(a5, MemOperand(a0, offsetof(T, lwl_1))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a6, MemOperand(a0, offsetof(T, mem_init) + 2)); __ sw(a6, MemOperand(a0, offsetof(T, lwl_2))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a7, MemOperand(a0, offsetof(T, mem_init) + 3)); __ sw(a7, MemOperand(a0, offsetof(T, lwl_3))); // Test all combinations of LWR and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, lwr_0))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a5, MemOperand(a0, offsetof(T, mem_init) + 1)); __ sw(a5, MemOperand(a0, offsetof(T, lwr_1))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a6, MemOperand(a0, offsetof(T, mem_init) + 2)); __ sw(a6, MemOperand(a0, offsetof(T, lwr_2)) ); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a7, MemOperand(a0, offsetof(T, mem_init) + 3)); __ sw(a7, MemOperand(a0, offsetof(T, lwr_3)) ); // Test all combinations of SWL and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, swl_0))); __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ swl(a4, MemOperand(a0, offsetof(T, swl_0))); __ lw(a5, MemOperand(a0, offsetof(T, mem_init))); __ sw(a5, MemOperand(a0, offsetof(T, swl_1))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ swl(a5, MemOperand(a0, offsetof(T, swl_1) + 1)); __ lw(a6, MemOperand(a0, offsetof(T, mem_init))); __ sw(a6, MemOperand(a0, offsetof(T, swl_2))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ swl(a6, MemOperand(a0, offsetof(T, swl_2) + 2)); __ lw(a7, MemOperand(a0, offsetof(T, mem_init))); __ sw(a7, MemOperand(a0, offsetof(T, swl_3))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ swl(a7, MemOperand(a0, offsetof(T, swl_3) + 3)); // Test all combinations of SWR and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, swr_0))); __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ swr(a4, MemOperand(a0, offsetof(T, swr_0))); __ lw(a5, MemOperand(a0, offsetof(T, mem_init))); __ sw(a5, MemOperand(a0, offsetof(T, swr_1))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ swr(a5, MemOperand(a0, offsetof(T, swr_1) + 1)); __ lw(a6, MemOperand(a0, offsetof(T, mem_init))); __ sw(a6, MemOperand(a0, offsetof(T, swr_2))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ swr(a6, MemOperand(a0, offsetof(T, swr_2) + 2)); __ lw(a7, MemOperand(a0, offsetof(T, mem_init))); __ sw(a7, MemOperand(a0, offsetof(T, swr_3))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ swr(a7, MemOperand(a0, offsetof(T, swr_3) + 3)); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.reg_init = 0xaabbccdd; t.mem_init = 0x11223344; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); if (kArchEndian == kLittle) { CHECK_EQ(static_cast(0x44bbccdd), t.lwl_0); CHECK_EQ(static_cast(0x3344ccdd), t.lwl_1); CHECK_EQ(static_cast(0x223344dd), t.lwl_2); CHECK_EQ(static_cast(0x11223344), t.lwl_3); CHECK_EQ(static_cast(0x11223344), t.lwr_0); CHECK_EQ(static_cast(0xaa112233), t.lwr_1); CHECK_EQ(static_cast(0xaabb1122), t.lwr_2); CHECK_EQ(static_cast(0xaabbcc11), t.lwr_3); CHECK_EQ(static_cast(0x112233aa), t.swl_0); CHECK_EQ(static_cast(0x1122aabb), t.swl_1); CHECK_EQ(static_cast(0x11aabbcc), t.swl_2); CHECK_EQ(static_cast(0xaabbccdd), t.swl_3); CHECK_EQ(static_cast(0xaabbccdd), t.swr_0); CHECK_EQ(static_cast(0xbbccdd44), t.swr_1); CHECK_EQ(static_cast(0xccdd3344), t.swr_2); CHECK_EQ(static_cast(0xdd223344), t.swr_3); } else { CHECK_EQ(static_cast(0x11223344), t.lwl_0); CHECK_EQ(static_cast(0x223344dd), t.lwl_1); CHECK_EQ(static_cast(0x3344ccdd), t.lwl_2); CHECK_EQ(static_cast(0x44bbccdd), t.lwl_3); CHECK_EQ(static_cast(0xaabbcc11), t.lwr_0); CHECK_EQ(static_cast(0xaabb1122), t.lwr_1); CHECK_EQ(static_cast(0xaa112233), t.lwr_2); CHECK_EQ(static_cast(0x11223344), t.lwr_3); CHECK_EQ(static_cast(0xaabbccdd), t.swl_0); CHECK_EQ(static_cast(0x11aabbcc), t.swl_1); CHECK_EQ(static_cast(0x1122aabb), t.swl_2); CHECK_EQ(static_cast(0x112233aa), t.swl_3); CHECK_EQ(static_cast(0xdd223344), t.swr_0); CHECK_EQ(static_cast(0xccdd3344), t.swr_1); CHECK_EQ(static_cast(0xbbccdd44), t.swr_2); CHECK_EQ(static_cast(0xaabbccdd), t.swr_3); } } } TEST(MIPS12) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { int32_t x; int32_t y; int32_t y1; int32_t y2; int32_t y3; int32_t y4; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ mov(t2, fp); // Save frame pointer. __ mov(fp, a0); // Access struct T by fp. __ lw(a4, MemOperand(a0, offsetof(T, y))); __ lw(a7, MemOperand(a0, offsetof(T, y4))); __ addu(a5, a4, a7); __ subu(t0, a4, a7); __ nop(); __ push(a4); // These instructions disappear after opt. __ Pop(); __ addu(a4, a4, a4); __ nop(); __ Pop(); // These instructions disappear after opt. __ push(a7); __ nop(); __ push(a7); // These instructions disappear after opt. __ pop(a7); __ nop(); __ push(a7); __ pop(t0); __ nop(); __ sw(a4, MemOperand(fp, offsetof(T, y))); __ lw(a4, MemOperand(fp, offsetof(T, y))); __ nop(); __ sw(a4, MemOperand(fp, offsetof(T, y))); __ lw(a5, MemOperand(fp, offsetof(T, y))); __ nop(); __ push(a5); __ lw(a5, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a6); __ nop(); __ push(a6); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a7); __ nop(); __ mov(fp, t2); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.x = 1; t.y = 2; t.y1 = 3; t.y2 = 4; t.y3 = 0XBABA; t.y4 = 0xDEDA; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(3, t.y1); } TEST(MIPS13) { // Test Cvt_d_uw and Trunc_uw_d macros. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double cvt_big_out; double cvt_small_out; uint32_t trunc_big_out; uint32_t trunc_small_out; uint32_t cvt_big_in; uint32_t cvt_small_in; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ sw(a4, MemOperand(a0, offsetof(T, cvt_small_in))); __ Cvt_d_uw(f10, a4); __ sdc1(f10, MemOperand(a0, offsetof(T, cvt_small_out))); __ Trunc_uw_d(f10, f10, f4); __ swc1(f10, MemOperand(a0, offsetof(T, trunc_small_out))); __ sw(a4, MemOperand(a0, offsetof(T, cvt_big_in))); __ Cvt_d_uw(f8, a4); __ sdc1(f8, MemOperand(a0, offsetof(T, cvt_big_out))); __ Trunc_uw_d(f8, f8, f4); __ swc1(f8, MemOperand(a0, offsetof(T, trunc_big_out))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.cvt_big_in = 0xFFFFFFFF; t.cvt_small_in = 333; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(t.cvt_big_out, static_cast(t.cvt_big_in)); CHECK_EQ(t.cvt_small_out, static_cast(t.cvt_small_in)); CHECK_EQ(static_cast(t.trunc_big_out), static_cast(t.cvt_big_in)); CHECK_EQ(static_cast(t.trunc_small_out), static_cast(t.cvt_small_in)); } TEST(MIPS14) { // Test round, floor, ceil, trunc, cvt. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); #define ROUND_STRUCT_ELEMENT(x) \ uint32_t x##_isNaN2008; \ int32_t x##_up_out; \ int32_t x##_down_out; \ int32_t neg_##x##_up_out; \ int32_t neg_##x##_down_out; \ uint32_t x##_err1_out; \ uint32_t x##_err2_out; \ uint32_t x##_err3_out; \ uint32_t x##_err4_out; \ int32_t x##_invalid_result; typedef struct { double round_up_in; double round_down_in; double neg_round_up_in; double neg_round_down_in; double err1_in; double err2_in; double err3_in; double err4_in; ROUND_STRUCT_ELEMENT(round) ROUND_STRUCT_ELEMENT(floor) ROUND_STRUCT_ELEMENT(ceil) ROUND_STRUCT_ELEMENT(trunc) ROUND_STRUCT_ELEMENT(cvt) } T; T t; #undef ROUND_STRUCT_ELEMENT MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); // Save FCSR. __ cfc1(a1, FCSR); // Disable FPU exceptions. __ ctc1(zero_reg, FCSR); #define RUN_ROUND_TEST(x) \ __ cfc1(t0, FCSR);\ __ sw(t0, MemOperand(a0, offsetof(T, x##_isNaN2008))); \ __ ldc1(f0, MemOperand(a0, offsetof(T, round_up_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_up_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, round_down_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_down_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, neg_round_up_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, neg_##x##_up_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, neg_round_down_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, neg_##x##_down_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err1_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err1_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err2_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err2_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err3_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err3_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err4_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err4_out))); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_invalid_result))); RUN_ROUND_TEST(round) RUN_ROUND_TEST(floor) RUN_ROUND_TEST(ceil) RUN_ROUND_TEST(trunc) RUN_ROUND_TEST(cvt) // Restore FCSR. __ ctc1(a1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.round_up_in = 123.51; t.round_down_in = 123.49; t.neg_round_up_in = -123.5; t.neg_round_down_in = -123.49; t.err1_in = 123.51; t.err2_in = 1; t.err3_in = static_cast(1) + 0xFFFFFFFF; t.err4_in = NAN; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); #define GET_FPU_ERR(x) (static_cast(x & kFCSRFlagMask)) #define CHECK_NAN2008(x) (x & kFCSRNaN2008FlagMask) #define CHECK_ROUND_RESULT(type) \ CHECK(GET_FPU_ERR(t.type##_err1_out) & kFCSRInexactFlagMask); \ CHECK_EQ(0, GET_FPU_ERR(t.type##_err2_out)); \ CHECK(GET_FPU_ERR(t.type##_err3_out) & kFCSRInvalidOpFlagMask); \ CHECK(GET_FPU_ERR(t.type##_err4_out) & kFCSRInvalidOpFlagMask); \ if (CHECK_NAN2008(t.type##_isNaN2008) && kArchVariant == kMips64r6) { \ CHECK_EQ(static_cast(0), t.type##_invalid_result);\ } else { \ CHECK_EQ(static_cast(kFPUInvalidResult), t.type##_invalid_result);\ } CHECK_ROUND_RESULT(round); CHECK_ROUND_RESULT(floor); CHECK_ROUND_RESULT(ceil); CHECK_ROUND_RESULT(cvt); } TEST(MIPS15) { // Test chaining of label usages within instructions (issue 1644). CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); Assembler assm(isolate, NULL, 0); Label target; __ beq(v0, v1, &target); __ nop(); __ bne(v0, v1, &target); __ nop(); __ bind(&target); __ nop(); } // ----- mips64 tests ----------------------------------------------- TEST(MIPS16) { // Test 64-bit memory loads and stores. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); struct T { int64_t r1; int64_t r2; int64_t r3; int64_t r4; int64_t r5; int64_t r6; int64_t r7; int64_t r8; int64_t r9; int64_t r10; int64_t r11; int64_t r12; uint32_t ui; int32_t si; }; T t; Assembler assm(isolate, NULL, 0); Label L, C; // Basic 32-bit word load/store, with un-signed data. __ lw(a4, MemOperand(a0, offsetof(T, ui))); __ sw(a4, MemOperand(a0, offsetof(T, r1))); // Check that the data got zero-extended into 64-bit a4. __ sd(a4, MemOperand(a0, offsetof(T, r2))); // Basic 32-bit word load/store, with SIGNED data. __ lw(a5, MemOperand(a0, offsetof(T, si))); __ sw(a5, MemOperand(a0, offsetof(T, r3))); // Check that the data got sign-extended into 64-bit a4. __ sd(a5, MemOperand(a0, offsetof(T, r4))); // 32-bit UNSIGNED word load/store, with SIGNED data. __ lwu(a6, MemOperand(a0, offsetof(T, si))); __ sw(a6, MemOperand(a0, offsetof(T, r5))); // Check that the data got zero-extended into 64-bit a4. __ sd(a6, MemOperand(a0, offsetof(T, r6))); // lh with positive data. __ lh(a5, MemOperand(a0, offsetof(T, ui))); __ sw(a5, MemOperand(a0, offsetof(T, r7))); // lh with negative data. __ lh(a6, MemOperand(a0, offsetof(T, si))); __ sw(a6, MemOperand(a0, offsetof(T, r8))); // lhu with negative data. __ lhu(a7, MemOperand(a0, offsetof(T, si))); __ sw(a7, MemOperand(a0, offsetof(T, r9))); // lb with negative data. __ lb(t0, MemOperand(a0, offsetof(T, si))); __ sw(t0, MemOperand(a0, offsetof(T, r10))); // sh writes only 1/2 of word. __ lw(a4, MemOperand(a0, offsetof(T, ui))); __ sh(a4, MemOperand(a0, offsetof(T, r11))); __ lw(a4, MemOperand(a0, offsetof(T, si))); __ sh(a4, MemOperand(a0, offsetof(T, r12))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.ui = 0x44332211; t.si = 0x99aabbcc; t.r1 = 0x5555555555555555; t.r2 = 0x5555555555555555; t.r3 = 0x5555555555555555; t.r4 = 0x5555555555555555; t.r5 = 0x5555555555555555; t.r6 = 0x5555555555555555; t.r7 = 0x5555555555555555; t.r8 = 0x5555555555555555; t.r9 = 0x5555555555555555; t.r10 = 0x5555555555555555; t.r11 = 0x5555555555555555; t.r12 = 0x5555555555555555; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); if (kArchEndian == kLittle) { // Unsigned data, 32 & 64 CHECK_EQ(static_cast(0x5555555544332211L), t.r1); // lw, sw. CHECK_EQ(static_cast(0x0000000044332211L), t.r2); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x5555555599aabbccL), t.r3); // lw, sw. CHECK_EQ(static_cast(0xffffffff99aabbccL), t.r4); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x5555555599aabbccL), t.r5); // lwu, sw. CHECK_EQ(static_cast(0x0000000099aabbccL), t.r6); // sd. // lh with unsigned and signed data. CHECK_EQ(static_cast(0x5555555500002211L), t.r7); // lh, sw. CHECK_EQ(static_cast(0x55555555ffffbbccL), t.r8); // lh, sw. // lhu with signed data. CHECK_EQ(static_cast(0x555555550000bbccL), t.r9); // lhu, sw. // lb with signed data. CHECK_EQ(static_cast(0x55555555ffffffccL), t.r10); // lb, sw. // sh with unsigned and signed data. CHECK_EQ(static_cast(0x5555555555552211L), t.r11); // lw, sh. CHECK_EQ(static_cast(0x555555555555bbccL), t.r12); // lw, sh. } else { // Unsigned data, 32 & 64 CHECK_EQ(static_cast(0x4433221155555555L), t.r1); // lw, sw. CHECK_EQ(static_cast(0x0000000044332211L), t.r2); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x99aabbcc55555555L), t.r3); // lw, sw. CHECK_EQ(static_cast(0xffffffff99aabbccL), t.r4); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x99aabbcc55555555L), t.r5); // lwu, sw. CHECK_EQ(static_cast(0x0000000099aabbccL), t.r6); // sd. // lh with unsigned and signed data. CHECK_EQ(static_cast(0x0000443355555555L), t.r7); // lh, sw. CHECK_EQ(static_cast(0xffff99aa55555555L), t.r8); // lh, sw. // lhu with signed data. CHECK_EQ(static_cast(0x000099aa55555555L), t.r9); // lhu, sw. // lb with signed data. CHECK_EQ(static_cast(0xffffff9955555555L), t.r10); // lb, sw. // sh with unsigned and signed data. CHECK_EQ(static_cast(0x2211555555555555L), t.r11); // lw, sh. CHECK_EQ(static_cast(0xbbcc555555555555L), t.r12); // lw, sh. } } // ----------------------mips64r6 specific tests---------------------- TEST(seleqz_selnez) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { int a; int b; int c; int d; double e; double f; double g; double h; float i; float j; float k; float l; } Test; Test test; // Integer part of test. __ addiu(t1, zero_reg, 1); // t1 = 1 __ seleqz(t3, t1, zero_reg); // t3 = 1 __ sw(t3, MemOperand(a0, offsetof(Test, a))); // a = 1 __ seleqz(t2, t1, t1); // t2 = 0 __ sw(t2, MemOperand(a0, offsetof(Test, b))); // b = 0 __ selnez(t3, t1, zero_reg); // t3 = 1; __ sw(t3, MemOperand(a0, offsetof(Test, c))); // c = 0 __ selnez(t3, t1, t1); // t3 = 1 __ sw(t3, MemOperand(a0, offsetof(Test, d))); // d = 1 // Floating point part of test. __ ldc1(f0, MemOperand(a0, offsetof(Test, e)) ); // src __ ldc1(f2, MemOperand(a0, offsetof(Test, f)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, i)) ); // src __ lwc1(f10, MemOperand(a0, offsetof(Test, j)) ); // test __ seleqz_d(f4, f0, f2); __ selnez_d(f6, f0, f2); __ seleqz_s(f12, f8, f10); __ selnez_s(f14, f8, f10); __ sdc1(f4, MemOperand(a0, offsetof(Test, g)) ); // src __ sdc1(f6, MemOperand(a0, offsetof(Test, h)) ); // src __ swc1(f12, MemOperand(a0, offsetof(Test, k)) ); // src __ swc1(f14, MemOperand(a0, offsetof(Test, l)) ); // src __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.a, 1); CHECK_EQ(test.b, 0); CHECK_EQ(test.c, 0); CHECK_EQ(test.d, 1); const int test_size = 3; const int input_size = 5; double inputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double outputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float inputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float outputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.e = inputs_D[i]; test.f = tests_D[j]; test.i = inputs_S[i]; test.j = tests_S[j]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, outputs_D[i]); CHECK_EQ(test.h, 0); CHECK_EQ(test.k, outputs_S[i]); CHECK_EQ(test.l, 0); test.f = tests_D[j+1]; test.j = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, 0); CHECK_EQ(test.h, outputs_D[i]); CHECK_EQ(test.k, 0); CHECK_EQ(test.l, outputs_S[i]); } } } } TEST(min_max) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); struct TestFloat { double a; double b; double c; double d; float e; float f; float g; float h; }; TestFloat test; const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); const int kTableLength = 13; double inputsa[kTableLength] = {2.0, 3.0, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = {3.0, 2.0, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double outputsdmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double outputsdmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputse[kTableLength] = {2.0, 3.0, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsf[kTableLength] = {3.0, 2.0, 3.0, fnan, 0.0, -0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float outputsfmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float outputsfmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a))); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, b))); __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, e))); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, f))); __ min_d(f10, f4, f8); __ max_d(f12, f4, f8); __ min_s(f14, f2, f6); __ max_s(f16, f2, f6); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, c))); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, d))); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, g))); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, h))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 4; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.e = inputse[i]; test.f = inputsf[i]; CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0); CHECK_EQ(0, memcmp(&test.c, &outputsdmin[i], sizeof(test.c))); CHECK_EQ(0, memcmp(&test.d, &outputsdmax[i], sizeof(test.d))); CHECK_EQ(0, memcmp(&test.g, &outputsfmin[i], sizeof(test.g))); CHECK_EQ(0, memcmp(&test.h, &outputsfmax[i], sizeof(test.h))); } } } TEST(rint_d) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; int fcsr; }TestFloat; TestFloat test; double inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E+308, 6.27463370218383111104242366943E-307, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ ctc1(t0, FCSR); __ rint_d(f8, f4); __ sdc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(sel) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { double dd; double ds; double dt; float fd; float fs; float ft; } Test; Test test; __ ldc1(f0, MemOperand(a0, offsetof(Test, dd)) ); // test __ ldc1(f2, MemOperand(a0, offsetof(Test, ds)) ); // src1 __ ldc1(f4, MemOperand(a0, offsetof(Test, dt)) ); // src2 __ lwc1(f6, MemOperand(a0, offsetof(Test, fd)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, fs)) ); // src1 __ lwc1(f10, MemOperand(a0, offsetof(Test, ft)) ); // src2 __ sel_d(f0, f2, f4); __ sel_s(f6, f8, f10); __ sdc1(f0, MemOperand(a0, offsetof(Test, dd)) ); __ swc1(f6, MemOperand(a0, offsetof(Test, fd)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); const int test_size = 3; const int input_size = 5; double inputs_dt[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double inputs_ds[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; float inputs_ft[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float inputs_fs[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.dt = inputs_dt[i]; test.dd = tests_D[j]; test.ds = inputs_ds[i]; test.ft = inputs_ft[i]; test.fd = tests_S[j]; test.fs = inputs_fs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_ds[i]); CHECK_EQ(test.fd, inputs_fs[i]); test.dd = tests_D[j+1]; test.fd = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_dt[i]); CHECK_EQ(test.fd, inputs_ft[i]); } } } } TEST(rint_s) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; int fcsr; }TestFloat; TestFloat test; float inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E+38, 6.27463370218383111104242366943E-37, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; float* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ rint_s(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(mina_maxa) { if (kArchVariant == kMips64r6) { const int kTableLength = 23; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); struct TestFloat { double a; double b; double resd; double resd1; float c; float d; float resf; float resf1; }; TestFloat test; double inputsa[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = { 4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double resd[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double resd1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputsc[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsd[kTableLength] = {4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, fnan, -0.0, 0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float resf[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float resf1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ lwc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ lwc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ mina_d(f6, f2, f4); __ mina_s(f12, f8, f10); __ maxa_d(f14, f2, f4); __ maxa_s(f16, f8, f10); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, resf)) ); __ sdc1(f6, MemOperand(a0, offsetof(TestFloat, resd)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resf1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resd1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.c = inputsc[i]; test.d = inputsd[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if (i < kTableLength - 1) { CHECK_EQ(test.resd, resd[i]); CHECK_EQ(test.resf, resf[i]); CHECK_EQ(test.resd1, resd1[i]); CHECK_EQ(test.resf1, resf1[i]); } else { CHECK(std::isnan(test.resd)); CHECK(std::isnan(test.resf)); CHECK(std::isnan(test.resd1)); CHECK(std::isnan(test.resf1)); } } } } // ----------------------mips64r2 specific tests---------------------- TEST(trunc_l) { if (kArchVariant == kMips64r2) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; // a trunc result int64_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_l_d(f8, f4); __ trunc_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } } TEST(movz_movn) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { int64_t rt; double a; double b; double bold; double b1; double bold1; float c; float d; float dold; float d1; float dold1; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ld(t0, MemOperand(a0, offsetof(TestFloat, rt))); __ Move(f12, 0.0); __ Move(f10, 0.0); __ Move(f16, 0.0); __ Move(f14, 0.0); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, bold)) ); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, dold)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, bold1)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, dold1)) ); __ movz_s(f10, f6, t0); __ movz_d(f12, f2, t0); __ movn_s(f14, f6, t0); __ movn_d(f16, f2, t0); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, b)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, d1)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, b1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; test.rt = 1; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, test.bold); CHECK_EQ(test.d, test.dold); CHECK_EQ(test.b1, outputs_D[i]); CHECK_EQ(test.d1, outputs_S[i]); test.rt = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); CHECK_EQ(test.b1, test.bold1); CHECK_EQ(test.d1, test.dold1); } } } TEST(movt_movd) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); typedef struct test_float { double srcd; double dstd; double dstdold; double dstd1; double dstdold1; float srcf; float dstf; float dstfold; float dstf1; float dstfold1; int32_t cc; int32_t fcsr; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; double inputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; int condition_flags[8] = {0, 1, 2, 3, 4, 5, 6, 7}; for (int i = 0; i < kTableLength; i++) { test.srcd = inputs_D[i]; test.srcf = inputs_S[i]; for (int j = 0; j< 8; j++) { test.cc = condition_flags[j]; if (test.cc == 0) { test.fcsr = 1 << 23; } else { test.fcsr = 1 << (24+condition_flags[j]); } HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, srcd)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, srcf)) ); __ lw(t1, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t0, FCSR); __ ctc1(t1, FCSR); __ li(t2, 0x0); __ mtc1(t2, f12); __ mtc1(t2, f10); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold)) ); __ movt_s(f12, f4, test.cc); __ movt_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold1)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold1)) ); __ movf_s(f12, f4, test.cc); __ movf_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf1)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd1)) ); __ ctc1(t0, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, outputs_S[i]); CHECK_EQ(test.dstd, outputs_D[i]); CHECK_EQ(test.dstf1, test.dstfold1); CHECK_EQ(test.dstd1, test.dstdold1); test.fcsr = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, test.dstfold); CHECK_EQ(test.dstd, test.dstdold); CHECK_EQ(test.dstf1, outputs_S[i]); CHECK_EQ(test.dstd1, outputs_D[i]); } } } } // ----------------------tests for all archs-------------------------- TEST(cvt_w_d) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; int32_t b; int fcsr; }Test; const int kTableLength = 24; double inputs[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, 2147483653.0 }; double outputs_RN[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RZ[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RP[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RM[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lw(t0, MemOperand(a0, offsetof(Test, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ cvt_w_d(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(Test, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } TEST(trunc_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_w_d(f8, f4); __ trunc_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_w_d(f8, f4); __ round_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_l_d(f8, f4); __ round_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(sub) { const int kTableLength = 12; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; double inputft_D[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; double outputs_D[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; float inputfs_S[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; float inputft_S[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; float outputs_S[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sub_s(f6, f2, f4); __ sub_d(f12, f8, f10); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(sqrt_rsqrt_recip) { const int kTableLength = 4; const double deltaDouble = 2E-15; const float deltaFloat = 2E-7; const float sqrt2_s = sqrt(2); const double sqrt2_d = sqrt(2); CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; float resultS1; float resultS2; double c; double resultD; double resultD1; double resultD2; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 0.0L, 4.0L, 2.0L, 4e-28L }; double outputs_D[kTableLength] = { 0.0L, 2.0L, sqrt2_d, 2e-14L }; float inputs_S[kTableLength] = { 0.0, 4.0, 2.0, 4e-28 }; float outputs_S[kTableLength] = { 0.0, 2.0, sqrt2_s, 2e-14 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ sqrt_s(f6, f2); __ sqrt_d(f12, f8); __ rsqrt_d(f14, f8); __ rsqrt_s(f16, f2); __ recip_d(f18, f8); __ recip_s(f4, f2); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resultS1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resultD1)) ); __ swc1(f4, MemOperand(a0, offsetof(TestFloat, resultS2)) ); __ sdc1(f18, MemOperand(a0, offsetof(TestFloat, resultD2)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { float f1; double d1; test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); if (i != 0) { f1 = test.resultS1 - 1.0F/outputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD1 - 1.0L/outputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); f1 = test.resultS2 - 1.0F/inputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD2 - 1.0L/inputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); } else { CHECK_EQ(test.resultS1, 1.0F/outputs_S[i]); CHECK_EQ(test.resultD1, 1.0L/outputs_D[i]); CHECK_EQ(test.resultS2, 1.0F/inputs_S[i]); CHECK_EQ(test.resultD2, 1.0L/inputs_D[i]); } } } TEST(neg) { const int kTableLength = 2; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; double c; double resultD; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 4.0, -2.0 }; double outputs_D[kTableLength] = { -4.0, 2.0 }; float inputs_S[kTableLength] = { 4.0, -2.0 }; float outputs_S[kTableLength] = { -4.0, 2.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ neg_s(f6, f2); __ neg_d(f12, f8); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.ui = 0x11223344; t.si = 0x99aabbcc; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(static_cast(0x11223344), t.r1); if (kArchEndian == kLittle) { CHECK_EQ(static_cast(0x3344), t.r2); CHECK_EQ(static_cast(0xffffbbcc), t.r3); CHECK_EQ(static_cast(0x0000bbcc), t.r4); CHECK_EQ(static_cast(0xffffffcc), t.r5); CHECK_EQ(static_cast(0x3333bbcc), t.r6); } else { CHECK_EQ(static_cast(0x1122), t.r2); CHECK_EQ(static_cast(0xffff99aa), t.r3); CHECK_EQ(static_cast(0x000099aa), t.r4); CHECK_EQ(static_cast(0xffffff99), t.r5); CHECK_EQ(static_cast(0x99aa3333), t.r6); } } TEST(MIPS7) { // Test floating point compare and branch instructions. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double a; double b; double c; double d; double e; double f; int32_t result; } T; T t; // Create a function that accepts &t, and loads, manipulates, and stores // the doubles t.a ... t.f. MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); Label neither_is_nan, less_than, outa_here; __ ldc1(f4, MemOperand(a0, offsetof(T, a)) ); __ ldc1(f6, MemOperand(a0, offsetof(T, b)) ); if (kArchVariant != kMips64r6) { __ c(UN, D, f4, f6); __ bc1f(&neither_is_nan); } else { __ cmp(UN, L, f2, f4, f6); __ bc1eqz(&neither_is_nan, f2); } __ nop(); __ sw(zero_reg, MemOperand(a0, offsetof(T, result)) ); __ Branch(&outa_here); __ bind(&neither_is_nan); if (kArchVariant == kMips64r6) { __ cmp(OLT, L, f2, f6, f4); __ bc1nez(&less_than, f2); } else { __ c(OLT, D, f6, f4, 2); __ bc1t(&less_than, 2); } __ nop(); __ sw(zero_reg, MemOperand(a0, offsetof(T, result)) ); __ Branch(&outa_here); __ bind(&less_than); __ Addu(a4, zero_reg, Operand(1)); __ sw(a4, MemOperand(a0, offsetof(T, result)) ); // Set true. // This test-case should have additional tests. __ bind(&outa_here); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.a = 1.5e14; t.b = 2.75e11; t.c = 2.0; t.d = -4.0; t.e = 0.0; t.f = 0.0; t.result = 0; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(1.5e14, t.a); CHECK_EQ(2.75e11, t.b); CHECK_EQ(1, t.result); } TEST(MIPS8) { if (kArchVariant == kMips64r2) { // Test ROTR and ROTRV instructions. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { int32_t input; int32_t result_rotr_4; int32_t result_rotr_8; int32_t result_rotr_12; int32_t result_rotr_16; int32_t result_rotr_20; int32_t result_rotr_24; int32_t result_rotr_28; int32_t result_rotrv_4; int32_t result_rotrv_8; int32_t result_rotrv_12; int32_t result_rotrv_16; int32_t result_rotrv_20; int32_t result_rotrv_24; int32_t result_rotrv_28; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); // Basic word load. __ lw(a4, MemOperand(a0, offsetof(T, input)) ); // ROTR instruction (called through the Ror macro). __ Ror(a5, a4, 0x0004); __ Ror(a6, a4, 0x0008); __ Ror(a7, a4, 0x000c); __ Ror(t0, a4, 0x0010); __ Ror(t1, a4, 0x0014); __ Ror(t2, a4, 0x0018); __ Ror(t3, a4, 0x001c); // Basic word store. __ sw(a5, MemOperand(a0, offsetof(T, result_rotr_4)) ); __ sw(a6, MemOperand(a0, offsetof(T, result_rotr_8)) ); __ sw(a7, MemOperand(a0, offsetof(T, result_rotr_12)) ); __ sw(t0, MemOperand(a0, offsetof(T, result_rotr_16)) ); __ sw(t1, MemOperand(a0, offsetof(T, result_rotr_20)) ); __ sw(t2, MemOperand(a0, offsetof(T, result_rotr_24)) ); __ sw(t3, MemOperand(a0, offsetof(T, result_rotr_28)) ); // ROTRV instruction (called through the Ror macro). __ li(t3, 0x0004); __ Ror(a5, a4, t3); __ li(t3, 0x0008); __ Ror(a6, a4, t3); __ li(t3, 0x000C); __ Ror(a7, a4, t3); __ li(t3, 0x0010); __ Ror(t0, a4, t3); __ li(t3, 0x0014); __ Ror(t1, a4, t3); __ li(t3, 0x0018); __ Ror(t2, a4, t3); __ li(t3, 0x001C); __ Ror(t3, a4, t3); // Basic word store. __ sw(a5, MemOperand(a0, offsetof(T, result_rotrv_4)) ); __ sw(a6, MemOperand(a0, offsetof(T, result_rotrv_8)) ); __ sw(a7, MemOperand(a0, offsetof(T, result_rotrv_12)) ); __ sw(t0, MemOperand(a0, offsetof(T, result_rotrv_16)) ); __ sw(t1, MemOperand(a0, offsetof(T, result_rotrv_20)) ); __ sw(t2, MemOperand(a0, offsetof(T, result_rotrv_24)) ); __ sw(t3, MemOperand(a0, offsetof(T, result_rotrv_28)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.input = 0x12345678; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0x0, 0, 0, 0); USE(dummy); CHECK_EQ(static_cast(0x81234567), t.result_rotr_4); CHECK_EQ(static_cast(0x78123456), t.result_rotr_8); CHECK_EQ(static_cast(0x67812345), t.result_rotr_12); CHECK_EQ(static_cast(0x56781234), t.result_rotr_16); CHECK_EQ(static_cast(0x45678123), t.result_rotr_20); CHECK_EQ(static_cast(0x34567812), t.result_rotr_24); CHECK_EQ(static_cast(0x23456781), t.result_rotr_28); CHECK_EQ(static_cast(0x81234567), t.result_rotrv_4); CHECK_EQ(static_cast(0x78123456), t.result_rotrv_8); CHECK_EQ(static_cast(0x67812345), t.result_rotrv_12); CHECK_EQ(static_cast(0x56781234), t.result_rotrv_16); CHECK_EQ(static_cast(0x45678123), t.result_rotrv_20); CHECK_EQ(static_cast(0x34567812), t.result_rotrv_24); CHECK_EQ(static_cast(0x23456781), t.result_rotrv_28); } } TEST(MIPS9) { // Test BRANCH improvements. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); Label exit, exit2, exit3; __ Branch(&exit, ge, a0, Operand(zero_reg)); __ Branch(&exit2, ge, a0, Operand(0x00001FFF)); __ Branch(&exit3, ge, a0, Operand(0x0001FFFF)); __ bind(&exit); __ bind(&exit2); __ bind(&exit3); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); } TEST(MIPS10) { // Test conversions between doubles and long integers. // Test hos the long ints map to FP regs pairs. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double a; double a_converted; double b; int32_t dbl_mant; int32_t dbl_exp; int32_t long_hi; int32_t long_lo; int64_t long_as_int64; int32_t b_long_hi; int32_t b_long_lo; int64_t b_long_as_int64; } T; T t; Assembler assm(isolate, NULL, 0); Label L, C; if (kArchVariant == kMips64r2) { // Rewritten for FR=1 FPU mode: // - 32 FP regs of 64-bits each, no odd/even pairs. // - Note that cvt_l_d/cvt_d_l ARE legal in FR=1 mode. // Load all structure elements to registers. __ ldc1(f0, MemOperand(a0, offsetof(T, a))); // Save the raw bits of the double. __ mfc1(a4, f0); __ mfhc1(a5, f0); __ sw(a4, MemOperand(a0, offsetof(T, dbl_mant))); __ sw(a5, MemOperand(a0, offsetof(T, dbl_exp))); // Convert double in f0 to long, save hi/lo parts. __ cvt_l_d(f0, f0); __ mfc1(a4, f0); // f0 LS 32 bits of long. __ mfhc1(a5, f0); // f0 MS 32 bits of long. __ sw(a4, MemOperand(a0, offsetof(T, long_lo))); __ sw(a5, MemOperand(a0, offsetof(T, long_hi))); // Combine the high/low ints, convert back to double. __ dsll32(a6, a5, 0); // Move a5 to high bits of a6. __ or_(a6, a6, a4); __ dmtc1(a6, f1); __ cvt_d_l(f1, f1); __ sdc1(f1, MemOperand(a0, offsetof(T, a_converted))); // Convert the b long integers to double b. __ lw(a4, MemOperand(a0, offsetof(T, b_long_lo))); __ lw(a5, MemOperand(a0, offsetof(T, b_long_hi))); __ mtc1(a4, f8); // f8 LS 32-bits. __ mthc1(a5, f8); // f8 MS 32-bits. __ cvt_d_l(f10, f8); __ sdc1(f10, MemOperand(a0, offsetof(T, b))); // Convert double b back to long-int. __ ldc1(f31, MemOperand(a0, offsetof(T, b))); __ cvt_l_d(f31, f31); __ dmfc1(a7, f31); __ sd(a7, MemOperand(a0, offsetof(T, b_long_as_int64))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.a = 2.147483647e9; // 0x7fffffff -> 0x41DFFFFFFFC00000 as double. t.b_long_hi = 0x000000ff; // 0xFF00FF00FF -> 0x426FE01FE01FE000 as double. t.b_long_lo = 0x00ff00ff; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(static_cast(0x41DFFFFF), t.dbl_exp); CHECK_EQ(static_cast(0xFFC00000), t.dbl_mant); CHECK_EQ(0, t.long_hi); CHECK_EQ(static_cast(0x7fffffff), t.long_lo); CHECK_EQ(2.147483647e9, t.a_converted); // 0xFF00FF00FF -> 1.095233372415e12. CHECK_EQ(1.095233372415e12, t.b); CHECK_EQ(static_cast(0xFF00FF00FF), t.b_long_as_int64); } } TEST(MIPS11) { // Do not run test on MIPS64r6, as these instructions are removed. if (kArchVariant != kMips64r6) { // Test LWL, LWR, SWL and SWR instructions. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { int32_t reg_init; int32_t mem_init; int32_t lwl_0; int32_t lwl_1; int32_t lwl_2; int32_t lwl_3; int32_t lwr_0; int32_t lwr_1; int32_t lwr_2; int32_t lwr_3; int32_t swl_0; int32_t swl_1; int32_t swl_2; int32_t swl_3; int32_t swr_0; int32_t swr_1; int32_t swr_2; int32_t swr_3; } T; T t; Assembler assm(isolate, NULL, 0); // Test all combinations of LWL and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, lwl_0))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a5, MemOperand(a0, offsetof(T, mem_init) + 1)); __ sw(a5, MemOperand(a0, offsetof(T, lwl_1))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a6, MemOperand(a0, offsetof(T, mem_init) + 2)); __ sw(a6, MemOperand(a0, offsetof(T, lwl_2))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a7, MemOperand(a0, offsetof(T, mem_init) + 3)); __ sw(a7, MemOperand(a0, offsetof(T, lwl_3))); // Test all combinations of LWR and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, lwr_0))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a5, MemOperand(a0, offsetof(T, mem_init) + 1)); __ sw(a5, MemOperand(a0, offsetof(T, lwr_1))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a6, MemOperand(a0, offsetof(T, mem_init) + 2)); __ sw(a6, MemOperand(a0, offsetof(T, lwr_2)) ); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a7, MemOperand(a0, offsetof(T, mem_init) + 3)); __ sw(a7, MemOperand(a0, offsetof(T, lwr_3)) ); // Test all combinations of SWL and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, swl_0))); __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ swl(a4, MemOperand(a0, offsetof(T, swl_0))); __ lw(a5, MemOperand(a0, offsetof(T, mem_init))); __ sw(a5, MemOperand(a0, offsetof(T, swl_1))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ swl(a5, MemOperand(a0, offsetof(T, swl_1) + 1)); __ lw(a6, MemOperand(a0, offsetof(T, mem_init))); __ sw(a6, MemOperand(a0, offsetof(T, swl_2))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ swl(a6, MemOperand(a0, offsetof(T, swl_2) + 2)); __ lw(a7, MemOperand(a0, offsetof(T, mem_init))); __ sw(a7, MemOperand(a0, offsetof(T, swl_3))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ swl(a7, MemOperand(a0, offsetof(T, swl_3) + 3)); // Test all combinations of SWR and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, swr_0))); __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ swr(a4, MemOperand(a0, offsetof(T, swr_0))); __ lw(a5, MemOperand(a0, offsetof(T, mem_init))); __ sw(a5, MemOperand(a0, offsetof(T, swr_1))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ swr(a5, MemOperand(a0, offsetof(T, swr_1) + 1)); __ lw(a6, MemOperand(a0, offsetof(T, mem_init))); __ sw(a6, MemOperand(a0, offsetof(T, swr_2))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ swr(a6, MemOperand(a0, offsetof(T, swr_2) + 2)); __ lw(a7, MemOperand(a0, offsetof(T, mem_init))); __ sw(a7, MemOperand(a0, offsetof(T, swr_3))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ swr(a7, MemOperand(a0, offsetof(T, swr_3) + 3)); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.reg_init = 0xaabbccdd; t.mem_init = 0x11223344; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); if (kArchEndian == kLittle) { CHECK_EQ(static_cast(0x44bbccdd), t.lwl_0); CHECK_EQ(static_cast(0x3344ccdd), t.lwl_1); CHECK_EQ(static_cast(0x223344dd), t.lwl_2); CHECK_EQ(static_cast(0x11223344), t.lwl_3); CHECK_EQ(static_cast(0x11223344), t.lwr_0); CHECK_EQ(static_cast(0xaa112233), t.lwr_1); CHECK_EQ(static_cast(0xaabb1122), t.lwr_2); CHECK_EQ(static_cast(0xaabbcc11), t.lwr_3); CHECK_EQ(static_cast(0x112233aa), t.swl_0); CHECK_EQ(static_cast(0x1122aabb), t.swl_1); CHECK_EQ(static_cast(0x11aabbcc), t.swl_2); CHECK_EQ(static_cast(0xaabbccdd), t.swl_3); CHECK_EQ(static_cast(0xaabbccdd), t.swr_0); CHECK_EQ(static_cast(0xbbccdd44), t.swr_1); CHECK_EQ(static_cast(0xccdd3344), t.swr_2); CHECK_EQ(static_cast(0xdd223344), t.swr_3); } else { CHECK_EQ(static_cast(0x11223344), t.lwl_0); CHECK_EQ(static_cast(0x223344dd), t.lwl_1); CHECK_EQ(static_cast(0x3344ccdd), t.lwl_2); CHECK_EQ(static_cast(0x44bbccdd), t.lwl_3); CHECK_EQ(static_cast(0xaabbcc11), t.lwr_0); CHECK_EQ(static_cast(0xaabb1122), t.lwr_1); CHECK_EQ(static_cast(0xaa112233), t.lwr_2); CHECK_EQ(static_cast(0x11223344), t.lwr_3); CHECK_EQ(static_cast(0xaabbccdd), t.swl_0); CHECK_EQ(static_cast(0x11aabbcc), t.swl_1); CHECK_EQ(static_cast(0x1122aabb), t.swl_2); CHECK_EQ(static_cast(0x112233aa), t.swl_3); CHECK_EQ(static_cast(0xdd223344), t.swr_0); CHECK_EQ(static_cast(0xccdd3344), t.swr_1); CHECK_EQ(static_cast(0xbbccdd44), t.swr_2); CHECK_EQ(static_cast(0xaabbccdd), t.swr_3); } } } TEST(MIPS12) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { int32_t x; int32_t y; int32_t y1; int32_t y2; int32_t y3; int32_t y4; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ mov(t2, fp); // Save frame pointer. __ mov(fp, a0); // Access struct T by fp. __ lw(a4, MemOperand(a0, offsetof(T, y))); __ lw(a7, MemOperand(a0, offsetof(T, y4))); __ addu(a5, a4, a7); __ subu(t0, a4, a7); __ nop(); __ push(a4); // These instructions disappear after opt. __ Pop(); __ addu(a4, a4, a4); __ nop(); __ Pop(); // These instructions disappear after opt. __ push(a7); __ nop(); __ push(a7); // These instructions disappear after opt. __ pop(a7); __ nop(); __ push(a7); __ pop(t0); __ nop(); __ sw(a4, MemOperand(fp, offsetof(T, y))); __ lw(a4, MemOperand(fp, offsetof(T, y))); __ nop(); __ sw(a4, MemOperand(fp, offsetof(T, y))); __ lw(a5, MemOperand(fp, offsetof(T, y))); __ nop(); __ push(a5); __ lw(a5, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a6); __ nop(); __ push(a6); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a7); __ nop(); __ mov(fp, t2); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.x = 1; t.y = 2; t.y1 = 3; t.y2 = 4; t.y3 = 0XBABA; t.y4 = 0xDEDA; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(3, t.y1); } TEST(MIPS13) { // Test Cvt_d_uw and Trunc_uw_d macros. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double cvt_big_out; double cvt_small_out; uint32_t trunc_big_out; uint32_t trunc_small_out; uint32_t cvt_big_in; uint32_t cvt_small_in; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ sw(a4, MemOperand(a0, offsetof(T, cvt_small_in))); __ Cvt_d_uw(f10, a4); __ sdc1(f10, MemOperand(a0, offsetof(T, cvt_small_out))); __ Trunc_uw_d(f10, f10, f4); __ swc1(f10, MemOperand(a0, offsetof(T, trunc_small_out))); __ sw(a4, MemOperand(a0, offsetof(T, cvt_big_in))); __ Cvt_d_uw(f8, a4); __ sdc1(f8, MemOperand(a0, offsetof(T, cvt_big_out))); __ Trunc_uw_d(f8, f8, f4); __ swc1(f8, MemOperand(a0, offsetof(T, trunc_big_out))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.cvt_big_in = 0xFFFFFFFF; t.cvt_small_in = 333; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(t.cvt_big_out, static_cast(t.cvt_big_in)); CHECK_EQ(t.cvt_small_out, static_cast(t.cvt_small_in)); CHECK_EQ(static_cast(t.trunc_big_out), static_cast(t.cvt_big_in)); CHECK_EQ(static_cast(t.trunc_small_out), static_cast(t.cvt_small_in)); } TEST(MIPS14) { // Test round, floor, ceil, trunc, cvt. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); #define ROUND_STRUCT_ELEMENT(x) \ uint32_t x##_isNaN2008; \ int32_t x##_up_out; \ int32_t x##_down_out; \ int32_t neg_##x##_up_out; \ int32_t neg_##x##_down_out; \ uint32_t x##_err1_out; \ uint32_t x##_err2_out; \ uint32_t x##_err3_out; \ uint32_t x##_err4_out; \ int32_t x##_invalid_result; typedef struct { double round_up_in; double round_down_in; double neg_round_up_in; double neg_round_down_in; double err1_in; double err2_in; double err3_in; double err4_in; ROUND_STRUCT_ELEMENT(round) ROUND_STRUCT_ELEMENT(floor) ROUND_STRUCT_ELEMENT(ceil) ROUND_STRUCT_ELEMENT(trunc) ROUND_STRUCT_ELEMENT(cvt) } T; T t; #undef ROUND_STRUCT_ELEMENT MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); // Save FCSR. __ cfc1(a1, FCSR); // Disable FPU exceptions. __ ctc1(zero_reg, FCSR); #define RUN_ROUND_TEST(x) \ __ cfc1(t0, FCSR);\ __ sw(t0, MemOperand(a0, offsetof(T, x##_isNaN2008))); \ __ ldc1(f0, MemOperand(a0, offsetof(T, round_up_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_up_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, round_down_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_down_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, neg_round_up_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, neg_##x##_up_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, neg_round_down_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, neg_##x##_down_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err1_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err1_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err2_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err2_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err3_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err3_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err4_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err4_out))); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_invalid_result))); RUN_ROUND_TEST(round) RUN_ROUND_TEST(floor) RUN_ROUND_TEST(ceil) RUN_ROUND_TEST(trunc) RUN_ROUND_TEST(cvt) // Restore FCSR. __ ctc1(a1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.round_up_in = 123.51; t.round_down_in = 123.49; t.neg_round_up_in = -123.5; t.neg_round_down_in = -123.49; t.err1_in = 123.51; t.err2_in = 1; t.err3_in = static_cast(1) + 0xFFFFFFFF; t.err4_in = NAN; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); #define GET_FPU_ERR(x) (static_cast(x & kFCSRFlagMask)) #define CHECK_NAN2008(x) (x & kFCSRNaN2008FlagMask) #define CHECK_ROUND_RESULT(type) \ CHECK(GET_FPU_ERR(t.type##_err1_out) & kFCSRInexactFlagMask); \ CHECK_EQ(0, GET_FPU_ERR(t.type##_err2_out)); \ CHECK(GET_FPU_ERR(t.type##_err3_out) & kFCSRInvalidOpFlagMask); \ CHECK(GET_FPU_ERR(t.type##_err4_out) & kFCSRInvalidOpFlagMask); \ if (CHECK_NAN2008(t.type##_isNaN2008) && kArchVariant == kMips64r6) { \ CHECK_EQ(static_cast(0), t.type##_invalid_result);\ } else { \ CHECK_EQ(static_cast(kFPUInvalidResult), t.type##_invalid_result);\ } CHECK_ROUND_RESULT(round); CHECK_ROUND_RESULT(floor); CHECK_ROUND_RESULT(ceil); CHECK_ROUND_RESULT(cvt); } TEST(MIPS15) { // Test chaining of label usages within instructions (issue 1644). CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); Assembler assm(isolate, NULL, 0); Label target; __ beq(v0, v1, &target); __ nop(); __ bne(v0, v1, &target); __ nop(); __ bind(&target); __ nop(); } // ----- mips64 tests ----------------------------------------------- TEST(MIPS16) { // Test 64-bit memory loads and stores. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); struct T { int64_t r1; int64_t r2; int64_t r3; int64_t r4; int64_t r5; int64_t r6; int64_t r7; int64_t r8; int64_t r9; int64_t r10; int64_t r11; int64_t r12; uint32_t ui; int32_t si; }; T t; Assembler assm(isolate, NULL, 0); Label L, C; // Basic 32-bit word load/store, with un-signed data. __ lw(a4, MemOperand(a0, offsetof(T, ui))); __ sw(a4, MemOperand(a0, offsetof(T, r1))); // Check that the data got zero-extended into 64-bit a4. __ sd(a4, MemOperand(a0, offsetof(T, r2))); // Basic 32-bit word load/store, with SIGNED data. __ lw(a5, MemOperand(a0, offsetof(T, si))); __ sw(a5, MemOperand(a0, offsetof(T, r3))); // Check that the data got sign-extended into 64-bit a4. __ sd(a5, MemOperand(a0, offsetof(T, r4))); // 32-bit UNSIGNED word load/store, with SIGNED data. __ lwu(a6, MemOperand(a0, offsetof(T, si))); __ sw(a6, MemOperand(a0, offsetof(T, r5))); // Check that the data got zero-extended into 64-bit a4. __ sd(a6, MemOperand(a0, offsetof(T, r6))); // lh with positive data. __ lh(a5, MemOperand(a0, offsetof(T, ui))); __ sw(a5, MemOperand(a0, offsetof(T, r7))); // lh with negative data. __ lh(a6, MemOperand(a0, offsetof(T, si))); __ sw(a6, MemOperand(a0, offsetof(T, r8))); // lhu with negative data. __ lhu(a7, MemOperand(a0, offsetof(T, si))); __ sw(a7, MemOperand(a0, offsetof(T, r9))); // lb with negative data. __ lb(t0, MemOperand(a0, offsetof(T, si))); __ sw(t0, MemOperand(a0, offsetof(T, r10))); // sh writes only 1/2 of word. __ lw(a4, MemOperand(a0, offsetof(T, ui))); __ sh(a4, MemOperand(a0, offsetof(T, r11))); __ lw(a4, MemOperand(a0, offsetof(T, si))); __ sh(a4, MemOperand(a0, offsetof(T, r12))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.ui = 0x44332211; t.si = 0x99aabbcc; t.r1 = 0x5555555555555555; t.r2 = 0x5555555555555555; t.r3 = 0x5555555555555555; t.r4 = 0x5555555555555555; t.r5 = 0x5555555555555555; t.r6 = 0x5555555555555555; t.r7 = 0x5555555555555555; t.r8 = 0x5555555555555555; t.r9 = 0x5555555555555555; t.r10 = 0x5555555555555555; t.r11 = 0x5555555555555555; t.r12 = 0x5555555555555555; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); if (kArchEndian == kLittle) { // Unsigned data, 32 & 64 CHECK_EQ(static_cast(0x5555555544332211L), t.r1); // lw, sw. CHECK_EQ(static_cast(0x0000000044332211L), t.r2); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x5555555599aabbccL), t.r3); // lw, sw. CHECK_EQ(static_cast(0xffffffff99aabbccL), t.r4); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x5555555599aabbccL), t.r5); // lwu, sw. CHECK_EQ(static_cast(0x0000000099aabbccL), t.r6); // sd. // lh with unsigned and signed data. CHECK_EQ(static_cast(0x5555555500002211L), t.r7); // lh, sw. CHECK_EQ(static_cast(0x55555555ffffbbccL), t.r8); // lh, sw. // lhu with signed data. CHECK_EQ(static_cast(0x555555550000bbccL), t.r9); // lhu, sw. // lb with signed data. CHECK_EQ(static_cast(0x55555555ffffffccL), t.r10); // lb, sw. // sh with unsigned and signed data. CHECK_EQ(static_cast(0x5555555555552211L), t.r11); // lw, sh. CHECK_EQ(static_cast(0x555555555555bbccL), t.r12); // lw, sh. } else { // Unsigned data, 32 & 64 CHECK_EQ(static_cast(0x4433221155555555L), t.r1); // lw, sw. CHECK_EQ(static_cast(0x0000000044332211L), t.r2); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x99aabbcc55555555L), t.r3); // lw, sw. CHECK_EQ(static_cast(0xffffffff99aabbccL), t.r4); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x99aabbcc55555555L), t.r5); // lwu, sw. CHECK_EQ(static_cast(0x0000000099aabbccL), t.r6); // sd. // lh with unsigned and signed data. CHECK_EQ(static_cast(0x0000443355555555L), t.r7); // lh, sw. CHECK_EQ(static_cast(0xffff99aa55555555L), t.r8); // lh, sw. // lhu with signed data. CHECK_EQ(static_cast(0x000099aa55555555L), t.r9); // lhu, sw. // lb with signed data. CHECK_EQ(static_cast(0xffffff9955555555L), t.r10); // lb, sw. // sh with unsigned and signed data. CHECK_EQ(static_cast(0x2211555555555555L), t.r11); // lw, sh. CHECK_EQ(static_cast(0xbbcc555555555555L), t.r12); // lw, sh. } } // ----------------------mips64r6 specific tests---------------------- TEST(seleqz_selnez) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { int a; int b; int c; int d; double e; double f; double g; double h; float i; float j; float k; float l; } Test; Test test; // Integer part of test. __ addiu(t1, zero_reg, 1); // t1 = 1 __ seleqz(t3, t1, zero_reg); // t3 = 1 __ sw(t3, MemOperand(a0, offsetof(Test, a))); // a = 1 __ seleqz(t2, t1, t1); // t2 = 0 __ sw(t2, MemOperand(a0, offsetof(Test, b))); // b = 0 __ selnez(t3, t1, zero_reg); // t3 = 1; __ sw(t3, MemOperand(a0, offsetof(Test, c))); // c = 0 __ selnez(t3, t1, t1); // t3 = 1 __ sw(t3, MemOperand(a0, offsetof(Test, d))); // d = 1 // Floating point part of test. __ ldc1(f0, MemOperand(a0, offsetof(Test, e)) ); // src __ ldc1(f2, MemOperand(a0, offsetof(Test, f)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, i)) ); // src __ lwc1(f10, MemOperand(a0, offsetof(Test, j)) ); // test __ seleqz_d(f4, f0, f2); __ selnez_d(f6, f0, f2); __ seleqz_s(f12, f8, f10); __ selnez_s(f14, f8, f10); __ sdc1(f4, MemOperand(a0, offsetof(Test, g)) ); // src __ sdc1(f6, MemOperand(a0, offsetof(Test, h)) ); // src __ swc1(f12, MemOperand(a0, offsetof(Test, k)) ); // src __ swc1(f14, MemOperand(a0, offsetof(Test, l)) ); // src __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.a, 1); CHECK_EQ(test.b, 0); CHECK_EQ(test.c, 0); CHECK_EQ(test.d, 1); const int test_size = 3; const int input_size = 5; double inputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double outputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float inputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float outputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.e = inputs_D[i]; test.f = tests_D[j]; test.i = inputs_S[i]; test.j = tests_S[j]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, outputs_D[i]); CHECK_EQ(test.h, 0); CHECK_EQ(test.k, outputs_S[i]); CHECK_EQ(test.l, 0); test.f = tests_D[j+1]; test.j = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, 0); CHECK_EQ(test.h, outputs_D[i]); CHECK_EQ(test.k, 0); CHECK_EQ(test.l, outputs_S[i]); } } } } TEST(min_max) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); struct TestFloat { double a; double b; double c; double d; float e; float f; float g; float h; }; TestFloat test; const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); const int kTableLength = 13; double inputsa[kTableLength] = {2.0, 3.0, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = {3.0, 2.0, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double outputsdmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double outputsdmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputse[kTableLength] = {2.0, 3.0, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsf[kTableLength] = {3.0, 2.0, 3.0, fnan, 0.0, -0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float outputsfmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float outputsfmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a))); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, b))); __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, e))); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, f))); __ min_d(f10, f4, f8); __ max_d(f12, f4, f8); __ min_s(f14, f2, f6); __ max_s(f16, f2, f6); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, c))); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, d))); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, g))); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, h))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 4; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.e = inputse[i]; test.f = inputsf[i]; CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0); CHECK_EQ(0, memcmp(&test.c, &outputsdmin[i], sizeof(test.c))); CHECK_EQ(0, memcmp(&test.d, &outputsdmax[i], sizeof(test.d))); CHECK_EQ(0, memcmp(&test.g, &outputsfmin[i], sizeof(test.g))); CHECK_EQ(0, memcmp(&test.h, &outputsfmax[i], sizeof(test.h))); } } } TEST(rint_d) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; int fcsr; }TestFloat; TestFloat test; double inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E+308, 6.27463370218383111104242366943E-307, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ ctc1(t0, FCSR); __ rint_d(f8, f4); __ sdc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(sel) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { double dd; double ds; double dt; float fd; float fs; float ft; } Test; Test test; __ ldc1(f0, MemOperand(a0, offsetof(Test, dd)) ); // test __ ldc1(f2, MemOperand(a0, offsetof(Test, ds)) ); // src1 __ ldc1(f4, MemOperand(a0, offsetof(Test, dt)) ); // src2 __ lwc1(f6, MemOperand(a0, offsetof(Test, fd)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, fs)) ); // src1 __ lwc1(f10, MemOperand(a0, offsetof(Test, ft)) ); // src2 __ sel_d(f0, f2, f4); __ sel_s(f6, f8, f10); __ sdc1(f0, MemOperand(a0, offsetof(Test, dd)) ); __ swc1(f6, MemOperand(a0, offsetof(Test, fd)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); const int test_size = 3; const int input_size = 5; double inputs_dt[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double inputs_ds[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; float inputs_ft[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float inputs_fs[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.dt = inputs_dt[i]; test.dd = tests_D[j]; test.ds = inputs_ds[i]; test.ft = inputs_ft[i]; test.fd = tests_S[j]; test.fs = inputs_fs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_ds[i]); CHECK_EQ(test.fd, inputs_fs[i]); test.dd = tests_D[j+1]; test.fd = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_dt[i]); CHECK_EQ(test.fd, inputs_ft[i]); } } } } TEST(rint_s) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; int fcsr; }TestFloat; TestFloat test; float inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E+38, 6.27463370218383111104242366943E-37, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; float* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ rint_s(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(mina_maxa) { if (kArchVariant == kMips64r6) { const int kTableLength = 23; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); struct TestFloat { double a; double b; double resd; double resd1; float c; float d; float resf; float resf1; }; TestFloat test; double inputsa[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = { 4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double resd[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double resd1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputsc[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsd[kTableLength] = {4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, fnan, -0.0, 0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float resf[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float resf1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ lwc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ lwc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ mina_d(f6, f2, f4); __ mina_s(f12, f8, f10); __ maxa_d(f14, f2, f4); __ maxa_s(f16, f8, f10); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, resf)) ); __ sdc1(f6, MemOperand(a0, offsetof(TestFloat, resd)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resf1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resd1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.c = inputsc[i]; test.d = inputsd[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if (i < kTableLength - 1) { CHECK_EQ(test.resd, resd[i]); CHECK_EQ(test.resf, resf[i]); CHECK_EQ(test.resd1, resd1[i]); CHECK_EQ(test.resf1, resf1[i]); } else { CHECK(std::isnan(test.resd)); CHECK(std::isnan(test.resf)); CHECK(std::isnan(test.resd1)); CHECK(std::isnan(test.resf1)); } } } } // ----------------------mips64r2 specific tests---------------------- TEST(trunc_l) { if (kArchVariant == kMips64r2) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; // a trunc result int64_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_l_d(f8, f4); __ trunc_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } } TEST(movz_movn) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { int64_t rt; double a; double b; double bold; double b1; double bold1; float c; float d; float dold; float d1; float dold1; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ld(t0, MemOperand(a0, offsetof(TestFloat, rt))); __ Move(f12, 0.0); __ Move(f10, 0.0); __ Move(f16, 0.0); __ Move(f14, 0.0); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, bold)) ); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, dold)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, bold1)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, dold1)) ); __ movz_s(f10, f6, t0); __ movz_d(f12, f2, t0); __ movn_s(f14, f6, t0); __ movn_d(f16, f2, t0); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, b)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, d1)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, b1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; test.rt = 1; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, test.bold); CHECK_EQ(test.d, test.dold); CHECK_EQ(test.b1, outputs_D[i]); CHECK_EQ(test.d1, outputs_S[i]); test.rt = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); CHECK_EQ(test.b1, test.bold1); CHECK_EQ(test.d1, test.dold1); } } } TEST(movt_movd) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); typedef struct test_float { double srcd; double dstd; double dstdold; double dstd1; double dstdold1; float srcf; float dstf; float dstfold; float dstf1; float dstfold1; int32_t cc; int32_t fcsr; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; double inputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; int condition_flags[8] = {0, 1, 2, 3, 4, 5, 6, 7}; for (int i = 0; i < kTableLength; i++) { test.srcd = inputs_D[i]; test.srcf = inputs_S[i]; for (int j = 0; j< 8; j++) { test.cc = condition_flags[j]; if (test.cc == 0) { test.fcsr = 1 << 23; } else { test.fcsr = 1 << (24+condition_flags[j]); } HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, srcd)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, srcf)) ); __ lw(t1, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t0, FCSR); __ ctc1(t1, FCSR); __ li(t2, 0x0); __ mtc1(t2, f12); __ mtc1(t2, f10); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold)) ); __ movt_s(f12, f4, test.cc); __ movt_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold1)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold1)) ); __ movf_s(f12, f4, test.cc); __ movf_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf1)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd1)) ); __ ctc1(t0, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, outputs_S[i]); CHECK_EQ(test.dstd, outputs_D[i]); CHECK_EQ(test.dstf1, test.dstfold1); CHECK_EQ(test.dstd1, test.dstdold1); test.fcsr = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, test.dstfold); CHECK_EQ(test.dstd, test.dstdold); CHECK_EQ(test.dstf1, outputs_S[i]); CHECK_EQ(test.dstd1, outputs_D[i]); } } } } // ----------------------tests for all archs-------------------------- TEST(cvt_w_d) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; int32_t b; int fcsr; }Test; const int kTableLength = 24; double inputs[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, 2147483653.0 }; double outputs_RN[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RZ[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RP[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RM[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lw(t0, MemOperand(a0, offsetof(Test, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ cvt_w_d(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(Test, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } TEST(trunc_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_w_d(f8, f4); __ trunc_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_w_d(f8, f4); __ round_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_l_d(f8, f4); __ round_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(sub) { const int kTableLength = 12; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; double inputft_D[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; double outputs_D[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; float inputfs_S[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; float inputft_S[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; float outputs_S[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sub_s(f6, f2, f4); __ sub_d(f12, f8, f10); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(sqrt_rsqrt_recip) { const int kTableLength = 4; const double deltaDouble = 2E-15; const float deltaFloat = 2E-7; const float sqrt2_s = sqrt(2); const double sqrt2_d = sqrt(2); CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; float resultS1; float resultS2; double c; double resultD; double resultD1; double resultD2; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 0.0L, 4.0L, 2.0L, 4e-28L }; double outputs_D[kTableLength] = { 0.0L, 2.0L, sqrt2_d, 2e-14L }; float inputs_S[kTableLength] = { 0.0, 4.0, 2.0, 4e-28 }; float outputs_S[kTableLength] = { 0.0, 2.0, sqrt2_s, 2e-14 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ sqrt_s(f6, f2); __ sqrt_d(f12, f8); __ rsqrt_d(f14, f8); __ rsqrt_s(f16, f2); __ recip_d(f18, f8); __ recip_s(f4, f2); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resultS1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resultD1)) ); __ swc1(f4, MemOperand(a0, offsetof(TestFloat, resultS2)) ); __ sdc1(f18, MemOperand(a0, offsetof(TestFloat, resultD2)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { float f1; double d1; test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); if (i != 0) { f1 = test.resultS1 - 1.0F/outputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD1 - 1.0L/outputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); f1 = test.resultS2 - 1.0F/inputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD2 - 1.0L/inputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); } else { CHECK_EQ(test.resultS1, 1.0F/outputs_S[i]); CHECK_EQ(test.resultD1, 1.0L/outputs_D[i]); CHECK_EQ(test.resultS2, 1.0F/inputs_S[i]); CHECK_EQ(test.resultD2, 1.0L/inputs_D[i]); } } } TEST(neg) { const int kTableLength = 2; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; double c; double resultD; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 4.0, -2.0 }; double outputs_D[kTableLength] = { -4.0, 2.0 }; float inputs_S[kTableLength] = { 4.0, -2.0 }; float outputs_S[kTableLength] = { -4.0, 2.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ neg_s(f6, f2); __ neg_d(f12, f8); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
()); F3 f = FUNCTION_CAST(code->entry()); t.ui = 0x11223344; t.si = 0x99aabbcc; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(static_cast(0x11223344), t.r1); if (kArchEndian == kLittle) { CHECK_EQ(static_cast(0x3344), t.r2); CHECK_EQ(static_cast(0xffffbbcc), t.r3); CHECK_EQ(static_cast(0x0000bbcc), t.r4); CHECK_EQ(static_cast(0xffffffcc), t.r5); CHECK_EQ(static_cast(0x3333bbcc), t.r6); } else { CHECK_EQ(static_cast(0x1122), t.r2); CHECK_EQ(static_cast(0xffff99aa), t.r3); CHECK_EQ(static_cast(0x000099aa), t.r4); CHECK_EQ(static_cast(0xffffff99), t.r5); CHECK_EQ(static_cast(0x99aa3333), t.r6); } } TEST(MIPS7) { // Test floating point compare and branch instructions. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double a; double b; double c; double d; double e; double f; int32_t result; } T; T t; // Create a function that accepts &t, and loads, manipulates, and stores // the doubles t.a ... t.f. MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); Label neither_is_nan, less_than, outa_here; __ ldc1(f4, MemOperand(a0, offsetof(T, a)) ); __ ldc1(f6, MemOperand(a0, offsetof(T, b)) ); if (kArchVariant != kMips64r6) { __ c(UN, D, f4, f6); __ bc1f(&neither_is_nan); } else { __ cmp(UN, L, f2, f4, f6); __ bc1eqz(&neither_is_nan, f2); } __ nop(); __ sw(zero_reg, MemOperand(a0, offsetof(T, result)) ); __ Branch(&outa_here); __ bind(&neither_is_nan); if (kArchVariant == kMips64r6) { __ cmp(OLT, L, f2, f6, f4); __ bc1nez(&less_than, f2); } else { __ c(OLT, D, f6, f4, 2); __ bc1t(&less_than, 2); } __ nop(); __ sw(zero_reg, MemOperand(a0, offsetof(T, result)) ); __ Branch(&outa_here); __ bind(&less_than); __ Addu(a4, zero_reg, Operand(1)); __ sw(a4, MemOperand(a0, offsetof(T, result)) ); // Set true. // This test-case should have additional tests. __ bind(&outa_here); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.a = 1.5e14; t.b = 2.75e11; t.c = 2.0; t.d = -4.0; t.e = 0.0; t.f = 0.0; t.result = 0; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(1.5e14, t.a); CHECK_EQ(2.75e11, t.b); CHECK_EQ(1, t.result); } TEST(MIPS8) { if (kArchVariant == kMips64r2) { // Test ROTR and ROTRV instructions. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { int32_t input; int32_t result_rotr_4; int32_t result_rotr_8; int32_t result_rotr_12; int32_t result_rotr_16; int32_t result_rotr_20; int32_t result_rotr_24; int32_t result_rotr_28; int32_t result_rotrv_4; int32_t result_rotrv_8; int32_t result_rotrv_12; int32_t result_rotrv_16; int32_t result_rotrv_20; int32_t result_rotrv_24; int32_t result_rotrv_28; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); // Basic word load. __ lw(a4, MemOperand(a0, offsetof(T, input)) ); // ROTR instruction (called through the Ror macro). __ Ror(a5, a4, 0x0004); __ Ror(a6, a4, 0x0008); __ Ror(a7, a4, 0x000c); __ Ror(t0, a4, 0x0010); __ Ror(t1, a4, 0x0014); __ Ror(t2, a4, 0x0018); __ Ror(t3, a4, 0x001c); // Basic word store. __ sw(a5, MemOperand(a0, offsetof(T, result_rotr_4)) ); __ sw(a6, MemOperand(a0, offsetof(T, result_rotr_8)) ); __ sw(a7, MemOperand(a0, offsetof(T, result_rotr_12)) ); __ sw(t0, MemOperand(a0, offsetof(T, result_rotr_16)) ); __ sw(t1, MemOperand(a0, offsetof(T, result_rotr_20)) ); __ sw(t2, MemOperand(a0, offsetof(T, result_rotr_24)) ); __ sw(t3, MemOperand(a0, offsetof(T, result_rotr_28)) ); // ROTRV instruction (called through the Ror macro). __ li(t3, 0x0004); __ Ror(a5, a4, t3); __ li(t3, 0x0008); __ Ror(a6, a4, t3); __ li(t3, 0x000C); __ Ror(a7, a4, t3); __ li(t3, 0x0010); __ Ror(t0, a4, t3); __ li(t3, 0x0014); __ Ror(t1, a4, t3); __ li(t3, 0x0018); __ Ror(t2, a4, t3); __ li(t3, 0x001C); __ Ror(t3, a4, t3); // Basic word store. __ sw(a5, MemOperand(a0, offsetof(T, result_rotrv_4)) ); __ sw(a6, MemOperand(a0, offsetof(T, result_rotrv_8)) ); __ sw(a7, MemOperand(a0, offsetof(T, result_rotrv_12)) ); __ sw(t0, MemOperand(a0, offsetof(T, result_rotrv_16)) ); __ sw(t1, MemOperand(a0, offsetof(T, result_rotrv_20)) ); __ sw(t2, MemOperand(a0, offsetof(T, result_rotrv_24)) ); __ sw(t3, MemOperand(a0, offsetof(T, result_rotrv_28)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.input = 0x12345678; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0x0, 0, 0, 0); USE(dummy); CHECK_EQ(static_cast(0x81234567), t.result_rotr_4); CHECK_EQ(static_cast(0x78123456), t.result_rotr_8); CHECK_EQ(static_cast(0x67812345), t.result_rotr_12); CHECK_EQ(static_cast(0x56781234), t.result_rotr_16); CHECK_EQ(static_cast(0x45678123), t.result_rotr_20); CHECK_EQ(static_cast(0x34567812), t.result_rotr_24); CHECK_EQ(static_cast(0x23456781), t.result_rotr_28); CHECK_EQ(static_cast(0x81234567), t.result_rotrv_4); CHECK_EQ(static_cast(0x78123456), t.result_rotrv_8); CHECK_EQ(static_cast(0x67812345), t.result_rotrv_12); CHECK_EQ(static_cast(0x56781234), t.result_rotrv_16); CHECK_EQ(static_cast(0x45678123), t.result_rotrv_20); CHECK_EQ(static_cast(0x34567812), t.result_rotrv_24); CHECK_EQ(static_cast(0x23456781), t.result_rotrv_28); } } TEST(MIPS9) { // Test BRANCH improvements. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); Label exit, exit2, exit3; __ Branch(&exit, ge, a0, Operand(zero_reg)); __ Branch(&exit2, ge, a0, Operand(0x00001FFF)); __ Branch(&exit3, ge, a0, Operand(0x0001FFFF)); __ bind(&exit); __ bind(&exit2); __ bind(&exit3); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); } TEST(MIPS10) { // Test conversions between doubles and long integers. // Test hos the long ints map to FP regs pairs. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double a; double a_converted; double b; int32_t dbl_mant; int32_t dbl_exp; int32_t long_hi; int32_t long_lo; int64_t long_as_int64; int32_t b_long_hi; int32_t b_long_lo; int64_t b_long_as_int64; } T; T t; Assembler assm(isolate, NULL, 0); Label L, C; if (kArchVariant == kMips64r2) { // Rewritten for FR=1 FPU mode: // - 32 FP regs of 64-bits each, no odd/even pairs. // - Note that cvt_l_d/cvt_d_l ARE legal in FR=1 mode. // Load all structure elements to registers. __ ldc1(f0, MemOperand(a0, offsetof(T, a))); // Save the raw bits of the double. __ mfc1(a4, f0); __ mfhc1(a5, f0); __ sw(a4, MemOperand(a0, offsetof(T, dbl_mant))); __ sw(a5, MemOperand(a0, offsetof(T, dbl_exp))); // Convert double in f0 to long, save hi/lo parts. __ cvt_l_d(f0, f0); __ mfc1(a4, f0); // f0 LS 32 bits of long. __ mfhc1(a5, f0); // f0 MS 32 bits of long. __ sw(a4, MemOperand(a0, offsetof(T, long_lo))); __ sw(a5, MemOperand(a0, offsetof(T, long_hi))); // Combine the high/low ints, convert back to double. __ dsll32(a6, a5, 0); // Move a5 to high bits of a6. __ or_(a6, a6, a4); __ dmtc1(a6, f1); __ cvt_d_l(f1, f1); __ sdc1(f1, MemOperand(a0, offsetof(T, a_converted))); // Convert the b long integers to double b. __ lw(a4, MemOperand(a0, offsetof(T, b_long_lo))); __ lw(a5, MemOperand(a0, offsetof(T, b_long_hi))); __ mtc1(a4, f8); // f8 LS 32-bits. __ mthc1(a5, f8); // f8 MS 32-bits. __ cvt_d_l(f10, f8); __ sdc1(f10, MemOperand(a0, offsetof(T, b))); // Convert double b back to long-int. __ ldc1(f31, MemOperand(a0, offsetof(T, b))); __ cvt_l_d(f31, f31); __ dmfc1(a7, f31); __ sd(a7, MemOperand(a0, offsetof(T, b_long_as_int64))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.a = 2.147483647e9; // 0x7fffffff -> 0x41DFFFFFFFC00000 as double. t.b_long_hi = 0x000000ff; // 0xFF00FF00FF -> 0x426FE01FE01FE000 as double. t.b_long_lo = 0x00ff00ff; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(static_cast(0x41DFFFFF), t.dbl_exp); CHECK_EQ(static_cast(0xFFC00000), t.dbl_mant); CHECK_EQ(0, t.long_hi); CHECK_EQ(static_cast(0x7fffffff), t.long_lo); CHECK_EQ(2.147483647e9, t.a_converted); // 0xFF00FF00FF -> 1.095233372415e12. CHECK_EQ(1.095233372415e12, t.b); CHECK_EQ(static_cast(0xFF00FF00FF), t.b_long_as_int64); } } TEST(MIPS11) { // Do not run test on MIPS64r6, as these instructions are removed. if (kArchVariant != kMips64r6) { // Test LWL, LWR, SWL and SWR instructions. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { int32_t reg_init; int32_t mem_init; int32_t lwl_0; int32_t lwl_1; int32_t lwl_2; int32_t lwl_3; int32_t lwr_0; int32_t lwr_1; int32_t lwr_2; int32_t lwr_3; int32_t swl_0; int32_t swl_1; int32_t swl_2; int32_t swl_3; int32_t swr_0; int32_t swr_1; int32_t swr_2; int32_t swr_3; } T; T t; Assembler assm(isolate, NULL, 0); // Test all combinations of LWL and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, lwl_0))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a5, MemOperand(a0, offsetof(T, mem_init) + 1)); __ sw(a5, MemOperand(a0, offsetof(T, lwl_1))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a6, MemOperand(a0, offsetof(T, mem_init) + 2)); __ sw(a6, MemOperand(a0, offsetof(T, lwl_2))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a7, MemOperand(a0, offsetof(T, mem_init) + 3)); __ sw(a7, MemOperand(a0, offsetof(T, lwl_3))); // Test all combinations of LWR and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, lwr_0))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a5, MemOperand(a0, offsetof(T, mem_init) + 1)); __ sw(a5, MemOperand(a0, offsetof(T, lwr_1))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a6, MemOperand(a0, offsetof(T, mem_init) + 2)); __ sw(a6, MemOperand(a0, offsetof(T, lwr_2)) ); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a7, MemOperand(a0, offsetof(T, mem_init) + 3)); __ sw(a7, MemOperand(a0, offsetof(T, lwr_3)) ); // Test all combinations of SWL and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, swl_0))); __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ swl(a4, MemOperand(a0, offsetof(T, swl_0))); __ lw(a5, MemOperand(a0, offsetof(T, mem_init))); __ sw(a5, MemOperand(a0, offsetof(T, swl_1))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ swl(a5, MemOperand(a0, offsetof(T, swl_1) + 1)); __ lw(a6, MemOperand(a0, offsetof(T, mem_init))); __ sw(a6, MemOperand(a0, offsetof(T, swl_2))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ swl(a6, MemOperand(a0, offsetof(T, swl_2) + 2)); __ lw(a7, MemOperand(a0, offsetof(T, mem_init))); __ sw(a7, MemOperand(a0, offsetof(T, swl_3))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ swl(a7, MemOperand(a0, offsetof(T, swl_3) + 3)); // Test all combinations of SWR and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, swr_0))); __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ swr(a4, MemOperand(a0, offsetof(T, swr_0))); __ lw(a5, MemOperand(a0, offsetof(T, mem_init))); __ sw(a5, MemOperand(a0, offsetof(T, swr_1))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ swr(a5, MemOperand(a0, offsetof(T, swr_1) + 1)); __ lw(a6, MemOperand(a0, offsetof(T, mem_init))); __ sw(a6, MemOperand(a0, offsetof(T, swr_2))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ swr(a6, MemOperand(a0, offsetof(T, swr_2) + 2)); __ lw(a7, MemOperand(a0, offsetof(T, mem_init))); __ sw(a7, MemOperand(a0, offsetof(T, swr_3))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ swr(a7, MemOperand(a0, offsetof(T, swr_3) + 3)); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.reg_init = 0xaabbccdd; t.mem_init = 0x11223344; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); if (kArchEndian == kLittle) { CHECK_EQ(static_cast(0x44bbccdd), t.lwl_0); CHECK_EQ(static_cast(0x3344ccdd), t.lwl_1); CHECK_EQ(static_cast(0x223344dd), t.lwl_2); CHECK_EQ(static_cast(0x11223344), t.lwl_3); CHECK_EQ(static_cast(0x11223344), t.lwr_0); CHECK_EQ(static_cast(0xaa112233), t.lwr_1); CHECK_EQ(static_cast(0xaabb1122), t.lwr_2); CHECK_EQ(static_cast(0xaabbcc11), t.lwr_3); CHECK_EQ(static_cast(0x112233aa), t.swl_0); CHECK_EQ(static_cast(0x1122aabb), t.swl_1); CHECK_EQ(static_cast(0x11aabbcc), t.swl_2); CHECK_EQ(static_cast(0xaabbccdd), t.swl_3); CHECK_EQ(static_cast(0xaabbccdd), t.swr_0); CHECK_EQ(static_cast(0xbbccdd44), t.swr_1); CHECK_EQ(static_cast(0xccdd3344), t.swr_2); CHECK_EQ(static_cast(0xdd223344), t.swr_3); } else { CHECK_EQ(static_cast(0x11223344), t.lwl_0); CHECK_EQ(static_cast(0x223344dd), t.lwl_1); CHECK_EQ(static_cast(0x3344ccdd), t.lwl_2); CHECK_EQ(static_cast(0x44bbccdd), t.lwl_3); CHECK_EQ(static_cast(0xaabbcc11), t.lwr_0); CHECK_EQ(static_cast(0xaabb1122), t.lwr_1); CHECK_EQ(static_cast(0xaa112233), t.lwr_2); CHECK_EQ(static_cast(0x11223344), t.lwr_3); CHECK_EQ(static_cast(0xaabbccdd), t.swl_0); CHECK_EQ(static_cast(0x11aabbcc), t.swl_1); CHECK_EQ(static_cast(0x1122aabb), t.swl_2); CHECK_EQ(static_cast(0x112233aa), t.swl_3); CHECK_EQ(static_cast(0xdd223344), t.swr_0); CHECK_EQ(static_cast(0xccdd3344), t.swr_1); CHECK_EQ(static_cast(0xbbccdd44), t.swr_2); CHECK_EQ(static_cast(0xaabbccdd), t.swr_3); } } } TEST(MIPS12) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { int32_t x; int32_t y; int32_t y1; int32_t y2; int32_t y3; int32_t y4; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ mov(t2, fp); // Save frame pointer. __ mov(fp, a0); // Access struct T by fp. __ lw(a4, MemOperand(a0, offsetof(T, y))); __ lw(a7, MemOperand(a0, offsetof(T, y4))); __ addu(a5, a4, a7); __ subu(t0, a4, a7); __ nop(); __ push(a4); // These instructions disappear after opt. __ Pop(); __ addu(a4, a4, a4); __ nop(); __ Pop(); // These instructions disappear after opt. __ push(a7); __ nop(); __ push(a7); // These instructions disappear after opt. __ pop(a7); __ nop(); __ push(a7); __ pop(t0); __ nop(); __ sw(a4, MemOperand(fp, offsetof(T, y))); __ lw(a4, MemOperand(fp, offsetof(T, y))); __ nop(); __ sw(a4, MemOperand(fp, offsetof(T, y))); __ lw(a5, MemOperand(fp, offsetof(T, y))); __ nop(); __ push(a5); __ lw(a5, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a6); __ nop(); __ push(a6); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a7); __ nop(); __ mov(fp, t2); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.x = 1; t.y = 2; t.y1 = 3; t.y2 = 4; t.y3 = 0XBABA; t.y4 = 0xDEDA; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(3, t.y1); } TEST(MIPS13) { // Test Cvt_d_uw and Trunc_uw_d macros. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double cvt_big_out; double cvt_small_out; uint32_t trunc_big_out; uint32_t trunc_small_out; uint32_t cvt_big_in; uint32_t cvt_small_in; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ sw(a4, MemOperand(a0, offsetof(T, cvt_small_in))); __ Cvt_d_uw(f10, a4); __ sdc1(f10, MemOperand(a0, offsetof(T, cvt_small_out))); __ Trunc_uw_d(f10, f10, f4); __ swc1(f10, MemOperand(a0, offsetof(T, trunc_small_out))); __ sw(a4, MemOperand(a0, offsetof(T, cvt_big_in))); __ Cvt_d_uw(f8, a4); __ sdc1(f8, MemOperand(a0, offsetof(T, cvt_big_out))); __ Trunc_uw_d(f8, f8, f4); __ swc1(f8, MemOperand(a0, offsetof(T, trunc_big_out))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.cvt_big_in = 0xFFFFFFFF; t.cvt_small_in = 333; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(t.cvt_big_out, static_cast(t.cvt_big_in)); CHECK_EQ(t.cvt_small_out, static_cast(t.cvt_small_in)); CHECK_EQ(static_cast(t.trunc_big_out), static_cast(t.cvt_big_in)); CHECK_EQ(static_cast(t.trunc_small_out), static_cast(t.cvt_small_in)); } TEST(MIPS14) { // Test round, floor, ceil, trunc, cvt. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); #define ROUND_STRUCT_ELEMENT(x) \ uint32_t x##_isNaN2008; \ int32_t x##_up_out; \ int32_t x##_down_out; \ int32_t neg_##x##_up_out; \ int32_t neg_##x##_down_out; \ uint32_t x##_err1_out; \ uint32_t x##_err2_out; \ uint32_t x##_err3_out; \ uint32_t x##_err4_out; \ int32_t x##_invalid_result; typedef struct { double round_up_in; double round_down_in; double neg_round_up_in; double neg_round_down_in; double err1_in; double err2_in; double err3_in; double err4_in; ROUND_STRUCT_ELEMENT(round) ROUND_STRUCT_ELEMENT(floor) ROUND_STRUCT_ELEMENT(ceil) ROUND_STRUCT_ELEMENT(trunc) ROUND_STRUCT_ELEMENT(cvt) } T; T t; #undef ROUND_STRUCT_ELEMENT MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); // Save FCSR. __ cfc1(a1, FCSR); // Disable FPU exceptions. __ ctc1(zero_reg, FCSR); #define RUN_ROUND_TEST(x) \ __ cfc1(t0, FCSR);\ __ sw(t0, MemOperand(a0, offsetof(T, x##_isNaN2008))); \ __ ldc1(f0, MemOperand(a0, offsetof(T, round_up_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_up_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, round_down_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_down_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, neg_round_up_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, neg_##x##_up_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, neg_round_down_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, neg_##x##_down_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err1_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err1_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err2_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err2_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err3_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err3_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err4_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err4_out))); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_invalid_result))); RUN_ROUND_TEST(round) RUN_ROUND_TEST(floor) RUN_ROUND_TEST(ceil) RUN_ROUND_TEST(trunc) RUN_ROUND_TEST(cvt) // Restore FCSR. __ ctc1(a1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.round_up_in = 123.51; t.round_down_in = 123.49; t.neg_round_up_in = -123.5; t.neg_round_down_in = -123.49; t.err1_in = 123.51; t.err2_in = 1; t.err3_in = static_cast(1) + 0xFFFFFFFF; t.err4_in = NAN; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); #define GET_FPU_ERR(x) (static_cast(x & kFCSRFlagMask)) #define CHECK_NAN2008(x) (x & kFCSRNaN2008FlagMask) #define CHECK_ROUND_RESULT(type) \ CHECK(GET_FPU_ERR(t.type##_err1_out) & kFCSRInexactFlagMask); \ CHECK_EQ(0, GET_FPU_ERR(t.type##_err2_out)); \ CHECK(GET_FPU_ERR(t.type##_err3_out) & kFCSRInvalidOpFlagMask); \ CHECK(GET_FPU_ERR(t.type##_err4_out) & kFCSRInvalidOpFlagMask); \ if (CHECK_NAN2008(t.type##_isNaN2008) && kArchVariant == kMips64r6) { \ CHECK_EQ(static_cast(0), t.type##_invalid_result);\ } else { \ CHECK_EQ(static_cast(kFPUInvalidResult), t.type##_invalid_result);\ } CHECK_ROUND_RESULT(round); CHECK_ROUND_RESULT(floor); CHECK_ROUND_RESULT(ceil); CHECK_ROUND_RESULT(cvt); } TEST(MIPS15) { // Test chaining of label usages within instructions (issue 1644). CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); Assembler assm(isolate, NULL, 0); Label target; __ beq(v0, v1, &target); __ nop(); __ bne(v0, v1, &target); __ nop(); __ bind(&target); __ nop(); } // ----- mips64 tests ----------------------------------------------- TEST(MIPS16) { // Test 64-bit memory loads and stores. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); struct T { int64_t r1; int64_t r2; int64_t r3; int64_t r4; int64_t r5; int64_t r6; int64_t r7; int64_t r8; int64_t r9; int64_t r10; int64_t r11; int64_t r12; uint32_t ui; int32_t si; }; T t; Assembler assm(isolate, NULL, 0); Label L, C; // Basic 32-bit word load/store, with un-signed data. __ lw(a4, MemOperand(a0, offsetof(T, ui))); __ sw(a4, MemOperand(a0, offsetof(T, r1))); // Check that the data got zero-extended into 64-bit a4. __ sd(a4, MemOperand(a0, offsetof(T, r2))); // Basic 32-bit word load/store, with SIGNED data. __ lw(a5, MemOperand(a0, offsetof(T, si))); __ sw(a5, MemOperand(a0, offsetof(T, r3))); // Check that the data got sign-extended into 64-bit a4. __ sd(a5, MemOperand(a0, offsetof(T, r4))); // 32-bit UNSIGNED word load/store, with SIGNED data. __ lwu(a6, MemOperand(a0, offsetof(T, si))); __ sw(a6, MemOperand(a0, offsetof(T, r5))); // Check that the data got zero-extended into 64-bit a4. __ sd(a6, MemOperand(a0, offsetof(T, r6))); // lh with positive data. __ lh(a5, MemOperand(a0, offsetof(T, ui))); __ sw(a5, MemOperand(a0, offsetof(T, r7))); // lh with negative data. __ lh(a6, MemOperand(a0, offsetof(T, si))); __ sw(a6, MemOperand(a0, offsetof(T, r8))); // lhu with negative data. __ lhu(a7, MemOperand(a0, offsetof(T, si))); __ sw(a7, MemOperand(a0, offsetof(T, r9))); // lb with negative data. __ lb(t0, MemOperand(a0, offsetof(T, si))); __ sw(t0, MemOperand(a0, offsetof(T, r10))); // sh writes only 1/2 of word. __ lw(a4, MemOperand(a0, offsetof(T, ui))); __ sh(a4, MemOperand(a0, offsetof(T, r11))); __ lw(a4, MemOperand(a0, offsetof(T, si))); __ sh(a4, MemOperand(a0, offsetof(T, r12))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.ui = 0x44332211; t.si = 0x99aabbcc; t.r1 = 0x5555555555555555; t.r2 = 0x5555555555555555; t.r3 = 0x5555555555555555; t.r4 = 0x5555555555555555; t.r5 = 0x5555555555555555; t.r6 = 0x5555555555555555; t.r7 = 0x5555555555555555; t.r8 = 0x5555555555555555; t.r9 = 0x5555555555555555; t.r10 = 0x5555555555555555; t.r11 = 0x5555555555555555; t.r12 = 0x5555555555555555; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); if (kArchEndian == kLittle) { // Unsigned data, 32 & 64 CHECK_EQ(static_cast(0x5555555544332211L), t.r1); // lw, sw. CHECK_EQ(static_cast(0x0000000044332211L), t.r2); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x5555555599aabbccL), t.r3); // lw, sw. CHECK_EQ(static_cast(0xffffffff99aabbccL), t.r4); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x5555555599aabbccL), t.r5); // lwu, sw. CHECK_EQ(static_cast(0x0000000099aabbccL), t.r6); // sd. // lh with unsigned and signed data. CHECK_EQ(static_cast(0x5555555500002211L), t.r7); // lh, sw. CHECK_EQ(static_cast(0x55555555ffffbbccL), t.r8); // lh, sw. // lhu with signed data. CHECK_EQ(static_cast(0x555555550000bbccL), t.r9); // lhu, sw. // lb with signed data. CHECK_EQ(static_cast(0x55555555ffffffccL), t.r10); // lb, sw. // sh with unsigned and signed data. CHECK_EQ(static_cast(0x5555555555552211L), t.r11); // lw, sh. CHECK_EQ(static_cast(0x555555555555bbccL), t.r12); // lw, sh. } else { // Unsigned data, 32 & 64 CHECK_EQ(static_cast(0x4433221155555555L), t.r1); // lw, sw. CHECK_EQ(static_cast(0x0000000044332211L), t.r2); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x99aabbcc55555555L), t.r3); // lw, sw. CHECK_EQ(static_cast(0xffffffff99aabbccL), t.r4); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x99aabbcc55555555L), t.r5); // lwu, sw. CHECK_EQ(static_cast(0x0000000099aabbccL), t.r6); // sd. // lh with unsigned and signed data. CHECK_EQ(static_cast(0x0000443355555555L), t.r7); // lh, sw. CHECK_EQ(static_cast(0xffff99aa55555555L), t.r8); // lh, sw. // lhu with signed data. CHECK_EQ(static_cast(0x000099aa55555555L), t.r9); // lhu, sw. // lb with signed data. CHECK_EQ(static_cast(0xffffff9955555555L), t.r10); // lb, sw. // sh with unsigned and signed data. CHECK_EQ(static_cast(0x2211555555555555L), t.r11); // lw, sh. CHECK_EQ(static_cast(0xbbcc555555555555L), t.r12); // lw, sh. } } // ----------------------mips64r6 specific tests---------------------- TEST(seleqz_selnez) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { int a; int b; int c; int d; double e; double f; double g; double h; float i; float j; float k; float l; } Test; Test test; // Integer part of test. __ addiu(t1, zero_reg, 1); // t1 = 1 __ seleqz(t3, t1, zero_reg); // t3 = 1 __ sw(t3, MemOperand(a0, offsetof(Test, a))); // a = 1 __ seleqz(t2, t1, t1); // t2 = 0 __ sw(t2, MemOperand(a0, offsetof(Test, b))); // b = 0 __ selnez(t3, t1, zero_reg); // t3 = 1; __ sw(t3, MemOperand(a0, offsetof(Test, c))); // c = 0 __ selnez(t3, t1, t1); // t3 = 1 __ sw(t3, MemOperand(a0, offsetof(Test, d))); // d = 1 // Floating point part of test. __ ldc1(f0, MemOperand(a0, offsetof(Test, e)) ); // src __ ldc1(f2, MemOperand(a0, offsetof(Test, f)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, i)) ); // src __ lwc1(f10, MemOperand(a0, offsetof(Test, j)) ); // test __ seleqz_d(f4, f0, f2); __ selnez_d(f6, f0, f2); __ seleqz_s(f12, f8, f10); __ selnez_s(f14, f8, f10); __ sdc1(f4, MemOperand(a0, offsetof(Test, g)) ); // src __ sdc1(f6, MemOperand(a0, offsetof(Test, h)) ); // src __ swc1(f12, MemOperand(a0, offsetof(Test, k)) ); // src __ swc1(f14, MemOperand(a0, offsetof(Test, l)) ); // src __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.a, 1); CHECK_EQ(test.b, 0); CHECK_EQ(test.c, 0); CHECK_EQ(test.d, 1); const int test_size = 3; const int input_size = 5; double inputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double outputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float inputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float outputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.e = inputs_D[i]; test.f = tests_D[j]; test.i = inputs_S[i]; test.j = tests_S[j]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, outputs_D[i]); CHECK_EQ(test.h, 0); CHECK_EQ(test.k, outputs_S[i]); CHECK_EQ(test.l, 0); test.f = tests_D[j+1]; test.j = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, 0); CHECK_EQ(test.h, outputs_D[i]); CHECK_EQ(test.k, 0); CHECK_EQ(test.l, outputs_S[i]); } } } } TEST(min_max) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); struct TestFloat { double a; double b; double c; double d; float e; float f; float g; float h; }; TestFloat test; const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); const int kTableLength = 13; double inputsa[kTableLength] = {2.0, 3.0, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = {3.0, 2.0, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double outputsdmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double outputsdmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputse[kTableLength] = {2.0, 3.0, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsf[kTableLength] = {3.0, 2.0, 3.0, fnan, 0.0, -0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float outputsfmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float outputsfmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a))); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, b))); __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, e))); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, f))); __ min_d(f10, f4, f8); __ max_d(f12, f4, f8); __ min_s(f14, f2, f6); __ max_s(f16, f2, f6); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, c))); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, d))); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, g))); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, h))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 4; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.e = inputse[i]; test.f = inputsf[i]; CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0); CHECK_EQ(0, memcmp(&test.c, &outputsdmin[i], sizeof(test.c))); CHECK_EQ(0, memcmp(&test.d, &outputsdmax[i], sizeof(test.d))); CHECK_EQ(0, memcmp(&test.g, &outputsfmin[i], sizeof(test.g))); CHECK_EQ(0, memcmp(&test.h, &outputsfmax[i], sizeof(test.h))); } } } TEST(rint_d) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; int fcsr; }TestFloat; TestFloat test; double inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E+308, 6.27463370218383111104242366943E-307, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ ctc1(t0, FCSR); __ rint_d(f8, f4); __ sdc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(sel) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { double dd; double ds; double dt; float fd; float fs; float ft; } Test; Test test; __ ldc1(f0, MemOperand(a0, offsetof(Test, dd)) ); // test __ ldc1(f2, MemOperand(a0, offsetof(Test, ds)) ); // src1 __ ldc1(f4, MemOperand(a0, offsetof(Test, dt)) ); // src2 __ lwc1(f6, MemOperand(a0, offsetof(Test, fd)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, fs)) ); // src1 __ lwc1(f10, MemOperand(a0, offsetof(Test, ft)) ); // src2 __ sel_d(f0, f2, f4); __ sel_s(f6, f8, f10); __ sdc1(f0, MemOperand(a0, offsetof(Test, dd)) ); __ swc1(f6, MemOperand(a0, offsetof(Test, fd)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); const int test_size = 3; const int input_size = 5; double inputs_dt[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double inputs_ds[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; float inputs_ft[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float inputs_fs[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.dt = inputs_dt[i]; test.dd = tests_D[j]; test.ds = inputs_ds[i]; test.ft = inputs_ft[i]; test.fd = tests_S[j]; test.fs = inputs_fs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_ds[i]); CHECK_EQ(test.fd, inputs_fs[i]); test.dd = tests_D[j+1]; test.fd = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_dt[i]); CHECK_EQ(test.fd, inputs_ft[i]); } } } } TEST(rint_s) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; int fcsr; }TestFloat; TestFloat test; float inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E+38, 6.27463370218383111104242366943E-37, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; float* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ rint_s(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(mina_maxa) { if (kArchVariant == kMips64r6) { const int kTableLength = 23; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); struct TestFloat { double a; double b; double resd; double resd1; float c; float d; float resf; float resf1; }; TestFloat test; double inputsa[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = { 4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double resd[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double resd1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputsc[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsd[kTableLength] = {4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, fnan, -0.0, 0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float resf[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float resf1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ lwc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ lwc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ mina_d(f6, f2, f4); __ mina_s(f12, f8, f10); __ maxa_d(f14, f2, f4); __ maxa_s(f16, f8, f10); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, resf)) ); __ sdc1(f6, MemOperand(a0, offsetof(TestFloat, resd)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resf1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resd1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.c = inputsc[i]; test.d = inputsd[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if (i < kTableLength - 1) { CHECK_EQ(test.resd, resd[i]); CHECK_EQ(test.resf, resf[i]); CHECK_EQ(test.resd1, resd1[i]); CHECK_EQ(test.resf1, resf1[i]); } else { CHECK(std::isnan(test.resd)); CHECK(std::isnan(test.resf)); CHECK(std::isnan(test.resd1)); CHECK(std::isnan(test.resf1)); } } } } // ----------------------mips64r2 specific tests---------------------- TEST(trunc_l) { if (kArchVariant == kMips64r2) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; // a trunc result int64_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_l_d(f8, f4); __ trunc_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } } TEST(movz_movn) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { int64_t rt; double a; double b; double bold; double b1; double bold1; float c; float d; float dold; float d1; float dold1; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ld(t0, MemOperand(a0, offsetof(TestFloat, rt))); __ Move(f12, 0.0); __ Move(f10, 0.0); __ Move(f16, 0.0); __ Move(f14, 0.0); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, bold)) ); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, dold)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, bold1)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, dold1)) ); __ movz_s(f10, f6, t0); __ movz_d(f12, f2, t0); __ movn_s(f14, f6, t0); __ movn_d(f16, f2, t0); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, b)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, d1)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, b1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; test.rt = 1; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, test.bold); CHECK_EQ(test.d, test.dold); CHECK_EQ(test.b1, outputs_D[i]); CHECK_EQ(test.d1, outputs_S[i]); test.rt = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); CHECK_EQ(test.b1, test.bold1); CHECK_EQ(test.d1, test.dold1); } } } TEST(movt_movd) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); typedef struct test_float { double srcd; double dstd; double dstdold; double dstd1; double dstdold1; float srcf; float dstf; float dstfold; float dstf1; float dstfold1; int32_t cc; int32_t fcsr; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; double inputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; int condition_flags[8] = {0, 1, 2, 3, 4, 5, 6, 7}; for (int i = 0; i < kTableLength; i++) { test.srcd = inputs_D[i]; test.srcf = inputs_S[i]; for (int j = 0; j< 8; j++) { test.cc = condition_flags[j]; if (test.cc == 0) { test.fcsr = 1 << 23; } else { test.fcsr = 1 << (24+condition_flags[j]); } HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, srcd)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, srcf)) ); __ lw(t1, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t0, FCSR); __ ctc1(t1, FCSR); __ li(t2, 0x0); __ mtc1(t2, f12); __ mtc1(t2, f10); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold)) ); __ movt_s(f12, f4, test.cc); __ movt_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold1)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold1)) ); __ movf_s(f12, f4, test.cc); __ movf_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf1)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd1)) ); __ ctc1(t0, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, outputs_S[i]); CHECK_EQ(test.dstd, outputs_D[i]); CHECK_EQ(test.dstf1, test.dstfold1); CHECK_EQ(test.dstd1, test.dstdold1); test.fcsr = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, test.dstfold); CHECK_EQ(test.dstd, test.dstdold); CHECK_EQ(test.dstf1, outputs_S[i]); CHECK_EQ(test.dstd1, outputs_D[i]); } } } } // ----------------------tests for all archs-------------------------- TEST(cvt_w_d) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; int32_t b; int fcsr; }Test; const int kTableLength = 24; double inputs[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, 2147483653.0 }; double outputs_RN[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RZ[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RP[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RM[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lw(t0, MemOperand(a0, offsetof(Test, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ cvt_w_d(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(Test, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } TEST(trunc_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_w_d(f8, f4); __ trunc_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_w_d(f8, f4); __ round_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_l_d(f8, f4); __ round_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(sub) { const int kTableLength = 12; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; double inputft_D[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; double outputs_D[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; float inputfs_S[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; float inputft_S[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; float outputs_S[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sub_s(f6, f2, f4); __ sub_d(f12, f8, f10); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(sqrt_rsqrt_recip) { const int kTableLength = 4; const double deltaDouble = 2E-15; const float deltaFloat = 2E-7; const float sqrt2_s = sqrt(2); const double sqrt2_d = sqrt(2); CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; float resultS1; float resultS2; double c; double resultD; double resultD1; double resultD2; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 0.0L, 4.0L, 2.0L, 4e-28L }; double outputs_D[kTableLength] = { 0.0L, 2.0L, sqrt2_d, 2e-14L }; float inputs_S[kTableLength] = { 0.0, 4.0, 2.0, 4e-28 }; float outputs_S[kTableLength] = { 0.0, 2.0, sqrt2_s, 2e-14 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ sqrt_s(f6, f2); __ sqrt_d(f12, f8); __ rsqrt_d(f14, f8); __ rsqrt_s(f16, f2); __ recip_d(f18, f8); __ recip_s(f4, f2); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resultS1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resultD1)) ); __ swc1(f4, MemOperand(a0, offsetof(TestFloat, resultS2)) ); __ sdc1(f18, MemOperand(a0, offsetof(TestFloat, resultD2)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { float f1; double d1; test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); if (i != 0) { f1 = test.resultS1 - 1.0F/outputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD1 - 1.0L/outputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); f1 = test.resultS2 - 1.0F/inputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD2 - 1.0L/inputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); } else { CHECK_EQ(test.resultS1, 1.0F/outputs_S[i]); CHECK_EQ(test.resultD1, 1.0L/outputs_D[i]); CHECK_EQ(test.resultS2, 1.0F/inputs_S[i]); CHECK_EQ(test.resultD2, 1.0L/inputs_D[i]); } } } TEST(neg) { const int kTableLength = 2; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; double c; double resultD; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 4.0, -2.0 }; double outputs_D[kTableLength] = { -4.0, 2.0 }; float inputs_S[kTableLength] = { 4.0, -2.0 }; float outputs_S[kTableLength] = { -4.0, 2.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ neg_s(f6, f2); __ neg_d(f12, f8); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.a = 1.5e14; t.b = 2.75e11; t.c = 2.0; t.d = -4.0; t.e = 0.0; t.f = 0.0; t.result = 0; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(1.5e14, t.a); CHECK_EQ(2.75e11, t.b); CHECK_EQ(1, t.result); } TEST(MIPS8) { if (kArchVariant == kMips64r2) { // Test ROTR and ROTRV instructions. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { int32_t input; int32_t result_rotr_4; int32_t result_rotr_8; int32_t result_rotr_12; int32_t result_rotr_16; int32_t result_rotr_20; int32_t result_rotr_24; int32_t result_rotr_28; int32_t result_rotrv_4; int32_t result_rotrv_8; int32_t result_rotrv_12; int32_t result_rotrv_16; int32_t result_rotrv_20; int32_t result_rotrv_24; int32_t result_rotrv_28; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); // Basic word load. __ lw(a4, MemOperand(a0, offsetof(T, input)) ); // ROTR instruction (called through the Ror macro). __ Ror(a5, a4, 0x0004); __ Ror(a6, a4, 0x0008); __ Ror(a7, a4, 0x000c); __ Ror(t0, a4, 0x0010); __ Ror(t1, a4, 0x0014); __ Ror(t2, a4, 0x0018); __ Ror(t3, a4, 0x001c); // Basic word store. __ sw(a5, MemOperand(a0, offsetof(T, result_rotr_4)) ); __ sw(a6, MemOperand(a0, offsetof(T, result_rotr_8)) ); __ sw(a7, MemOperand(a0, offsetof(T, result_rotr_12)) ); __ sw(t0, MemOperand(a0, offsetof(T, result_rotr_16)) ); __ sw(t1, MemOperand(a0, offsetof(T, result_rotr_20)) ); __ sw(t2, MemOperand(a0, offsetof(T, result_rotr_24)) ); __ sw(t3, MemOperand(a0, offsetof(T, result_rotr_28)) ); // ROTRV instruction (called through the Ror macro). __ li(t3, 0x0004); __ Ror(a5, a4, t3); __ li(t3, 0x0008); __ Ror(a6, a4, t3); __ li(t3, 0x000C); __ Ror(a7, a4, t3); __ li(t3, 0x0010); __ Ror(t0, a4, t3); __ li(t3, 0x0014); __ Ror(t1, a4, t3); __ li(t3, 0x0018); __ Ror(t2, a4, t3); __ li(t3, 0x001C); __ Ror(t3, a4, t3); // Basic word store. __ sw(a5, MemOperand(a0, offsetof(T, result_rotrv_4)) ); __ sw(a6, MemOperand(a0, offsetof(T, result_rotrv_8)) ); __ sw(a7, MemOperand(a0, offsetof(T, result_rotrv_12)) ); __ sw(t0, MemOperand(a0, offsetof(T, result_rotrv_16)) ); __ sw(t1, MemOperand(a0, offsetof(T, result_rotrv_20)) ); __ sw(t2, MemOperand(a0, offsetof(T, result_rotrv_24)) ); __ sw(t3, MemOperand(a0, offsetof(T, result_rotrv_28)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.input = 0x12345678; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0x0, 0, 0, 0); USE(dummy); CHECK_EQ(static_cast(0x81234567), t.result_rotr_4); CHECK_EQ(static_cast(0x78123456), t.result_rotr_8); CHECK_EQ(static_cast(0x67812345), t.result_rotr_12); CHECK_EQ(static_cast(0x56781234), t.result_rotr_16); CHECK_EQ(static_cast(0x45678123), t.result_rotr_20); CHECK_EQ(static_cast(0x34567812), t.result_rotr_24); CHECK_EQ(static_cast(0x23456781), t.result_rotr_28); CHECK_EQ(static_cast(0x81234567), t.result_rotrv_4); CHECK_EQ(static_cast(0x78123456), t.result_rotrv_8); CHECK_EQ(static_cast(0x67812345), t.result_rotrv_12); CHECK_EQ(static_cast(0x56781234), t.result_rotrv_16); CHECK_EQ(static_cast(0x45678123), t.result_rotrv_20); CHECK_EQ(static_cast(0x34567812), t.result_rotrv_24); CHECK_EQ(static_cast(0x23456781), t.result_rotrv_28); } } TEST(MIPS9) { // Test BRANCH improvements. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); Label exit, exit2, exit3; __ Branch(&exit, ge, a0, Operand(zero_reg)); __ Branch(&exit2, ge, a0, Operand(0x00001FFF)); __ Branch(&exit3, ge, a0, Operand(0x0001FFFF)); __ bind(&exit); __ bind(&exit2); __ bind(&exit3); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); } TEST(MIPS10) { // Test conversions between doubles and long integers. // Test hos the long ints map to FP regs pairs. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double a; double a_converted; double b; int32_t dbl_mant; int32_t dbl_exp; int32_t long_hi; int32_t long_lo; int64_t long_as_int64; int32_t b_long_hi; int32_t b_long_lo; int64_t b_long_as_int64; } T; T t; Assembler assm(isolate, NULL, 0); Label L, C; if (kArchVariant == kMips64r2) { // Rewritten for FR=1 FPU mode: // - 32 FP regs of 64-bits each, no odd/even pairs. // - Note that cvt_l_d/cvt_d_l ARE legal in FR=1 mode. // Load all structure elements to registers. __ ldc1(f0, MemOperand(a0, offsetof(T, a))); // Save the raw bits of the double. __ mfc1(a4, f0); __ mfhc1(a5, f0); __ sw(a4, MemOperand(a0, offsetof(T, dbl_mant))); __ sw(a5, MemOperand(a0, offsetof(T, dbl_exp))); // Convert double in f0 to long, save hi/lo parts. __ cvt_l_d(f0, f0); __ mfc1(a4, f0); // f0 LS 32 bits of long. __ mfhc1(a5, f0); // f0 MS 32 bits of long. __ sw(a4, MemOperand(a0, offsetof(T, long_lo))); __ sw(a5, MemOperand(a0, offsetof(T, long_hi))); // Combine the high/low ints, convert back to double. __ dsll32(a6, a5, 0); // Move a5 to high bits of a6. __ or_(a6, a6, a4); __ dmtc1(a6, f1); __ cvt_d_l(f1, f1); __ sdc1(f1, MemOperand(a0, offsetof(T, a_converted))); // Convert the b long integers to double b. __ lw(a4, MemOperand(a0, offsetof(T, b_long_lo))); __ lw(a5, MemOperand(a0, offsetof(T, b_long_hi))); __ mtc1(a4, f8); // f8 LS 32-bits. __ mthc1(a5, f8); // f8 MS 32-bits. __ cvt_d_l(f10, f8); __ sdc1(f10, MemOperand(a0, offsetof(T, b))); // Convert double b back to long-int. __ ldc1(f31, MemOperand(a0, offsetof(T, b))); __ cvt_l_d(f31, f31); __ dmfc1(a7, f31); __ sd(a7, MemOperand(a0, offsetof(T, b_long_as_int64))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.a = 2.147483647e9; // 0x7fffffff -> 0x41DFFFFFFFC00000 as double. t.b_long_hi = 0x000000ff; // 0xFF00FF00FF -> 0x426FE01FE01FE000 as double. t.b_long_lo = 0x00ff00ff; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(static_cast(0x41DFFFFF), t.dbl_exp); CHECK_EQ(static_cast(0xFFC00000), t.dbl_mant); CHECK_EQ(0, t.long_hi); CHECK_EQ(static_cast(0x7fffffff), t.long_lo); CHECK_EQ(2.147483647e9, t.a_converted); // 0xFF00FF00FF -> 1.095233372415e12. CHECK_EQ(1.095233372415e12, t.b); CHECK_EQ(static_cast(0xFF00FF00FF), t.b_long_as_int64); } } TEST(MIPS11) { // Do not run test on MIPS64r6, as these instructions are removed. if (kArchVariant != kMips64r6) { // Test LWL, LWR, SWL and SWR instructions. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { int32_t reg_init; int32_t mem_init; int32_t lwl_0; int32_t lwl_1; int32_t lwl_2; int32_t lwl_3; int32_t lwr_0; int32_t lwr_1; int32_t lwr_2; int32_t lwr_3; int32_t swl_0; int32_t swl_1; int32_t swl_2; int32_t swl_3; int32_t swr_0; int32_t swr_1; int32_t swr_2; int32_t swr_3; } T; T t; Assembler assm(isolate, NULL, 0); // Test all combinations of LWL and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, lwl_0))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a5, MemOperand(a0, offsetof(T, mem_init) + 1)); __ sw(a5, MemOperand(a0, offsetof(T, lwl_1))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a6, MemOperand(a0, offsetof(T, mem_init) + 2)); __ sw(a6, MemOperand(a0, offsetof(T, lwl_2))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a7, MemOperand(a0, offsetof(T, mem_init) + 3)); __ sw(a7, MemOperand(a0, offsetof(T, lwl_3))); // Test all combinations of LWR and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, lwr_0))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a5, MemOperand(a0, offsetof(T, mem_init) + 1)); __ sw(a5, MemOperand(a0, offsetof(T, lwr_1))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a6, MemOperand(a0, offsetof(T, mem_init) + 2)); __ sw(a6, MemOperand(a0, offsetof(T, lwr_2)) ); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a7, MemOperand(a0, offsetof(T, mem_init) + 3)); __ sw(a7, MemOperand(a0, offsetof(T, lwr_3)) ); // Test all combinations of SWL and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, swl_0))); __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ swl(a4, MemOperand(a0, offsetof(T, swl_0))); __ lw(a5, MemOperand(a0, offsetof(T, mem_init))); __ sw(a5, MemOperand(a0, offsetof(T, swl_1))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ swl(a5, MemOperand(a0, offsetof(T, swl_1) + 1)); __ lw(a6, MemOperand(a0, offsetof(T, mem_init))); __ sw(a6, MemOperand(a0, offsetof(T, swl_2))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ swl(a6, MemOperand(a0, offsetof(T, swl_2) + 2)); __ lw(a7, MemOperand(a0, offsetof(T, mem_init))); __ sw(a7, MemOperand(a0, offsetof(T, swl_3))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ swl(a7, MemOperand(a0, offsetof(T, swl_3) + 3)); // Test all combinations of SWR and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, swr_0))); __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ swr(a4, MemOperand(a0, offsetof(T, swr_0))); __ lw(a5, MemOperand(a0, offsetof(T, mem_init))); __ sw(a5, MemOperand(a0, offsetof(T, swr_1))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ swr(a5, MemOperand(a0, offsetof(T, swr_1) + 1)); __ lw(a6, MemOperand(a0, offsetof(T, mem_init))); __ sw(a6, MemOperand(a0, offsetof(T, swr_2))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ swr(a6, MemOperand(a0, offsetof(T, swr_2) + 2)); __ lw(a7, MemOperand(a0, offsetof(T, mem_init))); __ sw(a7, MemOperand(a0, offsetof(T, swr_3))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ swr(a7, MemOperand(a0, offsetof(T, swr_3) + 3)); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.reg_init = 0xaabbccdd; t.mem_init = 0x11223344; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); if (kArchEndian == kLittle) { CHECK_EQ(static_cast(0x44bbccdd), t.lwl_0); CHECK_EQ(static_cast(0x3344ccdd), t.lwl_1); CHECK_EQ(static_cast(0x223344dd), t.lwl_2); CHECK_EQ(static_cast(0x11223344), t.lwl_3); CHECK_EQ(static_cast(0x11223344), t.lwr_0); CHECK_EQ(static_cast(0xaa112233), t.lwr_1); CHECK_EQ(static_cast(0xaabb1122), t.lwr_2); CHECK_EQ(static_cast(0xaabbcc11), t.lwr_3); CHECK_EQ(static_cast(0x112233aa), t.swl_0); CHECK_EQ(static_cast(0x1122aabb), t.swl_1); CHECK_EQ(static_cast(0x11aabbcc), t.swl_2); CHECK_EQ(static_cast(0xaabbccdd), t.swl_3); CHECK_EQ(static_cast(0xaabbccdd), t.swr_0); CHECK_EQ(static_cast(0xbbccdd44), t.swr_1); CHECK_EQ(static_cast(0xccdd3344), t.swr_2); CHECK_EQ(static_cast(0xdd223344), t.swr_3); } else { CHECK_EQ(static_cast(0x11223344), t.lwl_0); CHECK_EQ(static_cast(0x223344dd), t.lwl_1); CHECK_EQ(static_cast(0x3344ccdd), t.lwl_2); CHECK_EQ(static_cast(0x44bbccdd), t.lwl_3); CHECK_EQ(static_cast(0xaabbcc11), t.lwr_0); CHECK_EQ(static_cast(0xaabb1122), t.lwr_1); CHECK_EQ(static_cast(0xaa112233), t.lwr_2); CHECK_EQ(static_cast(0x11223344), t.lwr_3); CHECK_EQ(static_cast(0xaabbccdd), t.swl_0); CHECK_EQ(static_cast(0x11aabbcc), t.swl_1); CHECK_EQ(static_cast(0x1122aabb), t.swl_2); CHECK_EQ(static_cast(0x112233aa), t.swl_3); CHECK_EQ(static_cast(0xdd223344), t.swr_0); CHECK_EQ(static_cast(0xccdd3344), t.swr_1); CHECK_EQ(static_cast(0xbbccdd44), t.swr_2); CHECK_EQ(static_cast(0xaabbccdd), t.swr_3); } } } TEST(MIPS12) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { int32_t x; int32_t y; int32_t y1; int32_t y2; int32_t y3; int32_t y4; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ mov(t2, fp); // Save frame pointer. __ mov(fp, a0); // Access struct T by fp. __ lw(a4, MemOperand(a0, offsetof(T, y))); __ lw(a7, MemOperand(a0, offsetof(T, y4))); __ addu(a5, a4, a7); __ subu(t0, a4, a7); __ nop(); __ push(a4); // These instructions disappear after opt. __ Pop(); __ addu(a4, a4, a4); __ nop(); __ Pop(); // These instructions disappear after opt. __ push(a7); __ nop(); __ push(a7); // These instructions disappear after opt. __ pop(a7); __ nop(); __ push(a7); __ pop(t0); __ nop(); __ sw(a4, MemOperand(fp, offsetof(T, y))); __ lw(a4, MemOperand(fp, offsetof(T, y))); __ nop(); __ sw(a4, MemOperand(fp, offsetof(T, y))); __ lw(a5, MemOperand(fp, offsetof(T, y))); __ nop(); __ push(a5); __ lw(a5, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a6); __ nop(); __ push(a6); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a7); __ nop(); __ mov(fp, t2); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.x = 1; t.y = 2; t.y1 = 3; t.y2 = 4; t.y3 = 0XBABA; t.y4 = 0xDEDA; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(3, t.y1); } TEST(MIPS13) { // Test Cvt_d_uw and Trunc_uw_d macros. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double cvt_big_out; double cvt_small_out; uint32_t trunc_big_out; uint32_t trunc_small_out; uint32_t cvt_big_in; uint32_t cvt_small_in; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ sw(a4, MemOperand(a0, offsetof(T, cvt_small_in))); __ Cvt_d_uw(f10, a4); __ sdc1(f10, MemOperand(a0, offsetof(T, cvt_small_out))); __ Trunc_uw_d(f10, f10, f4); __ swc1(f10, MemOperand(a0, offsetof(T, trunc_small_out))); __ sw(a4, MemOperand(a0, offsetof(T, cvt_big_in))); __ Cvt_d_uw(f8, a4); __ sdc1(f8, MemOperand(a0, offsetof(T, cvt_big_out))); __ Trunc_uw_d(f8, f8, f4); __ swc1(f8, MemOperand(a0, offsetof(T, trunc_big_out))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.cvt_big_in = 0xFFFFFFFF; t.cvt_small_in = 333; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(t.cvt_big_out, static_cast(t.cvt_big_in)); CHECK_EQ(t.cvt_small_out, static_cast(t.cvt_small_in)); CHECK_EQ(static_cast(t.trunc_big_out), static_cast(t.cvt_big_in)); CHECK_EQ(static_cast(t.trunc_small_out), static_cast(t.cvt_small_in)); } TEST(MIPS14) { // Test round, floor, ceil, trunc, cvt. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); #define ROUND_STRUCT_ELEMENT(x) \ uint32_t x##_isNaN2008; \ int32_t x##_up_out; \ int32_t x##_down_out; \ int32_t neg_##x##_up_out; \ int32_t neg_##x##_down_out; \ uint32_t x##_err1_out; \ uint32_t x##_err2_out; \ uint32_t x##_err3_out; \ uint32_t x##_err4_out; \ int32_t x##_invalid_result; typedef struct { double round_up_in; double round_down_in; double neg_round_up_in; double neg_round_down_in; double err1_in; double err2_in; double err3_in; double err4_in; ROUND_STRUCT_ELEMENT(round) ROUND_STRUCT_ELEMENT(floor) ROUND_STRUCT_ELEMENT(ceil) ROUND_STRUCT_ELEMENT(trunc) ROUND_STRUCT_ELEMENT(cvt) } T; T t; #undef ROUND_STRUCT_ELEMENT MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); // Save FCSR. __ cfc1(a1, FCSR); // Disable FPU exceptions. __ ctc1(zero_reg, FCSR); #define RUN_ROUND_TEST(x) \ __ cfc1(t0, FCSR);\ __ sw(t0, MemOperand(a0, offsetof(T, x##_isNaN2008))); \ __ ldc1(f0, MemOperand(a0, offsetof(T, round_up_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_up_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, round_down_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_down_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, neg_round_up_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, neg_##x##_up_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, neg_round_down_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, neg_##x##_down_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err1_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err1_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err2_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err2_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err3_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err3_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err4_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err4_out))); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_invalid_result))); RUN_ROUND_TEST(round) RUN_ROUND_TEST(floor) RUN_ROUND_TEST(ceil) RUN_ROUND_TEST(trunc) RUN_ROUND_TEST(cvt) // Restore FCSR. __ ctc1(a1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.round_up_in = 123.51; t.round_down_in = 123.49; t.neg_round_up_in = -123.5; t.neg_round_down_in = -123.49; t.err1_in = 123.51; t.err2_in = 1; t.err3_in = static_cast(1) + 0xFFFFFFFF; t.err4_in = NAN; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); #define GET_FPU_ERR(x) (static_cast(x & kFCSRFlagMask)) #define CHECK_NAN2008(x) (x & kFCSRNaN2008FlagMask) #define CHECK_ROUND_RESULT(type) \ CHECK(GET_FPU_ERR(t.type##_err1_out) & kFCSRInexactFlagMask); \ CHECK_EQ(0, GET_FPU_ERR(t.type##_err2_out)); \ CHECK(GET_FPU_ERR(t.type##_err3_out) & kFCSRInvalidOpFlagMask); \ CHECK(GET_FPU_ERR(t.type##_err4_out) & kFCSRInvalidOpFlagMask); \ if (CHECK_NAN2008(t.type##_isNaN2008) && kArchVariant == kMips64r6) { \ CHECK_EQ(static_cast(0), t.type##_invalid_result);\ } else { \ CHECK_EQ(static_cast(kFPUInvalidResult), t.type##_invalid_result);\ } CHECK_ROUND_RESULT(round); CHECK_ROUND_RESULT(floor); CHECK_ROUND_RESULT(ceil); CHECK_ROUND_RESULT(cvt); } TEST(MIPS15) { // Test chaining of label usages within instructions (issue 1644). CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); Assembler assm(isolate, NULL, 0); Label target; __ beq(v0, v1, &target); __ nop(); __ bne(v0, v1, &target); __ nop(); __ bind(&target); __ nop(); } // ----- mips64 tests ----------------------------------------------- TEST(MIPS16) { // Test 64-bit memory loads and stores. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); struct T { int64_t r1; int64_t r2; int64_t r3; int64_t r4; int64_t r5; int64_t r6; int64_t r7; int64_t r8; int64_t r9; int64_t r10; int64_t r11; int64_t r12; uint32_t ui; int32_t si; }; T t; Assembler assm(isolate, NULL, 0); Label L, C; // Basic 32-bit word load/store, with un-signed data. __ lw(a4, MemOperand(a0, offsetof(T, ui))); __ sw(a4, MemOperand(a0, offsetof(T, r1))); // Check that the data got zero-extended into 64-bit a4. __ sd(a4, MemOperand(a0, offsetof(T, r2))); // Basic 32-bit word load/store, with SIGNED data. __ lw(a5, MemOperand(a0, offsetof(T, si))); __ sw(a5, MemOperand(a0, offsetof(T, r3))); // Check that the data got sign-extended into 64-bit a4. __ sd(a5, MemOperand(a0, offsetof(T, r4))); // 32-bit UNSIGNED word load/store, with SIGNED data. __ lwu(a6, MemOperand(a0, offsetof(T, si))); __ sw(a6, MemOperand(a0, offsetof(T, r5))); // Check that the data got zero-extended into 64-bit a4. __ sd(a6, MemOperand(a0, offsetof(T, r6))); // lh with positive data. __ lh(a5, MemOperand(a0, offsetof(T, ui))); __ sw(a5, MemOperand(a0, offsetof(T, r7))); // lh with negative data. __ lh(a6, MemOperand(a0, offsetof(T, si))); __ sw(a6, MemOperand(a0, offsetof(T, r8))); // lhu with negative data. __ lhu(a7, MemOperand(a0, offsetof(T, si))); __ sw(a7, MemOperand(a0, offsetof(T, r9))); // lb with negative data. __ lb(t0, MemOperand(a0, offsetof(T, si))); __ sw(t0, MemOperand(a0, offsetof(T, r10))); // sh writes only 1/2 of word. __ lw(a4, MemOperand(a0, offsetof(T, ui))); __ sh(a4, MemOperand(a0, offsetof(T, r11))); __ lw(a4, MemOperand(a0, offsetof(T, si))); __ sh(a4, MemOperand(a0, offsetof(T, r12))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.ui = 0x44332211; t.si = 0x99aabbcc; t.r1 = 0x5555555555555555; t.r2 = 0x5555555555555555; t.r3 = 0x5555555555555555; t.r4 = 0x5555555555555555; t.r5 = 0x5555555555555555; t.r6 = 0x5555555555555555; t.r7 = 0x5555555555555555; t.r8 = 0x5555555555555555; t.r9 = 0x5555555555555555; t.r10 = 0x5555555555555555; t.r11 = 0x5555555555555555; t.r12 = 0x5555555555555555; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); if (kArchEndian == kLittle) { // Unsigned data, 32 & 64 CHECK_EQ(static_cast(0x5555555544332211L), t.r1); // lw, sw. CHECK_EQ(static_cast(0x0000000044332211L), t.r2); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x5555555599aabbccL), t.r3); // lw, sw. CHECK_EQ(static_cast(0xffffffff99aabbccL), t.r4); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x5555555599aabbccL), t.r5); // lwu, sw. CHECK_EQ(static_cast(0x0000000099aabbccL), t.r6); // sd. // lh with unsigned and signed data. CHECK_EQ(static_cast(0x5555555500002211L), t.r7); // lh, sw. CHECK_EQ(static_cast(0x55555555ffffbbccL), t.r8); // lh, sw. // lhu with signed data. CHECK_EQ(static_cast(0x555555550000bbccL), t.r9); // lhu, sw. // lb with signed data. CHECK_EQ(static_cast(0x55555555ffffffccL), t.r10); // lb, sw. // sh with unsigned and signed data. CHECK_EQ(static_cast(0x5555555555552211L), t.r11); // lw, sh. CHECK_EQ(static_cast(0x555555555555bbccL), t.r12); // lw, sh. } else { // Unsigned data, 32 & 64 CHECK_EQ(static_cast(0x4433221155555555L), t.r1); // lw, sw. CHECK_EQ(static_cast(0x0000000044332211L), t.r2); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x99aabbcc55555555L), t.r3); // lw, sw. CHECK_EQ(static_cast(0xffffffff99aabbccL), t.r4); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x99aabbcc55555555L), t.r5); // lwu, sw. CHECK_EQ(static_cast(0x0000000099aabbccL), t.r6); // sd. // lh with unsigned and signed data. CHECK_EQ(static_cast(0x0000443355555555L), t.r7); // lh, sw. CHECK_EQ(static_cast(0xffff99aa55555555L), t.r8); // lh, sw. // lhu with signed data. CHECK_EQ(static_cast(0x000099aa55555555L), t.r9); // lhu, sw. // lb with signed data. CHECK_EQ(static_cast(0xffffff9955555555L), t.r10); // lb, sw. // sh with unsigned and signed data. CHECK_EQ(static_cast(0x2211555555555555L), t.r11); // lw, sh. CHECK_EQ(static_cast(0xbbcc555555555555L), t.r12); // lw, sh. } } // ----------------------mips64r6 specific tests---------------------- TEST(seleqz_selnez) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { int a; int b; int c; int d; double e; double f; double g; double h; float i; float j; float k; float l; } Test; Test test; // Integer part of test. __ addiu(t1, zero_reg, 1); // t1 = 1 __ seleqz(t3, t1, zero_reg); // t3 = 1 __ sw(t3, MemOperand(a0, offsetof(Test, a))); // a = 1 __ seleqz(t2, t1, t1); // t2 = 0 __ sw(t2, MemOperand(a0, offsetof(Test, b))); // b = 0 __ selnez(t3, t1, zero_reg); // t3 = 1; __ sw(t3, MemOperand(a0, offsetof(Test, c))); // c = 0 __ selnez(t3, t1, t1); // t3 = 1 __ sw(t3, MemOperand(a0, offsetof(Test, d))); // d = 1 // Floating point part of test. __ ldc1(f0, MemOperand(a0, offsetof(Test, e)) ); // src __ ldc1(f2, MemOperand(a0, offsetof(Test, f)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, i)) ); // src __ lwc1(f10, MemOperand(a0, offsetof(Test, j)) ); // test __ seleqz_d(f4, f0, f2); __ selnez_d(f6, f0, f2); __ seleqz_s(f12, f8, f10); __ selnez_s(f14, f8, f10); __ sdc1(f4, MemOperand(a0, offsetof(Test, g)) ); // src __ sdc1(f6, MemOperand(a0, offsetof(Test, h)) ); // src __ swc1(f12, MemOperand(a0, offsetof(Test, k)) ); // src __ swc1(f14, MemOperand(a0, offsetof(Test, l)) ); // src __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.a, 1); CHECK_EQ(test.b, 0); CHECK_EQ(test.c, 0); CHECK_EQ(test.d, 1); const int test_size = 3; const int input_size = 5; double inputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double outputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float inputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float outputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.e = inputs_D[i]; test.f = tests_D[j]; test.i = inputs_S[i]; test.j = tests_S[j]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, outputs_D[i]); CHECK_EQ(test.h, 0); CHECK_EQ(test.k, outputs_S[i]); CHECK_EQ(test.l, 0); test.f = tests_D[j+1]; test.j = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, 0); CHECK_EQ(test.h, outputs_D[i]); CHECK_EQ(test.k, 0); CHECK_EQ(test.l, outputs_S[i]); } } } } TEST(min_max) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); struct TestFloat { double a; double b; double c; double d; float e; float f; float g; float h; }; TestFloat test; const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); const int kTableLength = 13; double inputsa[kTableLength] = {2.0, 3.0, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = {3.0, 2.0, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double outputsdmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double outputsdmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputse[kTableLength] = {2.0, 3.0, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsf[kTableLength] = {3.0, 2.0, 3.0, fnan, 0.0, -0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float outputsfmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float outputsfmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a))); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, b))); __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, e))); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, f))); __ min_d(f10, f4, f8); __ max_d(f12, f4, f8); __ min_s(f14, f2, f6); __ max_s(f16, f2, f6); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, c))); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, d))); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, g))); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, h))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 4; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.e = inputse[i]; test.f = inputsf[i]; CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0); CHECK_EQ(0, memcmp(&test.c, &outputsdmin[i], sizeof(test.c))); CHECK_EQ(0, memcmp(&test.d, &outputsdmax[i], sizeof(test.d))); CHECK_EQ(0, memcmp(&test.g, &outputsfmin[i], sizeof(test.g))); CHECK_EQ(0, memcmp(&test.h, &outputsfmax[i], sizeof(test.h))); } } } TEST(rint_d) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; int fcsr; }TestFloat; TestFloat test; double inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E+308, 6.27463370218383111104242366943E-307, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ ctc1(t0, FCSR); __ rint_d(f8, f4); __ sdc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(sel) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { double dd; double ds; double dt; float fd; float fs; float ft; } Test; Test test; __ ldc1(f0, MemOperand(a0, offsetof(Test, dd)) ); // test __ ldc1(f2, MemOperand(a0, offsetof(Test, ds)) ); // src1 __ ldc1(f4, MemOperand(a0, offsetof(Test, dt)) ); // src2 __ lwc1(f6, MemOperand(a0, offsetof(Test, fd)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, fs)) ); // src1 __ lwc1(f10, MemOperand(a0, offsetof(Test, ft)) ); // src2 __ sel_d(f0, f2, f4); __ sel_s(f6, f8, f10); __ sdc1(f0, MemOperand(a0, offsetof(Test, dd)) ); __ swc1(f6, MemOperand(a0, offsetof(Test, fd)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); const int test_size = 3; const int input_size = 5; double inputs_dt[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double inputs_ds[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; float inputs_ft[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float inputs_fs[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.dt = inputs_dt[i]; test.dd = tests_D[j]; test.ds = inputs_ds[i]; test.ft = inputs_ft[i]; test.fd = tests_S[j]; test.fs = inputs_fs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_ds[i]); CHECK_EQ(test.fd, inputs_fs[i]); test.dd = tests_D[j+1]; test.fd = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_dt[i]); CHECK_EQ(test.fd, inputs_ft[i]); } } } } TEST(rint_s) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; int fcsr; }TestFloat; TestFloat test; float inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E+38, 6.27463370218383111104242366943E-37, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; float* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ rint_s(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(mina_maxa) { if (kArchVariant == kMips64r6) { const int kTableLength = 23; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); struct TestFloat { double a; double b; double resd; double resd1; float c; float d; float resf; float resf1; }; TestFloat test; double inputsa[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = { 4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double resd[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double resd1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputsc[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsd[kTableLength] = {4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, fnan, -0.0, 0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float resf[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float resf1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ lwc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ lwc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ mina_d(f6, f2, f4); __ mina_s(f12, f8, f10); __ maxa_d(f14, f2, f4); __ maxa_s(f16, f8, f10); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, resf)) ); __ sdc1(f6, MemOperand(a0, offsetof(TestFloat, resd)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resf1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resd1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.c = inputsc[i]; test.d = inputsd[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if (i < kTableLength - 1) { CHECK_EQ(test.resd, resd[i]); CHECK_EQ(test.resf, resf[i]); CHECK_EQ(test.resd1, resd1[i]); CHECK_EQ(test.resf1, resf1[i]); } else { CHECK(std::isnan(test.resd)); CHECK(std::isnan(test.resf)); CHECK(std::isnan(test.resd1)); CHECK(std::isnan(test.resf1)); } } } } // ----------------------mips64r2 specific tests---------------------- TEST(trunc_l) { if (kArchVariant == kMips64r2) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; // a trunc result int64_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_l_d(f8, f4); __ trunc_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } } TEST(movz_movn) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { int64_t rt; double a; double b; double bold; double b1; double bold1; float c; float d; float dold; float d1; float dold1; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ld(t0, MemOperand(a0, offsetof(TestFloat, rt))); __ Move(f12, 0.0); __ Move(f10, 0.0); __ Move(f16, 0.0); __ Move(f14, 0.0); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, bold)) ); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, dold)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, bold1)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, dold1)) ); __ movz_s(f10, f6, t0); __ movz_d(f12, f2, t0); __ movn_s(f14, f6, t0); __ movn_d(f16, f2, t0); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, b)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, d1)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, b1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; test.rt = 1; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, test.bold); CHECK_EQ(test.d, test.dold); CHECK_EQ(test.b1, outputs_D[i]); CHECK_EQ(test.d1, outputs_S[i]); test.rt = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); CHECK_EQ(test.b1, test.bold1); CHECK_EQ(test.d1, test.dold1); } } } TEST(movt_movd) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); typedef struct test_float { double srcd; double dstd; double dstdold; double dstd1; double dstdold1; float srcf; float dstf; float dstfold; float dstf1; float dstfold1; int32_t cc; int32_t fcsr; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; double inputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; int condition_flags[8] = {0, 1, 2, 3, 4, 5, 6, 7}; for (int i = 0; i < kTableLength; i++) { test.srcd = inputs_D[i]; test.srcf = inputs_S[i]; for (int j = 0; j< 8; j++) { test.cc = condition_flags[j]; if (test.cc == 0) { test.fcsr = 1 << 23; } else { test.fcsr = 1 << (24+condition_flags[j]); } HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, srcd)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, srcf)) ); __ lw(t1, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t0, FCSR); __ ctc1(t1, FCSR); __ li(t2, 0x0); __ mtc1(t2, f12); __ mtc1(t2, f10); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold)) ); __ movt_s(f12, f4, test.cc); __ movt_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold1)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold1)) ); __ movf_s(f12, f4, test.cc); __ movf_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf1)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd1)) ); __ ctc1(t0, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, outputs_S[i]); CHECK_EQ(test.dstd, outputs_D[i]); CHECK_EQ(test.dstf1, test.dstfold1); CHECK_EQ(test.dstd1, test.dstdold1); test.fcsr = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, test.dstfold); CHECK_EQ(test.dstd, test.dstdold); CHECK_EQ(test.dstf1, outputs_S[i]); CHECK_EQ(test.dstd1, outputs_D[i]); } } } } // ----------------------tests for all archs-------------------------- TEST(cvt_w_d) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; int32_t b; int fcsr; }Test; const int kTableLength = 24; double inputs[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, 2147483653.0 }; double outputs_RN[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RZ[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RP[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RM[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lw(t0, MemOperand(a0, offsetof(Test, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ cvt_w_d(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(Test, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } TEST(trunc_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_w_d(f8, f4); __ trunc_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_w_d(f8, f4); __ round_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_l_d(f8, f4); __ round_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(sub) { const int kTableLength = 12; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; double inputft_D[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; double outputs_D[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; float inputfs_S[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; float inputft_S[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; float outputs_S[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sub_s(f6, f2, f4); __ sub_d(f12, f8, f10); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(sqrt_rsqrt_recip) { const int kTableLength = 4; const double deltaDouble = 2E-15; const float deltaFloat = 2E-7; const float sqrt2_s = sqrt(2); const double sqrt2_d = sqrt(2); CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; float resultS1; float resultS2; double c; double resultD; double resultD1; double resultD2; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 0.0L, 4.0L, 2.0L, 4e-28L }; double outputs_D[kTableLength] = { 0.0L, 2.0L, sqrt2_d, 2e-14L }; float inputs_S[kTableLength] = { 0.0, 4.0, 2.0, 4e-28 }; float outputs_S[kTableLength] = { 0.0, 2.0, sqrt2_s, 2e-14 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ sqrt_s(f6, f2); __ sqrt_d(f12, f8); __ rsqrt_d(f14, f8); __ rsqrt_s(f16, f2); __ recip_d(f18, f8); __ recip_s(f4, f2); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resultS1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resultD1)) ); __ swc1(f4, MemOperand(a0, offsetof(TestFloat, resultS2)) ); __ sdc1(f18, MemOperand(a0, offsetof(TestFloat, resultD2)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { float f1; double d1; test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); if (i != 0) { f1 = test.resultS1 - 1.0F/outputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD1 - 1.0L/outputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); f1 = test.resultS2 - 1.0F/inputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD2 - 1.0L/inputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); } else { CHECK_EQ(test.resultS1, 1.0F/outputs_S[i]); CHECK_EQ(test.resultD1, 1.0L/outputs_D[i]); CHECK_EQ(test.resultS2, 1.0F/inputs_S[i]); CHECK_EQ(test.resultD2, 1.0L/inputs_D[i]); } } } TEST(neg) { const int kTableLength = 2; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; double c; double resultD; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 4.0, -2.0 }; double outputs_D[kTableLength] = { -4.0, 2.0 }; float inputs_S[kTableLength] = { 4.0, -2.0 }; float outputs_S[kTableLength] = { -4.0, 2.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ neg_s(f6, f2); __ neg_d(f12, f8); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
()); F3 f = FUNCTION_CAST(code->entry()); t.a = 1.5e14; t.b = 2.75e11; t.c = 2.0; t.d = -4.0; t.e = 0.0; t.f = 0.0; t.result = 0; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(1.5e14, t.a); CHECK_EQ(2.75e11, t.b); CHECK_EQ(1, t.result); } TEST(MIPS8) { if (kArchVariant == kMips64r2) { // Test ROTR and ROTRV instructions. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { int32_t input; int32_t result_rotr_4; int32_t result_rotr_8; int32_t result_rotr_12; int32_t result_rotr_16; int32_t result_rotr_20; int32_t result_rotr_24; int32_t result_rotr_28; int32_t result_rotrv_4; int32_t result_rotrv_8; int32_t result_rotrv_12; int32_t result_rotrv_16; int32_t result_rotrv_20; int32_t result_rotrv_24; int32_t result_rotrv_28; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); // Basic word load. __ lw(a4, MemOperand(a0, offsetof(T, input)) ); // ROTR instruction (called through the Ror macro). __ Ror(a5, a4, 0x0004); __ Ror(a6, a4, 0x0008); __ Ror(a7, a4, 0x000c); __ Ror(t0, a4, 0x0010); __ Ror(t1, a4, 0x0014); __ Ror(t2, a4, 0x0018); __ Ror(t3, a4, 0x001c); // Basic word store. __ sw(a5, MemOperand(a0, offsetof(T, result_rotr_4)) ); __ sw(a6, MemOperand(a0, offsetof(T, result_rotr_8)) ); __ sw(a7, MemOperand(a0, offsetof(T, result_rotr_12)) ); __ sw(t0, MemOperand(a0, offsetof(T, result_rotr_16)) ); __ sw(t1, MemOperand(a0, offsetof(T, result_rotr_20)) ); __ sw(t2, MemOperand(a0, offsetof(T, result_rotr_24)) ); __ sw(t3, MemOperand(a0, offsetof(T, result_rotr_28)) ); // ROTRV instruction (called through the Ror macro). __ li(t3, 0x0004); __ Ror(a5, a4, t3); __ li(t3, 0x0008); __ Ror(a6, a4, t3); __ li(t3, 0x000C); __ Ror(a7, a4, t3); __ li(t3, 0x0010); __ Ror(t0, a4, t3); __ li(t3, 0x0014); __ Ror(t1, a4, t3); __ li(t3, 0x0018); __ Ror(t2, a4, t3); __ li(t3, 0x001C); __ Ror(t3, a4, t3); // Basic word store. __ sw(a5, MemOperand(a0, offsetof(T, result_rotrv_4)) ); __ sw(a6, MemOperand(a0, offsetof(T, result_rotrv_8)) ); __ sw(a7, MemOperand(a0, offsetof(T, result_rotrv_12)) ); __ sw(t0, MemOperand(a0, offsetof(T, result_rotrv_16)) ); __ sw(t1, MemOperand(a0, offsetof(T, result_rotrv_20)) ); __ sw(t2, MemOperand(a0, offsetof(T, result_rotrv_24)) ); __ sw(t3, MemOperand(a0, offsetof(T, result_rotrv_28)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.input = 0x12345678; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0x0, 0, 0, 0); USE(dummy); CHECK_EQ(static_cast(0x81234567), t.result_rotr_4); CHECK_EQ(static_cast(0x78123456), t.result_rotr_8); CHECK_EQ(static_cast(0x67812345), t.result_rotr_12); CHECK_EQ(static_cast(0x56781234), t.result_rotr_16); CHECK_EQ(static_cast(0x45678123), t.result_rotr_20); CHECK_EQ(static_cast(0x34567812), t.result_rotr_24); CHECK_EQ(static_cast(0x23456781), t.result_rotr_28); CHECK_EQ(static_cast(0x81234567), t.result_rotrv_4); CHECK_EQ(static_cast(0x78123456), t.result_rotrv_8); CHECK_EQ(static_cast(0x67812345), t.result_rotrv_12); CHECK_EQ(static_cast(0x56781234), t.result_rotrv_16); CHECK_EQ(static_cast(0x45678123), t.result_rotrv_20); CHECK_EQ(static_cast(0x34567812), t.result_rotrv_24); CHECK_EQ(static_cast(0x23456781), t.result_rotrv_28); } } TEST(MIPS9) { // Test BRANCH improvements. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); Label exit, exit2, exit3; __ Branch(&exit, ge, a0, Operand(zero_reg)); __ Branch(&exit2, ge, a0, Operand(0x00001FFF)); __ Branch(&exit3, ge, a0, Operand(0x0001FFFF)); __ bind(&exit); __ bind(&exit2); __ bind(&exit3); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); } TEST(MIPS10) { // Test conversions between doubles and long integers. // Test hos the long ints map to FP regs pairs. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double a; double a_converted; double b; int32_t dbl_mant; int32_t dbl_exp; int32_t long_hi; int32_t long_lo; int64_t long_as_int64; int32_t b_long_hi; int32_t b_long_lo; int64_t b_long_as_int64; } T; T t; Assembler assm(isolate, NULL, 0); Label L, C; if (kArchVariant == kMips64r2) { // Rewritten for FR=1 FPU mode: // - 32 FP regs of 64-bits each, no odd/even pairs. // - Note that cvt_l_d/cvt_d_l ARE legal in FR=1 mode. // Load all structure elements to registers. __ ldc1(f0, MemOperand(a0, offsetof(T, a))); // Save the raw bits of the double. __ mfc1(a4, f0); __ mfhc1(a5, f0); __ sw(a4, MemOperand(a0, offsetof(T, dbl_mant))); __ sw(a5, MemOperand(a0, offsetof(T, dbl_exp))); // Convert double in f0 to long, save hi/lo parts. __ cvt_l_d(f0, f0); __ mfc1(a4, f0); // f0 LS 32 bits of long. __ mfhc1(a5, f0); // f0 MS 32 bits of long. __ sw(a4, MemOperand(a0, offsetof(T, long_lo))); __ sw(a5, MemOperand(a0, offsetof(T, long_hi))); // Combine the high/low ints, convert back to double. __ dsll32(a6, a5, 0); // Move a5 to high bits of a6. __ or_(a6, a6, a4); __ dmtc1(a6, f1); __ cvt_d_l(f1, f1); __ sdc1(f1, MemOperand(a0, offsetof(T, a_converted))); // Convert the b long integers to double b. __ lw(a4, MemOperand(a0, offsetof(T, b_long_lo))); __ lw(a5, MemOperand(a0, offsetof(T, b_long_hi))); __ mtc1(a4, f8); // f8 LS 32-bits. __ mthc1(a5, f8); // f8 MS 32-bits. __ cvt_d_l(f10, f8); __ sdc1(f10, MemOperand(a0, offsetof(T, b))); // Convert double b back to long-int. __ ldc1(f31, MemOperand(a0, offsetof(T, b))); __ cvt_l_d(f31, f31); __ dmfc1(a7, f31); __ sd(a7, MemOperand(a0, offsetof(T, b_long_as_int64))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.a = 2.147483647e9; // 0x7fffffff -> 0x41DFFFFFFFC00000 as double. t.b_long_hi = 0x000000ff; // 0xFF00FF00FF -> 0x426FE01FE01FE000 as double. t.b_long_lo = 0x00ff00ff; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(static_cast(0x41DFFFFF), t.dbl_exp); CHECK_EQ(static_cast(0xFFC00000), t.dbl_mant); CHECK_EQ(0, t.long_hi); CHECK_EQ(static_cast(0x7fffffff), t.long_lo); CHECK_EQ(2.147483647e9, t.a_converted); // 0xFF00FF00FF -> 1.095233372415e12. CHECK_EQ(1.095233372415e12, t.b); CHECK_EQ(static_cast(0xFF00FF00FF), t.b_long_as_int64); } } TEST(MIPS11) { // Do not run test on MIPS64r6, as these instructions are removed. if (kArchVariant != kMips64r6) { // Test LWL, LWR, SWL and SWR instructions. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { int32_t reg_init; int32_t mem_init; int32_t lwl_0; int32_t lwl_1; int32_t lwl_2; int32_t lwl_3; int32_t lwr_0; int32_t lwr_1; int32_t lwr_2; int32_t lwr_3; int32_t swl_0; int32_t swl_1; int32_t swl_2; int32_t swl_3; int32_t swr_0; int32_t swr_1; int32_t swr_2; int32_t swr_3; } T; T t; Assembler assm(isolate, NULL, 0); // Test all combinations of LWL and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, lwl_0))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a5, MemOperand(a0, offsetof(T, mem_init) + 1)); __ sw(a5, MemOperand(a0, offsetof(T, lwl_1))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a6, MemOperand(a0, offsetof(T, mem_init) + 2)); __ sw(a6, MemOperand(a0, offsetof(T, lwl_2))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a7, MemOperand(a0, offsetof(T, mem_init) + 3)); __ sw(a7, MemOperand(a0, offsetof(T, lwl_3))); // Test all combinations of LWR and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, lwr_0))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a5, MemOperand(a0, offsetof(T, mem_init) + 1)); __ sw(a5, MemOperand(a0, offsetof(T, lwr_1))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a6, MemOperand(a0, offsetof(T, mem_init) + 2)); __ sw(a6, MemOperand(a0, offsetof(T, lwr_2)) ); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a7, MemOperand(a0, offsetof(T, mem_init) + 3)); __ sw(a7, MemOperand(a0, offsetof(T, lwr_3)) ); // Test all combinations of SWL and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, swl_0))); __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ swl(a4, MemOperand(a0, offsetof(T, swl_0))); __ lw(a5, MemOperand(a0, offsetof(T, mem_init))); __ sw(a5, MemOperand(a0, offsetof(T, swl_1))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ swl(a5, MemOperand(a0, offsetof(T, swl_1) + 1)); __ lw(a6, MemOperand(a0, offsetof(T, mem_init))); __ sw(a6, MemOperand(a0, offsetof(T, swl_2))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ swl(a6, MemOperand(a0, offsetof(T, swl_2) + 2)); __ lw(a7, MemOperand(a0, offsetof(T, mem_init))); __ sw(a7, MemOperand(a0, offsetof(T, swl_3))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ swl(a7, MemOperand(a0, offsetof(T, swl_3) + 3)); // Test all combinations of SWR and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, swr_0))); __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ swr(a4, MemOperand(a0, offsetof(T, swr_0))); __ lw(a5, MemOperand(a0, offsetof(T, mem_init))); __ sw(a5, MemOperand(a0, offsetof(T, swr_1))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ swr(a5, MemOperand(a0, offsetof(T, swr_1) + 1)); __ lw(a6, MemOperand(a0, offsetof(T, mem_init))); __ sw(a6, MemOperand(a0, offsetof(T, swr_2))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ swr(a6, MemOperand(a0, offsetof(T, swr_2) + 2)); __ lw(a7, MemOperand(a0, offsetof(T, mem_init))); __ sw(a7, MemOperand(a0, offsetof(T, swr_3))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ swr(a7, MemOperand(a0, offsetof(T, swr_3) + 3)); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.reg_init = 0xaabbccdd; t.mem_init = 0x11223344; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); if (kArchEndian == kLittle) { CHECK_EQ(static_cast(0x44bbccdd), t.lwl_0); CHECK_EQ(static_cast(0x3344ccdd), t.lwl_1); CHECK_EQ(static_cast(0x223344dd), t.lwl_2); CHECK_EQ(static_cast(0x11223344), t.lwl_3); CHECK_EQ(static_cast(0x11223344), t.lwr_0); CHECK_EQ(static_cast(0xaa112233), t.lwr_1); CHECK_EQ(static_cast(0xaabb1122), t.lwr_2); CHECK_EQ(static_cast(0xaabbcc11), t.lwr_3); CHECK_EQ(static_cast(0x112233aa), t.swl_0); CHECK_EQ(static_cast(0x1122aabb), t.swl_1); CHECK_EQ(static_cast(0x11aabbcc), t.swl_2); CHECK_EQ(static_cast(0xaabbccdd), t.swl_3); CHECK_EQ(static_cast(0xaabbccdd), t.swr_0); CHECK_EQ(static_cast(0xbbccdd44), t.swr_1); CHECK_EQ(static_cast(0xccdd3344), t.swr_2); CHECK_EQ(static_cast(0xdd223344), t.swr_3); } else { CHECK_EQ(static_cast(0x11223344), t.lwl_0); CHECK_EQ(static_cast(0x223344dd), t.lwl_1); CHECK_EQ(static_cast(0x3344ccdd), t.lwl_2); CHECK_EQ(static_cast(0x44bbccdd), t.lwl_3); CHECK_EQ(static_cast(0xaabbcc11), t.lwr_0); CHECK_EQ(static_cast(0xaabb1122), t.lwr_1); CHECK_EQ(static_cast(0xaa112233), t.lwr_2); CHECK_EQ(static_cast(0x11223344), t.lwr_3); CHECK_EQ(static_cast(0xaabbccdd), t.swl_0); CHECK_EQ(static_cast(0x11aabbcc), t.swl_1); CHECK_EQ(static_cast(0x1122aabb), t.swl_2); CHECK_EQ(static_cast(0x112233aa), t.swl_3); CHECK_EQ(static_cast(0xdd223344), t.swr_0); CHECK_EQ(static_cast(0xccdd3344), t.swr_1); CHECK_EQ(static_cast(0xbbccdd44), t.swr_2); CHECK_EQ(static_cast(0xaabbccdd), t.swr_3); } } } TEST(MIPS12) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { int32_t x; int32_t y; int32_t y1; int32_t y2; int32_t y3; int32_t y4; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ mov(t2, fp); // Save frame pointer. __ mov(fp, a0); // Access struct T by fp. __ lw(a4, MemOperand(a0, offsetof(T, y))); __ lw(a7, MemOperand(a0, offsetof(T, y4))); __ addu(a5, a4, a7); __ subu(t0, a4, a7); __ nop(); __ push(a4); // These instructions disappear after opt. __ Pop(); __ addu(a4, a4, a4); __ nop(); __ Pop(); // These instructions disappear after opt. __ push(a7); __ nop(); __ push(a7); // These instructions disappear after opt. __ pop(a7); __ nop(); __ push(a7); __ pop(t0); __ nop(); __ sw(a4, MemOperand(fp, offsetof(T, y))); __ lw(a4, MemOperand(fp, offsetof(T, y))); __ nop(); __ sw(a4, MemOperand(fp, offsetof(T, y))); __ lw(a5, MemOperand(fp, offsetof(T, y))); __ nop(); __ push(a5); __ lw(a5, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a6); __ nop(); __ push(a6); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a7); __ nop(); __ mov(fp, t2); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.x = 1; t.y = 2; t.y1 = 3; t.y2 = 4; t.y3 = 0XBABA; t.y4 = 0xDEDA; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(3, t.y1); } TEST(MIPS13) { // Test Cvt_d_uw and Trunc_uw_d macros. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double cvt_big_out; double cvt_small_out; uint32_t trunc_big_out; uint32_t trunc_small_out; uint32_t cvt_big_in; uint32_t cvt_small_in; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ sw(a4, MemOperand(a0, offsetof(T, cvt_small_in))); __ Cvt_d_uw(f10, a4); __ sdc1(f10, MemOperand(a0, offsetof(T, cvt_small_out))); __ Trunc_uw_d(f10, f10, f4); __ swc1(f10, MemOperand(a0, offsetof(T, trunc_small_out))); __ sw(a4, MemOperand(a0, offsetof(T, cvt_big_in))); __ Cvt_d_uw(f8, a4); __ sdc1(f8, MemOperand(a0, offsetof(T, cvt_big_out))); __ Trunc_uw_d(f8, f8, f4); __ swc1(f8, MemOperand(a0, offsetof(T, trunc_big_out))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.cvt_big_in = 0xFFFFFFFF; t.cvt_small_in = 333; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(t.cvt_big_out, static_cast(t.cvt_big_in)); CHECK_EQ(t.cvt_small_out, static_cast(t.cvt_small_in)); CHECK_EQ(static_cast(t.trunc_big_out), static_cast(t.cvt_big_in)); CHECK_EQ(static_cast(t.trunc_small_out), static_cast(t.cvt_small_in)); } TEST(MIPS14) { // Test round, floor, ceil, trunc, cvt. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); #define ROUND_STRUCT_ELEMENT(x) \ uint32_t x##_isNaN2008; \ int32_t x##_up_out; \ int32_t x##_down_out; \ int32_t neg_##x##_up_out; \ int32_t neg_##x##_down_out; \ uint32_t x##_err1_out; \ uint32_t x##_err2_out; \ uint32_t x##_err3_out; \ uint32_t x##_err4_out; \ int32_t x##_invalid_result; typedef struct { double round_up_in; double round_down_in; double neg_round_up_in; double neg_round_down_in; double err1_in; double err2_in; double err3_in; double err4_in; ROUND_STRUCT_ELEMENT(round) ROUND_STRUCT_ELEMENT(floor) ROUND_STRUCT_ELEMENT(ceil) ROUND_STRUCT_ELEMENT(trunc) ROUND_STRUCT_ELEMENT(cvt) } T; T t; #undef ROUND_STRUCT_ELEMENT MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); // Save FCSR. __ cfc1(a1, FCSR); // Disable FPU exceptions. __ ctc1(zero_reg, FCSR); #define RUN_ROUND_TEST(x) \ __ cfc1(t0, FCSR);\ __ sw(t0, MemOperand(a0, offsetof(T, x##_isNaN2008))); \ __ ldc1(f0, MemOperand(a0, offsetof(T, round_up_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_up_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, round_down_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_down_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, neg_round_up_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, neg_##x##_up_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, neg_round_down_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, neg_##x##_down_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err1_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err1_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err2_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err2_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err3_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err3_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err4_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err4_out))); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_invalid_result))); RUN_ROUND_TEST(round) RUN_ROUND_TEST(floor) RUN_ROUND_TEST(ceil) RUN_ROUND_TEST(trunc) RUN_ROUND_TEST(cvt) // Restore FCSR. __ ctc1(a1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.round_up_in = 123.51; t.round_down_in = 123.49; t.neg_round_up_in = -123.5; t.neg_round_down_in = -123.49; t.err1_in = 123.51; t.err2_in = 1; t.err3_in = static_cast(1) + 0xFFFFFFFF; t.err4_in = NAN; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); #define GET_FPU_ERR(x) (static_cast(x & kFCSRFlagMask)) #define CHECK_NAN2008(x) (x & kFCSRNaN2008FlagMask) #define CHECK_ROUND_RESULT(type) \ CHECK(GET_FPU_ERR(t.type##_err1_out) & kFCSRInexactFlagMask); \ CHECK_EQ(0, GET_FPU_ERR(t.type##_err2_out)); \ CHECK(GET_FPU_ERR(t.type##_err3_out) & kFCSRInvalidOpFlagMask); \ CHECK(GET_FPU_ERR(t.type##_err4_out) & kFCSRInvalidOpFlagMask); \ if (CHECK_NAN2008(t.type##_isNaN2008) && kArchVariant == kMips64r6) { \ CHECK_EQ(static_cast(0), t.type##_invalid_result);\ } else { \ CHECK_EQ(static_cast(kFPUInvalidResult), t.type##_invalid_result);\ } CHECK_ROUND_RESULT(round); CHECK_ROUND_RESULT(floor); CHECK_ROUND_RESULT(ceil); CHECK_ROUND_RESULT(cvt); } TEST(MIPS15) { // Test chaining of label usages within instructions (issue 1644). CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); Assembler assm(isolate, NULL, 0); Label target; __ beq(v0, v1, &target); __ nop(); __ bne(v0, v1, &target); __ nop(); __ bind(&target); __ nop(); } // ----- mips64 tests ----------------------------------------------- TEST(MIPS16) { // Test 64-bit memory loads and stores. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); struct T { int64_t r1; int64_t r2; int64_t r3; int64_t r4; int64_t r5; int64_t r6; int64_t r7; int64_t r8; int64_t r9; int64_t r10; int64_t r11; int64_t r12; uint32_t ui; int32_t si; }; T t; Assembler assm(isolate, NULL, 0); Label L, C; // Basic 32-bit word load/store, with un-signed data. __ lw(a4, MemOperand(a0, offsetof(T, ui))); __ sw(a4, MemOperand(a0, offsetof(T, r1))); // Check that the data got zero-extended into 64-bit a4. __ sd(a4, MemOperand(a0, offsetof(T, r2))); // Basic 32-bit word load/store, with SIGNED data. __ lw(a5, MemOperand(a0, offsetof(T, si))); __ sw(a5, MemOperand(a0, offsetof(T, r3))); // Check that the data got sign-extended into 64-bit a4. __ sd(a5, MemOperand(a0, offsetof(T, r4))); // 32-bit UNSIGNED word load/store, with SIGNED data. __ lwu(a6, MemOperand(a0, offsetof(T, si))); __ sw(a6, MemOperand(a0, offsetof(T, r5))); // Check that the data got zero-extended into 64-bit a4. __ sd(a6, MemOperand(a0, offsetof(T, r6))); // lh with positive data. __ lh(a5, MemOperand(a0, offsetof(T, ui))); __ sw(a5, MemOperand(a0, offsetof(T, r7))); // lh with negative data. __ lh(a6, MemOperand(a0, offsetof(T, si))); __ sw(a6, MemOperand(a0, offsetof(T, r8))); // lhu with negative data. __ lhu(a7, MemOperand(a0, offsetof(T, si))); __ sw(a7, MemOperand(a0, offsetof(T, r9))); // lb with negative data. __ lb(t0, MemOperand(a0, offsetof(T, si))); __ sw(t0, MemOperand(a0, offsetof(T, r10))); // sh writes only 1/2 of word. __ lw(a4, MemOperand(a0, offsetof(T, ui))); __ sh(a4, MemOperand(a0, offsetof(T, r11))); __ lw(a4, MemOperand(a0, offsetof(T, si))); __ sh(a4, MemOperand(a0, offsetof(T, r12))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.ui = 0x44332211; t.si = 0x99aabbcc; t.r1 = 0x5555555555555555; t.r2 = 0x5555555555555555; t.r3 = 0x5555555555555555; t.r4 = 0x5555555555555555; t.r5 = 0x5555555555555555; t.r6 = 0x5555555555555555; t.r7 = 0x5555555555555555; t.r8 = 0x5555555555555555; t.r9 = 0x5555555555555555; t.r10 = 0x5555555555555555; t.r11 = 0x5555555555555555; t.r12 = 0x5555555555555555; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); if (kArchEndian == kLittle) { // Unsigned data, 32 & 64 CHECK_EQ(static_cast(0x5555555544332211L), t.r1); // lw, sw. CHECK_EQ(static_cast(0x0000000044332211L), t.r2); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x5555555599aabbccL), t.r3); // lw, sw. CHECK_EQ(static_cast(0xffffffff99aabbccL), t.r4); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x5555555599aabbccL), t.r5); // lwu, sw. CHECK_EQ(static_cast(0x0000000099aabbccL), t.r6); // sd. // lh with unsigned and signed data. CHECK_EQ(static_cast(0x5555555500002211L), t.r7); // lh, sw. CHECK_EQ(static_cast(0x55555555ffffbbccL), t.r8); // lh, sw. // lhu with signed data. CHECK_EQ(static_cast(0x555555550000bbccL), t.r9); // lhu, sw. // lb with signed data. CHECK_EQ(static_cast(0x55555555ffffffccL), t.r10); // lb, sw. // sh with unsigned and signed data. CHECK_EQ(static_cast(0x5555555555552211L), t.r11); // lw, sh. CHECK_EQ(static_cast(0x555555555555bbccL), t.r12); // lw, sh. } else { // Unsigned data, 32 & 64 CHECK_EQ(static_cast(0x4433221155555555L), t.r1); // lw, sw. CHECK_EQ(static_cast(0x0000000044332211L), t.r2); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x99aabbcc55555555L), t.r3); // lw, sw. CHECK_EQ(static_cast(0xffffffff99aabbccL), t.r4); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x99aabbcc55555555L), t.r5); // lwu, sw. CHECK_EQ(static_cast(0x0000000099aabbccL), t.r6); // sd. // lh with unsigned and signed data. CHECK_EQ(static_cast(0x0000443355555555L), t.r7); // lh, sw. CHECK_EQ(static_cast(0xffff99aa55555555L), t.r8); // lh, sw. // lhu with signed data. CHECK_EQ(static_cast(0x000099aa55555555L), t.r9); // lhu, sw. // lb with signed data. CHECK_EQ(static_cast(0xffffff9955555555L), t.r10); // lb, sw. // sh with unsigned and signed data. CHECK_EQ(static_cast(0x2211555555555555L), t.r11); // lw, sh. CHECK_EQ(static_cast(0xbbcc555555555555L), t.r12); // lw, sh. } } // ----------------------mips64r6 specific tests---------------------- TEST(seleqz_selnez) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { int a; int b; int c; int d; double e; double f; double g; double h; float i; float j; float k; float l; } Test; Test test; // Integer part of test. __ addiu(t1, zero_reg, 1); // t1 = 1 __ seleqz(t3, t1, zero_reg); // t3 = 1 __ sw(t3, MemOperand(a0, offsetof(Test, a))); // a = 1 __ seleqz(t2, t1, t1); // t2 = 0 __ sw(t2, MemOperand(a0, offsetof(Test, b))); // b = 0 __ selnez(t3, t1, zero_reg); // t3 = 1; __ sw(t3, MemOperand(a0, offsetof(Test, c))); // c = 0 __ selnez(t3, t1, t1); // t3 = 1 __ sw(t3, MemOperand(a0, offsetof(Test, d))); // d = 1 // Floating point part of test. __ ldc1(f0, MemOperand(a0, offsetof(Test, e)) ); // src __ ldc1(f2, MemOperand(a0, offsetof(Test, f)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, i)) ); // src __ lwc1(f10, MemOperand(a0, offsetof(Test, j)) ); // test __ seleqz_d(f4, f0, f2); __ selnez_d(f6, f0, f2); __ seleqz_s(f12, f8, f10); __ selnez_s(f14, f8, f10); __ sdc1(f4, MemOperand(a0, offsetof(Test, g)) ); // src __ sdc1(f6, MemOperand(a0, offsetof(Test, h)) ); // src __ swc1(f12, MemOperand(a0, offsetof(Test, k)) ); // src __ swc1(f14, MemOperand(a0, offsetof(Test, l)) ); // src __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.a, 1); CHECK_EQ(test.b, 0); CHECK_EQ(test.c, 0); CHECK_EQ(test.d, 1); const int test_size = 3; const int input_size = 5; double inputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double outputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float inputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float outputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.e = inputs_D[i]; test.f = tests_D[j]; test.i = inputs_S[i]; test.j = tests_S[j]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, outputs_D[i]); CHECK_EQ(test.h, 0); CHECK_EQ(test.k, outputs_S[i]); CHECK_EQ(test.l, 0); test.f = tests_D[j+1]; test.j = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, 0); CHECK_EQ(test.h, outputs_D[i]); CHECK_EQ(test.k, 0); CHECK_EQ(test.l, outputs_S[i]); } } } } TEST(min_max) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); struct TestFloat { double a; double b; double c; double d; float e; float f; float g; float h; }; TestFloat test; const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); const int kTableLength = 13; double inputsa[kTableLength] = {2.0, 3.0, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = {3.0, 2.0, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double outputsdmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double outputsdmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputse[kTableLength] = {2.0, 3.0, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsf[kTableLength] = {3.0, 2.0, 3.0, fnan, 0.0, -0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float outputsfmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float outputsfmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a))); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, b))); __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, e))); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, f))); __ min_d(f10, f4, f8); __ max_d(f12, f4, f8); __ min_s(f14, f2, f6); __ max_s(f16, f2, f6); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, c))); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, d))); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, g))); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, h))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 4; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.e = inputse[i]; test.f = inputsf[i]; CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0); CHECK_EQ(0, memcmp(&test.c, &outputsdmin[i], sizeof(test.c))); CHECK_EQ(0, memcmp(&test.d, &outputsdmax[i], sizeof(test.d))); CHECK_EQ(0, memcmp(&test.g, &outputsfmin[i], sizeof(test.g))); CHECK_EQ(0, memcmp(&test.h, &outputsfmax[i], sizeof(test.h))); } } } TEST(rint_d) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; int fcsr; }TestFloat; TestFloat test; double inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E+308, 6.27463370218383111104242366943E-307, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ ctc1(t0, FCSR); __ rint_d(f8, f4); __ sdc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(sel) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { double dd; double ds; double dt; float fd; float fs; float ft; } Test; Test test; __ ldc1(f0, MemOperand(a0, offsetof(Test, dd)) ); // test __ ldc1(f2, MemOperand(a0, offsetof(Test, ds)) ); // src1 __ ldc1(f4, MemOperand(a0, offsetof(Test, dt)) ); // src2 __ lwc1(f6, MemOperand(a0, offsetof(Test, fd)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, fs)) ); // src1 __ lwc1(f10, MemOperand(a0, offsetof(Test, ft)) ); // src2 __ sel_d(f0, f2, f4); __ sel_s(f6, f8, f10); __ sdc1(f0, MemOperand(a0, offsetof(Test, dd)) ); __ swc1(f6, MemOperand(a0, offsetof(Test, fd)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); const int test_size = 3; const int input_size = 5; double inputs_dt[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double inputs_ds[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; float inputs_ft[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float inputs_fs[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.dt = inputs_dt[i]; test.dd = tests_D[j]; test.ds = inputs_ds[i]; test.ft = inputs_ft[i]; test.fd = tests_S[j]; test.fs = inputs_fs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_ds[i]); CHECK_EQ(test.fd, inputs_fs[i]); test.dd = tests_D[j+1]; test.fd = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_dt[i]); CHECK_EQ(test.fd, inputs_ft[i]); } } } } TEST(rint_s) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; int fcsr; }TestFloat; TestFloat test; float inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E+38, 6.27463370218383111104242366943E-37, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; float* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ rint_s(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(mina_maxa) { if (kArchVariant == kMips64r6) { const int kTableLength = 23; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); struct TestFloat { double a; double b; double resd; double resd1; float c; float d; float resf; float resf1; }; TestFloat test; double inputsa[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = { 4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double resd[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double resd1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputsc[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsd[kTableLength] = {4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, fnan, -0.0, 0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float resf[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float resf1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ lwc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ lwc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ mina_d(f6, f2, f4); __ mina_s(f12, f8, f10); __ maxa_d(f14, f2, f4); __ maxa_s(f16, f8, f10); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, resf)) ); __ sdc1(f6, MemOperand(a0, offsetof(TestFloat, resd)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resf1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resd1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.c = inputsc[i]; test.d = inputsd[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if (i < kTableLength - 1) { CHECK_EQ(test.resd, resd[i]); CHECK_EQ(test.resf, resf[i]); CHECK_EQ(test.resd1, resd1[i]); CHECK_EQ(test.resf1, resf1[i]); } else { CHECK(std::isnan(test.resd)); CHECK(std::isnan(test.resf)); CHECK(std::isnan(test.resd1)); CHECK(std::isnan(test.resf1)); } } } } // ----------------------mips64r2 specific tests---------------------- TEST(trunc_l) { if (kArchVariant == kMips64r2) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; // a trunc result int64_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_l_d(f8, f4); __ trunc_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } } TEST(movz_movn) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { int64_t rt; double a; double b; double bold; double b1; double bold1; float c; float d; float dold; float d1; float dold1; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ld(t0, MemOperand(a0, offsetof(TestFloat, rt))); __ Move(f12, 0.0); __ Move(f10, 0.0); __ Move(f16, 0.0); __ Move(f14, 0.0); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, bold)) ); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, dold)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, bold1)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, dold1)) ); __ movz_s(f10, f6, t0); __ movz_d(f12, f2, t0); __ movn_s(f14, f6, t0); __ movn_d(f16, f2, t0); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, b)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, d1)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, b1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; test.rt = 1; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, test.bold); CHECK_EQ(test.d, test.dold); CHECK_EQ(test.b1, outputs_D[i]); CHECK_EQ(test.d1, outputs_S[i]); test.rt = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); CHECK_EQ(test.b1, test.bold1); CHECK_EQ(test.d1, test.dold1); } } } TEST(movt_movd) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); typedef struct test_float { double srcd; double dstd; double dstdold; double dstd1; double dstdold1; float srcf; float dstf; float dstfold; float dstf1; float dstfold1; int32_t cc; int32_t fcsr; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; double inputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; int condition_flags[8] = {0, 1, 2, 3, 4, 5, 6, 7}; for (int i = 0; i < kTableLength; i++) { test.srcd = inputs_D[i]; test.srcf = inputs_S[i]; for (int j = 0; j< 8; j++) { test.cc = condition_flags[j]; if (test.cc == 0) { test.fcsr = 1 << 23; } else { test.fcsr = 1 << (24+condition_flags[j]); } HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, srcd)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, srcf)) ); __ lw(t1, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t0, FCSR); __ ctc1(t1, FCSR); __ li(t2, 0x0); __ mtc1(t2, f12); __ mtc1(t2, f10); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold)) ); __ movt_s(f12, f4, test.cc); __ movt_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold1)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold1)) ); __ movf_s(f12, f4, test.cc); __ movf_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf1)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd1)) ); __ ctc1(t0, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, outputs_S[i]); CHECK_EQ(test.dstd, outputs_D[i]); CHECK_EQ(test.dstf1, test.dstfold1); CHECK_EQ(test.dstd1, test.dstdold1); test.fcsr = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, test.dstfold); CHECK_EQ(test.dstd, test.dstdold); CHECK_EQ(test.dstf1, outputs_S[i]); CHECK_EQ(test.dstd1, outputs_D[i]); } } } } // ----------------------tests for all archs-------------------------- TEST(cvt_w_d) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; int32_t b; int fcsr; }Test; const int kTableLength = 24; double inputs[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, 2147483653.0 }; double outputs_RN[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RZ[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RP[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RM[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lw(t0, MemOperand(a0, offsetof(Test, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ cvt_w_d(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(Test, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } TEST(trunc_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_w_d(f8, f4); __ trunc_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_w_d(f8, f4); __ round_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_l_d(f8, f4); __ round_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(sub) { const int kTableLength = 12; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; double inputft_D[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; double outputs_D[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; float inputfs_S[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; float inputft_S[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; float outputs_S[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sub_s(f6, f2, f4); __ sub_d(f12, f8, f10); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(sqrt_rsqrt_recip) { const int kTableLength = 4; const double deltaDouble = 2E-15; const float deltaFloat = 2E-7; const float sqrt2_s = sqrt(2); const double sqrt2_d = sqrt(2); CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; float resultS1; float resultS2; double c; double resultD; double resultD1; double resultD2; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 0.0L, 4.0L, 2.0L, 4e-28L }; double outputs_D[kTableLength] = { 0.0L, 2.0L, sqrt2_d, 2e-14L }; float inputs_S[kTableLength] = { 0.0, 4.0, 2.0, 4e-28 }; float outputs_S[kTableLength] = { 0.0, 2.0, sqrt2_s, 2e-14 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ sqrt_s(f6, f2); __ sqrt_d(f12, f8); __ rsqrt_d(f14, f8); __ rsqrt_s(f16, f2); __ recip_d(f18, f8); __ recip_s(f4, f2); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resultS1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resultD1)) ); __ swc1(f4, MemOperand(a0, offsetof(TestFloat, resultS2)) ); __ sdc1(f18, MemOperand(a0, offsetof(TestFloat, resultD2)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { float f1; double d1; test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); if (i != 0) { f1 = test.resultS1 - 1.0F/outputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD1 - 1.0L/outputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); f1 = test.resultS2 - 1.0F/inputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD2 - 1.0L/inputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); } else { CHECK_EQ(test.resultS1, 1.0F/outputs_S[i]); CHECK_EQ(test.resultD1, 1.0L/outputs_D[i]); CHECK_EQ(test.resultS2, 1.0F/inputs_S[i]); CHECK_EQ(test.resultD2, 1.0L/inputs_D[i]); } } } TEST(neg) { const int kTableLength = 2; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; double c; double resultD; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 4.0, -2.0 }; double outputs_D[kTableLength] = { -4.0, 2.0 }; float inputs_S[kTableLength] = { 4.0, -2.0 }; float outputs_S[kTableLength] = { -4.0, 2.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ neg_s(f6, f2); __ neg_d(f12, f8); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.input = 0x12345678; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0x0, 0, 0, 0); USE(dummy); CHECK_EQ(static_cast(0x81234567), t.result_rotr_4); CHECK_EQ(static_cast(0x78123456), t.result_rotr_8); CHECK_EQ(static_cast(0x67812345), t.result_rotr_12); CHECK_EQ(static_cast(0x56781234), t.result_rotr_16); CHECK_EQ(static_cast(0x45678123), t.result_rotr_20); CHECK_EQ(static_cast(0x34567812), t.result_rotr_24); CHECK_EQ(static_cast(0x23456781), t.result_rotr_28); CHECK_EQ(static_cast(0x81234567), t.result_rotrv_4); CHECK_EQ(static_cast(0x78123456), t.result_rotrv_8); CHECK_EQ(static_cast(0x67812345), t.result_rotrv_12); CHECK_EQ(static_cast(0x56781234), t.result_rotrv_16); CHECK_EQ(static_cast(0x45678123), t.result_rotrv_20); CHECK_EQ(static_cast(0x34567812), t.result_rotrv_24); CHECK_EQ(static_cast(0x23456781), t.result_rotrv_28); } } TEST(MIPS9) { // Test BRANCH improvements. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); Label exit, exit2, exit3; __ Branch(&exit, ge, a0, Operand(zero_reg)); __ Branch(&exit2, ge, a0, Operand(0x00001FFF)); __ Branch(&exit3, ge, a0, Operand(0x0001FFFF)); __ bind(&exit); __ bind(&exit2); __ bind(&exit3); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); } TEST(MIPS10) { // Test conversions between doubles and long integers. // Test hos the long ints map to FP regs pairs. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double a; double a_converted; double b; int32_t dbl_mant; int32_t dbl_exp; int32_t long_hi; int32_t long_lo; int64_t long_as_int64; int32_t b_long_hi; int32_t b_long_lo; int64_t b_long_as_int64; } T; T t; Assembler assm(isolate, NULL, 0); Label L, C; if (kArchVariant == kMips64r2) { // Rewritten for FR=1 FPU mode: // - 32 FP regs of 64-bits each, no odd/even pairs. // - Note that cvt_l_d/cvt_d_l ARE legal in FR=1 mode. // Load all structure elements to registers. __ ldc1(f0, MemOperand(a0, offsetof(T, a))); // Save the raw bits of the double. __ mfc1(a4, f0); __ mfhc1(a5, f0); __ sw(a4, MemOperand(a0, offsetof(T, dbl_mant))); __ sw(a5, MemOperand(a0, offsetof(T, dbl_exp))); // Convert double in f0 to long, save hi/lo parts. __ cvt_l_d(f0, f0); __ mfc1(a4, f0); // f0 LS 32 bits of long. __ mfhc1(a5, f0); // f0 MS 32 bits of long. __ sw(a4, MemOperand(a0, offsetof(T, long_lo))); __ sw(a5, MemOperand(a0, offsetof(T, long_hi))); // Combine the high/low ints, convert back to double. __ dsll32(a6, a5, 0); // Move a5 to high bits of a6. __ or_(a6, a6, a4); __ dmtc1(a6, f1); __ cvt_d_l(f1, f1); __ sdc1(f1, MemOperand(a0, offsetof(T, a_converted))); // Convert the b long integers to double b. __ lw(a4, MemOperand(a0, offsetof(T, b_long_lo))); __ lw(a5, MemOperand(a0, offsetof(T, b_long_hi))); __ mtc1(a4, f8); // f8 LS 32-bits. __ mthc1(a5, f8); // f8 MS 32-bits. __ cvt_d_l(f10, f8); __ sdc1(f10, MemOperand(a0, offsetof(T, b))); // Convert double b back to long-int. __ ldc1(f31, MemOperand(a0, offsetof(T, b))); __ cvt_l_d(f31, f31); __ dmfc1(a7, f31); __ sd(a7, MemOperand(a0, offsetof(T, b_long_as_int64))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.a = 2.147483647e9; // 0x7fffffff -> 0x41DFFFFFFFC00000 as double. t.b_long_hi = 0x000000ff; // 0xFF00FF00FF -> 0x426FE01FE01FE000 as double. t.b_long_lo = 0x00ff00ff; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(static_cast(0x41DFFFFF), t.dbl_exp); CHECK_EQ(static_cast(0xFFC00000), t.dbl_mant); CHECK_EQ(0, t.long_hi); CHECK_EQ(static_cast(0x7fffffff), t.long_lo); CHECK_EQ(2.147483647e9, t.a_converted); // 0xFF00FF00FF -> 1.095233372415e12. CHECK_EQ(1.095233372415e12, t.b); CHECK_EQ(static_cast(0xFF00FF00FF), t.b_long_as_int64); } } TEST(MIPS11) { // Do not run test on MIPS64r6, as these instructions are removed. if (kArchVariant != kMips64r6) { // Test LWL, LWR, SWL and SWR instructions. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { int32_t reg_init; int32_t mem_init; int32_t lwl_0; int32_t lwl_1; int32_t lwl_2; int32_t lwl_3; int32_t lwr_0; int32_t lwr_1; int32_t lwr_2; int32_t lwr_3; int32_t swl_0; int32_t swl_1; int32_t swl_2; int32_t swl_3; int32_t swr_0; int32_t swr_1; int32_t swr_2; int32_t swr_3; } T; T t; Assembler assm(isolate, NULL, 0); // Test all combinations of LWL and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, lwl_0))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a5, MemOperand(a0, offsetof(T, mem_init) + 1)); __ sw(a5, MemOperand(a0, offsetof(T, lwl_1))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a6, MemOperand(a0, offsetof(T, mem_init) + 2)); __ sw(a6, MemOperand(a0, offsetof(T, lwl_2))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a7, MemOperand(a0, offsetof(T, mem_init) + 3)); __ sw(a7, MemOperand(a0, offsetof(T, lwl_3))); // Test all combinations of LWR and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, lwr_0))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a5, MemOperand(a0, offsetof(T, mem_init) + 1)); __ sw(a5, MemOperand(a0, offsetof(T, lwr_1))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a6, MemOperand(a0, offsetof(T, mem_init) + 2)); __ sw(a6, MemOperand(a0, offsetof(T, lwr_2)) ); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a7, MemOperand(a0, offsetof(T, mem_init) + 3)); __ sw(a7, MemOperand(a0, offsetof(T, lwr_3)) ); // Test all combinations of SWL and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, swl_0))); __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ swl(a4, MemOperand(a0, offsetof(T, swl_0))); __ lw(a5, MemOperand(a0, offsetof(T, mem_init))); __ sw(a5, MemOperand(a0, offsetof(T, swl_1))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ swl(a5, MemOperand(a0, offsetof(T, swl_1) + 1)); __ lw(a6, MemOperand(a0, offsetof(T, mem_init))); __ sw(a6, MemOperand(a0, offsetof(T, swl_2))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ swl(a6, MemOperand(a0, offsetof(T, swl_2) + 2)); __ lw(a7, MemOperand(a0, offsetof(T, mem_init))); __ sw(a7, MemOperand(a0, offsetof(T, swl_3))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ swl(a7, MemOperand(a0, offsetof(T, swl_3) + 3)); // Test all combinations of SWR and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, swr_0))); __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ swr(a4, MemOperand(a0, offsetof(T, swr_0))); __ lw(a5, MemOperand(a0, offsetof(T, mem_init))); __ sw(a5, MemOperand(a0, offsetof(T, swr_1))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ swr(a5, MemOperand(a0, offsetof(T, swr_1) + 1)); __ lw(a6, MemOperand(a0, offsetof(T, mem_init))); __ sw(a6, MemOperand(a0, offsetof(T, swr_2))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ swr(a6, MemOperand(a0, offsetof(T, swr_2) + 2)); __ lw(a7, MemOperand(a0, offsetof(T, mem_init))); __ sw(a7, MemOperand(a0, offsetof(T, swr_3))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ swr(a7, MemOperand(a0, offsetof(T, swr_3) + 3)); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.reg_init = 0xaabbccdd; t.mem_init = 0x11223344; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); if (kArchEndian == kLittle) { CHECK_EQ(static_cast(0x44bbccdd), t.lwl_0); CHECK_EQ(static_cast(0x3344ccdd), t.lwl_1); CHECK_EQ(static_cast(0x223344dd), t.lwl_2); CHECK_EQ(static_cast(0x11223344), t.lwl_3); CHECK_EQ(static_cast(0x11223344), t.lwr_0); CHECK_EQ(static_cast(0xaa112233), t.lwr_1); CHECK_EQ(static_cast(0xaabb1122), t.lwr_2); CHECK_EQ(static_cast(0xaabbcc11), t.lwr_3); CHECK_EQ(static_cast(0x112233aa), t.swl_0); CHECK_EQ(static_cast(0x1122aabb), t.swl_1); CHECK_EQ(static_cast(0x11aabbcc), t.swl_2); CHECK_EQ(static_cast(0xaabbccdd), t.swl_3); CHECK_EQ(static_cast(0xaabbccdd), t.swr_0); CHECK_EQ(static_cast(0xbbccdd44), t.swr_1); CHECK_EQ(static_cast(0xccdd3344), t.swr_2); CHECK_EQ(static_cast(0xdd223344), t.swr_3); } else { CHECK_EQ(static_cast(0x11223344), t.lwl_0); CHECK_EQ(static_cast(0x223344dd), t.lwl_1); CHECK_EQ(static_cast(0x3344ccdd), t.lwl_2); CHECK_EQ(static_cast(0x44bbccdd), t.lwl_3); CHECK_EQ(static_cast(0xaabbcc11), t.lwr_0); CHECK_EQ(static_cast(0xaabb1122), t.lwr_1); CHECK_EQ(static_cast(0xaa112233), t.lwr_2); CHECK_EQ(static_cast(0x11223344), t.lwr_3); CHECK_EQ(static_cast(0xaabbccdd), t.swl_0); CHECK_EQ(static_cast(0x11aabbcc), t.swl_1); CHECK_EQ(static_cast(0x1122aabb), t.swl_2); CHECK_EQ(static_cast(0x112233aa), t.swl_3); CHECK_EQ(static_cast(0xdd223344), t.swr_0); CHECK_EQ(static_cast(0xccdd3344), t.swr_1); CHECK_EQ(static_cast(0xbbccdd44), t.swr_2); CHECK_EQ(static_cast(0xaabbccdd), t.swr_3); } } } TEST(MIPS12) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { int32_t x; int32_t y; int32_t y1; int32_t y2; int32_t y3; int32_t y4; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ mov(t2, fp); // Save frame pointer. __ mov(fp, a0); // Access struct T by fp. __ lw(a4, MemOperand(a0, offsetof(T, y))); __ lw(a7, MemOperand(a0, offsetof(T, y4))); __ addu(a5, a4, a7); __ subu(t0, a4, a7); __ nop(); __ push(a4); // These instructions disappear after opt. __ Pop(); __ addu(a4, a4, a4); __ nop(); __ Pop(); // These instructions disappear after opt. __ push(a7); __ nop(); __ push(a7); // These instructions disappear after opt. __ pop(a7); __ nop(); __ push(a7); __ pop(t0); __ nop(); __ sw(a4, MemOperand(fp, offsetof(T, y))); __ lw(a4, MemOperand(fp, offsetof(T, y))); __ nop(); __ sw(a4, MemOperand(fp, offsetof(T, y))); __ lw(a5, MemOperand(fp, offsetof(T, y))); __ nop(); __ push(a5); __ lw(a5, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a6); __ nop(); __ push(a6); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a7); __ nop(); __ mov(fp, t2); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.x = 1; t.y = 2; t.y1 = 3; t.y2 = 4; t.y3 = 0XBABA; t.y4 = 0xDEDA; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(3, t.y1); } TEST(MIPS13) { // Test Cvt_d_uw and Trunc_uw_d macros. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double cvt_big_out; double cvt_small_out; uint32_t trunc_big_out; uint32_t trunc_small_out; uint32_t cvt_big_in; uint32_t cvt_small_in; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ sw(a4, MemOperand(a0, offsetof(T, cvt_small_in))); __ Cvt_d_uw(f10, a4); __ sdc1(f10, MemOperand(a0, offsetof(T, cvt_small_out))); __ Trunc_uw_d(f10, f10, f4); __ swc1(f10, MemOperand(a0, offsetof(T, trunc_small_out))); __ sw(a4, MemOperand(a0, offsetof(T, cvt_big_in))); __ Cvt_d_uw(f8, a4); __ sdc1(f8, MemOperand(a0, offsetof(T, cvt_big_out))); __ Trunc_uw_d(f8, f8, f4); __ swc1(f8, MemOperand(a0, offsetof(T, trunc_big_out))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.cvt_big_in = 0xFFFFFFFF; t.cvt_small_in = 333; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(t.cvt_big_out, static_cast(t.cvt_big_in)); CHECK_EQ(t.cvt_small_out, static_cast(t.cvt_small_in)); CHECK_EQ(static_cast(t.trunc_big_out), static_cast(t.cvt_big_in)); CHECK_EQ(static_cast(t.trunc_small_out), static_cast(t.cvt_small_in)); } TEST(MIPS14) { // Test round, floor, ceil, trunc, cvt. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); #define ROUND_STRUCT_ELEMENT(x) \ uint32_t x##_isNaN2008; \ int32_t x##_up_out; \ int32_t x##_down_out; \ int32_t neg_##x##_up_out; \ int32_t neg_##x##_down_out; \ uint32_t x##_err1_out; \ uint32_t x##_err2_out; \ uint32_t x##_err3_out; \ uint32_t x##_err4_out; \ int32_t x##_invalid_result; typedef struct { double round_up_in; double round_down_in; double neg_round_up_in; double neg_round_down_in; double err1_in; double err2_in; double err3_in; double err4_in; ROUND_STRUCT_ELEMENT(round) ROUND_STRUCT_ELEMENT(floor) ROUND_STRUCT_ELEMENT(ceil) ROUND_STRUCT_ELEMENT(trunc) ROUND_STRUCT_ELEMENT(cvt) } T; T t; #undef ROUND_STRUCT_ELEMENT MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); // Save FCSR. __ cfc1(a1, FCSR); // Disable FPU exceptions. __ ctc1(zero_reg, FCSR); #define RUN_ROUND_TEST(x) \ __ cfc1(t0, FCSR);\ __ sw(t0, MemOperand(a0, offsetof(T, x##_isNaN2008))); \ __ ldc1(f0, MemOperand(a0, offsetof(T, round_up_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_up_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, round_down_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_down_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, neg_round_up_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, neg_##x##_up_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, neg_round_down_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, neg_##x##_down_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err1_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err1_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err2_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err2_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err3_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err3_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err4_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err4_out))); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_invalid_result))); RUN_ROUND_TEST(round) RUN_ROUND_TEST(floor) RUN_ROUND_TEST(ceil) RUN_ROUND_TEST(trunc) RUN_ROUND_TEST(cvt) // Restore FCSR. __ ctc1(a1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.round_up_in = 123.51; t.round_down_in = 123.49; t.neg_round_up_in = -123.5; t.neg_round_down_in = -123.49; t.err1_in = 123.51; t.err2_in = 1; t.err3_in = static_cast(1) + 0xFFFFFFFF; t.err4_in = NAN; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); #define GET_FPU_ERR(x) (static_cast(x & kFCSRFlagMask)) #define CHECK_NAN2008(x) (x & kFCSRNaN2008FlagMask) #define CHECK_ROUND_RESULT(type) \ CHECK(GET_FPU_ERR(t.type##_err1_out) & kFCSRInexactFlagMask); \ CHECK_EQ(0, GET_FPU_ERR(t.type##_err2_out)); \ CHECK(GET_FPU_ERR(t.type##_err3_out) & kFCSRInvalidOpFlagMask); \ CHECK(GET_FPU_ERR(t.type##_err4_out) & kFCSRInvalidOpFlagMask); \ if (CHECK_NAN2008(t.type##_isNaN2008) && kArchVariant == kMips64r6) { \ CHECK_EQ(static_cast(0), t.type##_invalid_result);\ } else { \ CHECK_EQ(static_cast(kFPUInvalidResult), t.type##_invalid_result);\ } CHECK_ROUND_RESULT(round); CHECK_ROUND_RESULT(floor); CHECK_ROUND_RESULT(ceil); CHECK_ROUND_RESULT(cvt); } TEST(MIPS15) { // Test chaining of label usages within instructions (issue 1644). CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); Assembler assm(isolate, NULL, 0); Label target; __ beq(v0, v1, &target); __ nop(); __ bne(v0, v1, &target); __ nop(); __ bind(&target); __ nop(); } // ----- mips64 tests ----------------------------------------------- TEST(MIPS16) { // Test 64-bit memory loads and stores. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); struct T { int64_t r1; int64_t r2; int64_t r3; int64_t r4; int64_t r5; int64_t r6; int64_t r7; int64_t r8; int64_t r9; int64_t r10; int64_t r11; int64_t r12; uint32_t ui; int32_t si; }; T t; Assembler assm(isolate, NULL, 0); Label L, C; // Basic 32-bit word load/store, with un-signed data. __ lw(a4, MemOperand(a0, offsetof(T, ui))); __ sw(a4, MemOperand(a0, offsetof(T, r1))); // Check that the data got zero-extended into 64-bit a4. __ sd(a4, MemOperand(a0, offsetof(T, r2))); // Basic 32-bit word load/store, with SIGNED data. __ lw(a5, MemOperand(a0, offsetof(T, si))); __ sw(a5, MemOperand(a0, offsetof(T, r3))); // Check that the data got sign-extended into 64-bit a4. __ sd(a5, MemOperand(a0, offsetof(T, r4))); // 32-bit UNSIGNED word load/store, with SIGNED data. __ lwu(a6, MemOperand(a0, offsetof(T, si))); __ sw(a6, MemOperand(a0, offsetof(T, r5))); // Check that the data got zero-extended into 64-bit a4. __ sd(a6, MemOperand(a0, offsetof(T, r6))); // lh with positive data. __ lh(a5, MemOperand(a0, offsetof(T, ui))); __ sw(a5, MemOperand(a0, offsetof(T, r7))); // lh with negative data. __ lh(a6, MemOperand(a0, offsetof(T, si))); __ sw(a6, MemOperand(a0, offsetof(T, r8))); // lhu with negative data. __ lhu(a7, MemOperand(a0, offsetof(T, si))); __ sw(a7, MemOperand(a0, offsetof(T, r9))); // lb with negative data. __ lb(t0, MemOperand(a0, offsetof(T, si))); __ sw(t0, MemOperand(a0, offsetof(T, r10))); // sh writes only 1/2 of word. __ lw(a4, MemOperand(a0, offsetof(T, ui))); __ sh(a4, MemOperand(a0, offsetof(T, r11))); __ lw(a4, MemOperand(a0, offsetof(T, si))); __ sh(a4, MemOperand(a0, offsetof(T, r12))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.ui = 0x44332211; t.si = 0x99aabbcc; t.r1 = 0x5555555555555555; t.r2 = 0x5555555555555555; t.r3 = 0x5555555555555555; t.r4 = 0x5555555555555555; t.r5 = 0x5555555555555555; t.r6 = 0x5555555555555555; t.r7 = 0x5555555555555555; t.r8 = 0x5555555555555555; t.r9 = 0x5555555555555555; t.r10 = 0x5555555555555555; t.r11 = 0x5555555555555555; t.r12 = 0x5555555555555555; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); if (kArchEndian == kLittle) { // Unsigned data, 32 & 64 CHECK_EQ(static_cast(0x5555555544332211L), t.r1); // lw, sw. CHECK_EQ(static_cast(0x0000000044332211L), t.r2); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x5555555599aabbccL), t.r3); // lw, sw. CHECK_EQ(static_cast(0xffffffff99aabbccL), t.r4); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x5555555599aabbccL), t.r5); // lwu, sw. CHECK_EQ(static_cast(0x0000000099aabbccL), t.r6); // sd. // lh with unsigned and signed data. CHECK_EQ(static_cast(0x5555555500002211L), t.r7); // lh, sw. CHECK_EQ(static_cast(0x55555555ffffbbccL), t.r8); // lh, sw. // lhu with signed data. CHECK_EQ(static_cast(0x555555550000bbccL), t.r9); // lhu, sw. // lb with signed data. CHECK_EQ(static_cast(0x55555555ffffffccL), t.r10); // lb, sw. // sh with unsigned and signed data. CHECK_EQ(static_cast(0x5555555555552211L), t.r11); // lw, sh. CHECK_EQ(static_cast(0x555555555555bbccL), t.r12); // lw, sh. } else { // Unsigned data, 32 & 64 CHECK_EQ(static_cast(0x4433221155555555L), t.r1); // lw, sw. CHECK_EQ(static_cast(0x0000000044332211L), t.r2); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x99aabbcc55555555L), t.r3); // lw, sw. CHECK_EQ(static_cast(0xffffffff99aabbccL), t.r4); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x99aabbcc55555555L), t.r5); // lwu, sw. CHECK_EQ(static_cast(0x0000000099aabbccL), t.r6); // sd. // lh with unsigned and signed data. CHECK_EQ(static_cast(0x0000443355555555L), t.r7); // lh, sw. CHECK_EQ(static_cast(0xffff99aa55555555L), t.r8); // lh, sw. // lhu with signed data. CHECK_EQ(static_cast(0x000099aa55555555L), t.r9); // lhu, sw. // lb with signed data. CHECK_EQ(static_cast(0xffffff9955555555L), t.r10); // lb, sw. // sh with unsigned and signed data. CHECK_EQ(static_cast(0x2211555555555555L), t.r11); // lw, sh. CHECK_EQ(static_cast(0xbbcc555555555555L), t.r12); // lw, sh. } } // ----------------------mips64r6 specific tests---------------------- TEST(seleqz_selnez) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { int a; int b; int c; int d; double e; double f; double g; double h; float i; float j; float k; float l; } Test; Test test; // Integer part of test. __ addiu(t1, zero_reg, 1); // t1 = 1 __ seleqz(t3, t1, zero_reg); // t3 = 1 __ sw(t3, MemOperand(a0, offsetof(Test, a))); // a = 1 __ seleqz(t2, t1, t1); // t2 = 0 __ sw(t2, MemOperand(a0, offsetof(Test, b))); // b = 0 __ selnez(t3, t1, zero_reg); // t3 = 1; __ sw(t3, MemOperand(a0, offsetof(Test, c))); // c = 0 __ selnez(t3, t1, t1); // t3 = 1 __ sw(t3, MemOperand(a0, offsetof(Test, d))); // d = 1 // Floating point part of test. __ ldc1(f0, MemOperand(a0, offsetof(Test, e)) ); // src __ ldc1(f2, MemOperand(a0, offsetof(Test, f)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, i)) ); // src __ lwc1(f10, MemOperand(a0, offsetof(Test, j)) ); // test __ seleqz_d(f4, f0, f2); __ selnez_d(f6, f0, f2); __ seleqz_s(f12, f8, f10); __ selnez_s(f14, f8, f10); __ sdc1(f4, MemOperand(a0, offsetof(Test, g)) ); // src __ sdc1(f6, MemOperand(a0, offsetof(Test, h)) ); // src __ swc1(f12, MemOperand(a0, offsetof(Test, k)) ); // src __ swc1(f14, MemOperand(a0, offsetof(Test, l)) ); // src __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.a, 1); CHECK_EQ(test.b, 0); CHECK_EQ(test.c, 0); CHECK_EQ(test.d, 1); const int test_size = 3; const int input_size = 5; double inputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double outputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float inputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float outputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.e = inputs_D[i]; test.f = tests_D[j]; test.i = inputs_S[i]; test.j = tests_S[j]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, outputs_D[i]); CHECK_EQ(test.h, 0); CHECK_EQ(test.k, outputs_S[i]); CHECK_EQ(test.l, 0); test.f = tests_D[j+1]; test.j = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, 0); CHECK_EQ(test.h, outputs_D[i]); CHECK_EQ(test.k, 0); CHECK_EQ(test.l, outputs_S[i]); } } } } TEST(min_max) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); struct TestFloat { double a; double b; double c; double d; float e; float f; float g; float h; }; TestFloat test; const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); const int kTableLength = 13; double inputsa[kTableLength] = {2.0, 3.0, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = {3.0, 2.0, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double outputsdmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double outputsdmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputse[kTableLength] = {2.0, 3.0, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsf[kTableLength] = {3.0, 2.0, 3.0, fnan, 0.0, -0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float outputsfmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float outputsfmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a))); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, b))); __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, e))); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, f))); __ min_d(f10, f4, f8); __ max_d(f12, f4, f8); __ min_s(f14, f2, f6); __ max_s(f16, f2, f6); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, c))); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, d))); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, g))); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, h))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 4; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.e = inputse[i]; test.f = inputsf[i]; CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0); CHECK_EQ(0, memcmp(&test.c, &outputsdmin[i], sizeof(test.c))); CHECK_EQ(0, memcmp(&test.d, &outputsdmax[i], sizeof(test.d))); CHECK_EQ(0, memcmp(&test.g, &outputsfmin[i], sizeof(test.g))); CHECK_EQ(0, memcmp(&test.h, &outputsfmax[i], sizeof(test.h))); } } } TEST(rint_d) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; int fcsr; }TestFloat; TestFloat test; double inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E+308, 6.27463370218383111104242366943E-307, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ ctc1(t0, FCSR); __ rint_d(f8, f4); __ sdc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(sel) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { double dd; double ds; double dt; float fd; float fs; float ft; } Test; Test test; __ ldc1(f0, MemOperand(a0, offsetof(Test, dd)) ); // test __ ldc1(f2, MemOperand(a0, offsetof(Test, ds)) ); // src1 __ ldc1(f4, MemOperand(a0, offsetof(Test, dt)) ); // src2 __ lwc1(f6, MemOperand(a0, offsetof(Test, fd)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, fs)) ); // src1 __ lwc1(f10, MemOperand(a0, offsetof(Test, ft)) ); // src2 __ sel_d(f0, f2, f4); __ sel_s(f6, f8, f10); __ sdc1(f0, MemOperand(a0, offsetof(Test, dd)) ); __ swc1(f6, MemOperand(a0, offsetof(Test, fd)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); const int test_size = 3; const int input_size = 5; double inputs_dt[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double inputs_ds[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; float inputs_ft[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float inputs_fs[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.dt = inputs_dt[i]; test.dd = tests_D[j]; test.ds = inputs_ds[i]; test.ft = inputs_ft[i]; test.fd = tests_S[j]; test.fs = inputs_fs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_ds[i]); CHECK_EQ(test.fd, inputs_fs[i]); test.dd = tests_D[j+1]; test.fd = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_dt[i]); CHECK_EQ(test.fd, inputs_ft[i]); } } } } TEST(rint_s) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; int fcsr; }TestFloat; TestFloat test; float inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E+38, 6.27463370218383111104242366943E-37, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; float* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ rint_s(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(mina_maxa) { if (kArchVariant == kMips64r6) { const int kTableLength = 23; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); struct TestFloat { double a; double b; double resd; double resd1; float c; float d; float resf; float resf1; }; TestFloat test; double inputsa[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = { 4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double resd[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double resd1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputsc[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsd[kTableLength] = {4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, fnan, -0.0, 0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float resf[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float resf1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ lwc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ lwc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ mina_d(f6, f2, f4); __ mina_s(f12, f8, f10); __ maxa_d(f14, f2, f4); __ maxa_s(f16, f8, f10); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, resf)) ); __ sdc1(f6, MemOperand(a0, offsetof(TestFloat, resd)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resf1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resd1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.c = inputsc[i]; test.d = inputsd[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if (i < kTableLength - 1) { CHECK_EQ(test.resd, resd[i]); CHECK_EQ(test.resf, resf[i]); CHECK_EQ(test.resd1, resd1[i]); CHECK_EQ(test.resf1, resf1[i]); } else { CHECK(std::isnan(test.resd)); CHECK(std::isnan(test.resf)); CHECK(std::isnan(test.resd1)); CHECK(std::isnan(test.resf1)); } } } } // ----------------------mips64r2 specific tests---------------------- TEST(trunc_l) { if (kArchVariant == kMips64r2) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; // a trunc result int64_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_l_d(f8, f4); __ trunc_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } } TEST(movz_movn) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { int64_t rt; double a; double b; double bold; double b1; double bold1; float c; float d; float dold; float d1; float dold1; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ld(t0, MemOperand(a0, offsetof(TestFloat, rt))); __ Move(f12, 0.0); __ Move(f10, 0.0); __ Move(f16, 0.0); __ Move(f14, 0.0); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, bold)) ); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, dold)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, bold1)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, dold1)) ); __ movz_s(f10, f6, t0); __ movz_d(f12, f2, t0); __ movn_s(f14, f6, t0); __ movn_d(f16, f2, t0); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, b)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, d1)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, b1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; test.rt = 1; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, test.bold); CHECK_EQ(test.d, test.dold); CHECK_EQ(test.b1, outputs_D[i]); CHECK_EQ(test.d1, outputs_S[i]); test.rt = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); CHECK_EQ(test.b1, test.bold1); CHECK_EQ(test.d1, test.dold1); } } } TEST(movt_movd) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); typedef struct test_float { double srcd; double dstd; double dstdold; double dstd1; double dstdold1; float srcf; float dstf; float dstfold; float dstf1; float dstfold1; int32_t cc; int32_t fcsr; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; double inputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; int condition_flags[8] = {0, 1, 2, 3, 4, 5, 6, 7}; for (int i = 0; i < kTableLength; i++) { test.srcd = inputs_D[i]; test.srcf = inputs_S[i]; for (int j = 0; j< 8; j++) { test.cc = condition_flags[j]; if (test.cc == 0) { test.fcsr = 1 << 23; } else { test.fcsr = 1 << (24+condition_flags[j]); } HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, srcd)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, srcf)) ); __ lw(t1, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t0, FCSR); __ ctc1(t1, FCSR); __ li(t2, 0x0); __ mtc1(t2, f12); __ mtc1(t2, f10); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold)) ); __ movt_s(f12, f4, test.cc); __ movt_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold1)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold1)) ); __ movf_s(f12, f4, test.cc); __ movf_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf1)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd1)) ); __ ctc1(t0, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, outputs_S[i]); CHECK_EQ(test.dstd, outputs_D[i]); CHECK_EQ(test.dstf1, test.dstfold1); CHECK_EQ(test.dstd1, test.dstdold1); test.fcsr = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, test.dstfold); CHECK_EQ(test.dstd, test.dstdold); CHECK_EQ(test.dstf1, outputs_S[i]); CHECK_EQ(test.dstd1, outputs_D[i]); } } } } // ----------------------tests for all archs-------------------------- TEST(cvt_w_d) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; int32_t b; int fcsr; }Test; const int kTableLength = 24; double inputs[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, 2147483653.0 }; double outputs_RN[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RZ[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RP[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RM[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lw(t0, MemOperand(a0, offsetof(Test, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ cvt_w_d(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(Test, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } TEST(trunc_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_w_d(f8, f4); __ trunc_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_w_d(f8, f4); __ round_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_l_d(f8, f4); __ round_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(sub) { const int kTableLength = 12; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; double inputft_D[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; double outputs_D[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; float inputfs_S[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; float inputft_S[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; float outputs_S[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sub_s(f6, f2, f4); __ sub_d(f12, f8, f10); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(sqrt_rsqrt_recip) { const int kTableLength = 4; const double deltaDouble = 2E-15; const float deltaFloat = 2E-7; const float sqrt2_s = sqrt(2); const double sqrt2_d = sqrt(2); CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; float resultS1; float resultS2; double c; double resultD; double resultD1; double resultD2; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 0.0L, 4.0L, 2.0L, 4e-28L }; double outputs_D[kTableLength] = { 0.0L, 2.0L, sqrt2_d, 2e-14L }; float inputs_S[kTableLength] = { 0.0, 4.0, 2.0, 4e-28 }; float outputs_S[kTableLength] = { 0.0, 2.0, sqrt2_s, 2e-14 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ sqrt_s(f6, f2); __ sqrt_d(f12, f8); __ rsqrt_d(f14, f8); __ rsqrt_s(f16, f2); __ recip_d(f18, f8); __ recip_s(f4, f2); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resultS1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resultD1)) ); __ swc1(f4, MemOperand(a0, offsetof(TestFloat, resultS2)) ); __ sdc1(f18, MemOperand(a0, offsetof(TestFloat, resultD2)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { float f1; double d1; test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); if (i != 0) { f1 = test.resultS1 - 1.0F/outputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD1 - 1.0L/outputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); f1 = test.resultS2 - 1.0F/inputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD2 - 1.0L/inputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); } else { CHECK_EQ(test.resultS1, 1.0F/outputs_S[i]); CHECK_EQ(test.resultD1, 1.0L/outputs_D[i]); CHECK_EQ(test.resultS2, 1.0F/inputs_S[i]); CHECK_EQ(test.resultD2, 1.0L/inputs_D[i]); } } } TEST(neg) { const int kTableLength = 2; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; double c; double resultD; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 4.0, -2.0 }; double outputs_D[kTableLength] = { -4.0, 2.0 }; float inputs_S[kTableLength] = { 4.0, -2.0 }; float outputs_S[kTableLength] = { -4.0, 2.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ neg_s(f6, f2); __ neg_d(f12, f8); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
()); F3 f = FUNCTION_CAST(code->entry()); t.input = 0x12345678; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0x0, 0, 0, 0); USE(dummy); CHECK_EQ(static_cast(0x81234567), t.result_rotr_4); CHECK_EQ(static_cast(0x78123456), t.result_rotr_8); CHECK_EQ(static_cast(0x67812345), t.result_rotr_12); CHECK_EQ(static_cast(0x56781234), t.result_rotr_16); CHECK_EQ(static_cast(0x45678123), t.result_rotr_20); CHECK_EQ(static_cast(0x34567812), t.result_rotr_24); CHECK_EQ(static_cast(0x23456781), t.result_rotr_28); CHECK_EQ(static_cast(0x81234567), t.result_rotrv_4); CHECK_EQ(static_cast(0x78123456), t.result_rotrv_8); CHECK_EQ(static_cast(0x67812345), t.result_rotrv_12); CHECK_EQ(static_cast(0x56781234), t.result_rotrv_16); CHECK_EQ(static_cast(0x45678123), t.result_rotrv_20); CHECK_EQ(static_cast(0x34567812), t.result_rotrv_24); CHECK_EQ(static_cast(0x23456781), t.result_rotrv_28); } } TEST(MIPS9) { // Test BRANCH improvements. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); Label exit, exit2, exit3; __ Branch(&exit, ge, a0, Operand(zero_reg)); __ Branch(&exit2, ge, a0, Operand(0x00001FFF)); __ Branch(&exit3, ge, a0, Operand(0x0001FFFF)); __ bind(&exit); __ bind(&exit2); __ bind(&exit3); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); } TEST(MIPS10) { // Test conversions between doubles and long integers. // Test hos the long ints map to FP regs pairs. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double a; double a_converted; double b; int32_t dbl_mant; int32_t dbl_exp; int32_t long_hi; int32_t long_lo; int64_t long_as_int64; int32_t b_long_hi; int32_t b_long_lo; int64_t b_long_as_int64; } T; T t; Assembler assm(isolate, NULL, 0); Label L, C; if (kArchVariant == kMips64r2) { // Rewritten for FR=1 FPU mode: // - 32 FP regs of 64-bits each, no odd/even pairs. // - Note that cvt_l_d/cvt_d_l ARE legal in FR=1 mode. // Load all structure elements to registers. __ ldc1(f0, MemOperand(a0, offsetof(T, a))); // Save the raw bits of the double. __ mfc1(a4, f0); __ mfhc1(a5, f0); __ sw(a4, MemOperand(a0, offsetof(T, dbl_mant))); __ sw(a5, MemOperand(a0, offsetof(T, dbl_exp))); // Convert double in f0 to long, save hi/lo parts. __ cvt_l_d(f0, f0); __ mfc1(a4, f0); // f0 LS 32 bits of long. __ mfhc1(a5, f0); // f0 MS 32 bits of long. __ sw(a4, MemOperand(a0, offsetof(T, long_lo))); __ sw(a5, MemOperand(a0, offsetof(T, long_hi))); // Combine the high/low ints, convert back to double. __ dsll32(a6, a5, 0); // Move a5 to high bits of a6. __ or_(a6, a6, a4); __ dmtc1(a6, f1); __ cvt_d_l(f1, f1); __ sdc1(f1, MemOperand(a0, offsetof(T, a_converted))); // Convert the b long integers to double b. __ lw(a4, MemOperand(a0, offsetof(T, b_long_lo))); __ lw(a5, MemOperand(a0, offsetof(T, b_long_hi))); __ mtc1(a4, f8); // f8 LS 32-bits. __ mthc1(a5, f8); // f8 MS 32-bits. __ cvt_d_l(f10, f8); __ sdc1(f10, MemOperand(a0, offsetof(T, b))); // Convert double b back to long-int. __ ldc1(f31, MemOperand(a0, offsetof(T, b))); __ cvt_l_d(f31, f31); __ dmfc1(a7, f31); __ sd(a7, MemOperand(a0, offsetof(T, b_long_as_int64))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.a = 2.147483647e9; // 0x7fffffff -> 0x41DFFFFFFFC00000 as double. t.b_long_hi = 0x000000ff; // 0xFF00FF00FF -> 0x426FE01FE01FE000 as double. t.b_long_lo = 0x00ff00ff; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(static_cast(0x41DFFFFF), t.dbl_exp); CHECK_EQ(static_cast(0xFFC00000), t.dbl_mant); CHECK_EQ(0, t.long_hi); CHECK_EQ(static_cast(0x7fffffff), t.long_lo); CHECK_EQ(2.147483647e9, t.a_converted); // 0xFF00FF00FF -> 1.095233372415e12. CHECK_EQ(1.095233372415e12, t.b); CHECK_EQ(static_cast(0xFF00FF00FF), t.b_long_as_int64); } } TEST(MIPS11) { // Do not run test on MIPS64r6, as these instructions are removed. if (kArchVariant != kMips64r6) { // Test LWL, LWR, SWL and SWR instructions. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { int32_t reg_init; int32_t mem_init; int32_t lwl_0; int32_t lwl_1; int32_t lwl_2; int32_t lwl_3; int32_t lwr_0; int32_t lwr_1; int32_t lwr_2; int32_t lwr_3; int32_t swl_0; int32_t swl_1; int32_t swl_2; int32_t swl_3; int32_t swr_0; int32_t swr_1; int32_t swr_2; int32_t swr_3; } T; T t; Assembler assm(isolate, NULL, 0); // Test all combinations of LWL and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, lwl_0))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a5, MemOperand(a0, offsetof(T, mem_init) + 1)); __ sw(a5, MemOperand(a0, offsetof(T, lwl_1))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a6, MemOperand(a0, offsetof(T, mem_init) + 2)); __ sw(a6, MemOperand(a0, offsetof(T, lwl_2))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a7, MemOperand(a0, offsetof(T, mem_init) + 3)); __ sw(a7, MemOperand(a0, offsetof(T, lwl_3))); // Test all combinations of LWR and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, lwr_0))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a5, MemOperand(a0, offsetof(T, mem_init) + 1)); __ sw(a5, MemOperand(a0, offsetof(T, lwr_1))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a6, MemOperand(a0, offsetof(T, mem_init) + 2)); __ sw(a6, MemOperand(a0, offsetof(T, lwr_2)) ); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a7, MemOperand(a0, offsetof(T, mem_init) + 3)); __ sw(a7, MemOperand(a0, offsetof(T, lwr_3)) ); // Test all combinations of SWL and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, swl_0))); __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ swl(a4, MemOperand(a0, offsetof(T, swl_0))); __ lw(a5, MemOperand(a0, offsetof(T, mem_init))); __ sw(a5, MemOperand(a0, offsetof(T, swl_1))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ swl(a5, MemOperand(a0, offsetof(T, swl_1) + 1)); __ lw(a6, MemOperand(a0, offsetof(T, mem_init))); __ sw(a6, MemOperand(a0, offsetof(T, swl_2))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ swl(a6, MemOperand(a0, offsetof(T, swl_2) + 2)); __ lw(a7, MemOperand(a0, offsetof(T, mem_init))); __ sw(a7, MemOperand(a0, offsetof(T, swl_3))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ swl(a7, MemOperand(a0, offsetof(T, swl_3) + 3)); // Test all combinations of SWR and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, swr_0))); __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ swr(a4, MemOperand(a0, offsetof(T, swr_0))); __ lw(a5, MemOperand(a0, offsetof(T, mem_init))); __ sw(a5, MemOperand(a0, offsetof(T, swr_1))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ swr(a5, MemOperand(a0, offsetof(T, swr_1) + 1)); __ lw(a6, MemOperand(a0, offsetof(T, mem_init))); __ sw(a6, MemOperand(a0, offsetof(T, swr_2))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ swr(a6, MemOperand(a0, offsetof(T, swr_2) + 2)); __ lw(a7, MemOperand(a0, offsetof(T, mem_init))); __ sw(a7, MemOperand(a0, offsetof(T, swr_3))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ swr(a7, MemOperand(a0, offsetof(T, swr_3) + 3)); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.reg_init = 0xaabbccdd; t.mem_init = 0x11223344; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); if (kArchEndian == kLittle) { CHECK_EQ(static_cast(0x44bbccdd), t.lwl_0); CHECK_EQ(static_cast(0x3344ccdd), t.lwl_1); CHECK_EQ(static_cast(0x223344dd), t.lwl_2); CHECK_EQ(static_cast(0x11223344), t.lwl_3); CHECK_EQ(static_cast(0x11223344), t.lwr_0); CHECK_EQ(static_cast(0xaa112233), t.lwr_1); CHECK_EQ(static_cast(0xaabb1122), t.lwr_2); CHECK_EQ(static_cast(0xaabbcc11), t.lwr_3); CHECK_EQ(static_cast(0x112233aa), t.swl_0); CHECK_EQ(static_cast(0x1122aabb), t.swl_1); CHECK_EQ(static_cast(0x11aabbcc), t.swl_2); CHECK_EQ(static_cast(0xaabbccdd), t.swl_3); CHECK_EQ(static_cast(0xaabbccdd), t.swr_0); CHECK_EQ(static_cast(0xbbccdd44), t.swr_1); CHECK_EQ(static_cast(0xccdd3344), t.swr_2); CHECK_EQ(static_cast(0xdd223344), t.swr_3); } else { CHECK_EQ(static_cast(0x11223344), t.lwl_0); CHECK_EQ(static_cast(0x223344dd), t.lwl_1); CHECK_EQ(static_cast(0x3344ccdd), t.lwl_2); CHECK_EQ(static_cast(0x44bbccdd), t.lwl_3); CHECK_EQ(static_cast(0xaabbcc11), t.lwr_0); CHECK_EQ(static_cast(0xaabb1122), t.lwr_1); CHECK_EQ(static_cast(0xaa112233), t.lwr_2); CHECK_EQ(static_cast(0x11223344), t.lwr_3); CHECK_EQ(static_cast(0xaabbccdd), t.swl_0); CHECK_EQ(static_cast(0x11aabbcc), t.swl_1); CHECK_EQ(static_cast(0x1122aabb), t.swl_2); CHECK_EQ(static_cast(0x112233aa), t.swl_3); CHECK_EQ(static_cast(0xdd223344), t.swr_0); CHECK_EQ(static_cast(0xccdd3344), t.swr_1); CHECK_EQ(static_cast(0xbbccdd44), t.swr_2); CHECK_EQ(static_cast(0xaabbccdd), t.swr_3); } } } TEST(MIPS12) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { int32_t x; int32_t y; int32_t y1; int32_t y2; int32_t y3; int32_t y4; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ mov(t2, fp); // Save frame pointer. __ mov(fp, a0); // Access struct T by fp. __ lw(a4, MemOperand(a0, offsetof(T, y))); __ lw(a7, MemOperand(a0, offsetof(T, y4))); __ addu(a5, a4, a7); __ subu(t0, a4, a7); __ nop(); __ push(a4); // These instructions disappear after opt. __ Pop(); __ addu(a4, a4, a4); __ nop(); __ Pop(); // These instructions disappear after opt. __ push(a7); __ nop(); __ push(a7); // These instructions disappear after opt. __ pop(a7); __ nop(); __ push(a7); __ pop(t0); __ nop(); __ sw(a4, MemOperand(fp, offsetof(T, y))); __ lw(a4, MemOperand(fp, offsetof(T, y))); __ nop(); __ sw(a4, MemOperand(fp, offsetof(T, y))); __ lw(a5, MemOperand(fp, offsetof(T, y))); __ nop(); __ push(a5); __ lw(a5, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a6); __ nop(); __ push(a6); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a7); __ nop(); __ mov(fp, t2); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.x = 1; t.y = 2; t.y1 = 3; t.y2 = 4; t.y3 = 0XBABA; t.y4 = 0xDEDA; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(3, t.y1); } TEST(MIPS13) { // Test Cvt_d_uw and Trunc_uw_d macros. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double cvt_big_out; double cvt_small_out; uint32_t trunc_big_out; uint32_t trunc_small_out; uint32_t cvt_big_in; uint32_t cvt_small_in; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ sw(a4, MemOperand(a0, offsetof(T, cvt_small_in))); __ Cvt_d_uw(f10, a4); __ sdc1(f10, MemOperand(a0, offsetof(T, cvt_small_out))); __ Trunc_uw_d(f10, f10, f4); __ swc1(f10, MemOperand(a0, offsetof(T, trunc_small_out))); __ sw(a4, MemOperand(a0, offsetof(T, cvt_big_in))); __ Cvt_d_uw(f8, a4); __ sdc1(f8, MemOperand(a0, offsetof(T, cvt_big_out))); __ Trunc_uw_d(f8, f8, f4); __ swc1(f8, MemOperand(a0, offsetof(T, trunc_big_out))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.cvt_big_in = 0xFFFFFFFF; t.cvt_small_in = 333; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(t.cvt_big_out, static_cast(t.cvt_big_in)); CHECK_EQ(t.cvt_small_out, static_cast(t.cvt_small_in)); CHECK_EQ(static_cast(t.trunc_big_out), static_cast(t.cvt_big_in)); CHECK_EQ(static_cast(t.trunc_small_out), static_cast(t.cvt_small_in)); } TEST(MIPS14) { // Test round, floor, ceil, trunc, cvt. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); #define ROUND_STRUCT_ELEMENT(x) \ uint32_t x##_isNaN2008; \ int32_t x##_up_out; \ int32_t x##_down_out; \ int32_t neg_##x##_up_out; \ int32_t neg_##x##_down_out; \ uint32_t x##_err1_out; \ uint32_t x##_err2_out; \ uint32_t x##_err3_out; \ uint32_t x##_err4_out; \ int32_t x##_invalid_result; typedef struct { double round_up_in; double round_down_in; double neg_round_up_in; double neg_round_down_in; double err1_in; double err2_in; double err3_in; double err4_in; ROUND_STRUCT_ELEMENT(round) ROUND_STRUCT_ELEMENT(floor) ROUND_STRUCT_ELEMENT(ceil) ROUND_STRUCT_ELEMENT(trunc) ROUND_STRUCT_ELEMENT(cvt) } T; T t; #undef ROUND_STRUCT_ELEMENT MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); // Save FCSR. __ cfc1(a1, FCSR); // Disable FPU exceptions. __ ctc1(zero_reg, FCSR); #define RUN_ROUND_TEST(x) \ __ cfc1(t0, FCSR);\ __ sw(t0, MemOperand(a0, offsetof(T, x##_isNaN2008))); \ __ ldc1(f0, MemOperand(a0, offsetof(T, round_up_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_up_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, round_down_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_down_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, neg_round_up_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, neg_##x##_up_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, neg_round_down_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, neg_##x##_down_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err1_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err1_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err2_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err2_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err3_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err3_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err4_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err4_out))); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_invalid_result))); RUN_ROUND_TEST(round) RUN_ROUND_TEST(floor) RUN_ROUND_TEST(ceil) RUN_ROUND_TEST(trunc) RUN_ROUND_TEST(cvt) // Restore FCSR. __ ctc1(a1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.round_up_in = 123.51; t.round_down_in = 123.49; t.neg_round_up_in = -123.5; t.neg_round_down_in = -123.49; t.err1_in = 123.51; t.err2_in = 1; t.err3_in = static_cast(1) + 0xFFFFFFFF; t.err4_in = NAN; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); #define GET_FPU_ERR(x) (static_cast(x & kFCSRFlagMask)) #define CHECK_NAN2008(x) (x & kFCSRNaN2008FlagMask) #define CHECK_ROUND_RESULT(type) \ CHECK(GET_FPU_ERR(t.type##_err1_out) & kFCSRInexactFlagMask); \ CHECK_EQ(0, GET_FPU_ERR(t.type##_err2_out)); \ CHECK(GET_FPU_ERR(t.type##_err3_out) & kFCSRInvalidOpFlagMask); \ CHECK(GET_FPU_ERR(t.type##_err4_out) & kFCSRInvalidOpFlagMask); \ if (CHECK_NAN2008(t.type##_isNaN2008) && kArchVariant == kMips64r6) { \ CHECK_EQ(static_cast(0), t.type##_invalid_result);\ } else { \ CHECK_EQ(static_cast(kFPUInvalidResult), t.type##_invalid_result);\ } CHECK_ROUND_RESULT(round); CHECK_ROUND_RESULT(floor); CHECK_ROUND_RESULT(ceil); CHECK_ROUND_RESULT(cvt); } TEST(MIPS15) { // Test chaining of label usages within instructions (issue 1644). CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); Assembler assm(isolate, NULL, 0); Label target; __ beq(v0, v1, &target); __ nop(); __ bne(v0, v1, &target); __ nop(); __ bind(&target); __ nop(); } // ----- mips64 tests ----------------------------------------------- TEST(MIPS16) { // Test 64-bit memory loads and stores. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); struct T { int64_t r1; int64_t r2; int64_t r3; int64_t r4; int64_t r5; int64_t r6; int64_t r7; int64_t r8; int64_t r9; int64_t r10; int64_t r11; int64_t r12; uint32_t ui; int32_t si; }; T t; Assembler assm(isolate, NULL, 0); Label L, C; // Basic 32-bit word load/store, with un-signed data. __ lw(a4, MemOperand(a0, offsetof(T, ui))); __ sw(a4, MemOperand(a0, offsetof(T, r1))); // Check that the data got zero-extended into 64-bit a4. __ sd(a4, MemOperand(a0, offsetof(T, r2))); // Basic 32-bit word load/store, with SIGNED data. __ lw(a5, MemOperand(a0, offsetof(T, si))); __ sw(a5, MemOperand(a0, offsetof(T, r3))); // Check that the data got sign-extended into 64-bit a4. __ sd(a5, MemOperand(a0, offsetof(T, r4))); // 32-bit UNSIGNED word load/store, with SIGNED data. __ lwu(a6, MemOperand(a0, offsetof(T, si))); __ sw(a6, MemOperand(a0, offsetof(T, r5))); // Check that the data got zero-extended into 64-bit a4. __ sd(a6, MemOperand(a0, offsetof(T, r6))); // lh with positive data. __ lh(a5, MemOperand(a0, offsetof(T, ui))); __ sw(a5, MemOperand(a0, offsetof(T, r7))); // lh with negative data. __ lh(a6, MemOperand(a0, offsetof(T, si))); __ sw(a6, MemOperand(a0, offsetof(T, r8))); // lhu with negative data. __ lhu(a7, MemOperand(a0, offsetof(T, si))); __ sw(a7, MemOperand(a0, offsetof(T, r9))); // lb with negative data. __ lb(t0, MemOperand(a0, offsetof(T, si))); __ sw(t0, MemOperand(a0, offsetof(T, r10))); // sh writes only 1/2 of word. __ lw(a4, MemOperand(a0, offsetof(T, ui))); __ sh(a4, MemOperand(a0, offsetof(T, r11))); __ lw(a4, MemOperand(a0, offsetof(T, si))); __ sh(a4, MemOperand(a0, offsetof(T, r12))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.ui = 0x44332211; t.si = 0x99aabbcc; t.r1 = 0x5555555555555555; t.r2 = 0x5555555555555555; t.r3 = 0x5555555555555555; t.r4 = 0x5555555555555555; t.r5 = 0x5555555555555555; t.r6 = 0x5555555555555555; t.r7 = 0x5555555555555555; t.r8 = 0x5555555555555555; t.r9 = 0x5555555555555555; t.r10 = 0x5555555555555555; t.r11 = 0x5555555555555555; t.r12 = 0x5555555555555555; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); if (kArchEndian == kLittle) { // Unsigned data, 32 & 64 CHECK_EQ(static_cast(0x5555555544332211L), t.r1); // lw, sw. CHECK_EQ(static_cast(0x0000000044332211L), t.r2); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x5555555599aabbccL), t.r3); // lw, sw. CHECK_EQ(static_cast(0xffffffff99aabbccL), t.r4); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x5555555599aabbccL), t.r5); // lwu, sw. CHECK_EQ(static_cast(0x0000000099aabbccL), t.r6); // sd. // lh with unsigned and signed data. CHECK_EQ(static_cast(0x5555555500002211L), t.r7); // lh, sw. CHECK_EQ(static_cast(0x55555555ffffbbccL), t.r8); // lh, sw. // lhu with signed data. CHECK_EQ(static_cast(0x555555550000bbccL), t.r9); // lhu, sw. // lb with signed data. CHECK_EQ(static_cast(0x55555555ffffffccL), t.r10); // lb, sw. // sh with unsigned and signed data. CHECK_EQ(static_cast(0x5555555555552211L), t.r11); // lw, sh. CHECK_EQ(static_cast(0x555555555555bbccL), t.r12); // lw, sh. } else { // Unsigned data, 32 & 64 CHECK_EQ(static_cast(0x4433221155555555L), t.r1); // lw, sw. CHECK_EQ(static_cast(0x0000000044332211L), t.r2); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x99aabbcc55555555L), t.r3); // lw, sw. CHECK_EQ(static_cast(0xffffffff99aabbccL), t.r4); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x99aabbcc55555555L), t.r5); // lwu, sw. CHECK_EQ(static_cast(0x0000000099aabbccL), t.r6); // sd. // lh with unsigned and signed data. CHECK_EQ(static_cast(0x0000443355555555L), t.r7); // lh, sw. CHECK_EQ(static_cast(0xffff99aa55555555L), t.r8); // lh, sw. // lhu with signed data. CHECK_EQ(static_cast(0x000099aa55555555L), t.r9); // lhu, sw. // lb with signed data. CHECK_EQ(static_cast(0xffffff9955555555L), t.r10); // lb, sw. // sh with unsigned and signed data. CHECK_EQ(static_cast(0x2211555555555555L), t.r11); // lw, sh. CHECK_EQ(static_cast(0xbbcc555555555555L), t.r12); // lw, sh. } } // ----------------------mips64r6 specific tests---------------------- TEST(seleqz_selnez) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { int a; int b; int c; int d; double e; double f; double g; double h; float i; float j; float k; float l; } Test; Test test; // Integer part of test. __ addiu(t1, zero_reg, 1); // t1 = 1 __ seleqz(t3, t1, zero_reg); // t3 = 1 __ sw(t3, MemOperand(a0, offsetof(Test, a))); // a = 1 __ seleqz(t2, t1, t1); // t2 = 0 __ sw(t2, MemOperand(a0, offsetof(Test, b))); // b = 0 __ selnez(t3, t1, zero_reg); // t3 = 1; __ sw(t3, MemOperand(a0, offsetof(Test, c))); // c = 0 __ selnez(t3, t1, t1); // t3 = 1 __ sw(t3, MemOperand(a0, offsetof(Test, d))); // d = 1 // Floating point part of test. __ ldc1(f0, MemOperand(a0, offsetof(Test, e)) ); // src __ ldc1(f2, MemOperand(a0, offsetof(Test, f)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, i)) ); // src __ lwc1(f10, MemOperand(a0, offsetof(Test, j)) ); // test __ seleqz_d(f4, f0, f2); __ selnez_d(f6, f0, f2); __ seleqz_s(f12, f8, f10); __ selnez_s(f14, f8, f10); __ sdc1(f4, MemOperand(a0, offsetof(Test, g)) ); // src __ sdc1(f6, MemOperand(a0, offsetof(Test, h)) ); // src __ swc1(f12, MemOperand(a0, offsetof(Test, k)) ); // src __ swc1(f14, MemOperand(a0, offsetof(Test, l)) ); // src __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.a, 1); CHECK_EQ(test.b, 0); CHECK_EQ(test.c, 0); CHECK_EQ(test.d, 1); const int test_size = 3; const int input_size = 5; double inputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double outputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float inputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float outputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.e = inputs_D[i]; test.f = tests_D[j]; test.i = inputs_S[i]; test.j = tests_S[j]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, outputs_D[i]); CHECK_EQ(test.h, 0); CHECK_EQ(test.k, outputs_S[i]); CHECK_EQ(test.l, 0); test.f = tests_D[j+1]; test.j = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, 0); CHECK_EQ(test.h, outputs_D[i]); CHECK_EQ(test.k, 0); CHECK_EQ(test.l, outputs_S[i]); } } } } TEST(min_max) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); struct TestFloat { double a; double b; double c; double d; float e; float f; float g; float h; }; TestFloat test; const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); const int kTableLength = 13; double inputsa[kTableLength] = {2.0, 3.0, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = {3.0, 2.0, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double outputsdmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double outputsdmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputse[kTableLength] = {2.0, 3.0, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsf[kTableLength] = {3.0, 2.0, 3.0, fnan, 0.0, -0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float outputsfmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float outputsfmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a))); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, b))); __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, e))); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, f))); __ min_d(f10, f4, f8); __ max_d(f12, f4, f8); __ min_s(f14, f2, f6); __ max_s(f16, f2, f6); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, c))); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, d))); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, g))); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, h))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 4; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.e = inputse[i]; test.f = inputsf[i]; CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0); CHECK_EQ(0, memcmp(&test.c, &outputsdmin[i], sizeof(test.c))); CHECK_EQ(0, memcmp(&test.d, &outputsdmax[i], sizeof(test.d))); CHECK_EQ(0, memcmp(&test.g, &outputsfmin[i], sizeof(test.g))); CHECK_EQ(0, memcmp(&test.h, &outputsfmax[i], sizeof(test.h))); } } } TEST(rint_d) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; int fcsr; }TestFloat; TestFloat test; double inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E+308, 6.27463370218383111104242366943E-307, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ ctc1(t0, FCSR); __ rint_d(f8, f4); __ sdc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(sel) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { double dd; double ds; double dt; float fd; float fs; float ft; } Test; Test test; __ ldc1(f0, MemOperand(a0, offsetof(Test, dd)) ); // test __ ldc1(f2, MemOperand(a0, offsetof(Test, ds)) ); // src1 __ ldc1(f4, MemOperand(a0, offsetof(Test, dt)) ); // src2 __ lwc1(f6, MemOperand(a0, offsetof(Test, fd)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, fs)) ); // src1 __ lwc1(f10, MemOperand(a0, offsetof(Test, ft)) ); // src2 __ sel_d(f0, f2, f4); __ sel_s(f6, f8, f10); __ sdc1(f0, MemOperand(a0, offsetof(Test, dd)) ); __ swc1(f6, MemOperand(a0, offsetof(Test, fd)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); const int test_size = 3; const int input_size = 5; double inputs_dt[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double inputs_ds[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; float inputs_ft[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float inputs_fs[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.dt = inputs_dt[i]; test.dd = tests_D[j]; test.ds = inputs_ds[i]; test.ft = inputs_ft[i]; test.fd = tests_S[j]; test.fs = inputs_fs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_ds[i]); CHECK_EQ(test.fd, inputs_fs[i]); test.dd = tests_D[j+1]; test.fd = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_dt[i]); CHECK_EQ(test.fd, inputs_ft[i]); } } } } TEST(rint_s) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; int fcsr; }TestFloat; TestFloat test; float inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E+38, 6.27463370218383111104242366943E-37, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; float* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ rint_s(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(mina_maxa) { if (kArchVariant == kMips64r6) { const int kTableLength = 23; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); struct TestFloat { double a; double b; double resd; double resd1; float c; float d; float resf; float resf1; }; TestFloat test; double inputsa[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = { 4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double resd[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double resd1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputsc[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsd[kTableLength] = {4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, fnan, -0.0, 0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float resf[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float resf1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ lwc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ lwc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ mina_d(f6, f2, f4); __ mina_s(f12, f8, f10); __ maxa_d(f14, f2, f4); __ maxa_s(f16, f8, f10); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, resf)) ); __ sdc1(f6, MemOperand(a0, offsetof(TestFloat, resd)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resf1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resd1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.c = inputsc[i]; test.d = inputsd[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if (i < kTableLength - 1) { CHECK_EQ(test.resd, resd[i]); CHECK_EQ(test.resf, resf[i]); CHECK_EQ(test.resd1, resd1[i]); CHECK_EQ(test.resf1, resf1[i]); } else { CHECK(std::isnan(test.resd)); CHECK(std::isnan(test.resf)); CHECK(std::isnan(test.resd1)); CHECK(std::isnan(test.resf1)); } } } } // ----------------------mips64r2 specific tests---------------------- TEST(trunc_l) { if (kArchVariant == kMips64r2) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; // a trunc result int64_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_l_d(f8, f4); __ trunc_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } } TEST(movz_movn) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { int64_t rt; double a; double b; double bold; double b1; double bold1; float c; float d; float dold; float d1; float dold1; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ld(t0, MemOperand(a0, offsetof(TestFloat, rt))); __ Move(f12, 0.0); __ Move(f10, 0.0); __ Move(f16, 0.0); __ Move(f14, 0.0); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, bold)) ); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, dold)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, bold1)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, dold1)) ); __ movz_s(f10, f6, t0); __ movz_d(f12, f2, t0); __ movn_s(f14, f6, t0); __ movn_d(f16, f2, t0); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, b)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, d1)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, b1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; test.rt = 1; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, test.bold); CHECK_EQ(test.d, test.dold); CHECK_EQ(test.b1, outputs_D[i]); CHECK_EQ(test.d1, outputs_S[i]); test.rt = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); CHECK_EQ(test.b1, test.bold1); CHECK_EQ(test.d1, test.dold1); } } } TEST(movt_movd) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); typedef struct test_float { double srcd; double dstd; double dstdold; double dstd1; double dstdold1; float srcf; float dstf; float dstfold; float dstf1; float dstfold1; int32_t cc; int32_t fcsr; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; double inputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; int condition_flags[8] = {0, 1, 2, 3, 4, 5, 6, 7}; for (int i = 0; i < kTableLength; i++) { test.srcd = inputs_D[i]; test.srcf = inputs_S[i]; for (int j = 0; j< 8; j++) { test.cc = condition_flags[j]; if (test.cc == 0) { test.fcsr = 1 << 23; } else { test.fcsr = 1 << (24+condition_flags[j]); } HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, srcd)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, srcf)) ); __ lw(t1, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t0, FCSR); __ ctc1(t1, FCSR); __ li(t2, 0x0); __ mtc1(t2, f12); __ mtc1(t2, f10); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold)) ); __ movt_s(f12, f4, test.cc); __ movt_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold1)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold1)) ); __ movf_s(f12, f4, test.cc); __ movf_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf1)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd1)) ); __ ctc1(t0, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, outputs_S[i]); CHECK_EQ(test.dstd, outputs_D[i]); CHECK_EQ(test.dstf1, test.dstfold1); CHECK_EQ(test.dstd1, test.dstdold1); test.fcsr = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, test.dstfold); CHECK_EQ(test.dstd, test.dstdold); CHECK_EQ(test.dstf1, outputs_S[i]); CHECK_EQ(test.dstd1, outputs_D[i]); } } } } // ----------------------tests for all archs-------------------------- TEST(cvt_w_d) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; int32_t b; int fcsr; }Test; const int kTableLength = 24; double inputs[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, 2147483653.0 }; double outputs_RN[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RZ[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RP[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RM[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lw(t0, MemOperand(a0, offsetof(Test, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ cvt_w_d(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(Test, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } TEST(trunc_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_w_d(f8, f4); __ trunc_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_w_d(f8, f4); __ round_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_l_d(f8, f4); __ round_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(sub) { const int kTableLength = 12; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; double inputft_D[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; double outputs_D[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; float inputfs_S[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; float inputft_S[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; float outputs_S[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sub_s(f6, f2, f4); __ sub_d(f12, f8, f10); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(sqrt_rsqrt_recip) { const int kTableLength = 4; const double deltaDouble = 2E-15; const float deltaFloat = 2E-7; const float sqrt2_s = sqrt(2); const double sqrt2_d = sqrt(2); CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; float resultS1; float resultS2; double c; double resultD; double resultD1; double resultD2; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 0.0L, 4.0L, 2.0L, 4e-28L }; double outputs_D[kTableLength] = { 0.0L, 2.0L, sqrt2_d, 2e-14L }; float inputs_S[kTableLength] = { 0.0, 4.0, 2.0, 4e-28 }; float outputs_S[kTableLength] = { 0.0, 2.0, sqrt2_s, 2e-14 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ sqrt_s(f6, f2); __ sqrt_d(f12, f8); __ rsqrt_d(f14, f8); __ rsqrt_s(f16, f2); __ recip_d(f18, f8); __ recip_s(f4, f2); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resultS1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resultD1)) ); __ swc1(f4, MemOperand(a0, offsetof(TestFloat, resultS2)) ); __ sdc1(f18, MemOperand(a0, offsetof(TestFloat, resultD2)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { float f1; double d1; test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); if (i != 0) { f1 = test.resultS1 - 1.0F/outputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD1 - 1.0L/outputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); f1 = test.resultS2 - 1.0F/inputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD2 - 1.0L/inputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); } else { CHECK_EQ(test.resultS1, 1.0F/outputs_S[i]); CHECK_EQ(test.resultD1, 1.0L/outputs_D[i]); CHECK_EQ(test.resultS2, 1.0F/inputs_S[i]); CHECK_EQ(test.resultD2, 1.0L/inputs_D[i]); } } } TEST(neg) { const int kTableLength = 2; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; double c; double resultD; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 4.0, -2.0 }; double outputs_D[kTableLength] = { -4.0, 2.0 }; float inputs_S[kTableLength] = { 4.0, -2.0 }; float outputs_S[kTableLength] = { -4.0, 2.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ neg_s(f6, f2); __ neg_d(f12, f8); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
()); } TEST(MIPS10) { // Test conversions between doubles and long integers. // Test hos the long ints map to FP regs pairs. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double a; double a_converted; double b; int32_t dbl_mant; int32_t dbl_exp; int32_t long_hi; int32_t long_lo; int64_t long_as_int64; int32_t b_long_hi; int32_t b_long_lo; int64_t b_long_as_int64; } T; T t; Assembler assm(isolate, NULL, 0); Label L, C; if (kArchVariant == kMips64r2) { // Rewritten for FR=1 FPU mode: // - 32 FP regs of 64-bits each, no odd/even pairs. // - Note that cvt_l_d/cvt_d_l ARE legal in FR=1 mode. // Load all structure elements to registers. __ ldc1(f0, MemOperand(a0, offsetof(T, a))); // Save the raw bits of the double. __ mfc1(a4, f0); __ mfhc1(a5, f0); __ sw(a4, MemOperand(a0, offsetof(T, dbl_mant))); __ sw(a5, MemOperand(a0, offsetof(T, dbl_exp))); // Convert double in f0 to long, save hi/lo parts. __ cvt_l_d(f0, f0); __ mfc1(a4, f0); // f0 LS 32 bits of long. __ mfhc1(a5, f0); // f0 MS 32 bits of long. __ sw(a4, MemOperand(a0, offsetof(T, long_lo))); __ sw(a5, MemOperand(a0, offsetof(T, long_hi))); // Combine the high/low ints, convert back to double. __ dsll32(a6, a5, 0); // Move a5 to high bits of a6. __ or_(a6, a6, a4); __ dmtc1(a6, f1); __ cvt_d_l(f1, f1); __ sdc1(f1, MemOperand(a0, offsetof(T, a_converted))); // Convert the b long integers to double b. __ lw(a4, MemOperand(a0, offsetof(T, b_long_lo))); __ lw(a5, MemOperand(a0, offsetof(T, b_long_hi))); __ mtc1(a4, f8); // f8 LS 32-bits. __ mthc1(a5, f8); // f8 MS 32-bits. __ cvt_d_l(f10, f8); __ sdc1(f10, MemOperand(a0, offsetof(T, b))); // Convert double b back to long-int. __ ldc1(f31, MemOperand(a0, offsetof(T, b))); __ cvt_l_d(f31, f31); __ dmfc1(a7, f31); __ sd(a7, MemOperand(a0, offsetof(T, b_long_as_int64))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.a = 2.147483647e9; // 0x7fffffff -> 0x41DFFFFFFFC00000 as double. t.b_long_hi = 0x000000ff; // 0xFF00FF00FF -> 0x426FE01FE01FE000 as double. t.b_long_lo = 0x00ff00ff; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(static_cast(0x41DFFFFF), t.dbl_exp); CHECK_EQ(static_cast(0xFFC00000), t.dbl_mant); CHECK_EQ(0, t.long_hi); CHECK_EQ(static_cast(0x7fffffff), t.long_lo); CHECK_EQ(2.147483647e9, t.a_converted); // 0xFF00FF00FF -> 1.095233372415e12. CHECK_EQ(1.095233372415e12, t.b); CHECK_EQ(static_cast(0xFF00FF00FF), t.b_long_as_int64); } } TEST(MIPS11) { // Do not run test on MIPS64r6, as these instructions are removed. if (kArchVariant != kMips64r6) { // Test LWL, LWR, SWL and SWR instructions. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { int32_t reg_init; int32_t mem_init; int32_t lwl_0; int32_t lwl_1; int32_t lwl_2; int32_t lwl_3; int32_t lwr_0; int32_t lwr_1; int32_t lwr_2; int32_t lwr_3; int32_t swl_0; int32_t swl_1; int32_t swl_2; int32_t swl_3; int32_t swr_0; int32_t swr_1; int32_t swr_2; int32_t swr_3; } T; T t; Assembler assm(isolate, NULL, 0); // Test all combinations of LWL and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, lwl_0))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a5, MemOperand(a0, offsetof(T, mem_init) + 1)); __ sw(a5, MemOperand(a0, offsetof(T, lwl_1))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a6, MemOperand(a0, offsetof(T, mem_init) + 2)); __ sw(a6, MemOperand(a0, offsetof(T, lwl_2))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a7, MemOperand(a0, offsetof(T, mem_init) + 3)); __ sw(a7, MemOperand(a0, offsetof(T, lwl_3))); // Test all combinations of LWR and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, lwr_0))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a5, MemOperand(a0, offsetof(T, mem_init) + 1)); __ sw(a5, MemOperand(a0, offsetof(T, lwr_1))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a6, MemOperand(a0, offsetof(T, mem_init) + 2)); __ sw(a6, MemOperand(a0, offsetof(T, lwr_2)) ); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a7, MemOperand(a0, offsetof(T, mem_init) + 3)); __ sw(a7, MemOperand(a0, offsetof(T, lwr_3)) ); // Test all combinations of SWL and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, swl_0))); __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ swl(a4, MemOperand(a0, offsetof(T, swl_0))); __ lw(a5, MemOperand(a0, offsetof(T, mem_init))); __ sw(a5, MemOperand(a0, offsetof(T, swl_1))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ swl(a5, MemOperand(a0, offsetof(T, swl_1) + 1)); __ lw(a6, MemOperand(a0, offsetof(T, mem_init))); __ sw(a6, MemOperand(a0, offsetof(T, swl_2))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ swl(a6, MemOperand(a0, offsetof(T, swl_2) + 2)); __ lw(a7, MemOperand(a0, offsetof(T, mem_init))); __ sw(a7, MemOperand(a0, offsetof(T, swl_3))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ swl(a7, MemOperand(a0, offsetof(T, swl_3) + 3)); // Test all combinations of SWR and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, swr_0))); __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ swr(a4, MemOperand(a0, offsetof(T, swr_0))); __ lw(a5, MemOperand(a0, offsetof(T, mem_init))); __ sw(a5, MemOperand(a0, offsetof(T, swr_1))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ swr(a5, MemOperand(a0, offsetof(T, swr_1) + 1)); __ lw(a6, MemOperand(a0, offsetof(T, mem_init))); __ sw(a6, MemOperand(a0, offsetof(T, swr_2))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ swr(a6, MemOperand(a0, offsetof(T, swr_2) + 2)); __ lw(a7, MemOperand(a0, offsetof(T, mem_init))); __ sw(a7, MemOperand(a0, offsetof(T, swr_3))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ swr(a7, MemOperand(a0, offsetof(T, swr_3) + 3)); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.reg_init = 0xaabbccdd; t.mem_init = 0x11223344; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); if (kArchEndian == kLittle) { CHECK_EQ(static_cast(0x44bbccdd), t.lwl_0); CHECK_EQ(static_cast(0x3344ccdd), t.lwl_1); CHECK_EQ(static_cast(0x223344dd), t.lwl_2); CHECK_EQ(static_cast(0x11223344), t.lwl_3); CHECK_EQ(static_cast(0x11223344), t.lwr_0); CHECK_EQ(static_cast(0xaa112233), t.lwr_1); CHECK_EQ(static_cast(0xaabb1122), t.lwr_2); CHECK_EQ(static_cast(0xaabbcc11), t.lwr_3); CHECK_EQ(static_cast(0x112233aa), t.swl_0); CHECK_EQ(static_cast(0x1122aabb), t.swl_1); CHECK_EQ(static_cast(0x11aabbcc), t.swl_2); CHECK_EQ(static_cast(0xaabbccdd), t.swl_3); CHECK_EQ(static_cast(0xaabbccdd), t.swr_0); CHECK_EQ(static_cast(0xbbccdd44), t.swr_1); CHECK_EQ(static_cast(0xccdd3344), t.swr_2); CHECK_EQ(static_cast(0xdd223344), t.swr_3); } else { CHECK_EQ(static_cast(0x11223344), t.lwl_0); CHECK_EQ(static_cast(0x223344dd), t.lwl_1); CHECK_EQ(static_cast(0x3344ccdd), t.lwl_2); CHECK_EQ(static_cast(0x44bbccdd), t.lwl_3); CHECK_EQ(static_cast(0xaabbcc11), t.lwr_0); CHECK_EQ(static_cast(0xaabb1122), t.lwr_1); CHECK_EQ(static_cast(0xaa112233), t.lwr_2); CHECK_EQ(static_cast(0x11223344), t.lwr_3); CHECK_EQ(static_cast(0xaabbccdd), t.swl_0); CHECK_EQ(static_cast(0x11aabbcc), t.swl_1); CHECK_EQ(static_cast(0x1122aabb), t.swl_2); CHECK_EQ(static_cast(0x112233aa), t.swl_3); CHECK_EQ(static_cast(0xdd223344), t.swr_0); CHECK_EQ(static_cast(0xccdd3344), t.swr_1); CHECK_EQ(static_cast(0xbbccdd44), t.swr_2); CHECK_EQ(static_cast(0xaabbccdd), t.swr_3); } } } TEST(MIPS12) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { int32_t x; int32_t y; int32_t y1; int32_t y2; int32_t y3; int32_t y4; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ mov(t2, fp); // Save frame pointer. __ mov(fp, a0); // Access struct T by fp. __ lw(a4, MemOperand(a0, offsetof(T, y))); __ lw(a7, MemOperand(a0, offsetof(T, y4))); __ addu(a5, a4, a7); __ subu(t0, a4, a7); __ nop(); __ push(a4); // These instructions disappear after opt. __ Pop(); __ addu(a4, a4, a4); __ nop(); __ Pop(); // These instructions disappear after opt. __ push(a7); __ nop(); __ push(a7); // These instructions disappear after opt. __ pop(a7); __ nop(); __ push(a7); __ pop(t0); __ nop(); __ sw(a4, MemOperand(fp, offsetof(T, y))); __ lw(a4, MemOperand(fp, offsetof(T, y))); __ nop(); __ sw(a4, MemOperand(fp, offsetof(T, y))); __ lw(a5, MemOperand(fp, offsetof(T, y))); __ nop(); __ push(a5); __ lw(a5, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a6); __ nop(); __ push(a6); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a7); __ nop(); __ mov(fp, t2); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.x = 1; t.y = 2; t.y1 = 3; t.y2 = 4; t.y3 = 0XBABA; t.y4 = 0xDEDA; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(3, t.y1); } TEST(MIPS13) { // Test Cvt_d_uw and Trunc_uw_d macros. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double cvt_big_out; double cvt_small_out; uint32_t trunc_big_out; uint32_t trunc_small_out; uint32_t cvt_big_in; uint32_t cvt_small_in; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ sw(a4, MemOperand(a0, offsetof(T, cvt_small_in))); __ Cvt_d_uw(f10, a4); __ sdc1(f10, MemOperand(a0, offsetof(T, cvt_small_out))); __ Trunc_uw_d(f10, f10, f4); __ swc1(f10, MemOperand(a0, offsetof(T, trunc_small_out))); __ sw(a4, MemOperand(a0, offsetof(T, cvt_big_in))); __ Cvt_d_uw(f8, a4); __ sdc1(f8, MemOperand(a0, offsetof(T, cvt_big_out))); __ Trunc_uw_d(f8, f8, f4); __ swc1(f8, MemOperand(a0, offsetof(T, trunc_big_out))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.cvt_big_in = 0xFFFFFFFF; t.cvt_small_in = 333; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(t.cvt_big_out, static_cast(t.cvt_big_in)); CHECK_EQ(t.cvt_small_out, static_cast(t.cvt_small_in)); CHECK_EQ(static_cast(t.trunc_big_out), static_cast(t.cvt_big_in)); CHECK_EQ(static_cast(t.trunc_small_out), static_cast(t.cvt_small_in)); } TEST(MIPS14) { // Test round, floor, ceil, trunc, cvt. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); #define ROUND_STRUCT_ELEMENT(x) \ uint32_t x##_isNaN2008; \ int32_t x##_up_out; \ int32_t x##_down_out; \ int32_t neg_##x##_up_out; \ int32_t neg_##x##_down_out; \ uint32_t x##_err1_out; \ uint32_t x##_err2_out; \ uint32_t x##_err3_out; \ uint32_t x##_err4_out; \ int32_t x##_invalid_result; typedef struct { double round_up_in; double round_down_in; double neg_round_up_in; double neg_round_down_in; double err1_in; double err2_in; double err3_in; double err4_in; ROUND_STRUCT_ELEMENT(round) ROUND_STRUCT_ELEMENT(floor) ROUND_STRUCT_ELEMENT(ceil) ROUND_STRUCT_ELEMENT(trunc) ROUND_STRUCT_ELEMENT(cvt) } T; T t; #undef ROUND_STRUCT_ELEMENT MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); // Save FCSR. __ cfc1(a1, FCSR); // Disable FPU exceptions. __ ctc1(zero_reg, FCSR); #define RUN_ROUND_TEST(x) \ __ cfc1(t0, FCSR);\ __ sw(t0, MemOperand(a0, offsetof(T, x##_isNaN2008))); \ __ ldc1(f0, MemOperand(a0, offsetof(T, round_up_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_up_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, round_down_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_down_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, neg_round_up_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, neg_##x##_up_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, neg_round_down_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, neg_##x##_down_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err1_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err1_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err2_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err2_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err3_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err3_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err4_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err4_out))); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_invalid_result))); RUN_ROUND_TEST(round) RUN_ROUND_TEST(floor) RUN_ROUND_TEST(ceil) RUN_ROUND_TEST(trunc) RUN_ROUND_TEST(cvt) // Restore FCSR. __ ctc1(a1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.round_up_in = 123.51; t.round_down_in = 123.49; t.neg_round_up_in = -123.5; t.neg_round_down_in = -123.49; t.err1_in = 123.51; t.err2_in = 1; t.err3_in = static_cast(1) + 0xFFFFFFFF; t.err4_in = NAN; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); #define GET_FPU_ERR(x) (static_cast(x & kFCSRFlagMask)) #define CHECK_NAN2008(x) (x & kFCSRNaN2008FlagMask) #define CHECK_ROUND_RESULT(type) \ CHECK(GET_FPU_ERR(t.type##_err1_out) & kFCSRInexactFlagMask); \ CHECK_EQ(0, GET_FPU_ERR(t.type##_err2_out)); \ CHECK(GET_FPU_ERR(t.type##_err3_out) & kFCSRInvalidOpFlagMask); \ CHECK(GET_FPU_ERR(t.type##_err4_out) & kFCSRInvalidOpFlagMask); \ if (CHECK_NAN2008(t.type##_isNaN2008) && kArchVariant == kMips64r6) { \ CHECK_EQ(static_cast(0), t.type##_invalid_result);\ } else { \ CHECK_EQ(static_cast(kFPUInvalidResult), t.type##_invalid_result);\ } CHECK_ROUND_RESULT(round); CHECK_ROUND_RESULT(floor); CHECK_ROUND_RESULT(ceil); CHECK_ROUND_RESULT(cvt); } TEST(MIPS15) { // Test chaining of label usages within instructions (issue 1644). CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); Assembler assm(isolate, NULL, 0); Label target; __ beq(v0, v1, &target); __ nop(); __ bne(v0, v1, &target); __ nop(); __ bind(&target); __ nop(); } // ----- mips64 tests ----------------------------------------------- TEST(MIPS16) { // Test 64-bit memory loads and stores. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); struct T { int64_t r1; int64_t r2; int64_t r3; int64_t r4; int64_t r5; int64_t r6; int64_t r7; int64_t r8; int64_t r9; int64_t r10; int64_t r11; int64_t r12; uint32_t ui; int32_t si; }; T t; Assembler assm(isolate, NULL, 0); Label L, C; // Basic 32-bit word load/store, with un-signed data. __ lw(a4, MemOperand(a0, offsetof(T, ui))); __ sw(a4, MemOperand(a0, offsetof(T, r1))); // Check that the data got zero-extended into 64-bit a4. __ sd(a4, MemOperand(a0, offsetof(T, r2))); // Basic 32-bit word load/store, with SIGNED data. __ lw(a5, MemOperand(a0, offsetof(T, si))); __ sw(a5, MemOperand(a0, offsetof(T, r3))); // Check that the data got sign-extended into 64-bit a4. __ sd(a5, MemOperand(a0, offsetof(T, r4))); // 32-bit UNSIGNED word load/store, with SIGNED data. __ lwu(a6, MemOperand(a0, offsetof(T, si))); __ sw(a6, MemOperand(a0, offsetof(T, r5))); // Check that the data got zero-extended into 64-bit a4. __ sd(a6, MemOperand(a0, offsetof(T, r6))); // lh with positive data. __ lh(a5, MemOperand(a0, offsetof(T, ui))); __ sw(a5, MemOperand(a0, offsetof(T, r7))); // lh with negative data. __ lh(a6, MemOperand(a0, offsetof(T, si))); __ sw(a6, MemOperand(a0, offsetof(T, r8))); // lhu with negative data. __ lhu(a7, MemOperand(a0, offsetof(T, si))); __ sw(a7, MemOperand(a0, offsetof(T, r9))); // lb with negative data. __ lb(t0, MemOperand(a0, offsetof(T, si))); __ sw(t0, MemOperand(a0, offsetof(T, r10))); // sh writes only 1/2 of word. __ lw(a4, MemOperand(a0, offsetof(T, ui))); __ sh(a4, MemOperand(a0, offsetof(T, r11))); __ lw(a4, MemOperand(a0, offsetof(T, si))); __ sh(a4, MemOperand(a0, offsetof(T, r12))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.ui = 0x44332211; t.si = 0x99aabbcc; t.r1 = 0x5555555555555555; t.r2 = 0x5555555555555555; t.r3 = 0x5555555555555555; t.r4 = 0x5555555555555555; t.r5 = 0x5555555555555555; t.r6 = 0x5555555555555555; t.r7 = 0x5555555555555555; t.r8 = 0x5555555555555555; t.r9 = 0x5555555555555555; t.r10 = 0x5555555555555555; t.r11 = 0x5555555555555555; t.r12 = 0x5555555555555555; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); if (kArchEndian == kLittle) { // Unsigned data, 32 & 64 CHECK_EQ(static_cast(0x5555555544332211L), t.r1); // lw, sw. CHECK_EQ(static_cast(0x0000000044332211L), t.r2); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x5555555599aabbccL), t.r3); // lw, sw. CHECK_EQ(static_cast(0xffffffff99aabbccL), t.r4); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x5555555599aabbccL), t.r5); // lwu, sw. CHECK_EQ(static_cast(0x0000000099aabbccL), t.r6); // sd. // lh with unsigned and signed data. CHECK_EQ(static_cast(0x5555555500002211L), t.r7); // lh, sw. CHECK_EQ(static_cast(0x55555555ffffbbccL), t.r8); // lh, sw. // lhu with signed data. CHECK_EQ(static_cast(0x555555550000bbccL), t.r9); // lhu, sw. // lb with signed data. CHECK_EQ(static_cast(0x55555555ffffffccL), t.r10); // lb, sw. // sh with unsigned and signed data. CHECK_EQ(static_cast(0x5555555555552211L), t.r11); // lw, sh. CHECK_EQ(static_cast(0x555555555555bbccL), t.r12); // lw, sh. } else { // Unsigned data, 32 & 64 CHECK_EQ(static_cast(0x4433221155555555L), t.r1); // lw, sw. CHECK_EQ(static_cast(0x0000000044332211L), t.r2); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x99aabbcc55555555L), t.r3); // lw, sw. CHECK_EQ(static_cast(0xffffffff99aabbccL), t.r4); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x99aabbcc55555555L), t.r5); // lwu, sw. CHECK_EQ(static_cast(0x0000000099aabbccL), t.r6); // sd. // lh with unsigned and signed data. CHECK_EQ(static_cast(0x0000443355555555L), t.r7); // lh, sw. CHECK_EQ(static_cast(0xffff99aa55555555L), t.r8); // lh, sw. // lhu with signed data. CHECK_EQ(static_cast(0x000099aa55555555L), t.r9); // lhu, sw. // lb with signed data. CHECK_EQ(static_cast(0xffffff9955555555L), t.r10); // lb, sw. // sh with unsigned and signed data. CHECK_EQ(static_cast(0x2211555555555555L), t.r11); // lw, sh. CHECK_EQ(static_cast(0xbbcc555555555555L), t.r12); // lw, sh. } } // ----------------------mips64r6 specific tests---------------------- TEST(seleqz_selnez) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { int a; int b; int c; int d; double e; double f; double g; double h; float i; float j; float k; float l; } Test; Test test; // Integer part of test. __ addiu(t1, zero_reg, 1); // t1 = 1 __ seleqz(t3, t1, zero_reg); // t3 = 1 __ sw(t3, MemOperand(a0, offsetof(Test, a))); // a = 1 __ seleqz(t2, t1, t1); // t2 = 0 __ sw(t2, MemOperand(a0, offsetof(Test, b))); // b = 0 __ selnez(t3, t1, zero_reg); // t3 = 1; __ sw(t3, MemOperand(a0, offsetof(Test, c))); // c = 0 __ selnez(t3, t1, t1); // t3 = 1 __ sw(t3, MemOperand(a0, offsetof(Test, d))); // d = 1 // Floating point part of test. __ ldc1(f0, MemOperand(a0, offsetof(Test, e)) ); // src __ ldc1(f2, MemOperand(a0, offsetof(Test, f)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, i)) ); // src __ lwc1(f10, MemOperand(a0, offsetof(Test, j)) ); // test __ seleqz_d(f4, f0, f2); __ selnez_d(f6, f0, f2); __ seleqz_s(f12, f8, f10); __ selnez_s(f14, f8, f10); __ sdc1(f4, MemOperand(a0, offsetof(Test, g)) ); // src __ sdc1(f6, MemOperand(a0, offsetof(Test, h)) ); // src __ swc1(f12, MemOperand(a0, offsetof(Test, k)) ); // src __ swc1(f14, MemOperand(a0, offsetof(Test, l)) ); // src __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.a, 1); CHECK_EQ(test.b, 0); CHECK_EQ(test.c, 0); CHECK_EQ(test.d, 1); const int test_size = 3; const int input_size = 5; double inputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double outputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float inputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float outputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.e = inputs_D[i]; test.f = tests_D[j]; test.i = inputs_S[i]; test.j = tests_S[j]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, outputs_D[i]); CHECK_EQ(test.h, 0); CHECK_EQ(test.k, outputs_S[i]); CHECK_EQ(test.l, 0); test.f = tests_D[j+1]; test.j = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, 0); CHECK_EQ(test.h, outputs_D[i]); CHECK_EQ(test.k, 0); CHECK_EQ(test.l, outputs_S[i]); } } } } TEST(min_max) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); struct TestFloat { double a; double b; double c; double d; float e; float f; float g; float h; }; TestFloat test; const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); const int kTableLength = 13; double inputsa[kTableLength] = {2.0, 3.0, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = {3.0, 2.0, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double outputsdmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double outputsdmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputse[kTableLength] = {2.0, 3.0, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsf[kTableLength] = {3.0, 2.0, 3.0, fnan, 0.0, -0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float outputsfmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float outputsfmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a))); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, b))); __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, e))); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, f))); __ min_d(f10, f4, f8); __ max_d(f12, f4, f8); __ min_s(f14, f2, f6); __ max_s(f16, f2, f6); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, c))); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, d))); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, g))); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, h))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 4; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.e = inputse[i]; test.f = inputsf[i]; CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0); CHECK_EQ(0, memcmp(&test.c, &outputsdmin[i], sizeof(test.c))); CHECK_EQ(0, memcmp(&test.d, &outputsdmax[i], sizeof(test.d))); CHECK_EQ(0, memcmp(&test.g, &outputsfmin[i], sizeof(test.g))); CHECK_EQ(0, memcmp(&test.h, &outputsfmax[i], sizeof(test.h))); } } } TEST(rint_d) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; int fcsr; }TestFloat; TestFloat test; double inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E+308, 6.27463370218383111104242366943E-307, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ ctc1(t0, FCSR); __ rint_d(f8, f4); __ sdc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(sel) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { double dd; double ds; double dt; float fd; float fs; float ft; } Test; Test test; __ ldc1(f0, MemOperand(a0, offsetof(Test, dd)) ); // test __ ldc1(f2, MemOperand(a0, offsetof(Test, ds)) ); // src1 __ ldc1(f4, MemOperand(a0, offsetof(Test, dt)) ); // src2 __ lwc1(f6, MemOperand(a0, offsetof(Test, fd)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, fs)) ); // src1 __ lwc1(f10, MemOperand(a0, offsetof(Test, ft)) ); // src2 __ sel_d(f0, f2, f4); __ sel_s(f6, f8, f10); __ sdc1(f0, MemOperand(a0, offsetof(Test, dd)) ); __ swc1(f6, MemOperand(a0, offsetof(Test, fd)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); const int test_size = 3; const int input_size = 5; double inputs_dt[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double inputs_ds[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; float inputs_ft[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float inputs_fs[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.dt = inputs_dt[i]; test.dd = tests_D[j]; test.ds = inputs_ds[i]; test.ft = inputs_ft[i]; test.fd = tests_S[j]; test.fs = inputs_fs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_ds[i]); CHECK_EQ(test.fd, inputs_fs[i]); test.dd = tests_D[j+1]; test.fd = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_dt[i]); CHECK_EQ(test.fd, inputs_ft[i]); } } } } TEST(rint_s) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; int fcsr; }TestFloat; TestFloat test; float inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E+38, 6.27463370218383111104242366943E-37, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; float* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ rint_s(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(mina_maxa) { if (kArchVariant == kMips64r6) { const int kTableLength = 23; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); struct TestFloat { double a; double b; double resd; double resd1; float c; float d; float resf; float resf1; }; TestFloat test; double inputsa[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = { 4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double resd[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double resd1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputsc[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsd[kTableLength] = {4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, fnan, -0.0, 0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float resf[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float resf1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ lwc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ lwc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ mina_d(f6, f2, f4); __ mina_s(f12, f8, f10); __ maxa_d(f14, f2, f4); __ maxa_s(f16, f8, f10); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, resf)) ); __ sdc1(f6, MemOperand(a0, offsetof(TestFloat, resd)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resf1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resd1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.c = inputsc[i]; test.d = inputsd[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if (i < kTableLength - 1) { CHECK_EQ(test.resd, resd[i]); CHECK_EQ(test.resf, resf[i]); CHECK_EQ(test.resd1, resd1[i]); CHECK_EQ(test.resf1, resf1[i]); } else { CHECK(std::isnan(test.resd)); CHECK(std::isnan(test.resf)); CHECK(std::isnan(test.resd1)); CHECK(std::isnan(test.resf1)); } } } } // ----------------------mips64r2 specific tests---------------------- TEST(trunc_l) { if (kArchVariant == kMips64r2) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; // a trunc result int64_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_l_d(f8, f4); __ trunc_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } } TEST(movz_movn) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { int64_t rt; double a; double b; double bold; double b1; double bold1; float c; float d; float dold; float d1; float dold1; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ld(t0, MemOperand(a0, offsetof(TestFloat, rt))); __ Move(f12, 0.0); __ Move(f10, 0.0); __ Move(f16, 0.0); __ Move(f14, 0.0); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, bold)) ); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, dold)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, bold1)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, dold1)) ); __ movz_s(f10, f6, t0); __ movz_d(f12, f2, t0); __ movn_s(f14, f6, t0); __ movn_d(f16, f2, t0); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, b)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, d1)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, b1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; test.rt = 1; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, test.bold); CHECK_EQ(test.d, test.dold); CHECK_EQ(test.b1, outputs_D[i]); CHECK_EQ(test.d1, outputs_S[i]); test.rt = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); CHECK_EQ(test.b1, test.bold1); CHECK_EQ(test.d1, test.dold1); } } } TEST(movt_movd) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); typedef struct test_float { double srcd; double dstd; double dstdold; double dstd1; double dstdold1; float srcf; float dstf; float dstfold; float dstf1; float dstfold1; int32_t cc; int32_t fcsr; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; double inputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; int condition_flags[8] = {0, 1, 2, 3, 4, 5, 6, 7}; for (int i = 0; i < kTableLength; i++) { test.srcd = inputs_D[i]; test.srcf = inputs_S[i]; for (int j = 0; j< 8; j++) { test.cc = condition_flags[j]; if (test.cc == 0) { test.fcsr = 1 << 23; } else { test.fcsr = 1 << (24+condition_flags[j]); } HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, srcd)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, srcf)) ); __ lw(t1, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t0, FCSR); __ ctc1(t1, FCSR); __ li(t2, 0x0); __ mtc1(t2, f12); __ mtc1(t2, f10); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold)) ); __ movt_s(f12, f4, test.cc); __ movt_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold1)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold1)) ); __ movf_s(f12, f4, test.cc); __ movf_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf1)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd1)) ); __ ctc1(t0, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, outputs_S[i]); CHECK_EQ(test.dstd, outputs_D[i]); CHECK_EQ(test.dstf1, test.dstfold1); CHECK_EQ(test.dstd1, test.dstdold1); test.fcsr = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, test.dstfold); CHECK_EQ(test.dstd, test.dstdold); CHECK_EQ(test.dstf1, outputs_S[i]); CHECK_EQ(test.dstd1, outputs_D[i]); } } } } // ----------------------tests for all archs-------------------------- TEST(cvt_w_d) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; int32_t b; int fcsr; }Test; const int kTableLength = 24; double inputs[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, 2147483653.0 }; double outputs_RN[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RZ[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RP[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RM[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lw(t0, MemOperand(a0, offsetof(Test, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ cvt_w_d(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(Test, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } TEST(trunc_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_w_d(f8, f4); __ trunc_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_w_d(f8, f4); __ round_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_l_d(f8, f4); __ round_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(sub) { const int kTableLength = 12; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; double inputft_D[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; double outputs_D[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; float inputfs_S[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; float inputft_S[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; float outputs_S[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sub_s(f6, f2, f4); __ sub_d(f12, f8, f10); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(sqrt_rsqrt_recip) { const int kTableLength = 4; const double deltaDouble = 2E-15; const float deltaFloat = 2E-7; const float sqrt2_s = sqrt(2); const double sqrt2_d = sqrt(2); CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; float resultS1; float resultS2; double c; double resultD; double resultD1; double resultD2; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 0.0L, 4.0L, 2.0L, 4e-28L }; double outputs_D[kTableLength] = { 0.0L, 2.0L, sqrt2_d, 2e-14L }; float inputs_S[kTableLength] = { 0.0, 4.0, 2.0, 4e-28 }; float outputs_S[kTableLength] = { 0.0, 2.0, sqrt2_s, 2e-14 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ sqrt_s(f6, f2); __ sqrt_d(f12, f8); __ rsqrt_d(f14, f8); __ rsqrt_s(f16, f2); __ recip_d(f18, f8); __ recip_s(f4, f2); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resultS1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resultD1)) ); __ swc1(f4, MemOperand(a0, offsetof(TestFloat, resultS2)) ); __ sdc1(f18, MemOperand(a0, offsetof(TestFloat, resultD2)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { float f1; double d1; test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); if (i != 0) { f1 = test.resultS1 - 1.0F/outputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD1 - 1.0L/outputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); f1 = test.resultS2 - 1.0F/inputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD2 - 1.0L/inputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); } else { CHECK_EQ(test.resultS1, 1.0F/outputs_S[i]); CHECK_EQ(test.resultD1, 1.0L/outputs_D[i]); CHECK_EQ(test.resultS2, 1.0F/inputs_S[i]); CHECK_EQ(test.resultD2, 1.0L/inputs_D[i]); } } } TEST(neg) { const int kTableLength = 2; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; double c; double resultD; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 4.0, -2.0 }; double outputs_D[kTableLength] = { -4.0, 2.0 }; float inputs_S[kTableLength] = { 4.0, -2.0 }; float outputs_S[kTableLength] = { -4.0, 2.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ neg_s(f6, f2); __ neg_d(f12, f8); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.a = 2.147483647e9; // 0x7fffffff -> 0x41DFFFFFFFC00000 as double. t.b_long_hi = 0x000000ff; // 0xFF00FF00FF -> 0x426FE01FE01FE000 as double. t.b_long_lo = 0x00ff00ff; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(static_cast(0x41DFFFFF), t.dbl_exp); CHECK_EQ(static_cast(0xFFC00000), t.dbl_mant); CHECK_EQ(0, t.long_hi); CHECK_EQ(static_cast(0x7fffffff), t.long_lo); CHECK_EQ(2.147483647e9, t.a_converted); // 0xFF00FF00FF -> 1.095233372415e12. CHECK_EQ(1.095233372415e12, t.b); CHECK_EQ(static_cast(0xFF00FF00FF), t.b_long_as_int64); } } TEST(MIPS11) { // Do not run test on MIPS64r6, as these instructions are removed. if (kArchVariant != kMips64r6) { // Test LWL, LWR, SWL and SWR instructions. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { int32_t reg_init; int32_t mem_init; int32_t lwl_0; int32_t lwl_1; int32_t lwl_2; int32_t lwl_3; int32_t lwr_0; int32_t lwr_1; int32_t lwr_2; int32_t lwr_3; int32_t swl_0; int32_t swl_1; int32_t swl_2; int32_t swl_3; int32_t swr_0; int32_t swr_1; int32_t swr_2; int32_t swr_3; } T; T t; Assembler assm(isolate, NULL, 0); // Test all combinations of LWL and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, lwl_0))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a5, MemOperand(a0, offsetof(T, mem_init) + 1)); __ sw(a5, MemOperand(a0, offsetof(T, lwl_1))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a6, MemOperand(a0, offsetof(T, mem_init) + 2)); __ sw(a6, MemOperand(a0, offsetof(T, lwl_2))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a7, MemOperand(a0, offsetof(T, mem_init) + 3)); __ sw(a7, MemOperand(a0, offsetof(T, lwl_3))); // Test all combinations of LWR and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, lwr_0))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a5, MemOperand(a0, offsetof(T, mem_init) + 1)); __ sw(a5, MemOperand(a0, offsetof(T, lwr_1))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a6, MemOperand(a0, offsetof(T, mem_init) + 2)); __ sw(a6, MemOperand(a0, offsetof(T, lwr_2)) ); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a7, MemOperand(a0, offsetof(T, mem_init) + 3)); __ sw(a7, MemOperand(a0, offsetof(T, lwr_3)) ); // Test all combinations of SWL and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, swl_0))); __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ swl(a4, MemOperand(a0, offsetof(T, swl_0))); __ lw(a5, MemOperand(a0, offsetof(T, mem_init))); __ sw(a5, MemOperand(a0, offsetof(T, swl_1))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ swl(a5, MemOperand(a0, offsetof(T, swl_1) + 1)); __ lw(a6, MemOperand(a0, offsetof(T, mem_init))); __ sw(a6, MemOperand(a0, offsetof(T, swl_2))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ swl(a6, MemOperand(a0, offsetof(T, swl_2) + 2)); __ lw(a7, MemOperand(a0, offsetof(T, mem_init))); __ sw(a7, MemOperand(a0, offsetof(T, swl_3))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ swl(a7, MemOperand(a0, offsetof(T, swl_3) + 3)); // Test all combinations of SWR and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, swr_0))); __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ swr(a4, MemOperand(a0, offsetof(T, swr_0))); __ lw(a5, MemOperand(a0, offsetof(T, mem_init))); __ sw(a5, MemOperand(a0, offsetof(T, swr_1))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ swr(a5, MemOperand(a0, offsetof(T, swr_1) + 1)); __ lw(a6, MemOperand(a0, offsetof(T, mem_init))); __ sw(a6, MemOperand(a0, offsetof(T, swr_2))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ swr(a6, MemOperand(a0, offsetof(T, swr_2) + 2)); __ lw(a7, MemOperand(a0, offsetof(T, mem_init))); __ sw(a7, MemOperand(a0, offsetof(T, swr_3))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ swr(a7, MemOperand(a0, offsetof(T, swr_3) + 3)); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.reg_init = 0xaabbccdd; t.mem_init = 0x11223344; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); if (kArchEndian == kLittle) { CHECK_EQ(static_cast(0x44bbccdd), t.lwl_0); CHECK_EQ(static_cast(0x3344ccdd), t.lwl_1); CHECK_EQ(static_cast(0x223344dd), t.lwl_2); CHECK_EQ(static_cast(0x11223344), t.lwl_3); CHECK_EQ(static_cast(0x11223344), t.lwr_0); CHECK_EQ(static_cast(0xaa112233), t.lwr_1); CHECK_EQ(static_cast(0xaabb1122), t.lwr_2); CHECK_EQ(static_cast(0xaabbcc11), t.lwr_3); CHECK_EQ(static_cast(0x112233aa), t.swl_0); CHECK_EQ(static_cast(0x1122aabb), t.swl_1); CHECK_EQ(static_cast(0x11aabbcc), t.swl_2); CHECK_EQ(static_cast(0xaabbccdd), t.swl_3); CHECK_EQ(static_cast(0xaabbccdd), t.swr_0); CHECK_EQ(static_cast(0xbbccdd44), t.swr_1); CHECK_EQ(static_cast(0xccdd3344), t.swr_2); CHECK_EQ(static_cast(0xdd223344), t.swr_3); } else { CHECK_EQ(static_cast(0x11223344), t.lwl_0); CHECK_EQ(static_cast(0x223344dd), t.lwl_1); CHECK_EQ(static_cast(0x3344ccdd), t.lwl_2); CHECK_EQ(static_cast(0x44bbccdd), t.lwl_3); CHECK_EQ(static_cast(0xaabbcc11), t.lwr_0); CHECK_EQ(static_cast(0xaabb1122), t.lwr_1); CHECK_EQ(static_cast(0xaa112233), t.lwr_2); CHECK_EQ(static_cast(0x11223344), t.lwr_3); CHECK_EQ(static_cast(0xaabbccdd), t.swl_0); CHECK_EQ(static_cast(0x11aabbcc), t.swl_1); CHECK_EQ(static_cast(0x1122aabb), t.swl_2); CHECK_EQ(static_cast(0x112233aa), t.swl_3); CHECK_EQ(static_cast(0xdd223344), t.swr_0); CHECK_EQ(static_cast(0xccdd3344), t.swr_1); CHECK_EQ(static_cast(0xbbccdd44), t.swr_2); CHECK_EQ(static_cast(0xaabbccdd), t.swr_3); } } } TEST(MIPS12) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { int32_t x; int32_t y; int32_t y1; int32_t y2; int32_t y3; int32_t y4; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ mov(t2, fp); // Save frame pointer. __ mov(fp, a0); // Access struct T by fp. __ lw(a4, MemOperand(a0, offsetof(T, y))); __ lw(a7, MemOperand(a0, offsetof(T, y4))); __ addu(a5, a4, a7); __ subu(t0, a4, a7); __ nop(); __ push(a4); // These instructions disappear after opt. __ Pop(); __ addu(a4, a4, a4); __ nop(); __ Pop(); // These instructions disappear after opt. __ push(a7); __ nop(); __ push(a7); // These instructions disappear after opt. __ pop(a7); __ nop(); __ push(a7); __ pop(t0); __ nop(); __ sw(a4, MemOperand(fp, offsetof(T, y))); __ lw(a4, MemOperand(fp, offsetof(T, y))); __ nop(); __ sw(a4, MemOperand(fp, offsetof(T, y))); __ lw(a5, MemOperand(fp, offsetof(T, y))); __ nop(); __ push(a5); __ lw(a5, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a6); __ nop(); __ push(a6); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a7); __ nop(); __ mov(fp, t2); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.x = 1; t.y = 2; t.y1 = 3; t.y2 = 4; t.y3 = 0XBABA; t.y4 = 0xDEDA; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(3, t.y1); } TEST(MIPS13) { // Test Cvt_d_uw and Trunc_uw_d macros. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double cvt_big_out; double cvt_small_out; uint32_t trunc_big_out; uint32_t trunc_small_out; uint32_t cvt_big_in; uint32_t cvt_small_in; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ sw(a4, MemOperand(a0, offsetof(T, cvt_small_in))); __ Cvt_d_uw(f10, a4); __ sdc1(f10, MemOperand(a0, offsetof(T, cvt_small_out))); __ Trunc_uw_d(f10, f10, f4); __ swc1(f10, MemOperand(a0, offsetof(T, trunc_small_out))); __ sw(a4, MemOperand(a0, offsetof(T, cvt_big_in))); __ Cvt_d_uw(f8, a4); __ sdc1(f8, MemOperand(a0, offsetof(T, cvt_big_out))); __ Trunc_uw_d(f8, f8, f4); __ swc1(f8, MemOperand(a0, offsetof(T, trunc_big_out))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.cvt_big_in = 0xFFFFFFFF; t.cvt_small_in = 333; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(t.cvt_big_out, static_cast(t.cvt_big_in)); CHECK_EQ(t.cvt_small_out, static_cast(t.cvt_small_in)); CHECK_EQ(static_cast(t.trunc_big_out), static_cast(t.cvt_big_in)); CHECK_EQ(static_cast(t.trunc_small_out), static_cast(t.cvt_small_in)); } TEST(MIPS14) { // Test round, floor, ceil, trunc, cvt. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); #define ROUND_STRUCT_ELEMENT(x) \ uint32_t x##_isNaN2008; \ int32_t x##_up_out; \ int32_t x##_down_out; \ int32_t neg_##x##_up_out; \ int32_t neg_##x##_down_out; \ uint32_t x##_err1_out; \ uint32_t x##_err2_out; \ uint32_t x##_err3_out; \ uint32_t x##_err4_out; \ int32_t x##_invalid_result; typedef struct { double round_up_in; double round_down_in; double neg_round_up_in; double neg_round_down_in; double err1_in; double err2_in; double err3_in; double err4_in; ROUND_STRUCT_ELEMENT(round) ROUND_STRUCT_ELEMENT(floor) ROUND_STRUCT_ELEMENT(ceil) ROUND_STRUCT_ELEMENT(trunc) ROUND_STRUCT_ELEMENT(cvt) } T; T t; #undef ROUND_STRUCT_ELEMENT MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); // Save FCSR. __ cfc1(a1, FCSR); // Disable FPU exceptions. __ ctc1(zero_reg, FCSR); #define RUN_ROUND_TEST(x) \ __ cfc1(t0, FCSR);\ __ sw(t0, MemOperand(a0, offsetof(T, x##_isNaN2008))); \ __ ldc1(f0, MemOperand(a0, offsetof(T, round_up_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_up_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, round_down_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_down_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, neg_round_up_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, neg_##x##_up_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, neg_round_down_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, neg_##x##_down_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err1_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err1_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err2_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err2_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err3_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err3_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err4_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err4_out))); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_invalid_result))); RUN_ROUND_TEST(round) RUN_ROUND_TEST(floor) RUN_ROUND_TEST(ceil) RUN_ROUND_TEST(trunc) RUN_ROUND_TEST(cvt) // Restore FCSR. __ ctc1(a1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.round_up_in = 123.51; t.round_down_in = 123.49; t.neg_round_up_in = -123.5; t.neg_round_down_in = -123.49; t.err1_in = 123.51; t.err2_in = 1; t.err3_in = static_cast(1) + 0xFFFFFFFF; t.err4_in = NAN; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); #define GET_FPU_ERR(x) (static_cast(x & kFCSRFlagMask)) #define CHECK_NAN2008(x) (x & kFCSRNaN2008FlagMask) #define CHECK_ROUND_RESULT(type) \ CHECK(GET_FPU_ERR(t.type##_err1_out) & kFCSRInexactFlagMask); \ CHECK_EQ(0, GET_FPU_ERR(t.type##_err2_out)); \ CHECK(GET_FPU_ERR(t.type##_err3_out) & kFCSRInvalidOpFlagMask); \ CHECK(GET_FPU_ERR(t.type##_err4_out) & kFCSRInvalidOpFlagMask); \ if (CHECK_NAN2008(t.type##_isNaN2008) && kArchVariant == kMips64r6) { \ CHECK_EQ(static_cast(0), t.type##_invalid_result);\ } else { \ CHECK_EQ(static_cast(kFPUInvalidResult), t.type##_invalid_result);\ } CHECK_ROUND_RESULT(round); CHECK_ROUND_RESULT(floor); CHECK_ROUND_RESULT(ceil); CHECK_ROUND_RESULT(cvt); } TEST(MIPS15) { // Test chaining of label usages within instructions (issue 1644). CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); Assembler assm(isolate, NULL, 0); Label target; __ beq(v0, v1, &target); __ nop(); __ bne(v0, v1, &target); __ nop(); __ bind(&target); __ nop(); } // ----- mips64 tests ----------------------------------------------- TEST(MIPS16) { // Test 64-bit memory loads and stores. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); struct T { int64_t r1; int64_t r2; int64_t r3; int64_t r4; int64_t r5; int64_t r6; int64_t r7; int64_t r8; int64_t r9; int64_t r10; int64_t r11; int64_t r12; uint32_t ui; int32_t si; }; T t; Assembler assm(isolate, NULL, 0); Label L, C; // Basic 32-bit word load/store, with un-signed data. __ lw(a4, MemOperand(a0, offsetof(T, ui))); __ sw(a4, MemOperand(a0, offsetof(T, r1))); // Check that the data got zero-extended into 64-bit a4. __ sd(a4, MemOperand(a0, offsetof(T, r2))); // Basic 32-bit word load/store, with SIGNED data. __ lw(a5, MemOperand(a0, offsetof(T, si))); __ sw(a5, MemOperand(a0, offsetof(T, r3))); // Check that the data got sign-extended into 64-bit a4. __ sd(a5, MemOperand(a0, offsetof(T, r4))); // 32-bit UNSIGNED word load/store, with SIGNED data. __ lwu(a6, MemOperand(a0, offsetof(T, si))); __ sw(a6, MemOperand(a0, offsetof(T, r5))); // Check that the data got zero-extended into 64-bit a4. __ sd(a6, MemOperand(a0, offsetof(T, r6))); // lh with positive data. __ lh(a5, MemOperand(a0, offsetof(T, ui))); __ sw(a5, MemOperand(a0, offsetof(T, r7))); // lh with negative data. __ lh(a6, MemOperand(a0, offsetof(T, si))); __ sw(a6, MemOperand(a0, offsetof(T, r8))); // lhu with negative data. __ lhu(a7, MemOperand(a0, offsetof(T, si))); __ sw(a7, MemOperand(a0, offsetof(T, r9))); // lb with negative data. __ lb(t0, MemOperand(a0, offsetof(T, si))); __ sw(t0, MemOperand(a0, offsetof(T, r10))); // sh writes only 1/2 of word. __ lw(a4, MemOperand(a0, offsetof(T, ui))); __ sh(a4, MemOperand(a0, offsetof(T, r11))); __ lw(a4, MemOperand(a0, offsetof(T, si))); __ sh(a4, MemOperand(a0, offsetof(T, r12))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.ui = 0x44332211; t.si = 0x99aabbcc; t.r1 = 0x5555555555555555; t.r2 = 0x5555555555555555; t.r3 = 0x5555555555555555; t.r4 = 0x5555555555555555; t.r5 = 0x5555555555555555; t.r6 = 0x5555555555555555; t.r7 = 0x5555555555555555; t.r8 = 0x5555555555555555; t.r9 = 0x5555555555555555; t.r10 = 0x5555555555555555; t.r11 = 0x5555555555555555; t.r12 = 0x5555555555555555; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); if (kArchEndian == kLittle) { // Unsigned data, 32 & 64 CHECK_EQ(static_cast(0x5555555544332211L), t.r1); // lw, sw. CHECK_EQ(static_cast(0x0000000044332211L), t.r2); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x5555555599aabbccL), t.r3); // lw, sw. CHECK_EQ(static_cast(0xffffffff99aabbccL), t.r4); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x5555555599aabbccL), t.r5); // lwu, sw. CHECK_EQ(static_cast(0x0000000099aabbccL), t.r6); // sd. // lh with unsigned and signed data. CHECK_EQ(static_cast(0x5555555500002211L), t.r7); // lh, sw. CHECK_EQ(static_cast(0x55555555ffffbbccL), t.r8); // lh, sw. // lhu with signed data. CHECK_EQ(static_cast(0x555555550000bbccL), t.r9); // lhu, sw. // lb with signed data. CHECK_EQ(static_cast(0x55555555ffffffccL), t.r10); // lb, sw. // sh with unsigned and signed data. CHECK_EQ(static_cast(0x5555555555552211L), t.r11); // lw, sh. CHECK_EQ(static_cast(0x555555555555bbccL), t.r12); // lw, sh. } else { // Unsigned data, 32 & 64 CHECK_EQ(static_cast(0x4433221155555555L), t.r1); // lw, sw. CHECK_EQ(static_cast(0x0000000044332211L), t.r2); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x99aabbcc55555555L), t.r3); // lw, sw. CHECK_EQ(static_cast(0xffffffff99aabbccL), t.r4); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x99aabbcc55555555L), t.r5); // lwu, sw. CHECK_EQ(static_cast(0x0000000099aabbccL), t.r6); // sd. // lh with unsigned and signed data. CHECK_EQ(static_cast(0x0000443355555555L), t.r7); // lh, sw. CHECK_EQ(static_cast(0xffff99aa55555555L), t.r8); // lh, sw. // lhu with signed data. CHECK_EQ(static_cast(0x000099aa55555555L), t.r9); // lhu, sw. // lb with signed data. CHECK_EQ(static_cast(0xffffff9955555555L), t.r10); // lb, sw. // sh with unsigned and signed data. CHECK_EQ(static_cast(0x2211555555555555L), t.r11); // lw, sh. CHECK_EQ(static_cast(0xbbcc555555555555L), t.r12); // lw, sh. } } // ----------------------mips64r6 specific tests---------------------- TEST(seleqz_selnez) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { int a; int b; int c; int d; double e; double f; double g; double h; float i; float j; float k; float l; } Test; Test test; // Integer part of test. __ addiu(t1, zero_reg, 1); // t1 = 1 __ seleqz(t3, t1, zero_reg); // t3 = 1 __ sw(t3, MemOperand(a0, offsetof(Test, a))); // a = 1 __ seleqz(t2, t1, t1); // t2 = 0 __ sw(t2, MemOperand(a0, offsetof(Test, b))); // b = 0 __ selnez(t3, t1, zero_reg); // t3 = 1; __ sw(t3, MemOperand(a0, offsetof(Test, c))); // c = 0 __ selnez(t3, t1, t1); // t3 = 1 __ sw(t3, MemOperand(a0, offsetof(Test, d))); // d = 1 // Floating point part of test. __ ldc1(f0, MemOperand(a0, offsetof(Test, e)) ); // src __ ldc1(f2, MemOperand(a0, offsetof(Test, f)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, i)) ); // src __ lwc1(f10, MemOperand(a0, offsetof(Test, j)) ); // test __ seleqz_d(f4, f0, f2); __ selnez_d(f6, f0, f2); __ seleqz_s(f12, f8, f10); __ selnez_s(f14, f8, f10); __ sdc1(f4, MemOperand(a0, offsetof(Test, g)) ); // src __ sdc1(f6, MemOperand(a0, offsetof(Test, h)) ); // src __ swc1(f12, MemOperand(a0, offsetof(Test, k)) ); // src __ swc1(f14, MemOperand(a0, offsetof(Test, l)) ); // src __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.a, 1); CHECK_EQ(test.b, 0); CHECK_EQ(test.c, 0); CHECK_EQ(test.d, 1); const int test_size = 3; const int input_size = 5; double inputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double outputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float inputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float outputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.e = inputs_D[i]; test.f = tests_D[j]; test.i = inputs_S[i]; test.j = tests_S[j]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, outputs_D[i]); CHECK_EQ(test.h, 0); CHECK_EQ(test.k, outputs_S[i]); CHECK_EQ(test.l, 0); test.f = tests_D[j+1]; test.j = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, 0); CHECK_EQ(test.h, outputs_D[i]); CHECK_EQ(test.k, 0); CHECK_EQ(test.l, outputs_S[i]); } } } } TEST(min_max) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); struct TestFloat { double a; double b; double c; double d; float e; float f; float g; float h; }; TestFloat test; const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); const int kTableLength = 13; double inputsa[kTableLength] = {2.0, 3.0, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = {3.0, 2.0, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double outputsdmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double outputsdmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputse[kTableLength] = {2.0, 3.0, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsf[kTableLength] = {3.0, 2.0, 3.0, fnan, 0.0, -0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float outputsfmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float outputsfmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a))); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, b))); __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, e))); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, f))); __ min_d(f10, f4, f8); __ max_d(f12, f4, f8); __ min_s(f14, f2, f6); __ max_s(f16, f2, f6); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, c))); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, d))); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, g))); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, h))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 4; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.e = inputse[i]; test.f = inputsf[i]; CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0); CHECK_EQ(0, memcmp(&test.c, &outputsdmin[i], sizeof(test.c))); CHECK_EQ(0, memcmp(&test.d, &outputsdmax[i], sizeof(test.d))); CHECK_EQ(0, memcmp(&test.g, &outputsfmin[i], sizeof(test.g))); CHECK_EQ(0, memcmp(&test.h, &outputsfmax[i], sizeof(test.h))); } } } TEST(rint_d) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; int fcsr; }TestFloat; TestFloat test; double inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E+308, 6.27463370218383111104242366943E-307, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ ctc1(t0, FCSR); __ rint_d(f8, f4); __ sdc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(sel) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { double dd; double ds; double dt; float fd; float fs; float ft; } Test; Test test; __ ldc1(f0, MemOperand(a0, offsetof(Test, dd)) ); // test __ ldc1(f2, MemOperand(a0, offsetof(Test, ds)) ); // src1 __ ldc1(f4, MemOperand(a0, offsetof(Test, dt)) ); // src2 __ lwc1(f6, MemOperand(a0, offsetof(Test, fd)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, fs)) ); // src1 __ lwc1(f10, MemOperand(a0, offsetof(Test, ft)) ); // src2 __ sel_d(f0, f2, f4); __ sel_s(f6, f8, f10); __ sdc1(f0, MemOperand(a0, offsetof(Test, dd)) ); __ swc1(f6, MemOperand(a0, offsetof(Test, fd)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); const int test_size = 3; const int input_size = 5; double inputs_dt[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double inputs_ds[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; float inputs_ft[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float inputs_fs[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.dt = inputs_dt[i]; test.dd = tests_D[j]; test.ds = inputs_ds[i]; test.ft = inputs_ft[i]; test.fd = tests_S[j]; test.fs = inputs_fs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_ds[i]); CHECK_EQ(test.fd, inputs_fs[i]); test.dd = tests_D[j+1]; test.fd = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_dt[i]); CHECK_EQ(test.fd, inputs_ft[i]); } } } } TEST(rint_s) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; int fcsr; }TestFloat; TestFloat test; float inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E+38, 6.27463370218383111104242366943E-37, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; float* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ rint_s(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(mina_maxa) { if (kArchVariant == kMips64r6) { const int kTableLength = 23; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); struct TestFloat { double a; double b; double resd; double resd1; float c; float d; float resf; float resf1; }; TestFloat test; double inputsa[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = { 4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double resd[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double resd1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputsc[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsd[kTableLength] = {4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, fnan, -0.0, 0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float resf[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float resf1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ lwc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ lwc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ mina_d(f6, f2, f4); __ mina_s(f12, f8, f10); __ maxa_d(f14, f2, f4); __ maxa_s(f16, f8, f10); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, resf)) ); __ sdc1(f6, MemOperand(a0, offsetof(TestFloat, resd)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resf1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resd1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.c = inputsc[i]; test.d = inputsd[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if (i < kTableLength - 1) { CHECK_EQ(test.resd, resd[i]); CHECK_EQ(test.resf, resf[i]); CHECK_EQ(test.resd1, resd1[i]); CHECK_EQ(test.resf1, resf1[i]); } else { CHECK(std::isnan(test.resd)); CHECK(std::isnan(test.resf)); CHECK(std::isnan(test.resd1)); CHECK(std::isnan(test.resf1)); } } } } // ----------------------mips64r2 specific tests---------------------- TEST(trunc_l) { if (kArchVariant == kMips64r2) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; // a trunc result int64_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_l_d(f8, f4); __ trunc_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } } TEST(movz_movn) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { int64_t rt; double a; double b; double bold; double b1; double bold1; float c; float d; float dold; float d1; float dold1; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ld(t0, MemOperand(a0, offsetof(TestFloat, rt))); __ Move(f12, 0.0); __ Move(f10, 0.0); __ Move(f16, 0.0); __ Move(f14, 0.0); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, bold)) ); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, dold)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, bold1)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, dold1)) ); __ movz_s(f10, f6, t0); __ movz_d(f12, f2, t0); __ movn_s(f14, f6, t0); __ movn_d(f16, f2, t0); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, b)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, d1)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, b1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; test.rt = 1; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, test.bold); CHECK_EQ(test.d, test.dold); CHECK_EQ(test.b1, outputs_D[i]); CHECK_EQ(test.d1, outputs_S[i]); test.rt = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); CHECK_EQ(test.b1, test.bold1); CHECK_EQ(test.d1, test.dold1); } } } TEST(movt_movd) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); typedef struct test_float { double srcd; double dstd; double dstdold; double dstd1; double dstdold1; float srcf; float dstf; float dstfold; float dstf1; float dstfold1; int32_t cc; int32_t fcsr; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; double inputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; int condition_flags[8] = {0, 1, 2, 3, 4, 5, 6, 7}; for (int i = 0; i < kTableLength; i++) { test.srcd = inputs_D[i]; test.srcf = inputs_S[i]; for (int j = 0; j< 8; j++) { test.cc = condition_flags[j]; if (test.cc == 0) { test.fcsr = 1 << 23; } else { test.fcsr = 1 << (24+condition_flags[j]); } HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, srcd)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, srcf)) ); __ lw(t1, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t0, FCSR); __ ctc1(t1, FCSR); __ li(t2, 0x0); __ mtc1(t2, f12); __ mtc1(t2, f10); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold)) ); __ movt_s(f12, f4, test.cc); __ movt_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold1)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold1)) ); __ movf_s(f12, f4, test.cc); __ movf_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf1)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd1)) ); __ ctc1(t0, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, outputs_S[i]); CHECK_EQ(test.dstd, outputs_D[i]); CHECK_EQ(test.dstf1, test.dstfold1); CHECK_EQ(test.dstd1, test.dstdold1); test.fcsr = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, test.dstfold); CHECK_EQ(test.dstd, test.dstdold); CHECK_EQ(test.dstf1, outputs_S[i]); CHECK_EQ(test.dstd1, outputs_D[i]); } } } } // ----------------------tests for all archs-------------------------- TEST(cvt_w_d) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; int32_t b; int fcsr; }Test; const int kTableLength = 24; double inputs[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, 2147483653.0 }; double outputs_RN[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RZ[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RP[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RM[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lw(t0, MemOperand(a0, offsetof(Test, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ cvt_w_d(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(Test, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } TEST(trunc_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_w_d(f8, f4); __ trunc_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_w_d(f8, f4); __ round_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_l_d(f8, f4); __ round_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(sub) { const int kTableLength = 12; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; double inputft_D[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; double outputs_D[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; float inputfs_S[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; float inputft_S[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; float outputs_S[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sub_s(f6, f2, f4); __ sub_d(f12, f8, f10); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(sqrt_rsqrt_recip) { const int kTableLength = 4; const double deltaDouble = 2E-15; const float deltaFloat = 2E-7; const float sqrt2_s = sqrt(2); const double sqrt2_d = sqrt(2); CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; float resultS1; float resultS2; double c; double resultD; double resultD1; double resultD2; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 0.0L, 4.0L, 2.0L, 4e-28L }; double outputs_D[kTableLength] = { 0.0L, 2.0L, sqrt2_d, 2e-14L }; float inputs_S[kTableLength] = { 0.0, 4.0, 2.0, 4e-28 }; float outputs_S[kTableLength] = { 0.0, 2.0, sqrt2_s, 2e-14 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ sqrt_s(f6, f2); __ sqrt_d(f12, f8); __ rsqrt_d(f14, f8); __ rsqrt_s(f16, f2); __ recip_d(f18, f8); __ recip_s(f4, f2); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resultS1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resultD1)) ); __ swc1(f4, MemOperand(a0, offsetof(TestFloat, resultS2)) ); __ sdc1(f18, MemOperand(a0, offsetof(TestFloat, resultD2)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { float f1; double d1; test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); if (i != 0) { f1 = test.resultS1 - 1.0F/outputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD1 - 1.0L/outputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); f1 = test.resultS2 - 1.0F/inputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD2 - 1.0L/inputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); } else { CHECK_EQ(test.resultS1, 1.0F/outputs_S[i]); CHECK_EQ(test.resultD1, 1.0L/outputs_D[i]); CHECK_EQ(test.resultS2, 1.0F/inputs_S[i]); CHECK_EQ(test.resultD2, 1.0L/inputs_D[i]); } } } TEST(neg) { const int kTableLength = 2; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; double c; double resultD; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 4.0, -2.0 }; double outputs_D[kTableLength] = { -4.0, 2.0 }; float inputs_S[kTableLength] = { 4.0, -2.0 }; float outputs_S[kTableLength] = { -4.0, 2.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ neg_s(f6, f2); __ neg_d(f12, f8); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
()); F3 f = FUNCTION_CAST(code->entry()); t.a = 2.147483647e9; // 0x7fffffff -> 0x41DFFFFFFFC00000 as double. t.b_long_hi = 0x000000ff; // 0xFF00FF00FF -> 0x426FE01FE01FE000 as double. t.b_long_lo = 0x00ff00ff; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(static_cast(0x41DFFFFF), t.dbl_exp); CHECK_EQ(static_cast(0xFFC00000), t.dbl_mant); CHECK_EQ(0, t.long_hi); CHECK_EQ(static_cast(0x7fffffff), t.long_lo); CHECK_EQ(2.147483647e9, t.a_converted); // 0xFF00FF00FF -> 1.095233372415e12. CHECK_EQ(1.095233372415e12, t.b); CHECK_EQ(static_cast(0xFF00FF00FF), t.b_long_as_int64); } } TEST(MIPS11) { // Do not run test on MIPS64r6, as these instructions are removed. if (kArchVariant != kMips64r6) { // Test LWL, LWR, SWL and SWR instructions. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { int32_t reg_init; int32_t mem_init; int32_t lwl_0; int32_t lwl_1; int32_t lwl_2; int32_t lwl_3; int32_t lwr_0; int32_t lwr_1; int32_t lwr_2; int32_t lwr_3; int32_t swl_0; int32_t swl_1; int32_t swl_2; int32_t swl_3; int32_t swr_0; int32_t swr_1; int32_t swr_2; int32_t swr_3; } T; T t; Assembler assm(isolate, NULL, 0); // Test all combinations of LWL and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, lwl_0))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a5, MemOperand(a0, offsetof(T, mem_init) + 1)); __ sw(a5, MemOperand(a0, offsetof(T, lwl_1))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a6, MemOperand(a0, offsetof(T, mem_init) + 2)); __ sw(a6, MemOperand(a0, offsetof(T, lwl_2))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ lwl(a7, MemOperand(a0, offsetof(T, mem_init) + 3)); __ sw(a7, MemOperand(a0, offsetof(T, lwl_3))); // Test all combinations of LWR and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, lwr_0))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a5, MemOperand(a0, offsetof(T, mem_init) + 1)); __ sw(a5, MemOperand(a0, offsetof(T, lwr_1))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a6, MemOperand(a0, offsetof(T, mem_init) + 2)); __ sw(a6, MemOperand(a0, offsetof(T, lwr_2)) ); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ lwr(a7, MemOperand(a0, offsetof(T, mem_init) + 3)); __ sw(a7, MemOperand(a0, offsetof(T, lwr_3)) ); // Test all combinations of SWL and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, swl_0))); __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ swl(a4, MemOperand(a0, offsetof(T, swl_0))); __ lw(a5, MemOperand(a0, offsetof(T, mem_init))); __ sw(a5, MemOperand(a0, offsetof(T, swl_1))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ swl(a5, MemOperand(a0, offsetof(T, swl_1) + 1)); __ lw(a6, MemOperand(a0, offsetof(T, mem_init))); __ sw(a6, MemOperand(a0, offsetof(T, swl_2))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ swl(a6, MemOperand(a0, offsetof(T, swl_2) + 2)); __ lw(a7, MemOperand(a0, offsetof(T, mem_init))); __ sw(a7, MemOperand(a0, offsetof(T, swl_3))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ swl(a7, MemOperand(a0, offsetof(T, swl_3) + 3)); // Test all combinations of SWR and vAddr. __ lw(a4, MemOperand(a0, offsetof(T, mem_init))); __ sw(a4, MemOperand(a0, offsetof(T, swr_0))); __ lw(a4, MemOperand(a0, offsetof(T, reg_init))); __ swr(a4, MemOperand(a0, offsetof(T, swr_0))); __ lw(a5, MemOperand(a0, offsetof(T, mem_init))); __ sw(a5, MemOperand(a0, offsetof(T, swr_1))); __ lw(a5, MemOperand(a0, offsetof(T, reg_init))); __ swr(a5, MemOperand(a0, offsetof(T, swr_1) + 1)); __ lw(a6, MemOperand(a0, offsetof(T, mem_init))); __ sw(a6, MemOperand(a0, offsetof(T, swr_2))); __ lw(a6, MemOperand(a0, offsetof(T, reg_init))); __ swr(a6, MemOperand(a0, offsetof(T, swr_2) + 2)); __ lw(a7, MemOperand(a0, offsetof(T, mem_init))); __ sw(a7, MemOperand(a0, offsetof(T, swr_3))); __ lw(a7, MemOperand(a0, offsetof(T, reg_init))); __ swr(a7, MemOperand(a0, offsetof(T, swr_3) + 3)); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.reg_init = 0xaabbccdd; t.mem_init = 0x11223344; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); if (kArchEndian == kLittle) { CHECK_EQ(static_cast(0x44bbccdd), t.lwl_0); CHECK_EQ(static_cast(0x3344ccdd), t.lwl_1); CHECK_EQ(static_cast(0x223344dd), t.lwl_2); CHECK_EQ(static_cast(0x11223344), t.lwl_3); CHECK_EQ(static_cast(0x11223344), t.lwr_0); CHECK_EQ(static_cast(0xaa112233), t.lwr_1); CHECK_EQ(static_cast(0xaabb1122), t.lwr_2); CHECK_EQ(static_cast(0xaabbcc11), t.lwr_3); CHECK_EQ(static_cast(0x112233aa), t.swl_0); CHECK_EQ(static_cast(0x1122aabb), t.swl_1); CHECK_EQ(static_cast(0x11aabbcc), t.swl_2); CHECK_EQ(static_cast(0xaabbccdd), t.swl_3); CHECK_EQ(static_cast(0xaabbccdd), t.swr_0); CHECK_EQ(static_cast(0xbbccdd44), t.swr_1); CHECK_EQ(static_cast(0xccdd3344), t.swr_2); CHECK_EQ(static_cast(0xdd223344), t.swr_3); } else { CHECK_EQ(static_cast(0x11223344), t.lwl_0); CHECK_EQ(static_cast(0x223344dd), t.lwl_1); CHECK_EQ(static_cast(0x3344ccdd), t.lwl_2); CHECK_EQ(static_cast(0x44bbccdd), t.lwl_3); CHECK_EQ(static_cast(0xaabbcc11), t.lwr_0); CHECK_EQ(static_cast(0xaabb1122), t.lwr_1); CHECK_EQ(static_cast(0xaa112233), t.lwr_2); CHECK_EQ(static_cast(0x11223344), t.lwr_3); CHECK_EQ(static_cast(0xaabbccdd), t.swl_0); CHECK_EQ(static_cast(0x11aabbcc), t.swl_1); CHECK_EQ(static_cast(0x1122aabb), t.swl_2); CHECK_EQ(static_cast(0x112233aa), t.swl_3); CHECK_EQ(static_cast(0xdd223344), t.swr_0); CHECK_EQ(static_cast(0xccdd3344), t.swr_1); CHECK_EQ(static_cast(0xbbccdd44), t.swr_2); CHECK_EQ(static_cast(0xaabbccdd), t.swr_3); } } } TEST(MIPS12) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { int32_t x; int32_t y; int32_t y1; int32_t y2; int32_t y3; int32_t y4; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ mov(t2, fp); // Save frame pointer. __ mov(fp, a0); // Access struct T by fp. __ lw(a4, MemOperand(a0, offsetof(T, y))); __ lw(a7, MemOperand(a0, offsetof(T, y4))); __ addu(a5, a4, a7); __ subu(t0, a4, a7); __ nop(); __ push(a4); // These instructions disappear after opt. __ Pop(); __ addu(a4, a4, a4); __ nop(); __ Pop(); // These instructions disappear after opt. __ push(a7); __ nop(); __ push(a7); // These instructions disappear after opt. __ pop(a7); __ nop(); __ push(a7); __ pop(t0); __ nop(); __ sw(a4, MemOperand(fp, offsetof(T, y))); __ lw(a4, MemOperand(fp, offsetof(T, y))); __ nop(); __ sw(a4, MemOperand(fp, offsetof(T, y))); __ lw(a5, MemOperand(fp, offsetof(T, y))); __ nop(); __ push(a5); __ lw(a5, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a6); __ nop(); __ push(a6); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a7); __ nop(); __ mov(fp, t2); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.x = 1; t.y = 2; t.y1 = 3; t.y2 = 4; t.y3 = 0XBABA; t.y4 = 0xDEDA; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(3, t.y1); } TEST(MIPS13) { // Test Cvt_d_uw and Trunc_uw_d macros. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double cvt_big_out; double cvt_small_out; uint32_t trunc_big_out; uint32_t trunc_small_out; uint32_t cvt_big_in; uint32_t cvt_small_in; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ sw(a4, MemOperand(a0, offsetof(T, cvt_small_in))); __ Cvt_d_uw(f10, a4); __ sdc1(f10, MemOperand(a0, offsetof(T, cvt_small_out))); __ Trunc_uw_d(f10, f10, f4); __ swc1(f10, MemOperand(a0, offsetof(T, trunc_small_out))); __ sw(a4, MemOperand(a0, offsetof(T, cvt_big_in))); __ Cvt_d_uw(f8, a4); __ sdc1(f8, MemOperand(a0, offsetof(T, cvt_big_out))); __ Trunc_uw_d(f8, f8, f4); __ swc1(f8, MemOperand(a0, offsetof(T, trunc_big_out))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.cvt_big_in = 0xFFFFFFFF; t.cvt_small_in = 333; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(t.cvt_big_out, static_cast(t.cvt_big_in)); CHECK_EQ(t.cvt_small_out, static_cast(t.cvt_small_in)); CHECK_EQ(static_cast(t.trunc_big_out), static_cast(t.cvt_big_in)); CHECK_EQ(static_cast(t.trunc_small_out), static_cast(t.cvt_small_in)); } TEST(MIPS14) { // Test round, floor, ceil, trunc, cvt. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); #define ROUND_STRUCT_ELEMENT(x) \ uint32_t x##_isNaN2008; \ int32_t x##_up_out; \ int32_t x##_down_out; \ int32_t neg_##x##_up_out; \ int32_t neg_##x##_down_out; \ uint32_t x##_err1_out; \ uint32_t x##_err2_out; \ uint32_t x##_err3_out; \ uint32_t x##_err4_out; \ int32_t x##_invalid_result; typedef struct { double round_up_in; double round_down_in; double neg_round_up_in; double neg_round_down_in; double err1_in; double err2_in; double err3_in; double err4_in; ROUND_STRUCT_ELEMENT(round) ROUND_STRUCT_ELEMENT(floor) ROUND_STRUCT_ELEMENT(ceil) ROUND_STRUCT_ELEMENT(trunc) ROUND_STRUCT_ELEMENT(cvt) } T; T t; #undef ROUND_STRUCT_ELEMENT MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); // Save FCSR. __ cfc1(a1, FCSR); // Disable FPU exceptions. __ ctc1(zero_reg, FCSR); #define RUN_ROUND_TEST(x) \ __ cfc1(t0, FCSR);\ __ sw(t0, MemOperand(a0, offsetof(T, x##_isNaN2008))); \ __ ldc1(f0, MemOperand(a0, offsetof(T, round_up_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_up_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, round_down_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_down_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, neg_round_up_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, neg_##x##_up_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, neg_round_down_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, neg_##x##_down_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err1_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err1_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err2_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err2_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err3_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err3_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err4_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err4_out))); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_invalid_result))); RUN_ROUND_TEST(round) RUN_ROUND_TEST(floor) RUN_ROUND_TEST(ceil) RUN_ROUND_TEST(trunc) RUN_ROUND_TEST(cvt) // Restore FCSR. __ ctc1(a1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.round_up_in = 123.51; t.round_down_in = 123.49; t.neg_round_up_in = -123.5; t.neg_round_down_in = -123.49; t.err1_in = 123.51; t.err2_in = 1; t.err3_in = static_cast(1) + 0xFFFFFFFF; t.err4_in = NAN; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); #define GET_FPU_ERR(x) (static_cast(x & kFCSRFlagMask)) #define CHECK_NAN2008(x) (x & kFCSRNaN2008FlagMask) #define CHECK_ROUND_RESULT(type) \ CHECK(GET_FPU_ERR(t.type##_err1_out) & kFCSRInexactFlagMask); \ CHECK_EQ(0, GET_FPU_ERR(t.type##_err2_out)); \ CHECK(GET_FPU_ERR(t.type##_err3_out) & kFCSRInvalidOpFlagMask); \ CHECK(GET_FPU_ERR(t.type##_err4_out) & kFCSRInvalidOpFlagMask); \ if (CHECK_NAN2008(t.type##_isNaN2008) && kArchVariant == kMips64r6) { \ CHECK_EQ(static_cast(0), t.type##_invalid_result);\ } else { \ CHECK_EQ(static_cast(kFPUInvalidResult), t.type##_invalid_result);\ } CHECK_ROUND_RESULT(round); CHECK_ROUND_RESULT(floor); CHECK_ROUND_RESULT(ceil); CHECK_ROUND_RESULT(cvt); } TEST(MIPS15) { // Test chaining of label usages within instructions (issue 1644). CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); Assembler assm(isolate, NULL, 0); Label target; __ beq(v0, v1, &target); __ nop(); __ bne(v0, v1, &target); __ nop(); __ bind(&target); __ nop(); } // ----- mips64 tests ----------------------------------------------- TEST(MIPS16) { // Test 64-bit memory loads and stores. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); struct T { int64_t r1; int64_t r2; int64_t r3; int64_t r4; int64_t r5; int64_t r6; int64_t r7; int64_t r8; int64_t r9; int64_t r10; int64_t r11; int64_t r12; uint32_t ui; int32_t si; }; T t; Assembler assm(isolate, NULL, 0); Label L, C; // Basic 32-bit word load/store, with un-signed data. __ lw(a4, MemOperand(a0, offsetof(T, ui))); __ sw(a4, MemOperand(a0, offsetof(T, r1))); // Check that the data got zero-extended into 64-bit a4. __ sd(a4, MemOperand(a0, offsetof(T, r2))); // Basic 32-bit word load/store, with SIGNED data. __ lw(a5, MemOperand(a0, offsetof(T, si))); __ sw(a5, MemOperand(a0, offsetof(T, r3))); // Check that the data got sign-extended into 64-bit a4. __ sd(a5, MemOperand(a0, offsetof(T, r4))); // 32-bit UNSIGNED word load/store, with SIGNED data. __ lwu(a6, MemOperand(a0, offsetof(T, si))); __ sw(a6, MemOperand(a0, offsetof(T, r5))); // Check that the data got zero-extended into 64-bit a4. __ sd(a6, MemOperand(a0, offsetof(T, r6))); // lh with positive data. __ lh(a5, MemOperand(a0, offsetof(T, ui))); __ sw(a5, MemOperand(a0, offsetof(T, r7))); // lh with negative data. __ lh(a6, MemOperand(a0, offsetof(T, si))); __ sw(a6, MemOperand(a0, offsetof(T, r8))); // lhu with negative data. __ lhu(a7, MemOperand(a0, offsetof(T, si))); __ sw(a7, MemOperand(a0, offsetof(T, r9))); // lb with negative data. __ lb(t0, MemOperand(a0, offsetof(T, si))); __ sw(t0, MemOperand(a0, offsetof(T, r10))); // sh writes only 1/2 of word. __ lw(a4, MemOperand(a0, offsetof(T, ui))); __ sh(a4, MemOperand(a0, offsetof(T, r11))); __ lw(a4, MemOperand(a0, offsetof(T, si))); __ sh(a4, MemOperand(a0, offsetof(T, r12))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.ui = 0x44332211; t.si = 0x99aabbcc; t.r1 = 0x5555555555555555; t.r2 = 0x5555555555555555; t.r3 = 0x5555555555555555; t.r4 = 0x5555555555555555; t.r5 = 0x5555555555555555; t.r6 = 0x5555555555555555; t.r7 = 0x5555555555555555; t.r8 = 0x5555555555555555; t.r9 = 0x5555555555555555; t.r10 = 0x5555555555555555; t.r11 = 0x5555555555555555; t.r12 = 0x5555555555555555; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); if (kArchEndian == kLittle) { // Unsigned data, 32 & 64 CHECK_EQ(static_cast(0x5555555544332211L), t.r1); // lw, sw. CHECK_EQ(static_cast(0x0000000044332211L), t.r2); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x5555555599aabbccL), t.r3); // lw, sw. CHECK_EQ(static_cast(0xffffffff99aabbccL), t.r4); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x5555555599aabbccL), t.r5); // lwu, sw. CHECK_EQ(static_cast(0x0000000099aabbccL), t.r6); // sd. // lh with unsigned and signed data. CHECK_EQ(static_cast(0x5555555500002211L), t.r7); // lh, sw. CHECK_EQ(static_cast(0x55555555ffffbbccL), t.r8); // lh, sw. // lhu with signed data. CHECK_EQ(static_cast(0x555555550000bbccL), t.r9); // lhu, sw. // lb with signed data. CHECK_EQ(static_cast(0x55555555ffffffccL), t.r10); // lb, sw. // sh with unsigned and signed data. CHECK_EQ(static_cast(0x5555555555552211L), t.r11); // lw, sh. CHECK_EQ(static_cast(0x555555555555bbccL), t.r12); // lw, sh. } else { // Unsigned data, 32 & 64 CHECK_EQ(static_cast(0x4433221155555555L), t.r1); // lw, sw. CHECK_EQ(static_cast(0x0000000044332211L), t.r2); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x99aabbcc55555555L), t.r3); // lw, sw. CHECK_EQ(static_cast(0xffffffff99aabbccL), t.r4); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x99aabbcc55555555L), t.r5); // lwu, sw. CHECK_EQ(static_cast(0x0000000099aabbccL), t.r6); // sd. // lh with unsigned and signed data. CHECK_EQ(static_cast(0x0000443355555555L), t.r7); // lh, sw. CHECK_EQ(static_cast(0xffff99aa55555555L), t.r8); // lh, sw. // lhu with signed data. CHECK_EQ(static_cast(0x000099aa55555555L), t.r9); // lhu, sw. // lb with signed data. CHECK_EQ(static_cast(0xffffff9955555555L), t.r10); // lb, sw. // sh with unsigned and signed data. CHECK_EQ(static_cast(0x2211555555555555L), t.r11); // lw, sh. CHECK_EQ(static_cast(0xbbcc555555555555L), t.r12); // lw, sh. } } // ----------------------mips64r6 specific tests---------------------- TEST(seleqz_selnez) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { int a; int b; int c; int d; double e; double f; double g; double h; float i; float j; float k; float l; } Test; Test test; // Integer part of test. __ addiu(t1, zero_reg, 1); // t1 = 1 __ seleqz(t3, t1, zero_reg); // t3 = 1 __ sw(t3, MemOperand(a0, offsetof(Test, a))); // a = 1 __ seleqz(t2, t1, t1); // t2 = 0 __ sw(t2, MemOperand(a0, offsetof(Test, b))); // b = 0 __ selnez(t3, t1, zero_reg); // t3 = 1; __ sw(t3, MemOperand(a0, offsetof(Test, c))); // c = 0 __ selnez(t3, t1, t1); // t3 = 1 __ sw(t3, MemOperand(a0, offsetof(Test, d))); // d = 1 // Floating point part of test. __ ldc1(f0, MemOperand(a0, offsetof(Test, e)) ); // src __ ldc1(f2, MemOperand(a0, offsetof(Test, f)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, i)) ); // src __ lwc1(f10, MemOperand(a0, offsetof(Test, j)) ); // test __ seleqz_d(f4, f0, f2); __ selnez_d(f6, f0, f2); __ seleqz_s(f12, f8, f10); __ selnez_s(f14, f8, f10); __ sdc1(f4, MemOperand(a0, offsetof(Test, g)) ); // src __ sdc1(f6, MemOperand(a0, offsetof(Test, h)) ); // src __ swc1(f12, MemOperand(a0, offsetof(Test, k)) ); // src __ swc1(f14, MemOperand(a0, offsetof(Test, l)) ); // src __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.a, 1); CHECK_EQ(test.b, 0); CHECK_EQ(test.c, 0); CHECK_EQ(test.d, 1); const int test_size = 3; const int input_size = 5; double inputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double outputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float inputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float outputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.e = inputs_D[i]; test.f = tests_D[j]; test.i = inputs_S[i]; test.j = tests_S[j]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, outputs_D[i]); CHECK_EQ(test.h, 0); CHECK_EQ(test.k, outputs_S[i]); CHECK_EQ(test.l, 0); test.f = tests_D[j+1]; test.j = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, 0); CHECK_EQ(test.h, outputs_D[i]); CHECK_EQ(test.k, 0); CHECK_EQ(test.l, outputs_S[i]); } } } } TEST(min_max) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); struct TestFloat { double a; double b; double c; double d; float e; float f; float g; float h; }; TestFloat test; const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); const int kTableLength = 13; double inputsa[kTableLength] = {2.0, 3.0, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = {3.0, 2.0, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double outputsdmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double outputsdmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputse[kTableLength] = {2.0, 3.0, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsf[kTableLength] = {3.0, 2.0, 3.0, fnan, 0.0, -0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float outputsfmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float outputsfmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a))); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, b))); __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, e))); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, f))); __ min_d(f10, f4, f8); __ max_d(f12, f4, f8); __ min_s(f14, f2, f6); __ max_s(f16, f2, f6); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, c))); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, d))); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, g))); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, h))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 4; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.e = inputse[i]; test.f = inputsf[i]; CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0); CHECK_EQ(0, memcmp(&test.c, &outputsdmin[i], sizeof(test.c))); CHECK_EQ(0, memcmp(&test.d, &outputsdmax[i], sizeof(test.d))); CHECK_EQ(0, memcmp(&test.g, &outputsfmin[i], sizeof(test.g))); CHECK_EQ(0, memcmp(&test.h, &outputsfmax[i], sizeof(test.h))); } } } TEST(rint_d) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; int fcsr; }TestFloat; TestFloat test; double inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E+308, 6.27463370218383111104242366943E-307, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ ctc1(t0, FCSR); __ rint_d(f8, f4); __ sdc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(sel) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { double dd; double ds; double dt; float fd; float fs; float ft; } Test; Test test; __ ldc1(f0, MemOperand(a0, offsetof(Test, dd)) ); // test __ ldc1(f2, MemOperand(a0, offsetof(Test, ds)) ); // src1 __ ldc1(f4, MemOperand(a0, offsetof(Test, dt)) ); // src2 __ lwc1(f6, MemOperand(a0, offsetof(Test, fd)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, fs)) ); // src1 __ lwc1(f10, MemOperand(a0, offsetof(Test, ft)) ); // src2 __ sel_d(f0, f2, f4); __ sel_s(f6, f8, f10); __ sdc1(f0, MemOperand(a0, offsetof(Test, dd)) ); __ swc1(f6, MemOperand(a0, offsetof(Test, fd)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); const int test_size = 3; const int input_size = 5; double inputs_dt[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double inputs_ds[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; float inputs_ft[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float inputs_fs[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.dt = inputs_dt[i]; test.dd = tests_D[j]; test.ds = inputs_ds[i]; test.ft = inputs_ft[i]; test.fd = tests_S[j]; test.fs = inputs_fs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_ds[i]); CHECK_EQ(test.fd, inputs_fs[i]); test.dd = tests_D[j+1]; test.fd = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_dt[i]); CHECK_EQ(test.fd, inputs_ft[i]); } } } } TEST(rint_s) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; int fcsr; }TestFloat; TestFloat test; float inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E+38, 6.27463370218383111104242366943E-37, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; float* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ rint_s(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(mina_maxa) { if (kArchVariant == kMips64r6) { const int kTableLength = 23; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); struct TestFloat { double a; double b; double resd; double resd1; float c; float d; float resf; float resf1; }; TestFloat test; double inputsa[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = { 4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double resd[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double resd1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputsc[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsd[kTableLength] = {4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, fnan, -0.0, 0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float resf[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float resf1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ lwc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ lwc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ mina_d(f6, f2, f4); __ mina_s(f12, f8, f10); __ maxa_d(f14, f2, f4); __ maxa_s(f16, f8, f10); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, resf)) ); __ sdc1(f6, MemOperand(a0, offsetof(TestFloat, resd)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resf1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resd1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.c = inputsc[i]; test.d = inputsd[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if (i < kTableLength - 1) { CHECK_EQ(test.resd, resd[i]); CHECK_EQ(test.resf, resf[i]); CHECK_EQ(test.resd1, resd1[i]); CHECK_EQ(test.resf1, resf1[i]); } else { CHECK(std::isnan(test.resd)); CHECK(std::isnan(test.resf)); CHECK(std::isnan(test.resd1)); CHECK(std::isnan(test.resf1)); } } } } // ----------------------mips64r2 specific tests---------------------- TEST(trunc_l) { if (kArchVariant == kMips64r2) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; // a trunc result int64_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_l_d(f8, f4); __ trunc_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } } TEST(movz_movn) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { int64_t rt; double a; double b; double bold; double b1; double bold1; float c; float d; float dold; float d1; float dold1; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ld(t0, MemOperand(a0, offsetof(TestFloat, rt))); __ Move(f12, 0.0); __ Move(f10, 0.0); __ Move(f16, 0.0); __ Move(f14, 0.0); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, bold)) ); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, dold)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, bold1)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, dold1)) ); __ movz_s(f10, f6, t0); __ movz_d(f12, f2, t0); __ movn_s(f14, f6, t0); __ movn_d(f16, f2, t0); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, b)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, d1)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, b1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; test.rt = 1; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, test.bold); CHECK_EQ(test.d, test.dold); CHECK_EQ(test.b1, outputs_D[i]); CHECK_EQ(test.d1, outputs_S[i]); test.rt = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); CHECK_EQ(test.b1, test.bold1); CHECK_EQ(test.d1, test.dold1); } } } TEST(movt_movd) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); typedef struct test_float { double srcd; double dstd; double dstdold; double dstd1; double dstdold1; float srcf; float dstf; float dstfold; float dstf1; float dstfold1; int32_t cc; int32_t fcsr; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; double inputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; int condition_flags[8] = {0, 1, 2, 3, 4, 5, 6, 7}; for (int i = 0; i < kTableLength; i++) { test.srcd = inputs_D[i]; test.srcf = inputs_S[i]; for (int j = 0; j< 8; j++) { test.cc = condition_flags[j]; if (test.cc == 0) { test.fcsr = 1 << 23; } else { test.fcsr = 1 << (24+condition_flags[j]); } HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, srcd)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, srcf)) ); __ lw(t1, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t0, FCSR); __ ctc1(t1, FCSR); __ li(t2, 0x0); __ mtc1(t2, f12); __ mtc1(t2, f10); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold)) ); __ movt_s(f12, f4, test.cc); __ movt_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold1)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold1)) ); __ movf_s(f12, f4, test.cc); __ movf_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf1)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd1)) ); __ ctc1(t0, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, outputs_S[i]); CHECK_EQ(test.dstd, outputs_D[i]); CHECK_EQ(test.dstf1, test.dstfold1); CHECK_EQ(test.dstd1, test.dstdold1); test.fcsr = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, test.dstfold); CHECK_EQ(test.dstd, test.dstdold); CHECK_EQ(test.dstf1, outputs_S[i]); CHECK_EQ(test.dstd1, outputs_D[i]); } } } } // ----------------------tests for all archs-------------------------- TEST(cvt_w_d) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; int32_t b; int fcsr; }Test; const int kTableLength = 24; double inputs[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, 2147483653.0 }; double outputs_RN[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RZ[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RP[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RM[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lw(t0, MemOperand(a0, offsetof(Test, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ cvt_w_d(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(Test, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } TEST(trunc_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_w_d(f8, f4); __ trunc_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_w_d(f8, f4); __ round_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_l_d(f8, f4); __ round_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(sub) { const int kTableLength = 12; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; double inputft_D[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; double outputs_D[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; float inputfs_S[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; float inputft_S[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; float outputs_S[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sub_s(f6, f2, f4); __ sub_d(f12, f8, f10); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(sqrt_rsqrt_recip) { const int kTableLength = 4; const double deltaDouble = 2E-15; const float deltaFloat = 2E-7; const float sqrt2_s = sqrt(2); const double sqrt2_d = sqrt(2); CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; float resultS1; float resultS2; double c; double resultD; double resultD1; double resultD2; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 0.0L, 4.0L, 2.0L, 4e-28L }; double outputs_D[kTableLength] = { 0.0L, 2.0L, sqrt2_d, 2e-14L }; float inputs_S[kTableLength] = { 0.0, 4.0, 2.0, 4e-28 }; float outputs_S[kTableLength] = { 0.0, 2.0, sqrt2_s, 2e-14 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ sqrt_s(f6, f2); __ sqrt_d(f12, f8); __ rsqrt_d(f14, f8); __ rsqrt_s(f16, f2); __ recip_d(f18, f8); __ recip_s(f4, f2); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resultS1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resultD1)) ); __ swc1(f4, MemOperand(a0, offsetof(TestFloat, resultS2)) ); __ sdc1(f18, MemOperand(a0, offsetof(TestFloat, resultD2)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { float f1; double d1; test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); if (i != 0) { f1 = test.resultS1 - 1.0F/outputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD1 - 1.0L/outputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); f1 = test.resultS2 - 1.0F/inputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD2 - 1.0L/inputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); } else { CHECK_EQ(test.resultS1, 1.0F/outputs_S[i]); CHECK_EQ(test.resultD1, 1.0L/outputs_D[i]); CHECK_EQ(test.resultS2, 1.0F/inputs_S[i]); CHECK_EQ(test.resultD2, 1.0L/inputs_D[i]); } } } TEST(neg) { const int kTableLength = 2; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; double c; double resultD; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 4.0, -2.0 }; double outputs_D[kTableLength] = { -4.0, 2.0 }; float inputs_S[kTableLength] = { 4.0, -2.0 }; float outputs_S[kTableLength] = { -4.0, 2.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ neg_s(f6, f2); __ neg_d(f12, f8); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.reg_init = 0xaabbccdd; t.mem_init = 0x11223344; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); if (kArchEndian == kLittle) { CHECK_EQ(static_cast(0x44bbccdd), t.lwl_0); CHECK_EQ(static_cast(0x3344ccdd), t.lwl_1); CHECK_EQ(static_cast(0x223344dd), t.lwl_2); CHECK_EQ(static_cast(0x11223344), t.lwl_3); CHECK_EQ(static_cast(0x11223344), t.lwr_0); CHECK_EQ(static_cast(0xaa112233), t.lwr_1); CHECK_EQ(static_cast(0xaabb1122), t.lwr_2); CHECK_EQ(static_cast(0xaabbcc11), t.lwr_3); CHECK_EQ(static_cast(0x112233aa), t.swl_0); CHECK_EQ(static_cast(0x1122aabb), t.swl_1); CHECK_EQ(static_cast(0x11aabbcc), t.swl_2); CHECK_EQ(static_cast(0xaabbccdd), t.swl_3); CHECK_EQ(static_cast(0xaabbccdd), t.swr_0); CHECK_EQ(static_cast(0xbbccdd44), t.swr_1); CHECK_EQ(static_cast(0xccdd3344), t.swr_2); CHECK_EQ(static_cast(0xdd223344), t.swr_3); } else { CHECK_EQ(static_cast(0x11223344), t.lwl_0); CHECK_EQ(static_cast(0x223344dd), t.lwl_1); CHECK_EQ(static_cast(0x3344ccdd), t.lwl_2); CHECK_EQ(static_cast(0x44bbccdd), t.lwl_3); CHECK_EQ(static_cast(0xaabbcc11), t.lwr_0); CHECK_EQ(static_cast(0xaabb1122), t.lwr_1); CHECK_EQ(static_cast(0xaa112233), t.lwr_2); CHECK_EQ(static_cast(0x11223344), t.lwr_3); CHECK_EQ(static_cast(0xaabbccdd), t.swl_0); CHECK_EQ(static_cast(0x11aabbcc), t.swl_1); CHECK_EQ(static_cast(0x1122aabb), t.swl_2); CHECK_EQ(static_cast(0x112233aa), t.swl_3); CHECK_EQ(static_cast(0xdd223344), t.swr_0); CHECK_EQ(static_cast(0xccdd3344), t.swr_1); CHECK_EQ(static_cast(0xbbccdd44), t.swr_2); CHECK_EQ(static_cast(0xaabbccdd), t.swr_3); } } } TEST(MIPS12) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { int32_t x; int32_t y; int32_t y1; int32_t y2; int32_t y3; int32_t y4; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ mov(t2, fp); // Save frame pointer. __ mov(fp, a0); // Access struct T by fp. __ lw(a4, MemOperand(a0, offsetof(T, y))); __ lw(a7, MemOperand(a0, offsetof(T, y4))); __ addu(a5, a4, a7); __ subu(t0, a4, a7); __ nop(); __ push(a4); // These instructions disappear after opt. __ Pop(); __ addu(a4, a4, a4); __ nop(); __ Pop(); // These instructions disappear after opt. __ push(a7); __ nop(); __ push(a7); // These instructions disappear after opt. __ pop(a7); __ nop(); __ push(a7); __ pop(t0); __ nop(); __ sw(a4, MemOperand(fp, offsetof(T, y))); __ lw(a4, MemOperand(fp, offsetof(T, y))); __ nop(); __ sw(a4, MemOperand(fp, offsetof(T, y))); __ lw(a5, MemOperand(fp, offsetof(T, y))); __ nop(); __ push(a5); __ lw(a5, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a6); __ nop(); __ push(a6); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a7); __ nop(); __ mov(fp, t2); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.x = 1; t.y = 2; t.y1 = 3; t.y2 = 4; t.y3 = 0XBABA; t.y4 = 0xDEDA; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(3, t.y1); } TEST(MIPS13) { // Test Cvt_d_uw and Trunc_uw_d macros. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double cvt_big_out; double cvt_small_out; uint32_t trunc_big_out; uint32_t trunc_small_out; uint32_t cvt_big_in; uint32_t cvt_small_in; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ sw(a4, MemOperand(a0, offsetof(T, cvt_small_in))); __ Cvt_d_uw(f10, a4); __ sdc1(f10, MemOperand(a0, offsetof(T, cvt_small_out))); __ Trunc_uw_d(f10, f10, f4); __ swc1(f10, MemOperand(a0, offsetof(T, trunc_small_out))); __ sw(a4, MemOperand(a0, offsetof(T, cvt_big_in))); __ Cvt_d_uw(f8, a4); __ sdc1(f8, MemOperand(a0, offsetof(T, cvt_big_out))); __ Trunc_uw_d(f8, f8, f4); __ swc1(f8, MemOperand(a0, offsetof(T, trunc_big_out))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.cvt_big_in = 0xFFFFFFFF; t.cvt_small_in = 333; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(t.cvt_big_out, static_cast(t.cvt_big_in)); CHECK_EQ(t.cvt_small_out, static_cast(t.cvt_small_in)); CHECK_EQ(static_cast(t.trunc_big_out), static_cast(t.cvt_big_in)); CHECK_EQ(static_cast(t.trunc_small_out), static_cast(t.cvt_small_in)); } TEST(MIPS14) { // Test round, floor, ceil, trunc, cvt. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); #define ROUND_STRUCT_ELEMENT(x) \ uint32_t x##_isNaN2008; \ int32_t x##_up_out; \ int32_t x##_down_out; \ int32_t neg_##x##_up_out; \ int32_t neg_##x##_down_out; \ uint32_t x##_err1_out; \ uint32_t x##_err2_out; \ uint32_t x##_err3_out; \ uint32_t x##_err4_out; \ int32_t x##_invalid_result; typedef struct { double round_up_in; double round_down_in; double neg_round_up_in; double neg_round_down_in; double err1_in; double err2_in; double err3_in; double err4_in; ROUND_STRUCT_ELEMENT(round) ROUND_STRUCT_ELEMENT(floor) ROUND_STRUCT_ELEMENT(ceil) ROUND_STRUCT_ELEMENT(trunc) ROUND_STRUCT_ELEMENT(cvt) } T; T t; #undef ROUND_STRUCT_ELEMENT MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); // Save FCSR. __ cfc1(a1, FCSR); // Disable FPU exceptions. __ ctc1(zero_reg, FCSR); #define RUN_ROUND_TEST(x) \ __ cfc1(t0, FCSR);\ __ sw(t0, MemOperand(a0, offsetof(T, x##_isNaN2008))); \ __ ldc1(f0, MemOperand(a0, offsetof(T, round_up_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_up_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, round_down_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_down_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, neg_round_up_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, neg_##x##_up_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, neg_round_down_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, neg_##x##_down_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err1_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err1_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err2_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err2_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err3_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err3_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err4_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err4_out))); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_invalid_result))); RUN_ROUND_TEST(round) RUN_ROUND_TEST(floor) RUN_ROUND_TEST(ceil) RUN_ROUND_TEST(trunc) RUN_ROUND_TEST(cvt) // Restore FCSR. __ ctc1(a1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.round_up_in = 123.51; t.round_down_in = 123.49; t.neg_round_up_in = -123.5; t.neg_round_down_in = -123.49; t.err1_in = 123.51; t.err2_in = 1; t.err3_in = static_cast(1) + 0xFFFFFFFF; t.err4_in = NAN; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); #define GET_FPU_ERR(x) (static_cast(x & kFCSRFlagMask)) #define CHECK_NAN2008(x) (x & kFCSRNaN2008FlagMask) #define CHECK_ROUND_RESULT(type) \ CHECK(GET_FPU_ERR(t.type##_err1_out) & kFCSRInexactFlagMask); \ CHECK_EQ(0, GET_FPU_ERR(t.type##_err2_out)); \ CHECK(GET_FPU_ERR(t.type##_err3_out) & kFCSRInvalidOpFlagMask); \ CHECK(GET_FPU_ERR(t.type##_err4_out) & kFCSRInvalidOpFlagMask); \ if (CHECK_NAN2008(t.type##_isNaN2008) && kArchVariant == kMips64r6) { \ CHECK_EQ(static_cast(0), t.type##_invalid_result);\ } else { \ CHECK_EQ(static_cast(kFPUInvalidResult), t.type##_invalid_result);\ } CHECK_ROUND_RESULT(round); CHECK_ROUND_RESULT(floor); CHECK_ROUND_RESULT(ceil); CHECK_ROUND_RESULT(cvt); } TEST(MIPS15) { // Test chaining of label usages within instructions (issue 1644). CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); Assembler assm(isolate, NULL, 0); Label target; __ beq(v0, v1, &target); __ nop(); __ bne(v0, v1, &target); __ nop(); __ bind(&target); __ nop(); } // ----- mips64 tests ----------------------------------------------- TEST(MIPS16) { // Test 64-bit memory loads and stores. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); struct T { int64_t r1; int64_t r2; int64_t r3; int64_t r4; int64_t r5; int64_t r6; int64_t r7; int64_t r8; int64_t r9; int64_t r10; int64_t r11; int64_t r12; uint32_t ui; int32_t si; }; T t; Assembler assm(isolate, NULL, 0); Label L, C; // Basic 32-bit word load/store, with un-signed data. __ lw(a4, MemOperand(a0, offsetof(T, ui))); __ sw(a4, MemOperand(a0, offsetof(T, r1))); // Check that the data got zero-extended into 64-bit a4. __ sd(a4, MemOperand(a0, offsetof(T, r2))); // Basic 32-bit word load/store, with SIGNED data. __ lw(a5, MemOperand(a0, offsetof(T, si))); __ sw(a5, MemOperand(a0, offsetof(T, r3))); // Check that the data got sign-extended into 64-bit a4. __ sd(a5, MemOperand(a0, offsetof(T, r4))); // 32-bit UNSIGNED word load/store, with SIGNED data. __ lwu(a6, MemOperand(a0, offsetof(T, si))); __ sw(a6, MemOperand(a0, offsetof(T, r5))); // Check that the data got zero-extended into 64-bit a4. __ sd(a6, MemOperand(a0, offsetof(T, r6))); // lh with positive data. __ lh(a5, MemOperand(a0, offsetof(T, ui))); __ sw(a5, MemOperand(a0, offsetof(T, r7))); // lh with negative data. __ lh(a6, MemOperand(a0, offsetof(T, si))); __ sw(a6, MemOperand(a0, offsetof(T, r8))); // lhu with negative data. __ lhu(a7, MemOperand(a0, offsetof(T, si))); __ sw(a7, MemOperand(a0, offsetof(T, r9))); // lb with negative data. __ lb(t0, MemOperand(a0, offsetof(T, si))); __ sw(t0, MemOperand(a0, offsetof(T, r10))); // sh writes only 1/2 of word. __ lw(a4, MemOperand(a0, offsetof(T, ui))); __ sh(a4, MemOperand(a0, offsetof(T, r11))); __ lw(a4, MemOperand(a0, offsetof(T, si))); __ sh(a4, MemOperand(a0, offsetof(T, r12))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.ui = 0x44332211; t.si = 0x99aabbcc; t.r1 = 0x5555555555555555; t.r2 = 0x5555555555555555; t.r3 = 0x5555555555555555; t.r4 = 0x5555555555555555; t.r5 = 0x5555555555555555; t.r6 = 0x5555555555555555; t.r7 = 0x5555555555555555; t.r8 = 0x5555555555555555; t.r9 = 0x5555555555555555; t.r10 = 0x5555555555555555; t.r11 = 0x5555555555555555; t.r12 = 0x5555555555555555; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); if (kArchEndian == kLittle) { // Unsigned data, 32 & 64 CHECK_EQ(static_cast(0x5555555544332211L), t.r1); // lw, sw. CHECK_EQ(static_cast(0x0000000044332211L), t.r2); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x5555555599aabbccL), t.r3); // lw, sw. CHECK_EQ(static_cast(0xffffffff99aabbccL), t.r4); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x5555555599aabbccL), t.r5); // lwu, sw. CHECK_EQ(static_cast(0x0000000099aabbccL), t.r6); // sd. // lh with unsigned and signed data. CHECK_EQ(static_cast(0x5555555500002211L), t.r7); // lh, sw. CHECK_EQ(static_cast(0x55555555ffffbbccL), t.r8); // lh, sw. // lhu with signed data. CHECK_EQ(static_cast(0x555555550000bbccL), t.r9); // lhu, sw. // lb with signed data. CHECK_EQ(static_cast(0x55555555ffffffccL), t.r10); // lb, sw. // sh with unsigned and signed data. CHECK_EQ(static_cast(0x5555555555552211L), t.r11); // lw, sh. CHECK_EQ(static_cast(0x555555555555bbccL), t.r12); // lw, sh. } else { // Unsigned data, 32 & 64 CHECK_EQ(static_cast(0x4433221155555555L), t.r1); // lw, sw. CHECK_EQ(static_cast(0x0000000044332211L), t.r2); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x99aabbcc55555555L), t.r3); // lw, sw. CHECK_EQ(static_cast(0xffffffff99aabbccL), t.r4); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x99aabbcc55555555L), t.r5); // lwu, sw. CHECK_EQ(static_cast(0x0000000099aabbccL), t.r6); // sd. // lh with unsigned and signed data. CHECK_EQ(static_cast(0x0000443355555555L), t.r7); // lh, sw. CHECK_EQ(static_cast(0xffff99aa55555555L), t.r8); // lh, sw. // lhu with signed data. CHECK_EQ(static_cast(0x000099aa55555555L), t.r9); // lhu, sw. // lb with signed data. CHECK_EQ(static_cast(0xffffff9955555555L), t.r10); // lb, sw. // sh with unsigned and signed data. CHECK_EQ(static_cast(0x2211555555555555L), t.r11); // lw, sh. CHECK_EQ(static_cast(0xbbcc555555555555L), t.r12); // lw, sh. } } // ----------------------mips64r6 specific tests---------------------- TEST(seleqz_selnez) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { int a; int b; int c; int d; double e; double f; double g; double h; float i; float j; float k; float l; } Test; Test test; // Integer part of test. __ addiu(t1, zero_reg, 1); // t1 = 1 __ seleqz(t3, t1, zero_reg); // t3 = 1 __ sw(t3, MemOperand(a0, offsetof(Test, a))); // a = 1 __ seleqz(t2, t1, t1); // t2 = 0 __ sw(t2, MemOperand(a0, offsetof(Test, b))); // b = 0 __ selnez(t3, t1, zero_reg); // t3 = 1; __ sw(t3, MemOperand(a0, offsetof(Test, c))); // c = 0 __ selnez(t3, t1, t1); // t3 = 1 __ sw(t3, MemOperand(a0, offsetof(Test, d))); // d = 1 // Floating point part of test. __ ldc1(f0, MemOperand(a0, offsetof(Test, e)) ); // src __ ldc1(f2, MemOperand(a0, offsetof(Test, f)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, i)) ); // src __ lwc1(f10, MemOperand(a0, offsetof(Test, j)) ); // test __ seleqz_d(f4, f0, f2); __ selnez_d(f6, f0, f2); __ seleqz_s(f12, f8, f10); __ selnez_s(f14, f8, f10); __ sdc1(f4, MemOperand(a0, offsetof(Test, g)) ); // src __ sdc1(f6, MemOperand(a0, offsetof(Test, h)) ); // src __ swc1(f12, MemOperand(a0, offsetof(Test, k)) ); // src __ swc1(f14, MemOperand(a0, offsetof(Test, l)) ); // src __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.a, 1); CHECK_EQ(test.b, 0); CHECK_EQ(test.c, 0); CHECK_EQ(test.d, 1); const int test_size = 3; const int input_size = 5; double inputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double outputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float inputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float outputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.e = inputs_D[i]; test.f = tests_D[j]; test.i = inputs_S[i]; test.j = tests_S[j]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, outputs_D[i]); CHECK_EQ(test.h, 0); CHECK_EQ(test.k, outputs_S[i]); CHECK_EQ(test.l, 0); test.f = tests_D[j+1]; test.j = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, 0); CHECK_EQ(test.h, outputs_D[i]); CHECK_EQ(test.k, 0); CHECK_EQ(test.l, outputs_S[i]); } } } } TEST(min_max) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); struct TestFloat { double a; double b; double c; double d; float e; float f; float g; float h; }; TestFloat test; const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); const int kTableLength = 13; double inputsa[kTableLength] = {2.0, 3.0, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = {3.0, 2.0, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double outputsdmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double outputsdmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputse[kTableLength] = {2.0, 3.0, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsf[kTableLength] = {3.0, 2.0, 3.0, fnan, 0.0, -0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float outputsfmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float outputsfmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a))); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, b))); __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, e))); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, f))); __ min_d(f10, f4, f8); __ max_d(f12, f4, f8); __ min_s(f14, f2, f6); __ max_s(f16, f2, f6); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, c))); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, d))); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, g))); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, h))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 4; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.e = inputse[i]; test.f = inputsf[i]; CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0); CHECK_EQ(0, memcmp(&test.c, &outputsdmin[i], sizeof(test.c))); CHECK_EQ(0, memcmp(&test.d, &outputsdmax[i], sizeof(test.d))); CHECK_EQ(0, memcmp(&test.g, &outputsfmin[i], sizeof(test.g))); CHECK_EQ(0, memcmp(&test.h, &outputsfmax[i], sizeof(test.h))); } } } TEST(rint_d) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; int fcsr; }TestFloat; TestFloat test; double inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E+308, 6.27463370218383111104242366943E-307, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ ctc1(t0, FCSR); __ rint_d(f8, f4); __ sdc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(sel) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { double dd; double ds; double dt; float fd; float fs; float ft; } Test; Test test; __ ldc1(f0, MemOperand(a0, offsetof(Test, dd)) ); // test __ ldc1(f2, MemOperand(a0, offsetof(Test, ds)) ); // src1 __ ldc1(f4, MemOperand(a0, offsetof(Test, dt)) ); // src2 __ lwc1(f6, MemOperand(a0, offsetof(Test, fd)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, fs)) ); // src1 __ lwc1(f10, MemOperand(a0, offsetof(Test, ft)) ); // src2 __ sel_d(f0, f2, f4); __ sel_s(f6, f8, f10); __ sdc1(f0, MemOperand(a0, offsetof(Test, dd)) ); __ swc1(f6, MemOperand(a0, offsetof(Test, fd)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); const int test_size = 3; const int input_size = 5; double inputs_dt[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double inputs_ds[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; float inputs_ft[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float inputs_fs[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.dt = inputs_dt[i]; test.dd = tests_D[j]; test.ds = inputs_ds[i]; test.ft = inputs_ft[i]; test.fd = tests_S[j]; test.fs = inputs_fs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_ds[i]); CHECK_EQ(test.fd, inputs_fs[i]); test.dd = tests_D[j+1]; test.fd = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_dt[i]); CHECK_EQ(test.fd, inputs_ft[i]); } } } } TEST(rint_s) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; int fcsr; }TestFloat; TestFloat test; float inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E+38, 6.27463370218383111104242366943E-37, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; float* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ rint_s(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(mina_maxa) { if (kArchVariant == kMips64r6) { const int kTableLength = 23; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); struct TestFloat { double a; double b; double resd; double resd1; float c; float d; float resf; float resf1; }; TestFloat test; double inputsa[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = { 4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double resd[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double resd1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputsc[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsd[kTableLength] = {4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, fnan, -0.0, 0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float resf[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float resf1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ lwc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ lwc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ mina_d(f6, f2, f4); __ mina_s(f12, f8, f10); __ maxa_d(f14, f2, f4); __ maxa_s(f16, f8, f10); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, resf)) ); __ sdc1(f6, MemOperand(a0, offsetof(TestFloat, resd)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resf1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resd1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.c = inputsc[i]; test.d = inputsd[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if (i < kTableLength - 1) { CHECK_EQ(test.resd, resd[i]); CHECK_EQ(test.resf, resf[i]); CHECK_EQ(test.resd1, resd1[i]); CHECK_EQ(test.resf1, resf1[i]); } else { CHECK(std::isnan(test.resd)); CHECK(std::isnan(test.resf)); CHECK(std::isnan(test.resd1)); CHECK(std::isnan(test.resf1)); } } } } // ----------------------mips64r2 specific tests---------------------- TEST(trunc_l) { if (kArchVariant == kMips64r2) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; // a trunc result int64_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_l_d(f8, f4); __ trunc_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } } TEST(movz_movn) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { int64_t rt; double a; double b; double bold; double b1; double bold1; float c; float d; float dold; float d1; float dold1; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ld(t0, MemOperand(a0, offsetof(TestFloat, rt))); __ Move(f12, 0.0); __ Move(f10, 0.0); __ Move(f16, 0.0); __ Move(f14, 0.0); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, bold)) ); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, dold)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, bold1)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, dold1)) ); __ movz_s(f10, f6, t0); __ movz_d(f12, f2, t0); __ movn_s(f14, f6, t0); __ movn_d(f16, f2, t0); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, b)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, d1)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, b1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; test.rt = 1; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, test.bold); CHECK_EQ(test.d, test.dold); CHECK_EQ(test.b1, outputs_D[i]); CHECK_EQ(test.d1, outputs_S[i]); test.rt = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); CHECK_EQ(test.b1, test.bold1); CHECK_EQ(test.d1, test.dold1); } } } TEST(movt_movd) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); typedef struct test_float { double srcd; double dstd; double dstdold; double dstd1; double dstdold1; float srcf; float dstf; float dstfold; float dstf1; float dstfold1; int32_t cc; int32_t fcsr; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; double inputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; int condition_flags[8] = {0, 1, 2, 3, 4, 5, 6, 7}; for (int i = 0; i < kTableLength; i++) { test.srcd = inputs_D[i]; test.srcf = inputs_S[i]; for (int j = 0; j< 8; j++) { test.cc = condition_flags[j]; if (test.cc == 0) { test.fcsr = 1 << 23; } else { test.fcsr = 1 << (24+condition_flags[j]); } HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, srcd)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, srcf)) ); __ lw(t1, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t0, FCSR); __ ctc1(t1, FCSR); __ li(t2, 0x0); __ mtc1(t2, f12); __ mtc1(t2, f10); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold)) ); __ movt_s(f12, f4, test.cc); __ movt_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold1)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold1)) ); __ movf_s(f12, f4, test.cc); __ movf_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf1)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd1)) ); __ ctc1(t0, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, outputs_S[i]); CHECK_EQ(test.dstd, outputs_D[i]); CHECK_EQ(test.dstf1, test.dstfold1); CHECK_EQ(test.dstd1, test.dstdold1); test.fcsr = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, test.dstfold); CHECK_EQ(test.dstd, test.dstdold); CHECK_EQ(test.dstf1, outputs_S[i]); CHECK_EQ(test.dstd1, outputs_D[i]); } } } } // ----------------------tests for all archs-------------------------- TEST(cvt_w_d) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; int32_t b; int fcsr; }Test; const int kTableLength = 24; double inputs[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, 2147483653.0 }; double outputs_RN[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RZ[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RP[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RM[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lw(t0, MemOperand(a0, offsetof(Test, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ cvt_w_d(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(Test, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } TEST(trunc_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_w_d(f8, f4); __ trunc_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_w_d(f8, f4); __ round_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_l_d(f8, f4); __ round_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(sub) { const int kTableLength = 12; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; double inputft_D[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; double outputs_D[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; float inputfs_S[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; float inputft_S[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; float outputs_S[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sub_s(f6, f2, f4); __ sub_d(f12, f8, f10); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(sqrt_rsqrt_recip) { const int kTableLength = 4; const double deltaDouble = 2E-15; const float deltaFloat = 2E-7; const float sqrt2_s = sqrt(2); const double sqrt2_d = sqrt(2); CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; float resultS1; float resultS2; double c; double resultD; double resultD1; double resultD2; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 0.0L, 4.0L, 2.0L, 4e-28L }; double outputs_D[kTableLength] = { 0.0L, 2.0L, sqrt2_d, 2e-14L }; float inputs_S[kTableLength] = { 0.0, 4.0, 2.0, 4e-28 }; float outputs_S[kTableLength] = { 0.0, 2.0, sqrt2_s, 2e-14 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ sqrt_s(f6, f2); __ sqrt_d(f12, f8); __ rsqrt_d(f14, f8); __ rsqrt_s(f16, f2); __ recip_d(f18, f8); __ recip_s(f4, f2); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resultS1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resultD1)) ); __ swc1(f4, MemOperand(a0, offsetof(TestFloat, resultS2)) ); __ sdc1(f18, MemOperand(a0, offsetof(TestFloat, resultD2)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { float f1; double d1; test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); if (i != 0) { f1 = test.resultS1 - 1.0F/outputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD1 - 1.0L/outputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); f1 = test.resultS2 - 1.0F/inputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD2 - 1.0L/inputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); } else { CHECK_EQ(test.resultS1, 1.0F/outputs_S[i]); CHECK_EQ(test.resultD1, 1.0L/outputs_D[i]); CHECK_EQ(test.resultS2, 1.0F/inputs_S[i]); CHECK_EQ(test.resultD2, 1.0L/inputs_D[i]); } } } TEST(neg) { const int kTableLength = 2; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; double c; double resultD; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 4.0, -2.0 }; double outputs_D[kTableLength] = { -4.0, 2.0 }; float inputs_S[kTableLength] = { 4.0, -2.0 }; float outputs_S[kTableLength] = { -4.0, 2.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ neg_s(f6, f2); __ neg_d(f12, f8); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
()); F3 f = FUNCTION_CAST(code->entry()); t.reg_init = 0xaabbccdd; t.mem_init = 0x11223344; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); if (kArchEndian == kLittle) { CHECK_EQ(static_cast(0x44bbccdd), t.lwl_0); CHECK_EQ(static_cast(0x3344ccdd), t.lwl_1); CHECK_EQ(static_cast(0x223344dd), t.lwl_2); CHECK_EQ(static_cast(0x11223344), t.lwl_3); CHECK_EQ(static_cast(0x11223344), t.lwr_0); CHECK_EQ(static_cast(0xaa112233), t.lwr_1); CHECK_EQ(static_cast(0xaabb1122), t.lwr_2); CHECK_EQ(static_cast(0xaabbcc11), t.lwr_3); CHECK_EQ(static_cast(0x112233aa), t.swl_0); CHECK_EQ(static_cast(0x1122aabb), t.swl_1); CHECK_EQ(static_cast(0x11aabbcc), t.swl_2); CHECK_EQ(static_cast(0xaabbccdd), t.swl_3); CHECK_EQ(static_cast(0xaabbccdd), t.swr_0); CHECK_EQ(static_cast(0xbbccdd44), t.swr_1); CHECK_EQ(static_cast(0xccdd3344), t.swr_2); CHECK_EQ(static_cast(0xdd223344), t.swr_3); } else { CHECK_EQ(static_cast(0x11223344), t.lwl_0); CHECK_EQ(static_cast(0x223344dd), t.lwl_1); CHECK_EQ(static_cast(0x3344ccdd), t.lwl_2); CHECK_EQ(static_cast(0x44bbccdd), t.lwl_3); CHECK_EQ(static_cast(0xaabbcc11), t.lwr_0); CHECK_EQ(static_cast(0xaabb1122), t.lwr_1); CHECK_EQ(static_cast(0xaa112233), t.lwr_2); CHECK_EQ(static_cast(0x11223344), t.lwr_3); CHECK_EQ(static_cast(0xaabbccdd), t.swl_0); CHECK_EQ(static_cast(0x11aabbcc), t.swl_1); CHECK_EQ(static_cast(0x1122aabb), t.swl_2); CHECK_EQ(static_cast(0x112233aa), t.swl_3); CHECK_EQ(static_cast(0xdd223344), t.swr_0); CHECK_EQ(static_cast(0xccdd3344), t.swr_1); CHECK_EQ(static_cast(0xbbccdd44), t.swr_2); CHECK_EQ(static_cast(0xaabbccdd), t.swr_3); } } } TEST(MIPS12) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { int32_t x; int32_t y; int32_t y1; int32_t y2; int32_t y3; int32_t y4; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ mov(t2, fp); // Save frame pointer. __ mov(fp, a0); // Access struct T by fp. __ lw(a4, MemOperand(a0, offsetof(T, y))); __ lw(a7, MemOperand(a0, offsetof(T, y4))); __ addu(a5, a4, a7); __ subu(t0, a4, a7); __ nop(); __ push(a4); // These instructions disappear after opt. __ Pop(); __ addu(a4, a4, a4); __ nop(); __ Pop(); // These instructions disappear after opt. __ push(a7); __ nop(); __ push(a7); // These instructions disappear after opt. __ pop(a7); __ nop(); __ push(a7); __ pop(t0); __ nop(); __ sw(a4, MemOperand(fp, offsetof(T, y))); __ lw(a4, MemOperand(fp, offsetof(T, y))); __ nop(); __ sw(a4, MemOperand(fp, offsetof(T, y))); __ lw(a5, MemOperand(fp, offsetof(T, y))); __ nop(); __ push(a5); __ lw(a5, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a6); __ nop(); __ push(a6); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a5); __ nop(); __ push(a5); __ lw(a6, MemOperand(fp, offsetof(T, y))); __ pop(a7); __ nop(); __ mov(fp, t2); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.x = 1; t.y = 2; t.y1 = 3; t.y2 = 4; t.y3 = 0XBABA; t.y4 = 0xDEDA; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(3, t.y1); } TEST(MIPS13) { // Test Cvt_d_uw and Trunc_uw_d macros. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double cvt_big_out; double cvt_small_out; uint32_t trunc_big_out; uint32_t trunc_small_out; uint32_t cvt_big_in; uint32_t cvt_small_in; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ sw(a4, MemOperand(a0, offsetof(T, cvt_small_in))); __ Cvt_d_uw(f10, a4); __ sdc1(f10, MemOperand(a0, offsetof(T, cvt_small_out))); __ Trunc_uw_d(f10, f10, f4); __ swc1(f10, MemOperand(a0, offsetof(T, trunc_small_out))); __ sw(a4, MemOperand(a0, offsetof(T, cvt_big_in))); __ Cvt_d_uw(f8, a4); __ sdc1(f8, MemOperand(a0, offsetof(T, cvt_big_out))); __ Trunc_uw_d(f8, f8, f4); __ swc1(f8, MemOperand(a0, offsetof(T, trunc_big_out))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.cvt_big_in = 0xFFFFFFFF; t.cvt_small_in = 333; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(t.cvt_big_out, static_cast(t.cvt_big_in)); CHECK_EQ(t.cvt_small_out, static_cast(t.cvt_small_in)); CHECK_EQ(static_cast(t.trunc_big_out), static_cast(t.cvt_big_in)); CHECK_EQ(static_cast(t.trunc_small_out), static_cast(t.cvt_small_in)); } TEST(MIPS14) { // Test round, floor, ceil, trunc, cvt. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); #define ROUND_STRUCT_ELEMENT(x) \ uint32_t x##_isNaN2008; \ int32_t x##_up_out; \ int32_t x##_down_out; \ int32_t neg_##x##_up_out; \ int32_t neg_##x##_down_out; \ uint32_t x##_err1_out; \ uint32_t x##_err2_out; \ uint32_t x##_err3_out; \ uint32_t x##_err4_out; \ int32_t x##_invalid_result; typedef struct { double round_up_in; double round_down_in; double neg_round_up_in; double neg_round_down_in; double err1_in; double err2_in; double err3_in; double err4_in; ROUND_STRUCT_ELEMENT(round) ROUND_STRUCT_ELEMENT(floor) ROUND_STRUCT_ELEMENT(ceil) ROUND_STRUCT_ELEMENT(trunc) ROUND_STRUCT_ELEMENT(cvt) } T; T t; #undef ROUND_STRUCT_ELEMENT MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); // Save FCSR. __ cfc1(a1, FCSR); // Disable FPU exceptions. __ ctc1(zero_reg, FCSR); #define RUN_ROUND_TEST(x) \ __ cfc1(t0, FCSR);\ __ sw(t0, MemOperand(a0, offsetof(T, x##_isNaN2008))); \ __ ldc1(f0, MemOperand(a0, offsetof(T, round_up_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_up_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, round_down_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_down_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, neg_round_up_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, neg_##x##_up_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, neg_round_down_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, neg_##x##_down_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err1_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err1_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err2_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err2_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err3_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err3_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err4_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err4_out))); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_invalid_result))); RUN_ROUND_TEST(round) RUN_ROUND_TEST(floor) RUN_ROUND_TEST(ceil) RUN_ROUND_TEST(trunc) RUN_ROUND_TEST(cvt) // Restore FCSR. __ ctc1(a1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.round_up_in = 123.51; t.round_down_in = 123.49; t.neg_round_up_in = -123.5; t.neg_round_down_in = -123.49; t.err1_in = 123.51; t.err2_in = 1; t.err3_in = static_cast(1) + 0xFFFFFFFF; t.err4_in = NAN; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); #define GET_FPU_ERR(x) (static_cast(x & kFCSRFlagMask)) #define CHECK_NAN2008(x) (x & kFCSRNaN2008FlagMask) #define CHECK_ROUND_RESULT(type) \ CHECK(GET_FPU_ERR(t.type##_err1_out) & kFCSRInexactFlagMask); \ CHECK_EQ(0, GET_FPU_ERR(t.type##_err2_out)); \ CHECK(GET_FPU_ERR(t.type##_err3_out) & kFCSRInvalidOpFlagMask); \ CHECK(GET_FPU_ERR(t.type##_err4_out) & kFCSRInvalidOpFlagMask); \ if (CHECK_NAN2008(t.type##_isNaN2008) && kArchVariant == kMips64r6) { \ CHECK_EQ(static_cast(0), t.type##_invalid_result);\ } else { \ CHECK_EQ(static_cast(kFPUInvalidResult), t.type##_invalid_result);\ } CHECK_ROUND_RESULT(round); CHECK_ROUND_RESULT(floor); CHECK_ROUND_RESULT(ceil); CHECK_ROUND_RESULT(cvt); } TEST(MIPS15) { // Test chaining of label usages within instructions (issue 1644). CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); Assembler assm(isolate, NULL, 0); Label target; __ beq(v0, v1, &target); __ nop(); __ bne(v0, v1, &target); __ nop(); __ bind(&target); __ nop(); } // ----- mips64 tests ----------------------------------------------- TEST(MIPS16) { // Test 64-bit memory loads and stores. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); struct T { int64_t r1; int64_t r2; int64_t r3; int64_t r4; int64_t r5; int64_t r6; int64_t r7; int64_t r8; int64_t r9; int64_t r10; int64_t r11; int64_t r12; uint32_t ui; int32_t si; }; T t; Assembler assm(isolate, NULL, 0); Label L, C; // Basic 32-bit word load/store, with un-signed data. __ lw(a4, MemOperand(a0, offsetof(T, ui))); __ sw(a4, MemOperand(a0, offsetof(T, r1))); // Check that the data got zero-extended into 64-bit a4. __ sd(a4, MemOperand(a0, offsetof(T, r2))); // Basic 32-bit word load/store, with SIGNED data. __ lw(a5, MemOperand(a0, offsetof(T, si))); __ sw(a5, MemOperand(a0, offsetof(T, r3))); // Check that the data got sign-extended into 64-bit a4. __ sd(a5, MemOperand(a0, offsetof(T, r4))); // 32-bit UNSIGNED word load/store, with SIGNED data. __ lwu(a6, MemOperand(a0, offsetof(T, si))); __ sw(a6, MemOperand(a0, offsetof(T, r5))); // Check that the data got zero-extended into 64-bit a4. __ sd(a6, MemOperand(a0, offsetof(T, r6))); // lh with positive data. __ lh(a5, MemOperand(a0, offsetof(T, ui))); __ sw(a5, MemOperand(a0, offsetof(T, r7))); // lh with negative data. __ lh(a6, MemOperand(a0, offsetof(T, si))); __ sw(a6, MemOperand(a0, offsetof(T, r8))); // lhu with negative data. __ lhu(a7, MemOperand(a0, offsetof(T, si))); __ sw(a7, MemOperand(a0, offsetof(T, r9))); // lb with negative data. __ lb(t0, MemOperand(a0, offsetof(T, si))); __ sw(t0, MemOperand(a0, offsetof(T, r10))); // sh writes only 1/2 of word. __ lw(a4, MemOperand(a0, offsetof(T, ui))); __ sh(a4, MemOperand(a0, offsetof(T, r11))); __ lw(a4, MemOperand(a0, offsetof(T, si))); __ sh(a4, MemOperand(a0, offsetof(T, r12))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.ui = 0x44332211; t.si = 0x99aabbcc; t.r1 = 0x5555555555555555; t.r2 = 0x5555555555555555; t.r3 = 0x5555555555555555; t.r4 = 0x5555555555555555; t.r5 = 0x5555555555555555; t.r6 = 0x5555555555555555; t.r7 = 0x5555555555555555; t.r8 = 0x5555555555555555; t.r9 = 0x5555555555555555; t.r10 = 0x5555555555555555; t.r11 = 0x5555555555555555; t.r12 = 0x5555555555555555; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); if (kArchEndian == kLittle) { // Unsigned data, 32 & 64 CHECK_EQ(static_cast(0x5555555544332211L), t.r1); // lw, sw. CHECK_EQ(static_cast(0x0000000044332211L), t.r2); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x5555555599aabbccL), t.r3); // lw, sw. CHECK_EQ(static_cast(0xffffffff99aabbccL), t.r4); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x5555555599aabbccL), t.r5); // lwu, sw. CHECK_EQ(static_cast(0x0000000099aabbccL), t.r6); // sd. // lh with unsigned and signed data. CHECK_EQ(static_cast(0x5555555500002211L), t.r7); // lh, sw. CHECK_EQ(static_cast(0x55555555ffffbbccL), t.r8); // lh, sw. // lhu with signed data. CHECK_EQ(static_cast(0x555555550000bbccL), t.r9); // lhu, sw. // lb with signed data. CHECK_EQ(static_cast(0x55555555ffffffccL), t.r10); // lb, sw. // sh with unsigned and signed data. CHECK_EQ(static_cast(0x5555555555552211L), t.r11); // lw, sh. CHECK_EQ(static_cast(0x555555555555bbccL), t.r12); // lw, sh. } else { // Unsigned data, 32 & 64 CHECK_EQ(static_cast(0x4433221155555555L), t.r1); // lw, sw. CHECK_EQ(static_cast(0x0000000044332211L), t.r2); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x99aabbcc55555555L), t.r3); // lw, sw. CHECK_EQ(static_cast(0xffffffff99aabbccL), t.r4); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x99aabbcc55555555L), t.r5); // lwu, sw. CHECK_EQ(static_cast(0x0000000099aabbccL), t.r6); // sd. // lh with unsigned and signed data. CHECK_EQ(static_cast(0x0000443355555555L), t.r7); // lh, sw. CHECK_EQ(static_cast(0xffff99aa55555555L), t.r8); // lh, sw. // lhu with signed data. CHECK_EQ(static_cast(0x000099aa55555555L), t.r9); // lhu, sw. // lb with signed data. CHECK_EQ(static_cast(0xffffff9955555555L), t.r10); // lb, sw. // sh with unsigned and signed data. CHECK_EQ(static_cast(0x2211555555555555L), t.r11); // lw, sh. CHECK_EQ(static_cast(0xbbcc555555555555L), t.r12); // lw, sh. } } // ----------------------mips64r6 specific tests---------------------- TEST(seleqz_selnez) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { int a; int b; int c; int d; double e; double f; double g; double h; float i; float j; float k; float l; } Test; Test test; // Integer part of test. __ addiu(t1, zero_reg, 1); // t1 = 1 __ seleqz(t3, t1, zero_reg); // t3 = 1 __ sw(t3, MemOperand(a0, offsetof(Test, a))); // a = 1 __ seleqz(t2, t1, t1); // t2 = 0 __ sw(t2, MemOperand(a0, offsetof(Test, b))); // b = 0 __ selnez(t3, t1, zero_reg); // t3 = 1; __ sw(t3, MemOperand(a0, offsetof(Test, c))); // c = 0 __ selnez(t3, t1, t1); // t3 = 1 __ sw(t3, MemOperand(a0, offsetof(Test, d))); // d = 1 // Floating point part of test. __ ldc1(f0, MemOperand(a0, offsetof(Test, e)) ); // src __ ldc1(f2, MemOperand(a0, offsetof(Test, f)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, i)) ); // src __ lwc1(f10, MemOperand(a0, offsetof(Test, j)) ); // test __ seleqz_d(f4, f0, f2); __ selnez_d(f6, f0, f2); __ seleqz_s(f12, f8, f10); __ selnez_s(f14, f8, f10); __ sdc1(f4, MemOperand(a0, offsetof(Test, g)) ); // src __ sdc1(f6, MemOperand(a0, offsetof(Test, h)) ); // src __ swc1(f12, MemOperand(a0, offsetof(Test, k)) ); // src __ swc1(f14, MemOperand(a0, offsetof(Test, l)) ); // src __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.a, 1); CHECK_EQ(test.b, 0); CHECK_EQ(test.c, 0); CHECK_EQ(test.d, 1); const int test_size = 3; const int input_size = 5; double inputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double outputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float inputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float outputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.e = inputs_D[i]; test.f = tests_D[j]; test.i = inputs_S[i]; test.j = tests_S[j]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, outputs_D[i]); CHECK_EQ(test.h, 0); CHECK_EQ(test.k, outputs_S[i]); CHECK_EQ(test.l, 0); test.f = tests_D[j+1]; test.j = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, 0); CHECK_EQ(test.h, outputs_D[i]); CHECK_EQ(test.k, 0); CHECK_EQ(test.l, outputs_S[i]); } } } } TEST(min_max) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); struct TestFloat { double a; double b; double c; double d; float e; float f; float g; float h; }; TestFloat test; const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); const int kTableLength = 13; double inputsa[kTableLength] = {2.0, 3.0, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = {3.0, 2.0, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double outputsdmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double outputsdmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputse[kTableLength] = {2.0, 3.0, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsf[kTableLength] = {3.0, 2.0, 3.0, fnan, 0.0, -0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float outputsfmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float outputsfmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a))); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, b))); __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, e))); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, f))); __ min_d(f10, f4, f8); __ max_d(f12, f4, f8); __ min_s(f14, f2, f6); __ max_s(f16, f2, f6); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, c))); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, d))); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, g))); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, h))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 4; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.e = inputse[i]; test.f = inputsf[i]; CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0); CHECK_EQ(0, memcmp(&test.c, &outputsdmin[i], sizeof(test.c))); CHECK_EQ(0, memcmp(&test.d, &outputsdmax[i], sizeof(test.d))); CHECK_EQ(0, memcmp(&test.g, &outputsfmin[i], sizeof(test.g))); CHECK_EQ(0, memcmp(&test.h, &outputsfmax[i], sizeof(test.h))); } } } TEST(rint_d) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; int fcsr; }TestFloat; TestFloat test; double inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E+308, 6.27463370218383111104242366943E-307, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ ctc1(t0, FCSR); __ rint_d(f8, f4); __ sdc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(sel) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { double dd; double ds; double dt; float fd; float fs; float ft; } Test; Test test; __ ldc1(f0, MemOperand(a0, offsetof(Test, dd)) ); // test __ ldc1(f2, MemOperand(a0, offsetof(Test, ds)) ); // src1 __ ldc1(f4, MemOperand(a0, offsetof(Test, dt)) ); // src2 __ lwc1(f6, MemOperand(a0, offsetof(Test, fd)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, fs)) ); // src1 __ lwc1(f10, MemOperand(a0, offsetof(Test, ft)) ); // src2 __ sel_d(f0, f2, f4); __ sel_s(f6, f8, f10); __ sdc1(f0, MemOperand(a0, offsetof(Test, dd)) ); __ swc1(f6, MemOperand(a0, offsetof(Test, fd)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); const int test_size = 3; const int input_size = 5; double inputs_dt[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double inputs_ds[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; float inputs_ft[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float inputs_fs[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.dt = inputs_dt[i]; test.dd = tests_D[j]; test.ds = inputs_ds[i]; test.ft = inputs_ft[i]; test.fd = tests_S[j]; test.fs = inputs_fs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_ds[i]); CHECK_EQ(test.fd, inputs_fs[i]); test.dd = tests_D[j+1]; test.fd = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_dt[i]); CHECK_EQ(test.fd, inputs_ft[i]); } } } } TEST(rint_s) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; int fcsr; }TestFloat; TestFloat test; float inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E+38, 6.27463370218383111104242366943E-37, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; float* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ rint_s(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(mina_maxa) { if (kArchVariant == kMips64r6) { const int kTableLength = 23; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); struct TestFloat { double a; double b; double resd; double resd1; float c; float d; float resf; float resf1; }; TestFloat test; double inputsa[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = { 4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double resd[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double resd1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputsc[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsd[kTableLength] = {4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, fnan, -0.0, 0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float resf[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float resf1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ lwc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ lwc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ mina_d(f6, f2, f4); __ mina_s(f12, f8, f10); __ maxa_d(f14, f2, f4); __ maxa_s(f16, f8, f10); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, resf)) ); __ sdc1(f6, MemOperand(a0, offsetof(TestFloat, resd)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resf1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resd1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.c = inputsc[i]; test.d = inputsd[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if (i < kTableLength - 1) { CHECK_EQ(test.resd, resd[i]); CHECK_EQ(test.resf, resf[i]); CHECK_EQ(test.resd1, resd1[i]); CHECK_EQ(test.resf1, resf1[i]); } else { CHECK(std::isnan(test.resd)); CHECK(std::isnan(test.resf)); CHECK(std::isnan(test.resd1)); CHECK(std::isnan(test.resf1)); } } } } // ----------------------mips64r2 specific tests---------------------- TEST(trunc_l) { if (kArchVariant == kMips64r2) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; // a trunc result int64_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_l_d(f8, f4); __ trunc_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } } TEST(movz_movn) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { int64_t rt; double a; double b; double bold; double b1; double bold1; float c; float d; float dold; float d1; float dold1; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ld(t0, MemOperand(a0, offsetof(TestFloat, rt))); __ Move(f12, 0.0); __ Move(f10, 0.0); __ Move(f16, 0.0); __ Move(f14, 0.0); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, bold)) ); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, dold)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, bold1)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, dold1)) ); __ movz_s(f10, f6, t0); __ movz_d(f12, f2, t0); __ movn_s(f14, f6, t0); __ movn_d(f16, f2, t0); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, b)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, d1)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, b1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; test.rt = 1; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, test.bold); CHECK_EQ(test.d, test.dold); CHECK_EQ(test.b1, outputs_D[i]); CHECK_EQ(test.d1, outputs_S[i]); test.rt = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); CHECK_EQ(test.b1, test.bold1); CHECK_EQ(test.d1, test.dold1); } } } TEST(movt_movd) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); typedef struct test_float { double srcd; double dstd; double dstdold; double dstd1; double dstdold1; float srcf; float dstf; float dstfold; float dstf1; float dstfold1; int32_t cc; int32_t fcsr; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; double inputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; int condition_flags[8] = {0, 1, 2, 3, 4, 5, 6, 7}; for (int i = 0; i < kTableLength; i++) { test.srcd = inputs_D[i]; test.srcf = inputs_S[i]; for (int j = 0; j< 8; j++) { test.cc = condition_flags[j]; if (test.cc == 0) { test.fcsr = 1 << 23; } else { test.fcsr = 1 << (24+condition_flags[j]); } HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, srcd)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, srcf)) ); __ lw(t1, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t0, FCSR); __ ctc1(t1, FCSR); __ li(t2, 0x0); __ mtc1(t2, f12); __ mtc1(t2, f10); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold)) ); __ movt_s(f12, f4, test.cc); __ movt_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold1)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold1)) ); __ movf_s(f12, f4, test.cc); __ movf_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf1)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd1)) ); __ ctc1(t0, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, outputs_S[i]); CHECK_EQ(test.dstd, outputs_D[i]); CHECK_EQ(test.dstf1, test.dstfold1); CHECK_EQ(test.dstd1, test.dstdold1); test.fcsr = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, test.dstfold); CHECK_EQ(test.dstd, test.dstdold); CHECK_EQ(test.dstf1, outputs_S[i]); CHECK_EQ(test.dstd1, outputs_D[i]); } } } } // ----------------------tests for all archs-------------------------- TEST(cvt_w_d) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; int32_t b; int fcsr; }Test; const int kTableLength = 24; double inputs[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, 2147483653.0 }; double outputs_RN[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RZ[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RP[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RM[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lw(t0, MemOperand(a0, offsetof(Test, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ cvt_w_d(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(Test, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } TEST(trunc_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_w_d(f8, f4); __ trunc_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_w_d(f8, f4); __ round_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_l_d(f8, f4); __ round_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(sub) { const int kTableLength = 12; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; double inputft_D[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; double outputs_D[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; float inputfs_S[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; float inputft_S[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; float outputs_S[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sub_s(f6, f2, f4); __ sub_d(f12, f8, f10); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(sqrt_rsqrt_recip) { const int kTableLength = 4; const double deltaDouble = 2E-15; const float deltaFloat = 2E-7; const float sqrt2_s = sqrt(2); const double sqrt2_d = sqrt(2); CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; float resultS1; float resultS2; double c; double resultD; double resultD1; double resultD2; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 0.0L, 4.0L, 2.0L, 4e-28L }; double outputs_D[kTableLength] = { 0.0L, 2.0L, sqrt2_d, 2e-14L }; float inputs_S[kTableLength] = { 0.0, 4.0, 2.0, 4e-28 }; float outputs_S[kTableLength] = { 0.0, 2.0, sqrt2_s, 2e-14 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ sqrt_s(f6, f2); __ sqrt_d(f12, f8); __ rsqrt_d(f14, f8); __ rsqrt_s(f16, f2); __ recip_d(f18, f8); __ recip_s(f4, f2); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resultS1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resultD1)) ); __ swc1(f4, MemOperand(a0, offsetof(TestFloat, resultS2)) ); __ sdc1(f18, MemOperand(a0, offsetof(TestFloat, resultD2)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { float f1; double d1; test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); if (i != 0) { f1 = test.resultS1 - 1.0F/outputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD1 - 1.0L/outputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); f1 = test.resultS2 - 1.0F/inputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD2 - 1.0L/inputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); } else { CHECK_EQ(test.resultS1, 1.0F/outputs_S[i]); CHECK_EQ(test.resultD1, 1.0L/outputs_D[i]); CHECK_EQ(test.resultS2, 1.0F/inputs_S[i]); CHECK_EQ(test.resultD2, 1.0L/inputs_D[i]); } } } TEST(neg) { const int kTableLength = 2; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; double c; double resultD; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 4.0, -2.0 }; double outputs_D[kTableLength] = { -4.0, 2.0 }; float inputs_S[kTableLength] = { 4.0, -2.0 }; float outputs_S[kTableLength] = { -4.0, 2.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ neg_s(f6, f2); __ neg_d(f12, f8); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.x = 1; t.y = 2; t.y1 = 3; t.y2 = 4; t.y3 = 0XBABA; t.y4 = 0xDEDA; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(3, t.y1); } TEST(MIPS13) { // Test Cvt_d_uw and Trunc_uw_d macros. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double cvt_big_out; double cvt_small_out; uint32_t trunc_big_out; uint32_t trunc_small_out; uint32_t cvt_big_in; uint32_t cvt_small_in; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ sw(a4, MemOperand(a0, offsetof(T, cvt_small_in))); __ Cvt_d_uw(f10, a4); __ sdc1(f10, MemOperand(a0, offsetof(T, cvt_small_out))); __ Trunc_uw_d(f10, f10, f4); __ swc1(f10, MemOperand(a0, offsetof(T, trunc_small_out))); __ sw(a4, MemOperand(a0, offsetof(T, cvt_big_in))); __ Cvt_d_uw(f8, a4); __ sdc1(f8, MemOperand(a0, offsetof(T, cvt_big_out))); __ Trunc_uw_d(f8, f8, f4); __ swc1(f8, MemOperand(a0, offsetof(T, trunc_big_out))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.cvt_big_in = 0xFFFFFFFF; t.cvt_small_in = 333; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(t.cvt_big_out, static_cast(t.cvt_big_in)); CHECK_EQ(t.cvt_small_out, static_cast(t.cvt_small_in)); CHECK_EQ(static_cast(t.trunc_big_out), static_cast(t.cvt_big_in)); CHECK_EQ(static_cast(t.trunc_small_out), static_cast(t.cvt_small_in)); } TEST(MIPS14) { // Test round, floor, ceil, trunc, cvt. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); #define ROUND_STRUCT_ELEMENT(x) \ uint32_t x##_isNaN2008; \ int32_t x##_up_out; \ int32_t x##_down_out; \ int32_t neg_##x##_up_out; \ int32_t neg_##x##_down_out; \ uint32_t x##_err1_out; \ uint32_t x##_err2_out; \ uint32_t x##_err3_out; \ uint32_t x##_err4_out; \ int32_t x##_invalid_result; typedef struct { double round_up_in; double round_down_in; double neg_round_up_in; double neg_round_down_in; double err1_in; double err2_in; double err3_in; double err4_in; ROUND_STRUCT_ELEMENT(round) ROUND_STRUCT_ELEMENT(floor) ROUND_STRUCT_ELEMENT(ceil) ROUND_STRUCT_ELEMENT(trunc) ROUND_STRUCT_ELEMENT(cvt) } T; T t; #undef ROUND_STRUCT_ELEMENT MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); // Save FCSR. __ cfc1(a1, FCSR); // Disable FPU exceptions. __ ctc1(zero_reg, FCSR); #define RUN_ROUND_TEST(x) \ __ cfc1(t0, FCSR);\ __ sw(t0, MemOperand(a0, offsetof(T, x##_isNaN2008))); \ __ ldc1(f0, MemOperand(a0, offsetof(T, round_up_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_up_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, round_down_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_down_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, neg_round_up_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, neg_##x##_up_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, neg_round_down_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, neg_##x##_down_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err1_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err1_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err2_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err2_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err3_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err3_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err4_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err4_out))); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_invalid_result))); RUN_ROUND_TEST(round) RUN_ROUND_TEST(floor) RUN_ROUND_TEST(ceil) RUN_ROUND_TEST(trunc) RUN_ROUND_TEST(cvt) // Restore FCSR. __ ctc1(a1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.round_up_in = 123.51; t.round_down_in = 123.49; t.neg_round_up_in = -123.5; t.neg_round_down_in = -123.49; t.err1_in = 123.51; t.err2_in = 1; t.err3_in = static_cast(1) + 0xFFFFFFFF; t.err4_in = NAN; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); #define GET_FPU_ERR(x) (static_cast(x & kFCSRFlagMask)) #define CHECK_NAN2008(x) (x & kFCSRNaN2008FlagMask) #define CHECK_ROUND_RESULT(type) \ CHECK(GET_FPU_ERR(t.type##_err1_out) & kFCSRInexactFlagMask); \ CHECK_EQ(0, GET_FPU_ERR(t.type##_err2_out)); \ CHECK(GET_FPU_ERR(t.type##_err3_out) & kFCSRInvalidOpFlagMask); \ CHECK(GET_FPU_ERR(t.type##_err4_out) & kFCSRInvalidOpFlagMask); \ if (CHECK_NAN2008(t.type##_isNaN2008) && kArchVariant == kMips64r6) { \ CHECK_EQ(static_cast(0), t.type##_invalid_result);\ } else { \ CHECK_EQ(static_cast(kFPUInvalidResult), t.type##_invalid_result);\ } CHECK_ROUND_RESULT(round); CHECK_ROUND_RESULT(floor); CHECK_ROUND_RESULT(ceil); CHECK_ROUND_RESULT(cvt); } TEST(MIPS15) { // Test chaining of label usages within instructions (issue 1644). CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); Assembler assm(isolate, NULL, 0); Label target; __ beq(v0, v1, &target); __ nop(); __ bne(v0, v1, &target); __ nop(); __ bind(&target); __ nop(); } // ----- mips64 tests ----------------------------------------------- TEST(MIPS16) { // Test 64-bit memory loads and stores. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); struct T { int64_t r1; int64_t r2; int64_t r3; int64_t r4; int64_t r5; int64_t r6; int64_t r7; int64_t r8; int64_t r9; int64_t r10; int64_t r11; int64_t r12; uint32_t ui; int32_t si; }; T t; Assembler assm(isolate, NULL, 0); Label L, C; // Basic 32-bit word load/store, with un-signed data. __ lw(a4, MemOperand(a0, offsetof(T, ui))); __ sw(a4, MemOperand(a0, offsetof(T, r1))); // Check that the data got zero-extended into 64-bit a4. __ sd(a4, MemOperand(a0, offsetof(T, r2))); // Basic 32-bit word load/store, with SIGNED data. __ lw(a5, MemOperand(a0, offsetof(T, si))); __ sw(a5, MemOperand(a0, offsetof(T, r3))); // Check that the data got sign-extended into 64-bit a4. __ sd(a5, MemOperand(a0, offsetof(T, r4))); // 32-bit UNSIGNED word load/store, with SIGNED data. __ lwu(a6, MemOperand(a0, offsetof(T, si))); __ sw(a6, MemOperand(a0, offsetof(T, r5))); // Check that the data got zero-extended into 64-bit a4. __ sd(a6, MemOperand(a0, offsetof(T, r6))); // lh with positive data. __ lh(a5, MemOperand(a0, offsetof(T, ui))); __ sw(a5, MemOperand(a0, offsetof(T, r7))); // lh with negative data. __ lh(a6, MemOperand(a0, offsetof(T, si))); __ sw(a6, MemOperand(a0, offsetof(T, r8))); // lhu with negative data. __ lhu(a7, MemOperand(a0, offsetof(T, si))); __ sw(a7, MemOperand(a0, offsetof(T, r9))); // lb with negative data. __ lb(t0, MemOperand(a0, offsetof(T, si))); __ sw(t0, MemOperand(a0, offsetof(T, r10))); // sh writes only 1/2 of word. __ lw(a4, MemOperand(a0, offsetof(T, ui))); __ sh(a4, MemOperand(a0, offsetof(T, r11))); __ lw(a4, MemOperand(a0, offsetof(T, si))); __ sh(a4, MemOperand(a0, offsetof(T, r12))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.ui = 0x44332211; t.si = 0x99aabbcc; t.r1 = 0x5555555555555555; t.r2 = 0x5555555555555555; t.r3 = 0x5555555555555555; t.r4 = 0x5555555555555555; t.r5 = 0x5555555555555555; t.r6 = 0x5555555555555555; t.r7 = 0x5555555555555555; t.r8 = 0x5555555555555555; t.r9 = 0x5555555555555555; t.r10 = 0x5555555555555555; t.r11 = 0x5555555555555555; t.r12 = 0x5555555555555555; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); if (kArchEndian == kLittle) { // Unsigned data, 32 & 64 CHECK_EQ(static_cast(0x5555555544332211L), t.r1); // lw, sw. CHECK_EQ(static_cast(0x0000000044332211L), t.r2); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x5555555599aabbccL), t.r3); // lw, sw. CHECK_EQ(static_cast(0xffffffff99aabbccL), t.r4); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x5555555599aabbccL), t.r5); // lwu, sw. CHECK_EQ(static_cast(0x0000000099aabbccL), t.r6); // sd. // lh with unsigned and signed data. CHECK_EQ(static_cast(0x5555555500002211L), t.r7); // lh, sw. CHECK_EQ(static_cast(0x55555555ffffbbccL), t.r8); // lh, sw. // lhu with signed data. CHECK_EQ(static_cast(0x555555550000bbccL), t.r9); // lhu, sw. // lb with signed data. CHECK_EQ(static_cast(0x55555555ffffffccL), t.r10); // lb, sw. // sh with unsigned and signed data. CHECK_EQ(static_cast(0x5555555555552211L), t.r11); // lw, sh. CHECK_EQ(static_cast(0x555555555555bbccL), t.r12); // lw, sh. } else { // Unsigned data, 32 & 64 CHECK_EQ(static_cast(0x4433221155555555L), t.r1); // lw, sw. CHECK_EQ(static_cast(0x0000000044332211L), t.r2); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x99aabbcc55555555L), t.r3); // lw, sw. CHECK_EQ(static_cast(0xffffffff99aabbccL), t.r4); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x99aabbcc55555555L), t.r5); // lwu, sw. CHECK_EQ(static_cast(0x0000000099aabbccL), t.r6); // sd. // lh with unsigned and signed data. CHECK_EQ(static_cast(0x0000443355555555L), t.r7); // lh, sw. CHECK_EQ(static_cast(0xffff99aa55555555L), t.r8); // lh, sw. // lhu with signed data. CHECK_EQ(static_cast(0x000099aa55555555L), t.r9); // lhu, sw. // lb with signed data. CHECK_EQ(static_cast(0xffffff9955555555L), t.r10); // lb, sw. // sh with unsigned and signed data. CHECK_EQ(static_cast(0x2211555555555555L), t.r11); // lw, sh. CHECK_EQ(static_cast(0xbbcc555555555555L), t.r12); // lw, sh. } } // ----------------------mips64r6 specific tests---------------------- TEST(seleqz_selnez) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { int a; int b; int c; int d; double e; double f; double g; double h; float i; float j; float k; float l; } Test; Test test; // Integer part of test. __ addiu(t1, zero_reg, 1); // t1 = 1 __ seleqz(t3, t1, zero_reg); // t3 = 1 __ sw(t3, MemOperand(a0, offsetof(Test, a))); // a = 1 __ seleqz(t2, t1, t1); // t2 = 0 __ sw(t2, MemOperand(a0, offsetof(Test, b))); // b = 0 __ selnez(t3, t1, zero_reg); // t3 = 1; __ sw(t3, MemOperand(a0, offsetof(Test, c))); // c = 0 __ selnez(t3, t1, t1); // t3 = 1 __ sw(t3, MemOperand(a0, offsetof(Test, d))); // d = 1 // Floating point part of test. __ ldc1(f0, MemOperand(a0, offsetof(Test, e)) ); // src __ ldc1(f2, MemOperand(a0, offsetof(Test, f)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, i)) ); // src __ lwc1(f10, MemOperand(a0, offsetof(Test, j)) ); // test __ seleqz_d(f4, f0, f2); __ selnez_d(f6, f0, f2); __ seleqz_s(f12, f8, f10); __ selnez_s(f14, f8, f10); __ sdc1(f4, MemOperand(a0, offsetof(Test, g)) ); // src __ sdc1(f6, MemOperand(a0, offsetof(Test, h)) ); // src __ swc1(f12, MemOperand(a0, offsetof(Test, k)) ); // src __ swc1(f14, MemOperand(a0, offsetof(Test, l)) ); // src __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.a, 1); CHECK_EQ(test.b, 0); CHECK_EQ(test.c, 0); CHECK_EQ(test.d, 1); const int test_size = 3; const int input_size = 5; double inputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double outputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float inputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float outputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.e = inputs_D[i]; test.f = tests_D[j]; test.i = inputs_S[i]; test.j = tests_S[j]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, outputs_D[i]); CHECK_EQ(test.h, 0); CHECK_EQ(test.k, outputs_S[i]); CHECK_EQ(test.l, 0); test.f = tests_D[j+1]; test.j = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, 0); CHECK_EQ(test.h, outputs_D[i]); CHECK_EQ(test.k, 0); CHECK_EQ(test.l, outputs_S[i]); } } } } TEST(min_max) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); struct TestFloat { double a; double b; double c; double d; float e; float f; float g; float h; }; TestFloat test; const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); const int kTableLength = 13; double inputsa[kTableLength] = {2.0, 3.0, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = {3.0, 2.0, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double outputsdmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double outputsdmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputse[kTableLength] = {2.0, 3.0, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsf[kTableLength] = {3.0, 2.0, 3.0, fnan, 0.0, -0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float outputsfmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float outputsfmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a))); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, b))); __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, e))); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, f))); __ min_d(f10, f4, f8); __ max_d(f12, f4, f8); __ min_s(f14, f2, f6); __ max_s(f16, f2, f6); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, c))); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, d))); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, g))); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, h))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 4; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.e = inputse[i]; test.f = inputsf[i]; CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0); CHECK_EQ(0, memcmp(&test.c, &outputsdmin[i], sizeof(test.c))); CHECK_EQ(0, memcmp(&test.d, &outputsdmax[i], sizeof(test.d))); CHECK_EQ(0, memcmp(&test.g, &outputsfmin[i], sizeof(test.g))); CHECK_EQ(0, memcmp(&test.h, &outputsfmax[i], sizeof(test.h))); } } } TEST(rint_d) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; int fcsr; }TestFloat; TestFloat test; double inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E+308, 6.27463370218383111104242366943E-307, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ ctc1(t0, FCSR); __ rint_d(f8, f4); __ sdc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(sel) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { double dd; double ds; double dt; float fd; float fs; float ft; } Test; Test test; __ ldc1(f0, MemOperand(a0, offsetof(Test, dd)) ); // test __ ldc1(f2, MemOperand(a0, offsetof(Test, ds)) ); // src1 __ ldc1(f4, MemOperand(a0, offsetof(Test, dt)) ); // src2 __ lwc1(f6, MemOperand(a0, offsetof(Test, fd)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, fs)) ); // src1 __ lwc1(f10, MemOperand(a0, offsetof(Test, ft)) ); // src2 __ sel_d(f0, f2, f4); __ sel_s(f6, f8, f10); __ sdc1(f0, MemOperand(a0, offsetof(Test, dd)) ); __ swc1(f6, MemOperand(a0, offsetof(Test, fd)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); const int test_size = 3; const int input_size = 5; double inputs_dt[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double inputs_ds[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; float inputs_ft[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float inputs_fs[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.dt = inputs_dt[i]; test.dd = tests_D[j]; test.ds = inputs_ds[i]; test.ft = inputs_ft[i]; test.fd = tests_S[j]; test.fs = inputs_fs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_ds[i]); CHECK_EQ(test.fd, inputs_fs[i]); test.dd = tests_D[j+1]; test.fd = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_dt[i]); CHECK_EQ(test.fd, inputs_ft[i]); } } } } TEST(rint_s) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; int fcsr; }TestFloat; TestFloat test; float inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E+38, 6.27463370218383111104242366943E-37, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; float* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ rint_s(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(mina_maxa) { if (kArchVariant == kMips64r6) { const int kTableLength = 23; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); struct TestFloat { double a; double b; double resd; double resd1; float c; float d; float resf; float resf1; }; TestFloat test; double inputsa[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = { 4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double resd[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double resd1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputsc[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsd[kTableLength] = {4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, fnan, -0.0, 0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float resf[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float resf1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ lwc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ lwc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ mina_d(f6, f2, f4); __ mina_s(f12, f8, f10); __ maxa_d(f14, f2, f4); __ maxa_s(f16, f8, f10); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, resf)) ); __ sdc1(f6, MemOperand(a0, offsetof(TestFloat, resd)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resf1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resd1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.c = inputsc[i]; test.d = inputsd[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if (i < kTableLength - 1) { CHECK_EQ(test.resd, resd[i]); CHECK_EQ(test.resf, resf[i]); CHECK_EQ(test.resd1, resd1[i]); CHECK_EQ(test.resf1, resf1[i]); } else { CHECK(std::isnan(test.resd)); CHECK(std::isnan(test.resf)); CHECK(std::isnan(test.resd1)); CHECK(std::isnan(test.resf1)); } } } } // ----------------------mips64r2 specific tests---------------------- TEST(trunc_l) { if (kArchVariant == kMips64r2) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; // a trunc result int64_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_l_d(f8, f4); __ trunc_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } } TEST(movz_movn) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { int64_t rt; double a; double b; double bold; double b1; double bold1; float c; float d; float dold; float d1; float dold1; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ld(t0, MemOperand(a0, offsetof(TestFloat, rt))); __ Move(f12, 0.0); __ Move(f10, 0.0); __ Move(f16, 0.0); __ Move(f14, 0.0); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, bold)) ); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, dold)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, bold1)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, dold1)) ); __ movz_s(f10, f6, t0); __ movz_d(f12, f2, t0); __ movn_s(f14, f6, t0); __ movn_d(f16, f2, t0); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, b)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, d1)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, b1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; test.rt = 1; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, test.bold); CHECK_EQ(test.d, test.dold); CHECK_EQ(test.b1, outputs_D[i]); CHECK_EQ(test.d1, outputs_S[i]); test.rt = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); CHECK_EQ(test.b1, test.bold1); CHECK_EQ(test.d1, test.dold1); } } } TEST(movt_movd) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); typedef struct test_float { double srcd; double dstd; double dstdold; double dstd1; double dstdold1; float srcf; float dstf; float dstfold; float dstf1; float dstfold1; int32_t cc; int32_t fcsr; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; double inputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; int condition_flags[8] = {0, 1, 2, 3, 4, 5, 6, 7}; for (int i = 0; i < kTableLength; i++) { test.srcd = inputs_D[i]; test.srcf = inputs_S[i]; for (int j = 0; j< 8; j++) { test.cc = condition_flags[j]; if (test.cc == 0) { test.fcsr = 1 << 23; } else { test.fcsr = 1 << (24+condition_flags[j]); } HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, srcd)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, srcf)) ); __ lw(t1, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t0, FCSR); __ ctc1(t1, FCSR); __ li(t2, 0x0); __ mtc1(t2, f12); __ mtc1(t2, f10); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold)) ); __ movt_s(f12, f4, test.cc); __ movt_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold1)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold1)) ); __ movf_s(f12, f4, test.cc); __ movf_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf1)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd1)) ); __ ctc1(t0, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, outputs_S[i]); CHECK_EQ(test.dstd, outputs_D[i]); CHECK_EQ(test.dstf1, test.dstfold1); CHECK_EQ(test.dstd1, test.dstdold1); test.fcsr = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, test.dstfold); CHECK_EQ(test.dstd, test.dstdold); CHECK_EQ(test.dstf1, outputs_S[i]); CHECK_EQ(test.dstd1, outputs_D[i]); } } } } // ----------------------tests for all archs-------------------------- TEST(cvt_w_d) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; int32_t b; int fcsr; }Test; const int kTableLength = 24; double inputs[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, 2147483653.0 }; double outputs_RN[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RZ[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RP[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RM[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lw(t0, MemOperand(a0, offsetof(Test, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ cvt_w_d(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(Test, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } TEST(trunc_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_w_d(f8, f4); __ trunc_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_w_d(f8, f4); __ round_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_l_d(f8, f4); __ round_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(sub) { const int kTableLength = 12; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; double inputft_D[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; double outputs_D[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; float inputfs_S[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; float inputft_S[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; float outputs_S[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sub_s(f6, f2, f4); __ sub_d(f12, f8, f10); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(sqrt_rsqrt_recip) { const int kTableLength = 4; const double deltaDouble = 2E-15; const float deltaFloat = 2E-7; const float sqrt2_s = sqrt(2); const double sqrt2_d = sqrt(2); CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; float resultS1; float resultS2; double c; double resultD; double resultD1; double resultD2; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 0.0L, 4.0L, 2.0L, 4e-28L }; double outputs_D[kTableLength] = { 0.0L, 2.0L, sqrt2_d, 2e-14L }; float inputs_S[kTableLength] = { 0.0, 4.0, 2.0, 4e-28 }; float outputs_S[kTableLength] = { 0.0, 2.0, sqrt2_s, 2e-14 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ sqrt_s(f6, f2); __ sqrt_d(f12, f8); __ rsqrt_d(f14, f8); __ rsqrt_s(f16, f2); __ recip_d(f18, f8); __ recip_s(f4, f2); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resultS1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resultD1)) ); __ swc1(f4, MemOperand(a0, offsetof(TestFloat, resultS2)) ); __ sdc1(f18, MemOperand(a0, offsetof(TestFloat, resultD2)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { float f1; double d1; test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); if (i != 0) { f1 = test.resultS1 - 1.0F/outputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD1 - 1.0L/outputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); f1 = test.resultS2 - 1.0F/inputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD2 - 1.0L/inputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); } else { CHECK_EQ(test.resultS1, 1.0F/outputs_S[i]); CHECK_EQ(test.resultD1, 1.0L/outputs_D[i]); CHECK_EQ(test.resultS2, 1.0F/inputs_S[i]); CHECK_EQ(test.resultD2, 1.0L/inputs_D[i]); } } } TEST(neg) { const int kTableLength = 2; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; double c; double resultD; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 4.0, -2.0 }; double outputs_D[kTableLength] = { -4.0, 2.0 }; float inputs_S[kTableLength] = { 4.0, -2.0 }; float outputs_S[kTableLength] = { -4.0, 2.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ neg_s(f6, f2); __ neg_d(f12, f8); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
()); F3 f = FUNCTION_CAST(code->entry()); t.x = 1; t.y = 2; t.y1 = 3; t.y2 = 4; t.y3 = 0XBABA; t.y4 = 0xDEDA; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(3, t.y1); } TEST(MIPS13) { // Test Cvt_d_uw and Trunc_uw_d macros. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); typedef struct { double cvt_big_out; double cvt_small_out; uint32_t trunc_big_out; uint32_t trunc_small_out; uint32_t cvt_big_in; uint32_t cvt_small_in; } T; T t; MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ sw(a4, MemOperand(a0, offsetof(T, cvt_small_in))); __ Cvt_d_uw(f10, a4); __ sdc1(f10, MemOperand(a0, offsetof(T, cvt_small_out))); __ Trunc_uw_d(f10, f10, f4); __ swc1(f10, MemOperand(a0, offsetof(T, trunc_small_out))); __ sw(a4, MemOperand(a0, offsetof(T, cvt_big_in))); __ Cvt_d_uw(f8, a4); __ sdc1(f8, MemOperand(a0, offsetof(T, cvt_big_out))); __ Trunc_uw_d(f8, f8, f4); __ swc1(f8, MemOperand(a0, offsetof(T, trunc_big_out))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.cvt_big_in = 0xFFFFFFFF; t.cvt_small_in = 333; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(t.cvt_big_out, static_cast(t.cvt_big_in)); CHECK_EQ(t.cvt_small_out, static_cast(t.cvt_small_in)); CHECK_EQ(static_cast(t.trunc_big_out), static_cast(t.cvt_big_in)); CHECK_EQ(static_cast(t.trunc_small_out), static_cast(t.cvt_small_in)); } TEST(MIPS14) { // Test round, floor, ceil, trunc, cvt. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); #define ROUND_STRUCT_ELEMENT(x) \ uint32_t x##_isNaN2008; \ int32_t x##_up_out; \ int32_t x##_down_out; \ int32_t neg_##x##_up_out; \ int32_t neg_##x##_down_out; \ uint32_t x##_err1_out; \ uint32_t x##_err2_out; \ uint32_t x##_err3_out; \ uint32_t x##_err4_out; \ int32_t x##_invalid_result; typedef struct { double round_up_in; double round_down_in; double neg_round_up_in; double neg_round_down_in; double err1_in; double err2_in; double err3_in; double err4_in; ROUND_STRUCT_ELEMENT(round) ROUND_STRUCT_ELEMENT(floor) ROUND_STRUCT_ELEMENT(ceil) ROUND_STRUCT_ELEMENT(trunc) ROUND_STRUCT_ELEMENT(cvt) } T; T t; #undef ROUND_STRUCT_ELEMENT MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); // Save FCSR. __ cfc1(a1, FCSR); // Disable FPU exceptions. __ ctc1(zero_reg, FCSR); #define RUN_ROUND_TEST(x) \ __ cfc1(t0, FCSR);\ __ sw(t0, MemOperand(a0, offsetof(T, x##_isNaN2008))); \ __ ldc1(f0, MemOperand(a0, offsetof(T, round_up_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_up_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, round_down_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_down_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, neg_round_up_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, neg_##x##_up_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, neg_round_down_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, neg_##x##_down_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err1_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err1_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err2_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err2_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err3_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err3_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err4_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err4_out))); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_invalid_result))); RUN_ROUND_TEST(round) RUN_ROUND_TEST(floor) RUN_ROUND_TEST(ceil) RUN_ROUND_TEST(trunc) RUN_ROUND_TEST(cvt) // Restore FCSR. __ ctc1(a1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.round_up_in = 123.51; t.round_down_in = 123.49; t.neg_round_up_in = -123.5; t.neg_round_down_in = -123.49; t.err1_in = 123.51; t.err2_in = 1; t.err3_in = static_cast(1) + 0xFFFFFFFF; t.err4_in = NAN; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); #define GET_FPU_ERR(x) (static_cast(x & kFCSRFlagMask)) #define CHECK_NAN2008(x) (x & kFCSRNaN2008FlagMask) #define CHECK_ROUND_RESULT(type) \ CHECK(GET_FPU_ERR(t.type##_err1_out) & kFCSRInexactFlagMask); \ CHECK_EQ(0, GET_FPU_ERR(t.type##_err2_out)); \ CHECK(GET_FPU_ERR(t.type##_err3_out) & kFCSRInvalidOpFlagMask); \ CHECK(GET_FPU_ERR(t.type##_err4_out) & kFCSRInvalidOpFlagMask); \ if (CHECK_NAN2008(t.type##_isNaN2008) && kArchVariant == kMips64r6) { \ CHECK_EQ(static_cast(0), t.type##_invalid_result);\ } else { \ CHECK_EQ(static_cast(kFPUInvalidResult), t.type##_invalid_result);\ } CHECK_ROUND_RESULT(round); CHECK_ROUND_RESULT(floor); CHECK_ROUND_RESULT(ceil); CHECK_ROUND_RESULT(cvt); } TEST(MIPS15) { // Test chaining of label usages within instructions (issue 1644). CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); Assembler assm(isolate, NULL, 0); Label target; __ beq(v0, v1, &target); __ nop(); __ bne(v0, v1, &target); __ nop(); __ bind(&target); __ nop(); } // ----- mips64 tests ----------------------------------------------- TEST(MIPS16) { // Test 64-bit memory loads and stores. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); struct T { int64_t r1; int64_t r2; int64_t r3; int64_t r4; int64_t r5; int64_t r6; int64_t r7; int64_t r8; int64_t r9; int64_t r10; int64_t r11; int64_t r12; uint32_t ui; int32_t si; }; T t; Assembler assm(isolate, NULL, 0); Label L, C; // Basic 32-bit word load/store, with un-signed data. __ lw(a4, MemOperand(a0, offsetof(T, ui))); __ sw(a4, MemOperand(a0, offsetof(T, r1))); // Check that the data got zero-extended into 64-bit a4. __ sd(a4, MemOperand(a0, offsetof(T, r2))); // Basic 32-bit word load/store, with SIGNED data. __ lw(a5, MemOperand(a0, offsetof(T, si))); __ sw(a5, MemOperand(a0, offsetof(T, r3))); // Check that the data got sign-extended into 64-bit a4. __ sd(a5, MemOperand(a0, offsetof(T, r4))); // 32-bit UNSIGNED word load/store, with SIGNED data. __ lwu(a6, MemOperand(a0, offsetof(T, si))); __ sw(a6, MemOperand(a0, offsetof(T, r5))); // Check that the data got zero-extended into 64-bit a4. __ sd(a6, MemOperand(a0, offsetof(T, r6))); // lh with positive data. __ lh(a5, MemOperand(a0, offsetof(T, ui))); __ sw(a5, MemOperand(a0, offsetof(T, r7))); // lh with negative data. __ lh(a6, MemOperand(a0, offsetof(T, si))); __ sw(a6, MemOperand(a0, offsetof(T, r8))); // lhu with negative data. __ lhu(a7, MemOperand(a0, offsetof(T, si))); __ sw(a7, MemOperand(a0, offsetof(T, r9))); // lb with negative data. __ lb(t0, MemOperand(a0, offsetof(T, si))); __ sw(t0, MemOperand(a0, offsetof(T, r10))); // sh writes only 1/2 of word. __ lw(a4, MemOperand(a0, offsetof(T, ui))); __ sh(a4, MemOperand(a0, offsetof(T, r11))); __ lw(a4, MemOperand(a0, offsetof(T, si))); __ sh(a4, MemOperand(a0, offsetof(T, r12))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.ui = 0x44332211; t.si = 0x99aabbcc; t.r1 = 0x5555555555555555; t.r2 = 0x5555555555555555; t.r3 = 0x5555555555555555; t.r4 = 0x5555555555555555; t.r5 = 0x5555555555555555; t.r6 = 0x5555555555555555; t.r7 = 0x5555555555555555; t.r8 = 0x5555555555555555; t.r9 = 0x5555555555555555; t.r10 = 0x5555555555555555; t.r11 = 0x5555555555555555; t.r12 = 0x5555555555555555; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); if (kArchEndian == kLittle) { // Unsigned data, 32 & 64 CHECK_EQ(static_cast(0x5555555544332211L), t.r1); // lw, sw. CHECK_EQ(static_cast(0x0000000044332211L), t.r2); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x5555555599aabbccL), t.r3); // lw, sw. CHECK_EQ(static_cast(0xffffffff99aabbccL), t.r4); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x5555555599aabbccL), t.r5); // lwu, sw. CHECK_EQ(static_cast(0x0000000099aabbccL), t.r6); // sd. // lh with unsigned and signed data. CHECK_EQ(static_cast(0x5555555500002211L), t.r7); // lh, sw. CHECK_EQ(static_cast(0x55555555ffffbbccL), t.r8); // lh, sw. // lhu with signed data. CHECK_EQ(static_cast(0x555555550000bbccL), t.r9); // lhu, sw. // lb with signed data. CHECK_EQ(static_cast(0x55555555ffffffccL), t.r10); // lb, sw. // sh with unsigned and signed data. CHECK_EQ(static_cast(0x5555555555552211L), t.r11); // lw, sh. CHECK_EQ(static_cast(0x555555555555bbccL), t.r12); // lw, sh. } else { // Unsigned data, 32 & 64 CHECK_EQ(static_cast(0x4433221155555555L), t.r1); // lw, sw. CHECK_EQ(static_cast(0x0000000044332211L), t.r2); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x99aabbcc55555555L), t.r3); // lw, sw. CHECK_EQ(static_cast(0xffffffff99aabbccL), t.r4); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x99aabbcc55555555L), t.r5); // lwu, sw. CHECK_EQ(static_cast(0x0000000099aabbccL), t.r6); // sd. // lh with unsigned and signed data. CHECK_EQ(static_cast(0x0000443355555555L), t.r7); // lh, sw. CHECK_EQ(static_cast(0xffff99aa55555555L), t.r8); // lh, sw. // lhu with signed data. CHECK_EQ(static_cast(0x000099aa55555555L), t.r9); // lhu, sw. // lb with signed data. CHECK_EQ(static_cast(0xffffff9955555555L), t.r10); // lb, sw. // sh with unsigned and signed data. CHECK_EQ(static_cast(0x2211555555555555L), t.r11); // lw, sh. CHECK_EQ(static_cast(0xbbcc555555555555L), t.r12); // lw, sh. } } // ----------------------mips64r6 specific tests---------------------- TEST(seleqz_selnez) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { int a; int b; int c; int d; double e; double f; double g; double h; float i; float j; float k; float l; } Test; Test test; // Integer part of test. __ addiu(t1, zero_reg, 1); // t1 = 1 __ seleqz(t3, t1, zero_reg); // t3 = 1 __ sw(t3, MemOperand(a0, offsetof(Test, a))); // a = 1 __ seleqz(t2, t1, t1); // t2 = 0 __ sw(t2, MemOperand(a0, offsetof(Test, b))); // b = 0 __ selnez(t3, t1, zero_reg); // t3 = 1; __ sw(t3, MemOperand(a0, offsetof(Test, c))); // c = 0 __ selnez(t3, t1, t1); // t3 = 1 __ sw(t3, MemOperand(a0, offsetof(Test, d))); // d = 1 // Floating point part of test. __ ldc1(f0, MemOperand(a0, offsetof(Test, e)) ); // src __ ldc1(f2, MemOperand(a0, offsetof(Test, f)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, i)) ); // src __ lwc1(f10, MemOperand(a0, offsetof(Test, j)) ); // test __ seleqz_d(f4, f0, f2); __ selnez_d(f6, f0, f2); __ seleqz_s(f12, f8, f10); __ selnez_s(f14, f8, f10); __ sdc1(f4, MemOperand(a0, offsetof(Test, g)) ); // src __ sdc1(f6, MemOperand(a0, offsetof(Test, h)) ); // src __ swc1(f12, MemOperand(a0, offsetof(Test, k)) ); // src __ swc1(f14, MemOperand(a0, offsetof(Test, l)) ); // src __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.a, 1); CHECK_EQ(test.b, 0); CHECK_EQ(test.c, 0); CHECK_EQ(test.d, 1); const int test_size = 3; const int input_size = 5; double inputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double outputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float inputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float outputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.e = inputs_D[i]; test.f = tests_D[j]; test.i = inputs_S[i]; test.j = tests_S[j]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, outputs_D[i]); CHECK_EQ(test.h, 0); CHECK_EQ(test.k, outputs_S[i]); CHECK_EQ(test.l, 0); test.f = tests_D[j+1]; test.j = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, 0); CHECK_EQ(test.h, outputs_D[i]); CHECK_EQ(test.k, 0); CHECK_EQ(test.l, outputs_S[i]); } } } } TEST(min_max) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); struct TestFloat { double a; double b; double c; double d; float e; float f; float g; float h; }; TestFloat test; const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); const int kTableLength = 13; double inputsa[kTableLength] = {2.0, 3.0, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = {3.0, 2.0, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double outputsdmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double outputsdmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputse[kTableLength] = {2.0, 3.0, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsf[kTableLength] = {3.0, 2.0, 3.0, fnan, 0.0, -0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float outputsfmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float outputsfmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a))); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, b))); __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, e))); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, f))); __ min_d(f10, f4, f8); __ max_d(f12, f4, f8); __ min_s(f14, f2, f6); __ max_s(f16, f2, f6); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, c))); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, d))); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, g))); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, h))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 4; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.e = inputse[i]; test.f = inputsf[i]; CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0); CHECK_EQ(0, memcmp(&test.c, &outputsdmin[i], sizeof(test.c))); CHECK_EQ(0, memcmp(&test.d, &outputsdmax[i], sizeof(test.d))); CHECK_EQ(0, memcmp(&test.g, &outputsfmin[i], sizeof(test.g))); CHECK_EQ(0, memcmp(&test.h, &outputsfmax[i], sizeof(test.h))); } } } TEST(rint_d) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; int fcsr; }TestFloat; TestFloat test; double inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E+308, 6.27463370218383111104242366943E-307, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ ctc1(t0, FCSR); __ rint_d(f8, f4); __ sdc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(sel) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { double dd; double ds; double dt; float fd; float fs; float ft; } Test; Test test; __ ldc1(f0, MemOperand(a0, offsetof(Test, dd)) ); // test __ ldc1(f2, MemOperand(a0, offsetof(Test, ds)) ); // src1 __ ldc1(f4, MemOperand(a0, offsetof(Test, dt)) ); // src2 __ lwc1(f6, MemOperand(a0, offsetof(Test, fd)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, fs)) ); // src1 __ lwc1(f10, MemOperand(a0, offsetof(Test, ft)) ); // src2 __ sel_d(f0, f2, f4); __ sel_s(f6, f8, f10); __ sdc1(f0, MemOperand(a0, offsetof(Test, dd)) ); __ swc1(f6, MemOperand(a0, offsetof(Test, fd)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); const int test_size = 3; const int input_size = 5; double inputs_dt[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double inputs_ds[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; float inputs_ft[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float inputs_fs[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.dt = inputs_dt[i]; test.dd = tests_D[j]; test.ds = inputs_ds[i]; test.ft = inputs_ft[i]; test.fd = tests_S[j]; test.fs = inputs_fs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_ds[i]); CHECK_EQ(test.fd, inputs_fs[i]); test.dd = tests_D[j+1]; test.fd = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_dt[i]); CHECK_EQ(test.fd, inputs_ft[i]); } } } } TEST(rint_s) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; int fcsr; }TestFloat; TestFloat test; float inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E+38, 6.27463370218383111104242366943E-37, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; float* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ rint_s(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(mina_maxa) { if (kArchVariant == kMips64r6) { const int kTableLength = 23; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); struct TestFloat { double a; double b; double resd; double resd1; float c; float d; float resf; float resf1; }; TestFloat test; double inputsa[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = { 4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double resd[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double resd1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputsc[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsd[kTableLength] = {4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, fnan, -0.0, 0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float resf[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float resf1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ lwc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ lwc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ mina_d(f6, f2, f4); __ mina_s(f12, f8, f10); __ maxa_d(f14, f2, f4); __ maxa_s(f16, f8, f10); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, resf)) ); __ sdc1(f6, MemOperand(a0, offsetof(TestFloat, resd)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resf1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resd1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.c = inputsc[i]; test.d = inputsd[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if (i < kTableLength - 1) { CHECK_EQ(test.resd, resd[i]); CHECK_EQ(test.resf, resf[i]); CHECK_EQ(test.resd1, resd1[i]); CHECK_EQ(test.resf1, resf1[i]); } else { CHECK(std::isnan(test.resd)); CHECK(std::isnan(test.resf)); CHECK(std::isnan(test.resd1)); CHECK(std::isnan(test.resf1)); } } } } // ----------------------mips64r2 specific tests---------------------- TEST(trunc_l) { if (kArchVariant == kMips64r2) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; // a trunc result int64_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_l_d(f8, f4); __ trunc_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } } TEST(movz_movn) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { int64_t rt; double a; double b; double bold; double b1; double bold1; float c; float d; float dold; float d1; float dold1; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ld(t0, MemOperand(a0, offsetof(TestFloat, rt))); __ Move(f12, 0.0); __ Move(f10, 0.0); __ Move(f16, 0.0); __ Move(f14, 0.0); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, bold)) ); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, dold)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, bold1)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, dold1)) ); __ movz_s(f10, f6, t0); __ movz_d(f12, f2, t0); __ movn_s(f14, f6, t0); __ movn_d(f16, f2, t0); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, b)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, d1)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, b1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; test.rt = 1; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, test.bold); CHECK_EQ(test.d, test.dold); CHECK_EQ(test.b1, outputs_D[i]); CHECK_EQ(test.d1, outputs_S[i]); test.rt = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); CHECK_EQ(test.b1, test.bold1); CHECK_EQ(test.d1, test.dold1); } } } TEST(movt_movd) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); typedef struct test_float { double srcd; double dstd; double dstdold; double dstd1; double dstdold1; float srcf; float dstf; float dstfold; float dstf1; float dstfold1; int32_t cc; int32_t fcsr; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; double inputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; int condition_flags[8] = {0, 1, 2, 3, 4, 5, 6, 7}; for (int i = 0; i < kTableLength; i++) { test.srcd = inputs_D[i]; test.srcf = inputs_S[i]; for (int j = 0; j< 8; j++) { test.cc = condition_flags[j]; if (test.cc == 0) { test.fcsr = 1 << 23; } else { test.fcsr = 1 << (24+condition_flags[j]); } HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, srcd)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, srcf)) ); __ lw(t1, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t0, FCSR); __ ctc1(t1, FCSR); __ li(t2, 0x0); __ mtc1(t2, f12); __ mtc1(t2, f10); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold)) ); __ movt_s(f12, f4, test.cc); __ movt_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold1)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold1)) ); __ movf_s(f12, f4, test.cc); __ movf_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf1)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd1)) ); __ ctc1(t0, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, outputs_S[i]); CHECK_EQ(test.dstd, outputs_D[i]); CHECK_EQ(test.dstf1, test.dstfold1); CHECK_EQ(test.dstd1, test.dstdold1); test.fcsr = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, test.dstfold); CHECK_EQ(test.dstd, test.dstdold); CHECK_EQ(test.dstf1, outputs_S[i]); CHECK_EQ(test.dstd1, outputs_D[i]); } } } } // ----------------------tests for all archs-------------------------- TEST(cvt_w_d) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; int32_t b; int fcsr; }Test; const int kTableLength = 24; double inputs[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, 2147483653.0 }; double outputs_RN[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RZ[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RP[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RM[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lw(t0, MemOperand(a0, offsetof(Test, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ cvt_w_d(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(Test, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } TEST(trunc_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_w_d(f8, f4); __ trunc_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_w_d(f8, f4); __ round_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_l_d(f8, f4); __ round_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(sub) { const int kTableLength = 12; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; double inputft_D[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; double outputs_D[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; float inputfs_S[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; float inputft_S[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; float outputs_S[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sub_s(f6, f2, f4); __ sub_d(f12, f8, f10); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(sqrt_rsqrt_recip) { const int kTableLength = 4; const double deltaDouble = 2E-15; const float deltaFloat = 2E-7; const float sqrt2_s = sqrt(2); const double sqrt2_d = sqrt(2); CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; float resultS1; float resultS2; double c; double resultD; double resultD1; double resultD2; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 0.0L, 4.0L, 2.0L, 4e-28L }; double outputs_D[kTableLength] = { 0.0L, 2.0L, sqrt2_d, 2e-14L }; float inputs_S[kTableLength] = { 0.0, 4.0, 2.0, 4e-28 }; float outputs_S[kTableLength] = { 0.0, 2.0, sqrt2_s, 2e-14 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ sqrt_s(f6, f2); __ sqrt_d(f12, f8); __ rsqrt_d(f14, f8); __ rsqrt_s(f16, f2); __ recip_d(f18, f8); __ recip_s(f4, f2); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resultS1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resultD1)) ); __ swc1(f4, MemOperand(a0, offsetof(TestFloat, resultS2)) ); __ sdc1(f18, MemOperand(a0, offsetof(TestFloat, resultD2)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { float f1; double d1; test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); if (i != 0) { f1 = test.resultS1 - 1.0F/outputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD1 - 1.0L/outputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); f1 = test.resultS2 - 1.0F/inputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD2 - 1.0L/inputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); } else { CHECK_EQ(test.resultS1, 1.0F/outputs_S[i]); CHECK_EQ(test.resultD1, 1.0L/outputs_D[i]); CHECK_EQ(test.resultS2, 1.0F/inputs_S[i]); CHECK_EQ(test.resultD2, 1.0L/inputs_D[i]); } } } TEST(neg) { const int kTableLength = 2; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; double c; double resultD; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 4.0, -2.0 }; double outputs_D[kTableLength] = { -4.0, 2.0 }; float inputs_S[kTableLength] = { 4.0, -2.0 }; float outputs_S[kTableLength] = { -4.0, 2.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ neg_s(f6, f2); __ neg_d(f12, f8); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.cvt_big_in = 0xFFFFFFFF; t.cvt_small_in = 333; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(t.cvt_big_out, static_cast(t.cvt_big_in)); CHECK_EQ(t.cvt_small_out, static_cast(t.cvt_small_in)); CHECK_EQ(static_cast(t.trunc_big_out), static_cast(t.cvt_big_in)); CHECK_EQ(static_cast(t.trunc_small_out), static_cast(t.cvt_small_in)); } TEST(MIPS14) { // Test round, floor, ceil, trunc, cvt. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); #define ROUND_STRUCT_ELEMENT(x) \ uint32_t x##_isNaN2008; \ int32_t x##_up_out; \ int32_t x##_down_out; \ int32_t neg_##x##_up_out; \ int32_t neg_##x##_down_out; \ uint32_t x##_err1_out; \ uint32_t x##_err2_out; \ uint32_t x##_err3_out; \ uint32_t x##_err4_out; \ int32_t x##_invalid_result; typedef struct { double round_up_in; double round_down_in; double neg_round_up_in; double neg_round_down_in; double err1_in; double err2_in; double err3_in; double err4_in; ROUND_STRUCT_ELEMENT(round) ROUND_STRUCT_ELEMENT(floor) ROUND_STRUCT_ELEMENT(ceil) ROUND_STRUCT_ELEMENT(trunc) ROUND_STRUCT_ELEMENT(cvt) } T; T t; #undef ROUND_STRUCT_ELEMENT MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); // Save FCSR. __ cfc1(a1, FCSR); // Disable FPU exceptions. __ ctc1(zero_reg, FCSR); #define RUN_ROUND_TEST(x) \ __ cfc1(t0, FCSR);\ __ sw(t0, MemOperand(a0, offsetof(T, x##_isNaN2008))); \ __ ldc1(f0, MemOperand(a0, offsetof(T, round_up_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_up_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, round_down_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_down_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, neg_round_up_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, neg_##x##_up_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, neg_round_down_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, neg_##x##_down_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err1_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err1_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err2_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err2_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err3_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err3_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err4_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err4_out))); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_invalid_result))); RUN_ROUND_TEST(round) RUN_ROUND_TEST(floor) RUN_ROUND_TEST(ceil) RUN_ROUND_TEST(trunc) RUN_ROUND_TEST(cvt) // Restore FCSR. __ ctc1(a1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.round_up_in = 123.51; t.round_down_in = 123.49; t.neg_round_up_in = -123.5; t.neg_round_down_in = -123.49; t.err1_in = 123.51; t.err2_in = 1; t.err3_in = static_cast(1) + 0xFFFFFFFF; t.err4_in = NAN; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); #define GET_FPU_ERR(x) (static_cast(x & kFCSRFlagMask)) #define CHECK_NAN2008(x) (x & kFCSRNaN2008FlagMask) #define CHECK_ROUND_RESULT(type) \ CHECK(GET_FPU_ERR(t.type##_err1_out) & kFCSRInexactFlagMask); \ CHECK_EQ(0, GET_FPU_ERR(t.type##_err2_out)); \ CHECK(GET_FPU_ERR(t.type##_err3_out) & kFCSRInvalidOpFlagMask); \ CHECK(GET_FPU_ERR(t.type##_err4_out) & kFCSRInvalidOpFlagMask); \ if (CHECK_NAN2008(t.type##_isNaN2008) && kArchVariant == kMips64r6) { \ CHECK_EQ(static_cast(0), t.type##_invalid_result);\ } else { \ CHECK_EQ(static_cast(kFPUInvalidResult), t.type##_invalid_result);\ } CHECK_ROUND_RESULT(round); CHECK_ROUND_RESULT(floor); CHECK_ROUND_RESULT(ceil); CHECK_ROUND_RESULT(cvt); } TEST(MIPS15) { // Test chaining of label usages within instructions (issue 1644). CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); Assembler assm(isolate, NULL, 0); Label target; __ beq(v0, v1, &target); __ nop(); __ bne(v0, v1, &target); __ nop(); __ bind(&target); __ nop(); } // ----- mips64 tests ----------------------------------------------- TEST(MIPS16) { // Test 64-bit memory loads and stores. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); struct T { int64_t r1; int64_t r2; int64_t r3; int64_t r4; int64_t r5; int64_t r6; int64_t r7; int64_t r8; int64_t r9; int64_t r10; int64_t r11; int64_t r12; uint32_t ui; int32_t si; }; T t; Assembler assm(isolate, NULL, 0); Label L, C; // Basic 32-bit word load/store, with un-signed data. __ lw(a4, MemOperand(a0, offsetof(T, ui))); __ sw(a4, MemOperand(a0, offsetof(T, r1))); // Check that the data got zero-extended into 64-bit a4. __ sd(a4, MemOperand(a0, offsetof(T, r2))); // Basic 32-bit word load/store, with SIGNED data. __ lw(a5, MemOperand(a0, offsetof(T, si))); __ sw(a5, MemOperand(a0, offsetof(T, r3))); // Check that the data got sign-extended into 64-bit a4. __ sd(a5, MemOperand(a0, offsetof(T, r4))); // 32-bit UNSIGNED word load/store, with SIGNED data. __ lwu(a6, MemOperand(a0, offsetof(T, si))); __ sw(a6, MemOperand(a0, offsetof(T, r5))); // Check that the data got zero-extended into 64-bit a4. __ sd(a6, MemOperand(a0, offsetof(T, r6))); // lh with positive data. __ lh(a5, MemOperand(a0, offsetof(T, ui))); __ sw(a5, MemOperand(a0, offsetof(T, r7))); // lh with negative data. __ lh(a6, MemOperand(a0, offsetof(T, si))); __ sw(a6, MemOperand(a0, offsetof(T, r8))); // lhu with negative data. __ lhu(a7, MemOperand(a0, offsetof(T, si))); __ sw(a7, MemOperand(a0, offsetof(T, r9))); // lb with negative data. __ lb(t0, MemOperand(a0, offsetof(T, si))); __ sw(t0, MemOperand(a0, offsetof(T, r10))); // sh writes only 1/2 of word. __ lw(a4, MemOperand(a0, offsetof(T, ui))); __ sh(a4, MemOperand(a0, offsetof(T, r11))); __ lw(a4, MemOperand(a0, offsetof(T, si))); __ sh(a4, MemOperand(a0, offsetof(T, r12))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.ui = 0x44332211; t.si = 0x99aabbcc; t.r1 = 0x5555555555555555; t.r2 = 0x5555555555555555; t.r3 = 0x5555555555555555; t.r4 = 0x5555555555555555; t.r5 = 0x5555555555555555; t.r6 = 0x5555555555555555; t.r7 = 0x5555555555555555; t.r8 = 0x5555555555555555; t.r9 = 0x5555555555555555; t.r10 = 0x5555555555555555; t.r11 = 0x5555555555555555; t.r12 = 0x5555555555555555; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); if (kArchEndian == kLittle) { // Unsigned data, 32 & 64 CHECK_EQ(static_cast(0x5555555544332211L), t.r1); // lw, sw. CHECK_EQ(static_cast(0x0000000044332211L), t.r2); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x5555555599aabbccL), t.r3); // lw, sw. CHECK_EQ(static_cast(0xffffffff99aabbccL), t.r4); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x5555555599aabbccL), t.r5); // lwu, sw. CHECK_EQ(static_cast(0x0000000099aabbccL), t.r6); // sd. // lh with unsigned and signed data. CHECK_EQ(static_cast(0x5555555500002211L), t.r7); // lh, sw. CHECK_EQ(static_cast(0x55555555ffffbbccL), t.r8); // lh, sw. // lhu with signed data. CHECK_EQ(static_cast(0x555555550000bbccL), t.r9); // lhu, sw. // lb with signed data. CHECK_EQ(static_cast(0x55555555ffffffccL), t.r10); // lb, sw. // sh with unsigned and signed data. CHECK_EQ(static_cast(0x5555555555552211L), t.r11); // lw, sh. CHECK_EQ(static_cast(0x555555555555bbccL), t.r12); // lw, sh. } else { // Unsigned data, 32 & 64 CHECK_EQ(static_cast(0x4433221155555555L), t.r1); // lw, sw. CHECK_EQ(static_cast(0x0000000044332211L), t.r2); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x99aabbcc55555555L), t.r3); // lw, sw. CHECK_EQ(static_cast(0xffffffff99aabbccL), t.r4); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x99aabbcc55555555L), t.r5); // lwu, sw. CHECK_EQ(static_cast(0x0000000099aabbccL), t.r6); // sd. // lh with unsigned and signed data. CHECK_EQ(static_cast(0x0000443355555555L), t.r7); // lh, sw. CHECK_EQ(static_cast(0xffff99aa55555555L), t.r8); // lh, sw. // lhu with signed data. CHECK_EQ(static_cast(0x000099aa55555555L), t.r9); // lhu, sw. // lb with signed data. CHECK_EQ(static_cast(0xffffff9955555555L), t.r10); // lb, sw. // sh with unsigned and signed data. CHECK_EQ(static_cast(0x2211555555555555L), t.r11); // lw, sh. CHECK_EQ(static_cast(0xbbcc555555555555L), t.r12); // lw, sh. } } // ----------------------mips64r6 specific tests---------------------- TEST(seleqz_selnez) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { int a; int b; int c; int d; double e; double f; double g; double h; float i; float j; float k; float l; } Test; Test test; // Integer part of test. __ addiu(t1, zero_reg, 1); // t1 = 1 __ seleqz(t3, t1, zero_reg); // t3 = 1 __ sw(t3, MemOperand(a0, offsetof(Test, a))); // a = 1 __ seleqz(t2, t1, t1); // t2 = 0 __ sw(t2, MemOperand(a0, offsetof(Test, b))); // b = 0 __ selnez(t3, t1, zero_reg); // t3 = 1; __ sw(t3, MemOperand(a0, offsetof(Test, c))); // c = 0 __ selnez(t3, t1, t1); // t3 = 1 __ sw(t3, MemOperand(a0, offsetof(Test, d))); // d = 1 // Floating point part of test. __ ldc1(f0, MemOperand(a0, offsetof(Test, e)) ); // src __ ldc1(f2, MemOperand(a0, offsetof(Test, f)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, i)) ); // src __ lwc1(f10, MemOperand(a0, offsetof(Test, j)) ); // test __ seleqz_d(f4, f0, f2); __ selnez_d(f6, f0, f2); __ seleqz_s(f12, f8, f10); __ selnez_s(f14, f8, f10); __ sdc1(f4, MemOperand(a0, offsetof(Test, g)) ); // src __ sdc1(f6, MemOperand(a0, offsetof(Test, h)) ); // src __ swc1(f12, MemOperand(a0, offsetof(Test, k)) ); // src __ swc1(f14, MemOperand(a0, offsetof(Test, l)) ); // src __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.a, 1); CHECK_EQ(test.b, 0); CHECK_EQ(test.c, 0); CHECK_EQ(test.d, 1); const int test_size = 3; const int input_size = 5; double inputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double outputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float inputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float outputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.e = inputs_D[i]; test.f = tests_D[j]; test.i = inputs_S[i]; test.j = tests_S[j]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, outputs_D[i]); CHECK_EQ(test.h, 0); CHECK_EQ(test.k, outputs_S[i]); CHECK_EQ(test.l, 0); test.f = tests_D[j+1]; test.j = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, 0); CHECK_EQ(test.h, outputs_D[i]); CHECK_EQ(test.k, 0); CHECK_EQ(test.l, outputs_S[i]); } } } } TEST(min_max) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); struct TestFloat { double a; double b; double c; double d; float e; float f; float g; float h; }; TestFloat test; const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); const int kTableLength = 13; double inputsa[kTableLength] = {2.0, 3.0, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = {3.0, 2.0, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double outputsdmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double outputsdmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputse[kTableLength] = {2.0, 3.0, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsf[kTableLength] = {3.0, 2.0, 3.0, fnan, 0.0, -0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float outputsfmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float outputsfmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a))); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, b))); __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, e))); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, f))); __ min_d(f10, f4, f8); __ max_d(f12, f4, f8); __ min_s(f14, f2, f6); __ max_s(f16, f2, f6); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, c))); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, d))); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, g))); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, h))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 4; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.e = inputse[i]; test.f = inputsf[i]; CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0); CHECK_EQ(0, memcmp(&test.c, &outputsdmin[i], sizeof(test.c))); CHECK_EQ(0, memcmp(&test.d, &outputsdmax[i], sizeof(test.d))); CHECK_EQ(0, memcmp(&test.g, &outputsfmin[i], sizeof(test.g))); CHECK_EQ(0, memcmp(&test.h, &outputsfmax[i], sizeof(test.h))); } } } TEST(rint_d) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; int fcsr; }TestFloat; TestFloat test; double inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E+308, 6.27463370218383111104242366943E-307, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ ctc1(t0, FCSR); __ rint_d(f8, f4); __ sdc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(sel) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { double dd; double ds; double dt; float fd; float fs; float ft; } Test; Test test; __ ldc1(f0, MemOperand(a0, offsetof(Test, dd)) ); // test __ ldc1(f2, MemOperand(a0, offsetof(Test, ds)) ); // src1 __ ldc1(f4, MemOperand(a0, offsetof(Test, dt)) ); // src2 __ lwc1(f6, MemOperand(a0, offsetof(Test, fd)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, fs)) ); // src1 __ lwc1(f10, MemOperand(a0, offsetof(Test, ft)) ); // src2 __ sel_d(f0, f2, f4); __ sel_s(f6, f8, f10); __ sdc1(f0, MemOperand(a0, offsetof(Test, dd)) ); __ swc1(f6, MemOperand(a0, offsetof(Test, fd)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); const int test_size = 3; const int input_size = 5; double inputs_dt[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double inputs_ds[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; float inputs_ft[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float inputs_fs[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.dt = inputs_dt[i]; test.dd = tests_D[j]; test.ds = inputs_ds[i]; test.ft = inputs_ft[i]; test.fd = tests_S[j]; test.fs = inputs_fs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_ds[i]); CHECK_EQ(test.fd, inputs_fs[i]); test.dd = tests_D[j+1]; test.fd = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_dt[i]); CHECK_EQ(test.fd, inputs_ft[i]); } } } } TEST(rint_s) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; int fcsr; }TestFloat; TestFloat test; float inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E+38, 6.27463370218383111104242366943E-37, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; float* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ rint_s(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(mina_maxa) { if (kArchVariant == kMips64r6) { const int kTableLength = 23; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); struct TestFloat { double a; double b; double resd; double resd1; float c; float d; float resf; float resf1; }; TestFloat test; double inputsa[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = { 4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double resd[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double resd1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputsc[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsd[kTableLength] = {4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, fnan, -0.0, 0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float resf[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float resf1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ lwc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ lwc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ mina_d(f6, f2, f4); __ mina_s(f12, f8, f10); __ maxa_d(f14, f2, f4); __ maxa_s(f16, f8, f10); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, resf)) ); __ sdc1(f6, MemOperand(a0, offsetof(TestFloat, resd)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resf1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resd1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.c = inputsc[i]; test.d = inputsd[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if (i < kTableLength - 1) { CHECK_EQ(test.resd, resd[i]); CHECK_EQ(test.resf, resf[i]); CHECK_EQ(test.resd1, resd1[i]); CHECK_EQ(test.resf1, resf1[i]); } else { CHECK(std::isnan(test.resd)); CHECK(std::isnan(test.resf)); CHECK(std::isnan(test.resd1)); CHECK(std::isnan(test.resf1)); } } } } // ----------------------mips64r2 specific tests---------------------- TEST(trunc_l) { if (kArchVariant == kMips64r2) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; // a trunc result int64_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_l_d(f8, f4); __ trunc_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } } TEST(movz_movn) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { int64_t rt; double a; double b; double bold; double b1; double bold1; float c; float d; float dold; float d1; float dold1; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ld(t0, MemOperand(a0, offsetof(TestFloat, rt))); __ Move(f12, 0.0); __ Move(f10, 0.0); __ Move(f16, 0.0); __ Move(f14, 0.0); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, bold)) ); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, dold)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, bold1)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, dold1)) ); __ movz_s(f10, f6, t0); __ movz_d(f12, f2, t0); __ movn_s(f14, f6, t0); __ movn_d(f16, f2, t0); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, b)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, d1)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, b1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; test.rt = 1; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, test.bold); CHECK_EQ(test.d, test.dold); CHECK_EQ(test.b1, outputs_D[i]); CHECK_EQ(test.d1, outputs_S[i]); test.rt = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); CHECK_EQ(test.b1, test.bold1); CHECK_EQ(test.d1, test.dold1); } } } TEST(movt_movd) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); typedef struct test_float { double srcd; double dstd; double dstdold; double dstd1; double dstdold1; float srcf; float dstf; float dstfold; float dstf1; float dstfold1; int32_t cc; int32_t fcsr; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; double inputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; int condition_flags[8] = {0, 1, 2, 3, 4, 5, 6, 7}; for (int i = 0; i < kTableLength; i++) { test.srcd = inputs_D[i]; test.srcf = inputs_S[i]; for (int j = 0; j< 8; j++) { test.cc = condition_flags[j]; if (test.cc == 0) { test.fcsr = 1 << 23; } else { test.fcsr = 1 << (24+condition_flags[j]); } HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, srcd)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, srcf)) ); __ lw(t1, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t0, FCSR); __ ctc1(t1, FCSR); __ li(t2, 0x0); __ mtc1(t2, f12); __ mtc1(t2, f10); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold)) ); __ movt_s(f12, f4, test.cc); __ movt_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold1)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold1)) ); __ movf_s(f12, f4, test.cc); __ movf_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf1)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd1)) ); __ ctc1(t0, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, outputs_S[i]); CHECK_EQ(test.dstd, outputs_D[i]); CHECK_EQ(test.dstf1, test.dstfold1); CHECK_EQ(test.dstd1, test.dstdold1); test.fcsr = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, test.dstfold); CHECK_EQ(test.dstd, test.dstdold); CHECK_EQ(test.dstf1, outputs_S[i]); CHECK_EQ(test.dstd1, outputs_D[i]); } } } } // ----------------------tests for all archs-------------------------- TEST(cvt_w_d) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; int32_t b; int fcsr; }Test; const int kTableLength = 24; double inputs[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, 2147483653.0 }; double outputs_RN[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RZ[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RP[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RM[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lw(t0, MemOperand(a0, offsetof(Test, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ cvt_w_d(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(Test, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } TEST(trunc_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_w_d(f8, f4); __ trunc_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_w_d(f8, f4); __ round_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_l_d(f8, f4); __ round_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(sub) { const int kTableLength = 12; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; double inputft_D[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; double outputs_D[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; float inputfs_S[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; float inputft_S[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; float outputs_S[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sub_s(f6, f2, f4); __ sub_d(f12, f8, f10); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(sqrt_rsqrt_recip) { const int kTableLength = 4; const double deltaDouble = 2E-15; const float deltaFloat = 2E-7; const float sqrt2_s = sqrt(2); const double sqrt2_d = sqrt(2); CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; float resultS1; float resultS2; double c; double resultD; double resultD1; double resultD2; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 0.0L, 4.0L, 2.0L, 4e-28L }; double outputs_D[kTableLength] = { 0.0L, 2.0L, sqrt2_d, 2e-14L }; float inputs_S[kTableLength] = { 0.0, 4.0, 2.0, 4e-28 }; float outputs_S[kTableLength] = { 0.0, 2.0, sqrt2_s, 2e-14 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ sqrt_s(f6, f2); __ sqrt_d(f12, f8); __ rsqrt_d(f14, f8); __ rsqrt_s(f16, f2); __ recip_d(f18, f8); __ recip_s(f4, f2); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resultS1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resultD1)) ); __ swc1(f4, MemOperand(a0, offsetof(TestFloat, resultS2)) ); __ sdc1(f18, MemOperand(a0, offsetof(TestFloat, resultD2)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { float f1; double d1; test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); if (i != 0) { f1 = test.resultS1 - 1.0F/outputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD1 - 1.0L/outputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); f1 = test.resultS2 - 1.0F/inputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD2 - 1.0L/inputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); } else { CHECK_EQ(test.resultS1, 1.0F/outputs_S[i]); CHECK_EQ(test.resultD1, 1.0L/outputs_D[i]); CHECK_EQ(test.resultS2, 1.0F/inputs_S[i]); CHECK_EQ(test.resultD2, 1.0L/inputs_D[i]); } } } TEST(neg) { const int kTableLength = 2; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; double c; double resultD; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 4.0, -2.0 }; double outputs_D[kTableLength] = { -4.0, 2.0 }; float inputs_S[kTableLength] = { 4.0, -2.0 }; float outputs_S[kTableLength] = { -4.0, 2.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ neg_s(f6, f2); __ neg_d(f12, f8); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
()); F3 f = FUNCTION_CAST(code->entry()); t.cvt_big_in = 0xFFFFFFFF; t.cvt_small_in = 333; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); CHECK_EQ(t.cvt_big_out, static_cast(t.cvt_big_in)); CHECK_EQ(t.cvt_small_out, static_cast(t.cvt_small_in)); CHECK_EQ(static_cast(t.trunc_big_out), static_cast(t.cvt_big_in)); CHECK_EQ(static_cast(t.trunc_small_out), static_cast(t.cvt_small_in)); } TEST(MIPS14) { // Test round, floor, ceil, trunc, cvt. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); #define ROUND_STRUCT_ELEMENT(x) \ uint32_t x##_isNaN2008; \ int32_t x##_up_out; \ int32_t x##_down_out; \ int32_t neg_##x##_up_out; \ int32_t neg_##x##_down_out; \ uint32_t x##_err1_out; \ uint32_t x##_err2_out; \ uint32_t x##_err3_out; \ uint32_t x##_err4_out; \ int32_t x##_invalid_result; typedef struct { double round_up_in; double round_down_in; double neg_round_up_in; double neg_round_down_in; double err1_in; double err2_in; double err3_in; double err4_in; ROUND_STRUCT_ELEMENT(round) ROUND_STRUCT_ELEMENT(floor) ROUND_STRUCT_ELEMENT(ceil) ROUND_STRUCT_ELEMENT(trunc) ROUND_STRUCT_ELEMENT(cvt) } T; T t; #undef ROUND_STRUCT_ELEMENT MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); // Save FCSR. __ cfc1(a1, FCSR); // Disable FPU exceptions. __ ctc1(zero_reg, FCSR); #define RUN_ROUND_TEST(x) \ __ cfc1(t0, FCSR);\ __ sw(t0, MemOperand(a0, offsetof(T, x##_isNaN2008))); \ __ ldc1(f0, MemOperand(a0, offsetof(T, round_up_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_up_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, round_down_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_down_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, neg_round_up_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, neg_##x##_up_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, neg_round_down_in))); \ __ x##_w_d(f0, f0); \ __ swc1(f0, MemOperand(a0, offsetof(T, neg_##x##_down_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err1_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err1_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err2_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err2_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err3_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err3_out))); \ \ __ ldc1(f0, MemOperand(a0, offsetof(T, err4_in))); \ __ ctc1(zero_reg, FCSR); \ __ x##_w_d(f0, f0); \ __ cfc1(a2, FCSR); \ __ sw(a2, MemOperand(a0, offsetof(T, x##_err4_out))); \ __ swc1(f0, MemOperand(a0, offsetof(T, x##_invalid_result))); RUN_ROUND_TEST(round) RUN_ROUND_TEST(floor) RUN_ROUND_TEST(ceil) RUN_ROUND_TEST(trunc) RUN_ROUND_TEST(cvt) // Restore FCSR. __ ctc1(a1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.round_up_in = 123.51; t.round_down_in = 123.49; t.neg_round_up_in = -123.5; t.neg_round_down_in = -123.49; t.err1_in = 123.51; t.err2_in = 1; t.err3_in = static_cast(1) + 0xFFFFFFFF; t.err4_in = NAN; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); #define GET_FPU_ERR(x) (static_cast(x & kFCSRFlagMask)) #define CHECK_NAN2008(x) (x & kFCSRNaN2008FlagMask) #define CHECK_ROUND_RESULT(type) \ CHECK(GET_FPU_ERR(t.type##_err1_out) & kFCSRInexactFlagMask); \ CHECK_EQ(0, GET_FPU_ERR(t.type##_err2_out)); \ CHECK(GET_FPU_ERR(t.type##_err3_out) & kFCSRInvalidOpFlagMask); \ CHECK(GET_FPU_ERR(t.type##_err4_out) & kFCSRInvalidOpFlagMask); \ if (CHECK_NAN2008(t.type##_isNaN2008) && kArchVariant == kMips64r6) { \ CHECK_EQ(static_cast(0), t.type##_invalid_result);\ } else { \ CHECK_EQ(static_cast(kFPUInvalidResult), t.type##_invalid_result);\ } CHECK_ROUND_RESULT(round); CHECK_ROUND_RESULT(floor); CHECK_ROUND_RESULT(ceil); CHECK_ROUND_RESULT(cvt); } TEST(MIPS15) { // Test chaining of label usages within instructions (issue 1644). CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); Assembler assm(isolate, NULL, 0); Label target; __ beq(v0, v1, &target); __ nop(); __ bne(v0, v1, &target); __ nop(); __ bind(&target); __ nop(); } // ----- mips64 tests ----------------------------------------------- TEST(MIPS16) { // Test 64-bit memory loads and stores. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); struct T { int64_t r1; int64_t r2; int64_t r3; int64_t r4; int64_t r5; int64_t r6; int64_t r7; int64_t r8; int64_t r9; int64_t r10; int64_t r11; int64_t r12; uint32_t ui; int32_t si; }; T t; Assembler assm(isolate, NULL, 0); Label L, C; // Basic 32-bit word load/store, with un-signed data. __ lw(a4, MemOperand(a0, offsetof(T, ui))); __ sw(a4, MemOperand(a0, offsetof(T, r1))); // Check that the data got zero-extended into 64-bit a4. __ sd(a4, MemOperand(a0, offsetof(T, r2))); // Basic 32-bit word load/store, with SIGNED data. __ lw(a5, MemOperand(a0, offsetof(T, si))); __ sw(a5, MemOperand(a0, offsetof(T, r3))); // Check that the data got sign-extended into 64-bit a4. __ sd(a5, MemOperand(a0, offsetof(T, r4))); // 32-bit UNSIGNED word load/store, with SIGNED data. __ lwu(a6, MemOperand(a0, offsetof(T, si))); __ sw(a6, MemOperand(a0, offsetof(T, r5))); // Check that the data got zero-extended into 64-bit a4. __ sd(a6, MemOperand(a0, offsetof(T, r6))); // lh with positive data. __ lh(a5, MemOperand(a0, offsetof(T, ui))); __ sw(a5, MemOperand(a0, offsetof(T, r7))); // lh with negative data. __ lh(a6, MemOperand(a0, offsetof(T, si))); __ sw(a6, MemOperand(a0, offsetof(T, r8))); // lhu with negative data. __ lhu(a7, MemOperand(a0, offsetof(T, si))); __ sw(a7, MemOperand(a0, offsetof(T, r9))); // lb with negative data. __ lb(t0, MemOperand(a0, offsetof(T, si))); __ sw(t0, MemOperand(a0, offsetof(T, r10))); // sh writes only 1/2 of word. __ lw(a4, MemOperand(a0, offsetof(T, ui))); __ sh(a4, MemOperand(a0, offsetof(T, r11))); __ lw(a4, MemOperand(a0, offsetof(T, si))); __ sh(a4, MemOperand(a0, offsetof(T, r12))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.ui = 0x44332211; t.si = 0x99aabbcc; t.r1 = 0x5555555555555555; t.r2 = 0x5555555555555555; t.r3 = 0x5555555555555555; t.r4 = 0x5555555555555555; t.r5 = 0x5555555555555555; t.r6 = 0x5555555555555555; t.r7 = 0x5555555555555555; t.r8 = 0x5555555555555555; t.r9 = 0x5555555555555555; t.r10 = 0x5555555555555555; t.r11 = 0x5555555555555555; t.r12 = 0x5555555555555555; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); if (kArchEndian == kLittle) { // Unsigned data, 32 & 64 CHECK_EQ(static_cast(0x5555555544332211L), t.r1); // lw, sw. CHECK_EQ(static_cast(0x0000000044332211L), t.r2); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x5555555599aabbccL), t.r3); // lw, sw. CHECK_EQ(static_cast(0xffffffff99aabbccL), t.r4); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x5555555599aabbccL), t.r5); // lwu, sw. CHECK_EQ(static_cast(0x0000000099aabbccL), t.r6); // sd. // lh with unsigned and signed data. CHECK_EQ(static_cast(0x5555555500002211L), t.r7); // lh, sw. CHECK_EQ(static_cast(0x55555555ffffbbccL), t.r8); // lh, sw. // lhu with signed data. CHECK_EQ(static_cast(0x555555550000bbccL), t.r9); // lhu, sw. // lb with signed data. CHECK_EQ(static_cast(0x55555555ffffffccL), t.r10); // lb, sw. // sh with unsigned and signed data. CHECK_EQ(static_cast(0x5555555555552211L), t.r11); // lw, sh. CHECK_EQ(static_cast(0x555555555555bbccL), t.r12); // lw, sh. } else { // Unsigned data, 32 & 64 CHECK_EQ(static_cast(0x4433221155555555L), t.r1); // lw, sw. CHECK_EQ(static_cast(0x0000000044332211L), t.r2); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x99aabbcc55555555L), t.r3); // lw, sw. CHECK_EQ(static_cast(0xffffffff99aabbccL), t.r4); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x99aabbcc55555555L), t.r5); // lwu, sw. CHECK_EQ(static_cast(0x0000000099aabbccL), t.r6); // sd. // lh with unsigned and signed data. CHECK_EQ(static_cast(0x0000443355555555L), t.r7); // lh, sw. CHECK_EQ(static_cast(0xffff99aa55555555L), t.r8); // lh, sw. // lhu with signed data. CHECK_EQ(static_cast(0x000099aa55555555L), t.r9); // lhu, sw. // lb with signed data. CHECK_EQ(static_cast(0xffffff9955555555L), t.r10); // lb, sw. // sh with unsigned and signed data. CHECK_EQ(static_cast(0x2211555555555555L), t.r11); // lw, sh. CHECK_EQ(static_cast(0xbbcc555555555555L), t.r12); // lw, sh. } } // ----------------------mips64r6 specific tests---------------------- TEST(seleqz_selnez) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { int a; int b; int c; int d; double e; double f; double g; double h; float i; float j; float k; float l; } Test; Test test; // Integer part of test. __ addiu(t1, zero_reg, 1); // t1 = 1 __ seleqz(t3, t1, zero_reg); // t3 = 1 __ sw(t3, MemOperand(a0, offsetof(Test, a))); // a = 1 __ seleqz(t2, t1, t1); // t2 = 0 __ sw(t2, MemOperand(a0, offsetof(Test, b))); // b = 0 __ selnez(t3, t1, zero_reg); // t3 = 1; __ sw(t3, MemOperand(a0, offsetof(Test, c))); // c = 0 __ selnez(t3, t1, t1); // t3 = 1 __ sw(t3, MemOperand(a0, offsetof(Test, d))); // d = 1 // Floating point part of test. __ ldc1(f0, MemOperand(a0, offsetof(Test, e)) ); // src __ ldc1(f2, MemOperand(a0, offsetof(Test, f)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, i)) ); // src __ lwc1(f10, MemOperand(a0, offsetof(Test, j)) ); // test __ seleqz_d(f4, f0, f2); __ selnez_d(f6, f0, f2); __ seleqz_s(f12, f8, f10); __ selnez_s(f14, f8, f10); __ sdc1(f4, MemOperand(a0, offsetof(Test, g)) ); // src __ sdc1(f6, MemOperand(a0, offsetof(Test, h)) ); // src __ swc1(f12, MemOperand(a0, offsetof(Test, k)) ); // src __ swc1(f14, MemOperand(a0, offsetof(Test, l)) ); // src __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.a, 1); CHECK_EQ(test.b, 0); CHECK_EQ(test.c, 0); CHECK_EQ(test.d, 1); const int test_size = 3; const int input_size = 5; double inputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double outputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float inputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float outputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.e = inputs_D[i]; test.f = tests_D[j]; test.i = inputs_S[i]; test.j = tests_S[j]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, outputs_D[i]); CHECK_EQ(test.h, 0); CHECK_EQ(test.k, outputs_S[i]); CHECK_EQ(test.l, 0); test.f = tests_D[j+1]; test.j = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, 0); CHECK_EQ(test.h, outputs_D[i]); CHECK_EQ(test.k, 0); CHECK_EQ(test.l, outputs_S[i]); } } } } TEST(min_max) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); struct TestFloat { double a; double b; double c; double d; float e; float f; float g; float h; }; TestFloat test; const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); const int kTableLength = 13; double inputsa[kTableLength] = {2.0, 3.0, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = {3.0, 2.0, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double outputsdmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double outputsdmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputse[kTableLength] = {2.0, 3.0, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsf[kTableLength] = {3.0, 2.0, 3.0, fnan, 0.0, -0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float outputsfmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float outputsfmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a))); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, b))); __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, e))); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, f))); __ min_d(f10, f4, f8); __ max_d(f12, f4, f8); __ min_s(f14, f2, f6); __ max_s(f16, f2, f6); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, c))); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, d))); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, g))); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, h))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 4; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.e = inputse[i]; test.f = inputsf[i]; CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0); CHECK_EQ(0, memcmp(&test.c, &outputsdmin[i], sizeof(test.c))); CHECK_EQ(0, memcmp(&test.d, &outputsdmax[i], sizeof(test.d))); CHECK_EQ(0, memcmp(&test.g, &outputsfmin[i], sizeof(test.g))); CHECK_EQ(0, memcmp(&test.h, &outputsfmax[i], sizeof(test.h))); } } } TEST(rint_d) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; int fcsr; }TestFloat; TestFloat test; double inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E+308, 6.27463370218383111104242366943E-307, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ ctc1(t0, FCSR); __ rint_d(f8, f4); __ sdc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(sel) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { double dd; double ds; double dt; float fd; float fs; float ft; } Test; Test test; __ ldc1(f0, MemOperand(a0, offsetof(Test, dd)) ); // test __ ldc1(f2, MemOperand(a0, offsetof(Test, ds)) ); // src1 __ ldc1(f4, MemOperand(a0, offsetof(Test, dt)) ); // src2 __ lwc1(f6, MemOperand(a0, offsetof(Test, fd)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, fs)) ); // src1 __ lwc1(f10, MemOperand(a0, offsetof(Test, ft)) ); // src2 __ sel_d(f0, f2, f4); __ sel_s(f6, f8, f10); __ sdc1(f0, MemOperand(a0, offsetof(Test, dd)) ); __ swc1(f6, MemOperand(a0, offsetof(Test, fd)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); const int test_size = 3; const int input_size = 5; double inputs_dt[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double inputs_ds[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; float inputs_ft[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float inputs_fs[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.dt = inputs_dt[i]; test.dd = tests_D[j]; test.ds = inputs_ds[i]; test.ft = inputs_ft[i]; test.fd = tests_S[j]; test.fs = inputs_fs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_ds[i]); CHECK_EQ(test.fd, inputs_fs[i]); test.dd = tests_D[j+1]; test.fd = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_dt[i]); CHECK_EQ(test.fd, inputs_ft[i]); } } } } TEST(rint_s) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; int fcsr; }TestFloat; TestFloat test; float inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E+38, 6.27463370218383111104242366943E-37, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; float* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ rint_s(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(mina_maxa) { if (kArchVariant == kMips64r6) { const int kTableLength = 23; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); struct TestFloat { double a; double b; double resd; double resd1; float c; float d; float resf; float resf1; }; TestFloat test; double inputsa[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = { 4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double resd[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double resd1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputsc[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsd[kTableLength] = {4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, fnan, -0.0, 0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float resf[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float resf1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ lwc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ lwc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ mina_d(f6, f2, f4); __ mina_s(f12, f8, f10); __ maxa_d(f14, f2, f4); __ maxa_s(f16, f8, f10); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, resf)) ); __ sdc1(f6, MemOperand(a0, offsetof(TestFloat, resd)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resf1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resd1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.c = inputsc[i]; test.d = inputsd[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if (i < kTableLength - 1) { CHECK_EQ(test.resd, resd[i]); CHECK_EQ(test.resf, resf[i]); CHECK_EQ(test.resd1, resd1[i]); CHECK_EQ(test.resf1, resf1[i]); } else { CHECK(std::isnan(test.resd)); CHECK(std::isnan(test.resf)); CHECK(std::isnan(test.resd1)); CHECK(std::isnan(test.resf1)); } } } } // ----------------------mips64r2 specific tests---------------------- TEST(trunc_l) { if (kArchVariant == kMips64r2) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; // a trunc result int64_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_l_d(f8, f4); __ trunc_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } } TEST(movz_movn) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { int64_t rt; double a; double b; double bold; double b1; double bold1; float c; float d; float dold; float d1; float dold1; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ld(t0, MemOperand(a0, offsetof(TestFloat, rt))); __ Move(f12, 0.0); __ Move(f10, 0.0); __ Move(f16, 0.0); __ Move(f14, 0.0); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, bold)) ); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, dold)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, bold1)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, dold1)) ); __ movz_s(f10, f6, t0); __ movz_d(f12, f2, t0); __ movn_s(f14, f6, t0); __ movn_d(f16, f2, t0); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, b)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, d1)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, b1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; test.rt = 1; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, test.bold); CHECK_EQ(test.d, test.dold); CHECK_EQ(test.b1, outputs_D[i]); CHECK_EQ(test.d1, outputs_S[i]); test.rt = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); CHECK_EQ(test.b1, test.bold1); CHECK_EQ(test.d1, test.dold1); } } } TEST(movt_movd) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); typedef struct test_float { double srcd; double dstd; double dstdold; double dstd1; double dstdold1; float srcf; float dstf; float dstfold; float dstf1; float dstfold1; int32_t cc; int32_t fcsr; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; double inputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; int condition_flags[8] = {0, 1, 2, 3, 4, 5, 6, 7}; for (int i = 0; i < kTableLength; i++) { test.srcd = inputs_D[i]; test.srcf = inputs_S[i]; for (int j = 0; j< 8; j++) { test.cc = condition_flags[j]; if (test.cc == 0) { test.fcsr = 1 << 23; } else { test.fcsr = 1 << (24+condition_flags[j]); } HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, srcd)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, srcf)) ); __ lw(t1, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t0, FCSR); __ ctc1(t1, FCSR); __ li(t2, 0x0); __ mtc1(t2, f12); __ mtc1(t2, f10); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold)) ); __ movt_s(f12, f4, test.cc); __ movt_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold1)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold1)) ); __ movf_s(f12, f4, test.cc); __ movf_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf1)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd1)) ); __ ctc1(t0, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, outputs_S[i]); CHECK_EQ(test.dstd, outputs_D[i]); CHECK_EQ(test.dstf1, test.dstfold1); CHECK_EQ(test.dstd1, test.dstdold1); test.fcsr = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, test.dstfold); CHECK_EQ(test.dstd, test.dstdold); CHECK_EQ(test.dstf1, outputs_S[i]); CHECK_EQ(test.dstd1, outputs_D[i]); } } } } // ----------------------tests for all archs-------------------------- TEST(cvt_w_d) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; int32_t b; int fcsr; }Test; const int kTableLength = 24; double inputs[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, 2147483653.0 }; double outputs_RN[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RZ[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RP[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RM[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lw(t0, MemOperand(a0, offsetof(Test, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ cvt_w_d(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(Test, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } TEST(trunc_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_w_d(f8, f4); __ trunc_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_w_d(f8, f4); __ round_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_l_d(f8, f4); __ round_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(sub) { const int kTableLength = 12; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; double inputft_D[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; double outputs_D[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; float inputfs_S[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; float inputft_S[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; float outputs_S[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sub_s(f6, f2, f4); __ sub_d(f12, f8, f10); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(sqrt_rsqrt_recip) { const int kTableLength = 4; const double deltaDouble = 2E-15; const float deltaFloat = 2E-7; const float sqrt2_s = sqrt(2); const double sqrt2_d = sqrt(2); CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; float resultS1; float resultS2; double c; double resultD; double resultD1; double resultD2; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 0.0L, 4.0L, 2.0L, 4e-28L }; double outputs_D[kTableLength] = { 0.0L, 2.0L, sqrt2_d, 2e-14L }; float inputs_S[kTableLength] = { 0.0, 4.0, 2.0, 4e-28 }; float outputs_S[kTableLength] = { 0.0, 2.0, sqrt2_s, 2e-14 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ sqrt_s(f6, f2); __ sqrt_d(f12, f8); __ rsqrt_d(f14, f8); __ rsqrt_s(f16, f2); __ recip_d(f18, f8); __ recip_s(f4, f2); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resultS1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resultD1)) ); __ swc1(f4, MemOperand(a0, offsetof(TestFloat, resultS2)) ); __ sdc1(f18, MemOperand(a0, offsetof(TestFloat, resultD2)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { float f1; double d1; test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); if (i != 0) { f1 = test.resultS1 - 1.0F/outputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD1 - 1.0L/outputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); f1 = test.resultS2 - 1.0F/inputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD2 - 1.0L/inputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); } else { CHECK_EQ(test.resultS1, 1.0F/outputs_S[i]); CHECK_EQ(test.resultD1, 1.0L/outputs_D[i]); CHECK_EQ(test.resultS2, 1.0F/inputs_S[i]); CHECK_EQ(test.resultD2, 1.0L/inputs_D[i]); } } } TEST(neg) { const int kTableLength = 2; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; double c; double resultD; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 4.0, -2.0 }; double outputs_D[kTableLength] = { -4.0, 2.0 }; float inputs_S[kTableLength] = { 4.0, -2.0 }; float outputs_S[kTableLength] = { -4.0, 2.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ neg_s(f6, f2); __ neg_d(f12, f8); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.round_up_in = 123.51; t.round_down_in = 123.49; t.neg_round_up_in = -123.5; t.neg_round_down_in = -123.49; t.err1_in = 123.51; t.err2_in = 1; t.err3_in = static_cast(1) + 0xFFFFFFFF; t.err4_in = NAN; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); #define GET_FPU_ERR(x) (static_cast(x & kFCSRFlagMask)) #define CHECK_NAN2008(x) (x & kFCSRNaN2008FlagMask) #define CHECK_ROUND_RESULT(type) \ CHECK(GET_FPU_ERR(t.type##_err1_out) & kFCSRInexactFlagMask); \ CHECK_EQ(0, GET_FPU_ERR(t.type##_err2_out)); \ CHECK(GET_FPU_ERR(t.type##_err3_out) & kFCSRInvalidOpFlagMask); \ CHECK(GET_FPU_ERR(t.type##_err4_out) & kFCSRInvalidOpFlagMask); \ if (CHECK_NAN2008(t.type##_isNaN2008) && kArchVariant == kMips64r6) { \ CHECK_EQ(static_cast(0), t.type##_invalid_result);\ } else { \ CHECK_EQ(static_cast(kFPUInvalidResult), t.type##_invalid_result);\ } CHECK_ROUND_RESULT(round); CHECK_ROUND_RESULT(floor); CHECK_ROUND_RESULT(ceil); CHECK_ROUND_RESULT(cvt); } TEST(MIPS15) { // Test chaining of label usages within instructions (issue 1644). CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); Assembler assm(isolate, NULL, 0); Label target; __ beq(v0, v1, &target); __ nop(); __ bne(v0, v1, &target); __ nop(); __ bind(&target); __ nop(); } // ----- mips64 tests ----------------------------------------------- TEST(MIPS16) { // Test 64-bit memory loads and stores. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); struct T { int64_t r1; int64_t r2; int64_t r3; int64_t r4; int64_t r5; int64_t r6; int64_t r7; int64_t r8; int64_t r9; int64_t r10; int64_t r11; int64_t r12; uint32_t ui; int32_t si; }; T t; Assembler assm(isolate, NULL, 0); Label L, C; // Basic 32-bit word load/store, with un-signed data. __ lw(a4, MemOperand(a0, offsetof(T, ui))); __ sw(a4, MemOperand(a0, offsetof(T, r1))); // Check that the data got zero-extended into 64-bit a4. __ sd(a4, MemOperand(a0, offsetof(T, r2))); // Basic 32-bit word load/store, with SIGNED data. __ lw(a5, MemOperand(a0, offsetof(T, si))); __ sw(a5, MemOperand(a0, offsetof(T, r3))); // Check that the data got sign-extended into 64-bit a4. __ sd(a5, MemOperand(a0, offsetof(T, r4))); // 32-bit UNSIGNED word load/store, with SIGNED data. __ lwu(a6, MemOperand(a0, offsetof(T, si))); __ sw(a6, MemOperand(a0, offsetof(T, r5))); // Check that the data got zero-extended into 64-bit a4. __ sd(a6, MemOperand(a0, offsetof(T, r6))); // lh with positive data. __ lh(a5, MemOperand(a0, offsetof(T, ui))); __ sw(a5, MemOperand(a0, offsetof(T, r7))); // lh with negative data. __ lh(a6, MemOperand(a0, offsetof(T, si))); __ sw(a6, MemOperand(a0, offsetof(T, r8))); // lhu with negative data. __ lhu(a7, MemOperand(a0, offsetof(T, si))); __ sw(a7, MemOperand(a0, offsetof(T, r9))); // lb with negative data. __ lb(t0, MemOperand(a0, offsetof(T, si))); __ sw(t0, MemOperand(a0, offsetof(T, r10))); // sh writes only 1/2 of word. __ lw(a4, MemOperand(a0, offsetof(T, ui))); __ sh(a4, MemOperand(a0, offsetof(T, r11))); __ lw(a4, MemOperand(a0, offsetof(T, si))); __ sh(a4, MemOperand(a0, offsetof(T, r12))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.ui = 0x44332211; t.si = 0x99aabbcc; t.r1 = 0x5555555555555555; t.r2 = 0x5555555555555555; t.r3 = 0x5555555555555555; t.r4 = 0x5555555555555555; t.r5 = 0x5555555555555555; t.r6 = 0x5555555555555555; t.r7 = 0x5555555555555555; t.r8 = 0x5555555555555555; t.r9 = 0x5555555555555555; t.r10 = 0x5555555555555555; t.r11 = 0x5555555555555555; t.r12 = 0x5555555555555555; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); if (kArchEndian == kLittle) { // Unsigned data, 32 & 64 CHECK_EQ(static_cast(0x5555555544332211L), t.r1); // lw, sw. CHECK_EQ(static_cast(0x0000000044332211L), t.r2); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x5555555599aabbccL), t.r3); // lw, sw. CHECK_EQ(static_cast(0xffffffff99aabbccL), t.r4); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x5555555599aabbccL), t.r5); // lwu, sw. CHECK_EQ(static_cast(0x0000000099aabbccL), t.r6); // sd. // lh with unsigned and signed data. CHECK_EQ(static_cast(0x5555555500002211L), t.r7); // lh, sw. CHECK_EQ(static_cast(0x55555555ffffbbccL), t.r8); // lh, sw. // lhu with signed data. CHECK_EQ(static_cast(0x555555550000bbccL), t.r9); // lhu, sw. // lb with signed data. CHECK_EQ(static_cast(0x55555555ffffffccL), t.r10); // lb, sw. // sh with unsigned and signed data. CHECK_EQ(static_cast(0x5555555555552211L), t.r11); // lw, sh. CHECK_EQ(static_cast(0x555555555555bbccL), t.r12); // lw, sh. } else { // Unsigned data, 32 & 64 CHECK_EQ(static_cast(0x4433221155555555L), t.r1); // lw, sw. CHECK_EQ(static_cast(0x0000000044332211L), t.r2); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x99aabbcc55555555L), t.r3); // lw, sw. CHECK_EQ(static_cast(0xffffffff99aabbccL), t.r4); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x99aabbcc55555555L), t.r5); // lwu, sw. CHECK_EQ(static_cast(0x0000000099aabbccL), t.r6); // sd. // lh with unsigned and signed data. CHECK_EQ(static_cast(0x0000443355555555L), t.r7); // lh, sw. CHECK_EQ(static_cast(0xffff99aa55555555L), t.r8); // lh, sw. // lhu with signed data. CHECK_EQ(static_cast(0x000099aa55555555L), t.r9); // lhu, sw. // lb with signed data. CHECK_EQ(static_cast(0xffffff9955555555L), t.r10); // lb, sw. // sh with unsigned and signed data. CHECK_EQ(static_cast(0x2211555555555555L), t.r11); // lw, sh. CHECK_EQ(static_cast(0xbbcc555555555555L), t.r12); // lw, sh. } } // ----------------------mips64r6 specific tests---------------------- TEST(seleqz_selnez) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { int a; int b; int c; int d; double e; double f; double g; double h; float i; float j; float k; float l; } Test; Test test; // Integer part of test. __ addiu(t1, zero_reg, 1); // t1 = 1 __ seleqz(t3, t1, zero_reg); // t3 = 1 __ sw(t3, MemOperand(a0, offsetof(Test, a))); // a = 1 __ seleqz(t2, t1, t1); // t2 = 0 __ sw(t2, MemOperand(a0, offsetof(Test, b))); // b = 0 __ selnez(t3, t1, zero_reg); // t3 = 1; __ sw(t3, MemOperand(a0, offsetof(Test, c))); // c = 0 __ selnez(t3, t1, t1); // t3 = 1 __ sw(t3, MemOperand(a0, offsetof(Test, d))); // d = 1 // Floating point part of test. __ ldc1(f0, MemOperand(a0, offsetof(Test, e)) ); // src __ ldc1(f2, MemOperand(a0, offsetof(Test, f)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, i)) ); // src __ lwc1(f10, MemOperand(a0, offsetof(Test, j)) ); // test __ seleqz_d(f4, f0, f2); __ selnez_d(f6, f0, f2); __ seleqz_s(f12, f8, f10); __ selnez_s(f14, f8, f10); __ sdc1(f4, MemOperand(a0, offsetof(Test, g)) ); // src __ sdc1(f6, MemOperand(a0, offsetof(Test, h)) ); // src __ swc1(f12, MemOperand(a0, offsetof(Test, k)) ); // src __ swc1(f14, MemOperand(a0, offsetof(Test, l)) ); // src __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.a, 1); CHECK_EQ(test.b, 0); CHECK_EQ(test.c, 0); CHECK_EQ(test.d, 1); const int test_size = 3; const int input_size = 5; double inputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double outputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float inputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float outputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.e = inputs_D[i]; test.f = tests_D[j]; test.i = inputs_S[i]; test.j = tests_S[j]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, outputs_D[i]); CHECK_EQ(test.h, 0); CHECK_EQ(test.k, outputs_S[i]); CHECK_EQ(test.l, 0); test.f = tests_D[j+1]; test.j = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, 0); CHECK_EQ(test.h, outputs_D[i]); CHECK_EQ(test.k, 0); CHECK_EQ(test.l, outputs_S[i]); } } } } TEST(min_max) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); struct TestFloat { double a; double b; double c; double d; float e; float f; float g; float h; }; TestFloat test; const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); const int kTableLength = 13; double inputsa[kTableLength] = {2.0, 3.0, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = {3.0, 2.0, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double outputsdmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double outputsdmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputse[kTableLength] = {2.0, 3.0, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsf[kTableLength] = {3.0, 2.0, 3.0, fnan, 0.0, -0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float outputsfmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float outputsfmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a))); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, b))); __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, e))); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, f))); __ min_d(f10, f4, f8); __ max_d(f12, f4, f8); __ min_s(f14, f2, f6); __ max_s(f16, f2, f6); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, c))); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, d))); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, g))); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, h))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 4; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.e = inputse[i]; test.f = inputsf[i]; CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0); CHECK_EQ(0, memcmp(&test.c, &outputsdmin[i], sizeof(test.c))); CHECK_EQ(0, memcmp(&test.d, &outputsdmax[i], sizeof(test.d))); CHECK_EQ(0, memcmp(&test.g, &outputsfmin[i], sizeof(test.g))); CHECK_EQ(0, memcmp(&test.h, &outputsfmax[i], sizeof(test.h))); } } } TEST(rint_d) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; int fcsr; }TestFloat; TestFloat test; double inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E+308, 6.27463370218383111104242366943E-307, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ ctc1(t0, FCSR); __ rint_d(f8, f4); __ sdc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(sel) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { double dd; double ds; double dt; float fd; float fs; float ft; } Test; Test test; __ ldc1(f0, MemOperand(a0, offsetof(Test, dd)) ); // test __ ldc1(f2, MemOperand(a0, offsetof(Test, ds)) ); // src1 __ ldc1(f4, MemOperand(a0, offsetof(Test, dt)) ); // src2 __ lwc1(f6, MemOperand(a0, offsetof(Test, fd)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, fs)) ); // src1 __ lwc1(f10, MemOperand(a0, offsetof(Test, ft)) ); // src2 __ sel_d(f0, f2, f4); __ sel_s(f6, f8, f10); __ sdc1(f0, MemOperand(a0, offsetof(Test, dd)) ); __ swc1(f6, MemOperand(a0, offsetof(Test, fd)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); const int test_size = 3; const int input_size = 5; double inputs_dt[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double inputs_ds[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; float inputs_ft[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float inputs_fs[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.dt = inputs_dt[i]; test.dd = tests_D[j]; test.ds = inputs_ds[i]; test.ft = inputs_ft[i]; test.fd = tests_S[j]; test.fs = inputs_fs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_ds[i]); CHECK_EQ(test.fd, inputs_fs[i]); test.dd = tests_D[j+1]; test.fd = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_dt[i]); CHECK_EQ(test.fd, inputs_ft[i]); } } } } TEST(rint_s) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; int fcsr; }TestFloat; TestFloat test; float inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E+38, 6.27463370218383111104242366943E-37, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; float* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ rint_s(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(mina_maxa) { if (kArchVariant == kMips64r6) { const int kTableLength = 23; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); struct TestFloat { double a; double b; double resd; double resd1; float c; float d; float resf; float resf1; }; TestFloat test; double inputsa[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = { 4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double resd[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double resd1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputsc[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsd[kTableLength] = {4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, fnan, -0.0, 0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float resf[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float resf1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ lwc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ lwc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ mina_d(f6, f2, f4); __ mina_s(f12, f8, f10); __ maxa_d(f14, f2, f4); __ maxa_s(f16, f8, f10); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, resf)) ); __ sdc1(f6, MemOperand(a0, offsetof(TestFloat, resd)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resf1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resd1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.c = inputsc[i]; test.d = inputsd[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if (i < kTableLength - 1) { CHECK_EQ(test.resd, resd[i]); CHECK_EQ(test.resf, resf[i]); CHECK_EQ(test.resd1, resd1[i]); CHECK_EQ(test.resf1, resf1[i]); } else { CHECK(std::isnan(test.resd)); CHECK(std::isnan(test.resf)); CHECK(std::isnan(test.resd1)); CHECK(std::isnan(test.resf1)); } } } } // ----------------------mips64r2 specific tests---------------------- TEST(trunc_l) { if (kArchVariant == kMips64r2) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; // a trunc result int64_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_l_d(f8, f4); __ trunc_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } } TEST(movz_movn) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { int64_t rt; double a; double b; double bold; double b1; double bold1; float c; float d; float dold; float d1; float dold1; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ld(t0, MemOperand(a0, offsetof(TestFloat, rt))); __ Move(f12, 0.0); __ Move(f10, 0.0); __ Move(f16, 0.0); __ Move(f14, 0.0); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, bold)) ); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, dold)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, bold1)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, dold1)) ); __ movz_s(f10, f6, t0); __ movz_d(f12, f2, t0); __ movn_s(f14, f6, t0); __ movn_d(f16, f2, t0); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, b)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, d1)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, b1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; test.rt = 1; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, test.bold); CHECK_EQ(test.d, test.dold); CHECK_EQ(test.b1, outputs_D[i]); CHECK_EQ(test.d1, outputs_S[i]); test.rt = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); CHECK_EQ(test.b1, test.bold1); CHECK_EQ(test.d1, test.dold1); } } } TEST(movt_movd) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); typedef struct test_float { double srcd; double dstd; double dstdold; double dstd1; double dstdold1; float srcf; float dstf; float dstfold; float dstf1; float dstfold1; int32_t cc; int32_t fcsr; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; double inputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; int condition_flags[8] = {0, 1, 2, 3, 4, 5, 6, 7}; for (int i = 0; i < kTableLength; i++) { test.srcd = inputs_D[i]; test.srcf = inputs_S[i]; for (int j = 0; j< 8; j++) { test.cc = condition_flags[j]; if (test.cc == 0) { test.fcsr = 1 << 23; } else { test.fcsr = 1 << (24+condition_flags[j]); } HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, srcd)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, srcf)) ); __ lw(t1, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t0, FCSR); __ ctc1(t1, FCSR); __ li(t2, 0x0); __ mtc1(t2, f12); __ mtc1(t2, f10); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold)) ); __ movt_s(f12, f4, test.cc); __ movt_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold1)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold1)) ); __ movf_s(f12, f4, test.cc); __ movf_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf1)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd1)) ); __ ctc1(t0, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, outputs_S[i]); CHECK_EQ(test.dstd, outputs_D[i]); CHECK_EQ(test.dstf1, test.dstfold1); CHECK_EQ(test.dstd1, test.dstdold1); test.fcsr = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, test.dstfold); CHECK_EQ(test.dstd, test.dstdold); CHECK_EQ(test.dstf1, outputs_S[i]); CHECK_EQ(test.dstd1, outputs_D[i]); } } } } // ----------------------tests for all archs-------------------------- TEST(cvt_w_d) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; int32_t b; int fcsr; }Test; const int kTableLength = 24; double inputs[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, 2147483653.0 }; double outputs_RN[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RZ[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RP[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RM[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lw(t0, MemOperand(a0, offsetof(Test, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ cvt_w_d(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(Test, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } TEST(trunc_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_w_d(f8, f4); __ trunc_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_w_d(f8, f4); __ round_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_l_d(f8, f4); __ round_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(sub) { const int kTableLength = 12; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; double inputft_D[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; double outputs_D[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; float inputfs_S[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; float inputft_S[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; float outputs_S[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sub_s(f6, f2, f4); __ sub_d(f12, f8, f10); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(sqrt_rsqrt_recip) { const int kTableLength = 4; const double deltaDouble = 2E-15; const float deltaFloat = 2E-7; const float sqrt2_s = sqrt(2); const double sqrt2_d = sqrt(2); CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; float resultS1; float resultS2; double c; double resultD; double resultD1; double resultD2; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 0.0L, 4.0L, 2.0L, 4e-28L }; double outputs_D[kTableLength] = { 0.0L, 2.0L, sqrt2_d, 2e-14L }; float inputs_S[kTableLength] = { 0.0, 4.0, 2.0, 4e-28 }; float outputs_S[kTableLength] = { 0.0, 2.0, sqrt2_s, 2e-14 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ sqrt_s(f6, f2); __ sqrt_d(f12, f8); __ rsqrt_d(f14, f8); __ rsqrt_s(f16, f2); __ recip_d(f18, f8); __ recip_s(f4, f2); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resultS1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resultD1)) ); __ swc1(f4, MemOperand(a0, offsetof(TestFloat, resultS2)) ); __ sdc1(f18, MemOperand(a0, offsetof(TestFloat, resultD2)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { float f1; double d1; test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); if (i != 0) { f1 = test.resultS1 - 1.0F/outputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD1 - 1.0L/outputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); f1 = test.resultS2 - 1.0F/inputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD2 - 1.0L/inputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); } else { CHECK_EQ(test.resultS1, 1.0F/outputs_S[i]); CHECK_EQ(test.resultD1, 1.0L/outputs_D[i]); CHECK_EQ(test.resultS2, 1.0F/inputs_S[i]); CHECK_EQ(test.resultD2, 1.0L/inputs_D[i]); } } } TEST(neg) { const int kTableLength = 2; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; double c; double resultD; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 4.0, -2.0 }; double outputs_D[kTableLength] = { -4.0, 2.0 }; float inputs_S[kTableLength] = { 4.0, -2.0 }; float outputs_S[kTableLength] = { -4.0, 2.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ neg_s(f6, f2); __ neg_d(f12, f8); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
()); F3 f = FUNCTION_CAST(code->entry()); t.round_up_in = 123.51; t.round_down_in = 123.49; t.neg_round_up_in = -123.5; t.neg_round_down_in = -123.49; t.err1_in = 123.51; t.err2_in = 1; t.err3_in = static_cast(1) + 0xFFFFFFFF; t.err4_in = NAN; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); #define GET_FPU_ERR(x) (static_cast(x & kFCSRFlagMask)) #define CHECK_NAN2008(x) (x & kFCSRNaN2008FlagMask) #define CHECK_ROUND_RESULT(type) \ CHECK(GET_FPU_ERR(t.type##_err1_out) & kFCSRInexactFlagMask); \ CHECK_EQ(0, GET_FPU_ERR(t.type##_err2_out)); \ CHECK(GET_FPU_ERR(t.type##_err3_out) & kFCSRInvalidOpFlagMask); \ CHECK(GET_FPU_ERR(t.type##_err4_out) & kFCSRInvalidOpFlagMask); \ if (CHECK_NAN2008(t.type##_isNaN2008) && kArchVariant == kMips64r6) { \ CHECK_EQ(static_cast(0), t.type##_invalid_result);\ } else { \ CHECK_EQ(static_cast(kFPUInvalidResult), t.type##_invalid_result);\ } CHECK_ROUND_RESULT(round); CHECK_ROUND_RESULT(floor); CHECK_ROUND_RESULT(ceil); CHECK_ROUND_RESULT(cvt); } TEST(MIPS15) { // Test chaining of label usages within instructions (issue 1644). CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); Assembler assm(isolate, NULL, 0); Label target; __ beq(v0, v1, &target); __ nop(); __ bne(v0, v1, &target); __ nop(); __ bind(&target); __ nop(); } // ----- mips64 tests ----------------------------------------------- TEST(MIPS16) { // Test 64-bit memory loads and stores. CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); struct T { int64_t r1; int64_t r2; int64_t r3; int64_t r4; int64_t r5; int64_t r6; int64_t r7; int64_t r8; int64_t r9; int64_t r10; int64_t r11; int64_t r12; uint32_t ui; int32_t si; }; T t; Assembler assm(isolate, NULL, 0); Label L, C; // Basic 32-bit word load/store, with un-signed data. __ lw(a4, MemOperand(a0, offsetof(T, ui))); __ sw(a4, MemOperand(a0, offsetof(T, r1))); // Check that the data got zero-extended into 64-bit a4. __ sd(a4, MemOperand(a0, offsetof(T, r2))); // Basic 32-bit word load/store, with SIGNED data. __ lw(a5, MemOperand(a0, offsetof(T, si))); __ sw(a5, MemOperand(a0, offsetof(T, r3))); // Check that the data got sign-extended into 64-bit a4. __ sd(a5, MemOperand(a0, offsetof(T, r4))); // 32-bit UNSIGNED word load/store, with SIGNED data. __ lwu(a6, MemOperand(a0, offsetof(T, si))); __ sw(a6, MemOperand(a0, offsetof(T, r5))); // Check that the data got zero-extended into 64-bit a4. __ sd(a6, MemOperand(a0, offsetof(T, r6))); // lh with positive data. __ lh(a5, MemOperand(a0, offsetof(T, ui))); __ sw(a5, MemOperand(a0, offsetof(T, r7))); // lh with negative data. __ lh(a6, MemOperand(a0, offsetof(T, si))); __ sw(a6, MemOperand(a0, offsetof(T, r8))); // lhu with negative data. __ lhu(a7, MemOperand(a0, offsetof(T, si))); __ sw(a7, MemOperand(a0, offsetof(T, r9))); // lb with negative data. __ lb(t0, MemOperand(a0, offsetof(T, si))); __ sw(t0, MemOperand(a0, offsetof(T, r10))); // sh writes only 1/2 of word. __ lw(a4, MemOperand(a0, offsetof(T, ui))); __ sh(a4, MemOperand(a0, offsetof(T, r11))); __ lw(a4, MemOperand(a0, offsetof(T, si))); __ sh(a4, MemOperand(a0, offsetof(T, r12))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.ui = 0x44332211; t.si = 0x99aabbcc; t.r1 = 0x5555555555555555; t.r2 = 0x5555555555555555; t.r3 = 0x5555555555555555; t.r4 = 0x5555555555555555; t.r5 = 0x5555555555555555; t.r6 = 0x5555555555555555; t.r7 = 0x5555555555555555; t.r8 = 0x5555555555555555; t.r9 = 0x5555555555555555; t.r10 = 0x5555555555555555; t.r11 = 0x5555555555555555; t.r12 = 0x5555555555555555; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); if (kArchEndian == kLittle) { // Unsigned data, 32 & 64 CHECK_EQ(static_cast(0x5555555544332211L), t.r1); // lw, sw. CHECK_EQ(static_cast(0x0000000044332211L), t.r2); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x5555555599aabbccL), t.r3); // lw, sw. CHECK_EQ(static_cast(0xffffffff99aabbccL), t.r4); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x5555555599aabbccL), t.r5); // lwu, sw. CHECK_EQ(static_cast(0x0000000099aabbccL), t.r6); // sd. // lh with unsigned and signed data. CHECK_EQ(static_cast(0x5555555500002211L), t.r7); // lh, sw. CHECK_EQ(static_cast(0x55555555ffffbbccL), t.r8); // lh, sw. // lhu with signed data. CHECK_EQ(static_cast(0x555555550000bbccL), t.r9); // lhu, sw. // lb with signed data. CHECK_EQ(static_cast(0x55555555ffffffccL), t.r10); // lb, sw. // sh with unsigned and signed data. CHECK_EQ(static_cast(0x5555555555552211L), t.r11); // lw, sh. CHECK_EQ(static_cast(0x555555555555bbccL), t.r12); // lw, sh. } else { // Unsigned data, 32 & 64 CHECK_EQ(static_cast(0x4433221155555555L), t.r1); // lw, sw. CHECK_EQ(static_cast(0x0000000044332211L), t.r2); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x99aabbcc55555555L), t.r3); // lw, sw. CHECK_EQ(static_cast(0xffffffff99aabbccL), t.r4); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x99aabbcc55555555L), t.r5); // lwu, sw. CHECK_EQ(static_cast(0x0000000099aabbccL), t.r6); // sd. // lh with unsigned and signed data. CHECK_EQ(static_cast(0x0000443355555555L), t.r7); // lh, sw. CHECK_EQ(static_cast(0xffff99aa55555555L), t.r8); // lh, sw. // lhu with signed data. CHECK_EQ(static_cast(0x000099aa55555555L), t.r9); // lhu, sw. // lb with signed data. CHECK_EQ(static_cast(0xffffff9955555555L), t.r10); // lb, sw. // sh with unsigned and signed data. CHECK_EQ(static_cast(0x2211555555555555L), t.r11); // lw, sh. CHECK_EQ(static_cast(0xbbcc555555555555L), t.r12); // lw, sh. } } // ----------------------mips64r6 specific tests---------------------- TEST(seleqz_selnez) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { int a; int b; int c; int d; double e; double f; double g; double h; float i; float j; float k; float l; } Test; Test test; // Integer part of test. __ addiu(t1, zero_reg, 1); // t1 = 1 __ seleqz(t3, t1, zero_reg); // t3 = 1 __ sw(t3, MemOperand(a0, offsetof(Test, a))); // a = 1 __ seleqz(t2, t1, t1); // t2 = 0 __ sw(t2, MemOperand(a0, offsetof(Test, b))); // b = 0 __ selnez(t3, t1, zero_reg); // t3 = 1; __ sw(t3, MemOperand(a0, offsetof(Test, c))); // c = 0 __ selnez(t3, t1, t1); // t3 = 1 __ sw(t3, MemOperand(a0, offsetof(Test, d))); // d = 1 // Floating point part of test. __ ldc1(f0, MemOperand(a0, offsetof(Test, e)) ); // src __ ldc1(f2, MemOperand(a0, offsetof(Test, f)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, i)) ); // src __ lwc1(f10, MemOperand(a0, offsetof(Test, j)) ); // test __ seleqz_d(f4, f0, f2); __ selnez_d(f6, f0, f2); __ seleqz_s(f12, f8, f10); __ selnez_s(f14, f8, f10); __ sdc1(f4, MemOperand(a0, offsetof(Test, g)) ); // src __ sdc1(f6, MemOperand(a0, offsetof(Test, h)) ); // src __ swc1(f12, MemOperand(a0, offsetof(Test, k)) ); // src __ swc1(f14, MemOperand(a0, offsetof(Test, l)) ); // src __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.a, 1); CHECK_EQ(test.b, 0); CHECK_EQ(test.c, 0); CHECK_EQ(test.d, 1); const int test_size = 3; const int input_size = 5; double inputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double outputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float inputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float outputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.e = inputs_D[i]; test.f = tests_D[j]; test.i = inputs_S[i]; test.j = tests_S[j]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, outputs_D[i]); CHECK_EQ(test.h, 0); CHECK_EQ(test.k, outputs_S[i]); CHECK_EQ(test.l, 0); test.f = tests_D[j+1]; test.j = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, 0); CHECK_EQ(test.h, outputs_D[i]); CHECK_EQ(test.k, 0); CHECK_EQ(test.l, outputs_S[i]); } } } } TEST(min_max) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); struct TestFloat { double a; double b; double c; double d; float e; float f; float g; float h; }; TestFloat test; const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); const int kTableLength = 13; double inputsa[kTableLength] = {2.0, 3.0, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = {3.0, 2.0, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double outputsdmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double outputsdmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputse[kTableLength] = {2.0, 3.0, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsf[kTableLength] = {3.0, 2.0, 3.0, fnan, 0.0, -0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float outputsfmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float outputsfmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a))); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, b))); __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, e))); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, f))); __ min_d(f10, f4, f8); __ max_d(f12, f4, f8); __ min_s(f14, f2, f6); __ max_s(f16, f2, f6); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, c))); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, d))); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, g))); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, h))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 4; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.e = inputse[i]; test.f = inputsf[i]; CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0); CHECK_EQ(0, memcmp(&test.c, &outputsdmin[i], sizeof(test.c))); CHECK_EQ(0, memcmp(&test.d, &outputsdmax[i], sizeof(test.d))); CHECK_EQ(0, memcmp(&test.g, &outputsfmin[i], sizeof(test.g))); CHECK_EQ(0, memcmp(&test.h, &outputsfmax[i], sizeof(test.h))); } } } TEST(rint_d) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; int fcsr; }TestFloat; TestFloat test; double inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E+308, 6.27463370218383111104242366943E-307, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ ctc1(t0, FCSR); __ rint_d(f8, f4); __ sdc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(sel) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { double dd; double ds; double dt; float fd; float fs; float ft; } Test; Test test; __ ldc1(f0, MemOperand(a0, offsetof(Test, dd)) ); // test __ ldc1(f2, MemOperand(a0, offsetof(Test, ds)) ); // src1 __ ldc1(f4, MemOperand(a0, offsetof(Test, dt)) ); // src2 __ lwc1(f6, MemOperand(a0, offsetof(Test, fd)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, fs)) ); // src1 __ lwc1(f10, MemOperand(a0, offsetof(Test, ft)) ); // src2 __ sel_d(f0, f2, f4); __ sel_s(f6, f8, f10); __ sdc1(f0, MemOperand(a0, offsetof(Test, dd)) ); __ swc1(f6, MemOperand(a0, offsetof(Test, fd)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); const int test_size = 3; const int input_size = 5; double inputs_dt[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double inputs_ds[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; float inputs_ft[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float inputs_fs[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.dt = inputs_dt[i]; test.dd = tests_D[j]; test.ds = inputs_ds[i]; test.ft = inputs_ft[i]; test.fd = tests_S[j]; test.fs = inputs_fs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_ds[i]); CHECK_EQ(test.fd, inputs_fs[i]); test.dd = tests_D[j+1]; test.fd = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_dt[i]); CHECK_EQ(test.fd, inputs_ft[i]); } } } } TEST(rint_s) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; int fcsr; }TestFloat; TestFloat test; float inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E+38, 6.27463370218383111104242366943E-37, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; float* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ rint_s(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(mina_maxa) { if (kArchVariant == kMips64r6) { const int kTableLength = 23; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); struct TestFloat { double a; double b; double resd; double resd1; float c; float d; float resf; float resf1; }; TestFloat test; double inputsa[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = { 4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double resd[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double resd1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputsc[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsd[kTableLength] = {4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, fnan, -0.0, 0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float resf[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float resf1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ lwc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ lwc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ mina_d(f6, f2, f4); __ mina_s(f12, f8, f10); __ maxa_d(f14, f2, f4); __ maxa_s(f16, f8, f10); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, resf)) ); __ sdc1(f6, MemOperand(a0, offsetof(TestFloat, resd)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resf1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resd1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.c = inputsc[i]; test.d = inputsd[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if (i < kTableLength - 1) { CHECK_EQ(test.resd, resd[i]); CHECK_EQ(test.resf, resf[i]); CHECK_EQ(test.resd1, resd1[i]); CHECK_EQ(test.resf1, resf1[i]); } else { CHECK(std::isnan(test.resd)); CHECK(std::isnan(test.resf)); CHECK(std::isnan(test.resd1)); CHECK(std::isnan(test.resf1)); } } } } // ----------------------mips64r2 specific tests---------------------- TEST(trunc_l) { if (kArchVariant == kMips64r2) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; // a trunc result int64_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_l_d(f8, f4); __ trunc_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } } TEST(movz_movn) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { int64_t rt; double a; double b; double bold; double b1; double bold1; float c; float d; float dold; float d1; float dold1; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ld(t0, MemOperand(a0, offsetof(TestFloat, rt))); __ Move(f12, 0.0); __ Move(f10, 0.0); __ Move(f16, 0.0); __ Move(f14, 0.0); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, bold)) ); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, dold)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, bold1)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, dold1)) ); __ movz_s(f10, f6, t0); __ movz_d(f12, f2, t0); __ movn_s(f14, f6, t0); __ movn_d(f16, f2, t0); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, b)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, d1)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, b1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; test.rt = 1; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, test.bold); CHECK_EQ(test.d, test.dold); CHECK_EQ(test.b1, outputs_D[i]); CHECK_EQ(test.d1, outputs_S[i]); test.rt = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); CHECK_EQ(test.b1, test.bold1); CHECK_EQ(test.d1, test.dold1); } } } TEST(movt_movd) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); typedef struct test_float { double srcd; double dstd; double dstdold; double dstd1; double dstdold1; float srcf; float dstf; float dstfold; float dstf1; float dstfold1; int32_t cc; int32_t fcsr; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; double inputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; int condition_flags[8] = {0, 1, 2, 3, 4, 5, 6, 7}; for (int i = 0; i < kTableLength; i++) { test.srcd = inputs_D[i]; test.srcf = inputs_S[i]; for (int j = 0; j< 8; j++) { test.cc = condition_flags[j]; if (test.cc == 0) { test.fcsr = 1 << 23; } else { test.fcsr = 1 << (24+condition_flags[j]); } HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, srcd)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, srcf)) ); __ lw(t1, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t0, FCSR); __ ctc1(t1, FCSR); __ li(t2, 0x0); __ mtc1(t2, f12); __ mtc1(t2, f10); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold)) ); __ movt_s(f12, f4, test.cc); __ movt_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold1)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold1)) ); __ movf_s(f12, f4, test.cc); __ movf_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf1)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd1)) ); __ ctc1(t0, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, outputs_S[i]); CHECK_EQ(test.dstd, outputs_D[i]); CHECK_EQ(test.dstf1, test.dstfold1); CHECK_EQ(test.dstd1, test.dstdold1); test.fcsr = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, test.dstfold); CHECK_EQ(test.dstd, test.dstdold); CHECK_EQ(test.dstf1, outputs_S[i]); CHECK_EQ(test.dstd1, outputs_D[i]); } } } } // ----------------------tests for all archs-------------------------- TEST(cvt_w_d) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; int32_t b; int fcsr; }Test; const int kTableLength = 24; double inputs[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, 2147483653.0 }; double outputs_RN[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RZ[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RP[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RM[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lw(t0, MemOperand(a0, offsetof(Test, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ cvt_w_d(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(Test, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } TEST(trunc_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_w_d(f8, f4); __ trunc_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_w_d(f8, f4); __ round_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_l_d(f8, f4); __ round_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(sub) { const int kTableLength = 12; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; double inputft_D[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; double outputs_D[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; float inputfs_S[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; float inputft_S[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; float outputs_S[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sub_s(f6, f2, f4); __ sub_d(f12, f8, f10); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(sqrt_rsqrt_recip) { const int kTableLength = 4; const double deltaDouble = 2E-15; const float deltaFloat = 2E-7; const float sqrt2_s = sqrt(2); const double sqrt2_d = sqrt(2); CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; float resultS1; float resultS2; double c; double resultD; double resultD1; double resultD2; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 0.0L, 4.0L, 2.0L, 4e-28L }; double outputs_D[kTableLength] = { 0.0L, 2.0L, sqrt2_d, 2e-14L }; float inputs_S[kTableLength] = { 0.0, 4.0, 2.0, 4e-28 }; float outputs_S[kTableLength] = { 0.0, 2.0, sqrt2_s, 2e-14 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ sqrt_s(f6, f2); __ sqrt_d(f12, f8); __ rsqrt_d(f14, f8); __ rsqrt_s(f16, f2); __ recip_d(f18, f8); __ recip_s(f4, f2); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resultS1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resultD1)) ); __ swc1(f4, MemOperand(a0, offsetof(TestFloat, resultS2)) ); __ sdc1(f18, MemOperand(a0, offsetof(TestFloat, resultD2)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { float f1; double d1; test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); if (i != 0) { f1 = test.resultS1 - 1.0F/outputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD1 - 1.0L/outputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); f1 = test.resultS2 - 1.0F/inputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD2 - 1.0L/inputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); } else { CHECK_EQ(test.resultS1, 1.0F/outputs_S[i]); CHECK_EQ(test.resultD1, 1.0L/outputs_D[i]); CHECK_EQ(test.resultS2, 1.0F/inputs_S[i]); CHECK_EQ(test.resultD2, 1.0L/inputs_D[i]); } } } TEST(neg) { const int kTableLength = 2; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; double c; double resultD; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 4.0, -2.0 }; double outputs_D[kTableLength] = { -4.0, 2.0 }; float inputs_S[kTableLength] = { 4.0, -2.0 }; float outputs_S[kTableLength] = { -4.0, 2.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ neg_s(f6, f2); __ neg_d(f12, f8); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); t.ui = 0x44332211; t.si = 0x99aabbcc; t.r1 = 0x5555555555555555; t.r2 = 0x5555555555555555; t.r3 = 0x5555555555555555; t.r4 = 0x5555555555555555; t.r5 = 0x5555555555555555; t.r6 = 0x5555555555555555; t.r7 = 0x5555555555555555; t.r8 = 0x5555555555555555; t.r9 = 0x5555555555555555; t.r10 = 0x5555555555555555; t.r11 = 0x5555555555555555; t.r12 = 0x5555555555555555; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); if (kArchEndian == kLittle) { // Unsigned data, 32 & 64 CHECK_EQ(static_cast(0x5555555544332211L), t.r1); // lw, sw. CHECK_EQ(static_cast(0x0000000044332211L), t.r2); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x5555555599aabbccL), t.r3); // lw, sw. CHECK_EQ(static_cast(0xffffffff99aabbccL), t.r4); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x5555555599aabbccL), t.r5); // lwu, sw. CHECK_EQ(static_cast(0x0000000099aabbccL), t.r6); // sd. // lh with unsigned and signed data. CHECK_EQ(static_cast(0x5555555500002211L), t.r7); // lh, sw. CHECK_EQ(static_cast(0x55555555ffffbbccL), t.r8); // lh, sw. // lhu with signed data. CHECK_EQ(static_cast(0x555555550000bbccL), t.r9); // lhu, sw. // lb with signed data. CHECK_EQ(static_cast(0x55555555ffffffccL), t.r10); // lb, sw. // sh with unsigned and signed data. CHECK_EQ(static_cast(0x5555555555552211L), t.r11); // lw, sh. CHECK_EQ(static_cast(0x555555555555bbccL), t.r12); // lw, sh. } else { // Unsigned data, 32 & 64 CHECK_EQ(static_cast(0x4433221155555555L), t.r1); // lw, sw. CHECK_EQ(static_cast(0x0000000044332211L), t.r2); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x99aabbcc55555555L), t.r3); // lw, sw. CHECK_EQ(static_cast(0xffffffff99aabbccL), t.r4); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x99aabbcc55555555L), t.r5); // lwu, sw. CHECK_EQ(static_cast(0x0000000099aabbccL), t.r6); // sd. // lh with unsigned and signed data. CHECK_EQ(static_cast(0x0000443355555555L), t.r7); // lh, sw. CHECK_EQ(static_cast(0xffff99aa55555555L), t.r8); // lh, sw. // lhu with signed data. CHECK_EQ(static_cast(0x000099aa55555555L), t.r9); // lhu, sw. // lb with signed data. CHECK_EQ(static_cast(0xffffff9955555555L), t.r10); // lb, sw. // sh with unsigned and signed data. CHECK_EQ(static_cast(0x2211555555555555L), t.r11); // lw, sh. CHECK_EQ(static_cast(0xbbcc555555555555L), t.r12); // lw, sh. } } // ----------------------mips64r6 specific tests---------------------- TEST(seleqz_selnez) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { int a; int b; int c; int d; double e; double f; double g; double h; float i; float j; float k; float l; } Test; Test test; // Integer part of test. __ addiu(t1, zero_reg, 1); // t1 = 1 __ seleqz(t3, t1, zero_reg); // t3 = 1 __ sw(t3, MemOperand(a0, offsetof(Test, a))); // a = 1 __ seleqz(t2, t1, t1); // t2 = 0 __ sw(t2, MemOperand(a0, offsetof(Test, b))); // b = 0 __ selnez(t3, t1, zero_reg); // t3 = 1; __ sw(t3, MemOperand(a0, offsetof(Test, c))); // c = 0 __ selnez(t3, t1, t1); // t3 = 1 __ sw(t3, MemOperand(a0, offsetof(Test, d))); // d = 1 // Floating point part of test. __ ldc1(f0, MemOperand(a0, offsetof(Test, e)) ); // src __ ldc1(f2, MemOperand(a0, offsetof(Test, f)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, i)) ); // src __ lwc1(f10, MemOperand(a0, offsetof(Test, j)) ); // test __ seleqz_d(f4, f0, f2); __ selnez_d(f6, f0, f2); __ seleqz_s(f12, f8, f10); __ selnez_s(f14, f8, f10); __ sdc1(f4, MemOperand(a0, offsetof(Test, g)) ); // src __ sdc1(f6, MemOperand(a0, offsetof(Test, h)) ); // src __ swc1(f12, MemOperand(a0, offsetof(Test, k)) ); // src __ swc1(f14, MemOperand(a0, offsetof(Test, l)) ); // src __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.a, 1); CHECK_EQ(test.b, 0); CHECK_EQ(test.c, 0); CHECK_EQ(test.d, 1); const int test_size = 3; const int input_size = 5; double inputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double outputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float inputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float outputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.e = inputs_D[i]; test.f = tests_D[j]; test.i = inputs_S[i]; test.j = tests_S[j]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, outputs_D[i]); CHECK_EQ(test.h, 0); CHECK_EQ(test.k, outputs_S[i]); CHECK_EQ(test.l, 0); test.f = tests_D[j+1]; test.j = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, 0); CHECK_EQ(test.h, outputs_D[i]); CHECK_EQ(test.k, 0); CHECK_EQ(test.l, outputs_S[i]); } } } } TEST(min_max) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); struct TestFloat { double a; double b; double c; double d; float e; float f; float g; float h; }; TestFloat test; const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); const int kTableLength = 13; double inputsa[kTableLength] = {2.0, 3.0, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = {3.0, 2.0, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double outputsdmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double outputsdmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputse[kTableLength] = {2.0, 3.0, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsf[kTableLength] = {3.0, 2.0, 3.0, fnan, 0.0, -0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float outputsfmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float outputsfmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a))); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, b))); __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, e))); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, f))); __ min_d(f10, f4, f8); __ max_d(f12, f4, f8); __ min_s(f14, f2, f6); __ max_s(f16, f2, f6); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, c))); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, d))); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, g))); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, h))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 4; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.e = inputse[i]; test.f = inputsf[i]; CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0); CHECK_EQ(0, memcmp(&test.c, &outputsdmin[i], sizeof(test.c))); CHECK_EQ(0, memcmp(&test.d, &outputsdmax[i], sizeof(test.d))); CHECK_EQ(0, memcmp(&test.g, &outputsfmin[i], sizeof(test.g))); CHECK_EQ(0, memcmp(&test.h, &outputsfmax[i], sizeof(test.h))); } } } TEST(rint_d) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; int fcsr; }TestFloat; TestFloat test; double inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E+308, 6.27463370218383111104242366943E-307, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ ctc1(t0, FCSR); __ rint_d(f8, f4); __ sdc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(sel) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { double dd; double ds; double dt; float fd; float fs; float ft; } Test; Test test; __ ldc1(f0, MemOperand(a0, offsetof(Test, dd)) ); // test __ ldc1(f2, MemOperand(a0, offsetof(Test, ds)) ); // src1 __ ldc1(f4, MemOperand(a0, offsetof(Test, dt)) ); // src2 __ lwc1(f6, MemOperand(a0, offsetof(Test, fd)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, fs)) ); // src1 __ lwc1(f10, MemOperand(a0, offsetof(Test, ft)) ); // src2 __ sel_d(f0, f2, f4); __ sel_s(f6, f8, f10); __ sdc1(f0, MemOperand(a0, offsetof(Test, dd)) ); __ swc1(f6, MemOperand(a0, offsetof(Test, fd)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); const int test_size = 3; const int input_size = 5; double inputs_dt[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double inputs_ds[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; float inputs_ft[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float inputs_fs[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.dt = inputs_dt[i]; test.dd = tests_D[j]; test.ds = inputs_ds[i]; test.ft = inputs_ft[i]; test.fd = tests_S[j]; test.fs = inputs_fs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_ds[i]); CHECK_EQ(test.fd, inputs_fs[i]); test.dd = tests_D[j+1]; test.fd = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_dt[i]); CHECK_EQ(test.fd, inputs_ft[i]); } } } } TEST(rint_s) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; int fcsr; }TestFloat; TestFloat test; float inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E+38, 6.27463370218383111104242366943E-37, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; float* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ rint_s(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(mina_maxa) { if (kArchVariant == kMips64r6) { const int kTableLength = 23; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); struct TestFloat { double a; double b; double resd; double resd1; float c; float d; float resf; float resf1; }; TestFloat test; double inputsa[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = { 4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double resd[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double resd1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputsc[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsd[kTableLength] = {4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, fnan, -0.0, 0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float resf[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float resf1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ lwc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ lwc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ mina_d(f6, f2, f4); __ mina_s(f12, f8, f10); __ maxa_d(f14, f2, f4); __ maxa_s(f16, f8, f10); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, resf)) ); __ sdc1(f6, MemOperand(a0, offsetof(TestFloat, resd)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resf1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resd1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.c = inputsc[i]; test.d = inputsd[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if (i < kTableLength - 1) { CHECK_EQ(test.resd, resd[i]); CHECK_EQ(test.resf, resf[i]); CHECK_EQ(test.resd1, resd1[i]); CHECK_EQ(test.resf1, resf1[i]); } else { CHECK(std::isnan(test.resd)); CHECK(std::isnan(test.resf)); CHECK(std::isnan(test.resd1)); CHECK(std::isnan(test.resf1)); } } } } // ----------------------mips64r2 specific tests---------------------- TEST(trunc_l) { if (kArchVariant == kMips64r2) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; // a trunc result int64_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_l_d(f8, f4); __ trunc_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } } TEST(movz_movn) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { int64_t rt; double a; double b; double bold; double b1; double bold1; float c; float d; float dold; float d1; float dold1; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ld(t0, MemOperand(a0, offsetof(TestFloat, rt))); __ Move(f12, 0.0); __ Move(f10, 0.0); __ Move(f16, 0.0); __ Move(f14, 0.0); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, bold)) ); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, dold)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, bold1)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, dold1)) ); __ movz_s(f10, f6, t0); __ movz_d(f12, f2, t0); __ movn_s(f14, f6, t0); __ movn_d(f16, f2, t0); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, b)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, d1)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, b1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; test.rt = 1; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, test.bold); CHECK_EQ(test.d, test.dold); CHECK_EQ(test.b1, outputs_D[i]); CHECK_EQ(test.d1, outputs_S[i]); test.rt = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); CHECK_EQ(test.b1, test.bold1); CHECK_EQ(test.d1, test.dold1); } } } TEST(movt_movd) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); typedef struct test_float { double srcd; double dstd; double dstdold; double dstd1; double dstdold1; float srcf; float dstf; float dstfold; float dstf1; float dstfold1; int32_t cc; int32_t fcsr; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; double inputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; int condition_flags[8] = {0, 1, 2, 3, 4, 5, 6, 7}; for (int i = 0; i < kTableLength; i++) { test.srcd = inputs_D[i]; test.srcf = inputs_S[i]; for (int j = 0; j< 8; j++) { test.cc = condition_flags[j]; if (test.cc == 0) { test.fcsr = 1 << 23; } else { test.fcsr = 1 << (24+condition_flags[j]); } HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, srcd)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, srcf)) ); __ lw(t1, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t0, FCSR); __ ctc1(t1, FCSR); __ li(t2, 0x0); __ mtc1(t2, f12); __ mtc1(t2, f10); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold)) ); __ movt_s(f12, f4, test.cc); __ movt_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold1)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold1)) ); __ movf_s(f12, f4, test.cc); __ movf_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf1)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd1)) ); __ ctc1(t0, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, outputs_S[i]); CHECK_EQ(test.dstd, outputs_D[i]); CHECK_EQ(test.dstf1, test.dstfold1); CHECK_EQ(test.dstd1, test.dstdold1); test.fcsr = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, test.dstfold); CHECK_EQ(test.dstd, test.dstdold); CHECK_EQ(test.dstf1, outputs_S[i]); CHECK_EQ(test.dstd1, outputs_D[i]); } } } } // ----------------------tests for all archs-------------------------- TEST(cvt_w_d) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; int32_t b; int fcsr; }Test; const int kTableLength = 24; double inputs[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, 2147483653.0 }; double outputs_RN[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RZ[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RP[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RM[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lw(t0, MemOperand(a0, offsetof(Test, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ cvt_w_d(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(Test, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } TEST(trunc_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_w_d(f8, f4); __ trunc_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_w_d(f8, f4); __ round_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_l_d(f8, f4); __ round_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(sub) { const int kTableLength = 12; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; double inputft_D[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; double outputs_D[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; float inputfs_S[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; float inputft_S[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; float outputs_S[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sub_s(f6, f2, f4); __ sub_d(f12, f8, f10); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(sqrt_rsqrt_recip) { const int kTableLength = 4; const double deltaDouble = 2E-15; const float deltaFloat = 2E-7; const float sqrt2_s = sqrt(2); const double sqrt2_d = sqrt(2); CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; float resultS1; float resultS2; double c; double resultD; double resultD1; double resultD2; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 0.0L, 4.0L, 2.0L, 4e-28L }; double outputs_D[kTableLength] = { 0.0L, 2.0L, sqrt2_d, 2e-14L }; float inputs_S[kTableLength] = { 0.0, 4.0, 2.0, 4e-28 }; float outputs_S[kTableLength] = { 0.0, 2.0, sqrt2_s, 2e-14 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ sqrt_s(f6, f2); __ sqrt_d(f12, f8); __ rsqrt_d(f14, f8); __ rsqrt_s(f16, f2); __ recip_d(f18, f8); __ recip_s(f4, f2); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resultS1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resultD1)) ); __ swc1(f4, MemOperand(a0, offsetof(TestFloat, resultS2)) ); __ sdc1(f18, MemOperand(a0, offsetof(TestFloat, resultD2)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { float f1; double d1; test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); if (i != 0) { f1 = test.resultS1 - 1.0F/outputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD1 - 1.0L/outputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); f1 = test.resultS2 - 1.0F/inputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD2 - 1.0L/inputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); } else { CHECK_EQ(test.resultS1, 1.0F/outputs_S[i]); CHECK_EQ(test.resultD1, 1.0L/outputs_D[i]); CHECK_EQ(test.resultS2, 1.0F/inputs_S[i]); CHECK_EQ(test.resultD2, 1.0L/inputs_D[i]); } } } TEST(neg) { const int kTableLength = 2; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; double c; double resultD; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 4.0, -2.0 }; double outputs_D[kTableLength] = { -4.0, 2.0 }; float inputs_S[kTableLength] = { 4.0, -2.0 }; float outputs_S[kTableLength] = { -4.0, 2.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ neg_s(f6, f2); __ neg_d(f12, f8); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
()); F3 f = FUNCTION_CAST(code->entry()); t.ui = 0x44332211; t.si = 0x99aabbcc; t.r1 = 0x5555555555555555; t.r2 = 0x5555555555555555; t.r3 = 0x5555555555555555; t.r4 = 0x5555555555555555; t.r5 = 0x5555555555555555; t.r6 = 0x5555555555555555; t.r7 = 0x5555555555555555; t.r8 = 0x5555555555555555; t.r9 = 0x5555555555555555; t.r10 = 0x5555555555555555; t.r11 = 0x5555555555555555; t.r12 = 0x5555555555555555; Object* dummy = CALL_GENERATED_CODE(isolate, f, &t, 0, 0, 0, 0); USE(dummy); if (kArchEndian == kLittle) { // Unsigned data, 32 & 64 CHECK_EQ(static_cast(0x5555555544332211L), t.r1); // lw, sw. CHECK_EQ(static_cast(0x0000000044332211L), t.r2); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x5555555599aabbccL), t.r3); // lw, sw. CHECK_EQ(static_cast(0xffffffff99aabbccL), t.r4); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x5555555599aabbccL), t.r5); // lwu, sw. CHECK_EQ(static_cast(0x0000000099aabbccL), t.r6); // sd. // lh with unsigned and signed data. CHECK_EQ(static_cast(0x5555555500002211L), t.r7); // lh, sw. CHECK_EQ(static_cast(0x55555555ffffbbccL), t.r8); // lh, sw. // lhu with signed data. CHECK_EQ(static_cast(0x555555550000bbccL), t.r9); // lhu, sw. // lb with signed data. CHECK_EQ(static_cast(0x55555555ffffffccL), t.r10); // lb, sw. // sh with unsigned and signed data. CHECK_EQ(static_cast(0x5555555555552211L), t.r11); // lw, sh. CHECK_EQ(static_cast(0x555555555555bbccL), t.r12); // lw, sh. } else { // Unsigned data, 32 & 64 CHECK_EQ(static_cast(0x4433221155555555L), t.r1); // lw, sw. CHECK_EQ(static_cast(0x0000000044332211L), t.r2); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x99aabbcc55555555L), t.r3); // lw, sw. CHECK_EQ(static_cast(0xffffffff99aabbccL), t.r4); // sd. // Signed data, 32 & 64. CHECK_EQ(static_cast(0x99aabbcc55555555L), t.r5); // lwu, sw. CHECK_EQ(static_cast(0x0000000099aabbccL), t.r6); // sd. // lh with unsigned and signed data. CHECK_EQ(static_cast(0x0000443355555555L), t.r7); // lh, sw. CHECK_EQ(static_cast(0xffff99aa55555555L), t.r8); // lh, sw. // lhu with signed data. CHECK_EQ(static_cast(0x000099aa55555555L), t.r9); // lhu, sw. // lb with signed data. CHECK_EQ(static_cast(0xffffff9955555555L), t.r10); // lb, sw. // sh with unsigned and signed data. CHECK_EQ(static_cast(0x2211555555555555L), t.r11); // lw, sh. CHECK_EQ(static_cast(0xbbcc555555555555L), t.r12); // lw, sh. } } // ----------------------mips64r6 specific tests---------------------- TEST(seleqz_selnez) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { int a; int b; int c; int d; double e; double f; double g; double h; float i; float j; float k; float l; } Test; Test test; // Integer part of test. __ addiu(t1, zero_reg, 1); // t1 = 1 __ seleqz(t3, t1, zero_reg); // t3 = 1 __ sw(t3, MemOperand(a0, offsetof(Test, a))); // a = 1 __ seleqz(t2, t1, t1); // t2 = 0 __ sw(t2, MemOperand(a0, offsetof(Test, b))); // b = 0 __ selnez(t3, t1, zero_reg); // t3 = 1; __ sw(t3, MemOperand(a0, offsetof(Test, c))); // c = 0 __ selnez(t3, t1, t1); // t3 = 1 __ sw(t3, MemOperand(a0, offsetof(Test, d))); // d = 1 // Floating point part of test. __ ldc1(f0, MemOperand(a0, offsetof(Test, e)) ); // src __ ldc1(f2, MemOperand(a0, offsetof(Test, f)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, i)) ); // src __ lwc1(f10, MemOperand(a0, offsetof(Test, j)) ); // test __ seleqz_d(f4, f0, f2); __ selnez_d(f6, f0, f2); __ seleqz_s(f12, f8, f10); __ selnez_s(f14, f8, f10); __ sdc1(f4, MemOperand(a0, offsetof(Test, g)) ); // src __ sdc1(f6, MemOperand(a0, offsetof(Test, h)) ); // src __ swc1(f12, MemOperand(a0, offsetof(Test, k)) ); // src __ swc1(f14, MemOperand(a0, offsetof(Test, l)) ); // src __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.a, 1); CHECK_EQ(test.b, 0); CHECK_EQ(test.c, 0); CHECK_EQ(test.d, 1); const int test_size = 3; const int input_size = 5; double inputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double outputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float inputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float outputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.e = inputs_D[i]; test.f = tests_D[j]; test.i = inputs_S[i]; test.j = tests_S[j]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, outputs_D[i]); CHECK_EQ(test.h, 0); CHECK_EQ(test.k, outputs_S[i]); CHECK_EQ(test.l, 0); test.f = tests_D[j+1]; test.j = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, 0); CHECK_EQ(test.h, outputs_D[i]); CHECK_EQ(test.k, 0); CHECK_EQ(test.l, outputs_S[i]); } } } } TEST(min_max) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); struct TestFloat { double a; double b; double c; double d; float e; float f; float g; float h; }; TestFloat test; const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); const int kTableLength = 13; double inputsa[kTableLength] = {2.0, 3.0, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = {3.0, 2.0, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double outputsdmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double outputsdmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputse[kTableLength] = {2.0, 3.0, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsf[kTableLength] = {3.0, 2.0, 3.0, fnan, 0.0, -0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float outputsfmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float outputsfmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a))); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, b))); __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, e))); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, f))); __ min_d(f10, f4, f8); __ max_d(f12, f4, f8); __ min_s(f14, f2, f6); __ max_s(f16, f2, f6); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, c))); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, d))); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, g))); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, h))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 4; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.e = inputse[i]; test.f = inputsf[i]; CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0); CHECK_EQ(0, memcmp(&test.c, &outputsdmin[i], sizeof(test.c))); CHECK_EQ(0, memcmp(&test.d, &outputsdmax[i], sizeof(test.d))); CHECK_EQ(0, memcmp(&test.g, &outputsfmin[i], sizeof(test.g))); CHECK_EQ(0, memcmp(&test.h, &outputsfmax[i], sizeof(test.h))); } } } TEST(rint_d) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; int fcsr; }TestFloat; TestFloat test; double inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E+308, 6.27463370218383111104242366943E-307, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ ctc1(t0, FCSR); __ rint_d(f8, f4); __ sdc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(sel) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { double dd; double ds; double dt; float fd; float fs; float ft; } Test; Test test; __ ldc1(f0, MemOperand(a0, offsetof(Test, dd)) ); // test __ ldc1(f2, MemOperand(a0, offsetof(Test, ds)) ); // src1 __ ldc1(f4, MemOperand(a0, offsetof(Test, dt)) ); // src2 __ lwc1(f6, MemOperand(a0, offsetof(Test, fd)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, fs)) ); // src1 __ lwc1(f10, MemOperand(a0, offsetof(Test, ft)) ); // src2 __ sel_d(f0, f2, f4); __ sel_s(f6, f8, f10); __ sdc1(f0, MemOperand(a0, offsetof(Test, dd)) ); __ swc1(f6, MemOperand(a0, offsetof(Test, fd)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); const int test_size = 3; const int input_size = 5; double inputs_dt[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double inputs_ds[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; float inputs_ft[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float inputs_fs[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.dt = inputs_dt[i]; test.dd = tests_D[j]; test.ds = inputs_ds[i]; test.ft = inputs_ft[i]; test.fd = tests_S[j]; test.fs = inputs_fs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_ds[i]); CHECK_EQ(test.fd, inputs_fs[i]); test.dd = tests_D[j+1]; test.fd = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_dt[i]); CHECK_EQ(test.fd, inputs_ft[i]); } } } } TEST(rint_s) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; int fcsr; }TestFloat; TestFloat test; float inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E+38, 6.27463370218383111104242366943E-37, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; float* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ rint_s(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(mina_maxa) { if (kArchVariant == kMips64r6) { const int kTableLength = 23; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); struct TestFloat { double a; double b; double resd; double resd1; float c; float d; float resf; float resf1; }; TestFloat test; double inputsa[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = { 4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double resd[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double resd1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputsc[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsd[kTableLength] = {4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, fnan, -0.0, 0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float resf[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float resf1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ lwc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ lwc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ mina_d(f6, f2, f4); __ mina_s(f12, f8, f10); __ maxa_d(f14, f2, f4); __ maxa_s(f16, f8, f10); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, resf)) ); __ sdc1(f6, MemOperand(a0, offsetof(TestFloat, resd)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resf1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resd1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.c = inputsc[i]; test.d = inputsd[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if (i < kTableLength - 1) { CHECK_EQ(test.resd, resd[i]); CHECK_EQ(test.resf, resf[i]); CHECK_EQ(test.resd1, resd1[i]); CHECK_EQ(test.resf1, resf1[i]); } else { CHECK(std::isnan(test.resd)); CHECK(std::isnan(test.resf)); CHECK(std::isnan(test.resd1)); CHECK(std::isnan(test.resf1)); } } } } // ----------------------mips64r2 specific tests---------------------- TEST(trunc_l) { if (kArchVariant == kMips64r2) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; // a trunc result int64_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_l_d(f8, f4); __ trunc_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } } TEST(movz_movn) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { int64_t rt; double a; double b; double bold; double b1; double bold1; float c; float d; float dold; float d1; float dold1; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ld(t0, MemOperand(a0, offsetof(TestFloat, rt))); __ Move(f12, 0.0); __ Move(f10, 0.0); __ Move(f16, 0.0); __ Move(f14, 0.0); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, bold)) ); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, dold)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, bold1)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, dold1)) ); __ movz_s(f10, f6, t0); __ movz_d(f12, f2, t0); __ movn_s(f14, f6, t0); __ movn_d(f16, f2, t0); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, b)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, d1)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, b1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; test.rt = 1; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, test.bold); CHECK_EQ(test.d, test.dold); CHECK_EQ(test.b1, outputs_D[i]); CHECK_EQ(test.d1, outputs_S[i]); test.rt = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); CHECK_EQ(test.b1, test.bold1); CHECK_EQ(test.d1, test.dold1); } } } TEST(movt_movd) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); typedef struct test_float { double srcd; double dstd; double dstdold; double dstd1; double dstdold1; float srcf; float dstf; float dstfold; float dstf1; float dstfold1; int32_t cc; int32_t fcsr; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; double inputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; int condition_flags[8] = {0, 1, 2, 3, 4, 5, 6, 7}; for (int i = 0; i < kTableLength; i++) { test.srcd = inputs_D[i]; test.srcf = inputs_S[i]; for (int j = 0; j< 8; j++) { test.cc = condition_flags[j]; if (test.cc == 0) { test.fcsr = 1 << 23; } else { test.fcsr = 1 << (24+condition_flags[j]); } HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, srcd)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, srcf)) ); __ lw(t1, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t0, FCSR); __ ctc1(t1, FCSR); __ li(t2, 0x0); __ mtc1(t2, f12); __ mtc1(t2, f10); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold)) ); __ movt_s(f12, f4, test.cc); __ movt_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold1)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold1)) ); __ movf_s(f12, f4, test.cc); __ movf_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf1)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd1)) ); __ ctc1(t0, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, outputs_S[i]); CHECK_EQ(test.dstd, outputs_D[i]); CHECK_EQ(test.dstf1, test.dstfold1); CHECK_EQ(test.dstd1, test.dstdold1); test.fcsr = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, test.dstfold); CHECK_EQ(test.dstd, test.dstdold); CHECK_EQ(test.dstf1, outputs_S[i]); CHECK_EQ(test.dstd1, outputs_D[i]); } } } } // ----------------------tests for all archs-------------------------- TEST(cvt_w_d) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; int32_t b; int fcsr; }Test; const int kTableLength = 24; double inputs[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, 2147483653.0 }; double outputs_RN[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RZ[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RP[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RM[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lw(t0, MemOperand(a0, offsetof(Test, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ cvt_w_d(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(Test, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } TEST(trunc_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_w_d(f8, f4); __ trunc_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_w_d(f8, f4); __ round_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_l_d(f8, f4); __ round_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(sub) { const int kTableLength = 12; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; double inputft_D[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; double outputs_D[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; float inputfs_S[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; float inputft_S[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; float outputs_S[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sub_s(f6, f2, f4); __ sub_d(f12, f8, f10); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(sqrt_rsqrt_recip) { const int kTableLength = 4; const double deltaDouble = 2E-15; const float deltaFloat = 2E-7; const float sqrt2_s = sqrt(2); const double sqrt2_d = sqrt(2); CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; float resultS1; float resultS2; double c; double resultD; double resultD1; double resultD2; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 0.0L, 4.0L, 2.0L, 4e-28L }; double outputs_D[kTableLength] = { 0.0L, 2.0L, sqrt2_d, 2e-14L }; float inputs_S[kTableLength] = { 0.0, 4.0, 2.0, 4e-28 }; float outputs_S[kTableLength] = { 0.0, 2.0, sqrt2_s, 2e-14 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ sqrt_s(f6, f2); __ sqrt_d(f12, f8); __ rsqrt_d(f14, f8); __ rsqrt_s(f16, f2); __ recip_d(f18, f8); __ recip_s(f4, f2); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resultS1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resultD1)) ); __ swc1(f4, MemOperand(a0, offsetof(TestFloat, resultS2)) ); __ sdc1(f18, MemOperand(a0, offsetof(TestFloat, resultD2)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { float f1; double d1; test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); if (i != 0) { f1 = test.resultS1 - 1.0F/outputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD1 - 1.0L/outputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); f1 = test.resultS2 - 1.0F/inputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD2 - 1.0L/inputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); } else { CHECK_EQ(test.resultS1, 1.0F/outputs_S[i]); CHECK_EQ(test.resultD1, 1.0L/outputs_D[i]); CHECK_EQ(test.resultS2, 1.0F/inputs_S[i]); CHECK_EQ(test.resultD2, 1.0L/inputs_D[i]); } } } TEST(neg) { const int kTableLength = 2; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; double c; double resultD; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 4.0, -2.0 }; double outputs_D[kTableLength] = { -4.0, 2.0 }; float inputs_S[kTableLength] = { 4.0, -2.0 }; float outputs_S[kTableLength] = { -4.0, 2.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ neg_s(f6, f2); __ neg_d(f12, f8); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.a, 1); CHECK_EQ(test.b, 0); CHECK_EQ(test.c, 0); CHECK_EQ(test.d, 1); const int test_size = 3; const int input_size = 5; double inputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double outputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float inputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float outputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.e = inputs_D[i]; test.f = tests_D[j]; test.i = inputs_S[i]; test.j = tests_S[j]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, outputs_D[i]); CHECK_EQ(test.h, 0); CHECK_EQ(test.k, outputs_S[i]); CHECK_EQ(test.l, 0); test.f = tests_D[j+1]; test.j = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, 0); CHECK_EQ(test.h, outputs_D[i]); CHECK_EQ(test.k, 0); CHECK_EQ(test.l, outputs_S[i]); } } } } TEST(min_max) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); struct TestFloat { double a; double b; double c; double d; float e; float f; float g; float h; }; TestFloat test; const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); const int kTableLength = 13; double inputsa[kTableLength] = {2.0, 3.0, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = {3.0, 2.0, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double outputsdmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double outputsdmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputse[kTableLength] = {2.0, 3.0, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsf[kTableLength] = {3.0, 2.0, 3.0, fnan, 0.0, -0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float outputsfmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float outputsfmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a))); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, b))); __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, e))); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, f))); __ min_d(f10, f4, f8); __ max_d(f12, f4, f8); __ min_s(f14, f2, f6); __ max_s(f16, f2, f6); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, c))); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, d))); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, g))); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, h))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 4; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.e = inputse[i]; test.f = inputsf[i]; CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0); CHECK_EQ(0, memcmp(&test.c, &outputsdmin[i], sizeof(test.c))); CHECK_EQ(0, memcmp(&test.d, &outputsdmax[i], sizeof(test.d))); CHECK_EQ(0, memcmp(&test.g, &outputsfmin[i], sizeof(test.g))); CHECK_EQ(0, memcmp(&test.h, &outputsfmax[i], sizeof(test.h))); } } } TEST(rint_d) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; int fcsr; }TestFloat; TestFloat test; double inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E+308, 6.27463370218383111104242366943E-307, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ ctc1(t0, FCSR); __ rint_d(f8, f4); __ sdc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(sel) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { double dd; double ds; double dt; float fd; float fs; float ft; } Test; Test test; __ ldc1(f0, MemOperand(a0, offsetof(Test, dd)) ); // test __ ldc1(f2, MemOperand(a0, offsetof(Test, ds)) ); // src1 __ ldc1(f4, MemOperand(a0, offsetof(Test, dt)) ); // src2 __ lwc1(f6, MemOperand(a0, offsetof(Test, fd)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, fs)) ); // src1 __ lwc1(f10, MemOperand(a0, offsetof(Test, ft)) ); // src2 __ sel_d(f0, f2, f4); __ sel_s(f6, f8, f10); __ sdc1(f0, MemOperand(a0, offsetof(Test, dd)) ); __ swc1(f6, MemOperand(a0, offsetof(Test, fd)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); const int test_size = 3; const int input_size = 5; double inputs_dt[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double inputs_ds[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; float inputs_ft[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float inputs_fs[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.dt = inputs_dt[i]; test.dd = tests_D[j]; test.ds = inputs_ds[i]; test.ft = inputs_ft[i]; test.fd = tests_S[j]; test.fs = inputs_fs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_ds[i]); CHECK_EQ(test.fd, inputs_fs[i]); test.dd = tests_D[j+1]; test.fd = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_dt[i]); CHECK_EQ(test.fd, inputs_ft[i]); } } } } TEST(rint_s) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; int fcsr; }TestFloat; TestFloat test; float inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E+38, 6.27463370218383111104242366943E-37, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; float* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ rint_s(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(mina_maxa) { if (kArchVariant == kMips64r6) { const int kTableLength = 23; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); struct TestFloat { double a; double b; double resd; double resd1; float c; float d; float resf; float resf1; }; TestFloat test; double inputsa[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = { 4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double resd[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double resd1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputsc[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsd[kTableLength] = {4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, fnan, -0.0, 0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float resf[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float resf1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ lwc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ lwc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ mina_d(f6, f2, f4); __ mina_s(f12, f8, f10); __ maxa_d(f14, f2, f4); __ maxa_s(f16, f8, f10); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, resf)) ); __ sdc1(f6, MemOperand(a0, offsetof(TestFloat, resd)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resf1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resd1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.c = inputsc[i]; test.d = inputsd[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if (i < kTableLength - 1) { CHECK_EQ(test.resd, resd[i]); CHECK_EQ(test.resf, resf[i]); CHECK_EQ(test.resd1, resd1[i]); CHECK_EQ(test.resf1, resf1[i]); } else { CHECK(std::isnan(test.resd)); CHECK(std::isnan(test.resf)); CHECK(std::isnan(test.resd1)); CHECK(std::isnan(test.resf1)); } } } } // ----------------------mips64r2 specific tests---------------------- TEST(trunc_l) { if (kArchVariant == kMips64r2) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; // a trunc result int64_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_l_d(f8, f4); __ trunc_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } } TEST(movz_movn) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { int64_t rt; double a; double b; double bold; double b1; double bold1; float c; float d; float dold; float d1; float dold1; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ld(t0, MemOperand(a0, offsetof(TestFloat, rt))); __ Move(f12, 0.0); __ Move(f10, 0.0); __ Move(f16, 0.0); __ Move(f14, 0.0); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, bold)) ); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, dold)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, bold1)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, dold1)) ); __ movz_s(f10, f6, t0); __ movz_d(f12, f2, t0); __ movn_s(f14, f6, t0); __ movn_d(f16, f2, t0); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, b)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, d1)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, b1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; test.rt = 1; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, test.bold); CHECK_EQ(test.d, test.dold); CHECK_EQ(test.b1, outputs_D[i]); CHECK_EQ(test.d1, outputs_S[i]); test.rt = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); CHECK_EQ(test.b1, test.bold1); CHECK_EQ(test.d1, test.dold1); } } } TEST(movt_movd) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); typedef struct test_float { double srcd; double dstd; double dstdold; double dstd1; double dstdold1; float srcf; float dstf; float dstfold; float dstf1; float dstfold1; int32_t cc; int32_t fcsr; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; double inputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; int condition_flags[8] = {0, 1, 2, 3, 4, 5, 6, 7}; for (int i = 0; i < kTableLength; i++) { test.srcd = inputs_D[i]; test.srcf = inputs_S[i]; for (int j = 0; j< 8; j++) { test.cc = condition_flags[j]; if (test.cc == 0) { test.fcsr = 1 << 23; } else { test.fcsr = 1 << (24+condition_flags[j]); } HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, srcd)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, srcf)) ); __ lw(t1, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t0, FCSR); __ ctc1(t1, FCSR); __ li(t2, 0x0); __ mtc1(t2, f12); __ mtc1(t2, f10); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold)) ); __ movt_s(f12, f4, test.cc); __ movt_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold1)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold1)) ); __ movf_s(f12, f4, test.cc); __ movf_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf1)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd1)) ); __ ctc1(t0, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, outputs_S[i]); CHECK_EQ(test.dstd, outputs_D[i]); CHECK_EQ(test.dstf1, test.dstfold1); CHECK_EQ(test.dstd1, test.dstdold1); test.fcsr = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, test.dstfold); CHECK_EQ(test.dstd, test.dstdold); CHECK_EQ(test.dstf1, outputs_S[i]); CHECK_EQ(test.dstd1, outputs_D[i]); } } } } // ----------------------tests for all archs-------------------------- TEST(cvt_w_d) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; int32_t b; int fcsr; }Test; const int kTableLength = 24; double inputs[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, 2147483653.0 }; double outputs_RN[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RZ[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RP[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RM[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lw(t0, MemOperand(a0, offsetof(Test, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ cvt_w_d(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(Test, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } TEST(trunc_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_w_d(f8, f4); __ trunc_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_w_d(f8, f4); __ round_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_l_d(f8, f4); __ round_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(sub) { const int kTableLength = 12; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; double inputft_D[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; double outputs_D[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; float inputfs_S[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; float inputft_S[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; float outputs_S[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sub_s(f6, f2, f4); __ sub_d(f12, f8, f10); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(sqrt_rsqrt_recip) { const int kTableLength = 4; const double deltaDouble = 2E-15; const float deltaFloat = 2E-7; const float sqrt2_s = sqrt(2); const double sqrt2_d = sqrt(2); CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; float resultS1; float resultS2; double c; double resultD; double resultD1; double resultD2; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 0.0L, 4.0L, 2.0L, 4e-28L }; double outputs_D[kTableLength] = { 0.0L, 2.0L, sqrt2_d, 2e-14L }; float inputs_S[kTableLength] = { 0.0, 4.0, 2.0, 4e-28 }; float outputs_S[kTableLength] = { 0.0, 2.0, sqrt2_s, 2e-14 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ sqrt_s(f6, f2); __ sqrt_d(f12, f8); __ rsqrt_d(f14, f8); __ rsqrt_s(f16, f2); __ recip_d(f18, f8); __ recip_s(f4, f2); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resultS1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resultD1)) ); __ swc1(f4, MemOperand(a0, offsetof(TestFloat, resultS2)) ); __ sdc1(f18, MemOperand(a0, offsetof(TestFloat, resultD2)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { float f1; double d1; test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); if (i != 0) { f1 = test.resultS1 - 1.0F/outputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD1 - 1.0L/outputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); f1 = test.resultS2 - 1.0F/inputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD2 - 1.0L/inputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); } else { CHECK_EQ(test.resultS1, 1.0F/outputs_S[i]); CHECK_EQ(test.resultD1, 1.0L/outputs_D[i]); CHECK_EQ(test.resultS2, 1.0F/inputs_S[i]); CHECK_EQ(test.resultD2, 1.0L/inputs_D[i]); } } } TEST(neg) { const int kTableLength = 2; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; double c; double resultD; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 4.0, -2.0 }; double outputs_D[kTableLength] = { -4.0, 2.0 }; float inputs_S[kTableLength] = { 4.0, -2.0 }; float outputs_S[kTableLength] = { -4.0, 2.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ neg_s(f6, f2); __ neg_d(f12, f8); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.a, 1); CHECK_EQ(test.b, 0); CHECK_EQ(test.c, 0); CHECK_EQ(test.d, 1); const int test_size = 3; const int input_size = 5; double inputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double outputs_D[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float inputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float outputs_S[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.e = inputs_D[i]; test.f = tests_D[j]; test.i = inputs_S[i]; test.j = tests_S[j]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, outputs_D[i]); CHECK_EQ(test.h, 0); CHECK_EQ(test.k, outputs_S[i]); CHECK_EQ(test.l, 0); test.f = tests_D[j+1]; test.j = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.g, 0); CHECK_EQ(test.h, outputs_D[i]); CHECK_EQ(test.k, 0); CHECK_EQ(test.l, outputs_S[i]); } } } } TEST(min_max) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); struct TestFloat { double a; double b; double c; double d; float e; float f; float g; float h; }; TestFloat test; const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); const int kTableLength = 13; double inputsa[kTableLength] = {2.0, 3.0, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = {3.0, 2.0, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double outputsdmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double outputsdmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputse[kTableLength] = {2.0, 3.0, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsf[kTableLength] = {3.0, 2.0, 3.0, fnan, 0.0, -0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float outputsfmin[kTableLength] = {2.0, 2.0, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float outputsfmax[kTableLength] = {3.0, 3.0, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a))); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, b))); __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, e))); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, f))); __ min_d(f10, f4, f8); __ max_d(f12, f4, f8); __ min_s(f14, f2, f6); __ max_s(f16, f2, f6); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, c))); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, d))); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, g))); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, h))); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 4; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.e = inputse[i]; test.f = inputsf[i]; CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0); CHECK_EQ(0, memcmp(&test.c, &outputsdmin[i], sizeof(test.c))); CHECK_EQ(0, memcmp(&test.d, &outputsdmax[i], sizeof(test.d))); CHECK_EQ(0, memcmp(&test.g, &outputsfmin[i], sizeof(test.g))); CHECK_EQ(0, memcmp(&test.h, &outputsfmax[i], sizeof(test.h))); } } } TEST(rint_d) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; int fcsr; }TestFloat; TestFloat test; double inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E+308, 6.27463370218383111104242366943E-307, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ ctc1(t0, FCSR); __ rint_d(f8, f4); __ sdc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(sel) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { double dd; double ds; double dt; float fd; float fs; float ft; } Test; Test test; __ ldc1(f0, MemOperand(a0, offsetof(Test, dd)) ); // test __ ldc1(f2, MemOperand(a0, offsetof(Test, ds)) ); // src1 __ ldc1(f4, MemOperand(a0, offsetof(Test, dt)) ); // src2 __ lwc1(f6, MemOperand(a0, offsetof(Test, fd)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, fs)) ); // src1 __ lwc1(f10, MemOperand(a0, offsetof(Test, ft)) ); // src2 __ sel_d(f0, f2, f4); __ sel_s(f6, f8, f10); __ sdc1(f0, MemOperand(a0, offsetof(Test, dd)) ); __ swc1(f6, MemOperand(a0, offsetof(Test, fd)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); const int test_size = 3; const int input_size = 5; double inputs_dt[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double inputs_ds[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; float inputs_ft[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float inputs_fs[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.dt = inputs_dt[i]; test.dd = tests_D[j]; test.ds = inputs_ds[i]; test.ft = inputs_ft[i]; test.fd = tests_S[j]; test.fs = inputs_fs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_ds[i]); CHECK_EQ(test.fd, inputs_fs[i]); test.dd = tests_D[j+1]; test.fd = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_dt[i]); CHECK_EQ(test.fd, inputs_ft[i]); } } } } TEST(rint_s) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; int fcsr; }TestFloat; TestFloat test; float inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E+38, 6.27463370218383111104242366943E-37, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; float* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ rint_s(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(mina_maxa) { if (kArchVariant == kMips64r6) { const int kTableLength = 23; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); struct TestFloat { double a; double b; double resd; double resd1; float c; float d; float resf; float resf1; }; TestFloat test; double inputsa[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = { 4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double resd[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double resd1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputsc[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsd[kTableLength] = {4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, fnan, -0.0, 0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float resf[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float resf1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ lwc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ lwc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ mina_d(f6, f2, f4); __ mina_s(f12, f8, f10); __ maxa_d(f14, f2, f4); __ maxa_s(f16, f8, f10); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, resf)) ); __ sdc1(f6, MemOperand(a0, offsetof(TestFloat, resd)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resf1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resd1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.c = inputsc[i]; test.d = inputsd[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if (i < kTableLength - 1) { CHECK_EQ(test.resd, resd[i]); CHECK_EQ(test.resf, resf[i]); CHECK_EQ(test.resd1, resd1[i]); CHECK_EQ(test.resf1, resf1[i]); } else { CHECK(std::isnan(test.resd)); CHECK(std::isnan(test.resf)); CHECK(std::isnan(test.resd1)); CHECK(std::isnan(test.resf1)); } } } } // ----------------------mips64r2 specific tests---------------------- TEST(trunc_l) { if (kArchVariant == kMips64r2) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; // a trunc result int64_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_l_d(f8, f4); __ trunc_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } } TEST(movz_movn) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { int64_t rt; double a; double b; double bold; double b1; double bold1; float c; float d; float dold; float d1; float dold1; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ld(t0, MemOperand(a0, offsetof(TestFloat, rt))); __ Move(f12, 0.0); __ Move(f10, 0.0); __ Move(f16, 0.0); __ Move(f14, 0.0); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, bold)) ); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, dold)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, bold1)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, dold1)) ); __ movz_s(f10, f6, t0); __ movz_d(f12, f2, t0); __ movn_s(f14, f6, t0); __ movn_d(f16, f2, t0); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, b)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, d1)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, b1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; test.rt = 1; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, test.bold); CHECK_EQ(test.d, test.dold); CHECK_EQ(test.b1, outputs_D[i]); CHECK_EQ(test.d1, outputs_S[i]); test.rt = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); CHECK_EQ(test.b1, test.bold1); CHECK_EQ(test.d1, test.dold1); } } } TEST(movt_movd) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); typedef struct test_float { double srcd; double dstd; double dstdold; double dstd1; double dstdold1; float srcf; float dstf; float dstfold; float dstf1; float dstfold1; int32_t cc; int32_t fcsr; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; double inputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; int condition_flags[8] = {0, 1, 2, 3, 4, 5, 6, 7}; for (int i = 0; i < kTableLength; i++) { test.srcd = inputs_D[i]; test.srcf = inputs_S[i]; for (int j = 0; j< 8; j++) { test.cc = condition_flags[j]; if (test.cc == 0) { test.fcsr = 1 << 23; } else { test.fcsr = 1 << (24+condition_flags[j]); } HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, srcd)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, srcf)) ); __ lw(t1, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t0, FCSR); __ ctc1(t1, FCSR); __ li(t2, 0x0); __ mtc1(t2, f12); __ mtc1(t2, f10); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold)) ); __ movt_s(f12, f4, test.cc); __ movt_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold1)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold1)) ); __ movf_s(f12, f4, test.cc); __ movf_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf1)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd1)) ); __ ctc1(t0, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, outputs_S[i]); CHECK_EQ(test.dstd, outputs_D[i]); CHECK_EQ(test.dstf1, test.dstfold1); CHECK_EQ(test.dstd1, test.dstdold1); test.fcsr = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, test.dstfold); CHECK_EQ(test.dstd, test.dstdold); CHECK_EQ(test.dstf1, outputs_S[i]); CHECK_EQ(test.dstd1, outputs_D[i]); } } } } // ----------------------tests for all archs-------------------------- TEST(cvt_w_d) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; int32_t b; int fcsr; }Test; const int kTableLength = 24; double inputs[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, 2147483653.0 }; double outputs_RN[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RZ[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RP[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RM[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lw(t0, MemOperand(a0, offsetof(Test, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ cvt_w_d(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(Test, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } TEST(trunc_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_w_d(f8, f4); __ trunc_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_w_d(f8, f4); __ round_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_l_d(f8, f4); __ round_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(sub) { const int kTableLength = 12; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; double inputft_D[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; double outputs_D[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; float inputfs_S[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; float inputft_S[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; float outputs_S[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sub_s(f6, f2, f4); __ sub_d(f12, f8, f10); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(sqrt_rsqrt_recip) { const int kTableLength = 4; const double deltaDouble = 2E-15; const float deltaFloat = 2E-7; const float sqrt2_s = sqrt(2); const double sqrt2_d = sqrt(2); CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; float resultS1; float resultS2; double c; double resultD; double resultD1; double resultD2; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 0.0L, 4.0L, 2.0L, 4e-28L }; double outputs_D[kTableLength] = { 0.0L, 2.0L, sqrt2_d, 2e-14L }; float inputs_S[kTableLength] = { 0.0, 4.0, 2.0, 4e-28 }; float outputs_S[kTableLength] = { 0.0, 2.0, sqrt2_s, 2e-14 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ sqrt_s(f6, f2); __ sqrt_d(f12, f8); __ rsqrt_d(f14, f8); __ rsqrt_s(f16, f2); __ recip_d(f18, f8); __ recip_s(f4, f2); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resultS1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resultD1)) ); __ swc1(f4, MemOperand(a0, offsetof(TestFloat, resultS2)) ); __ sdc1(f18, MemOperand(a0, offsetof(TestFloat, resultD2)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { float f1; double d1; test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); if (i != 0) { f1 = test.resultS1 - 1.0F/outputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD1 - 1.0L/outputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); f1 = test.resultS2 - 1.0F/inputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD2 - 1.0L/inputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); } else { CHECK_EQ(test.resultS1, 1.0F/outputs_S[i]); CHECK_EQ(test.resultD1, 1.0L/outputs_D[i]); CHECK_EQ(test.resultS2, 1.0F/inputs_S[i]); CHECK_EQ(test.resultD2, 1.0L/inputs_D[i]); } } } TEST(neg) { const int kTableLength = 2; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; double c; double resultD; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 4.0, -2.0 }; double outputs_D[kTableLength] = { -4.0, 2.0 }; float inputs_S[kTableLength] = { 4.0, -2.0 }; float outputs_S[kTableLength] = { -4.0, 2.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ neg_s(f6, f2); __ neg_d(f12, f8); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 4; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.e = inputse[i]; test.f = inputsf[i]; CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0); CHECK_EQ(0, memcmp(&test.c, &outputsdmin[i], sizeof(test.c))); CHECK_EQ(0, memcmp(&test.d, &outputsdmax[i], sizeof(test.d))); CHECK_EQ(0, memcmp(&test.g, &outputsfmin[i], sizeof(test.g))); CHECK_EQ(0, memcmp(&test.h, &outputsfmax[i], sizeof(test.h))); } } } TEST(rint_d) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; int fcsr; }TestFloat; TestFloat test; double inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E+308, 6.27463370218383111104242366943E-307, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ ctc1(t0, FCSR); __ rint_d(f8, f4); __ sdc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(sel) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { double dd; double ds; double dt; float fd; float fs; float ft; } Test; Test test; __ ldc1(f0, MemOperand(a0, offsetof(Test, dd)) ); // test __ ldc1(f2, MemOperand(a0, offsetof(Test, ds)) ); // src1 __ ldc1(f4, MemOperand(a0, offsetof(Test, dt)) ); // src2 __ lwc1(f6, MemOperand(a0, offsetof(Test, fd)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, fs)) ); // src1 __ lwc1(f10, MemOperand(a0, offsetof(Test, ft)) ); // src2 __ sel_d(f0, f2, f4); __ sel_s(f6, f8, f10); __ sdc1(f0, MemOperand(a0, offsetof(Test, dd)) ); __ swc1(f6, MemOperand(a0, offsetof(Test, fd)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); const int test_size = 3; const int input_size = 5; double inputs_dt[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double inputs_ds[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; float inputs_ft[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float inputs_fs[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.dt = inputs_dt[i]; test.dd = tests_D[j]; test.ds = inputs_ds[i]; test.ft = inputs_ft[i]; test.fd = tests_S[j]; test.fs = inputs_fs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_ds[i]); CHECK_EQ(test.fd, inputs_fs[i]); test.dd = tests_D[j+1]; test.fd = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_dt[i]); CHECK_EQ(test.fd, inputs_ft[i]); } } } } TEST(rint_s) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; int fcsr; }TestFloat; TestFloat test; float inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E+38, 6.27463370218383111104242366943E-37, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; float* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ rint_s(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(mina_maxa) { if (kArchVariant == kMips64r6) { const int kTableLength = 23; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); struct TestFloat { double a; double b; double resd; double resd1; float c; float d; float resf; float resf1; }; TestFloat test; double inputsa[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = { 4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double resd[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double resd1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputsc[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsd[kTableLength] = {4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, fnan, -0.0, 0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float resf[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float resf1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ lwc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ lwc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ mina_d(f6, f2, f4); __ mina_s(f12, f8, f10); __ maxa_d(f14, f2, f4); __ maxa_s(f16, f8, f10); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, resf)) ); __ sdc1(f6, MemOperand(a0, offsetof(TestFloat, resd)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resf1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resd1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.c = inputsc[i]; test.d = inputsd[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if (i < kTableLength - 1) { CHECK_EQ(test.resd, resd[i]); CHECK_EQ(test.resf, resf[i]); CHECK_EQ(test.resd1, resd1[i]); CHECK_EQ(test.resf1, resf1[i]); } else { CHECK(std::isnan(test.resd)); CHECK(std::isnan(test.resf)); CHECK(std::isnan(test.resd1)); CHECK(std::isnan(test.resf1)); } } } } // ----------------------mips64r2 specific tests---------------------- TEST(trunc_l) { if (kArchVariant == kMips64r2) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; // a trunc result int64_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_l_d(f8, f4); __ trunc_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } } TEST(movz_movn) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { int64_t rt; double a; double b; double bold; double b1; double bold1; float c; float d; float dold; float d1; float dold1; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ld(t0, MemOperand(a0, offsetof(TestFloat, rt))); __ Move(f12, 0.0); __ Move(f10, 0.0); __ Move(f16, 0.0); __ Move(f14, 0.0); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, bold)) ); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, dold)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, bold1)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, dold1)) ); __ movz_s(f10, f6, t0); __ movz_d(f12, f2, t0); __ movn_s(f14, f6, t0); __ movn_d(f16, f2, t0); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, b)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, d1)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, b1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; test.rt = 1; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, test.bold); CHECK_EQ(test.d, test.dold); CHECK_EQ(test.b1, outputs_D[i]); CHECK_EQ(test.d1, outputs_S[i]); test.rt = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); CHECK_EQ(test.b1, test.bold1); CHECK_EQ(test.d1, test.dold1); } } } TEST(movt_movd) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); typedef struct test_float { double srcd; double dstd; double dstdold; double dstd1; double dstdold1; float srcf; float dstf; float dstfold; float dstf1; float dstfold1; int32_t cc; int32_t fcsr; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; double inputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; int condition_flags[8] = {0, 1, 2, 3, 4, 5, 6, 7}; for (int i = 0; i < kTableLength; i++) { test.srcd = inputs_D[i]; test.srcf = inputs_S[i]; for (int j = 0; j< 8; j++) { test.cc = condition_flags[j]; if (test.cc == 0) { test.fcsr = 1 << 23; } else { test.fcsr = 1 << (24+condition_flags[j]); } HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, srcd)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, srcf)) ); __ lw(t1, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t0, FCSR); __ ctc1(t1, FCSR); __ li(t2, 0x0); __ mtc1(t2, f12); __ mtc1(t2, f10); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold)) ); __ movt_s(f12, f4, test.cc); __ movt_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold1)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold1)) ); __ movf_s(f12, f4, test.cc); __ movf_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf1)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd1)) ); __ ctc1(t0, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, outputs_S[i]); CHECK_EQ(test.dstd, outputs_D[i]); CHECK_EQ(test.dstf1, test.dstfold1); CHECK_EQ(test.dstd1, test.dstdold1); test.fcsr = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, test.dstfold); CHECK_EQ(test.dstd, test.dstdold); CHECK_EQ(test.dstf1, outputs_S[i]); CHECK_EQ(test.dstd1, outputs_D[i]); } } } } // ----------------------tests for all archs-------------------------- TEST(cvt_w_d) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; int32_t b; int fcsr; }Test; const int kTableLength = 24; double inputs[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, 2147483653.0 }; double outputs_RN[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RZ[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RP[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RM[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lw(t0, MemOperand(a0, offsetof(Test, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ cvt_w_d(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(Test, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } TEST(trunc_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_w_d(f8, f4); __ trunc_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_w_d(f8, f4); __ round_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_l_d(f8, f4); __ round_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(sub) { const int kTableLength = 12; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; double inputft_D[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; double outputs_D[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; float inputfs_S[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; float inputft_S[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; float outputs_S[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sub_s(f6, f2, f4); __ sub_d(f12, f8, f10); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(sqrt_rsqrt_recip) { const int kTableLength = 4; const double deltaDouble = 2E-15; const float deltaFloat = 2E-7; const float sqrt2_s = sqrt(2); const double sqrt2_d = sqrt(2); CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; float resultS1; float resultS2; double c; double resultD; double resultD1; double resultD2; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 0.0L, 4.0L, 2.0L, 4e-28L }; double outputs_D[kTableLength] = { 0.0L, 2.0L, sqrt2_d, 2e-14L }; float inputs_S[kTableLength] = { 0.0, 4.0, 2.0, 4e-28 }; float outputs_S[kTableLength] = { 0.0, 2.0, sqrt2_s, 2e-14 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ sqrt_s(f6, f2); __ sqrt_d(f12, f8); __ rsqrt_d(f14, f8); __ rsqrt_s(f16, f2); __ recip_d(f18, f8); __ recip_s(f4, f2); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resultS1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resultD1)) ); __ swc1(f4, MemOperand(a0, offsetof(TestFloat, resultS2)) ); __ sdc1(f18, MemOperand(a0, offsetof(TestFloat, resultD2)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { float f1; double d1; test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); if (i != 0) { f1 = test.resultS1 - 1.0F/outputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD1 - 1.0L/outputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); f1 = test.resultS2 - 1.0F/inputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD2 - 1.0L/inputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); } else { CHECK_EQ(test.resultS1, 1.0F/outputs_S[i]); CHECK_EQ(test.resultD1, 1.0L/outputs_D[i]); CHECK_EQ(test.resultS2, 1.0F/inputs_S[i]); CHECK_EQ(test.resultD2, 1.0L/inputs_D[i]); } } } TEST(neg) { const int kTableLength = 2; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; double c; double resultD; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 4.0, -2.0 }; double outputs_D[kTableLength] = { -4.0, 2.0 }; float inputs_S[kTableLength] = { 4.0, -2.0 }; float outputs_S[kTableLength] = { -4.0, 2.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ neg_s(f6, f2); __ neg_d(f12, f8); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 4; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.e = inputse[i]; test.f = inputsf[i]; CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0); CHECK_EQ(0, memcmp(&test.c, &outputsdmin[i], sizeof(test.c))); CHECK_EQ(0, memcmp(&test.d, &outputsdmax[i], sizeof(test.d))); CHECK_EQ(0, memcmp(&test.g, &outputsfmin[i], sizeof(test.g))); CHECK_EQ(0, memcmp(&test.h, &outputsfmax[i], sizeof(test.h))); } } } TEST(rint_d) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; int fcsr; }TestFloat; TestFloat test; double inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E+308, 6.27463370218383111104242366943E-307, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; double outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E147, 1.7976931348623157E308, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ ctc1(t0, FCSR); __ rint_d(f8, f4); __ sdc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(sel) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { double dd; double ds; double dt; float fd; float fs; float ft; } Test; Test test; __ ldc1(f0, MemOperand(a0, offsetof(Test, dd)) ); // test __ ldc1(f2, MemOperand(a0, offsetof(Test, ds)) ); // src1 __ ldc1(f4, MemOperand(a0, offsetof(Test, dt)) ); // src2 __ lwc1(f6, MemOperand(a0, offsetof(Test, fd)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, fs)) ); // src1 __ lwc1(f10, MemOperand(a0, offsetof(Test, ft)) ); // src2 __ sel_d(f0, f2, f4); __ sel_s(f6, f8, f10); __ sdc1(f0, MemOperand(a0, offsetof(Test, dd)) ); __ swc1(f6, MemOperand(a0, offsetof(Test, fd)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); const int test_size = 3; const int input_size = 5; double inputs_dt[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double inputs_ds[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; float inputs_ft[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float inputs_fs[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.dt = inputs_dt[i]; test.dd = tests_D[j]; test.ds = inputs_ds[i]; test.ft = inputs_ft[i]; test.fd = tests_S[j]; test.fs = inputs_fs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_ds[i]); CHECK_EQ(test.fd, inputs_fs[i]); test.dd = tests_D[j+1]; test.fd = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_dt[i]); CHECK_EQ(test.fd, inputs_ft[i]); } } } } TEST(rint_s) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; int fcsr; }TestFloat; TestFloat test; float inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E+38, 6.27463370218383111104242366943E-37, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; float* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ rint_s(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(mina_maxa) { if (kArchVariant == kMips64r6) { const int kTableLength = 23; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); struct TestFloat { double a; double b; double resd; double resd1; float c; float d; float resf; float resf1; }; TestFloat test; double inputsa[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = { 4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double resd[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double resd1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputsc[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsd[kTableLength] = {4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, fnan, -0.0, 0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float resf[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float resf1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ lwc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ lwc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ mina_d(f6, f2, f4); __ mina_s(f12, f8, f10); __ maxa_d(f14, f2, f4); __ maxa_s(f16, f8, f10); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, resf)) ); __ sdc1(f6, MemOperand(a0, offsetof(TestFloat, resd)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resf1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resd1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.c = inputsc[i]; test.d = inputsd[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if (i < kTableLength - 1) { CHECK_EQ(test.resd, resd[i]); CHECK_EQ(test.resf, resf[i]); CHECK_EQ(test.resd1, resd1[i]); CHECK_EQ(test.resf1, resf1[i]); } else { CHECK(std::isnan(test.resd)); CHECK(std::isnan(test.resf)); CHECK(std::isnan(test.resd1)); CHECK(std::isnan(test.resf1)); } } } } // ----------------------mips64r2 specific tests---------------------- TEST(trunc_l) { if (kArchVariant == kMips64r2) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; // a trunc result int64_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_l_d(f8, f4); __ trunc_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } } TEST(movz_movn) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { int64_t rt; double a; double b; double bold; double b1; double bold1; float c; float d; float dold; float d1; float dold1; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ld(t0, MemOperand(a0, offsetof(TestFloat, rt))); __ Move(f12, 0.0); __ Move(f10, 0.0); __ Move(f16, 0.0); __ Move(f14, 0.0); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, bold)) ); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, dold)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, bold1)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, dold1)) ); __ movz_s(f10, f6, t0); __ movz_d(f12, f2, t0); __ movn_s(f14, f6, t0); __ movn_d(f16, f2, t0); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, b)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, d1)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, b1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; test.rt = 1; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, test.bold); CHECK_EQ(test.d, test.dold); CHECK_EQ(test.b1, outputs_D[i]); CHECK_EQ(test.d1, outputs_S[i]); test.rt = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); CHECK_EQ(test.b1, test.bold1); CHECK_EQ(test.d1, test.dold1); } } } TEST(movt_movd) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); typedef struct test_float { double srcd; double dstd; double dstdold; double dstd1; double dstdold1; float srcf; float dstf; float dstfold; float dstf1; float dstfold1; int32_t cc; int32_t fcsr; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; double inputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; int condition_flags[8] = {0, 1, 2, 3, 4, 5, 6, 7}; for (int i = 0; i < kTableLength; i++) { test.srcd = inputs_D[i]; test.srcf = inputs_S[i]; for (int j = 0; j< 8; j++) { test.cc = condition_flags[j]; if (test.cc == 0) { test.fcsr = 1 << 23; } else { test.fcsr = 1 << (24+condition_flags[j]); } HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, srcd)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, srcf)) ); __ lw(t1, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t0, FCSR); __ ctc1(t1, FCSR); __ li(t2, 0x0); __ mtc1(t2, f12); __ mtc1(t2, f10); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold)) ); __ movt_s(f12, f4, test.cc); __ movt_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold1)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold1)) ); __ movf_s(f12, f4, test.cc); __ movf_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf1)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd1)) ); __ ctc1(t0, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, outputs_S[i]); CHECK_EQ(test.dstd, outputs_D[i]); CHECK_EQ(test.dstf1, test.dstfold1); CHECK_EQ(test.dstd1, test.dstdold1); test.fcsr = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, test.dstfold); CHECK_EQ(test.dstd, test.dstdold); CHECK_EQ(test.dstf1, outputs_S[i]); CHECK_EQ(test.dstd1, outputs_D[i]); } } } } // ----------------------tests for all archs-------------------------- TEST(cvt_w_d) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; int32_t b; int fcsr; }Test; const int kTableLength = 24; double inputs[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, 2147483653.0 }; double outputs_RN[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RZ[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RP[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RM[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lw(t0, MemOperand(a0, offsetof(Test, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ cvt_w_d(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(Test, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } TEST(trunc_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_w_d(f8, f4); __ trunc_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_w_d(f8, f4); __ round_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_l_d(f8, f4); __ round_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(sub) { const int kTableLength = 12; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; double inputft_D[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; double outputs_D[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; float inputfs_S[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; float inputft_S[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; float outputs_S[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sub_s(f6, f2, f4); __ sub_d(f12, f8, f10); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(sqrt_rsqrt_recip) { const int kTableLength = 4; const double deltaDouble = 2E-15; const float deltaFloat = 2E-7; const float sqrt2_s = sqrt(2); const double sqrt2_d = sqrt(2); CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; float resultS1; float resultS2; double c; double resultD; double resultD1; double resultD2; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 0.0L, 4.0L, 2.0L, 4e-28L }; double outputs_D[kTableLength] = { 0.0L, 2.0L, sqrt2_d, 2e-14L }; float inputs_S[kTableLength] = { 0.0, 4.0, 2.0, 4e-28 }; float outputs_S[kTableLength] = { 0.0, 2.0, sqrt2_s, 2e-14 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ sqrt_s(f6, f2); __ sqrt_d(f12, f8); __ rsqrt_d(f14, f8); __ rsqrt_s(f16, f2); __ recip_d(f18, f8); __ recip_s(f4, f2); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resultS1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resultD1)) ); __ swc1(f4, MemOperand(a0, offsetof(TestFloat, resultS2)) ); __ sdc1(f18, MemOperand(a0, offsetof(TestFloat, resultD2)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { float f1; double d1; test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); if (i != 0) { f1 = test.resultS1 - 1.0F/outputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD1 - 1.0L/outputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); f1 = test.resultS2 - 1.0F/inputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD2 - 1.0L/inputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); } else { CHECK_EQ(test.resultS1, 1.0F/outputs_S[i]); CHECK_EQ(test.resultD1, 1.0L/outputs_D[i]); CHECK_EQ(test.resultS2, 1.0F/inputs_S[i]); CHECK_EQ(test.resultD2, 1.0L/inputs_D[i]); } } } TEST(neg) { const int kTableLength = 2; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; double c; double resultD; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 4.0, -2.0 }; double outputs_D[kTableLength] = { -4.0, 2.0 }; float inputs_S[kTableLength] = { 4.0, -2.0 }; float outputs_S[kTableLength] = { -4.0, 2.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ neg_s(f6, f2); __ neg_d(f12, f8); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(sel) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { double dd; double ds; double dt; float fd; float fs; float ft; } Test; Test test; __ ldc1(f0, MemOperand(a0, offsetof(Test, dd)) ); // test __ ldc1(f2, MemOperand(a0, offsetof(Test, ds)) ); // src1 __ ldc1(f4, MemOperand(a0, offsetof(Test, dt)) ); // src2 __ lwc1(f6, MemOperand(a0, offsetof(Test, fd)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, fs)) ); // src1 __ lwc1(f10, MemOperand(a0, offsetof(Test, ft)) ); // src2 __ sel_d(f0, f2, f4); __ sel_s(f6, f8, f10); __ sdc1(f0, MemOperand(a0, offsetof(Test, dd)) ); __ swc1(f6, MemOperand(a0, offsetof(Test, fd)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); const int test_size = 3; const int input_size = 5; double inputs_dt[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double inputs_ds[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; float inputs_ft[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float inputs_fs[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.dt = inputs_dt[i]; test.dd = tests_D[j]; test.ds = inputs_ds[i]; test.ft = inputs_ft[i]; test.fd = tests_S[j]; test.fs = inputs_fs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_ds[i]); CHECK_EQ(test.fd, inputs_fs[i]); test.dd = tests_D[j+1]; test.fd = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_dt[i]); CHECK_EQ(test.fd, inputs_ft[i]); } } } } TEST(rint_s) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; int fcsr; }TestFloat; TestFloat test; float inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E+38, 6.27463370218383111104242366943E-37, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; float* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ rint_s(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(mina_maxa) { if (kArchVariant == kMips64r6) { const int kTableLength = 23; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); struct TestFloat { double a; double b; double resd; double resd1; float c; float d; float resf; float resf1; }; TestFloat test; double inputsa[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = { 4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double resd[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double resd1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputsc[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsd[kTableLength] = {4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, fnan, -0.0, 0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float resf[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float resf1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ lwc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ lwc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ mina_d(f6, f2, f4); __ mina_s(f12, f8, f10); __ maxa_d(f14, f2, f4); __ maxa_s(f16, f8, f10); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, resf)) ); __ sdc1(f6, MemOperand(a0, offsetof(TestFloat, resd)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resf1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resd1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.c = inputsc[i]; test.d = inputsd[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if (i < kTableLength - 1) { CHECK_EQ(test.resd, resd[i]); CHECK_EQ(test.resf, resf[i]); CHECK_EQ(test.resd1, resd1[i]); CHECK_EQ(test.resf1, resf1[i]); } else { CHECK(std::isnan(test.resd)); CHECK(std::isnan(test.resf)); CHECK(std::isnan(test.resd1)); CHECK(std::isnan(test.resf1)); } } } } // ----------------------mips64r2 specific tests---------------------- TEST(trunc_l) { if (kArchVariant == kMips64r2) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; // a trunc result int64_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_l_d(f8, f4); __ trunc_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } } TEST(movz_movn) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { int64_t rt; double a; double b; double bold; double b1; double bold1; float c; float d; float dold; float d1; float dold1; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ld(t0, MemOperand(a0, offsetof(TestFloat, rt))); __ Move(f12, 0.0); __ Move(f10, 0.0); __ Move(f16, 0.0); __ Move(f14, 0.0); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, bold)) ); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, dold)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, bold1)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, dold1)) ); __ movz_s(f10, f6, t0); __ movz_d(f12, f2, t0); __ movn_s(f14, f6, t0); __ movn_d(f16, f2, t0); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, b)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, d1)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, b1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; test.rt = 1; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, test.bold); CHECK_EQ(test.d, test.dold); CHECK_EQ(test.b1, outputs_D[i]); CHECK_EQ(test.d1, outputs_S[i]); test.rt = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); CHECK_EQ(test.b1, test.bold1); CHECK_EQ(test.d1, test.dold1); } } } TEST(movt_movd) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); typedef struct test_float { double srcd; double dstd; double dstdold; double dstd1; double dstdold1; float srcf; float dstf; float dstfold; float dstf1; float dstfold1; int32_t cc; int32_t fcsr; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; double inputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; int condition_flags[8] = {0, 1, 2, 3, 4, 5, 6, 7}; for (int i = 0; i < kTableLength; i++) { test.srcd = inputs_D[i]; test.srcf = inputs_S[i]; for (int j = 0; j< 8; j++) { test.cc = condition_flags[j]; if (test.cc == 0) { test.fcsr = 1 << 23; } else { test.fcsr = 1 << (24+condition_flags[j]); } HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, srcd)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, srcf)) ); __ lw(t1, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t0, FCSR); __ ctc1(t1, FCSR); __ li(t2, 0x0); __ mtc1(t2, f12); __ mtc1(t2, f10); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold)) ); __ movt_s(f12, f4, test.cc); __ movt_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold1)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold1)) ); __ movf_s(f12, f4, test.cc); __ movf_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf1)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd1)) ); __ ctc1(t0, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, outputs_S[i]); CHECK_EQ(test.dstd, outputs_D[i]); CHECK_EQ(test.dstf1, test.dstfold1); CHECK_EQ(test.dstd1, test.dstdold1); test.fcsr = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, test.dstfold); CHECK_EQ(test.dstd, test.dstdold); CHECK_EQ(test.dstf1, outputs_S[i]); CHECK_EQ(test.dstd1, outputs_D[i]); } } } } // ----------------------tests for all archs-------------------------- TEST(cvt_w_d) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; int32_t b; int fcsr; }Test; const int kTableLength = 24; double inputs[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, 2147483653.0 }; double outputs_RN[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RZ[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RP[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RM[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lw(t0, MemOperand(a0, offsetof(Test, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ cvt_w_d(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(Test, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } TEST(trunc_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_w_d(f8, f4); __ trunc_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_w_d(f8, f4); __ round_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_l_d(f8, f4); __ round_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(sub) { const int kTableLength = 12; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; double inputft_D[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; double outputs_D[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; float inputfs_S[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; float inputft_S[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; float outputs_S[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sub_s(f6, f2, f4); __ sub_d(f12, f8, f10); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(sqrt_rsqrt_recip) { const int kTableLength = 4; const double deltaDouble = 2E-15; const float deltaFloat = 2E-7; const float sqrt2_s = sqrt(2); const double sqrt2_d = sqrt(2); CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; float resultS1; float resultS2; double c; double resultD; double resultD1; double resultD2; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 0.0L, 4.0L, 2.0L, 4e-28L }; double outputs_D[kTableLength] = { 0.0L, 2.0L, sqrt2_d, 2e-14L }; float inputs_S[kTableLength] = { 0.0, 4.0, 2.0, 4e-28 }; float outputs_S[kTableLength] = { 0.0, 2.0, sqrt2_s, 2e-14 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ sqrt_s(f6, f2); __ sqrt_d(f12, f8); __ rsqrt_d(f14, f8); __ rsqrt_s(f16, f2); __ recip_d(f18, f8); __ recip_s(f4, f2); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resultS1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resultD1)) ); __ swc1(f4, MemOperand(a0, offsetof(TestFloat, resultS2)) ); __ sdc1(f18, MemOperand(a0, offsetof(TestFloat, resultD2)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { float f1; double d1; test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); if (i != 0) { f1 = test.resultS1 - 1.0F/outputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD1 - 1.0L/outputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); f1 = test.resultS2 - 1.0F/inputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD2 - 1.0L/inputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); } else { CHECK_EQ(test.resultS1, 1.0F/outputs_S[i]); CHECK_EQ(test.resultD1, 1.0L/outputs_D[i]); CHECK_EQ(test.resultS2, 1.0F/inputs_S[i]); CHECK_EQ(test.resultD2, 1.0L/inputs_D[i]); } } } TEST(neg) { const int kTableLength = 2; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; double c; double resultD; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 4.0, -2.0 }; double outputs_D[kTableLength] = { -4.0, 2.0 }; float inputs_S[kTableLength] = { 4.0, -2.0 }; float outputs_S[kTableLength] = { -4.0, 2.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ neg_s(f6, f2); __ neg_d(f12, f8); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(sel) { if (kArchVariant == kMips64r6) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test { double dd; double ds; double dt; float fd; float fs; float ft; } Test; Test test; __ ldc1(f0, MemOperand(a0, offsetof(Test, dd)) ); // test __ ldc1(f2, MemOperand(a0, offsetof(Test, ds)) ); // src1 __ ldc1(f4, MemOperand(a0, offsetof(Test, dt)) ); // src2 __ lwc1(f6, MemOperand(a0, offsetof(Test, fd)) ); // test __ lwc1(f8, MemOperand(a0, offsetof(Test, fs)) ); // src1 __ lwc1(f10, MemOperand(a0, offsetof(Test, ft)) ); // src2 __ sel_d(f0, f2, f4); __ sel_s(f6, f8, f10); __ sdc1(f0, MemOperand(a0, offsetof(Test, dd)) ); __ swc1(f6, MemOperand(a0, offsetof(Test, fd)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); const int test_size = 3; const int input_size = 5; double inputs_dt[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double inputs_ds[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; float inputs_ft[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float inputs_fs[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.dt = inputs_dt[i]; test.dd = tests_D[j]; test.ds = inputs_ds[i]; test.ft = inputs_ft[i]; test.fd = tests_S[j]; test.fs = inputs_fs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_ds[i]); CHECK_EQ(test.fd, inputs_fs[i]); test.dd = tests_D[j+1]; test.fd = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_dt[i]); CHECK_EQ(test.fd, inputs_ft[i]); } } } } TEST(rint_s) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; int fcsr; }TestFloat; TestFloat test; float inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E+38, 6.27463370218383111104242366943E-37, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; float* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ rint_s(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(mina_maxa) { if (kArchVariant == kMips64r6) { const int kTableLength = 23; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); struct TestFloat { double a; double b; double resd; double resd1; float c; float d; float resf; float resf1; }; TestFloat test; double inputsa[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = { 4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double resd[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double resd1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputsc[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsd[kTableLength] = {4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, fnan, -0.0, 0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float resf[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float resf1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ lwc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ lwc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ mina_d(f6, f2, f4); __ mina_s(f12, f8, f10); __ maxa_d(f14, f2, f4); __ maxa_s(f16, f8, f10); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, resf)) ); __ sdc1(f6, MemOperand(a0, offsetof(TestFloat, resd)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resf1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resd1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.c = inputsc[i]; test.d = inputsd[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if (i < kTableLength - 1) { CHECK_EQ(test.resd, resd[i]); CHECK_EQ(test.resf, resf[i]); CHECK_EQ(test.resd1, resd1[i]); CHECK_EQ(test.resf1, resf1[i]); } else { CHECK(std::isnan(test.resd)); CHECK(std::isnan(test.resf)); CHECK(std::isnan(test.resd1)); CHECK(std::isnan(test.resf1)); } } } } // ----------------------mips64r2 specific tests---------------------- TEST(trunc_l) { if (kArchVariant == kMips64r2) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; // a trunc result int64_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_l_d(f8, f4); __ trunc_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } } TEST(movz_movn) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { int64_t rt; double a; double b; double bold; double b1; double bold1; float c; float d; float dold; float d1; float dold1; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ld(t0, MemOperand(a0, offsetof(TestFloat, rt))); __ Move(f12, 0.0); __ Move(f10, 0.0); __ Move(f16, 0.0); __ Move(f14, 0.0); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, bold)) ); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, dold)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, bold1)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, dold1)) ); __ movz_s(f10, f6, t0); __ movz_d(f12, f2, t0); __ movn_s(f14, f6, t0); __ movn_d(f16, f2, t0); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, b)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, d1)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, b1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; test.rt = 1; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, test.bold); CHECK_EQ(test.d, test.dold); CHECK_EQ(test.b1, outputs_D[i]); CHECK_EQ(test.d1, outputs_S[i]); test.rt = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); CHECK_EQ(test.b1, test.bold1); CHECK_EQ(test.d1, test.dold1); } } } TEST(movt_movd) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); typedef struct test_float { double srcd; double dstd; double dstdold; double dstd1; double dstdold1; float srcf; float dstf; float dstfold; float dstf1; float dstfold1; int32_t cc; int32_t fcsr; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; double inputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; int condition_flags[8] = {0, 1, 2, 3, 4, 5, 6, 7}; for (int i = 0; i < kTableLength; i++) { test.srcd = inputs_D[i]; test.srcf = inputs_S[i]; for (int j = 0; j< 8; j++) { test.cc = condition_flags[j]; if (test.cc == 0) { test.fcsr = 1 << 23; } else { test.fcsr = 1 << (24+condition_flags[j]); } HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, srcd)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, srcf)) ); __ lw(t1, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t0, FCSR); __ ctc1(t1, FCSR); __ li(t2, 0x0); __ mtc1(t2, f12); __ mtc1(t2, f10); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold)) ); __ movt_s(f12, f4, test.cc); __ movt_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold1)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold1)) ); __ movf_s(f12, f4, test.cc); __ movf_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf1)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd1)) ); __ ctc1(t0, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, outputs_S[i]); CHECK_EQ(test.dstd, outputs_D[i]); CHECK_EQ(test.dstf1, test.dstfold1); CHECK_EQ(test.dstd1, test.dstdold1); test.fcsr = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, test.dstfold); CHECK_EQ(test.dstd, test.dstdold); CHECK_EQ(test.dstf1, outputs_S[i]); CHECK_EQ(test.dstd1, outputs_D[i]); } } } } // ----------------------tests for all archs-------------------------- TEST(cvt_w_d) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; int32_t b; int fcsr; }Test; const int kTableLength = 24; double inputs[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, 2147483653.0 }; double outputs_RN[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RZ[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RP[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RM[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lw(t0, MemOperand(a0, offsetof(Test, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ cvt_w_d(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(Test, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } TEST(trunc_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_w_d(f8, f4); __ trunc_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_w_d(f8, f4); __ round_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_l_d(f8, f4); __ round_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(sub) { const int kTableLength = 12; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; double inputft_D[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; double outputs_D[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; float inputfs_S[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; float inputft_S[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; float outputs_S[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sub_s(f6, f2, f4); __ sub_d(f12, f8, f10); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(sqrt_rsqrt_recip) { const int kTableLength = 4; const double deltaDouble = 2E-15; const float deltaFloat = 2E-7; const float sqrt2_s = sqrt(2); const double sqrt2_d = sqrt(2); CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; float resultS1; float resultS2; double c; double resultD; double resultD1; double resultD2; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 0.0L, 4.0L, 2.0L, 4e-28L }; double outputs_D[kTableLength] = { 0.0L, 2.0L, sqrt2_d, 2e-14L }; float inputs_S[kTableLength] = { 0.0, 4.0, 2.0, 4e-28 }; float outputs_S[kTableLength] = { 0.0, 2.0, sqrt2_s, 2e-14 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ sqrt_s(f6, f2); __ sqrt_d(f12, f8); __ rsqrt_d(f14, f8); __ rsqrt_s(f16, f2); __ recip_d(f18, f8); __ recip_s(f4, f2); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resultS1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resultD1)) ); __ swc1(f4, MemOperand(a0, offsetof(TestFloat, resultS2)) ); __ sdc1(f18, MemOperand(a0, offsetof(TestFloat, resultD2)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { float f1; double d1; test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); if (i != 0) { f1 = test.resultS1 - 1.0F/outputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD1 - 1.0L/outputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); f1 = test.resultS2 - 1.0F/inputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD2 - 1.0L/inputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); } else { CHECK_EQ(test.resultS1, 1.0F/outputs_S[i]); CHECK_EQ(test.resultD1, 1.0L/outputs_D[i]); CHECK_EQ(test.resultS2, 1.0F/inputs_S[i]); CHECK_EQ(test.resultD2, 1.0L/inputs_D[i]); } } } TEST(neg) { const int kTableLength = 2; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; double c; double resultD; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 4.0, -2.0 }; double outputs_D[kTableLength] = { -4.0, 2.0 }; float inputs_S[kTableLength] = { 4.0, -2.0 }; float outputs_S[kTableLength] = { -4.0, 2.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ neg_s(f6, f2); __ neg_d(f12, f8); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); const int test_size = 3; const int input_size = 5; double inputs_dt[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double inputs_ds[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; float inputs_ft[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float inputs_fs[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.dt = inputs_dt[i]; test.dd = tests_D[j]; test.ds = inputs_ds[i]; test.ft = inputs_ft[i]; test.fd = tests_S[j]; test.fs = inputs_fs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_ds[i]); CHECK_EQ(test.fd, inputs_fs[i]); test.dd = tests_D[j+1]; test.fd = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_dt[i]); CHECK_EQ(test.fd, inputs_ft[i]); } } } } TEST(rint_s) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; int fcsr; }TestFloat; TestFloat test; float inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E+38, 6.27463370218383111104242366943E-37, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; float* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ rint_s(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(mina_maxa) { if (kArchVariant == kMips64r6) { const int kTableLength = 23; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); struct TestFloat { double a; double b; double resd; double resd1; float c; float d; float resf; float resf1; }; TestFloat test; double inputsa[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = { 4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double resd[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double resd1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputsc[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsd[kTableLength] = {4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, fnan, -0.0, 0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float resf[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float resf1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ lwc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ lwc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ mina_d(f6, f2, f4); __ mina_s(f12, f8, f10); __ maxa_d(f14, f2, f4); __ maxa_s(f16, f8, f10); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, resf)) ); __ sdc1(f6, MemOperand(a0, offsetof(TestFloat, resd)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resf1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resd1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.c = inputsc[i]; test.d = inputsd[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if (i < kTableLength - 1) { CHECK_EQ(test.resd, resd[i]); CHECK_EQ(test.resf, resf[i]); CHECK_EQ(test.resd1, resd1[i]); CHECK_EQ(test.resf1, resf1[i]); } else { CHECK(std::isnan(test.resd)); CHECK(std::isnan(test.resf)); CHECK(std::isnan(test.resd1)); CHECK(std::isnan(test.resf1)); } } } } // ----------------------mips64r2 specific tests---------------------- TEST(trunc_l) { if (kArchVariant == kMips64r2) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; // a trunc result int64_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_l_d(f8, f4); __ trunc_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } } TEST(movz_movn) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { int64_t rt; double a; double b; double bold; double b1; double bold1; float c; float d; float dold; float d1; float dold1; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ld(t0, MemOperand(a0, offsetof(TestFloat, rt))); __ Move(f12, 0.0); __ Move(f10, 0.0); __ Move(f16, 0.0); __ Move(f14, 0.0); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, bold)) ); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, dold)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, bold1)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, dold1)) ); __ movz_s(f10, f6, t0); __ movz_d(f12, f2, t0); __ movn_s(f14, f6, t0); __ movn_d(f16, f2, t0); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, b)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, d1)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, b1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; test.rt = 1; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, test.bold); CHECK_EQ(test.d, test.dold); CHECK_EQ(test.b1, outputs_D[i]); CHECK_EQ(test.d1, outputs_S[i]); test.rt = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); CHECK_EQ(test.b1, test.bold1); CHECK_EQ(test.d1, test.dold1); } } } TEST(movt_movd) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); typedef struct test_float { double srcd; double dstd; double dstdold; double dstd1; double dstdold1; float srcf; float dstf; float dstfold; float dstf1; float dstfold1; int32_t cc; int32_t fcsr; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; double inputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; int condition_flags[8] = {0, 1, 2, 3, 4, 5, 6, 7}; for (int i = 0; i < kTableLength; i++) { test.srcd = inputs_D[i]; test.srcf = inputs_S[i]; for (int j = 0; j< 8; j++) { test.cc = condition_flags[j]; if (test.cc == 0) { test.fcsr = 1 << 23; } else { test.fcsr = 1 << (24+condition_flags[j]); } HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, srcd)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, srcf)) ); __ lw(t1, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t0, FCSR); __ ctc1(t1, FCSR); __ li(t2, 0x0); __ mtc1(t2, f12); __ mtc1(t2, f10); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold)) ); __ movt_s(f12, f4, test.cc); __ movt_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold1)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold1)) ); __ movf_s(f12, f4, test.cc); __ movf_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf1)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd1)) ); __ ctc1(t0, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, outputs_S[i]); CHECK_EQ(test.dstd, outputs_D[i]); CHECK_EQ(test.dstf1, test.dstfold1); CHECK_EQ(test.dstd1, test.dstdold1); test.fcsr = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, test.dstfold); CHECK_EQ(test.dstd, test.dstdold); CHECK_EQ(test.dstf1, outputs_S[i]); CHECK_EQ(test.dstd1, outputs_D[i]); } } } } // ----------------------tests for all archs-------------------------- TEST(cvt_w_d) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; int32_t b; int fcsr; }Test; const int kTableLength = 24; double inputs[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, 2147483653.0 }; double outputs_RN[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RZ[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RP[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RM[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lw(t0, MemOperand(a0, offsetof(Test, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ cvt_w_d(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(Test, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } TEST(trunc_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_w_d(f8, f4); __ trunc_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_w_d(f8, f4); __ round_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_l_d(f8, f4); __ round_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(sub) { const int kTableLength = 12; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; double inputft_D[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; double outputs_D[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; float inputfs_S[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; float inputft_S[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; float outputs_S[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sub_s(f6, f2, f4); __ sub_d(f12, f8, f10); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(sqrt_rsqrt_recip) { const int kTableLength = 4; const double deltaDouble = 2E-15; const float deltaFloat = 2E-7; const float sqrt2_s = sqrt(2); const double sqrt2_d = sqrt(2); CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; float resultS1; float resultS2; double c; double resultD; double resultD1; double resultD2; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 0.0L, 4.0L, 2.0L, 4e-28L }; double outputs_D[kTableLength] = { 0.0L, 2.0L, sqrt2_d, 2e-14L }; float inputs_S[kTableLength] = { 0.0, 4.0, 2.0, 4e-28 }; float outputs_S[kTableLength] = { 0.0, 2.0, sqrt2_s, 2e-14 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ sqrt_s(f6, f2); __ sqrt_d(f12, f8); __ rsqrt_d(f14, f8); __ rsqrt_s(f16, f2); __ recip_d(f18, f8); __ recip_s(f4, f2); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resultS1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resultD1)) ); __ swc1(f4, MemOperand(a0, offsetof(TestFloat, resultS2)) ); __ sdc1(f18, MemOperand(a0, offsetof(TestFloat, resultD2)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { float f1; double d1; test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); if (i != 0) { f1 = test.resultS1 - 1.0F/outputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD1 - 1.0L/outputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); f1 = test.resultS2 - 1.0F/inputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD2 - 1.0L/inputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); } else { CHECK_EQ(test.resultS1, 1.0F/outputs_S[i]); CHECK_EQ(test.resultD1, 1.0L/outputs_D[i]); CHECK_EQ(test.resultS2, 1.0F/inputs_S[i]); CHECK_EQ(test.resultD2, 1.0L/inputs_D[i]); } } } TEST(neg) { const int kTableLength = 2; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; double c; double resultD; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 4.0, -2.0 }; double outputs_D[kTableLength] = { -4.0, 2.0 }; float inputs_S[kTableLength] = { 4.0, -2.0 }; float outputs_S[kTableLength] = { -4.0, 2.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ neg_s(f6, f2); __ neg_d(f12, f8); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
()); F3 f = FUNCTION_CAST(code->entry()); const int test_size = 3; const int input_size = 5; double inputs_dt[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; double inputs_ds[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; float inputs_ft[input_size] = {0.0, 65.2, -70.32, 18446744073709551621.0, -18446744073709551621.0}; float inputs_fs[input_size] = {0.1, 69.88, -91.325, 18446744073709551625.0, -18446744073709551625.0}; double tests_D[test_size*2] = {2.8, 2.9, -2.8, -2.9, 18446744073709551616.0, 18446744073709555712.0}; float tests_S[test_size*2] = {2.9, 2.8, -2.9, -2.8, 18446744073709551616.0, 18446746272732807168.0}; for (int j=0; j < test_size; j+=2) { for (int i=0; i < input_size; i++) { test.dt = inputs_dt[i]; test.dd = tests_D[j]; test.ds = inputs_ds[i]; test.ft = inputs_ft[i]; test.fd = tests_S[j]; test.fs = inputs_fs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_ds[i]); CHECK_EQ(test.fd, inputs_fs[i]); test.dd = tests_D[j+1]; test.fd = tests_S[j+1]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dd, inputs_dt[i]); CHECK_EQ(test.fd, inputs_ft[i]); } } } } TEST(rint_s) { if (kArchVariant == kMips64r6) { const int kTableLength = 30; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; int fcsr; }TestFloat; TestFloat test; float inputs[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E+38, 6.27463370218383111104242366943E-37, 309485009821345068724781056.89, 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RN[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RZ[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RP[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 1, 309485009821345068724781057.0, 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; float outputs_RM[kTableLength] = {18446744073709551617.0, 4503599627370496.0, -4503599627370496.0, 1.26782468584154733584017312973E30, 1.44860108245951772690707170478E37, 1.7976931348623157E38, 0, 309485009821345068724781057.0, 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 37778931862957161709568.0, 37778931862957161709569.0, 37778931862957161709580.0, 37778931862957161709581.0, 37778931862957161709582.0, 37778931862957161709583.0, 37778931862957161709584.0, 37778931862957161709585.0, 37778931862957161709586.0, 37778931862957161709587.0}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; float* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lw(t0, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ rint_s(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(mina_maxa) { if (kArchVariant == kMips64r6) { const int kTableLength = 23; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); struct TestFloat { double a; double b; double resd; double resd1; float c; float d; float resf; float resf1; }; TestFloat test; double inputsa[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = { 4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double resd[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double resd1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputsc[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsd[kTableLength] = {4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, fnan, -0.0, 0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float resf[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float resf1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ lwc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ lwc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ mina_d(f6, f2, f4); __ mina_s(f12, f8, f10); __ maxa_d(f14, f2, f4); __ maxa_s(f16, f8, f10); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, resf)) ); __ sdc1(f6, MemOperand(a0, offsetof(TestFloat, resd)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resf1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resd1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.c = inputsc[i]; test.d = inputsd[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if (i < kTableLength - 1) { CHECK_EQ(test.resd, resd[i]); CHECK_EQ(test.resf, resf[i]); CHECK_EQ(test.resd1, resd1[i]); CHECK_EQ(test.resf1, resf1[i]); } else { CHECK(std::isnan(test.resd)); CHECK(std::isnan(test.resf)); CHECK(std::isnan(test.resd1)); CHECK(std::isnan(test.resf1)); } } } } // ----------------------mips64r2 specific tests---------------------- TEST(trunc_l) { if (kArchVariant == kMips64r2) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; // a trunc result int64_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_l_d(f8, f4); __ trunc_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } } TEST(movz_movn) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { int64_t rt; double a; double b; double bold; double b1; double bold1; float c; float d; float dold; float d1; float dold1; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ld(t0, MemOperand(a0, offsetof(TestFloat, rt))); __ Move(f12, 0.0); __ Move(f10, 0.0); __ Move(f16, 0.0); __ Move(f14, 0.0); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, bold)) ); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, dold)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, bold1)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, dold1)) ); __ movz_s(f10, f6, t0); __ movz_d(f12, f2, t0); __ movn_s(f14, f6, t0); __ movn_d(f16, f2, t0); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, b)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, d1)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, b1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; test.rt = 1; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, test.bold); CHECK_EQ(test.d, test.dold); CHECK_EQ(test.b1, outputs_D[i]); CHECK_EQ(test.d1, outputs_S[i]); test.rt = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); CHECK_EQ(test.b1, test.bold1); CHECK_EQ(test.d1, test.dold1); } } } TEST(movt_movd) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); typedef struct test_float { double srcd; double dstd; double dstdold; double dstd1; double dstdold1; float srcf; float dstf; float dstfold; float dstf1; float dstfold1; int32_t cc; int32_t fcsr; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; double inputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; int condition_flags[8] = {0, 1, 2, 3, 4, 5, 6, 7}; for (int i = 0; i < kTableLength; i++) { test.srcd = inputs_D[i]; test.srcf = inputs_S[i]; for (int j = 0; j< 8; j++) { test.cc = condition_flags[j]; if (test.cc == 0) { test.fcsr = 1 << 23; } else { test.fcsr = 1 << (24+condition_flags[j]); } HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, srcd)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, srcf)) ); __ lw(t1, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t0, FCSR); __ ctc1(t1, FCSR); __ li(t2, 0x0); __ mtc1(t2, f12); __ mtc1(t2, f10); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold)) ); __ movt_s(f12, f4, test.cc); __ movt_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold1)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold1)) ); __ movf_s(f12, f4, test.cc); __ movf_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf1)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd1)) ); __ ctc1(t0, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, outputs_S[i]); CHECK_EQ(test.dstd, outputs_D[i]); CHECK_EQ(test.dstf1, test.dstfold1); CHECK_EQ(test.dstd1, test.dstdold1); test.fcsr = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, test.dstfold); CHECK_EQ(test.dstd, test.dstdold); CHECK_EQ(test.dstf1, outputs_S[i]); CHECK_EQ(test.dstd1, outputs_D[i]); } } } } // ----------------------tests for all archs-------------------------- TEST(cvt_w_d) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; int32_t b; int fcsr; }Test; const int kTableLength = 24; double inputs[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, 2147483653.0 }; double outputs_RN[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RZ[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RP[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RM[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lw(t0, MemOperand(a0, offsetof(Test, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ cvt_w_d(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(Test, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } TEST(trunc_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_w_d(f8, f4); __ trunc_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_w_d(f8, f4); __ round_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_l_d(f8, f4); __ round_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(sub) { const int kTableLength = 12; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; double inputft_D[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; double outputs_D[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; float inputfs_S[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; float inputft_S[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; float outputs_S[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sub_s(f6, f2, f4); __ sub_d(f12, f8, f10); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(sqrt_rsqrt_recip) { const int kTableLength = 4; const double deltaDouble = 2E-15; const float deltaFloat = 2E-7; const float sqrt2_s = sqrt(2); const double sqrt2_d = sqrt(2); CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; float resultS1; float resultS2; double c; double resultD; double resultD1; double resultD2; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 0.0L, 4.0L, 2.0L, 4e-28L }; double outputs_D[kTableLength] = { 0.0L, 2.0L, sqrt2_d, 2e-14L }; float inputs_S[kTableLength] = { 0.0, 4.0, 2.0, 4e-28 }; float outputs_S[kTableLength] = { 0.0, 2.0, sqrt2_s, 2e-14 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ sqrt_s(f6, f2); __ sqrt_d(f12, f8); __ rsqrt_d(f14, f8); __ rsqrt_s(f16, f2); __ recip_d(f18, f8); __ recip_s(f4, f2); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resultS1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resultD1)) ); __ swc1(f4, MemOperand(a0, offsetof(TestFloat, resultS2)) ); __ sdc1(f18, MemOperand(a0, offsetof(TestFloat, resultD2)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { float f1; double d1; test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); if (i != 0) { f1 = test.resultS1 - 1.0F/outputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD1 - 1.0L/outputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); f1 = test.resultS2 - 1.0F/inputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD2 - 1.0L/inputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); } else { CHECK_EQ(test.resultS1, 1.0F/outputs_S[i]); CHECK_EQ(test.resultD1, 1.0L/outputs_D[i]); CHECK_EQ(test.resultS2, 1.0F/inputs_S[i]); CHECK_EQ(test.resultD2, 1.0L/inputs_D[i]); } } } TEST(neg) { const int kTableLength = 2; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; double c; double resultD; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 4.0, -2.0 }; double outputs_D[kTableLength] = { -4.0, 2.0 }; float inputs_S[kTableLength] = { 4.0, -2.0 }; float outputs_S[kTableLength] = { -4.0, 2.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ neg_s(f6, f2); __ neg_d(f12, f8); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(mina_maxa) { if (kArchVariant == kMips64r6) { const int kTableLength = 23; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); struct TestFloat { double a; double b; double resd; double resd1; float c; float d; float resf; float resf1; }; TestFloat test; double inputsa[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = { 4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double resd[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double resd1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputsc[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsd[kTableLength] = {4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, fnan, -0.0, 0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float resf[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float resf1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ lwc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ lwc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ mina_d(f6, f2, f4); __ mina_s(f12, f8, f10); __ maxa_d(f14, f2, f4); __ maxa_s(f16, f8, f10); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, resf)) ); __ sdc1(f6, MemOperand(a0, offsetof(TestFloat, resd)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resf1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resd1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.c = inputsc[i]; test.d = inputsd[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if (i < kTableLength - 1) { CHECK_EQ(test.resd, resd[i]); CHECK_EQ(test.resf, resf[i]); CHECK_EQ(test.resd1, resd1[i]); CHECK_EQ(test.resf1, resf1[i]); } else { CHECK(std::isnan(test.resd)); CHECK(std::isnan(test.resf)); CHECK(std::isnan(test.resd1)); CHECK(std::isnan(test.resf1)); } } } } // ----------------------mips64r2 specific tests---------------------- TEST(trunc_l) { if (kArchVariant == kMips64r2) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; // a trunc result int64_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_l_d(f8, f4); __ trunc_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } } TEST(movz_movn) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { int64_t rt; double a; double b; double bold; double b1; double bold1; float c; float d; float dold; float d1; float dold1; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ld(t0, MemOperand(a0, offsetof(TestFloat, rt))); __ Move(f12, 0.0); __ Move(f10, 0.0); __ Move(f16, 0.0); __ Move(f14, 0.0); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, bold)) ); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, dold)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, bold1)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, dold1)) ); __ movz_s(f10, f6, t0); __ movz_d(f12, f2, t0); __ movn_s(f14, f6, t0); __ movn_d(f16, f2, t0); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, b)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, d1)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, b1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; test.rt = 1; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, test.bold); CHECK_EQ(test.d, test.dold); CHECK_EQ(test.b1, outputs_D[i]); CHECK_EQ(test.d1, outputs_S[i]); test.rt = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); CHECK_EQ(test.b1, test.bold1); CHECK_EQ(test.d1, test.dold1); } } } TEST(movt_movd) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); typedef struct test_float { double srcd; double dstd; double dstdold; double dstd1; double dstdold1; float srcf; float dstf; float dstfold; float dstf1; float dstfold1; int32_t cc; int32_t fcsr; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; double inputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; int condition_flags[8] = {0, 1, 2, 3, 4, 5, 6, 7}; for (int i = 0; i < kTableLength; i++) { test.srcd = inputs_D[i]; test.srcf = inputs_S[i]; for (int j = 0; j< 8; j++) { test.cc = condition_flags[j]; if (test.cc == 0) { test.fcsr = 1 << 23; } else { test.fcsr = 1 << (24+condition_flags[j]); } HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, srcd)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, srcf)) ); __ lw(t1, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t0, FCSR); __ ctc1(t1, FCSR); __ li(t2, 0x0); __ mtc1(t2, f12); __ mtc1(t2, f10); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold)) ); __ movt_s(f12, f4, test.cc); __ movt_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold1)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold1)) ); __ movf_s(f12, f4, test.cc); __ movf_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf1)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd1)) ); __ ctc1(t0, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, outputs_S[i]); CHECK_EQ(test.dstd, outputs_D[i]); CHECK_EQ(test.dstf1, test.dstfold1); CHECK_EQ(test.dstd1, test.dstdold1); test.fcsr = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, test.dstfold); CHECK_EQ(test.dstd, test.dstdold); CHECK_EQ(test.dstf1, outputs_S[i]); CHECK_EQ(test.dstd1, outputs_D[i]); } } } } // ----------------------tests for all archs-------------------------- TEST(cvt_w_d) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; int32_t b; int fcsr; }Test; const int kTableLength = 24; double inputs[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, 2147483653.0 }; double outputs_RN[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RZ[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RP[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RM[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lw(t0, MemOperand(a0, offsetof(Test, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ cvt_w_d(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(Test, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } TEST(trunc_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_w_d(f8, f4); __ trunc_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_w_d(f8, f4); __ round_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_l_d(f8, f4); __ round_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(sub) { const int kTableLength = 12; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; double inputft_D[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; double outputs_D[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; float inputfs_S[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; float inputft_S[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; float outputs_S[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sub_s(f6, f2, f4); __ sub_d(f12, f8, f10); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(sqrt_rsqrt_recip) { const int kTableLength = 4; const double deltaDouble = 2E-15; const float deltaFloat = 2E-7; const float sqrt2_s = sqrt(2); const double sqrt2_d = sqrt(2); CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; float resultS1; float resultS2; double c; double resultD; double resultD1; double resultD2; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 0.0L, 4.0L, 2.0L, 4e-28L }; double outputs_D[kTableLength] = { 0.0L, 2.0L, sqrt2_d, 2e-14L }; float inputs_S[kTableLength] = { 0.0, 4.0, 2.0, 4e-28 }; float outputs_S[kTableLength] = { 0.0, 2.0, sqrt2_s, 2e-14 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ sqrt_s(f6, f2); __ sqrt_d(f12, f8); __ rsqrt_d(f14, f8); __ rsqrt_s(f16, f2); __ recip_d(f18, f8); __ recip_s(f4, f2); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resultS1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resultD1)) ); __ swc1(f4, MemOperand(a0, offsetof(TestFloat, resultS2)) ); __ sdc1(f18, MemOperand(a0, offsetof(TestFloat, resultD2)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { float f1; double d1; test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); if (i != 0) { f1 = test.resultS1 - 1.0F/outputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD1 - 1.0L/outputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); f1 = test.resultS2 - 1.0F/inputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD2 - 1.0L/inputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); } else { CHECK_EQ(test.resultS1, 1.0F/outputs_S[i]); CHECK_EQ(test.resultD1, 1.0L/outputs_D[i]); CHECK_EQ(test.resultS2, 1.0F/inputs_S[i]); CHECK_EQ(test.resultD2, 1.0L/inputs_D[i]); } } } TEST(neg) { const int kTableLength = 2; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; double c; double resultD; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 4.0, -2.0 }; double outputs_D[kTableLength] = { -4.0, 2.0 }; float inputs_S[kTableLength] = { 4.0, -2.0 }; float outputs_S[kTableLength] = { -4.0, 2.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ neg_s(f6, f2); __ neg_d(f12, f8); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } } TEST(mina_maxa) { if (kArchVariant == kMips64r6) { const int kTableLength = 23; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, nullptr, 0, v8::internal::CodeObjectRequired::kYes); const double dnan = std::numeric_limits::quiet_NaN(); const double dinf = std::numeric_limits::infinity(); const double dminf = -std::numeric_limits::infinity(); const float fnan = std::numeric_limits::quiet_NaN(); const float finf = std::numeric_limits::infinity(); const float fminf = std::numeric_limits::infinity(); struct TestFloat { double a; double b; double resd; double resd1; float c; float d; float resf; float resf1; }; TestFloat test; double inputsa[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, dnan, 3.0, -0.0, 0.0, dinf, dnan, 42.0, dinf, dminf, dinf, dnan}; double inputsb[kTableLength] = { 4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, dnan, 0.0, -0.0, dnan, dinf, dinf, 42.0, dinf, dminf, dnan}; double resd[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, dinf, dinf, 42.0, 42.0, dminf, dminf, dnan}; double resd1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, dinf, dinf, dinf, dinf, dinf, dinf, dnan}; float inputsc[kTableLength] = { 5.3, 4.8, 6.1, 9.8, 9.8, 9.8, -10.0, -8.9, -9.8, -10.0, -8.9, -9.8, fnan, 3.0, -0.0, 0.0, finf, fnan, 42.0, finf, fminf, finf, fnan}; float inputsd[kTableLength] = {4.8, 5.3, 6.1, -10.0, -8.9, -9.8, 9.8, 9.8, 9.8, -9.8, -11.2, -9.8, 3.0, fnan, -0.0, 0.0, fnan, finf, finf, 42.0, finf, fminf, fnan}; float resf[kTableLength] = { 4.8, 4.8, 6.1, 9.8, -8.9, -9.8, 9.8, -8.9, -9.8, -9.8, -8.9, -9.8, 3.0, 3.0, -0.0, -0.0, finf, finf, 42.0, 42.0, fminf, fminf, fnan}; float resf1[kTableLength] = { 5.3, 5.3, 6.1, -10.0, 9.8, 9.8, -10.0, 9.8, 9.8, -10.0, -11.2, -9.8, 3.0, 3.0, 0.0, 0.0, finf, finf, finf, finf, finf, finf, fnan}; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ lwc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ lwc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ mina_d(f6, f2, f4); __ mina_s(f12, f8, f10); __ maxa_d(f14, f2, f4); __ maxa_s(f16, f8, f10); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, resf)) ); __ sdc1(f6, MemOperand(a0, offsetof(TestFloat, resd)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resf1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resd1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.c = inputsc[i]; test.d = inputsd[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if (i < kTableLength - 1) { CHECK_EQ(test.resd, resd[i]); CHECK_EQ(test.resf, resf[i]); CHECK_EQ(test.resd1, resd1[i]); CHECK_EQ(test.resf1, resf1[i]); } else { CHECK(std::isnan(test.resd)); CHECK(std::isnan(test.resf)); CHECK(std::isnan(test.resd1)); CHECK(std::isnan(test.resf1)); } } } } // ----------------------mips64r2 specific tests---------------------- TEST(trunc_l) { if (kArchVariant == kMips64r2) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; // a trunc result int64_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_l_d(f8, f4); __ trunc_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } } TEST(movz_movn) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { int64_t rt; double a; double b; double bold; double b1; double bold1; float c; float d; float dold; float d1; float dold1; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ld(t0, MemOperand(a0, offsetof(TestFloat, rt))); __ Move(f12, 0.0); __ Move(f10, 0.0); __ Move(f16, 0.0); __ Move(f14, 0.0); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, bold)) ); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, dold)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, bold1)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, dold1)) ); __ movz_s(f10, f6, t0); __ movz_d(f12, f2, t0); __ movn_s(f14, f6, t0); __ movn_d(f16, f2, t0); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, b)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, d1)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, b1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; test.rt = 1; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, test.bold); CHECK_EQ(test.d, test.dold); CHECK_EQ(test.b1, outputs_D[i]); CHECK_EQ(test.d1, outputs_S[i]); test.rt = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); CHECK_EQ(test.b1, test.bold1); CHECK_EQ(test.d1, test.dold1); } } } TEST(movt_movd) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); typedef struct test_float { double srcd; double dstd; double dstdold; double dstd1; double dstdold1; float srcf; float dstf; float dstfold; float dstf1; float dstfold1; int32_t cc; int32_t fcsr; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; double inputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; int condition_flags[8] = {0, 1, 2, 3, 4, 5, 6, 7}; for (int i = 0; i < kTableLength; i++) { test.srcd = inputs_D[i]; test.srcf = inputs_S[i]; for (int j = 0; j< 8; j++) { test.cc = condition_flags[j]; if (test.cc == 0) { test.fcsr = 1 << 23; } else { test.fcsr = 1 << (24+condition_flags[j]); } HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, srcd)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, srcf)) ); __ lw(t1, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t0, FCSR); __ ctc1(t1, FCSR); __ li(t2, 0x0); __ mtc1(t2, f12); __ mtc1(t2, f10); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold)) ); __ movt_s(f12, f4, test.cc); __ movt_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold1)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold1)) ); __ movf_s(f12, f4, test.cc); __ movf_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf1)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd1)) ); __ ctc1(t0, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, outputs_S[i]); CHECK_EQ(test.dstd, outputs_D[i]); CHECK_EQ(test.dstf1, test.dstfold1); CHECK_EQ(test.dstd1, test.dstdold1); test.fcsr = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, test.dstfold); CHECK_EQ(test.dstd, test.dstdold); CHECK_EQ(test.dstf1, outputs_S[i]); CHECK_EQ(test.dstd1, outputs_D[i]); } } } } // ----------------------tests for all archs-------------------------- TEST(cvt_w_d) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; int32_t b; int fcsr; }Test; const int kTableLength = 24; double inputs[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, 2147483653.0 }; double outputs_RN[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RZ[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RP[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RM[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lw(t0, MemOperand(a0, offsetof(Test, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ cvt_w_d(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(Test, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } TEST(trunc_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_w_d(f8, f4); __ trunc_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_w_d(f8, f4); __ round_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_l_d(f8, f4); __ round_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(sub) { const int kTableLength = 12; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; double inputft_D[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; double outputs_D[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; float inputfs_S[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; float inputft_S[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; float outputs_S[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sub_s(f6, f2, f4); __ sub_d(f12, f8, f10); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(sqrt_rsqrt_recip) { const int kTableLength = 4; const double deltaDouble = 2E-15; const float deltaFloat = 2E-7; const float sqrt2_s = sqrt(2); const double sqrt2_d = sqrt(2); CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; float resultS1; float resultS2; double c; double resultD; double resultD1; double resultD2; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 0.0L, 4.0L, 2.0L, 4e-28L }; double outputs_D[kTableLength] = { 0.0L, 2.0L, sqrt2_d, 2e-14L }; float inputs_S[kTableLength] = { 0.0, 4.0, 2.0, 4e-28 }; float outputs_S[kTableLength] = { 0.0, 2.0, sqrt2_s, 2e-14 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ sqrt_s(f6, f2); __ sqrt_d(f12, f8); __ rsqrt_d(f14, f8); __ rsqrt_s(f16, f2); __ recip_d(f18, f8); __ recip_s(f4, f2); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resultS1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resultD1)) ); __ swc1(f4, MemOperand(a0, offsetof(TestFloat, resultS2)) ); __ sdc1(f18, MemOperand(a0, offsetof(TestFloat, resultD2)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { float f1; double d1; test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); if (i != 0) { f1 = test.resultS1 - 1.0F/outputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD1 - 1.0L/outputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); f1 = test.resultS2 - 1.0F/inputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD2 - 1.0L/inputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); } else { CHECK_EQ(test.resultS1, 1.0F/outputs_S[i]); CHECK_EQ(test.resultD1, 1.0L/outputs_D[i]); CHECK_EQ(test.resultS2, 1.0F/inputs_S[i]); CHECK_EQ(test.resultD2, 1.0L/inputs_D[i]); } } } TEST(neg) { const int kTableLength = 2; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; double c; double resultD; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 4.0, -2.0 }; double outputs_D[kTableLength] = { -4.0, 2.0 }; float inputs_S[kTableLength] = { 4.0, -2.0 }; float outputs_S[kTableLength] = { -4.0, 2.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ neg_s(f6, f2); __ neg_d(f12, f8); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.c = inputsc[i]; test.d = inputsd[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if (i < kTableLength - 1) { CHECK_EQ(test.resd, resd[i]); CHECK_EQ(test.resf, resf[i]); CHECK_EQ(test.resd1, resd1[i]); CHECK_EQ(test.resf1, resf1[i]); } else { CHECK(std::isnan(test.resd)); CHECK(std::isnan(test.resf)); CHECK(std::isnan(test.resd1)); CHECK(std::isnan(test.resf1)); } } } } // ----------------------mips64r2 specific tests---------------------- TEST(trunc_l) { if (kArchVariant == kMips64r2) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; // a trunc result int64_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_l_d(f8, f4); __ trunc_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } } TEST(movz_movn) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { int64_t rt; double a; double b; double bold; double b1; double bold1; float c; float d; float dold; float d1; float dold1; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ld(t0, MemOperand(a0, offsetof(TestFloat, rt))); __ Move(f12, 0.0); __ Move(f10, 0.0); __ Move(f16, 0.0); __ Move(f14, 0.0); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, bold)) ); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, dold)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, bold1)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, dold1)) ); __ movz_s(f10, f6, t0); __ movz_d(f12, f2, t0); __ movn_s(f14, f6, t0); __ movn_d(f16, f2, t0); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, b)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, d1)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, b1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; test.rt = 1; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, test.bold); CHECK_EQ(test.d, test.dold); CHECK_EQ(test.b1, outputs_D[i]); CHECK_EQ(test.d1, outputs_S[i]); test.rt = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); CHECK_EQ(test.b1, test.bold1); CHECK_EQ(test.d1, test.dold1); } } } TEST(movt_movd) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); typedef struct test_float { double srcd; double dstd; double dstdold; double dstd1; double dstdold1; float srcf; float dstf; float dstfold; float dstf1; float dstfold1; int32_t cc; int32_t fcsr; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; double inputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; int condition_flags[8] = {0, 1, 2, 3, 4, 5, 6, 7}; for (int i = 0; i < kTableLength; i++) { test.srcd = inputs_D[i]; test.srcf = inputs_S[i]; for (int j = 0; j< 8; j++) { test.cc = condition_flags[j]; if (test.cc == 0) { test.fcsr = 1 << 23; } else { test.fcsr = 1 << (24+condition_flags[j]); } HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, srcd)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, srcf)) ); __ lw(t1, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t0, FCSR); __ ctc1(t1, FCSR); __ li(t2, 0x0); __ mtc1(t2, f12); __ mtc1(t2, f10); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold)) ); __ movt_s(f12, f4, test.cc); __ movt_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold1)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold1)) ); __ movf_s(f12, f4, test.cc); __ movf_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf1)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd1)) ); __ ctc1(t0, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, outputs_S[i]); CHECK_EQ(test.dstd, outputs_D[i]); CHECK_EQ(test.dstf1, test.dstfold1); CHECK_EQ(test.dstd1, test.dstdold1); test.fcsr = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, test.dstfold); CHECK_EQ(test.dstd, test.dstdold); CHECK_EQ(test.dstf1, outputs_S[i]); CHECK_EQ(test.dstd1, outputs_D[i]); } } } } // ----------------------tests for all archs-------------------------- TEST(cvt_w_d) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; int32_t b; int fcsr; }Test; const int kTableLength = 24; double inputs[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, 2147483653.0 }; double outputs_RN[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RZ[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RP[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RM[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lw(t0, MemOperand(a0, offsetof(Test, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ cvt_w_d(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(Test, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } TEST(trunc_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_w_d(f8, f4); __ trunc_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_w_d(f8, f4); __ round_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_l_d(f8, f4); __ round_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(sub) { const int kTableLength = 12; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; double inputft_D[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; double outputs_D[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; float inputfs_S[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; float inputft_S[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; float outputs_S[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sub_s(f6, f2, f4); __ sub_d(f12, f8, f10); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(sqrt_rsqrt_recip) { const int kTableLength = 4; const double deltaDouble = 2E-15; const float deltaFloat = 2E-7; const float sqrt2_s = sqrt(2); const double sqrt2_d = sqrt(2); CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; float resultS1; float resultS2; double c; double resultD; double resultD1; double resultD2; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 0.0L, 4.0L, 2.0L, 4e-28L }; double outputs_D[kTableLength] = { 0.0L, 2.0L, sqrt2_d, 2e-14L }; float inputs_S[kTableLength] = { 0.0, 4.0, 2.0, 4e-28 }; float outputs_S[kTableLength] = { 0.0, 2.0, sqrt2_s, 2e-14 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ sqrt_s(f6, f2); __ sqrt_d(f12, f8); __ rsqrt_d(f14, f8); __ rsqrt_s(f16, f2); __ recip_d(f18, f8); __ recip_s(f4, f2); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resultS1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resultD1)) ); __ swc1(f4, MemOperand(a0, offsetof(TestFloat, resultS2)) ); __ sdc1(f18, MemOperand(a0, offsetof(TestFloat, resultD2)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { float f1; double d1; test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); if (i != 0) { f1 = test.resultS1 - 1.0F/outputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD1 - 1.0L/outputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); f1 = test.resultS2 - 1.0F/inputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD2 - 1.0L/inputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); } else { CHECK_EQ(test.resultS1, 1.0F/outputs_S[i]); CHECK_EQ(test.resultD1, 1.0L/outputs_D[i]); CHECK_EQ(test.resultS2, 1.0F/inputs_S[i]); CHECK_EQ(test.resultD2, 1.0L/inputs_D[i]); } } } TEST(neg) { const int kTableLength = 2; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; double c; double resultD; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 4.0, -2.0 }; double outputs_D[kTableLength] = { -4.0, 2.0 }; float inputs_S[kTableLength] = { 4.0, -2.0 }; float outputs_S[kTableLength] = { -4.0, 2.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ neg_s(f6, f2); __ neg_d(f12, f8); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputsa[i]; test.b = inputsb[i]; test.c = inputsc[i]; test.d = inputsd[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if (i < kTableLength - 1) { CHECK_EQ(test.resd, resd[i]); CHECK_EQ(test.resf, resf[i]); CHECK_EQ(test.resd1, resd1[i]); CHECK_EQ(test.resf1, resf1[i]); } else { CHECK(std::isnan(test.resd)); CHECK(std::isnan(test.resf)); CHECK(std::isnan(test.resd1)); CHECK(std::isnan(test.resf1)); } } } } // ----------------------mips64r2 specific tests---------------------- TEST(trunc_l) { if (kArchVariant == kMips64r2) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; // a trunc result int64_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_l_d(f8, f4); __ trunc_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } } TEST(movz_movn) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { int64_t rt; double a; double b; double bold; double b1; double bold1; float c; float d; float dold; float d1; float dold1; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ld(t0, MemOperand(a0, offsetof(TestFloat, rt))); __ Move(f12, 0.0); __ Move(f10, 0.0); __ Move(f16, 0.0); __ Move(f14, 0.0); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, bold)) ); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, dold)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, bold1)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, dold1)) ); __ movz_s(f10, f6, t0); __ movz_d(f12, f2, t0); __ movn_s(f14, f6, t0); __ movn_d(f16, f2, t0); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, b)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, d1)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, b1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; test.rt = 1; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, test.bold); CHECK_EQ(test.d, test.dold); CHECK_EQ(test.b1, outputs_D[i]); CHECK_EQ(test.d1, outputs_S[i]); test.rt = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); CHECK_EQ(test.b1, test.bold1); CHECK_EQ(test.d1, test.dold1); } } } TEST(movt_movd) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); typedef struct test_float { double srcd; double dstd; double dstdold; double dstd1; double dstdold1; float srcf; float dstf; float dstfold; float dstf1; float dstfold1; int32_t cc; int32_t fcsr; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; double inputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; int condition_flags[8] = {0, 1, 2, 3, 4, 5, 6, 7}; for (int i = 0; i < kTableLength; i++) { test.srcd = inputs_D[i]; test.srcf = inputs_S[i]; for (int j = 0; j< 8; j++) { test.cc = condition_flags[j]; if (test.cc == 0) { test.fcsr = 1 << 23; } else { test.fcsr = 1 << (24+condition_flags[j]); } HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, srcd)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, srcf)) ); __ lw(t1, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t0, FCSR); __ ctc1(t1, FCSR); __ li(t2, 0x0); __ mtc1(t2, f12); __ mtc1(t2, f10); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold)) ); __ movt_s(f12, f4, test.cc); __ movt_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold1)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold1)) ); __ movf_s(f12, f4, test.cc); __ movf_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf1)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd1)) ); __ ctc1(t0, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, outputs_S[i]); CHECK_EQ(test.dstd, outputs_D[i]); CHECK_EQ(test.dstf1, test.dstfold1); CHECK_EQ(test.dstd1, test.dstdold1); test.fcsr = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, test.dstfold); CHECK_EQ(test.dstd, test.dstdold); CHECK_EQ(test.dstf1, outputs_S[i]); CHECK_EQ(test.dstd1, outputs_D[i]); } } } } // ----------------------tests for all archs-------------------------- TEST(cvt_w_d) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; int32_t b; int fcsr; }Test; const int kTableLength = 24; double inputs[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, 2147483653.0 }; double outputs_RN[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RZ[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RP[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RM[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lw(t0, MemOperand(a0, offsetof(Test, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ cvt_w_d(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(Test, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } TEST(trunc_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_w_d(f8, f4); __ trunc_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_w_d(f8, f4); __ round_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_l_d(f8, f4); __ round_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(sub) { const int kTableLength = 12; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; double inputft_D[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; double outputs_D[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; float inputfs_S[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; float inputft_S[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; float outputs_S[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sub_s(f6, f2, f4); __ sub_d(f12, f8, f10); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(sqrt_rsqrt_recip) { const int kTableLength = 4; const double deltaDouble = 2E-15; const float deltaFloat = 2E-7; const float sqrt2_s = sqrt(2); const double sqrt2_d = sqrt(2); CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; float resultS1; float resultS2; double c; double resultD; double resultD1; double resultD2; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 0.0L, 4.0L, 2.0L, 4e-28L }; double outputs_D[kTableLength] = { 0.0L, 2.0L, sqrt2_d, 2e-14L }; float inputs_S[kTableLength] = { 0.0, 4.0, 2.0, 4e-28 }; float outputs_S[kTableLength] = { 0.0, 2.0, sqrt2_s, 2e-14 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ sqrt_s(f6, f2); __ sqrt_d(f12, f8); __ rsqrt_d(f14, f8); __ rsqrt_s(f16, f2); __ recip_d(f18, f8); __ recip_s(f4, f2); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resultS1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resultD1)) ); __ swc1(f4, MemOperand(a0, offsetof(TestFloat, resultS2)) ); __ sdc1(f18, MemOperand(a0, offsetof(TestFloat, resultD2)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { float f1; double d1; test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); if (i != 0) { f1 = test.resultS1 - 1.0F/outputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD1 - 1.0L/outputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); f1 = test.resultS2 - 1.0F/inputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD2 - 1.0L/inputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); } else { CHECK_EQ(test.resultS1, 1.0F/outputs_S[i]); CHECK_EQ(test.resultD1, 1.0L/outputs_D[i]); CHECK_EQ(test.resultS2, 1.0F/inputs_S[i]); CHECK_EQ(test.resultD2, 1.0L/inputs_D[i]); } } } TEST(neg) { const int kTableLength = 2; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; double c; double resultD; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 4.0, -2.0 }; double outputs_D[kTableLength] = { -4.0, 2.0 }; float inputs_S[kTableLength] = { 4.0, -2.0 }; float outputs_S[kTableLength] = { -4.0, 2.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ neg_s(f6, f2); __ neg_d(f12, f8); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } } TEST(movz_movn) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { int64_t rt; double a; double b; double bold; double b1; double bold1; float c; float d; float dold; float d1; float dold1; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ld(t0, MemOperand(a0, offsetof(TestFloat, rt))); __ Move(f12, 0.0); __ Move(f10, 0.0); __ Move(f16, 0.0); __ Move(f14, 0.0); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, bold)) ); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, dold)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, bold1)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, dold1)) ); __ movz_s(f10, f6, t0); __ movz_d(f12, f2, t0); __ movn_s(f14, f6, t0); __ movn_d(f16, f2, t0); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, b)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, d1)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, b1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; test.rt = 1; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, test.bold); CHECK_EQ(test.d, test.dold); CHECK_EQ(test.b1, outputs_D[i]); CHECK_EQ(test.d1, outputs_S[i]); test.rt = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); CHECK_EQ(test.b1, test.bold1); CHECK_EQ(test.d1, test.dold1); } } } TEST(movt_movd) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); typedef struct test_float { double srcd; double dstd; double dstdold; double dstd1; double dstdold1; float srcf; float dstf; float dstfold; float dstf1; float dstfold1; int32_t cc; int32_t fcsr; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; double inputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; int condition_flags[8] = {0, 1, 2, 3, 4, 5, 6, 7}; for (int i = 0; i < kTableLength; i++) { test.srcd = inputs_D[i]; test.srcf = inputs_S[i]; for (int j = 0; j< 8; j++) { test.cc = condition_flags[j]; if (test.cc == 0) { test.fcsr = 1 << 23; } else { test.fcsr = 1 << (24+condition_flags[j]); } HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, srcd)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, srcf)) ); __ lw(t1, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t0, FCSR); __ ctc1(t1, FCSR); __ li(t2, 0x0); __ mtc1(t2, f12); __ mtc1(t2, f10); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold)) ); __ movt_s(f12, f4, test.cc); __ movt_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold1)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold1)) ); __ movf_s(f12, f4, test.cc); __ movf_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf1)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd1)) ); __ ctc1(t0, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, outputs_S[i]); CHECK_EQ(test.dstd, outputs_D[i]); CHECK_EQ(test.dstf1, test.dstfold1); CHECK_EQ(test.dstd1, test.dstdold1); test.fcsr = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, test.dstfold); CHECK_EQ(test.dstd, test.dstdold); CHECK_EQ(test.dstf1, outputs_S[i]); CHECK_EQ(test.dstd1, outputs_D[i]); } } } } // ----------------------tests for all archs-------------------------- TEST(cvt_w_d) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; int32_t b; int fcsr; }Test; const int kTableLength = 24; double inputs[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, 2147483653.0 }; double outputs_RN[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RZ[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RP[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RM[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lw(t0, MemOperand(a0, offsetof(Test, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ cvt_w_d(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(Test, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } TEST(trunc_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_w_d(f8, f4); __ trunc_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_w_d(f8, f4); __ round_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_l_d(f8, f4); __ round_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(sub) { const int kTableLength = 12; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; double inputft_D[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; double outputs_D[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; float inputfs_S[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; float inputft_S[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; float outputs_S[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sub_s(f6, f2, f4); __ sub_d(f12, f8, f10); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(sqrt_rsqrt_recip) { const int kTableLength = 4; const double deltaDouble = 2E-15; const float deltaFloat = 2E-7; const float sqrt2_s = sqrt(2); const double sqrt2_d = sqrt(2); CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; float resultS1; float resultS2; double c; double resultD; double resultD1; double resultD2; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 0.0L, 4.0L, 2.0L, 4e-28L }; double outputs_D[kTableLength] = { 0.0L, 2.0L, sqrt2_d, 2e-14L }; float inputs_S[kTableLength] = { 0.0, 4.0, 2.0, 4e-28 }; float outputs_S[kTableLength] = { 0.0, 2.0, sqrt2_s, 2e-14 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ sqrt_s(f6, f2); __ sqrt_d(f12, f8); __ rsqrt_d(f14, f8); __ rsqrt_s(f16, f2); __ recip_d(f18, f8); __ recip_s(f4, f2); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resultS1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resultD1)) ); __ swc1(f4, MemOperand(a0, offsetof(TestFloat, resultS2)) ); __ sdc1(f18, MemOperand(a0, offsetof(TestFloat, resultD2)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { float f1; double d1; test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); if (i != 0) { f1 = test.resultS1 - 1.0F/outputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD1 - 1.0L/outputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); f1 = test.resultS2 - 1.0F/inputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD2 - 1.0L/inputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); } else { CHECK_EQ(test.resultS1, 1.0F/outputs_S[i]); CHECK_EQ(test.resultD1, 1.0L/outputs_D[i]); CHECK_EQ(test.resultS2, 1.0F/inputs_S[i]); CHECK_EQ(test.resultD2, 1.0L/inputs_D[i]); } } } TEST(neg) { const int kTableLength = 2; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; double c; double resultD; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 4.0, -2.0 }; double outputs_D[kTableLength] = { -4.0, 2.0 }; float inputs_S[kTableLength] = { 4.0, -2.0 }; float outputs_S[kTableLength] = { -4.0, 2.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ neg_s(f6, f2); __ neg_d(f12, f8); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } } TEST(movz_movn) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { int64_t rt; double a; double b; double bold; double b1; double bold1; float c; float d; float dold; float d1; float dold1; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ld(t0, MemOperand(a0, offsetof(TestFloat, rt))); __ Move(f12, 0.0); __ Move(f10, 0.0); __ Move(f16, 0.0); __ Move(f14, 0.0); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, bold)) ); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, dold)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, bold1)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, dold1)) ); __ movz_s(f10, f6, t0); __ movz_d(f12, f2, t0); __ movn_s(f14, f6, t0); __ movn_d(f16, f2, t0); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, b)) ); __ swc1(f14, MemOperand(a0, offsetof(TestFloat, d1)) ); __ sdc1(f16, MemOperand(a0, offsetof(TestFloat, b1)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; test.rt = 1; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, test.bold); CHECK_EQ(test.d, test.dold); CHECK_EQ(test.b1, outputs_D[i]); CHECK_EQ(test.d1, outputs_S[i]); test.rt = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); CHECK_EQ(test.b1, test.bold1); CHECK_EQ(test.d1, test.dold1); } } } TEST(movt_movd) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); typedef struct test_float { double srcd; double dstd; double dstdold; double dstd1; double dstdold1; float srcf; float dstf; float dstfold; float dstf1; float dstfold1; int32_t cc; int32_t fcsr; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; double inputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; int condition_flags[8] = {0, 1, 2, 3, 4, 5, 6, 7}; for (int i = 0; i < kTableLength; i++) { test.srcd = inputs_D[i]; test.srcf = inputs_S[i]; for (int j = 0; j< 8; j++) { test.cc = condition_flags[j]; if (test.cc == 0) { test.fcsr = 1 << 23; } else { test.fcsr = 1 << (24+condition_flags[j]); } HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, srcd)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, srcf)) ); __ lw(t1, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t0, FCSR); __ ctc1(t1, FCSR); __ li(t2, 0x0); __ mtc1(t2, f12); __ mtc1(t2, f10); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold)) ); __ movt_s(f12, f4, test.cc); __ movt_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold1)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold1)) ); __ movf_s(f12, f4, test.cc); __ movf_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf1)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd1)) ); __ ctc1(t0, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, outputs_S[i]); CHECK_EQ(test.dstd, outputs_D[i]); CHECK_EQ(test.dstf1, test.dstfold1); CHECK_EQ(test.dstd1, test.dstdold1); test.fcsr = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, test.dstfold); CHECK_EQ(test.dstd, test.dstdold); CHECK_EQ(test.dstf1, outputs_S[i]); CHECK_EQ(test.dstd1, outputs_D[i]); } } } } // ----------------------tests for all archs-------------------------- TEST(cvt_w_d) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; int32_t b; int fcsr; }Test; const int kTableLength = 24; double inputs[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, 2147483653.0 }; double outputs_RN[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RZ[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RP[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RM[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lw(t0, MemOperand(a0, offsetof(Test, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ cvt_w_d(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(Test, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } TEST(trunc_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_w_d(f8, f4); __ trunc_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_w_d(f8, f4); __ round_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_l_d(f8, f4); __ round_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(sub) { const int kTableLength = 12; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; double inputft_D[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; double outputs_D[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; float inputfs_S[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; float inputft_S[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; float outputs_S[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sub_s(f6, f2, f4); __ sub_d(f12, f8, f10); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(sqrt_rsqrt_recip) { const int kTableLength = 4; const double deltaDouble = 2E-15; const float deltaFloat = 2E-7; const float sqrt2_s = sqrt(2); const double sqrt2_d = sqrt(2); CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; float resultS1; float resultS2; double c; double resultD; double resultD1; double resultD2; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 0.0L, 4.0L, 2.0L, 4e-28L }; double outputs_D[kTableLength] = { 0.0L, 2.0L, sqrt2_d, 2e-14L }; float inputs_S[kTableLength] = { 0.0, 4.0, 2.0, 4e-28 }; float outputs_S[kTableLength] = { 0.0, 2.0, sqrt2_s, 2e-14 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ sqrt_s(f6, f2); __ sqrt_d(f12, f8); __ rsqrt_d(f14, f8); __ rsqrt_s(f16, f2); __ recip_d(f18, f8); __ recip_s(f4, f2); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resultS1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resultD1)) ); __ swc1(f4, MemOperand(a0, offsetof(TestFloat, resultS2)) ); __ sdc1(f18, MemOperand(a0, offsetof(TestFloat, resultD2)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { float f1; double d1; test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); if (i != 0) { f1 = test.resultS1 - 1.0F/outputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD1 - 1.0L/outputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); f1 = test.resultS2 - 1.0F/inputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD2 - 1.0L/inputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); } else { CHECK_EQ(test.resultS1, 1.0F/outputs_S[i]); CHECK_EQ(test.resultD1, 1.0L/outputs_D[i]); CHECK_EQ(test.resultS2, 1.0F/inputs_S[i]); CHECK_EQ(test.resultD2, 1.0L/inputs_D[i]); } } } TEST(neg) { const int kTableLength = 2; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; double c; double resultD; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 4.0, -2.0 }; double outputs_D[kTableLength] = { -4.0, 2.0 }; float inputs_S[kTableLength] = { 4.0, -2.0 }; float outputs_S[kTableLength] = { -4.0, 2.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ neg_s(f6, f2); __ neg_d(f12, f8); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; test.rt = 1; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, test.bold); CHECK_EQ(test.d, test.dold); CHECK_EQ(test.b1, outputs_D[i]); CHECK_EQ(test.d1, outputs_S[i]); test.rt = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); CHECK_EQ(test.b1, test.bold1); CHECK_EQ(test.d1, test.dold1); } } } TEST(movt_movd) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); typedef struct test_float { double srcd; double dstd; double dstdold; double dstd1; double dstdold1; float srcf; float dstf; float dstfold; float dstf1; float dstfold1; int32_t cc; int32_t fcsr; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; double inputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; int condition_flags[8] = {0, 1, 2, 3, 4, 5, 6, 7}; for (int i = 0; i < kTableLength; i++) { test.srcd = inputs_D[i]; test.srcf = inputs_S[i]; for (int j = 0; j< 8; j++) { test.cc = condition_flags[j]; if (test.cc == 0) { test.fcsr = 1 << 23; } else { test.fcsr = 1 << (24+condition_flags[j]); } HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, srcd)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, srcf)) ); __ lw(t1, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t0, FCSR); __ ctc1(t1, FCSR); __ li(t2, 0x0); __ mtc1(t2, f12); __ mtc1(t2, f10); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold)) ); __ movt_s(f12, f4, test.cc); __ movt_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold1)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold1)) ); __ movf_s(f12, f4, test.cc); __ movf_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf1)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd1)) ); __ ctc1(t0, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, outputs_S[i]); CHECK_EQ(test.dstd, outputs_D[i]); CHECK_EQ(test.dstf1, test.dstfold1); CHECK_EQ(test.dstd1, test.dstdold1); test.fcsr = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, test.dstfold); CHECK_EQ(test.dstd, test.dstdold); CHECK_EQ(test.dstf1, outputs_S[i]); CHECK_EQ(test.dstd1, outputs_D[i]); } } } } // ----------------------tests for all archs-------------------------- TEST(cvt_w_d) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; int32_t b; int fcsr; }Test; const int kTableLength = 24; double inputs[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, 2147483653.0 }; double outputs_RN[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RZ[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RP[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RM[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lw(t0, MemOperand(a0, offsetof(Test, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ cvt_w_d(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(Test, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } TEST(trunc_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_w_d(f8, f4); __ trunc_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_w_d(f8, f4); __ round_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_l_d(f8, f4); __ round_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(sub) { const int kTableLength = 12; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; double inputft_D[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; double outputs_D[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; float inputfs_S[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; float inputft_S[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; float outputs_S[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sub_s(f6, f2, f4); __ sub_d(f12, f8, f10); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(sqrt_rsqrt_recip) { const int kTableLength = 4; const double deltaDouble = 2E-15; const float deltaFloat = 2E-7; const float sqrt2_s = sqrt(2); const double sqrt2_d = sqrt(2); CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; float resultS1; float resultS2; double c; double resultD; double resultD1; double resultD2; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 0.0L, 4.0L, 2.0L, 4e-28L }; double outputs_D[kTableLength] = { 0.0L, 2.0L, sqrt2_d, 2e-14L }; float inputs_S[kTableLength] = { 0.0, 4.0, 2.0, 4e-28 }; float outputs_S[kTableLength] = { 0.0, 2.0, sqrt2_s, 2e-14 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ sqrt_s(f6, f2); __ sqrt_d(f12, f8); __ rsqrt_d(f14, f8); __ rsqrt_s(f16, f2); __ recip_d(f18, f8); __ recip_s(f4, f2); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resultS1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resultD1)) ); __ swc1(f4, MemOperand(a0, offsetof(TestFloat, resultS2)) ); __ sdc1(f18, MemOperand(a0, offsetof(TestFloat, resultD2)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { float f1; double d1; test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); if (i != 0) { f1 = test.resultS1 - 1.0F/outputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD1 - 1.0L/outputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); f1 = test.resultS2 - 1.0F/inputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD2 - 1.0L/inputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); } else { CHECK_EQ(test.resultS1, 1.0F/outputs_S[i]); CHECK_EQ(test.resultD1, 1.0L/outputs_D[i]); CHECK_EQ(test.resultS2, 1.0F/inputs_S[i]); CHECK_EQ(test.resultD2, 1.0L/inputs_D[i]); } } } TEST(neg) { const int kTableLength = 2; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; double c; double resultD; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 4.0, -2.0 }; double outputs_D[kTableLength] = { -4.0, 2.0 }; float inputs_S[kTableLength] = { 4.0, -2.0 }; float outputs_S[kTableLength] = { -4.0, 2.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ neg_s(f6, f2); __ neg_d(f12, f8); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; test.rt = 1; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, test.bold); CHECK_EQ(test.d, test.dold); CHECK_EQ(test.b1, outputs_D[i]); CHECK_EQ(test.d1, outputs_S[i]); test.rt = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); CHECK_EQ(test.b1, test.bold1); CHECK_EQ(test.d1, test.dold1); } } } TEST(movt_movd) { if (kArchVariant == kMips64r2) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); typedef struct test_float { double srcd; double dstd; double dstdold; double dstd1; double dstdold1; float srcf; float dstf; float dstfold; float dstf1; float dstfold1; int32_t cc; int32_t fcsr; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; double inputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.88, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 20.8, -2.9 }; int condition_flags[8] = {0, 1, 2, 3, 4, 5, 6, 7}; for (int i = 0; i < kTableLength; i++) { test.srcd = inputs_D[i]; test.srcf = inputs_S[i]; for (int j = 0; j< 8; j++) { test.cc = condition_flags[j]; if (test.cc == 0) { test.fcsr = 1 << 23; } else { test.fcsr = 1 << (24+condition_flags[j]); } HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); __ ldc1(f2, MemOperand(a0, offsetof(TestFloat, srcd)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, srcf)) ); __ lw(t1, MemOperand(a0, offsetof(TestFloat, fcsr)) ); __ cfc1(t0, FCSR); __ ctc1(t1, FCSR); __ li(t2, 0x0); __ mtc1(t2, f12); __ mtc1(t2, f10); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold)) ); __ movt_s(f12, f4, test.cc); __ movt_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstdold1)) ); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstfold1)) ); __ movf_s(f12, f4, test.cc); __ movf_d(f10, f2, test.cc); __ swc1(f12, MemOperand(a0, offsetof(TestFloat, dstf1)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, dstd1)) ); __ ctc1(t0, FCSR); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, outputs_S[i]); CHECK_EQ(test.dstd, outputs_D[i]); CHECK_EQ(test.dstf1, test.dstfold1); CHECK_EQ(test.dstd1, test.dstdold1); test.fcsr = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, test.dstfold); CHECK_EQ(test.dstd, test.dstdold); CHECK_EQ(test.dstf1, outputs_S[i]); CHECK_EQ(test.dstd1, outputs_D[i]); } } } } // ----------------------tests for all archs-------------------------- TEST(cvt_w_d) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; int32_t b; int fcsr; }Test; const int kTableLength = 24; double inputs[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, 2147483653.0 }; double outputs_RN[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RZ[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RP[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RM[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lw(t0, MemOperand(a0, offsetof(Test, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ cvt_w_d(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(Test, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } TEST(trunc_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_w_d(f8, f4); __ trunc_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_w_d(f8, f4); __ round_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_l_d(f8, f4); __ round_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(sub) { const int kTableLength = 12; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; double inputft_D[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; double outputs_D[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; float inputfs_S[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; float inputft_S[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; float outputs_S[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sub_s(f6, f2, f4); __ sub_d(f12, f8, f10); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(sqrt_rsqrt_recip) { const int kTableLength = 4; const double deltaDouble = 2E-15; const float deltaFloat = 2E-7; const float sqrt2_s = sqrt(2); const double sqrt2_d = sqrt(2); CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; float resultS1; float resultS2; double c; double resultD; double resultD1; double resultD2; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 0.0L, 4.0L, 2.0L, 4e-28L }; double outputs_D[kTableLength] = { 0.0L, 2.0L, sqrt2_d, 2e-14L }; float inputs_S[kTableLength] = { 0.0, 4.0, 2.0, 4e-28 }; float outputs_S[kTableLength] = { 0.0, 2.0, sqrt2_s, 2e-14 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ sqrt_s(f6, f2); __ sqrt_d(f12, f8); __ rsqrt_d(f14, f8); __ rsqrt_s(f16, f2); __ recip_d(f18, f8); __ recip_s(f4, f2); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resultS1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resultD1)) ); __ swc1(f4, MemOperand(a0, offsetof(TestFloat, resultS2)) ); __ sdc1(f18, MemOperand(a0, offsetof(TestFloat, resultD2)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { float f1; double d1; test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); if (i != 0) { f1 = test.resultS1 - 1.0F/outputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD1 - 1.0L/outputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); f1 = test.resultS2 - 1.0F/inputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD2 - 1.0L/inputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); } else { CHECK_EQ(test.resultS1, 1.0F/outputs_S[i]); CHECK_EQ(test.resultD1, 1.0L/outputs_D[i]); CHECK_EQ(test.resultS2, 1.0F/inputs_S[i]); CHECK_EQ(test.resultD2, 1.0L/inputs_D[i]); } } } TEST(neg) { const int kTableLength = 2; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; double c; double resultD; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 4.0, -2.0 }; double outputs_D[kTableLength] = { -4.0, 2.0 }; float inputs_S[kTableLength] = { 4.0, -2.0 }; float outputs_S[kTableLength] = { -4.0, 2.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ neg_s(f6, f2); __ neg_d(f12, f8); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, outputs_S[i]); CHECK_EQ(test.dstd, outputs_D[i]); CHECK_EQ(test.dstf1, test.dstfold1); CHECK_EQ(test.dstd1, test.dstdold1); test.fcsr = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, test.dstfold); CHECK_EQ(test.dstd, test.dstdold); CHECK_EQ(test.dstf1, outputs_S[i]); CHECK_EQ(test.dstd1, outputs_D[i]); } } } } // ----------------------tests for all archs-------------------------- TEST(cvt_w_d) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; int32_t b; int fcsr; }Test; const int kTableLength = 24; double inputs[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, 2147483653.0 }; double outputs_RN[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RZ[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RP[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RM[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lw(t0, MemOperand(a0, offsetof(Test, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ cvt_w_d(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(Test, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } TEST(trunc_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_w_d(f8, f4); __ trunc_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_w_d(f8, f4); __ round_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_l_d(f8, f4); __ round_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(sub) { const int kTableLength = 12; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; double inputft_D[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; double outputs_D[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; float inputfs_S[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; float inputft_S[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; float outputs_S[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sub_s(f6, f2, f4); __ sub_d(f12, f8, f10); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(sqrt_rsqrt_recip) { const int kTableLength = 4; const double deltaDouble = 2E-15; const float deltaFloat = 2E-7; const float sqrt2_s = sqrt(2); const double sqrt2_d = sqrt(2); CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; float resultS1; float resultS2; double c; double resultD; double resultD1; double resultD2; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 0.0L, 4.0L, 2.0L, 4e-28L }; double outputs_D[kTableLength] = { 0.0L, 2.0L, sqrt2_d, 2e-14L }; float inputs_S[kTableLength] = { 0.0, 4.0, 2.0, 4e-28 }; float outputs_S[kTableLength] = { 0.0, 2.0, sqrt2_s, 2e-14 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ sqrt_s(f6, f2); __ sqrt_d(f12, f8); __ rsqrt_d(f14, f8); __ rsqrt_s(f16, f2); __ recip_d(f18, f8); __ recip_s(f4, f2); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resultS1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resultD1)) ); __ swc1(f4, MemOperand(a0, offsetof(TestFloat, resultS2)) ); __ sdc1(f18, MemOperand(a0, offsetof(TestFloat, resultD2)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { float f1; double d1; test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); if (i != 0) { f1 = test.resultS1 - 1.0F/outputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD1 - 1.0L/outputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); f1 = test.resultS2 - 1.0F/inputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD2 - 1.0L/inputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); } else { CHECK_EQ(test.resultS1, 1.0F/outputs_S[i]); CHECK_EQ(test.resultD1, 1.0L/outputs_D[i]); CHECK_EQ(test.resultS2, 1.0F/inputs_S[i]); CHECK_EQ(test.resultD2, 1.0L/inputs_D[i]); } } } TEST(neg) { const int kTableLength = 2; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; double c; double resultD; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 4.0, -2.0 }; double outputs_D[kTableLength] = { -4.0, 2.0 }; float inputs_S[kTableLength] = { 4.0, -2.0 }; float outputs_S[kTableLength] = { -4.0, 2.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ neg_s(f6, f2); __ neg_d(f12, f8); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
()); F3 f = FUNCTION_CAST(code->entry()); (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, outputs_S[i]); CHECK_EQ(test.dstd, outputs_D[i]); CHECK_EQ(test.dstf1, test.dstfold1); CHECK_EQ(test.dstd1, test.dstdold1); test.fcsr = 0; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.dstf, test.dstfold); CHECK_EQ(test.dstd, test.dstdold); CHECK_EQ(test.dstf1, outputs_S[i]); CHECK_EQ(test.dstd1, outputs_D[i]); } } } } // ----------------------tests for all archs-------------------------- TEST(cvt_w_d) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; int32_t b; int fcsr; }Test; const int kTableLength = 24; double inputs[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, 2147483653.0 }; double outputs_RN[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RZ[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RP[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; double outputs_RM[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483637.0, 2147483638.0, 2147483639.0, 2147483640.0, 2147483641.0, 2147483642.0, 2147483643.0, 2147483644.0, 2147483645.0, 2147483646.0, 2147483647.0, kFPUInvalidResult}; int fcsr_inputs[4] = {kRoundToNearest, kRoundToZero, kRoundToPlusInf, kRoundToMinusInf}; double* outputs[4] = {outputs_RN, outputs_RZ, outputs_RP, outputs_RM}; __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lw(t0, MemOperand(a0, offsetof(Test, fcsr)) ); __ cfc1(t1, FCSR); __ ctc1(t0, FCSR); __ cvt_w_d(f8, f4); __ swc1(f8, MemOperand(a0, offsetof(Test, b)) ); __ ctc1(t1, FCSR); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } TEST(trunc_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_w_d(f8, f4); __ trunc_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_w_d(f8, f4); __ round_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_l_d(f8, f4); __ round_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(sub) { const int kTableLength = 12; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; double inputft_D[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; double outputs_D[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; float inputfs_S[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; float inputft_S[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; float outputs_S[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sub_s(f6, f2, f4); __ sub_d(f12, f8, f10); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(sqrt_rsqrt_recip) { const int kTableLength = 4; const double deltaDouble = 2E-15; const float deltaFloat = 2E-7; const float sqrt2_s = sqrt(2); const double sqrt2_d = sqrt(2); CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; float resultS1; float resultS2; double c; double resultD; double resultD1; double resultD2; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 0.0L, 4.0L, 2.0L, 4e-28L }; double outputs_D[kTableLength] = { 0.0L, 2.0L, sqrt2_d, 2e-14L }; float inputs_S[kTableLength] = { 0.0, 4.0, 2.0, 4e-28 }; float outputs_S[kTableLength] = { 0.0, 2.0, sqrt2_s, 2e-14 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ sqrt_s(f6, f2); __ sqrt_d(f12, f8); __ rsqrt_d(f14, f8); __ rsqrt_s(f16, f2); __ recip_d(f18, f8); __ recip_s(f4, f2); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resultS1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resultD1)) ); __ swc1(f4, MemOperand(a0, offsetof(TestFloat, resultS2)) ); __ sdc1(f18, MemOperand(a0, offsetof(TestFloat, resultD2)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { float f1; double d1; test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); if (i != 0) { f1 = test.resultS1 - 1.0F/outputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD1 - 1.0L/outputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); f1 = test.resultS2 - 1.0F/inputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD2 - 1.0L/inputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); } else { CHECK_EQ(test.resultS1, 1.0F/outputs_S[i]); CHECK_EQ(test.resultD1, 1.0L/outputs_D[i]); CHECK_EQ(test.resultS2, 1.0F/inputs_S[i]); CHECK_EQ(test.resultD2, 1.0L/inputs_D[i]); } } } TEST(neg) { const int kTableLength = 2; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; double c; double resultD; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 4.0, -2.0 }; double outputs_D[kTableLength] = { -4.0, 2.0 }; float inputs_S[kTableLength] = { 4.0, -2.0 }; float outputs_S[kTableLength] = { -4.0, 2.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ neg_s(f6, f2); __ neg_d(f12, f8); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } TEST(trunc_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_w_d(f8, f4); __ trunc_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_w_d(f8, f4); __ round_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_l_d(f8, f4); __ round_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(sub) { const int kTableLength = 12; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; double inputft_D[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; double outputs_D[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; float inputfs_S[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; float inputft_S[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; float outputs_S[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sub_s(f6, f2, f4); __ sub_d(f12, f8, f10); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(sqrt_rsqrt_recip) { const int kTableLength = 4; const double deltaDouble = 2E-15; const float deltaFloat = 2E-7; const float sqrt2_s = sqrt(2); const double sqrt2_d = sqrt(2); CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; float resultS1; float resultS2; double c; double resultD; double resultD1; double resultD2; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 0.0L, 4.0L, 2.0L, 4e-28L }; double outputs_D[kTableLength] = { 0.0L, 2.0L, sqrt2_d, 2e-14L }; float inputs_S[kTableLength] = { 0.0, 4.0, 2.0, 4e-28 }; float outputs_S[kTableLength] = { 0.0, 2.0, sqrt2_s, 2e-14 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ sqrt_s(f6, f2); __ sqrt_d(f12, f8); __ rsqrt_d(f14, f8); __ rsqrt_s(f16, f2); __ recip_d(f18, f8); __ recip_s(f4, f2); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resultS1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resultD1)) ); __ swc1(f4, MemOperand(a0, offsetof(TestFloat, resultS2)) ); __ sdc1(f18, MemOperand(a0, offsetof(TestFloat, resultD2)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { float f1; double d1; test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); if (i != 0) { f1 = test.resultS1 - 1.0F/outputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD1 - 1.0L/outputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); f1 = test.resultS2 - 1.0F/inputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD2 - 1.0L/inputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); } else { CHECK_EQ(test.resultS1, 1.0F/outputs_S[i]); CHECK_EQ(test.resultD1, 1.0L/outputs_D[i]); CHECK_EQ(test.resultS2, 1.0F/inputs_S[i]); CHECK_EQ(test.resultD2, 1.0L/inputs_D[i]); } } } TEST(neg) { const int kTableLength = 2; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; double c; double resultD; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 4.0, -2.0 }; double outputs_D[kTableLength] = { -4.0, 2.0 }; float inputs_S[kTableLength] = { 4.0, -2.0 }; float outputs_S[kTableLength] = { -4.0, 2.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ neg_s(f6, f2); __ neg_d(f12, f8); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
()); F3 f = FUNCTION_CAST(code->entry()); for (int j = 0; j < 4; j++) { test.fcsr = fcsr_inputs[j]; for (int i = 0; i < kTableLength; i++) { test.a = inputs[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs[j][i]); } } } TEST(trunc_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ trunc_w_d(f8, f4); __ trunc_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_w_d(f8, f4); __ round_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_l_d(f8, f4); __ round_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(sub) { const int kTableLength = 12; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; double inputft_D[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; double outputs_D[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; float inputfs_S[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; float inputft_S[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; float outputs_S[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sub_s(f6, f2, f4); __ sub_d(f12, f8, f10); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(sqrt_rsqrt_recip) { const int kTableLength = 4; const double deltaDouble = 2E-15; const float deltaFloat = 2E-7; const float sqrt2_s = sqrt(2); const double sqrt2_d = sqrt(2); CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; float resultS1; float resultS2; double c; double resultD; double resultD1; double resultD2; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 0.0L, 4.0L, 2.0L, 4e-28L }; double outputs_D[kTableLength] = { 0.0L, 2.0L, sqrt2_d, 2e-14L }; float inputs_S[kTableLength] = { 0.0, 4.0, 2.0, 4e-28 }; float outputs_S[kTableLength] = { 0.0, 2.0, sqrt2_s, 2e-14 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ sqrt_s(f6, f2); __ sqrt_d(f12, f8); __ rsqrt_d(f14, f8); __ rsqrt_s(f16, f2); __ recip_d(f18, f8); __ recip_s(f4, f2); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resultS1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resultD1)) ); __ swc1(f4, MemOperand(a0, offsetof(TestFloat, resultS2)) ); __ sdc1(f18, MemOperand(a0, offsetof(TestFloat, resultD2)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { float f1; double d1; test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); if (i != 0) { f1 = test.resultS1 - 1.0F/outputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD1 - 1.0L/outputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); f1 = test.resultS2 - 1.0F/inputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD2 - 1.0L/inputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); } else { CHECK_EQ(test.resultS1, 1.0F/outputs_S[i]); CHECK_EQ(test.resultD1, 1.0L/outputs_D[i]); CHECK_EQ(test.resultS2, 1.0F/inputs_S[i]); CHECK_EQ(test.resultD2, 1.0L/inputs_D[i]); } } } TEST(neg) { const int kTableLength = 2; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; double c; double resultD; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 4.0, -2.0 }; double outputs_D[kTableLength] = { -4.0, 2.0 }; float inputs_S[kTableLength] = { 4.0, -2.0 }; float outputs_S[kTableLength] = { -4.0, 2.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ neg_s(f6, f2); __ neg_d(f12, f8); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_w_d(f8, f4); __ round_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_l_d(f8, f4); __ round_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(sub) { const int kTableLength = 12; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; double inputft_D[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; double outputs_D[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; float inputfs_S[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; float inputft_S[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; float outputs_S[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sub_s(f6, f2, f4); __ sub_d(f12, f8, f10); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(sqrt_rsqrt_recip) { const int kTableLength = 4; const double deltaDouble = 2E-15; const float deltaFloat = 2E-7; const float sqrt2_s = sqrt(2); const double sqrt2_d = sqrt(2); CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; float resultS1; float resultS2; double c; double resultD; double resultD1; double resultD2; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 0.0L, 4.0L, 2.0L, 4e-28L }; double outputs_D[kTableLength] = { 0.0L, 2.0L, sqrt2_d, 2e-14L }; float inputs_S[kTableLength] = { 0.0, 4.0, 2.0, 4e-28 }; float outputs_S[kTableLength] = { 0.0, 2.0, sqrt2_s, 2e-14 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ sqrt_s(f6, f2); __ sqrt_d(f12, f8); __ rsqrt_d(f14, f8); __ rsqrt_s(f16, f2); __ recip_d(f18, f8); __ recip_s(f4, f2); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resultS1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resultD1)) ); __ swc1(f4, MemOperand(a0, offsetof(TestFloat, resultS2)) ); __ sdc1(f18, MemOperand(a0, offsetof(TestFloat, resultD2)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { float f1; double d1; test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); if (i != 0) { f1 = test.resultS1 - 1.0F/outputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD1 - 1.0L/outputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); f1 = test.resultS2 - 1.0F/inputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD2 - 1.0L/inputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); } else { CHECK_EQ(test.resultS1, 1.0F/outputs_S[i]); CHECK_EQ(test.resultD1, 1.0L/outputs_D[i]); CHECK_EQ(test.resultS2, 1.0F/inputs_S[i]); CHECK_EQ(test.resultD2, 1.0L/inputs_D[i]); } } } TEST(neg) { const int kTableLength = 2; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; double c; double resultD; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 4.0, -2.0 }; double outputs_D[kTableLength] = { -4.0, 2.0 }; float inputs_S[kTableLength] = { 4.0, -2.0 }; float outputs_S[kTableLength] = { -4.0, 2.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ neg_s(f6, f2); __ neg_d(f12, f8); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a trunc result int32_t d; // b trunc result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_w_d(f8, f4); __ round_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_l_d(f8, f4); __ round_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(sub) { const int kTableLength = 12; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; double inputft_D[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; double outputs_D[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; float inputfs_S[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; float inputft_S[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; float outputs_S[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sub_s(f6, f2, f4); __ sub_d(f12, f8, f10); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(sqrt_rsqrt_recip) { const int kTableLength = 4; const double deltaDouble = 2E-15; const float deltaFloat = 2E-7; const float sqrt2_s = sqrt(2); const double sqrt2_d = sqrt(2); CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; float resultS1; float resultS2; double c; double resultD; double resultD1; double resultD2; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 0.0L, 4.0L, 2.0L, 4e-28L }; double outputs_D[kTableLength] = { 0.0L, 2.0L, sqrt2_d, 2e-14L }; float inputs_S[kTableLength] = { 0.0, 4.0, 2.0, 4e-28 }; float outputs_S[kTableLength] = { 0.0, 2.0, sqrt2_s, 2e-14 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ sqrt_s(f6, f2); __ sqrt_d(f12, f8); __ rsqrt_d(f14, f8); __ rsqrt_s(f16, f2); __ recip_d(f18, f8); __ recip_s(f4, f2); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resultS1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resultD1)) ); __ swc1(f4, MemOperand(a0, offsetof(TestFloat, resultS2)) ); __ sdc1(f18, MemOperand(a0, offsetof(TestFloat, resultD2)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { float f1; double d1; test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); if (i != 0) { f1 = test.resultS1 - 1.0F/outputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD1 - 1.0L/outputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); f1 = test.resultS2 - 1.0F/inputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD2 - 1.0L/inputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); } else { CHECK_EQ(test.resultS1, 1.0F/outputs_S[i]); CHECK_EQ(test.resultD1, 1.0L/outputs_D[i]); CHECK_EQ(test.resultS2, 1.0F/inputs_S[i]); CHECK_EQ(test.resultD2, 1.0L/inputs_D[i]); } } } TEST(neg) { const int kTableLength = 2; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; double c; double resultD; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 4.0, -2.0 }; double outputs_D[kTableLength] = { -4.0, 2.0 }; float inputs_S[kTableLength] = { 4.0, -2.0 }; float outputs_S[kTableLength] = { -4.0, 2.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ neg_s(f6, f2); __ neg_d(f12, f8); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_l_d(f8, f4); __ round_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(sub) { const int kTableLength = 12; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; double inputft_D[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; double outputs_D[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; float inputfs_S[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; float inputft_S[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; float outputs_S[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sub_s(f6, f2, f4); __ sub_d(f12, f8, f10); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(sqrt_rsqrt_recip) { const int kTableLength = 4; const double deltaDouble = 2E-15; const float deltaFloat = 2E-7; const float sqrt2_s = sqrt(2); const double sqrt2_d = sqrt(2); CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; float resultS1; float resultS2; double c; double resultD; double resultD1; double resultD2; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 0.0L, 4.0L, 2.0L, 4e-28L }; double outputs_D[kTableLength] = { 0.0L, 2.0L, sqrt2_d, 2e-14L }; float inputs_S[kTableLength] = { 0.0, 4.0, 2.0, 4e-28 }; float outputs_S[kTableLength] = { 0.0, 2.0, sqrt2_s, 2e-14 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ sqrt_s(f6, f2); __ sqrt_d(f12, f8); __ rsqrt_d(f14, f8); __ rsqrt_s(f16, f2); __ recip_d(f18, f8); __ recip_s(f4, f2); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resultS1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resultD1)) ); __ swc1(f4, MemOperand(a0, offsetof(TestFloat, resultS2)) ); __ sdc1(f18, MemOperand(a0, offsetof(TestFloat, resultD2)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { float f1; double d1; test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); if (i != 0) { f1 = test.resultS1 - 1.0F/outputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD1 - 1.0L/outputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); f1 = test.resultS2 - 1.0F/inputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD2 - 1.0L/inputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); } else { CHECK_EQ(test.resultS1, 1.0F/outputs_S[i]); CHECK_EQ(test.resultD1, 1.0L/outputs_D[i]); CHECK_EQ(test.resultS2, 1.0F/inputs_S[i]); CHECK_EQ(test.resultD2, 1.0L/inputs_D[i]); } } } TEST(neg) { const int kTableLength = 2; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; double c; double resultD; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 4.0, -2.0 }; double outputs_D[kTableLength] = { -4.0, 2.0 }; float inputs_S[kTableLength] = { 4.0, -2.0 }; float outputs_S[kTableLength] = { -4.0, 2.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ neg_s(f6, f2); __ neg_d(f12, f8); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(round_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 3.0, 2.0, 3.0, 4.0, 4.0, -2.0, -3.0, -2.0, -3.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ round_l_d(f8, f4); __ round_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(sub) { const int kTableLength = 12; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; double inputft_D[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; double outputs_D[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; float inputfs_S[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; float inputft_S[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; float outputs_S[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sub_s(f6, f2, f4); __ sub_d(f12, f8, f10); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(sqrt_rsqrt_recip) { const int kTableLength = 4; const double deltaDouble = 2E-15; const float deltaFloat = 2E-7; const float sqrt2_s = sqrt(2); const double sqrt2_d = sqrt(2); CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; float resultS1; float resultS2; double c; double resultD; double resultD1; double resultD2; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 0.0L, 4.0L, 2.0L, 4e-28L }; double outputs_D[kTableLength] = { 0.0L, 2.0L, sqrt2_d, 2e-14L }; float inputs_S[kTableLength] = { 0.0, 4.0, 2.0, 4e-28 }; float outputs_S[kTableLength] = { 0.0, 2.0, sqrt2_s, 2e-14 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ sqrt_s(f6, f2); __ sqrt_d(f12, f8); __ rsqrt_d(f14, f8); __ rsqrt_s(f16, f2); __ recip_d(f18, f8); __ recip_s(f4, f2); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resultS1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resultD1)) ); __ swc1(f4, MemOperand(a0, offsetof(TestFloat, resultS2)) ); __ sdc1(f18, MemOperand(a0, offsetof(TestFloat, resultD2)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { float f1; double d1; test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); if (i != 0) { f1 = test.resultS1 - 1.0F/outputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD1 - 1.0L/outputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); f1 = test.resultS2 - 1.0F/inputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD2 - 1.0L/inputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); } else { CHECK_EQ(test.resultS1, 1.0F/outputs_S[i]); CHECK_EQ(test.resultD1, 1.0L/outputs_D[i]); CHECK_EQ(test.resultS2, 1.0F/inputs_S[i]); CHECK_EQ(test.resultD2, 1.0L/inputs_D[i]); } } } TEST(neg) { const int kTableLength = 2; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; double c; double resultD; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 4.0, -2.0 }; double outputs_D[kTableLength] = { -4.0, 2.0 }; float inputs_S[kTableLength] = { 4.0, -2.0 }; float outputs_S[kTableLength] = { -4.0, 2.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ neg_s(f6, f2); __ neg_d(f12, f8); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(sub) { const int kTableLength = 12; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; double inputft_D[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; double outputs_D[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; float inputfs_S[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; float inputft_S[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; float outputs_S[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sub_s(f6, f2, f4); __ sub_d(f12, f8, f10); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(sqrt_rsqrt_recip) { const int kTableLength = 4; const double deltaDouble = 2E-15; const float deltaFloat = 2E-7; const float sqrt2_s = sqrt(2); const double sqrt2_d = sqrt(2); CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; float resultS1; float resultS2; double c; double resultD; double resultD1; double resultD2; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 0.0L, 4.0L, 2.0L, 4e-28L }; double outputs_D[kTableLength] = { 0.0L, 2.0L, sqrt2_d, 2e-14L }; float inputs_S[kTableLength] = { 0.0, 4.0, 2.0, 4e-28 }; float outputs_S[kTableLength] = { 0.0, 2.0, sqrt2_s, 2e-14 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ sqrt_s(f6, f2); __ sqrt_d(f12, f8); __ rsqrt_d(f14, f8); __ rsqrt_s(f16, f2); __ recip_d(f18, f8); __ recip_s(f4, f2); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resultS1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resultD1)) ); __ swc1(f4, MemOperand(a0, offsetof(TestFloat, resultS2)) ); __ sdc1(f18, MemOperand(a0, offsetof(TestFloat, resultD2)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { float f1; double d1; test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); if (i != 0) { f1 = test.resultS1 - 1.0F/outputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD1 - 1.0L/outputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); f1 = test.resultS2 - 1.0F/inputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD2 - 1.0L/inputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); } else { CHECK_EQ(test.resultS1, 1.0F/outputs_S[i]); CHECK_EQ(test.resultD1, 1.0L/outputs_D[i]); CHECK_EQ(test.resultS2, 1.0F/inputs_S[i]); CHECK_EQ(test.resultD2, 1.0L/inputs_D[i]); } } } TEST(neg) { const int kTableLength = 2; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; double c; double resultD; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 4.0, -2.0 }; double outputs_D[kTableLength] = { -4.0, 2.0 }; float inputs_S[kTableLength] = { 4.0, -2.0 }; float outputs_S[kTableLength] = { -4.0, 2.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ neg_s(f6, f2); __ neg_d(f12, f8); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(sub) { const int kTableLength = 12; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; double inputft_D[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; double outputs_D[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; float inputfs_S[kTableLength] = { 5.3, 4.8, 2.9, -5.3, -4.8, -2.9, 5.3, 4.8, 2.9, -5.3, -4.8, -2.9 }; float inputft_S[kTableLength] = { 4.8, 5.3, 2.9, 4.8, 5.3, 2.9, -4.8, -5.3, -2.9, -4.8, -5.3, -2.9 }; float outputs_S[kTableLength] = { 0.5, -0.5, 0.0, -10.1, -10.1, -5.8, 10.1, 10.1, 5.8, -0.5, 0.5, 0.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f10, MemOperand(a0, offsetof(TestFloat, d)) ); __ sub_s(f6, f2, f4); __ sub_d(f12, f8, f10); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(sqrt_rsqrt_recip) { const int kTableLength = 4; const double deltaDouble = 2E-15; const float deltaFloat = 2E-7; const float sqrt2_s = sqrt(2); const double sqrt2_d = sqrt(2); CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; float resultS1; float resultS2; double c; double resultD; double resultD1; double resultD2; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 0.0L, 4.0L, 2.0L, 4e-28L }; double outputs_D[kTableLength] = { 0.0L, 2.0L, sqrt2_d, 2e-14L }; float inputs_S[kTableLength] = { 0.0, 4.0, 2.0, 4e-28 }; float outputs_S[kTableLength] = { 0.0, 2.0, sqrt2_s, 2e-14 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ sqrt_s(f6, f2); __ sqrt_d(f12, f8); __ rsqrt_d(f14, f8); __ rsqrt_s(f16, f2); __ recip_d(f18, f8); __ recip_s(f4, f2); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resultS1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resultD1)) ); __ swc1(f4, MemOperand(a0, offsetof(TestFloat, resultS2)) ); __ sdc1(f18, MemOperand(a0, offsetof(TestFloat, resultD2)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { float f1; double d1; test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); if (i != 0) { f1 = test.resultS1 - 1.0F/outputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD1 - 1.0L/outputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); f1 = test.resultS2 - 1.0F/inputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD2 - 1.0L/inputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); } else { CHECK_EQ(test.resultS1, 1.0F/outputs_S[i]); CHECK_EQ(test.resultD1, 1.0L/outputs_D[i]); CHECK_EQ(test.resultS2, 1.0F/inputs_S[i]); CHECK_EQ(test.resultD2, 1.0L/inputs_D[i]); } } } TEST(neg) { const int kTableLength = 2; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; double c; double resultD; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 4.0, -2.0 }; double outputs_D[kTableLength] = { -4.0, 2.0 }; float inputs_S[kTableLength] = { 4.0, -2.0 }; float outputs_S[kTableLength] = { -4.0, 2.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ neg_s(f6, f2); __ neg_d(f12, f8); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(sqrt_rsqrt_recip) { const int kTableLength = 4; const double deltaDouble = 2E-15; const float deltaFloat = 2E-7; const float sqrt2_s = sqrt(2); const double sqrt2_d = sqrt(2); CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; float resultS1; float resultS2; double c; double resultD; double resultD1; double resultD2; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 0.0L, 4.0L, 2.0L, 4e-28L }; double outputs_D[kTableLength] = { 0.0L, 2.0L, sqrt2_d, 2e-14L }; float inputs_S[kTableLength] = { 0.0, 4.0, 2.0, 4e-28 }; float outputs_S[kTableLength] = { 0.0, 2.0, sqrt2_s, 2e-14 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ sqrt_s(f6, f2); __ sqrt_d(f12, f8); __ rsqrt_d(f14, f8); __ rsqrt_s(f16, f2); __ recip_d(f18, f8); __ recip_s(f4, f2); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resultS1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resultD1)) ); __ swc1(f4, MemOperand(a0, offsetof(TestFloat, resultS2)) ); __ sdc1(f18, MemOperand(a0, offsetof(TestFloat, resultD2)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { float f1; double d1; test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); if (i != 0) { f1 = test.resultS1 - 1.0F/outputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD1 - 1.0L/outputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); f1 = test.resultS2 - 1.0F/inputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD2 - 1.0L/inputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); } else { CHECK_EQ(test.resultS1, 1.0F/outputs_S[i]); CHECK_EQ(test.resultD1, 1.0L/outputs_D[i]); CHECK_EQ(test.resultS2, 1.0F/inputs_S[i]); CHECK_EQ(test.resultD2, 1.0L/inputs_D[i]); } } } TEST(neg) { const int kTableLength = 2; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; double c; double resultD; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 4.0, -2.0 }; double outputs_D[kTableLength] = { -4.0, 2.0 }; float inputs_S[kTableLength] = { 4.0, -2.0 }; float outputs_S[kTableLength] = { -4.0, 2.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ neg_s(f6, f2); __ neg_d(f12, f8); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(sqrt_rsqrt_recip) { const int kTableLength = 4; const double deltaDouble = 2E-15; const float deltaFloat = 2E-7; const float sqrt2_s = sqrt(2); const double sqrt2_d = sqrt(2); CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; float resultS1; float resultS2; double c; double resultD; double resultD1; double resultD2; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 0.0L, 4.0L, 2.0L, 4e-28L }; double outputs_D[kTableLength] = { 0.0L, 2.0L, sqrt2_d, 2e-14L }; float inputs_S[kTableLength] = { 0.0, 4.0, 2.0, 4e-28 }; float outputs_S[kTableLength] = { 0.0, 2.0, sqrt2_s, 2e-14 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ sqrt_s(f6, f2); __ sqrt_d(f12, f8); __ rsqrt_d(f14, f8); __ rsqrt_s(f16, f2); __ recip_d(f18, f8); __ recip_s(f4, f2); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ swc1(f16, MemOperand(a0, offsetof(TestFloat, resultS1)) ); __ sdc1(f14, MemOperand(a0, offsetof(TestFloat, resultD1)) ); __ swc1(f4, MemOperand(a0, offsetof(TestFloat, resultS2)) ); __ sdc1(f18, MemOperand(a0, offsetof(TestFloat, resultD2)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { float f1; double d1; test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); if (i != 0) { f1 = test.resultS1 - 1.0F/outputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD1 - 1.0L/outputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); f1 = test.resultS2 - 1.0F/inputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD2 - 1.0L/inputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); } else { CHECK_EQ(test.resultS1, 1.0F/outputs_S[i]); CHECK_EQ(test.resultD1, 1.0L/outputs_D[i]); CHECK_EQ(test.resultS2, 1.0F/inputs_S[i]); CHECK_EQ(test.resultD2, 1.0L/inputs_D[i]); } } } TEST(neg) { const int kTableLength = 2; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; double c; double resultD; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 4.0, -2.0 }; double outputs_D[kTableLength] = { -4.0, 2.0 }; float inputs_S[kTableLength] = { 4.0, -2.0 }; float outputs_S[kTableLength] = { -4.0, 2.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ neg_s(f6, f2); __ neg_d(f12, f8); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { float f1; double d1; test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); if (i != 0) { f1 = test.resultS1 - 1.0F/outputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD1 - 1.0L/outputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); f1 = test.resultS2 - 1.0F/inputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD2 - 1.0L/inputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); } else { CHECK_EQ(test.resultS1, 1.0F/outputs_S[i]); CHECK_EQ(test.resultD1, 1.0L/outputs_D[i]); CHECK_EQ(test.resultS2, 1.0F/inputs_S[i]); CHECK_EQ(test.resultD2, 1.0L/inputs_D[i]); } } } TEST(neg) { const int kTableLength = 2; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; double c; double resultD; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 4.0, -2.0 }; double outputs_D[kTableLength] = { -4.0, 2.0 }; float inputs_S[kTableLength] = { 4.0, -2.0 }; float outputs_S[kTableLength] = { -4.0, 2.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ neg_s(f6, f2); __ neg_d(f12, f8); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { float f1; double d1; test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); if (i != 0) { f1 = test.resultS1 - 1.0F/outputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD1 - 1.0L/outputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); f1 = test.resultS2 - 1.0F/inputs_S[i]; f1 = (f1 < 0) ? f1 : -f1; CHECK(f1 <= deltaFloat); d1 = test.resultD2 - 1.0L/inputs_D[i]; d1 = (d1 < 0) ? d1 : -d1; CHECK(d1 <= deltaDouble); } else { CHECK_EQ(test.resultS1, 1.0F/outputs_S[i]); CHECK_EQ(test.resultD1, 1.0L/outputs_D[i]); CHECK_EQ(test.resultS2, 1.0F/inputs_S[i]); CHECK_EQ(test.resultD2, 1.0L/inputs_D[i]); } } } TEST(neg) { const int kTableLength = 2; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float resultS; double c; double resultD; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 4.0, -2.0 }; double outputs_D[kTableLength] = { -4.0, 2.0 }; float inputs_S[kTableLength] = { 4.0, -2.0 }; float outputs_S[kTableLength] = { -4.0, 2.0 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, c)) ); __ neg_s(f6, f2); __ neg_d(f12, f8); __ swc1(f6, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_S[i]; test.c = inputs_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, outputs_S[i]); CHECK_EQ(test.resultD, outputs_D[i]); } } TEST(mul) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { float a; float b; float resultS; double c; double d; double resultD; }TestFloat; TestFloat test; double inputfs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputft_D[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float inputfs_S[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; float inputft_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; __ lwc1(f2, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f4, MemOperand(a0, offsetof(TestFloat, b)) ); __ ldc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ ldc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ mul_s(f10, f2, f4); __ mul_d(f12, f6, f8); __ swc1(f10, MemOperand(a0, offsetof(TestFloat, resultS)) ); __ sdc1(f12, MemOperand(a0, offsetof(TestFloat, resultD)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputfs_S[i]; test.b = inputft_S[i]; test.c = inputfs_D[i]; test.d = inputft_D[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.resultS, inputfs_S[i]*inputft_S[i]); CHECK_EQ(test.resultD, inputfs_D[i]*inputft_D[i]); } } TEST(mov) { const int kTableLength = 4; CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { double a; double b; float c; float d; }TestFloat; TestFloat test; double inputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; double inputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; float outputs_S[kTableLength] = { 4.8, 4.8, -4.8, -0.29 }; double outputs_D[kTableLength] = { 5.3, -5.3, 5.3, -2.9 }; __ ldc1(f4, MemOperand(a0, offsetof(TestFloat, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(TestFloat, c)) ); __ mov_s(f8, f6); __ mov_d(f10, f4); __ swc1(f8, MemOperand(a0, offsetof(TestFloat, d)) ); __ sdc1(f10, MemOperand(a0, offsetof(TestFloat, b)) ); __ jr(ra); __ nop(); CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.c = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); CHECK_EQ(test.b, outputs_D[i]); CHECK_EQ(test.d, outputs_S[i]); } } TEST(floor_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_w_d(f8, f4); __ floor_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(floor_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast(kFPU64InvalidResult); typedef struct test_float { uint32_t isNaN2008; double a; float b; int64_t c; int64_t d; }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, dFPU64InvalidResult, dFPU64InvalidResult}; double outputsNaN2008[kTableLength] = { 2.0, 2.0, 2.0, 3.0, 3.0, 3.0, -3.0, -3.0, -3.0, -4.0, -4.0, -4.0, 2147483648.0, 0, dFPU64InvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ floor_l_d(f8, f4); __ floor_l_s(f10, f6); __ sdc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ sdc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_w) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); typedef struct test_float { uint32_t isNaN2008; double a; float b; int32_t c; // a floor result int32_t d; // b floor result }Test; const int kTableLength = 15; double inputs_D[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; float inputs_S[kTableLength] = { 2.1, 2.6, 2.5, 3.1, 3.6, 3.5, -2.1, -2.6, -2.5, -3.1, -3.6, -3.5, 2147483648.0, std::numeric_limits::quiet_NaN(), std::numeric_limits::infinity() }; double outputs[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, kFPUInvalidResult, kFPUInvalidResult}; double outputsNaN2008[kTableLength] = { 3.0, 3.0, 3.0, 4.0, 4.0, 4.0, -2.0, -2.0, -2.0, -3.0, -3.0, -3.0, kFPUInvalidResult, 0, kFPUInvalidResult}; __ cfc1(t1, FCSR); __ sw(t1, MemOperand(a0, offsetof(Test, isNaN2008))); __ ldc1(f4, MemOperand(a0, offsetof(Test, a)) ); __ lwc1(f6, MemOperand(a0, offsetof(Test, b)) ); __ ceil_w_d(f8, f4); __ ceil_w_s(f10, f6); __ swc1(f8, MemOperand(a0, offsetof(Test, c)) ); __ swc1(f10, MemOperand(a0, offsetof(Test, d)) ); __ jr(ra); __ nop(); Test test; CodeDesc desc; assm.GetCode(&desc); Handle code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
code = isolate->factory()->NewCode( desc, Code::ComputeFlags(Code::STUB), Handle()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast
()); F3 f = FUNCTION_CAST(code->entry()); for (int i = 0; i < kTableLength; i++) { test.a = inputs_D[i]; test.b = inputs_S[i]; (CALL_GENERATED_CODE(isolate, f, &test, 0, 0, 0, 0)); if ((test.isNaN2008 & kFCSRNaN2008FlagMask) && kArchVariant == kMips64r6) { CHECK_EQ(test.c, outputsNaN2008[i]); } else { CHECK_EQ(test.c, outputs[i]); } CHECK_EQ(test.d, test.c); } } TEST(ceil_l) { CcTest::InitializeVM(); Isolate* isolate = CcTest::i_isolate(); HandleScope scope(isolate); MacroAssembler assm(isolate, NULL, 0, v8::internal::CodeObjectRequired::kYes); const double dFPU64InvalidResult = static_cast