16-bit instructions
This should give us plenty of coding space.
If anything this seems to run faster:
Before: 21/21 MB 1 4.33ms 4.33ms 4.34ms 4.36ms 0% ▁▁▃▁▂▂▁▂▂█ 8888 GM_runtime_cf_interp_1
After: 21/21 MB 1 4.17ms 4.17ms 4.17ms 4.18ms 0% ▃▂▁▅▄▃█▅▅▆ 8888 GM_runtime_cf_interp_1
Change-Id: I6beb785fc0d00fb274a1f87c2fdd5ed530b96b8f
Reviewed-on: https://skia-review.googlesource.com/c/skia/+/215046
Commit-Queue: Mike Klein <mtklein@google.com>
Reviewed-by: Ethan Nicholas <ethannicholas@google.com>
Reviewed-by: Brian Osman <brianosman@google.com>
diff --git a/src/sksl/SkSLByteCode.h b/src/sksl/SkSLByteCode.h
index 19d739a..b28fd57 100644
--- a/src/sksl/SkSLByteCode.h
+++ b/src/sksl/SkSLByteCode.h
@@ -20,7 +20,7 @@
struct FunctionDeclaration;
#define VECTOR(name) name, name ## 2, name ## 3, name ## 4
-enum class ByteCodeInstruction : uint8_t {
+enum class ByteCodeInstruction : uint16_t {
// B = bool, F = float, I = int, S = signed, U = unsigned
VECTOR(kAddF),
VECTOR(kAddI),
@@ -101,9 +101,7 @@
VECTOR(kXorI),
// Followed by a byte indicating external value to write
VECTOR(kWriteExternal),
- kLast
};
-static_assert((int) ByteCodeInstruction::kLast <= 256, "opcodes must fit into a single byte");
#undef VECTOR
struct ByteCodeFunction {
diff --git a/src/sksl/SkSLByteCodeGenerator.cpp b/src/sksl/SkSLByteCodeGenerator.cpp
index 94f4e78..e213594 100644
--- a/src/sksl/SkSLByteCodeGenerator.cpp
+++ b/src/sksl/SkSLByteCodeGenerator.cpp
@@ -178,7 +178,7 @@
}
void ByteCodeGenerator::write(ByteCodeInstruction i) {
- this->write8((uint8_t) i);
+ this->write16((uint16_t)i);
}
static ByteCodeInstruction vector_instruction(ByteCodeInstruction base, int count) {
diff --git a/src/sksl/SkSLInterpreter.cpp b/src/sksl/SkSLInterpreter.cpp
index c0d79c5..2435abd 100644
--- a/src/sksl/SkSLInterpreter.cpp
+++ b/src/sksl/SkSLInterpreter.cpp
@@ -95,7 +95,7 @@
const uint8_t* ip = f.fCode.data();
while (ip < f.fCode.data() + f.fCode.size()) {
printf("%d: ", (int) (ip - f.fCode.data()));
- switch ((ByteCodeInstruction) READ8()) {
+ switch ((ByteCodeInstruction) READ16()) {
VECTOR_DISASSEMBLE(kAddF, "addf")
VECTOR_DISASSEMBLE(kAddI, "addi")
case ByteCodeInstruction::kAndB: printf("andb"); break;
@@ -292,7 +292,7 @@
std::vector<StackFrame> frames;
for (;;) {
- ByteCodeInstruction inst = (ByteCodeInstruction) READ8();
+ ByteCodeInstruction inst = (ByteCodeInstruction) READ16();
#ifdef TRACE
printf("at %d\n", (int) (ip - code - 1));
#endif