blob: 4e5a653a9de2504b1b48389c59a78354a0a6c8ae [file] [log] [blame]
Ethan Nicholas26a9aad2018-03-27 14:10:52 -04001/*
2 * Copyright 2018 Google Inc.
3 *
4 * Use of this source code is governed by a BSD-style license that can be
5 * found in the LICENSE file.
6 */
7
8#ifndef SKSL_STANDALONE
9
Ethan Nicholasae9633b2019-05-24 12:46:34 -040010#include "include/core/SkPoint3.h"
Brian Osman569f12f2019-06-13 11:23:57 -040011#include "include/private/SkVx.h"
Mike Klein7a177b42019-06-17 17:17:47 -050012#include "src/core/SkUtils.h" // sk_unaligned_load
Brian Osman80164412019-06-07 13:00:23 -040013#include "src/sksl/SkSLByteCode.h"
Brian Osman07c117b2019-05-23 12:51:06 -070014#include "src/sksl/SkSLByteCodeGenerator.h"
Ethan Nicholas91164d12019-05-15 15:29:54 -040015#include "src/sksl/SkSLExternalValue.h"
Brian Osman80164412019-06-07 13:00:23 -040016
17#include <vector>
Ethan Nicholas26a9aad2018-03-27 14:10:52 -040018
19namespace SkSL {
Brian Osman489cf882019-07-09 10:48:28 -040020
21#if defined(SK_ENABLE_SKSL_INTERPRETER)
22
Brian Osman80164412019-06-07 13:00:23 -040023namespace Interpreter {
Ethan Nicholas26a9aad2018-03-27 14:10:52 -040024
Mike Reed3fd3cc92019-06-20 12:40:30 -040025constexpr int VecWidth = ByteCode::kVecWidth;
Brian Osman569f12f2019-06-13 11:23:57 -040026
27using F32 = skvx::Vec<VecWidth, float>;
28using I32 = skvx::Vec<VecWidth, int32_t>;
29using U32 = skvx::Vec<VecWidth, uint32_t>;
30
Mike Kleine7007382019-05-21 08:36:32 -050031#define READ8() (*(ip++))
Mike Klein7a177b42019-06-17 17:17:47 -050032#define READ16() (ip += 2, sk_unaligned_load<uint16_t>(ip - 2))
33#define READ32() (ip += 4, sk_unaligned_load<uint32_t>(ip - 4))
Ethan Nicholas0e9401d2019-03-21 11:05:37 -040034
Brian Osman3e833e12019-05-23 13:23:24 -070035#define VECTOR_DISASSEMBLE(op, text) \
Ethan Nicholas48a75aa2019-05-16 17:15:56 -040036 case ByteCodeInstruction::op: printf(text); break; \
37 case ByteCodeInstruction::op##2: printf(text "2"); break; \
38 case ByteCodeInstruction::op##3: printf(text "3"); break; \
39 case ByteCodeInstruction::op##4: printf(text "4"); break;
40
Brian Osman1e855b22019-05-29 15:21:52 -040041#define VECTOR_MATRIX_DISASSEMBLE(op, text) \
42 case ByteCodeInstruction::op: printf(text); break; \
43 case ByteCodeInstruction::op##2: printf(text "2"); break; \
44 case ByteCodeInstruction::op##3: printf(text "3"); break; \
45 case ByteCodeInstruction::op##4: printf(text "4"); break; \
46 case ByteCodeInstruction::op##N: printf(text "N %d", READ8()); break;
47
Brian Osman3e833e12019-05-23 13:23:24 -070048static const uint8_t* disassemble_instruction(const uint8_t* ip) {
49 switch ((ByteCodeInstruction) READ16()) {
Brian Osman1e855b22019-05-29 15:21:52 -040050 VECTOR_MATRIX_DISASSEMBLE(kAddF, "addf")
Brian Osman3e833e12019-05-23 13:23:24 -070051 VECTOR_DISASSEMBLE(kAddI, "addi")
Brian Osman32c526b2019-06-03 16:13:52 -040052 case ByteCodeInstruction::kAndB: printf("andb"); break;
Brian Osman3e833e12019-05-23 13:23:24 -070053 case ByteCodeInstruction::kBranch: printf("branch %d", READ16()); break;
54 case ByteCodeInstruction::kCall: printf("call %d", READ8()); break;
55 case ByteCodeInstruction::kCallExternal: {
56 int argumentCount = READ8();
57 int returnCount = READ8();
58 int externalValue = READ8();
59 printf("callexternal %d, %d, %d", argumentCount, returnCount, externalValue);
60 break;
61 }
62 VECTOR_DISASSEMBLE(kCompareIEQ, "compareieq")
63 VECTOR_DISASSEMBLE(kCompareINEQ, "compareineq")
Brian Osman1e855b22019-05-29 15:21:52 -040064 VECTOR_MATRIX_DISASSEMBLE(kCompareFEQ, "comparefeq")
65 VECTOR_MATRIX_DISASSEMBLE(kCompareFNEQ, "comparefneq")
Brian Osman3e833e12019-05-23 13:23:24 -070066 VECTOR_DISASSEMBLE(kCompareFGT, "comparefgt")
67 VECTOR_DISASSEMBLE(kCompareFGTEQ, "comparefgteq")
68 VECTOR_DISASSEMBLE(kCompareFLT, "compareflt")
69 VECTOR_DISASSEMBLE(kCompareFLTEQ, "compareflteq")
70 VECTOR_DISASSEMBLE(kCompareSGT, "comparesgt")
71 VECTOR_DISASSEMBLE(kCompareSGTEQ, "comparesgteq")
72 VECTOR_DISASSEMBLE(kCompareSLT, "compareslt")
73 VECTOR_DISASSEMBLE(kCompareSLTEQ, "compareslteq")
74 VECTOR_DISASSEMBLE(kCompareUGT, "compareugt")
75 VECTOR_DISASSEMBLE(kCompareUGTEQ, "compareugteq")
76 VECTOR_DISASSEMBLE(kCompareULT, "compareult")
77 VECTOR_DISASSEMBLE(kCompareULTEQ, "compareulteq")
Brian Osman3e833e12019-05-23 13:23:24 -070078 VECTOR_DISASSEMBLE(kConvertFtoI, "convertftoi")
79 VECTOR_DISASSEMBLE(kConvertStoF, "convertstof")
80 VECTOR_DISASSEMBLE(kConvertUtoF, "convertutof")
81 VECTOR_DISASSEMBLE(kCos, "cos")
Brian Osmanecb3bb52019-06-20 14:59:12 -040082 case ByteCodeInstruction::kCross: printf("cross"); break;
Brian Osman1e855b22019-05-29 15:21:52 -040083 VECTOR_MATRIX_DISASSEMBLE(kDivideF, "dividef")
Brian Osman3e833e12019-05-23 13:23:24 -070084 VECTOR_DISASSEMBLE(kDivideS, "divideS")
85 VECTOR_DISASSEMBLE(kDivideU, "divideu")
Brian Osman1e855b22019-05-29 15:21:52 -040086 VECTOR_MATRIX_DISASSEMBLE(kDup, "dup")
Brian Osman3e833e12019-05-23 13:23:24 -070087 case ByteCodeInstruction::kLoad: printf("load %d", READ8()); break;
88 case ByteCodeInstruction::kLoad2: printf("load2 %d", READ8()); break;
89 case ByteCodeInstruction::kLoad3: printf("load3 %d", READ8()); break;
90 case ByteCodeInstruction::kLoad4: printf("load4 %d", READ8()); break;
91 case ByteCodeInstruction::kLoadGlobal: printf("loadglobal %d", READ8()); break;
92 case ByteCodeInstruction::kLoadGlobal2: printf("loadglobal2 %d", READ8()); break;
93 case ByteCodeInstruction::kLoadGlobal3: printf("loadglobal3 %d", READ8()); break;
94 case ByteCodeInstruction::kLoadGlobal4: printf("loadglobal4 %d", READ8()); break;
95 case ByteCodeInstruction::kLoadSwizzle: {
96 int target = READ8();
97 int count = READ8();
98 printf("loadswizzle %d %d", target, count);
99 for (int i = 0; i < count; ++i) {
100 printf(", %d", READ8());
101 }
102 break;
103 }
104 case ByteCodeInstruction::kLoadSwizzleGlobal: {
105 int target = READ8();
106 int count = READ8();
107 printf("loadswizzleglobal %d %d", target, count);
108 for (int i = 0; i < count; ++i) {
109 printf(", %d", READ8());
110 }
111 break;
112 }
113 case ByteCodeInstruction::kLoadExtended: printf("loadextended %d", READ8()); break;
114 case ByteCodeInstruction::kLoadExtendedGlobal: printf("loadextendedglobal %d", READ8());
115 break;
Brian Osman29e013d2019-05-28 17:16:03 -0400116 case ByteCodeInstruction::kMatrixToMatrix: {
117 int srcCols = READ8();
118 int srcRows = READ8();
119 int dstCols = READ8();
120 int dstRows = READ8();
121 printf("matrixtomatrix %dx%d %dx%d", srcCols, srcRows, dstCols, dstRows);
122 break;
123 }
Brian Osman909231c2019-05-29 15:34:36 -0400124 case ByteCodeInstruction::kMatrixMultiply: {
125 int lCols = READ8();
126 int lRows = READ8();
127 int rCols = READ8();
128 printf("matrixmultiply %dx%d %dx%d", lCols, lRows, rCols, lCols);
129 break;
130 }
Ethan Nicholasae9633b2019-05-24 12:46:34 -0400131 VECTOR_DISASSEMBLE(kMix, "mix")
Brian Osman1e855b22019-05-29 15:21:52 -0400132 VECTOR_MATRIX_DISASSEMBLE(kMultiplyF, "multiplyf")
Brian Osman3e833e12019-05-23 13:23:24 -0700133 VECTOR_DISASSEMBLE(kMultiplyI, "multiplyi")
Brian Osman1e855b22019-05-29 15:21:52 -0400134 VECTOR_MATRIX_DISASSEMBLE(kNegateF, "negatef")
Brian Osman3e833e12019-05-23 13:23:24 -0700135 VECTOR_DISASSEMBLE(kNegateI, "negatei")
Brian Osman569f12f2019-06-13 11:23:57 -0400136 case ByteCodeInstruction::kNotB: printf("notb"); break;
Brian Osman32c526b2019-06-03 16:13:52 -0400137 case ByteCodeInstruction::kOrB: printf("orb"); break;
Brian Osman1e855b22019-05-29 15:21:52 -0400138 VECTOR_MATRIX_DISASSEMBLE(kPop, "pop")
Brian Osman3e833e12019-05-23 13:23:24 -0700139 case ByteCodeInstruction::kPushImmediate: {
140 uint32_t v = READ32();
141 union { uint32_t u; float f; } pun = { v };
142 printf("pushimmediate %s", (to_string(v) + "(" + to_string(pun.f) + ")").c_str());
143 break;
144 }
145 case ByteCodeInstruction::kReadExternal: printf("readexternal %d", READ8()); break;
146 case ByteCodeInstruction::kReadExternal2: printf("readexternal2 %d", READ8()); break;
147 case ByteCodeInstruction::kReadExternal3: printf("readexternal3 %d", READ8()); break;
148 case ByteCodeInstruction::kReadExternal4: printf("readexternal4 %d", READ8()); break;
149 VECTOR_DISASSEMBLE(kRemainderF, "remainderf")
150 VECTOR_DISASSEMBLE(kRemainderS, "remainders")
151 VECTOR_DISASSEMBLE(kRemainderU, "remainderu")
Brian Osmand3494ed2019-06-20 15:41:34 -0400152 case ByteCodeInstruction::kReserve: printf("reserve %d", READ8()); break;
Brian Osman3e833e12019-05-23 13:23:24 -0700153 case ByteCodeInstruction::kReturn: printf("return %d", READ8()); break;
Brian Osman29e013d2019-05-28 17:16:03 -0400154 case ByteCodeInstruction::kScalarToMatrix: {
155 int cols = READ8();
156 int rows = READ8();
157 printf("scalartomatrix %dx%d", cols, rows);
158 break;
159 }
Brian Osman3e833e12019-05-23 13:23:24 -0700160 VECTOR_DISASSEMBLE(kSin, "sin")
161 VECTOR_DISASSEMBLE(kSqrt, "sqrt")
162 case ByteCodeInstruction::kStore: printf("store %d", READ8()); break;
163 case ByteCodeInstruction::kStore2: printf("store2 %d", READ8()); break;
164 case ByteCodeInstruction::kStore3: printf("store3 %d", READ8()); break;
165 case ByteCodeInstruction::kStore4: printf("store4 %d", READ8()); break;
166 case ByteCodeInstruction::kStoreGlobal: printf("storeglobal %d", READ8()); break;
167 case ByteCodeInstruction::kStoreGlobal2: printf("storeglobal2 %d", READ8()); break;
168 case ByteCodeInstruction::kStoreGlobal3: printf("storeglobal3 %d", READ8()); break;
169 case ByteCodeInstruction::kStoreGlobal4: printf("storeglobal4 %d", READ8()); break;
170 case ByteCodeInstruction::kStoreSwizzle: {
171 int target = READ8();
172 int count = READ8();
173 printf("storeswizzle %d %d", target, count);
174 for (int i = 0; i < count; ++i) {
175 printf(", %d", READ8());
176 }
177 break;
178 }
179 case ByteCodeInstruction::kStoreSwizzleGlobal: {
180 int target = READ8();
181 int count = READ8();
182 printf("storeswizzleglobal %d %d", target, count);
183 for (int i = 0; i < count; ++i) {
184 printf(", %d", READ8());
185 }
186 break;
187 }
188 case ByteCodeInstruction::kStoreSwizzleIndirect: {
189 int count = READ8();
190 printf("storeswizzleindirect %d", count);
191 for (int i = 0; i < count; ++i) {
192 printf(", %d", READ8());
193 }
194 break;
195 }
196 case ByteCodeInstruction::kStoreSwizzleIndirectGlobal: {
197 int count = READ8();
198 printf("storeswizzleindirectglobal %d", count);
199 for (int i = 0; i < count; ++i) {
200 printf(", %d", READ8());
201 }
202 break;
203 }
204 case ByteCodeInstruction::kStoreExtended: printf("storeextended %d", READ8()); break;
205 case ByteCodeInstruction::kStoreExtendedGlobal: printf("storeextendedglobal %d", READ8());
206 break;
Brian Osman1e855b22019-05-29 15:21:52 -0400207 VECTOR_MATRIX_DISASSEMBLE(kSubtractF, "subtractf")
Brian Osman3e833e12019-05-23 13:23:24 -0700208 VECTOR_DISASSEMBLE(kSubtractI, "subtracti")
209 case ByteCodeInstruction::kSwizzle: {
210 printf("swizzle %d, ", READ8());
211 int count = READ8();
212 printf("%d", count);
213 for (int i = 0; i < count; ++i) {
214 printf(", %d", READ8());
215 }
216 break;
217 }
218 VECTOR_DISASSEMBLE(kTan, "tan")
219 case ByteCodeInstruction::kWriteExternal: printf("writeexternal %d", READ8()); break;
220 case ByteCodeInstruction::kWriteExternal2: printf("writeexternal2 %d", READ8()); break;
221 case ByteCodeInstruction::kWriteExternal3: printf("writeexternal3 %d", READ8()); break;
222 case ByteCodeInstruction::kWriteExternal4: printf("writeexternal4 %d", READ8()); break;
Brian Osman569f12f2019-06-13 11:23:57 -0400223 case ByteCodeInstruction::kXorB: printf("xorb"); break;
224 case ByteCodeInstruction::kMaskPush: printf("maskpush"); break;
225 case ByteCodeInstruction::kMaskPop: printf("maskpop"); break;
226 case ByteCodeInstruction::kMaskNegate: printf("masknegate"); break;
227 case ByteCodeInstruction::kMaskBlend: printf("maskblend %d", READ8()); break;
228 case ByteCodeInstruction::kBranchIfAllFalse:
229 printf("branchifallfalse %d", READ16());
230 break;
231 case ByteCodeInstruction::kLoopBegin: printf("loopbegin"); break;
232 case ByteCodeInstruction::kLoopNext: printf("loopnext"); break;
233 case ByteCodeInstruction::kLoopMask: printf("loopmask"); break;
234 case ByteCodeInstruction::kLoopEnd: printf("loopend"); break;
235 case ByteCodeInstruction::kLoopContinue: printf("loopcontinue"); break;
236 case ByteCodeInstruction::kLoopBreak: printf("loopbreak"); break;
Brian Osman3e833e12019-05-23 13:23:24 -0700237 default: printf("unknown(%d)\n", *(ip - 1)); SkASSERT(false);
238 }
239 return ip;
240}
241
Mike Klein459aed12019-05-21 15:46:36 -0500242#define VECTOR_BINARY_OP(base, field, op) \
Mike Kleine7007382019-05-21 08:36:32 -0500243 case ByteCodeInstruction::base ## 4: \
Mike Klein459aed12019-05-21 15:46:36 -0500244 sp[-4] = sp[-4].field op sp[0].field; \
Mike Kleine7007382019-05-21 08:36:32 -0500245 POP(); \
246 /* fall through */ \
247 case ByteCodeInstruction::base ## 3: { \
248 int count = (int) ByteCodeInstruction::base - (int) inst - 1; \
Mike Klein459aed12019-05-21 15:46:36 -0500249 sp[count] = sp[count].field op sp[0].field; \
Mike Kleine7007382019-05-21 08:36:32 -0500250 POP(); \
251 } /* fall through */ \
252 case ByteCodeInstruction::base ## 2: { \
253 int count = (int) ByteCodeInstruction::base - (int) inst - 1; \
Mike Klein459aed12019-05-21 15:46:36 -0500254 sp[count] = sp[count].field op sp[0].field; \
Mike Kleine7007382019-05-21 08:36:32 -0500255 POP(); \
256 } /* fall through */ \
257 case ByteCodeInstruction::base: { \
258 int count = (int) ByteCodeInstruction::base - (int) inst - 1; \
Mike Klein459aed12019-05-21 15:46:36 -0500259 sp[count] = sp[count].field op sp[0].field; \
Mike Kleine7007382019-05-21 08:36:32 -0500260 POP(); \
261 break; \
262 }
Ethan Nicholasaeb71ce2019-05-20 09:55:44 -0400263
Brian Osman1e855b22019-05-29 15:21:52 -0400264#define VECTOR_MATRIX_BINARY_OP(base, field, op) \
265 VECTOR_BINARY_OP(base, field, op) \
266 case ByteCodeInstruction::base ## N: { \
267 int count = READ8(); \
268 for (int i = count; i > 0; --i) { \
269 sp[-count] = sp[-count].field op sp[0].field; \
270 POP(); \
271 } \
272 break; \
273 }
274
Ethan Nicholasae9633b2019-05-24 12:46:34 -0400275#define VECTOR_BINARY_FN(base, field, fn) \
276 case ByteCodeInstruction::base ## 4: \
277 sp[-4] = fn(sp[-4].field, sp[0].field); \
278 POP(); \
279 /* fall through */ \
280 case ByteCodeInstruction::base ## 3: { \
281 int target = (int) ByteCodeInstruction::base - (int) inst - 1; \
282 sp[target] = fn(sp[target].field, sp[0].field); \
283 POP(); \
284 } /* fall through */ \
285 case ByteCodeInstruction::base ## 2: { \
286 int target = (int) ByteCodeInstruction::base - (int) inst - 1; \
287 sp[target] = fn(sp[target].field, sp[0].field); \
288 POP(); \
289 } /* fall through */ \
290 case ByteCodeInstruction::base: { \
291 int target = (int) ByteCodeInstruction::base - (int) inst - 1; \
292 sp[target] = fn(sp[target].field, sp[0].field); \
293 POP(); \
294 break; \
Mike Kleine7007382019-05-21 08:36:32 -0500295 }
Ethan Nicholas0e9401d2019-03-21 11:05:37 -0400296
Mike Klein459aed12019-05-21 15:46:36 -0500297#define VECTOR_UNARY_FN(base, fn, field) \
298 case ByteCodeInstruction::base ## 4: sp[-3] = fn(sp[-3].field); \
299 case ByteCodeInstruction::base ## 3: sp[-2] = fn(sp[-2].field); \
300 case ByteCodeInstruction::base ## 2: sp[-1] = fn(sp[-1].field); \
301 case ByteCodeInstruction::base: sp[ 0] = fn(sp[ 0].field); \
Ethan Nicholas82162ee2019-05-21 16:05:08 -0400302 break;
303
Brian Osman569f12f2019-06-13 11:23:57 -0400304#define VECTOR_UNARY_FN_VEC(base, fn) \
305 case ByteCodeInstruction::base ## 4: \
306 case ByteCodeInstruction::base ## 3: \
307 case ByteCodeInstruction::base ## 2: \
308 case ByteCodeInstruction::base : { \
309 int count = (int)inst - (int)ByteCodeInstruction::base + 1; \
310 float* v = (float*)sp - count + 1; \
311 for (int i = VecWidth * count; i > 0; --i, ++v) { \
312 *v = fn(*v); \
313 } \
314 break; \
315 }
316
317union VValue {
318 VValue() {}
319
320 VValue(F32 f)
321 : fFloat(f) {
322 }
323
324 VValue(I32 s)
325 : fSigned(s) {
326 }
327
328 VValue(U32 u)
329 : fUnsigned(u) {
330 }
331
332 F32 fFloat;
333 I32 fSigned;
334 U32 fUnsigned;
335};
336
Brian Osman226668a2019-05-14 16:47:30 -0400337struct StackFrame {
338 const uint8_t* fCode;
339 const uint8_t* fIP;
Brian Osman569f12f2019-06-13 11:23:57 -0400340 VValue* fStack;
Brian Osmand3494ed2019-06-20 15:41:34 -0400341 int fParameterCount;
Brian Osman226668a2019-05-14 16:47:30 -0400342};
343
Brian Osman569f12f2019-06-13 11:23:57 -0400344static F32 mix(F32 start, F32 end, F32 t) {
Ethan Nicholasae9633b2019-05-24 12:46:34 -0400345 return start * (1 - t) + end * t;
346}
347
Brian Osman569f12f2019-06-13 11:23:57 -0400348// TODO: trunc on integers?
349template <typename T>
350static T vec_mod(T a, T b) {
351 return a - skvx::trunc(a / b) * b;
352}
Mike Kleine7007382019-05-21 08:36:32 -0500353
Brian Osman4b202a32019-06-21 09:50:29 -0400354static void innerRun(const ByteCode* byteCode, const ByteCodeFunction* f, VValue* stack,
Brian Osman1a79f0b2019-06-24 16:32:14 -0400355 float* outReturn[], VValue globals[], bool stripedOutput, int N,
356 int baseIndex) {
Brian Osman4b202a32019-06-21 09:50:29 -0400357 // Needs to be the first N non-negative integers, at least as large as VecWidth
358 static const Interpreter::I32 gLanes = {
359 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15
360 };
361
Brian Osman569f12f2019-06-13 11:23:57 -0400362 VValue* sp = stack + f->fParameterCount + f->fLocalCount - 1;
363
364 auto POP = [&] { SkASSERT(sp >= stack); return *(sp--); };
365 auto PUSH = [&](VValue v) { SkASSERT(sp + 1 >= stack); *(++sp) = v; };
Mike Kleine7007382019-05-21 08:36:32 -0500366
Brian Osman80164412019-06-07 13:00:23 -0400367 const uint8_t* code = f->fCode.data();
Ethan Nicholasdfcad062019-05-07 12:53:34 -0400368 const uint8_t* ip = code;
Brian Osman226668a2019-05-14 16:47:30 -0400369 std::vector<StackFrame> frames;
370
Brian Osman569f12f2019-06-13 11:23:57 -0400371 I32 condStack[16]; // Independent condition masks
372 I32 maskStack[16]; // Combined masks (eg maskStack[0] & maskStack[1] & ...)
373 I32 contStack[16]; // Continue flags for loops
374 I32 loopStack[16]; // Loop execution masks
Brian Osman4b202a32019-06-21 09:50:29 -0400375 condStack[0] = maskStack[0] = (gLanes < N);
Brian Osman569f12f2019-06-13 11:23:57 -0400376 contStack[0] = I32( 0);
377 loopStack[0] = I32(~0);
378 I32* condPtr = condStack;
379 I32* maskPtr = maskStack;
380 I32* contPtr = contStack;
381 I32* loopPtr = loopStack;
382
Brian Osmanaa2ca3f2019-07-15 13:24:48 -0400383 if (f->fConditionCount + 1 > (int)SK_ARRAY_COUNT(condStack) ||
384 f->fLoopCount + 1 > (int)SK_ARRAY_COUNT(loopStack)) {
385 SkDEBUGFAIL("Function with too much nested control flow to evaluate");
386 return;
387 }
388
Brian Osman569f12f2019-06-13 11:23:57 -0400389 auto mask = [&]() { return *maskPtr & *loopPtr; };
390
Ethan Nicholas7e603db2019-05-03 12:57:47 -0400391 for (;;) {
Ethan Nicholasdfcad062019-05-07 12:53:34 -0400392#ifdef TRACE
Brian Osman3e833e12019-05-23 13:23:24 -0700393 printf("at %3d ", (int) (ip - code));
394 disassemble_instruction(ip);
395 printf("\n");
Ethan Nicholasdfcad062019-05-07 12:53:34 -0400396#endif
Brian Osmane85b6a52019-05-22 14:50:59 -0700397 ByteCodeInstruction inst = (ByteCodeInstruction) READ16();
Ethan Nicholas9764ebd2019-05-01 14:43:54 -0400398 switch (inst) {
Mike Kleinc1999982019-05-21 13:03:49 -0500399 VECTOR_BINARY_OP(kAddI, fSigned, +)
Brian Osman1e855b22019-05-29 15:21:52 -0400400 VECTOR_MATRIX_BINARY_OP(kAddF, fFloat, +)
Brian Osman569f12f2019-06-13 11:23:57 -0400401
402 // Booleans are integer masks: 0/~0 for false/true. So bitwise ops do what we want:
Brian Osman32c526b2019-06-03 16:13:52 -0400403 case ByteCodeInstruction::kAndB:
Brian Osman569f12f2019-06-13 11:23:57 -0400404 sp[-1] = sp[-1].fSigned & sp[0].fSigned;
405 POP();
406 break;
407 case ByteCodeInstruction::kNotB:
408 sp[0] = ~sp[0].fSigned;
409 break;
410 case ByteCodeInstruction::kOrB:
411 sp[-1] = sp[-1].fSigned | sp[0].fSigned;
412 POP();
413 break;
414 case ByteCodeInstruction::kXorB:
415 sp[-1] = sp[-1].fSigned ^ sp[0].fSigned;
Brian Osman32c526b2019-06-03 16:13:52 -0400416 POP();
417 break;
Ethan Nicholas82162ee2019-05-21 16:05:08 -0400418
Ethan Nicholas48a75aa2019-05-16 17:15:56 -0400419 case ByteCodeInstruction::kBranch:
Ethan Nicholasdfcad062019-05-07 12:53:34 -0400420 ip = code + READ16();
Ethan Nicholas9764ebd2019-05-01 14:43:54 -0400421 break;
Ethan Nicholas82162ee2019-05-21 16:05:08 -0400422
Brian Osman226668a2019-05-14 16:47:30 -0400423 case ByteCodeInstruction::kCall: {
Brian Osmand3494ed2019-06-20 15:41:34 -0400424 // Precursor code reserved space for the return value, and pushed all parameters to
425 // the stack. Update our bottom of stack to point at the first parameter, and our
426 // sp to point past those parameters (plus space for locals).
Mike Kleine7007382019-05-21 08:36:32 -0500427 int target = READ8();
Brian Osman80164412019-06-07 13:00:23 -0400428 const ByteCodeFunction* fun = byteCode->fFunctions[target].get();
Brian Osman569f12f2019-06-13 11:23:57 -0400429 if (skvx::any(mask())) {
Brian Osmand3494ed2019-06-20 15:41:34 -0400430 frames.push_back({ code, ip, stack, fun->fParameterCount });
Brian Osman569f12f2019-06-13 11:23:57 -0400431 ip = code = fun->fCode.data();
432 stack = sp - fun->fParameterCount + 1;
433 sp = stack + fun->fParameterCount + fun->fLocalCount - 1;
Brian Osman569f12f2019-06-13 11:23:57 -0400434 }
Brian Osman226668a2019-05-14 16:47:30 -0400435 break;
436 }
Ethan Nicholas82162ee2019-05-21 16:05:08 -0400437
Ethan Nicholas9e6a3932019-05-17 16:31:21 -0400438 case ByteCodeInstruction::kCallExternal: {
439 int argumentCount = READ8();
440 int returnCount = READ8();
Mike Kleine7007382019-05-21 08:36:32 -0500441 int target = READ8();
Brian Osman80164412019-06-07 13:00:23 -0400442 ExternalValue* v = byteCode->fExternalValues[target];
Ethan Nicholas9e6a3932019-05-17 16:31:21 -0400443 sp -= argumentCount - 1;
Mike Kleine7007382019-05-21 08:36:32 -0500444
Brian Osman1a79f0b2019-06-24 16:32:14 -0400445 float tmpArgs[4];
446 float tmpReturn[4];
Brian Osman569f12f2019-06-13 11:23:57 -0400447 SkASSERT(argumentCount <= (int)SK_ARRAY_COUNT(tmpArgs));
448 SkASSERT(returnCount <= (int)SK_ARRAY_COUNT(tmpReturn));
449
450 I32 m = mask();
451 for (int i = 0; i < VecWidth; ++i) {
452 if (m[i]) {
453 for (int j = 0; j < argumentCount; ++j) {
Brian Osman1a79f0b2019-06-24 16:32:14 -0400454 tmpArgs[j] = sp[j].fFloat[i];
Brian Osman569f12f2019-06-13 11:23:57 -0400455 }
Brian Osman1a79f0b2019-06-24 16:32:14 -0400456 v->call(baseIndex + i, tmpArgs, tmpReturn);
Brian Osman569f12f2019-06-13 11:23:57 -0400457 for (int j = 0; j < returnCount; ++j) {
Brian Osman1a79f0b2019-06-24 16:32:14 -0400458 sp[j].fFloat[i] = tmpReturn[j];
Brian Osman569f12f2019-06-13 11:23:57 -0400459 }
460 }
461 }
Ethan Nicholas9e6a3932019-05-17 16:31:21 -0400462 sp += returnCount - 1;
463 break;
464 }
Ethan Nicholas82162ee2019-05-21 16:05:08 -0400465
Mike Kleinc1999982019-05-21 13:03:49 -0500466 VECTOR_BINARY_OP(kCompareIEQ, fSigned, ==)
Brian Osman1e855b22019-05-29 15:21:52 -0400467 VECTOR_MATRIX_BINARY_OP(kCompareFEQ, fFloat, ==)
Mike Kleinc1999982019-05-21 13:03:49 -0500468 VECTOR_BINARY_OP(kCompareINEQ, fSigned, !=)
Brian Osman1e855b22019-05-29 15:21:52 -0400469 VECTOR_MATRIX_BINARY_OP(kCompareFNEQ, fFloat, !=)
Mike Kleinc1999982019-05-21 13:03:49 -0500470 VECTOR_BINARY_OP(kCompareSGT, fSigned, >)
471 VECTOR_BINARY_OP(kCompareUGT, fUnsigned, >)
472 VECTOR_BINARY_OP(kCompareFGT, fFloat, >)
473 VECTOR_BINARY_OP(kCompareSGTEQ, fSigned, >=)
474 VECTOR_BINARY_OP(kCompareUGTEQ, fUnsigned, >=)
475 VECTOR_BINARY_OP(kCompareFGTEQ, fFloat, >=)
476 VECTOR_BINARY_OP(kCompareSLT, fSigned, <)
477 VECTOR_BINARY_OP(kCompareULT, fUnsigned, <)
478 VECTOR_BINARY_OP(kCompareFLT, fFloat, <)
479 VECTOR_BINARY_OP(kCompareSLTEQ, fSigned, <=)
480 VECTOR_BINARY_OP(kCompareULTEQ, fUnsigned, <=)
481 VECTOR_BINARY_OP(kCompareFLTEQ, fFloat, <=)
Ethan Nicholas82162ee2019-05-21 16:05:08 -0400482
Brian Osman569f12f2019-06-13 11:23:57 -0400483 case ByteCodeInstruction::kConvertFtoI4: sp[-3] = skvx::cast<int>(sp[-3].fFloat);
484 case ByteCodeInstruction::kConvertFtoI3: sp[-2] = skvx::cast<int>(sp[-2].fFloat);
485 case ByteCodeInstruction::kConvertFtoI2: sp[-1] = skvx::cast<int>(sp[-1].fFloat);
486 case ByteCodeInstruction::kConvertFtoI: sp[ 0] = skvx::cast<int>(sp[ 0].fFloat);
Ethan Nicholas82162ee2019-05-21 16:05:08 -0400487 break;
488
Brian Osman569f12f2019-06-13 11:23:57 -0400489 case ByteCodeInstruction::kConvertStoF4: sp[-3] = skvx::cast<float>(sp[-3].fSigned);
490 case ByteCodeInstruction::kConvertStoF3: sp[-2] = skvx::cast<float>(sp[-2].fSigned);
491 case ByteCodeInstruction::kConvertStoF2: sp[-1] = skvx::cast<float>(sp[-1].fSigned);
492 case ByteCodeInstruction::kConvertStoF : sp[ 0] = skvx::cast<float>(sp[ 0].fSigned);
Ethan Nicholas82162ee2019-05-21 16:05:08 -0400493 break;
494
Brian Osman569f12f2019-06-13 11:23:57 -0400495 case ByteCodeInstruction::kConvertUtoF4: sp[-3] = skvx::cast<float>(sp[-3].fUnsigned);
496 case ByteCodeInstruction::kConvertUtoF3: sp[-2] = skvx::cast<float>(sp[-2].fUnsigned);
497 case ByteCodeInstruction::kConvertUtoF2: sp[-1] = skvx::cast<float>(sp[-1].fUnsigned);
498 case ByteCodeInstruction::kConvertUtoF : sp[ 0] = skvx::cast<float>(sp[ 0].fUnsigned);
Ethan Nicholas82162ee2019-05-21 16:05:08 -0400499 break;
500
Brian Osman569f12f2019-06-13 11:23:57 -0400501 VECTOR_UNARY_FN_VEC(kCos, cosf)
Ethan Nicholas82162ee2019-05-21 16:05:08 -0400502
Ethan Nicholasae9633b2019-05-24 12:46:34 -0400503 case ByteCodeInstruction::kCross: {
Brian Osman569f12f2019-06-13 11:23:57 -0400504 F32 ax = sp[-5].fFloat, ay = sp[-4].fFloat, az = sp[-3].fFloat,
505 bx = sp[-2].fFloat, by = sp[-1].fFloat, bz = sp[ 0].fFloat;
506 F32 cx = ay*bz - az*by,
507 cy = az*bx - ax*bz,
508 cz = ax*by - ay*bx;
Ethan Nicholasae9633b2019-05-24 12:46:34 -0400509 sp -= 3;
Brian Osman569f12f2019-06-13 11:23:57 -0400510 sp[-2] = cx;
511 sp[-1] = cy;
512 sp[ 0] = cz;
Ethan Nicholasae9633b2019-05-24 12:46:34 -0400513 break;
514 }
515
Mike Kleinc1999982019-05-21 13:03:49 -0500516 VECTOR_BINARY_OP(kDivideS, fSigned, /)
517 VECTOR_BINARY_OP(kDivideU, fUnsigned, /)
Brian Osman1e855b22019-05-29 15:21:52 -0400518 VECTOR_MATRIX_BINARY_OP(kDivideF, fFloat, /)
Mike Kleine7007382019-05-21 08:36:32 -0500519
520 case ByteCodeInstruction::kDup4: PUSH(sp[(int)ByteCodeInstruction::kDup - (int)inst]);
521 case ByteCodeInstruction::kDup3: PUSH(sp[(int)ByteCodeInstruction::kDup - (int)inst]);
522 case ByteCodeInstruction::kDup2: PUSH(sp[(int)ByteCodeInstruction::kDup - (int)inst]);
523 case ByteCodeInstruction::kDup : PUSH(sp[(int)ByteCodeInstruction::kDup - (int)inst]);
524 break;
525
Brian Osman07c117b2019-05-23 12:51:06 -0700526 case ByteCodeInstruction::kDupN: {
527 int count = READ8();
Brian Osman569f12f2019-06-13 11:23:57 -0400528 memcpy(sp + 1, sp - count + 1, count * sizeof(VValue));
Brian Osman07c117b2019-05-23 12:51:06 -0700529 sp += count;
530 break;
531 }
532
Mike Kleine7007382019-05-21 08:36:32 -0500533 case ByteCodeInstruction::kLoad4: sp[4] = stack[*ip + 3];
534 case ByteCodeInstruction::kLoad3: sp[3] = stack[*ip + 2];
535 case ByteCodeInstruction::kLoad2: sp[2] = stack[*ip + 1];
536 case ByteCodeInstruction::kLoad : sp[1] = stack[*ip + 0];
537 ++ip;
538 sp += (int)inst - (int)ByteCodeInstruction::kLoad + 1;
539 break;
540
Brian Osman80164412019-06-07 13:00:23 -0400541 case ByteCodeInstruction::kLoadGlobal4: sp[4] = globals[*ip + 3];
542 case ByteCodeInstruction::kLoadGlobal3: sp[3] = globals[*ip + 2];
543 case ByteCodeInstruction::kLoadGlobal2: sp[2] = globals[*ip + 1];
544 case ByteCodeInstruction::kLoadGlobal : sp[1] = globals[*ip + 0];
Mike Kleine7007382019-05-21 08:36:32 -0500545 ++ip;
Brian Osman07c117b2019-05-23 12:51:06 -0700546 sp += (int)inst -
547 (int)ByteCodeInstruction::kLoadGlobal + 1;
Mike Kleine7007382019-05-21 08:36:32 -0500548 break;
549
Brian Osman07c117b2019-05-23 12:51:06 -0700550 case ByteCodeInstruction::kLoadExtended: {
551 int count = READ8();
Brian Osman569f12f2019-06-13 11:23:57 -0400552 I32 src = POP().fSigned;
553 I32 m = mask();
554 for (int i = 0; i < count; ++i) {
555 for (int j = 0; j < VecWidth; ++j) {
556 if (m[j]) {
557 sp[i + 1].fSigned[j] = stack[src[j] + i].fSigned[j];
558 }
559 }
560 }
Brian Osman07c117b2019-05-23 12:51:06 -0700561 sp += count;
562 break;
563 }
564
565 case ByteCodeInstruction::kLoadExtendedGlobal: {
566 int count = READ8();
Brian Osman569f12f2019-06-13 11:23:57 -0400567 I32 src = POP().fSigned;
568 I32 m = mask();
569 for (int i = 0; i < count; ++i) {
570 for (int j = 0; j < VecWidth; ++j) {
571 if (m[j]) {
572 sp[i + 1].fSigned[j] = globals[src[j] + i].fSigned[j];
573 }
574 }
575 }
Brian Osman07c117b2019-05-23 12:51:06 -0700576 sp += count;
577 break;
578 }
579
Mike Kleine7007382019-05-21 08:36:32 -0500580 case ByteCodeInstruction::kLoadSwizzle: {
581 int src = READ8();
582 int count = READ8();
Ethan Nicholas9764ebd2019-05-01 14:43:54 -0400583 for (int i = 0; i < count; ++i) {
Ethan Nicholas48a75aa2019-05-16 17:15:56 -0400584 PUSH(stack[src + *(ip + i)]);
Ethan Nicholas9764ebd2019-05-01 14:43:54 -0400585 }
Ethan Nicholas7e603db2019-05-03 12:57:47 -0400586 ip += count;
Ethan Nicholas9764ebd2019-05-01 14:43:54 -0400587 break;
Mike Kleine7007382019-05-21 08:36:32 -0500588 }
Ethan Nicholas82162ee2019-05-21 16:05:08 -0400589
Mike Kleine7007382019-05-21 08:36:32 -0500590 case ByteCodeInstruction::kLoadSwizzleGlobal: {
591 int src = READ8();
Mike Kleine7007382019-05-21 08:36:32 -0500592 int count = READ8();
Brian Osmanb7451292019-05-15 13:02:13 -0400593 for (int i = 0; i < count; ++i) {
Brian Osman80164412019-06-07 13:00:23 -0400594 PUSH(globals[src + *(ip + i)]);
Brian Osmanb7451292019-05-15 13:02:13 -0400595 }
596 ip += count;
597 break;
Mike Kleine7007382019-05-21 08:36:32 -0500598 }
Ethan Nicholas82162ee2019-05-21 16:05:08 -0400599
Brian Osman29e013d2019-05-28 17:16:03 -0400600 case ByteCodeInstruction::kMatrixToMatrix: {
601 int srcCols = READ8();
602 int srcRows = READ8();
603 int dstCols = READ8();
604 int dstRows = READ8();
605 SkASSERT(srcCols >= 2 && srcCols <= 4);
606 SkASSERT(srcRows >= 2 && srcRows <= 4);
607 SkASSERT(dstCols >= 2 && dstCols <= 4);
608 SkASSERT(dstRows >= 2 && dstRows <= 4);
Brian Osman569f12f2019-06-13 11:23:57 -0400609 F32 tmp[16];
610 memset(tmp, 0, sizeof(tmp));
611 tmp[0] = tmp[5] = tmp[10] = tmp[15] = F32(1.0f);
Brian Osman29e013d2019-05-28 17:16:03 -0400612 for (int c = srcCols - 1; c >= 0; --c) {
613 for (int r = srcRows - 1; r >= 0; --r) {
Brian Osman569f12f2019-06-13 11:23:57 -0400614 tmp[c*4 + r] = POP().fFloat;
Brian Osman29e013d2019-05-28 17:16:03 -0400615 }
616 }
617 for (int c = 0; c < dstCols; ++c) {
618 for (int r = 0; r < dstRows; ++r) {
Brian Osman569f12f2019-06-13 11:23:57 -0400619 PUSH(tmp[c*4 + r]);
Brian Osman29e013d2019-05-28 17:16:03 -0400620 }
621 }
622 break;
623 }
624
Brian Osman909231c2019-05-29 15:34:36 -0400625 case ByteCodeInstruction::kMatrixMultiply: {
626 int lCols = READ8();
627 int lRows = READ8();
628 int rCols = READ8();
629 int rRows = lCols;
Brian Osman569f12f2019-06-13 11:23:57 -0400630 F32 tmp[16] = { 0.0f };
631 F32* B = &(sp - (rCols * rRows) + 1)->fFloat;
632 F32* A = B - (lCols * lRows);
Brian Osman909231c2019-05-29 15:34:36 -0400633 for (int c = 0; c < rCols; ++c) {
634 for (int r = 0; r < lRows; ++r) {
635 for (int j = 0; j < lCols; ++j) {
636 tmp[c*lRows + r] += A[j*lRows + r] * B[c*rRows + j];
637 }
638 }
639 }
640 sp -= (lCols * lRows) + (rCols * rRows);
Brian Osman569f12f2019-06-13 11:23:57 -0400641 memcpy(sp + 1, tmp, rCols * lRows * sizeof(VValue));
Brian Osman909231c2019-05-29 15:34:36 -0400642 sp += (rCols * lRows);
643 break;
644 }
645
Ethan Nicholasae9633b2019-05-24 12:46:34 -0400646 // stack looks like: X1 Y1 Z1 W1 X2 Y2 Z2 W2 T
647 case ByteCodeInstruction::kMix4:
648 sp[-5] = mix(sp[-5].fFloat, sp[-1].fFloat, sp[0].fFloat);
649 // fall through
650 case ByteCodeInstruction::kMix3: {
651 int count = (int) inst - (int) ByteCodeInstruction::kMix + 1;
652 int target = 2 - count * 2;
653 sp[target] = mix(sp[target].fFloat, sp[2 - count].fFloat, sp[0].fFloat);
654 // fall through
655 }
656 case ByteCodeInstruction::kMix2: {
657 int count = (int) inst - (int) ByteCodeInstruction::kMix + 1;
658 int target = 1 - count * 2;
659 sp[target] = mix(sp[target].fFloat, sp[1 - count].fFloat, sp[0].fFloat);
660 // fall through
661 }
662 case ByteCodeInstruction::kMix: {
663 int count = (int) inst - (int) ByteCodeInstruction::kMix + 1;
664 int target = -count * 2;
665 sp[target] = mix(sp[target].fFloat, sp[-count].fFloat, sp[0].fFloat);
666 sp -= 1 + count;
667 break;
668 }
669
Mike Kleinc1999982019-05-21 13:03:49 -0500670 VECTOR_BINARY_OP(kMultiplyI, fSigned, *)
Brian Osman1e855b22019-05-29 15:21:52 -0400671 VECTOR_MATRIX_BINARY_OP(kMultiplyF, fFloat, *)
Ethan Nicholas82162ee2019-05-21 16:05:08 -0400672
Mike Kleinc1999982019-05-21 13:03:49 -0500673 case ByteCodeInstruction::kNegateF4: sp[-3] = -sp[-3].fFloat;
674 case ByteCodeInstruction::kNegateF3: sp[-2] = -sp[-2].fFloat;
675 case ByteCodeInstruction::kNegateF2: sp[-1] = -sp[-1].fFloat;
676 case ByteCodeInstruction::kNegateF : sp[ 0] = -sp[ 0].fFloat;
Mike Kleine7007382019-05-21 08:36:32 -0500677 break;
678
Brian Osman1e855b22019-05-29 15:21:52 -0400679 case ByteCodeInstruction::kNegateFN: {
680 int count = READ8();
681 for (int i = count - 1; i >= 0; --i) {
682 sp[-i] = -sp[-i].fFloat;
683 }
684 break;
685 }
686
Mike Kleinc1999982019-05-21 13:03:49 -0500687 case ByteCodeInstruction::kNegateI4: sp[-3] = -sp[-3].fSigned;
688 case ByteCodeInstruction::kNegateI3: sp[-2] = -sp[-2].fSigned;
689 case ByteCodeInstruction::kNegateI2: sp[-1] = -sp[-1].fSigned;
Brian Osman569f12f2019-06-13 11:23:57 -0400690 case ByteCodeInstruction::kNegateI : sp[ 0] = -sp[ 0].fSigned;
Mike Kleine7007382019-05-21 08:36:32 -0500691 break;
692
693 case ByteCodeInstruction::kPop4: POP();
694 case ByteCodeInstruction::kPop3: POP();
695 case ByteCodeInstruction::kPop2: POP();
696 case ByteCodeInstruction::kPop : POP();
697 break;
698
Brian Osman07c117b2019-05-23 12:51:06 -0700699 case ByteCodeInstruction::kPopN:
700 sp -= READ8();
701 break;
702
Ethan Nicholas9764ebd2019-05-01 14:43:54 -0400703 case ByteCodeInstruction::kPushImmediate:
Brian Osman569f12f2019-06-13 11:23:57 -0400704 PUSH(U32(READ32()));
Ethan Nicholas9764ebd2019-05-01 14:43:54 -0400705 break;
Ethan Nicholas82162ee2019-05-21 16:05:08 -0400706
Brian Osman569f12f2019-06-13 11:23:57 -0400707 case ByteCodeInstruction::kReadExternal:
708 case ByteCodeInstruction::kReadExternal2:
709 case ByteCodeInstruction::kReadExternal3:
Mike Kleine7007382019-05-21 08:36:32 -0500710 case ByteCodeInstruction::kReadExternal4: {
Brian Osman569f12f2019-06-13 11:23:57 -0400711 int count = (int)inst - (int)ByteCodeInstruction::kReadExternal + 1;
Mike Kleine7007382019-05-21 08:36:32 -0500712 int src = READ8();
Brian Osman1a79f0b2019-06-24 16:32:14 -0400713 float tmp[4];
Brian Osman569f12f2019-06-13 11:23:57 -0400714 I32 m = mask();
715 for (int i = 0; i < VecWidth; ++i) {
716 if (m[i]) {
Brian Osman1a79f0b2019-06-24 16:32:14 -0400717 byteCode->fExternalValues[src]->read(baseIndex + i, tmp);
Brian Osman569f12f2019-06-13 11:23:57 -0400718 for (int j = 0; j < count; ++j) {
Brian Osman1a79f0b2019-06-24 16:32:14 -0400719 sp[j + 1].fFloat[i] = tmp[j];
Brian Osman569f12f2019-06-13 11:23:57 -0400720 }
721 }
722 }
723 sp += count;
Ethan Nicholas91164d12019-05-15 15:29:54 -0400724 break;
Mike Kleine7007382019-05-21 08:36:32 -0500725 }
Ethan Nicholas82162ee2019-05-21 16:05:08 -0400726
Brian Osman569f12f2019-06-13 11:23:57 -0400727 VECTOR_BINARY_FN(kRemainderF, fFloat, vec_mod<F32>)
728 VECTOR_BINARY_FN(kRemainderS, fSigned, vec_mod<I32>)
729 VECTOR_BINARY_FN(kRemainderU, fUnsigned, vec_mod<U32>)
Ethan Nicholas82162ee2019-05-21 16:05:08 -0400730
Brian Osmand3494ed2019-06-20 15:41:34 -0400731 case ByteCodeInstruction::kReserve:
732 sp += READ8();
733 break;
734
Mike Kleine7007382019-05-21 08:36:32 -0500735 case ByteCodeInstruction::kReturn: {
736 int count = READ8();
Brian Osman226668a2019-05-14 16:47:30 -0400737 if (frames.empty()) {
738 if (outReturn) {
Brian Osman569f12f2019-06-13 11:23:57 -0400739 VValue* src = sp - count + 1;
Mike Reed3fd3cc92019-06-20 12:40:30 -0400740 if (stripedOutput) {
741 for (int i = 0; i < count; ++i) {
Brian Osman4b202a32019-06-21 09:50:29 -0400742 memcpy(outReturn[i], &src->fFloat, N * sizeof(float));
743 ++src;
Brian Osman569f12f2019-06-13 11:23:57 -0400744 }
Mike Reed3fd3cc92019-06-20 12:40:30 -0400745 } else {
746 float* outPtr = outReturn[0];
747 for (int i = 0; i < count; ++i) {
Brian Osman4b202a32019-06-21 09:50:29 -0400748 for (int j = 0; j < N; ++j) {
749 outPtr[count * j] = src->fFloat[j];
Mike Reed3fd3cc92019-06-20 12:40:30 -0400750 }
751 ++outPtr;
752 ++src;
753 }
Brian Osman569f12f2019-06-13 11:23:57 -0400754 }
Brian Osman226668a2019-05-14 16:47:30 -0400755 }
756 return;
757 } else {
Brian Osmand3494ed2019-06-20 15:41:34 -0400758 // When we were called, the caller reserved stack space for their copy of our
759 // return value, then 'stack' was positioned after that, where our parameters
760 // were placed. Copy our return values to their reserved area.
761 memcpy(stack - count, sp - count + 1, count * sizeof(VValue));
Brian Osman226668a2019-05-14 16:47:30 -0400762
Brian Osmand3494ed2019-06-20 15:41:34 -0400763 // Now move the stack pointer to the end of the passed-in parameters. This odd
764 // calling convention requires the caller to pop the arguments after calling,
765 // but allows them to store any out-parameters back during that unwinding.
766 // After that sequence finishes, the return value will be the top of the stack.
Brian Osman226668a2019-05-14 16:47:30 -0400767 const StackFrame& frame(frames.back());
Brian Osmand3494ed2019-06-20 15:41:34 -0400768 sp = stack + frame.fParameterCount - 1;
Brian Osman226668a2019-05-14 16:47:30 -0400769 stack = frame.fStack;
770 code = frame.fCode;
771 ip = frame.fIP;
772 frames.pop_back();
773 break;
Ethan Nicholas9764ebd2019-05-01 14:43:54 -0400774 }
Mike Kleine7007382019-05-21 08:36:32 -0500775 }
776
Brian Osman29e013d2019-05-28 17:16:03 -0400777 case ByteCodeInstruction::kScalarToMatrix: {
778 int cols = READ8();
779 int rows = READ8();
Brian Osman569f12f2019-06-13 11:23:57 -0400780 VValue v = POP();
Brian Osman29e013d2019-05-28 17:16:03 -0400781 for (int c = 0; c < cols; ++c) {
782 for (int r = 0; r < rows; ++r) {
Brian Osman569f12f2019-06-13 11:23:57 -0400783 PUSH(c == r ? v : F32(0.0f));
Brian Osman29e013d2019-05-28 17:16:03 -0400784 }
785 }
786 break;
787 }
788
Brian Osman569f12f2019-06-13 11:23:57 -0400789 VECTOR_UNARY_FN_VEC(kSin, sinf)
790 VECTOR_UNARY_FN(kSqrt, skvx::sqrt, fFloat)
Ethan Nicholas82162ee2019-05-21 16:05:08 -0400791
Brian Osman569f12f2019-06-13 11:23:57 -0400792 case ByteCodeInstruction::kStore4:
793 stack[*ip+3] = skvx::if_then_else(mask(), POP().fFloat, stack[*ip+3].fFloat);
794 case ByteCodeInstruction::kStore3:
795 stack[*ip+2] = skvx::if_then_else(mask(), POP().fFloat, stack[*ip+2].fFloat);
796 case ByteCodeInstruction::kStore2:
797 stack[*ip+1] = skvx::if_then_else(mask(), POP().fFloat, stack[*ip+1].fFloat);
798 case ByteCodeInstruction::kStore :
799 stack[*ip+0] = skvx::if_then_else(mask(), POP().fFloat, stack[*ip+0].fFloat);
800 ++ip;
801 break;
Mike Kleine7007382019-05-21 08:36:32 -0500802
Brian Osman569f12f2019-06-13 11:23:57 -0400803 case ByteCodeInstruction::kStoreGlobal4:
804 globals[*ip+3] = skvx::if_then_else(mask(), POP().fFloat, globals[*ip+3].fFloat);
805 case ByteCodeInstruction::kStoreGlobal3:
806 globals[*ip+2] = skvx::if_then_else(mask(), POP().fFloat, globals[*ip+2].fFloat);
807 case ByteCodeInstruction::kStoreGlobal2:
808 globals[*ip+1] = skvx::if_then_else(mask(), POP().fFloat, globals[*ip+1].fFloat);
809 case ByteCodeInstruction::kStoreGlobal :
810 globals[*ip+0] = skvx::if_then_else(mask(), POP().fFloat, globals[*ip+0].fFloat);
811 ++ip;
812 break;
Mike Kleine7007382019-05-21 08:36:32 -0500813
Brian Osman07c117b2019-05-23 12:51:06 -0700814 case ByteCodeInstruction::kStoreExtended: {
815 int count = READ8();
Brian Osman569f12f2019-06-13 11:23:57 -0400816 I32 target = POP().fSigned;
817 VValue* src = sp - count + 1;
818 I32 m = mask();
819 for (int i = 0; i < count; ++i) {
820 for (int j = 0; j < VecWidth; ++j) {
821 if (m[j]) {
822 stack[target[j] + i].fSigned[j] = src[i].fSigned[j];
823 }
824 }
825 }
Brian Osman07c117b2019-05-23 12:51:06 -0700826 sp -= count;
827 break;
828 }
829 case ByteCodeInstruction::kStoreExtendedGlobal: {
830 int count = READ8();
Brian Osman569f12f2019-06-13 11:23:57 -0400831 I32 target = POP().fSigned;
832 VValue* src = sp - count + 1;
833 I32 m = mask();
834 for (int i = 0; i < count; ++i) {
835 for (int j = 0; j < VecWidth; ++j) {
836 if (m[j]) {
837 globals[target[j] + i].fSigned[j] = src[i].fSigned[j];
838 }
839 }
840 }
Brian Osman07c117b2019-05-23 12:51:06 -0700841 sp -= count;
842 break;
843 }
844
Mike Kleine7007382019-05-21 08:36:32 -0500845 case ByteCodeInstruction::kStoreSwizzle: {
846 int target = READ8();
847 int count = READ8();
Ethan Nicholas9764ebd2019-05-01 14:43:54 -0400848 for (int i = count - 1; i >= 0; --i) {
Brian Osman569f12f2019-06-13 11:23:57 -0400849 stack[target + *(ip + i)] = skvx::if_then_else(
850 mask(), POP().fFloat, stack[target + *(ip + i)].fFloat);
Ethan Nicholas9764ebd2019-05-01 14:43:54 -0400851 }
Brian Osman1091f022019-05-16 09:42:16 -0400852 ip += count;
853 break;
Mike Kleine7007382019-05-21 08:36:32 -0500854 }
Ethan Nicholas82162ee2019-05-21 16:05:08 -0400855
Mike Kleine7007382019-05-21 08:36:32 -0500856 case ByteCodeInstruction::kStoreSwizzleGlobal: {
857 int target = READ8();
858 int count = READ8();
Brian Osman1091f022019-05-16 09:42:16 -0400859 for (int i = count - 1; i >= 0; --i) {
Brian Osman569f12f2019-06-13 11:23:57 -0400860 globals[target + *(ip + i)] = skvx::if_then_else(
861 mask(), POP().fFloat, globals[target + *(ip + i)].fFloat);
Brian Osman1091f022019-05-16 09:42:16 -0400862 }
Ethan Nicholas7e603db2019-05-03 12:57:47 -0400863 ip += count;
Ethan Nicholas9764ebd2019-05-01 14:43:54 -0400864 break;
Mike Kleine7007382019-05-21 08:36:32 -0500865 }
Brian Osman569f12f2019-06-13 11:23:57 -0400866
Brian Osman07c117b2019-05-23 12:51:06 -0700867 case ByteCodeInstruction::kStoreSwizzleIndirect: {
Brian Osman07c117b2019-05-23 12:51:06 -0700868 int count = READ8();
Brian Osman569f12f2019-06-13 11:23:57 -0400869 I32 target = POP().fSigned;
870 I32 m = mask();
Brian Osman07c117b2019-05-23 12:51:06 -0700871 for (int i = count - 1; i >= 0; --i) {
Brian Osman569f12f2019-06-13 11:23:57 -0400872 I32 v = POP().fSigned;
873 for (int j = 0; j < VecWidth; ++j) {
874 if (m[j]) {
875 stack[target[j] + *(ip + i)].fSigned[j] = v[j];
876 }
877 }
Brian Osman07c117b2019-05-23 12:51:06 -0700878 }
879 ip += count;
880 break;
881 }
Brian Osman569f12f2019-06-13 11:23:57 -0400882
Brian Osman07c117b2019-05-23 12:51:06 -0700883 case ByteCodeInstruction::kStoreSwizzleIndirectGlobal: {
Brian Osman07c117b2019-05-23 12:51:06 -0700884 int count = READ8();
Brian Osman569f12f2019-06-13 11:23:57 -0400885 I32 target = POP().fSigned;
886 I32 m = mask();
Brian Osman07c117b2019-05-23 12:51:06 -0700887 for (int i = count - 1; i >= 0; --i) {
Brian Osman569f12f2019-06-13 11:23:57 -0400888 I32 v = POP().fSigned;
889 for (int j = 0; j < VecWidth; ++j) {
890 if (m[j]) {
891 globals[target[j] + *(ip + i)].fSigned[j] = v[j];
892 }
893 }
Brian Osman07c117b2019-05-23 12:51:06 -0700894 }
895 ip += count;
896 break;
897 }
Ethan Nicholas82162ee2019-05-21 16:05:08 -0400898
Mike Kleinc1999982019-05-21 13:03:49 -0500899 VECTOR_BINARY_OP(kSubtractI, fSigned, -)
Brian Osman1e855b22019-05-29 15:21:52 -0400900 VECTOR_MATRIX_BINARY_OP(kSubtractF, fFloat, -)
Ethan Nicholas82162ee2019-05-21 16:05:08 -0400901
Mike Kleine7007382019-05-21 08:36:32 -0500902 case ByteCodeInstruction::kSwizzle: {
Brian Osman569f12f2019-06-13 11:23:57 -0400903 VValue tmp[4];
Ethan Nicholas7e603db2019-05-03 12:57:47 -0400904 for (int i = READ8() - 1; i >= 0; --i) {
Ethan Nicholas48a75aa2019-05-16 17:15:56 -0400905 tmp[i] = POP();
Ethan Nicholas9764ebd2019-05-01 14:43:54 -0400906 }
Ethan Nicholas7e603db2019-05-03 12:57:47 -0400907 for (int i = READ8() - 1; i >= 0; --i) {
Ethan Nicholas48a75aa2019-05-16 17:15:56 -0400908 PUSH(tmp[READ8()]);
Ethan Nicholas9764ebd2019-05-01 14:43:54 -0400909 }
910 break;
Mike Kleine7007382019-05-21 08:36:32 -0500911 }
Ethan Nicholas82162ee2019-05-21 16:05:08 -0400912
Brian Osman569f12f2019-06-13 11:23:57 -0400913 VECTOR_UNARY_FN_VEC(kTan, tanf)
Ethan Nicholas82162ee2019-05-21 16:05:08 -0400914
Brian Osman569f12f2019-06-13 11:23:57 -0400915 case ByteCodeInstruction::kWriteExternal:
916 case ByteCodeInstruction::kWriteExternal2:
917 case ByteCodeInstruction::kWriteExternal3:
Mike Kleine7007382019-05-21 08:36:32 -0500918 case ByteCodeInstruction::kWriteExternal4: {
Brian Osman569f12f2019-06-13 11:23:57 -0400919 int count = (int)inst - (int)ByteCodeInstruction::kWriteExternal + 1;
Mike Kleine7007382019-05-21 08:36:32 -0500920 int target = READ8();
Brian Osman1a79f0b2019-06-24 16:32:14 -0400921 float tmp[4];
Brian Osman569f12f2019-06-13 11:23:57 -0400922 I32 m = mask();
Ethan Nicholas48a75aa2019-05-16 17:15:56 -0400923 sp -= count;
Brian Osman569f12f2019-06-13 11:23:57 -0400924 for (int i = 0; i < VecWidth; ++i) {
925 if (m[i]) {
926 for (int j = 0; j < count; ++j) {
Brian Osman1a79f0b2019-06-24 16:32:14 -0400927 tmp[j] = sp[j + 1].fFloat[i];
Brian Osman569f12f2019-06-13 11:23:57 -0400928 }
Brian Osman1a79f0b2019-06-24 16:32:14 -0400929 byteCode->fExternalValues[target]->write(baseIndex + i, tmp);
Brian Osman569f12f2019-06-13 11:23:57 -0400930 }
931 }
932 break;
933 }
934
935 case ByteCodeInstruction::kMaskPush:
936 condPtr[1] = POP().fSigned;
937 maskPtr[1] = maskPtr[0] & condPtr[1];
938 ++condPtr; ++maskPtr;
939 break;
940 case ByteCodeInstruction::kMaskPop:
941 --condPtr; --maskPtr;
942 break;
943 case ByteCodeInstruction::kMaskNegate:
944 maskPtr[0] = maskPtr[-1] & ~condPtr[0];
945 break;
946 case ByteCodeInstruction::kMaskBlend: {
947 int count = READ8();
948 I32 m = condPtr[0];
949 --condPtr; --maskPtr;
950 for (int i = 0; i < count; ++i) {
951 sp[-count] = skvx::if_then_else(m, sp[-count].fFloat, sp[0].fFloat);
952 --sp;
953 }
954 break;
955 }
956 case ByteCodeInstruction::kBranchIfAllFalse: {
957 int target = READ16();
958 if (!skvx::any(mask())) {
959 ip = code + target;
960 }
961 break;
962 }
963
964 case ByteCodeInstruction::kLoopBegin:
Brian Osman8d564572019-06-19 11:00:28 -0400965 contPtr[1] = 0;
966 loopPtr[1] = loopPtr[0];
967 ++contPtr; ++loopPtr;
Brian Osman569f12f2019-06-13 11:23:57 -0400968 break;
969 case ByteCodeInstruction::kLoopNext:
970 *loopPtr |= *contPtr;
971 *contPtr = 0;
972 break;
973 case ByteCodeInstruction::kLoopMask:
974 *loopPtr &= POP().fSigned;
975 break;
976 case ByteCodeInstruction::kLoopEnd:
977 --contPtr; --loopPtr;
978 break;
979 case ByteCodeInstruction::kLoopBreak:
980 *loopPtr &= ~mask();
981 break;
982 case ByteCodeInstruction::kLoopContinue: {
983 I32 m = mask();
984 *contPtr |= m;
985 *loopPtr &= ~m;
Ethan Nicholas9764ebd2019-05-01 14:43:54 -0400986 break;
Mike Kleine7007382019-05-21 08:36:32 -0500987 }
Ethan Nicholas82162ee2019-05-21 16:05:08 -0400988
Ethan Nicholas9764ebd2019-05-01 14:43:54 -0400989 default:
Mike Kleine7007382019-05-21 08:36:32 -0500990 SkDEBUGFAILF("unsupported instruction %d\n", (int) inst);
Ethan Nicholas9764ebd2019-05-01 14:43:54 -0400991 }
Brian Osman569f12f2019-06-13 11:23:57 -0400992 }
993}
994
Brian Osman08a84962019-06-14 10:17:16 -0400995} // namespace Interpreter
996
Brian Osman489cf882019-07-09 10:48:28 -0400997#endif // SK_ENABLE_SKSL_INTERPRETER
998
Brian Osman08a84962019-06-14 10:17:16 -0400999void ByteCodeFunction::disassemble() const {
Brian Osman489cf882019-07-09 10:48:28 -04001000#if defined(SK_ENABLE_SKSL_INTERPRETER)
Brian Osman08a84962019-06-14 10:17:16 -04001001 const uint8_t* ip = fCode.data();
1002 while (ip < fCode.data() + fCode.size()) {
1003 printf("%d: ", (int)(ip - fCode.data()));
1004 ip = Interpreter::disassemble_instruction(ip);
1005 printf("\n");
1006 }
Brian Osman489cf882019-07-09 10:48:28 -04001007#endif
Brian Osman08a84962019-06-14 10:17:16 -04001008}
1009
1010void ByteCode::run(const ByteCodeFunction* f, float* args, float* outReturn, int N,
1011 const float* uniforms, int uniformCount) const {
Brian Osman489cf882019-07-09 10:48:28 -04001012#if defined(SK_ENABLE_SKSL_INTERPRETER)
Ethan Nicholas9764ebd2019-05-01 14:43:54 -04001013#ifdef TRACE
Brian Osman08a84962019-06-14 10:17:16 -04001014 f->disassemble();
Ethan Nicholas9764ebd2019-05-01 14:43:54 -04001015#endif
Brian Osman4b202a32019-06-21 09:50:29 -04001016 Interpreter::VValue stack[128];
Brian Osmanaa2ca3f2019-07-15 13:24:48 -04001017 int stackNeeded = f->fParameterCount + f->fLocalCount + f->fStackCount;
1018 if (stackNeeded > (int)SK_ARRAY_COUNT(stack)) {
1019 SkDEBUGFAIL("Function requires too much stack space to evaluate");
1020 return;
1021 }
Brian Osmanef787f72019-06-13 13:07:12 -04001022
Brian Osman08a84962019-06-14 10:17:16 -04001023 SkASSERT(uniformCount == (int)fInputSlots.size());
1024 Interpreter::VValue globals[32];
1025 SkASSERT((int)SK_ARRAY_COUNT(globals) >= fGlobalCount);
1026 for (uint8_t slot : fInputSlots) {
1027 globals[slot].fFloat = *uniforms++;
Brian Osman569f12f2019-06-13 11:23:57 -04001028 }
1029
Brian Osman1a79f0b2019-06-24 16:32:14 -04001030 int baseIndex = 0;
1031
Brian Osman569f12f2019-06-13 11:23:57 -04001032 while (N) {
Brian Osman08a84962019-06-14 10:17:16 -04001033 int w = std::min(N, Interpreter::VecWidth);
Brian Osman569f12f2019-06-13 11:23:57 -04001034
1035 // Transpose args into stack
1036 {
Brian Osman08a84962019-06-14 10:17:16 -04001037 float* src = args;
Brian Osman569f12f2019-06-13 11:23:57 -04001038 for (int i = 0; i < w; ++i) {
Brian Osman08a84962019-06-14 10:17:16 -04001039 float* dst = (float*)stack + i;
Brian Osman569f12f2019-06-13 11:23:57 -04001040 for (int j = f->fParameterCount; j > 0; --j) {
1041 *dst = *src++;
Brian Osman08a84962019-06-14 10:17:16 -04001042 dst += Interpreter::VecWidth;
Brian Osman569f12f2019-06-13 11:23:57 -04001043 }
1044 }
1045 }
1046
Mike Reed3fd3cc92019-06-20 12:40:30 -04001047 bool stripedOutput = false;
1048 float** outArray = outReturn ? &outReturn : nullptr;
Brian Osman1a79f0b2019-06-24 16:32:14 -04001049 innerRun(this, f, stack, outArray, globals, stripedOutput, w, baseIndex);
Brian Osman569f12f2019-06-13 11:23:57 -04001050
1051 // Transpose out parameters back
1052 {
Brian Osman08a84962019-06-14 10:17:16 -04001053 float* dst = args;
Brian Osman569f12f2019-06-13 11:23:57 -04001054 for (int i = 0; i < w; ++i) {
Brian Osman08a84962019-06-14 10:17:16 -04001055 float* src = (float*)stack + i;
Brian Osman569f12f2019-06-13 11:23:57 -04001056 for (const auto& p : f->fParameters) {
1057 if (p.fIsOutParameter) {
1058 for (int j = p.fSlotCount; j > 0; --j) {
1059 *dst++ = *src;
Brian Osman08a84962019-06-14 10:17:16 -04001060 src += Interpreter::VecWidth;
Brian Osman569f12f2019-06-13 11:23:57 -04001061 }
1062 } else {
1063 dst += p.fSlotCount;
Brian Osman08a84962019-06-14 10:17:16 -04001064 src += p.fSlotCount * Interpreter::VecWidth;
Brian Osman569f12f2019-06-13 11:23:57 -04001065 }
1066 }
1067 }
1068 }
1069
1070 args += f->fParameterCount * w;
Mike Reed3fd3cc92019-06-20 12:40:30 -04001071 if (outReturn) {
1072 outReturn += f->fReturnCount * w;
1073 }
Brian Osman4b202a32019-06-21 09:50:29 -04001074 N -= w;
Brian Osman1a79f0b2019-06-24 16:32:14 -04001075 baseIndex += w;
Ethan Nicholas0e9401d2019-03-21 11:05:37 -04001076 }
Brian Osman489cf882019-07-09 10:48:28 -04001077#else
1078 SkDEBUGFAIL("ByteCode interpreter not enabled");
1079#endif
Ethan Nicholas26a9aad2018-03-27 14:10:52 -04001080}
1081
Brian Osman2b1a5442019-06-19 11:40:33 -04001082void ByteCode::runStriped(const ByteCodeFunction* f, float* args[], int nargs, int N,
Mike Reed3fd3cc92019-06-20 12:40:30 -04001083 const float* uniforms, int uniformCount,
1084 float* outArgs[], int outCount) const {
Brian Osman489cf882019-07-09 10:48:28 -04001085#if defined(SK_ENABLE_SKSL_INTERPRETER)
Brian Osman2b1a5442019-06-19 11:40:33 -04001086#ifdef TRACE
Brian Osmanecb3bb52019-06-20 14:59:12 -04001087 f->disassemble();
Brian Osman2b1a5442019-06-19 11:40:33 -04001088#endif
1089 Interpreter::VValue stack[128];
Brian Osmanaa2ca3f2019-07-15 13:24:48 -04001090 int stackNeeded = f->fParameterCount + f->fLocalCount + f->fStackCount;
1091 if (stackNeeded > (int)SK_ARRAY_COUNT(stack)) {
1092 SkDEBUGFAIL("Function requires too much stack space to evaluate");
1093 return;
1094 }
Brian Osman2b1a5442019-06-19 11:40:33 -04001095
Mike Reed3fd3cc92019-06-20 12:40:30 -04001096 // innerRun just takes outArgs, so clear it if the count is zero
1097 if (outCount == 0) {
1098 outArgs = nullptr;
1099 }
1100
Brian Osman2b1a5442019-06-19 11:40:33 -04001101 SkASSERT(nargs == f->fParameterCount);
Mike Reed3fd3cc92019-06-20 12:40:30 -04001102 SkASSERT(outCount == f->fReturnCount);
Brian Osman2b1a5442019-06-19 11:40:33 -04001103 SkASSERT(uniformCount == (int)fInputSlots.size());
1104 Interpreter::VValue globals[32];
1105 SkASSERT((int)SK_ARRAY_COUNT(globals) >= fGlobalCount);
1106 for (uint8_t slot : fInputSlots) {
1107 globals[slot].fFloat = *uniforms++;
1108 }
1109
Brian Osman1a79f0b2019-06-24 16:32:14 -04001110 int baseIndex = 0;
1111
Brian Osman2b1a5442019-06-19 11:40:33 -04001112 while (N) {
1113 int w = std::min(N, Interpreter::VecWidth);
1114
1115 // Copy args into stack
1116 for (int i = 0; i < nargs; ++i) {
1117 memcpy(stack + i, args[i], w * sizeof(float));
1118 }
1119
Mike Reed3fd3cc92019-06-20 12:40:30 -04001120 bool stripedOutput = true;
Brian Osman1a79f0b2019-06-24 16:32:14 -04001121 innerRun(this, f, stack, outArgs, globals, stripedOutput, w, baseIndex);
Brian Osman2b1a5442019-06-19 11:40:33 -04001122
1123 // Copy out parameters back
1124 int slot = 0;
1125 for (const auto& p : f->fParameters) {
1126 if (p.fIsOutParameter) {
1127 for (int i = slot; i < slot + p.fSlotCount; ++i) {
1128 memcpy(args[i], stack + i, w * sizeof(float));
1129 }
1130 }
1131 slot += p.fSlotCount;
1132 }
1133
1134 // Step each argument pointer ahead
1135 for (int i = 0; i < nargs; ++i) {
1136 args[i] += w;
1137 }
1138 N -= w;
Brian Osman1a79f0b2019-06-24 16:32:14 -04001139 baseIndex += w;
Brian Osman2b1a5442019-06-19 11:40:33 -04001140 }
Brian Osman489cf882019-07-09 10:48:28 -04001141#else
1142 SkDEBUGFAIL("ByteCode interpreter not enabled");
1143#endif
Brian Osman2b1a5442019-06-19 11:40:33 -04001144}
1145
Brian Osman80164412019-06-07 13:00:23 -04001146} // namespace SkSL
Ethan Nicholas26a9aad2018-03-27 14:10:52 -04001147
1148#endif