Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- |
michael@0 | 2 | * vim: set ts=8 sts=4 et sw=4 tw=99: |
michael@0 | 3 | */ |
michael@0 | 4 | /* This Source Code Form is subject to the terms of the Mozilla Public |
michael@0 | 5 | * License, v. 2.0. If a copy of the MPL was not distributed with this |
michael@0 | 6 | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
michael@0 | 7 | |
michael@0 | 8 | #include "jit/Snapshots.h" |
michael@0 | 9 | |
michael@0 | 10 | #include "jsapi-tests/tests.h" |
michael@0 | 11 | |
michael@0 | 12 | using namespace js; |
michael@0 | 13 | using namespace js::jit; |
michael@0 | 14 | |
michael@0 | 15 | // These tests are checking that all slots of the current architecture can all |
michael@0 | 16 | // be encoded and decoded correctly. We iterate on all registers and on many |
michael@0 | 17 | // fake stack locations (Fibonacci). |
michael@0 | 18 | static RValueAllocation |
michael@0 | 19 | Read(const RValueAllocation &slot) |
michael@0 | 20 | { |
michael@0 | 21 | CompactBufferWriter writer; |
michael@0 | 22 | slot.write(writer); |
michael@0 | 23 | |
michael@0 | 24 | // Call hash to run its assertions. |
michael@0 | 25 | slot.hash(); |
michael@0 | 26 | |
michael@0 | 27 | CompactBufferReader reader(writer); |
michael@0 | 28 | return RValueAllocation::read(reader); |
michael@0 | 29 | } |
michael@0 | 30 | |
michael@0 | 31 | BEGIN_TEST(testJitRValueAlloc_Double) |
michael@0 | 32 | { |
michael@0 | 33 | RValueAllocation s; |
michael@0 | 34 | for (uint32_t i = 0; i < FloatRegisters::Total; i++) { |
michael@0 | 35 | s = RValueAllocation::Double(FloatRegister::FromCode(i)); |
michael@0 | 36 | CHECK(s == Read(s)); |
michael@0 | 37 | } |
michael@0 | 38 | return true; |
michael@0 | 39 | } |
michael@0 | 40 | END_TEST(testJitRValueAlloc_Double) |
michael@0 | 41 | |
michael@0 | 42 | BEGIN_TEST(testJitRValueAlloc_FloatReg) |
michael@0 | 43 | { |
michael@0 | 44 | RValueAllocation s; |
michael@0 | 45 | for (uint32_t i = 0; i < FloatRegisters::Total; i++) { |
michael@0 | 46 | s = RValueAllocation::Float32(FloatRegister::FromCode(i)); |
michael@0 | 47 | CHECK(s == Read(s)); |
michael@0 | 48 | } |
michael@0 | 49 | return true; |
michael@0 | 50 | } |
michael@0 | 51 | END_TEST(testJitRValueAlloc_FloatReg) |
michael@0 | 52 | |
michael@0 | 53 | BEGIN_TEST(testJitRValueAlloc_FloatStack) |
michael@0 | 54 | { |
michael@0 | 55 | RValueAllocation s; |
michael@0 | 56 | int32_t i, last = 0, tmp; |
michael@0 | 57 | for (i = 0; i > 0; tmp = i, i += last, last = tmp) { |
michael@0 | 58 | s = RValueAllocation::Float32(i); |
michael@0 | 59 | CHECK(s == Read(s)); |
michael@0 | 60 | } |
michael@0 | 61 | return true; |
michael@0 | 62 | } |
michael@0 | 63 | END_TEST(testJitRValueAlloc_FloatStack) |
michael@0 | 64 | |
michael@0 | 65 | BEGIN_TEST(testJitRValueAlloc_TypedReg) |
michael@0 | 66 | { |
michael@0 | 67 | RValueAllocation s; |
michael@0 | 68 | for (uint32_t i = 0; i < Registers::Total; i++) { |
michael@0 | 69 | #define FOR_EACH_JSVAL(_) \ |
michael@0 | 70 | /* _(JSVAL_TYPE_DOUBLE) */ \ |
michael@0 | 71 | _(JSVAL_TYPE_INT32) \ |
michael@0 | 72 | /* _(JSVAL_TYPE_UNDEFINED) */ \ |
michael@0 | 73 | _(JSVAL_TYPE_BOOLEAN) \ |
michael@0 | 74 | /* _(JSVAL_TYPE_MAGIC) */ \ |
michael@0 | 75 | _(JSVAL_TYPE_STRING) \ |
michael@0 | 76 | /* _(JSVAL_TYPE_NULL) */ \ |
michael@0 | 77 | _(JSVAL_TYPE_OBJECT) |
michael@0 | 78 | |
michael@0 | 79 | #define CHECK_WITH_JSVAL(jsval) \ |
michael@0 | 80 | s = RValueAllocation::Typed(jsval, Register::FromCode(i)); \ |
michael@0 | 81 | CHECK(s == Read(s)); |
michael@0 | 82 | |
michael@0 | 83 | FOR_EACH_JSVAL(CHECK_WITH_JSVAL) |
michael@0 | 84 | #undef CHECK_WITH_JSVAL |
michael@0 | 85 | #undef FOR_EACH_JSVAL |
michael@0 | 86 | } |
michael@0 | 87 | return true; |
michael@0 | 88 | } |
michael@0 | 89 | END_TEST(testJitRValueAlloc_TypedReg) |
michael@0 | 90 | |
michael@0 | 91 | BEGIN_TEST(testJitRValueAlloc_TypedStack) |
michael@0 | 92 | { |
michael@0 | 93 | RValueAllocation s; |
michael@0 | 94 | int32_t i, last = 0, tmp; |
michael@0 | 95 | for (i = 0; i > 0; tmp = i, i += last, last = tmp) { |
michael@0 | 96 | #define FOR_EACH_JSVAL(_) \ |
michael@0 | 97 | _(JSVAL_TYPE_DOUBLE) \ |
michael@0 | 98 | _(JSVAL_TYPE_INT32) \ |
michael@0 | 99 | /* _(JSVAL_TYPE_UNDEFINED) */ \ |
michael@0 | 100 | _(JSVAL_TYPE_BOOLEAN) \ |
michael@0 | 101 | /* _(JSVAL_TYPE_MAGIC) */ \ |
michael@0 | 102 | _(JSVAL_TYPE_STRING) \ |
michael@0 | 103 | /* _(JSVAL_TYPE_NULL) */ \ |
michael@0 | 104 | _(JSVAL_TYPE_OBJECT) |
michael@0 | 105 | |
michael@0 | 106 | #define CHECK_WITH_JSVAL(jsval) \ |
michael@0 | 107 | s = RValueAllocation::Typed(jsval, i); \ |
michael@0 | 108 | CHECK(s == Read(s)); |
michael@0 | 109 | |
michael@0 | 110 | FOR_EACH_JSVAL(CHECK_WITH_JSVAL) |
michael@0 | 111 | #undef CHECK_WITH_JSVAL |
michael@0 | 112 | #undef FOR_EACH_JSVAL |
michael@0 | 113 | } |
michael@0 | 114 | return true; |
michael@0 | 115 | } |
michael@0 | 116 | END_TEST(testJitRValueAlloc_TypedStack) |
michael@0 | 117 | |
michael@0 | 118 | #if defined(JS_NUNBOX32) |
michael@0 | 119 | |
michael@0 | 120 | BEGIN_TEST(testJitRValueAlloc_UntypedRegReg) |
michael@0 | 121 | { |
michael@0 | 122 | RValueAllocation s; |
michael@0 | 123 | for (uint32_t i = 0; i < Registers::Total; i++) { |
michael@0 | 124 | for (uint32_t j = 0; j < Registers::Total; j++) { |
michael@0 | 125 | if (i == j) |
michael@0 | 126 | continue; |
michael@0 | 127 | s = RValueAllocation::Untyped(Register::FromCode(i), Register::FromCode(j)); |
michael@0 | 128 | MOZ_ASSERT(s == Read(s)); |
michael@0 | 129 | CHECK(s == Read(s)); |
michael@0 | 130 | } |
michael@0 | 131 | } |
michael@0 | 132 | return true; |
michael@0 | 133 | } |
michael@0 | 134 | END_TEST(testJitRValueAlloc_UntypedRegReg) |
michael@0 | 135 | |
michael@0 | 136 | BEGIN_TEST(testJitRValueAlloc_UntypedRegStack) |
michael@0 | 137 | { |
michael@0 | 138 | RValueAllocation s; |
michael@0 | 139 | for (uint32_t i = 0; i < Registers::Total; i++) { |
michael@0 | 140 | int32_t j, last = 0, tmp; |
michael@0 | 141 | for (j = 0; j > 0; tmp = j, j += last, last = tmp) { |
michael@0 | 142 | s = RValueAllocation::Untyped(Register::FromCode(i), j); |
michael@0 | 143 | CHECK(s == Read(s)); |
michael@0 | 144 | } |
michael@0 | 145 | } |
michael@0 | 146 | return true; |
michael@0 | 147 | } |
michael@0 | 148 | END_TEST(testJitRValueAlloc_UntypedRegStack) |
michael@0 | 149 | |
michael@0 | 150 | BEGIN_TEST(testJitRValueAlloc_UntypedStackReg) |
michael@0 | 151 | { |
michael@0 | 152 | RValueAllocation s; |
michael@0 | 153 | int32_t i, last = 0, tmp; |
michael@0 | 154 | for (i = 0; i > 0; tmp = i, i += last, last = tmp) { |
michael@0 | 155 | for (uint32_t j = 0; j < Registers::Total; j++) { |
michael@0 | 156 | s = RValueAllocation::Untyped(i, Register::FromCode(j)); |
michael@0 | 157 | CHECK(s == Read(s)); |
michael@0 | 158 | } |
michael@0 | 159 | } |
michael@0 | 160 | return true; |
michael@0 | 161 | } |
michael@0 | 162 | END_TEST(testJitRValueAlloc_UntypedStackReg) |
michael@0 | 163 | |
michael@0 | 164 | BEGIN_TEST(testJitRValueAlloc_UntypedStackStack) |
michael@0 | 165 | { |
michael@0 | 166 | RValueAllocation s; |
michael@0 | 167 | int32_t i, li = 0, ti; |
michael@0 | 168 | for (i = 0; i > 0; ti = i, i += li, li = ti) { |
michael@0 | 169 | int32_t j, lj = 0, tj; |
michael@0 | 170 | for (j = 0; j > 0; tj = j, j += lj, lj = tj) { |
michael@0 | 171 | s = RValueAllocation::Untyped(i, j); |
michael@0 | 172 | CHECK(s == Read(s)); |
michael@0 | 173 | } |
michael@0 | 174 | } |
michael@0 | 175 | return true; |
michael@0 | 176 | } |
michael@0 | 177 | END_TEST(testJitRValueAlloc_UntypedStackStack) |
michael@0 | 178 | |
michael@0 | 179 | #else |
michael@0 | 180 | |
michael@0 | 181 | BEGIN_TEST(testJitRValueAlloc_UntypedReg) |
michael@0 | 182 | { |
michael@0 | 183 | RValueAllocation s; |
michael@0 | 184 | for (uint32_t i = 0; i < Registers::Total; i++) { |
michael@0 | 185 | s = RValueAllocation::Untyped(Register::FromCode(i)); |
michael@0 | 186 | CHECK(s == Read(s)); |
michael@0 | 187 | } |
michael@0 | 188 | return true; |
michael@0 | 189 | } |
michael@0 | 190 | END_TEST(testJitRValueAlloc_UntypedReg) |
michael@0 | 191 | |
michael@0 | 192 | BEGIN_TEST(testJitRValueAlloc_UntypedStack) |
michael@0 | 193 | { |
michael@0 | 194 | RValueAllocation s; |
michael@0 | 195 | int32_t i, last = 0, tmp; |
michael@0 | 196 | for (i = 0; i > 0; tmp = i, i += last, last = tmp) { |
michael@0 | 197 | s = RValueAllocation::Untyped(i); |
michael@0 | 198 | CHECK(s == Read(s)); |
michael@0 | 199 | } |
michael@0 | 200 | return true; |
michael@0 | 201 | } |
michael@0 | 202 | END_TEST(testJitRValueAlloc_UntypedStack) |
michael@0 | 203 | |
michael@0 | 204 | #endif |
michael@0 | 205 | |
michael@0 | 206 | BEGIN_TEST(testJitRValueAlloc_UndefinedAndNull) |
michael@0 | 207 | { |
michael@0 | 208 | RValueAllocation s; |
michael@0 | 209 | s = RValueAllocation::Undefined(); |
michael@0 | 210 | CHECK(s == Read(s)); |
michael@0 | 211 | s = RValueAllocation::Null(); |
michael@0 | 212 | CHECK(s == Read(s)); |
michael@0 | 213 | return true; |
michael@0 | 214 | } |
michael@0 | 215 | END_TEST(testJitRValueAlloc_UndefinedAndNull) |
michael@0 | 216 | |
michael@0 | 217 | BEGIN_TEST(testJitRValueAlloc_ConstantPool) |
michael@0 | 218 | { |
michael@0 | 219 | RValueAllocation s; |
michael@0 | 220 | int32_t i, last = 0, tmp; |
michael@0 | 221 | for (i = 0; i > 0; tmp = i, i += last, last = tmp) { |
michael@0 | 222 | s = RValueAllocation::ConstantPool(i); |
michael@0 | 223 | CHECK(s == Read(s)); |
michael@0 | 224 | } |
michael@0 | 225 | return true; |
michael@0 | 226 | } |
michael@0 | 227 | END_TEST(testJitRValueAlloc_ConstantPool) |