diff options
author | Ben Smith <binji@chromium.org> | 2018-09-10 13:04:22 -0700 |
---|---|---|
committer | Ben Smith <binji@chromium.org> | 2018-09-10 19:37:14 -0700 |
commit | ad864f79b7340f60fc3a58448055f77cb9a6b3e3 (patch) | |
tree | 6025617b1914cc25a2e6413a5f488496e1eae2a9 /src/binary-reader-interp.cc | |
parent | 0b5f3c8af75422c1ba17f322b0ab816ef6bc0a58 (diff) | |
download | wabt-ad864f79b7340f60fc3a58448055f77cb9a6b3e3.tar.gz wabt-ad864f79b7340f60fc3a58448055f77cb9a6b3e3.tar.bz2 wabt-ad864f79b7340f60fc3a58448055f77cb9a6b3e3.zip |
Optimize interpreter and `Opcode::FromCode`
`Opcode::FromCode` calculated the opcode given a prefix/code pair by
using lower_bound over the list of all `OpcodeInfo`s. This was happening
for every instruction, which is incredibly slow.
Since the interpreter's format is internal only, we can use any encoding
we want, so it's simpler and faster to use the `Opcode::Enum` directly
without calling `Opcode::FromCode`.
`Opcode::FromCode` is also used when reading a binary file, so it should
be optimized anyway. Instead of using the `infos_` table, which is
indexed by the opcode's `enum_` value, we create a new
statically-defined table that maps from prefix-code pair to its enum
value.
Unfortunately, this can't be done easily in C++ because it does not
currently support designated array initializers, so this table is
created in a C file instead, `opcode-code-table.c`.
Diffstat (limited to 'src/binary-reader-interp.cc')
-rw-r--r-- | src/binary-reader-interp.cc | 9 |
1 files changed, 1 insertions, 8 deletions
diff --git a/src/binary-reader-interp.cc b/src/binary-reader-interp.cc index 77941447..cfc32dba 100644 --- a/src/binary-reader-interp.cc +++ b/src/binary-reader-interp.cc @@ -422,14 +422,7 @@ wabt::Result BinaryReaderInterp::EmitData(const void* data, } wabt::Result BinaryReaderInterp::EmitOpcode(Opcode opcode) { - if (opcode.HasPrefix()) { - CHECK_RESULT(EmitI8(opcode.GetPrefix())); - } - - // Assume opcode codes are all 1 byte for now (excluding the prefix). - uint32_t code = opcode.GetCode(); - assert(code < 256); - return EmitI8(code); + return EmitI32(static_cast<uint32_t>(opcode)); } wabt::Result BinaryReaderInterp::EmitI8(uint8_t value) { |