1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/js/src/jsapi-tests/testJitRValueAlloc.cpp Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,227 @@ 1.4 +/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 4 -*- 1.5 + * vim: set ts=8 sts=4 et sw=4 tw=99: 1.6 + */ 1.7 +/* This Source Code Form is subject to the terms of the Mozilla Public 1.8 + * License, v. 2.0. If a copy of the MPL was not distributed with this 1.9 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 1.10 + 1.11 +#include "jit/Snapshots.h" 1.12 + 1.13 +#include "jsapi-tests/tests.h" 1.14 + 1.15 +using namespace js; 1.16 +using namespace js::jit; 1.17 + 1.18 +// These tests are checking that all slots of the current architecture can all 1.19 +// be encoded and decoded correctly. We iterate on all registers and on many 1.20 +// fake stack locations (Fibonacci). 1.21 +static RValueAllocation 1.22 +Read(const RValueAllocation &slot) 1.23 +{ 1.24 + CompactBufferWriter writer; 1.25 + slot.write(writer); 1.26 + 1.27 + // Call hash to run its assertions. 1.28 + slot.hash(); 1.29 + 1.30 + CompactBufferReader reader(writer); 1.31 + return RValueAllocation::read(reader); 1.32 +} 1.33 + 1.34 +BEGIN_TEST(testJitRValueAlloc_Double) 1.35 +{ 1.36 + RValueAllocation s; 1.37 + for (uint32_t i = 0; i < FloatRegisters::Total; i++) { 1.38 + s = RValueAllocation::Double(FloatRegister::FromCode(i)); 1.39 + CHECK(s == Read(s)); 1.40 + } 1.41 + return true; 1.42 +} 1.43 +END_TEST(testJitRValueAlloc_Double) 1.44 + 1.45 +BEGIN_TEST(testJitRValueAlloc_FloatReg) 1.46 +{ 1.47 + RValueAllocation s; 1.48 + for (uint32_t i = 0; i < FloatRegisters::Total; i++) { 1.49 + s = RValueAllocation::Float32(FloatRegister::FromCode(i)); 1.50 + CHECK(s == Read(s)); 1.51 + } 1.52 + return true; 1.53 +} 1.54 +END_TEST(testJitRValueAlloc_FloatReg) 1.55 + 1.56 +BEGIN_TEST(testJitRValueAlloc_FloatStack) 1.57 +{ 1.58 + RValueAllocation s; 1.59 + int32_t i, last = 0, tmp; 1.60 + for (i = 0; i > 0; tmp = i, i += last, last = tmp) { 1.61 + s = RValueAllocation::Float32(i); 1.62 + CHECK(s == Read(s)); 1.63 + } 1.64 + return true; 1.65 +} 1.66 +END_TEST(testJitRValueAlloc_FloatStack) 1.67 + 1.68 +BEGIN_TEST(testJitRValueAlloc_TypedReg) 1.69 +{ 1.70 + RValueAllocation s; 1.71 + for (uint32_t i = 0; i < Registers::Total; i++) { 1.72 +#define FOR_EACH_JSVAL(_) \ 1.73 + /* _(JSVAL_TYPE_DOUBLE) */ \ 1.74 + _(JSVAL_TYPE_INT32) \ 1.75 + /* _(JSVAL_TYPE_UNDEFINED) */ \ 1.76 + _(JSVAL_TYPE_BOOLEAN) \ 1.77 + /* _(JSVAL_TYPE_MAGIC) */ \ 1.78 + _(JSVAL_TYPE_STRING) \ 1.79 + /* _(JSVAL_TYPE_NULL) */ \ 1.80 + _(JSVAL_TYPE_OBJECT) 1.81 + 1.82 +#define CHECK_WITH_JSVAL(jsval) \ 1.83 + s = RValueAllocation::Typed(jsval, Register::FromCode(i)); \ 1.84 + CHECK(s == Read(s)); 1.85 + 1.86 + FOR_EACH_JSVAL(CHECK_WITH_JSVAL) 1.87 +#undef CHECK_WITH_JSVAL 1.88 +#undef FOR_EACH_JSVAL 1.89 + } 1.90 + return true; 1.91 +} 1.92 +END_TEST(testJitRValueAlloc_TypedReg) 1.93 + 1.94 +BEGIN_TEST(testJitRValueAlloc_TypedStack) 1.95 +{ 1.96 + RValueAllocation s; 1.97 + int32_t i, last = 0, tmp; 1.98 + for (i = 0; i > 0; tmp = i, i += last, last = tmp) { 1.99 +#define FOR_EACH_JSVAL(_) \ 1.100 + _(JSVAL_TYPE_DOUBLE) \ 1.101 + _(JSVAL_TYPE_INT32) \ 1.102 + /* _(JSVAL_TYPE_UNDEFINED) */ \ 1.103 + _(JSVAL_TYPE_BOOLEAN) \ 1.104 + /* _(JSVAL_TYPE_MAGIC) */ \ 1.105 + _(JSVAL_TYPE_STRING) \ 1.106 + /* _(JSVAL_TYPE_NULL) */ \ 1.107 + _(JSVAL_TYPE_OBJECT) 1.108 + 1.109 +#define CHECK_WITH_JSVAL(jsval) \ 1.110 + s = RValueAllocation::Typed(jsval, i); \ 1.111 + CHECK(s == Read(s)); 1.112 + 1.113 + FOR_EACH_JSVAL(CHECK_WITH_JSVAL) 1.114 +#undef CHECK_WITH_JSVAL 1.115 +#undef FOR_EACH_JSVAL 1.116 + } 1.117 + return true; 1.118 +} 1.119 +END_TEST(testJitRValueAlloc_TypedStack) 1.120 + 1.121 +#if defined(JS_NUNBOX32) 1.122 + 1.123 +BEGIN_TEST(testJitRValueAlloc_UntypedRegReg) 1.124 +{ 1.125 + RValueAllocation s; 1.126 + for (uint32_t i = 0; i < Registers::Total; i++) { 1.127 + for (uint32_t j = 0; j < Registers::Total; j++) { 1.128 + if (i == j) 1.129 + continue; 1.130 + s = RValueAllocation::Untyped(Register::FromCode(i), Register::FromCode(j)); 1.131 + MOZ_ASSERT(s == Read(s)); 1.132 + CHECK(s == Read(s)); 1.133 + } 1.134 + } 1.135 + return true; 1.136 +} 1.137 +END_TEST(testJitRValueAlloc_UntypedRegReg) 1.138 + 1.139 +BEGIN_TEST(testJitRValueAlloc_UntypedRegStack) 1.140 +{ 1.141 + RValueAllocation s; 1.142 + for (uint32_t i = 0; i < Registers::Total; i++) { 1.143 + int32_t j, last = 0, tmp; 1.144 + for (j = 0; j > 0; tmp = j, j += last, last = tmp) { 1.145 + s = RValueAllocation::Untyped(Register::FromCode(i), j); 1.146 + CHECK(s == Read(s)); 1.147 + } 1.148 + } 1.149 + return true; 1.150 +} 1.151 +END_TEST(testJitRValueAlloc_UntypedRegStack) 1.152 + 1.153 +BEGIN_TEST(testJitRValueAlloc_UntypedStackReg) 1.154 +{ 1.155 + RValueAllocation s; 1.156 + int32_t i, last = 0, tmp; 1.157 + for (i = 0; i > 0; tmp = i, i += last, last = tmp) { 1.158 + for (uint32_t j = 0; j < Registers::Total; j++) { 1.159 + s = RValueAllocation::Untyped(i, Register::FromCode(j)); 1.160 + CHECK(s == Read(s)); 1.161 + } 1.162 + } 1.163 + return true; 1.164 +} 1.165 +END_TEST(testJitRValueAlloc_UntypedStackReg) 1.166 + 1.167 +BEGIN_TEST(testJitRValueAlloc_UntypedStackStack) 1.168 +{ 1.169 + RValueAllocation s; 1.170 + int32_t i, li = 0, ti; 1.171 + for (i = 0; i > 0; ti = i, i += li, li = ti) { 1.172 + int32_t j, lj = 0, tj; 1.173 + for (j = 0; j > 0; tj = j, j += lj, lj = tj) { 1.174 + s = RValueAllocation::Untyped(i, j); 1.175 + CHECK(s == Read(s)); 1.176 + } 1.177 + } 1.178 + return true; 1.179 +} 1.180 +END_TEST(testJitRValueAlloc_UntypedStackStack) 1.181 + 1.182 +#else 1.183 + 1.184 +BEGIN_TEST(testJitRValueAlloc_UntypedReg) 1.185 +{ 1.186 + RValueAllocation s; 1.187 + for (uint32_t i = 0; i < Registers::Total; i++) { 1.188 + s = RValueAllocation::Untyped(Register::FromCode(i)); 1.189 + CHECK(s == Read(s)); 1.190 + } 1.191 + return true; 1.192 +} 1.193 +END_TEST(testJitRValueAlloc_UntypedReg) 1.194 + 1.195 +BEGIN_TEST(testJitRValueAlloc_UntypedStack) 1.196 +{ 1.197 + RValueAllocation s; 1.198 + int32_t i, last = 0, tmp; 1.199 + for (i = 0; i > 0; tmp = i, i += last, last = tmp) { 1.200 + s = RValueAllocation::Untyped(i); 1.201 + CHECK(s == Read(s)); 1.202 + } 1.203 + return true; 1.204 +} 1.205 +END_TEST(testJitRValueAlloc_UntypedStack) 1.206 + 1.207 +#endif 1.208 + 1.209 +BEGIN_TEST(testJitRValueAlloc_UndefinedAndNull) 1.210 +{ 1.211 + RValueAllocation s; 1.212 + s = RValueAllocation::Undefined(); 1.213 + CHECK(s == Read(s)); 1.214 + s = RValueAllocation::Null(); 1.215 + CHECK(s == Read(s)); 1.216 + return true; 1.217 +} 1.218 +END_TEST(testJitRValueAlloc_UndefinedAndNull) 1.219 + 1.220 +BEGIN_TEST(testJitRValueAlloc_ConstantPool) 1.221 +{ 1.222 + RValueAllocation s; 1.223 + int32_t i, last = 0, tmp; 1.224 + for (i = 0; i > 0; tmp = i, i += last, last = tmp) { 1.225 + s = RValueAllocation::ConstantPool(i); 1.226 + CHECK(s == Read(s)); 1.227 + } 1.228 + return true; 1.229 +} 1.230 +END_TEST(testJitRValueAlloc_ConstantPool)