switched over to using fallthrough in SkSL interpreter vector operations

Bug: skia:
Change-Id: Ibcbad9252f2da468549792bf7c3bb4e9a5b77805
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/214380
Reviewed-by: Mike Klein <mtklein@google.com>
Commit-Queue: Mike Klein <mtklein@google.com>
This commit is contained in:
Ethan Nicholas 2019-05-20 09:55:44 -04:00 committed by Skia Commit-Bot
parent 08f87346b6
commit aeb71ce166

View File

@ -245,34 +245,46 @@ void Interpreter::disassemble(const ByteCodeFunction& f) {
}
}
#define VECTOR_BINARY_OP(inst, type, srcField, targetField, op) \
case ByteCodeInstruction::inst: \
tmp[0] = POP(); \
sp->targetField = sp->srcField op tmp[0].srcField; \
break; \
case ByteCodeInstruction::inst ## 2: \
tmp[1] = POP(); \
tmp[0] = POP(); \
sp[ 0].targetField = sp[ 0].srcField op tmp[1].srcField; \
sp[-1].targetField = sp[-1].srcField op tmp[0].srcField; \
break; \
case ByteCodeInstruction::inst ## 3: \
tmp[2] = POP(); \
tmp[1] = POP(); \
tmp[0] = POP(); \
sp[ 0].targetField = sp[ 0].srcField op tmp[2].srcField; \
sp[-1].targetField = sp[-1].srcField op tmp[1].srcField; \
sp[-2].targetField = sp[-2].srcField op tmp[0].srcField; \
break; \
case ByteCodeInstruction::inst ## 4: \
tmp[3] = POP(); \
tmp[2] = POP(); \
tmp[1] = POP(); \
tmp[0] = POP(); \
sp[ 0].targetField = sp[ 0].srcField op tmp[3].srcField; \
sp[-1].targetField = sp[-1].srcField op tmp[2].srcField; \
sp[-2].targetField = sp[-2].srcField op tmp[1].srcField; \
sp[-3].targetField = sp[-3].srcField op tmp[0].srcField; \
#define VECTOR_BINARY_OP(base, type, src, target, op) \
case ByteCodeInstruction::base ## 4: \
sp[-4].target = sp[-4].src op sp[0].src; \
POP(); \
/* fall through */ \
case ByteCodeInstruction::base ## 3: \
count = (int) ByteCodeInstruction::base - (int) inst - 1; \
sp[count].target = sp[count].src op sp[0].src; \
POP(); \
/* fall through */ \
case ByteCodeInstruction::base ## 2: \
count = (int) ByteCodeInstruction::base - (int) inst - 1; \
sp[count].target = sp[count].src op sp[0].src; \
POP(); \
/* fall through */ \
case ByteCodeInstruction::base: \
count = (int) ByteCodeInstruction::base - (int) inst - 1; \
sp[count].target = sp[count].src op sp[0].src; \
POP(); \
break;
#define VECTOR_BINARY_FN(base, type, src, target, fn) \
case ByteCodeInstruction::base ## 4: \
sp[-4].target = fn(sp[-4].src, sp[0].src); \
POP(); \
/* fall through */ \
case ByteCodeInstruction::base ## 3: \
count = (int) ByteCodeInstruction::base - (int) inst - 1; \
sp[count].target = fn(sp[count].src, sp[0].src); \
POP(); \
/* fall through */ \
case ByteCodeInstruction::base ## 2: \
count = (int) ByteCodeInstruction::base - (int) inst - 1; \
sp[count].target = fn(sp[count].src, sp[0].src); \
POP(); \
/* fall through */ \
case ByteCodeInstruction::base: \
count = (int) ByteCodeInstruction::base - (int) inst - 1; \
sp[count].target = fn(sp[count].src, sp[0].src); \
POP(); \
break;
struct StackFrame {
@ -360,13 +372,24 @@ void Interpreter::run(const ByteCodeFunction& f, Value* stack, Value args[], Val
VECTOR_BINARY_OP(kDivideS, int32_t, fSigned, fSigned, /)
VECTOR_BINARY_OP(kDivideU, uint32_t, fUnsigned, fUnsigned, /)
VECTOR_BINARY_OP(kDivideF, float, fFloat, fFloat, /)
case ByteCodeInstruction::kDup: // fall through
case ByteCodeInstruction::kDup2: // fall through
case ByteCodeInstruction::kDup3: // fall through
case ByteCodeInstruction::kDup4:
count = (int) inst - (int) ByteCodeInstruction::kDup + 1;
memcpy(sp + 1, sp - count + 1, count * sizeof(Value));
sp += count;
sp[1] = sp[-3];
++sp;
// fall through
case ByteCodeInstruction::kDup3:
count = (int) ByteCodeInstruction::kDup - (int) inst;
sp[1] = sp[count];
++sp;
// fall through
case ByteCodeInstruction::kDup2:
count = (int) ByteCodeInstruction::kDup - (int) inst;
sp[1] = sp[count];
++sp;
// fall through
case ByteCodeInstruction::kDup:
count = (int) ByteCodeInstruction::kDup - (int) inst;
sp[1] = sp[count];
++sp;
break;
case ByteCodeInstruction::kFloatToInt4:
sp[-3].fSigned = (int) sp[-3].fFloat;
@ -404,24 +427,33 @@ void Interpreter::run(const ByteCodeFunction& f, Value* stack, Value args[], Val
case ByteCodeInstruction::kUnsignedToFloat:
sp[0].fFloat = (int) sp[0].fUnsigned;
break;
case ByteCodeInstruction::kLoad: // fall through
case ByteCodeInstruction::kLoad2: // fall through
case ByteCodeInstruction::kLoad3: // fall through
case ByteCodeInstruction::kLoad4:
count = (int) inst - (int) ByteCodeInstruction::kLoad + 1;
src = READ8();
memcpy(sp + 1, &stack[src], count * sizeof(Value));
sp += count;
sp[4] = stack[*ip + 3];
// fall through
case ByteCodeInstruction::kLoad3:
sp[3] = stack[*ip + 2];
// fall through
case ByteCodeInstruction::kLoad2:
sp[2] = stack[*ip + 1];
// fall through
case ByteCodeInstruction::kLoad:
sp[1] = stack[*ip];
++ip;
sp += (int) inst - (int) ByteCodeInstruction::kLoad + 1;
break;
case ByteCodeInstruction::kLoadGlobal: // fall through
case ByteCodeInstruction::kLoadGlobal2: // fall through
case ByteCodeInstruction::kLoadGlobal3: // fall through
case ByteCodeInstruction::kLoadGlobal4:
count = (int) inst - (int) ByteCodeInstruction::kLoadGlobal + 1;
src = READ8();
SkASSERT(src + count <= (int) fGlobals.size());
memcpy(sp + 1, &fGlobals[src], count * sizeof(Value));
sp += count;
sp[4] = fGlobals[*ip + 3];
// fall through
case ByteCodeInstruction::kLoadGlobal3:
sp[3] = fGlobals[*ip + 2];
// fall through
case ByteCodeInstruction::kLoadGlobal2:
sp[2] = fGlobals[*ip + 1];
// fall through
case ByteCodeInstruction::kLoadGlobal:
sp[1] = fGlobals[*ip];
++ip;
sp += (int) inst - (int) ByteCodeInstruction::kLoadGlobal + 1;
break;
case ByteCodeInstruction::kLoadSwizzle:
src = READ8();
@ -493,34 +525,7 @@ void Interpreter::run(const ByteCodeFunction& f, Value* stack, Value args[], Val
fByteCode->fExternalValues[src]->read(sp + 1);
sp += count;
break;
case ByteCodeInstruction::kRemainderF:
tmp[0] = POP();
TOP().fFloat = fmodf(TOP().fFloat, tmp[0].fFloat);
break;
case ByteCodeInstruction::kRemainderF2:
tmp[1] = POP();
tmp[0] = POP();
sp[ 0].fFloat = fmodf(sp[ 0].fFloat, tmp[1].fFloat);
sp[-1].fFloat = fmodf(sp[-1].fFloat, tmp[0].fFloat);
break;
case ByteCodeInstruction::kRemainderF3:
tmp[2] = POP();
tmp[1] = POP();
tmp[0] = POP();
sp[ 0].fFloat = fmodf(sp[ 0].fFloat, tmp[2].fFloat);
sp[-1].fFloat = fmodf(sp[-1].fFloat, tmp[1].fFloat);
sp[-2].fFloat = fmodf(sp[-2].fFloat, tmp[0].fFloat);
break;
case ByteCodeInstruction::kRemainderF4:
tmp[3] = POP();
tmp[2] = POP();
tmp[1] = POP();
tmp[0] = POP();
sp[ 0].fFloat = fmodf(sp[ 0].fFloat, tmp[3].fFloat);
sp[-1].fFloat = fmodf(sp[-1].fFloat, tmp[2].fFloat);
sp[-2].fFloat = fmodf(sp[-2].fFloat, tmp[1].fFloat);
sp[-3].fFloat = fmodf(sp[-3].fFloat, tmp[0].fFloat);
break;
VECTOR_BINARY_FN(kRemainderF, int32_t, fFloat, fFloat, fmodf)
VECTOR_BINARY_OP(kRemainderS, int32_t, fSigned, fSigned, %)
VECTOR_BINARY_OP(kRemainderU, uint32_t, fUnsigned, fUnsigned, %)
case ByteCodeInstruction::kReturn:
@ -545,25 +550,37 @@ void Interpreter::run(const ByteCodeFunction& f, Value* stack, Value args[], Val
frames.pop_back();
break;
}
case ByteCodeInstruction::kStore: // fall through
case ByteCodeInstruction::kStore2: // fall through
case ByteCodeInstruction::kStore3: // fall through
case ByteCodeInstruction::kStore4:
count = (int) inst - (int) ByteCodeInstruction::kStore + 1;
target = READ8();
SkASSERT(target + count <= STACK_SIZE());
memcpy(&stack[target], sp - count + 1, count * sizeof(Value));
sp -= count;
stack[*ip + 3] = sp[0];
POP();
// fall through
case ByteCodeInstruction::kStore3:
stack[*ip + 2] = sp[0];
POP();
// fall through
case ByteCodeInstruction::kStore2:
stack[*ip + 1] = sp[0];
POP();
case ByteCodeInstruction::kStore:
stack[*ip] = sp[0];
POP();
++ip;
break;
case ByteCodeInstruction::kStoreGlobal: // fall through
case ByteCodeInstruction::kStoreGlobal2: // fall through
case ByteCodeInstruction::kStoreGlobal3: // fall through
case ByteCodeInstruction::kStoreGlobal4:
count = (int) inst - (int) ByteCodeInstruction::kStoreGlobal + 1;
target = READ8();
SkASSERT(target + count <= (int) fGlobals.size());
memcpy(&fGlobals[target], sp - count + 1, count * sizeof(Value));
sp -= count;
fGlobals[*ip + 3] = sp[0];
POP();
// fall through
case ByteCodeInstruction::kStoreGlobal3:
fGlobals[*ip + 2] = sp[0];
POP();
// fall through
case ByteCodeInstruction::kStoreGlobal2:
fGlobals[*ip + 1] = sp[0];
POP();
case ByteCodeInstruction::kStoreGlobal:
fGlobals[*ip] = sp[0];
POP();
++ip;
break;
case ByteCodeInstruction::kStoreSwizzle:
target = READ8();