GH-91719: Make MSVC generate somewhat faster switch code (#91718)

Apparently a switch on an 8-bit quantity where all cases are
present generates a more efficient jump (doing only one indexed
memory load instead of two).

So we make opcode and use_tracing uint8_t, and generate a macro
full of extra `case NNN:` lines for all unused opcodes.

See https://github.com/faster-cpython/ideas/issues/321#issuecomment-1103263673
This commit is contained in:
Guido van Rossum 2022-04-21 11:53:57 -07:00 committed by GitHub
parent d44815cabc
commit f8dc6186d1
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 90 additions and 3 deletions

View file

@ -129,6 +129,13 @@ def main(opcode_py, outfile='Include/opcode.h'):
fobj.write("};\n")
fobj.write("#endif\n")
fobj.write("\n")
fobj.write("#define EXTRA_CASES \\\n")
for i, flag in enumerate(used):
if not flag:
fobj.write(f" case {i}: \\\n")
fobj.write(" ;\n")
fobj.write(footer)