1 /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*-
2 * vim: set ts=8 sts=2 et sw=2 tw=80:
4 /* This Source Code Form is subject to the terms of the Mozilla Public
5 * License, v. 2.0. If a copy of the MPL was not distributed with this
6 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
8 #include "jit/Snapshots.h"
10 #include "jsapi-tests/tests.h"
13 using namespace js::jit
;
15 // These tests are checking that all slots of the current architecture can all
16 // be encoded and decoded correctly. We iterate on all registers and on many
17 // fake stack locations (Fibonacci).
18 static RValueAllocation
Read(const RValueAllocation
& slot
) {
19 CompactBufferWriter writer
;
22 // Call hash to run its assertions.
25 CompactBufferReader
reader(writer
);
26 return RValueAllocation::read(reader
);
32 // std::iterator traits.
33 using iterator_category
= std::input_iterator_tag
;
34 using value_type
= int32_t;
35 using difference_type
= int32_t;
36 using pointer
= value_type
*;
37 using reference
= value_type
&;
44 Iterator(value_type value
, value_type last
) : value_(value
), last_(last
) {}
46 friend class Fibonacci
;
49 Iterator
& operator++() {
50 auto next
= value_
+ last_
;
51 if (next
<= static_cast<uint32_t>(INT32_MAX
)) {
60 bool operator==(const Iterator
& other
) const {
61 return value_
== other
.value_
&& last_
== other
.last_
;
64 bool operator!=(const Iterator
& other
) const { return !(*this == other
); }
66 auto operator*() const { return static_cast<int32_t>(value_
); }
70 auto begin() { return Iterator
{0, 1}; }
72 auto end() { return Iterator
{}; }
75 BEGIN_TEST(testJitRValueAlloc_Double
) {
77 for (uint32_t i
= 0; i
< FloatRegisters::Total
; i
++) {
78 s
= RValueAllocation::Double(FloatRegister::FromCode(i
));
83 END_TEST(testJitRValueAlloc_Double
)
85 BEGIN_TEST(testJitRValueAlloc_FloatReg
) {
87 for (uint32_t i
= 0; i
< FloatRegisters::Total
; i
++) {
88 s
= RValueAllocation::AnyFloat(FloatRegister::FromCode(i
));
93 END_TEST(testJitRValueAlloc_FloatReg
)
95 BEGIN_TEST(testJitRValueAlloc_FloatStack
) {
97 for (auto i
: Fibonacci
{}) {
98 s
= RValueAllocation::AnyFloat(i
);
103 END_TEST(testJitRValueAlloc_FloatStack
)
105 BEGIN_TEST(testJitRValueAlloc_TypedReg
) {
107 for (uint32_t i
= 0; i
< Registers::Total
; i
++) {
108 #define FOR_EACH_JSVAL(_) \
109 /* _(JSVAL_TYPE_DOUBLE) */ \
110 _(JSVAL_TYPE_INT32) \
111 /* _(JSVAL_TYPE_UNDEFINED) */ \
112 _(JSVAL_TYPE_BOOLEAN) \
113 /* _(JSVAL_TYPE_MAGIC) */ \
114 _(JSVAL_TYPE_STRING) \
115 _(JSVAL_TYPE_SYMBOL) \
116 _(JSVAL_TYPE_BIGINT) \
117 /* _(JSVAL_TYPE_NULL) */ \
120 #define CHECK_WITH_JSVAL(jsval) \
121 s = RValueAllocation::Typed(jsval, Register::FromCode(i)); \
124 FOR_EACH_JSVAL(CHECK_WITH_JSVAL
)
125 #undef CHECK_WITH_JSVAL
126 #undef FOR_EACH_JSVAL
130 END_TEST(testJitRValueAlloc_TypedReg
)
132 BEGIN_TEST(testJitRValueAlloc_TypedStack
) {
134 for (auto i
: Fibonacci
{}) {
135 #define FOR_EACH_JSVAL(_) \
136 _(JSVAL_TYPE_DOUBLE) \
137 _(JSVAL_TYPE_INT32) \
138 /* _(JSVAL_TYPE_UNDEFINED) */ \
139 _(JSVAL_TYPE_BOOLEAN) \
140 /* _(JSVAL_TYPE_MAGIC) */ \
141 _(JSVAL_TYPE_STRING) \
142 _(JSVAL_TYPE_SYMBOL) \
143 _(JSVAL_TYPE_BIGINT) \
144 /* _(JSVAL_TYPE_NULL) */ \
147 #define CHECK_WITH_JSVAL(jsval) \
148 s = RValueAllocation::Typed(jsval, i); \
151 FOR_EACH_JSVAL(CHECK_WITH_JSVAL
)
152 #undef CHECK_WITH_JSVAL
153 #undef FOR_EACH_JSVAL
157 END_TEST(testJitRValueAlloc_TypedStack
)
159 #if defined(JS_NUNBOX32)
161 BEGIN_TEST(testJitRValueAlloc_UntypedRegReg
) {
163 for (uint32_t i
= 0; i
< Registers::Total
; i
++) {
164 for (uint32_t j
= 0; j
< Registers::Total
; j
++) {
168 s
= RValueAllocation::Untyped(Register::FromCode(i
),
169 Register::FromCode(j
));
170 MOZ_ASSERT(s
== Read(s
));
176 END_TEST(testJitRValueAlloc_UntypedRegReg
)
178 BEGIN_TEST(testJitRValueAlloc_UntypedRegStack
) {
180 for (uint32_t i
= 0; i
< Registers::Total
; i
++) {
181 for (auto j
: Fibonacci
{}) {
182 s
= RValueAllocation::Untyped(Register::FromCode(i
), j
);
188 END_TEST(testJitRValueAlloc_UntypedRegStack
)
190 BEGIN_TEST(testJitRValueAlloc_UntypedStackReg
) {
192 for (auto i
: Fibonacci
{}) {
193 for (uint32_t j
= 0; j
< Registers::Total
; j
++) {
194 s
= RValueAllocation::Untyped(i
, Register::FromCode(j
));
200 END_TEST(testJitRValueAlloc_UntypedStackReg
)
202 BEGIN_TEST(testJitRValueAlloc_UntypedStackStack
) {
204 for (auto i
: Fibonacci
{}) {
205 for (auto j
: Fibonacci
{}) {
206 s
= RValueAllocation::Untyped(i
, j
);
212 END_TEST(testJitRValueAlloc_UntypedStackStack
)
216 BEGIN_TEST(testJitRValueAlloc_UntypedReg
) {
218 for (uint32_t i
= 0; i
< Registers::Total
; i
++) {
219 s
= RValueAllocation::Untyped(Register::FromCode(i
));
224 END_TEST(testJitRValueAlloc_UntypedReg
)
226 BEGIN_TEST(testJitRValueAlloc_UntypedStack
) {
228 for (auto i
: Fibonacci
{}) {
229 s
= RValueAllocation::Untyped(i
);
234 END_TEST(testJitRValueAlloc_UntypedStack
)
238 BEGIN_TEST(testJitRValueAlloc_UndefinedAndNull
) {
240 s
= RValueAllocation::Undefined();
242 s
= RValueAllocation::Null();
246 END_TEST(testJitRValueAlloc_UndefinedAndNull
)
248 BEGIN_TEST(testJitRValueAlloc_ConstantPool
) {
250 for (auto i
: Fibonacci
{}) {
251 s
= RValueAllocation::ConstantPool(i
);
256 END_TEST(testJitRValueAlloc_ConstantPool
)