Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 1 | // Copyright 2015 the V8 project authors. All rights reserved. |
| 2 | // Use of this source code is governed by a BSD-style license that can be |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "test/unittests/test-utils.h" |
| 6 | |
| 7 | #include "src/wasm/wasm-macro-gen.h" |
| 8 | |
| 9 | namespace v8 { |
| 10 | namespace internal { |
| 11 | namespace wasm { |
| 12 | |
| 13 | class WasmMacroGenTest : public TestWithZone {}; |
| 14 | |
| 15 | #define EXPECT_SIZE(size, ...) \ |
| 16 | do { \ |
| 17 | byte code[] = {__VA_ARGS__}; \ |
| 18 | EXPECT_EQ(size, sizeof(code)); \ |
| 19 | } while (false) |
| 20 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 21 | TEST_F(WasmMacroGenTest, Constants) { |
| 22 | EXPECT_SIZE(2, WASM_ONE); |
| 23 | EXPECT_SIZE(2, WASM_ZERO); |
| 24 | |
| 25 | EXPECT_SIZE(2, WASM_I8(122)); |
| 26 | EXPECT_SIZE(2, WASM_I8(254)); |
| 27 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 28 | EXPECT_SIZE(2, WASM_I32V_1(1)); |
| 29 | EXPECT_SIZE(3, WASM_I32V_2(200)); |
| 30 | EXPECT_SIZE(4, WASM_I32V_3(10000)); |
| 31 | EXPECT_SIZE(5, WASM_I32V_4(-9828934)); |
| 32 | EXPECT_SIZE(6, WASM_I32V_5(-1119828934)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 33 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 34 | EXPECT_SIZE(2, WASM_I64V_1(1)); |
| 35 | EXPECT_SIZE(3, WASM_I64V_2(300)); |
| 36 | EXPECT_SIZE(4, WASM_I64V_3(10000)); |
| 37 | EXPECT_SIZE(5, WASM_I64V_4(-9828934)); |
| 38 | EXPECT_SIZE(6, WASM_I64V_5(-1119828934)); |
| 39 | EXPECT_SIZE(10, WASM_I64V_9(0x123456789abcdef0ULL)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 40 | |
| 41 | EXPECT_SIZE(5, WASM_F32(1.0f)); |
| 42 | EXPECT_SIZE(5, WASM_F32(10000.0f)); |
| 43 | EXPECT_SIZE(5, WASM_F32(-9828934.0f)); |
| 44 | |
| 45 | EXPECT_SIZE(9, WASM_F64(1.5)); |
| 46 | EXPECT_SIZE(9, WASM_F64(10200.0)); |
| 47 | EXPECT_SIZE(9, WASM_F64(-9818934.0)); |
| 48 | } |
| 49 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 50 | TEST_F(WasmMacroGenTest, Statements) { |
| 51 | EXPECT_SIZE(1, WASM_NOP); |
| 52 | |
| 53 | EXPECT_SIZE(4, WASM_SET_LOCAL(0, WASM_ZERO)); |
| 54 | |
| 55 | EXPECT_SIZE(4, WASM_STORE_GLOBAL(0, WASM_ZERO)); |
| 56 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 57 | EXPECT_SIZE(7, WASM_STORE_MEM(MachineType::Int32(), WASM_ZERO, WASM_ZERO)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 58 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 59 | EXPECT_SIZE(5, WASM_IF(WASM_ZERO, WASM_NOP)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 60 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 61 | EXPECT_SIZE(7, WASM_IF_ELSE(WASM_ZERO, WASM_NOP, WASM_NOP)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 62 | |
| 63 | EXPECT_SIZE(5, WASM_SELECT(WASM_ZERO, WASM_NOP, WASM_NOP)); |
| 64 | |
| 65 | EXPECT_SIZE(3, WASM_BR(0)); |
| 66 | EXPECT_SIZE(5, WASM_BR_IF(0, WASM_ZERO)); |
| 67 | |
| 68 | EXPECT_SIZE(3, WASM_BLOCK(1, WASM_NOP)); |
| 69 | EXPECT_SIZE(4, WASM_BLOCK(2, WASM_NOP, WASM_NOP)); |
| 70 | EXPECT_SIZE(5, WASM_BLOCK(3, WASM_NOP, WASM_NOP, WASM_NOP)); |
| 71 | |
| 72 | EXPECT_SIZE(5, WASM_INFINITE_LOOP); |
| 73 | |
| 74 | EXPECT_SIZE(3, WASM_LOOP(1, WASM_NOP)); |
| 75 | EXPECT_SIZE(4, WASM_LOOP(2, WASM_NOP, WASM_NOP)); |
| 76 | EXPECT_SIZE(5, WASM_LOOP(3, WASM_NOP, WASM_NOP, WASM_NOP)); |
| 77 | EXPECT_SIZE(5, WASM_LOOP(1, WASM_BR(0))); |
| 78 | EXPECT_SIZE(7, WASM_LOOP(1, WASM_BR_IF(0, WASM_ZERO))); |
| 79 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 80 | EXPECT_SIZE(2, WASM_RETURN0); |
| 81 | EXPECT_SIZE(4, WASM_RETURN1(WASM_ZERO)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 82 | |
| 83 | EXPECT_SIZE(1, WASM_UNREACHABLE); |
| 84 | } |
| 85 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 86 | TEST_F(WasmMacroGenTest, MacroStatements) { |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 87 | EXPECT_SIZE(10, WASM_WHILE(WASM_I8(0), WASM_NOP)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 88 | EXPECT_SIZE(7, WASM_INC_LOCAL(0)); |
| 89 | EXPECT_SIZE(7, WASM_INC_LOCAL_BY(0, 3)); |
| 90 | |
| 91 | EXPECT_SIZE(3, WASM_BREAK(0)); |
| 92 | EXPECT_SIZE(3, WASM_CONTINUE(0)); |
| 93 | } |
| 94 | |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 95 | TEST_F(WasmMacroGenTest, BrTable) { |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 96 | EXPECT_SIZE(9, WASM_BR_TABLE(WASM_ZERO, 1, BR_TARGET(1))); |
| 97 | EXPECT_SIZE(11, WASM_BR_TABLEV(WASM_ZERO, WASM_ZERO, 1, BR_TARGET(1))); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 98 | } |
| 99 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 100 | TEST_F(WasmMacroGenTest, Expressions) { |
| 101 | EXPECT_SIZE(2, WASM_GET_LOCAL(0)); |
| 102 | EXPECT_SIZE(2, WASM_GET_LOCAL(1)); |
| 103 | EXPECT_SIZE(2, WASM_GET_LOCAL(12)); |
| 104 | EXPECT_SIZE(2, WASM_LOAD_GLOBAL(0)); |
| 105 | EXPECT_SIZE(2, WASM_LOAD_GLOBAL(1)); |
| 106 | EXPECT_SIZE(2, WASM_LOAD_GLOBAL(12)); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 107 | EXPECT_SIZE(5, WASM_LOAD_MEM(MachineType::Int32(), WASM_ZERO)); |
| 108 | EXPECT_SIZE(5, WASM_LOAD_MEM(MachineType::Float64(), WASM_ZERO)); |
| 109 | EXPECT_SIZE(5, WASM_LOAD_MEM(MachineType::Float32(), WASM_ZERO)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 110 | |
| 111 | EXPECT_SIZE(3, WASM_NOT(WASM_ZERO)); |
| 112 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 113 | EXPECT_SIZE(5, WASM_BRV(1, WASM_ZERO)); |
| 114 | EXPECT_SIZE(7, WASM_BRV_IF(1, WASM_ZERO, WASM_ZERO)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 115 | |
| 116 | EXPECT_SIZE(4, WASM_BLOCK(1, WASM_ZERO)); |
| 117 | EXPECT_SIZE(5, WASM_BLOCK(2, WASM_NOP, WASM_ZERO)); |
| 118 | EXPECT_SIZE(6, WASM_BLOCK(3, WASM_NOP, WASM_NOP, WASM_ZERO)); |
| 119 | |
| 120 | EXPECT_SIZE(4, WASM_LOOP(1, WASM_ZERO)); |
| 121 | EXPECT_SIZE(5, WASM_LOOP(2, WASM_NOP, WASM_ZERO)); |
| 122 | EXPECT_SIZE(6, WASM_LOOP(3, WASM_NOP, WASM_NOP, WASM_ZERO)); |
| 123 | } |
| 124 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 125 | TEST_F(WasmMacroGenTest, CallFunction) { |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 126 | EXPECT_SIZE(3, WASM_CALL_FUNCTION0(0)); |
| 127 | EXPECT_SIZE(3, WASM_CALL_FUNCTION0(1)); |
| 128 | EXPECT_SIZE(3, WASM_CALL_FUNCTION0(11)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 129 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 130 | EXPECT_SIZE(5, WASM_CALL_FUNCTION1(0, WASM_ZERO)); |
| 131 | EXPECT_SIZE(7, WASM_CALL_FUNCTION2(1, WASM_ZERO, WASM_ZERO)); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 132 | } |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 133 | |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 134 | TEST_F(WasmMacroGenTest, CallImport) { |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 135 | EXPECT_SIZE(3, WASM_CALL_IMPORT0(0)); |
| 136 | EXPECT_SIZE(3, WASM_CALL_IMPORT0(1)); |
| 137 | EXPECT_SIZE(3, WASM_CALL_IMPORT0(11)); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 138 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 139 | EXPECT_SIZE(5, WASM_CALL_IMPORT1(0, WASM_ZERO)); |
| 140 | EXPECT_SIZE(7, WASM_CALL_IMPORT2(1, WASM_ZERO, WASM_ZERO)); |
Ben Murdoch | 097c5b2 | 2016-05-18 11:27:45 +0100 | [diff] [blame] | 141 | } |
| 142 | |
| 143 | TEST_F(WasmMacroGenTest, CallIndirect) { |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 144 | EXPECT_SIZE(5, WASM_CALL_INDIRECT0(0, WASM_ZERO)); |
| 145 | EXPECT_SIZE(5, WASM_CALL_INDIRECT0(1, WASM_ZERO)); |
| 146 | EXPECT_SIZE(5, WASM_CALL_INDIRECT0(11, WASM_ZERO)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 147 | |
Ben Murdoch | c561043 | 2016-08-08 18:44:38 +0100 | [diff] [blame^] | 148 | EXPECT_SIZE(7, WASM_CALL_INDIRECT1(0, WASM_ZERO, WASM_ZERO)); |
| 149 | EXPECT_SIZE(9, WASM_CALL_INDIRECT2(1, WASM_ZERO, WASM_ZERO, WASM_ZERO)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 150 | } |
| 151 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 152 | TEST_F(WasmMacroGenTest, Int32Ops) { |
| 153 | EXPECT_SIZE(5, WASM_I32_ADD(WASM_ZERO, WASM_ZERO)); |
| 154 | EXPECT_SIZE(5, WASM_I32_SUB(WASM_ZERO, WASM_ZERO)); |
| 155 | EXPECT_SIZE(5, WASM_I32_MUL(WASM_ZERO, WASM_ZERO)); |
| 156 | EXPECT_SIZE(5, WASM_I32_DIVS(WASM_ZERO, WASM_ZERO)); |
| 157 | EXPECT_SIZE(5, WASM_I32_DIVU(WASM_ZERO, WASM_ZERO)); |
| 158 | EXPECT_SIZE(5, WASM_I32_REMS(WASM_ZERO, WASM_ZERO)); |
| 159 | EXPECT_SIZE(5, WASM_I32_REMU(WASM_ZERO, WASM_ZERO)); |
| 160 | EXPECT_SIZE(5, WASM_I32_AND(WASM_ZERO, WASM_ZERO)); |
| 161 | EXPECT_SIZE(5, WASM_I32_IOR(WASM_ZERO, WASM_ZERO)); |
| 162 | EXPECT_SIZE(5, WASM_I32_XOR(WASM_ZERO, WASM_ZERO)); |
| 163 | EXPECT_SIZE(5, WASM_I32_SHL(WASM_ZERO, WASM_ZERO)); |
| 164 | EXPECT_SIZE(5, WASM_I32_SHR(WASM_ZERO, WASM_ZERO)); |
| 165 | EXPECT_SIZE(5, WASM_I32_SAR(WASM_ZERO, WASM_ZERO)); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 166 | EXPECT_SIZE(5, WASM_I32_ROR(WASM_ZERO, WASM_ZERO)); |
| 167 | EXPECT_SIZE(5, WASM_I32_ROL(WASM_ZERO, WASM_ZERO)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 168 | EXPECT_SIZE(5, WASM_I32_EQ(WASM_ZERO, WASM_ZERO)); |
| 169 | |
| 170 | EXPECT_SIZE(5, WASM_I32_LTS(WASM_ZERO, WASM_ZERO)); |
| 171 | EXPECT_SIZE(5, WASM_I32_LES(WASM_ZERO, WASM_ZERO)); |
| 172 | EXPECT_SIZE(5, WASM_I32_LTU(WASM_ZERO, WASM_ZERO)); |
| 173 | EXPECT_SIZE(5, WASM_I32_LEU(WASM_ZERO, WASM_ZERO)); |
| 174 | |
| 175 | EXPECT_SIZE(5, WASM_I32_GTS(WASM_ZERO, WASM_ZERO)); |
| 176 | EXPECT_SIZE(5, WASM_I32_GES(WASM_ZERO, WASM_ZERO)); |
| 177 | EXPECT_SIZE(5, WASM_I32_GTU(WASM_ZERO, WASM_ZERO)); |
| 178 | EXPECT_SIZE(5, WASM_I32_GEU(WASM_ZERO, WASM_ZERO)); |
| 179 | |
| 180 | EXPECT_SIZE(3, WASM_I32_CLZ(WASM_ZERO)); |
| 181 | EXPECT_SIZE(3, WASM_I32_CTZ(WASM_ZERO)); |
| 182 | EXPECT_SIZE(3, WASM_I32_POPCNT(WASM_ZERO)); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 183 | |
| 184 | EXPECT_SIZE(3, WASM_I32_EQZ(WASM_ZERO)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 185 | } |
| 186 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 187 | TEST_F(WasmMacroGenTest, Int64Ops) { |
| 188 | EXPECT_SIZE(5, WASM_I64_ADD(WASM_ZERO, WASM_ZERO)); |
| 189 | EXPECT_SIZE(5, WASM_I64_SUB(WASM_ZERO, WASM_ZERO)); |
| 190 | EXPECT_SIZE(5, WASM_I64_MUL(WASM_ZERO, WASM_ZERO)); |
| 191 | EXPECT_SIZE(5, WASM_I64_DIVS(WASM_ZERO, WASM_ZERO)); |
| 192 | EXPECT_SIZE(5, WASM_I64_DIVU(WASM_ZERO, WASM_ZERO)); |
| 193 | EXPECT_SIZE(5, WASM_I64_REMS(WASM_ZERO, WASM_ZERO)); |
| 194 | EXPECT_SIZE(5, WASM_I64_REMU(WASM_ZERO, WASM_ZERO)); |
| 195 | EXPECT_SIZE(5, WASM_I64_AND(WASM_ZERO, WASM_ZERO)); |
| 196 | EXPECT_SIZE(5, WASM_I64_IOR(WASM_ZERO, WASM_ZERO)); |
| 197 | EXPECT_SIZE(5, WASM_I64_XOR(WASM_ZERO, WASM_ZERO)); |
| 198 | EXPECT_SIZE(5, WASM_I64_SHL(WASM_ZERO, WASM_ZERO)); |
| 199 | EXPECT_SIZE(5, WASM_I64_SHR(WASM_ZERO, WASM_ZERO)); |
| 200 | EXPECT_SIZE(5, WASM_I64_SAR(WASM_ZERO, WASM_ZERO)); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 201 | EXPECT_SIZE(5, WASM_I64_ROR(WASM_ZERO, WASM_ZERO)); |
| 202 | EXPECT_SIZE(5, WASM_I64_ROL(WASM_ZERO, WASM_ZERO)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 203 | EXPECT_SIZE(5, WASM_I64_EQ(WASM_ZERO, WASM_ZERO)); |
| 204 | |
| 205 | EXPECT_SIZE(5, WASM_I64_LTS(WASM_ZERO, WASM_ZERO)); |
| 206 | EXPECT_SIZE(5, WASM_I64_LES(WASM_ZERO, WASM_ZERO)); |
| 207 | EXPECT_SIZE(5, WASM_I64_LTU(WASM_ZERO, WASM_ZERO)); |
| 208 | EXPECT_SIZE(5, WASM_I64_LEU(WASM_ZERO, WASM_ZERO)); |
| 209 | |
| 210 | EXPECT_SIZE(5, WASM_I64_GTS(WASM_ZERO, WASM_ZERO)); |
| 211 | EXPECT_SIZE(5, WASM_I64_GES(WASM_ZERO, WASM_ZERO)); |
| 212 | EXPECT_SIZE(5, WASM_I64_GTU(WASM_ZERO, WASM_ZERO)); |
| 213 | EXPECT_SIZE(5, WASM_I64_GEU(WASM_ZERO, WASM_ZERO)); |
| 214 | |
| 215 | EXPECT_SIZE(3, WASM_I64_CLZ(WASM_ZERO)); |
| 216 | EXPECT_SIZE(3, WASM_I64_CTZ(WASM_ZERO)); |
| 217 | EXPECT_SIZE(3, WASM_I64_POPCNT(WASM_ZERO)); |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 218 | |
| 219 | EXPECT_SIZE(3, WASM_I64_EQZ(WASM_ZERO)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 220 | } |
| 221 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 222 | TEST_F(WasmMacroGenTest, Float32Ops) { |
| 223 | EXPECT_SIZE(5, WASM_F32_ADD(WASM_ZERO, WASM_ZERO)); |
| 224 | EXPECT_SIZE(5, WASM_F32_SUB(WASM_ZERO, WASM_ZERO)); |
| 225 | EXPECT_SIZE(5, WASM_F32_MUL(WASM_ZERO, WASM_ZERO)); |
| 226 | EXPECT_SIZE(5, WASM_F32_DIV(WASM_ZERO, WASM_ZERO)); |
| 227 | EXPECT_SIZE(5, WASM_F32_MIN(WASM_ZERO, WASM_ZERO)); |
| 228 | EXPECT_SIZE(5, WASM_F32_MAX(WASM_ZERO, WASM_ZERO)); |
| 229 | EXPECT_SIZE(5, WASM_F32_COPYSIGN(WASM_ZERO, WASM_ZERO)); |
| 230 | |
| 231 | EXPECT_SIZE(3, WASM_F32_ABS(WASM_ZERO)); |
| 232 | EXPECT_SIZE(3, WASM_F32_NEG(WASM_ZERO)); |
| 233 | EXPECT_SIZE(3, WASM_F32_CEIL(WASM_ZERO)); |
| 234 | EXPECT_SIZE(3, WASM_F32_FLOOR(WASM_ZERO)); |
| 235 | EXPECT_SIZE(3, WASM_F32_TRUNC(WASM_ZERO)); |
| 236 | EXPECT_SIZE(3, WASM_F32_NEARESTINT(WASM_ZERO)); |
| 237 | EXPECT_SIZE(3, WASM_F32_SQRT(WASM_ZERO)); |
| 238 | |
| 239 | EXPECT_SIZE(5, WASM_F32_EQ(WASM_ZERO, WASM_ZERO)); |
| 240 | EXPECT_SIZE(5, WASM_F32_LT(WASM_ZERO, WASM_ZERO)); |
| 241 | EXPECT_SIZE(5, WASM_F32_LE(WASM_ZERO, WASM_ZERO)); |
| 242 | EXPECT_SIZE(5, WASM_F32_GT(WASM_ZERO, WASM_ZERO)); |
| 243 | EXPECT_SIZE(5, WASM_F32_GE(WASM_ZERO, WASM_ZERO)); |
| 244 | } |
| 245 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 246 | TEST_F(WasmMacroGenTest, Float64Ops) { |
| 247 | EXPECT_SIZE(5, WASM_F64_ADD(WASM_ZERO, WASM_ZERO)); |
| 248 | EXPECT_SIZE(5, WASM_F64_SUB(WASM_ZERO, WASM_ZERO)); |
| 249 | EXPECT_SIZE(5, WASM_F64_MUL(WASM_ZERO, WASM_ZERO)); |
| 250 | EXPECT_SIZE(5, WASM_F64_DIV(WASM_ZERO, WASM_ZERO)); |
| 251 | EXPECT_SIZE(5, WASM_F64_MIN(WASM_ZERO, WASM_ZERO)); |
| 252 | EXPECT_SIZE(5, WASM_F64_MAX(WASM_ZERO, WASM_ZERO)); |
| 253 | EXPECT_SIZE(5, WASM_F64_COPYSIGN(WASM_ZERO, WASM_ZERO)); |
| 254 | |
| 255 | EXPECT_SIZE(3, WASM_F64_ABS(WASM_ZERO)); |
| 256 | EXPECT_SIZE(3, WASM_F64_NEG(WASM_ZERO)); |
| 257 | EXPECT_SIZE(3, WASM_F64_CEIL(WASM_ZERO)); |
| 258 | EXPECT_SIZE(3, WASM_F64_FLOOR(WASM_ZERO)); |
| 259 | EXPECT_SIZE(3, WASM_F64_TRUNC(WASM_ZERO)); |
| 260 | EXPECT_SIZE(3, WASM_F64_NEARESTINT(WASM_ZERO)); |
| 261 | EXPECT_SIZE(3, WASM_F64_SQRT(WASM_ZERO)); |
| 262 | |
| 263 | EXPECT_SIZE(5, WASM_F64_EQ(WASM_ZERO, WASM_ZERO)); |
| 264 | EXPECT_SIZE(5, WASM_F64_LT(WASM_ZERO, WASM_ZERO)); |
| 265 | EXPECT_SIZE(5, WASM_F64_LE(WASM_ZERO, WASM_ZERO)); |
| 266 | EXPECT_SIZE(5, WASM_F64_GT(WASM_ZERO, WASM_ZERO)); |
| 267 | EXPECT_SIZE(5, WASM_F64_GE(WASM_ZERO, WASM_ZERO)); |
| 268 | } |
| 269 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 270 | TEST_F(WasmMacroGenTest, Conversions) { |
| 271 | EXPECT_SIZE(3, WASM_I32_SCONVERT_F32(WASM_ZERO)); |
| 272 | EXPECT_SIZE(3, WASM_I32_SCONVERT_F64(WASM_ZERO)); |
| 273 | EXPECT_SIZE(3, WASM_I32_UCONVERT_F32(WASM_ZERO)); |
| 274 | EXPECT_SIZE(3, WASM_I32_UCONVERT_F64(WASM_ZERO)); |
| 275 | EXPECT_SIZE(3, WASM_I32_CONVERT_I64(WASM_ZERO)); |
| 276 | EXPECT_SIZE(3, WASM_I64_SCONVERT_F32(WASM_ZERO)); |
| 277 | EXPECT_SIZE(3, WASM_I64_SCONVERT_F64(WASM_ZERO)); |
| 278 | EXPECT_SIZE(3, WASM_I64_UCONVERT_F32(WASM_ZERO)); |
| 279 | EXPECT_SIZE(3, WASM_I64_UCONVERT_F64(WASM_ZERO)); |
| 280 | EXPECT_SIZE(3, WASM_I64_SCONVERT_I32(WASM_ZERO)); |
| 281 | EXPECT_SIZE(3, WASM_I64_UCONVERT_I32(WASM_ZERO)); |
| 282 | EXPECT_SIZE(3, WASM_F32_SCONVERT_I32(WASM_ZERO)); |
| 283 | EXPECT_SIZE(3, WASM_F32_UCONVERT_I32(WASM_ZERO)); |
| 284 | EXPECT_SIZE(3, WASM_F32_SCONVERT_I64(WASM_ZERO)); |
| 285 | EXPECT_SIZE(3, WASM_F32_UCONVERT_I64(WASM_ZERO)); |
| 286 | EXPECT_SIZE(3, WASM_F32_CONVERT_F64(WASM_ZERO)); |
| 287 | EXPECT_SIZE(3, WASM_F32_REINTERPRET_I32(WASM_ZERO)); |
| 288 | EXPECT_SIZE(3, WASM_F64_SCONVERT_I32(WASM_ZERO)); |
| 289 | EXPECT_SIZE(3, WASM_F64_UCONVERT_I32(WASM_ZERO)); |
| 290 | EXPECT_SIZE(3, WASM_F64_SCONVERT_I64(WASM_ZERO)); |
| 291 | EXPECT_SIZE(3, WASM_F64_UCONVERT_I64(WASM_ZERO)); |
| 292 | EXPECT_SIZE(3, WASM_F64_CONVERT_F32(WASM_ZERO)); |
| 293 | EXPECT_SIZE(3, WASM_F64_REINTERPRET_I64(WASM_ZERO)); |
| 294 | } |
| 295 | |
| 296 | static const MachineType kMemTypes[] = { |
| 297 | MachineType::Int8(), MachineType::Uint8(), MachineType::Int16(), |
| 298 | MachineType::Uint16(), MachineType::Int32(), MachineType::Uint32(), |
| 299 | MachineType::Int64(), MachineType::Uint64(), MachineType::Float32(), |
| 300 | MachineType::Float64()}; |
| 301 | |
| 302 | TEST_F(WasmMacroGenTest, LoadsAndStores) { |
| 303 | for (size_t i = 0; i < arraysize(kMemTypes); i++) { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 304 | EXPECT_SIZE(5, WASM_LOAD_MEM(kMemTypes[i], WASM_ZERO)); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 305 | } |
| 306 | for (size_t i = 0; i < arraysize(kMemTypes); i++) { |
Ben Murdoch | da12d29 | 2016-06-02 14:46:10 +0100 | [diff] [blame] | 307 | EXPECT_SIZE(7, WASM_STORE_MEM(kMemTypes[i], WASM_ZERO, WASM_GET_LOCAL(0))); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 308 | } |
| 309 | } |
| 310 | |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 311 | TEST_F(WasmMacroGenTest, LoadsAndStoresWithOffset) { |
| 312 | for (size_t i = 0; i < arraysize(kMemTypes); i++) { |
| 313 | EXPECT_SIZE(5, WASM_LOAD_MEM_OFFSET(kMemTypes[i], 11, WASM_ZERO)); |
| 314 | } |
| 315 | for (size_t i = 0; i < arraysize(kMemTypes); i++) { |
| 316 | EXPECT_SIZE(7, WASM_STORE_MEM_OFFSET(kMemTypes[i], 13, WASM_ZERO, |
| 317 | WASM_GET_LOCAL(0))); |
| 318 | } |
| 319 | } |
| 320 | } // namespace wasm |
| 321 | } // namespace internal |
| 322 | } // namespace v8 |