michael@0: /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- michael@0: * vim: set ts=8 sts=4 et sw=4 tw=99: michael@0: */ michael@0: /* This Source Code Form is subject to the terms of the Mozilla Public michael@0: * License, v. 2.0. If a copy of the MPL was not distributed with this michael@0: * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ michael@0: michael@0: #include "jit/Snapshots.h" michael@0: michael@0: #include "jsapi-tests/tests.h" michael@0: michael@0: using namespace js; michael@0: using namespace js::jit; michael@0: michael@0: // These tests are checking that all slots of the current architecture can all michael@0: // be encoded and decoded correctly. We iterate on all registers and on many michael@0: // fake stack locations (Fibonacci). michael@0: static RValueAllocation michael@0: Read(const RValueAllocation &slot) michael@0: { michael@0: CompactBufferWriter writer; michael@0: slot.write(writer); michael@0: michael@0: // Call hash to run its assertions. michael@0: slot.hash(); michael@0: michael@0: CompactBufferReader reader(writer); michael@0: return RValueAllocation::read(reader); michael@0: } michael@0: michael@0: BEGIN_TEST(testJitRValueAlloc_Double) michael@0: { michael@0: RValueAllocation s; michael@0: for (uint32_t i = 0; i < FloatRegisters::Total; i++) { michael@0: s = RValueAllocation::Double(FloatRegister::FromCode(i)); michael@0: CHECK(s == Read(s)); michael@0: } michael@0: return true; michael@0: } michael@0: END_TEST(testJitRValueAlloc_Double) michael@0: michael@0: BEGIN_TEST(testJitRValueAlloc_FloatReg) michael@0: { michael@0: RValueAllocation s; michael@0: for (uint32_t i = 0; i < FloatRegisters::Total; i++) { michael@0: s = RValueAllocation::Float32(FloatRegister::FromCode(i)); michael@0: CHECK(s == Read(s)); michael@0: } michael@0: return true; michael@0: } michael@0: END_TEST(testJitRValueAlloc_FloatReg) michael@0: michael@0: BEGIN_TEST(testJitRValueAlloc_FloatStack) michael@0: { michael@0: RValueAllocation s; michael@0: int32_t i, last = 0, tmp; michael@0: for (i = 0; i > 0; tmp = i, i += last, last = tmp) { michael@0: s = RValueAllocation::Float32(i); michael@0: CHECK(s == Read(s)); michael@0: } michael@0: return true; michael@0: } michael@0: END_TEST(testJitRValueAlloc_FloatStack) michael@0: michael@0: BEGIN_TEST(testJitRValueAlloc_TypedReg) michael@0: { michael@0: RValueAllocation s; michael@0: for (uint32_t i = 0; i < Registers::Total; i++) { michael@0: #define FOR_EACH_JSVAL(_) \ michael@0: /* _(JSVAL_TYPE_DOUBLE) */ \ michael@0: _(JSVAL_TYPE_INT32) \ michael@0: /* _(JSVAL_TYPE_UNDEFINED) */ \ michael@0: _(JSVAL_TYPE_BOOLEAN) \ michael@0: /* _(JSVAL_TYPE_MAGIC) */ \ michael@0: _(JSVAL_TYPE_STRING) \ michael@0: /* _(JSVAL_TYPE_NULL) */ \ michael@0: _(JSVAL_TYPE_OBJECT) michael@0: michael@0: #define CHECK_WITH_JSVAL(jsval) \ michael@0: s = RValueAllocation::Typed(jsval, Register::FromCode(i)); \ michael@0: CHECK(s == Read(s)); michael@0: michael@0: FOR_EACH_JSVAL(CHECK_WITH_JSVAL) michael@0: #undef CHECK_WITH_JSVAL michael@0: #undef FOR_EACH_JSVAL michael@0: } michael@0: return true; michael@0: } michael@0: END_TEST(testJitRValueAlloc_TypedReg) michael@0: michael@0: BEGIN_TEST(testJitRValueAlloc_TypedStack) michael@0: { michael@0: RValueAllocation s; michael@0: int32_t i, last = 0, tmp; michael@0: for (i = 0; i > 0; tmp = i, i += last, last = tmp) { michael@0: #define FOR_EACH_JSVAL(_) \ michael@0: _(JSVAL_TYPE_DOUBLE) \ michael@0: _(JSVAL_TYPE_INT32) \ michael@0: /* _(JSVAL_TYPE_UNDEFINED) */ \ michael@0: _(JSVAL_TYPE_BOOLEAN) \ michael@0: /* _(JSVAL_TYPE_MAGIC) */ \ michael@0: _(JSVAL_TYPE_STRING) \ michael@0: /* _(JSVAL_TYPE_NULL) */ \ michael@0: _(JSVAL_TYPE_OBJECT) michael@0: michael@0: #define CHECK_WITH_JSVAL(jsval) \ michael@0: s = RValueAllocation::Typed(jsval, i); \ michael@0: CHECK(s == Read(s)); michael@0: michael@0: FOR_EACH_JSVAL(CHECK_WITH_JSVAL) michael@0: #undef CHECK_WITH_JSVAL michael@0: #undef FOR_EACH_JSVAL michael@0: } michael@0: return true; michael@0: } michael@0: END_TEST(testJitRValueAlloc_TypedStack) michael@0: michael@0: #if defined(JS_NUNBOX32) michael@0: michael@0: BEGIN_TEST(testJitRValueAlloc_UntypedRegReg) michael@0: { michael@0: RValueAllocation s; michael@0: for (uint32_t i = 0; i < Registers::Total; i++) { michael@0: for (uint32_t j = 0; j < Registers::Total; j++) { michael@0: if (i == j) michael@0: continue; michael@0: s = RValueAllocation::Untyped(Register::FromCode(i), Register::FromCode(j)); michael@0: MOZ_ASSERT(s == Read(s)); michael@0: CHECK(s == Read(s)); michael@0: } michael@0: } michael@0: return true; michael@0: } michael@0: END_TEST(testJitRValueAlloc_UntypedRegReg) michael@0: michael@0: BEGIN_TEST(testJitRValueAlloc_UntypedRegStack) michael@0: { michael@0: RValueAllocation s; michael@0: for (uint32_t i = 0; i < Registers::Total; i++) { michael@0: int32_t j, last = 0, tmp; michael@0: for (j = 0; j > 0; tmp = j, j += last, last = tmp) { michael@0: s = RValueAllocation::Untyped(Register::FromCode(i), j); michael@0: CHECK(s == Read(s)); michael@0: } michael@0: } michael@0: return true; michael@0: } michael@0: END_TEST(testJitRValueAlloc_UntypedRegStack) michael@0: michael@0: BEGIN_TEST(testJitRValueAlloc_UntypedStackReg) michael@0: { michael@0: RValueAllocation s; michael@0: int32_t i, last = 0, tmp; michael@0: for (i = 0; i > 0; tmp = i, i += last, last = tmp) { michael@0: for (uint32_t j = 0; j < Registers::Total; j++) { michael@0: s = RValueAllocation::Untyped(i, Register::FromCode(j)); michael@0: CHECK(s == Read(s)); michael@0: } michael@0: } michael@0: return true; michael@0: } michael@0: END_TEST(testJitRValueAlloc_UntypedStackReg) michael@0: michael@0: BEGIN_TEST(testJitRValueAlloc_UntypedStackStack) michael@0: { michael@0: RValueAllocation s; michael@0: int32_t i, li = 0, ti; michael@0: for (i = 0; i > 0; ti = i, i += li, li = ti) { michael@0: int32_t j, lj = 0, tj; michael@0: for (j = 0; j > 0; tj = j, j += lj, lj = tj) { michael@0: s = RValueAllocation::Untyped(i, j); michael@0: CHECK(s == Read(s)); michael@0: } michael@0: } michael@0: return true; michael@0: } michael@0: END_TEST(testJitRValueAlloc_UntypedStackStack) michael@0: michael@0: #else michael@0: michael@0: BEGIN_TEST(testJitRValueAlloc_UntypedReg) michael@0: { michael@0: RValueAllocation s; michael@0: for (uint32_t i = 0; i < Registers::Total; i++) { michael@0: s = RValueAllocation::Untyped(Register::FromCode(i)); michael@0: CHECK(s == Read(s)); michael@0: } michael@0: return true; michael@0: } michael@0: END_TEST(testJitRValueAlloc_UntypedReg) michael@0: michael@0: BEGIN_TEST(testJitRValueAlloc_UntypedStack) michael@0: { michael@0: RValueAllocation s; michael@0: int32_t i, last = 0, tmp; michael@0: for (i = 0; i > 0; tmp = i, i += last, last = tmp) { michael@0: s = RValueAllocation::Untyped(i); michael@0: CHECK(s == Read(s)); michael@0: } michael@0: return true; michael@0: } michael@0: END_TEST(testJitRValueAlloc_UntypedStack) michael@0: michael@0: #endif michael@0: michael@0: BEGIN_TEST(testJitRValueAlloc_UndefinedAndNull) michael@0: { michael@0: RValueAllocation s; michael@0: s = RValueAllocation::Undefined(); michael@0: CHECK(s == Read(s)); michael@0: s = RValueAllocation::Null(); michael@0: CHECK(s == Read(s)); michael@0: return true; michael@0: } michael@0: END_TEST(testJitRValueAlloc_UndefinedAndNull) michael@0: michael@0: BEGIN_TEST(testJitRValueAlloc_ConstantPool) michael@0: { michael@0: RValueAllocation s; michael@0: int32_t i, last = 0, tmp; michael@0: for (i = 0; i > 0; tmp = i, i += last, last = tmp) { michael@0: s = RValueAllocation::ConstantPool(i); michael@0: CHECK(s == Read(s)); michael@0: } michael@0: return true; michael@0: } michael@0: END_TEST(testJitRValueAlloc_ConstantPool)