Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2)

Side by Side Diff: src/wasm/wasm-macro-gen.h

Issue 1760363003: Revert of [wasm] Update {i32,i64}.const to use signed leb128 (Closed) Base URL: http://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 4 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « src/wasm/decoder.h ('k') | test/cctest/wasm/test-run-wasm.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2015 the V8 project authors. All rights reserved. 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 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #ifndef V8_WASM_MACRO_GEN_H_ 5 #ifndef V8_WASM_MACRO_GEN_H_
6 #define V8_WASM_MACRO_GEN_H_ 6 #define V8_WASM_MACRO_GEN_H_
7 7
8 #include "src/wasm/wasm-opcodes.h" 8 #include "src/wasm/wasm-opcodes.h"
9 9
10 // Convenience macros for building Wasm bytecode directly into a byte array. 10 // Convenience macros for building Wasm bytecode directly into a byte array.
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 #define WASM_CASE(x) static_cast<byte>(x), static_cast<byte>(x >> 8) 45 #define WASM_CASE(x) static_cast<byte>(x), static_cast<byte>(x >> 8)
46 #define WASM_CASE_BR(x) static_cast<byte>(x), static_cast<byte>(0x80 | (x) >> 8) 46 #define WASM_CASE_BR(x) static_cast<byte>(x), static_cast<byte>(0x80 | (x) >> 8)
47 47
48 //------------------------------------------------------------------------------ 48 //------------------------------------------------------------------------------
49 // Misc expressions. 49 // Misc expressions.
50 //------------------------------------------------------------------------------ 50 //------------------------------------------------------------------------------
51 #define WASM_ID(...) __VA_ARGS__ 51 #define WASM_ID(...) __VA_ARGS__
52 #define WASM_ZERO kExprI8Const, 0 52 #define WASM_ZERO kExprI8Const, 0
53 #define WASM_ONE kExprI8Const, 1 53 #define WASM_ONE kExprI8Const, 1
54 #define WASM_I8(val) kExprI8Const, static_cast<byte>(val) 54 #define WASM_I8(val) kExprI8Const, static_cast<byte>(val)
55 55 #define WASM_I32(val) \
56 //------------------------------------------------------------------------------ 56 kExprI32Const, static_cast<byte>(val), static_cast<byte>(val >> 8), \
57 // Int32 Const operations 57 static_cast<byte>(val >> 16), static_cast<byte>(val >> 24)
58 //------------------------------------------------------------------------------ 58 #define WASM_I64(val) \
59 namespace v8 { 59 kExprI64Const, static_cast<byte>(static_cast<uint64_t>(val)), \
60 namespace internal { 60 static_cast<byte>(static_cast<uint64_t>(val) >> 8), \
61 namespace wasm { 61 static_cast<byte>(static_cast<uint64_t>(val) >> 16), \
62 62 static_cast<byte>(static_cast<uint64_t>(val) >> 24), \
63 #define I32V_MIN(length) -(1 << (6 + (7 * ((length) - 1)))) 63 static_cast<byte>(static_cast<uint64_t>(val) >> 32), \
64 #define I32V_MAX(length) ((1 << (6 + (7 * ((length) - 1)))) - 1) 64 static_cast<byte>(static_cast<uint64_t>(val) >> 40), \
65 65 static_cast<byte>(static_cast<uint64_t>(val) >> 48), \
66 #define I32V_IN_RANGE(value, length) \ 66 static_cast<byte>(static_cast<uint64_t>(val) >> 56)
67 ((value) >= I32V_MIN(length) && (value) <= I32V_MAX(length))
68
69 inline void CheckI32v(int32_t value, int length) {
70 DCHECK(length >= 1 && length <= 5);
71 DCHECK(length == 5 || I32V_IN_RANGE(value, length));
72 DCHECK(length == 1 || !I32V_IN_RANGE(value, length - 1));
73 }
74
75 } // namespace wasm
76 } // namespace internal
77 } // namespace v8
78
79 #define WASM_I32V(val) kExprI32Const, U32V_5(val)
80
81 #define WASM_I32V_1(val) \
82 static_cast<byte>(CheckI32v((val), 1), kExprI32Const), U32V_1(val)
83 #define WASM_I32V_2(val) \
84 static_cast<byte>(CheckI32v((val), 2), kExprI32Const), U32V_2(val)
85 #define WASM_I32V_3(val) \
86 static_cast<byte>(CheckI32v((val), 3), kExprI32Const), U32V_3(val)
87 #define WASM_I32V_4(val) \
88 static_cast<byte>(CheckI32v((val), 4), kExprI32Const), U32V_4(val)
89 #define WASM_I32V_5(val) \
90 static_cast<byte>(CheckI32v((val), 5), kExprI32Const), U32V_5(val)
91
92 //------------------------------------------------------------------------------
93 // Int64 Const operations
94 //------------------------------------------------------------------------------
95 namespace v8 {
96 namespace internal {
97 namespace wasm {
98
99 #define I64V_MIN(length) -(1LL << (6 + (7 * ((length)-1))))
100 #define I64V_MAX(length) ((1LL << (6 + 7 * ((length)-1))) - 1)
101
102 #define I64V_IN_RANGE(value, length) \
103 ((value) >= I64V_MIN(length) && (value) <= I64V_MAX(length))
104
105 inline void CheckI64v(int64_t value, int length) {
106 DCHECK(length >= 1 && length <= 10);
107 DCHECK(length == 10 || I64V_IN_RANGE(value, length));
108 DCHECK(length == 1 || !I64V_IN_RANGE(value, length - 1));
109 }
110
111 } // namespace wasm
112 } // namespace internal
113 } // namespace v8
114
115 #define WASM_I64V(val) \
116 kExprI64Const, \
117 static_cast<byte>((static_cast<int64_t>(val) & MASK_7) | 0x80), \
118 static_cast<byte>(((static_cast<int64_t>(val) >> 7) & MASK_7) | 0x80), \
119 static_cast<byte>(((static_cast<int64_t>(val) >> 14) & MASK_7) | 0x80), \
120 static_cast<byte>(((static_cast<int64_t>(val) >> 21) & MASK_7) | 0x80), \
121 static_cast<byte>(((static_cast<int64_t>(val) >> 28) & MASK_7) | 0x80), \
122 static_cast<byte>(((static_cast<int64_t>(val) >> 35) & MASK_7) | 0x80), \
123 static_cast<byte>(((static_cast<int64_t>(val) >> 42) & MASK_7) | 0x80), \
124 static_cast<byte>(((static_cast<int64_t>(val) >> 49) & MASK_7) | 0x80), \
125 static_cast<byte>(((static_cast<int64_t>(val) >> 56) & MASK_7) | 0x80), \
126 static_cast<byte>((static_cast<int64_t>(val) >> 63) & MASK_7)
127
128 #define WASM_I64V_1(val) \
129 static_cast<byte>(CheckI64v(static_cast<int64_t>(val), 1), kExprI64Const), \
130 static_cast<byte>(static_cast<int64_t>(val) & MASK_7)
131 #define WASM_I64V_2(val) \
132 static_cast<byte>(CheckI64v(static_cast<int64_t>(val), 2), kExprI64Const), \
133 static_cast<byte>((static_cast<int64_t>(val) & MASK_7) | 0x80), \
134 static_cast<byte>((static_cast<int64_t>(val) >> 7) & MASK_7)
135 #define WASM_I64V_3(val) \
136 static_cast<byte>(CheckI64v(static_cast<int64_t>(val), 3), kExprI64Const), \
137 static_cast<byte>((static_cast<int64_t>(val) & MASK_7) | 0x80), \
138 static_cast<byte>(((static_cast<int64_t>(val) >> 7) & MASK_7) | 0x80), \
139 static_cast<byte>((static_cast<int64_t>(val) >> 14) & MASK_7)
140 #define WASM_I64V_4(val) \
141 static_cast<byte>(CheckI64v(static_cast<int64_t>(val), 4), kExprI64Const), \
142 static_cast<byte>((static_cast<int64_t>(val) & MASK_7) | 0x80), \
143 static_cast<byte>(((static_cast<int64_t>(val) >> 7) & MASK_7) | 0x80), \
144 static_cast<byte>(((static_cast<int64_t>(val) >> 14) & MASK_7) | 0x80), \
145 static_cast<byte>((static_cast<int64_t>(val) >> 21) & MASK_7)
146 #define WASM_I64V_5(val) \
147 static_cast<byte>(CheckI64v(static_cast<int64_t>(val), 5), kExprI64Const), \
148 static_cast<byte>((static_cast<int64_t>(val) & MASK_7) | 0x80), \
149 static_cast<byte>(((static_cast<int64_t>(val) >> 7) & MASK_7) | 0x80), \
150 static_cast<byte>(((static_cast<int64_t>(val) >> 14) & MASK_7) | 0x80), \
151 static_cast<byte>(((static_cast<int64_t>(val) >> 21) & MASK_7) | 0x80), \
152 static_cast<byte>((static_cast<int64_t>(val) >> 28) & MASK_7)
153 #define WASM_I64V_6(val) \
154 static_cast<byte>(CheckI64v(static_cast<int64_t>(val), 6), kExprI64Const), \
155 static_cast<byte>((static_cast<int64_t>(val) & MASK_7) | 0x80), \
156 static_cast<byte>(((static_cast<int64_t>(val) >> 7) & MASK_7) | 0x80), \
157 static_cast<byte>(((static_cast<int64_t>(val) >> 14) & MASK_7) | 0x80), \
158 static_cast<byte>(((static_cast<int64_t>(val) >> 21) & MASK_7) | 0x80), \
159 static_cast<byte>(((static_cast<int64_t>(val) >> 28) & MASK_7) | 0x80), \
160 static_cast<byte>((static_cast<int64_t>(val) >> 35) & MASK_7)
161 #define WASM_I64V_7(val) \
162 static_cast<byte>(CheckI64v(static_cast<int64_t>(val), 7), kExprI64Const), \
163 static_cast<byte>((static_cast<int64_t>(val) & MASK_7) | 0x80), \
164 static_cast<byte>(((static_cast<int64_t>(val) >> 7) & MASK_7) | 0x80), \
165 static_cast<byte>(((static_cast<int64_t>(val) >> 14) & MASK_7) | 0x80), \
166 static_cast<byte>(((static_cast<int64_t>(val) >> 21) & MASK_7) | 0x80), \
167 static_cast<byte>(((static_cast<int64_t>(val) >> 28) & MASK_7) | 0x80), \
168 static_cast<byte>(((static_cast<int64_t>(val) >> 35) & MASK_7) | 0x80), \
169 static_cast<byte>((static_cast<int64_t>(val) >> 42) & MASK_7)
170 #define WASM_I64V_8(val) \
171 static_cast<byte>(CheckI64v(static_cast<int64_t>(val), 8), kExprI64Const), \
172 static_cast<byte>((static_cast<int64_t>(val) & MASK_7) | 0x80), \
173 static_cast<byte>(((static_cast<int64_t>(val) >> 7) & MASK_7) | 0x80), \
174 static_cast<byte>(((static_cast<int64_t>(val) >> 14) & MASK_7) | 0x80), \
175 static_cast<byte>(((static_cast<int64_t>(val) >> 21) & MASK_7) | 0x80), \
176 static_cast<byte>(((static_cast<int64_t>(val) >> 28) & MASK_7) | 0x80), \
177 static_cast<byte>(((static_cast<int64_t>(val) >> 35) & MASK_7) | 0x80), \
178 static_cast<byte>(((static_cast<int64_t>(val) >> 42) & MASK_7) | 0x80), \
179 static_cast<byte>((static_cast<int64_t>(val) >> 49) & MASK_7)
180 #define WASM_I64V_9(val) \
181 static_cast<byte>(CheckI64v(static_cast<int64_t>(val), 9), kExprI64Const), \
182 static_cast<byte>((static_cast<int64_t>(val) & MASK_7) | 0x80), \
183 static_cast<byte>(((static_cast<int64_t>(val) >> 7) & MASK_7) | 0x80), \
184 static_cast<byte>(((static_cast<int64_t>(val) >> 14) & MASK_7) | 0x80), \
185 static_cast<byte>(((static_cast<int64_t>(val) >> 21) & MASK_7) | 0x80), \
186 static_cast<byte>(((static_cast<int64_t>(val) >> 28) & MASK_7) | 0x80), \
187 static_cast<byte>(((static_cast<int64_t>(val) >> 35) & MASK_7) | 0x80), \
188 static_cast<byte>(((static_cast<int64_t>(val) >> 42) & MASK_7) | 0x80), \
189 static_cast<byte>(((static_cast<int64_t>(val) >> 49) & MASK_7) | 0x80), \
190 static_cast<byte>((static_cast<int64_t>(val) >> 56) & MASK_7)
191 #define WASM_I64V_10(val) \
192 static_cast<byte>(CheckI64v(static_cast<int64_t>(val), 10), kExprI64Const), \
193 static_cast<byte>((static_cast<int64_t>(val) & MASK_7) | 0x80), \
194 static_cast<byte>(((static_cast<int64_t>(val) >> 7) & MASK_7) | 0x80), \
195 static_cast<byte>(((static_cast<int64_t>(val) >> 14) & MASK_7) | 0x80), \
196 static_cast<byte>(((static_cast<int64_t>(val) >> 21) & MASK_7) | 0x80), \
197 static_cast<byte>(((static_cast<int64_t>(val) >> 28) & MASK_7) | 0x80), \
198 static_cast<byte>(((static_cast<int64_t>(val) >> 35) & MASK_7) | 0x80), \
199 static_cast<byte>(((static_cast<int64_t>(val) >> 42) & MASK_7) | 0x80), \
200 static_cast<byte>(((static_cast<int64_t>(val) >> 49) & MASK_7) | 0x80), \
201 static_cast<byte>(((static_cast<int64_t>(val) >> 56) & MASK_7) | 0x80), \
202 static_cast<byte>((static_cast<int64_t>(val) >> 63) & MASK_7)
203
204 #define WASM_F32(val) \ 67 #define WASM_F32(val) \
205 kExprF32Const, \ 68 kExprF32Const, \
206 static_cast<byte>(bit_cast<int32_t>(static_cast<float>(val))), \ 69 static_cast<byte>(bit_cast<int32_t>(static_cast<float>(val))), \
207 static_cast<byte>(bit_cast<uint32_t>(static_cast<float>(val)) >> 8), \ 70 static_cast<byte>(bit_cast<uint32_t>(static_cast<float>(val)) >> 8), \
208 static_cast<byte>(bit_cast<uint32_t>(static_cast<float>(val)) >> 16), \ 71 static_cast<byte>(bit_cast<uint32_t>(static_cast<float>(val)) >> 16), \
209 static_cast<byte>(bit_cast<uint32_t>(static_cast<float>(val)) >> 24) 72 static_cast<byte>(bit_cast<uint32_t>(static_cast<float>(val)) >> 24)
210 #define WASM_F64(val) \ 73 #define WASM_F64(val) \
211 kExprF64Const, static_cast<byte>(bit_cast<uint64_t>(val)), \ 74 kExprF64Const, static_cast<byte>(bit_cast<uint64_t>(val)), \
212 static_cast<byte>(bit_cast<uint64_t>(val) >> 8), \ 75 static_cast<byte>(bit_cast<uint64_t>(val) >> 8), \
213 static_cast<byte>(bit_cast<uint64_t>(val) >> 16), \ 76 static_cast<byte>(bit_cast<uint64_t>(val) >> 16), \
(...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after
433 #define U32V_4(x) \ 296 #define U32V_4(x) \
434 static_cast<byte>((x & MASK_7) | 0x80), \ 297 static_cast<byte>((x & MASK_7) | 0x80), \
435 static_cast<byte>(((x >> 7) & MASK_7) | 0x80), \ 298 static_cast<byte>(((x >> 7) & MASK_7) | 0x80), \
436 static_cast<byte>(((x >> 14) & MASK_7) | 0x80), \ 299 static_cast<byte>(((x >> 14) & MASK_7) | 0x80), \
437 static_cast<byte>((x >> 21) & MASK_7) 300 static_cast<byte>((x >> 21) & MASK_7)
438 #define U32V_5(x) \ 301 #define U32V_5(x) \
439 static_cast<byte>((x & MASK_7) | 0x80), \ 302 static_cast<byte>((x & MASK_7) | 0x80), \
440 static_cast<byte>(((x >> 7) & MASK_7) | 0x80), \ 303 static_cast<byte>(((x >> 7) & MASK_7) | 0x80), \
441 static_cast<byte>(((x >> 14) & MASK_7) | 0x80), \ 304 static_cast<byte>(((x >> 14) & MASK_7) | 0x80), \
442 static_cast<byte>(((x >> 21) & MASK_7) | 0x80), \ 305 static_cast<byte>(((x >> 21) & MASK_7) | 0x80), \
443 static_cast<byte>(((x >> 28) & MASK_7)) 306 static_cast<byte>((x >> 28) & 0xF)
444 307
445 #endif // V8_WASM_MACRO_GEN_H_ 308 #endif // V8_WASM_MACRO_GEN_H_
OLDNEW
« no previous file with comments | « src/wasm/decoder.h ('k') | test/cctest/wasm/test-run-wasm.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698