diff options
author | Serhiy Storchaka <storchaka@gmail.com> | 2016-09-11 10:48:15 (GMT) |
---|---|---|
committer | Serhiy Storchaka <storchaka@gmail.com> | 2016-09-11 10:48:15 (GMT) |
commit | ab8740058a7f76f1438dc18a2ffd918da4f8118d (patch) | |
tree | f4c763c6e8f6281255b326a17eaaae2c1b237e73 /Python/wordcode_helpers.h | |
parent | bdb847ae99512e0985e1a3e955c90e23d36f8804 (diff) | |
download | cpython-ab8740058a7f76f1438dc18a2ffd918da4f8118d.zip cpython-ab8740058a7f76f1438dc18a2ffd918da4f8118d.tar.gz cpython-ab8740058a7f76f1438dc18a2ffd918da4f8118d.tar.bz2 |
Issue #27129: Replaced wordcode related magic constants with macros.
Diffstat (limited to 'Python/wordcode_helpers.h')
-rw-r--r-- | Python/wordcode_helpers.h | 35 |
1 files changed, 19 insertions, 16 deletions
diff --git a/Python/wordcode_helpers.h b/Python/wordcode_helpers.h index b61ba33..b0e3a91 100644 --- a/Python/wordcode_helpers.h +++ b/Python/wordcode_helpers.h @@ -2,35 +2,38 @@ optimizer. */ -/* Minimum number of bytes necessary to encode instruction with EXTENDED_ARGs */ +#ifdef WORDS_BIGENDIAN +# define PACKOPARG(opcode, oparg) ((_Py_CODEUNIT)(((opcode) << 8) | (oparg))) +#else +# define PACKOPARG(opcode, oparg) ((_Py_CODEUNIT)(((oparg) << 8) | (opcode))) +#endif + +/* Minimum number of code units necessary to encode instruction with + EXTENDED_ARGs */ static int instrsize(unsigned int oparg) { - return oparg <= 0xff ? 2 : - oparg <= 0xffff ? 4 : - oparg <= 0xffffff ? 6 : - 8; + return oparg <= 0xff ? 1 : + oparg <= 0xffff ? 2 : + oparg <= 0xffffff ? 3 : + 4; } /* Spits out op/oparg pair using ilen bytes. codestr should be pointed at the desired location of the first EXTENDED_ARG */ static void -write_op_arg(unsigned char *codestr, unsigned char opcode, +write_op_arg(_Py_CODEUNIT *codestr, unsigned char opcode, unsigned int oparg, int ilen) { switch (ilen) { - case 8: - *codestr++ = EXTENDED_ARG; - *codestr++ = (oparg >> 24) & 0xff; - case 6: - *codestr++ = EXTENDED_ARG; - *codestr++ = (oparg >> 16) & 0xff; case 4: - *codestr++ = EXTENDED_ARG; - *codestr++ = (oparg >> 8) & 0xff; + *codestr++ = PACKOPARG(EXTENDED_ARG, (oparg >> 24) & 0xff); + case 3: + *codestr++ = PACKOPARG(EXTENDED_ARG, (oparg >> 16) & 0xff); case 2: - *codestr++ = opcode; - *codestr++ = oparg & 0xff; + *codestr++ = PACKOPARG(EXTENDED_ARG, (oparg >> 8) & 0xff); + case 1: + *codestr++ = PACKOPARG(opcode, oparg & 0xff); break; default: assert(0); |