Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 1515fc2

Browse files
committed
A 2% speed improvement with gcc on low-endian machines. My guess is that this
new pattern for NEXTARG() is detected and optimized as a single (*short) loading.
1 parent 09240f6 commit 1515fc2

1 file changed

Lines changed: 10 additions & 6 deletions

File tree

Python/ceval.c

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -627,7 +627,8 @@ eval_frame(PyFrameObject *f)
627627

628628
#define INSTR_OFFSET() (next_instr - first_instr)
629629
#define NEXTOP() (*next_instr++)
630-
#define NEXTARG() (next_instr += 2, (next_instr[-1]<<8) + next_instr[-2])
630+
#define OPARG() (next_instr[0] + (next_instr[1]<<8))
631+
#define OPARG_SIZE 2
631632
#define JUMPTO(x) (next_instr = first_instr + (x))
632633
#define JUMPBY(x) (next_instr += (x))
633634

@@ -658,8 +659,7 @@ eval_frame(PyFrameObject *f)
658659
#endif
659660

660661
#define PREDICTED(op) PRED_##op: next_instr++
661-
#define PREDICTED_WITH_ARG(op) PRED_##op: oparg = (next_instr[2]<<8) + \
662-
next_instr[1]; next_instr += 3
662+
#define PREDICTED_WITH_ARG(op) PRED_##op: next_instr++; oparg = OPARG(); next_instr += OPARG_SIZE
663663

664664
/* Stack manipulation macros */
665665

@@ -862,8 +862,11 @@ eval_frame(PyFrameObject *f)
862862
/* Extract opcode and argument */
863863

864864
opcode = NEXTOP();
865-
if (HAS_ARG(opcode))
866-
oparg = NEXTARG();
865+
if (HAS_ARG(opcode)) {
866+
oparg = OPARG();
867+
next_instr += OPARG_SIZE;
868+
}
869+
867870
dispatch_opcode:
868871
#ifdef DYNAMIC_EXECUTION_PROFILE
869872
#ifdef DXPAIRS
@@ -2249,7 +2252,8 @@ eval_frame(PyFrameObject *f)
22492252

22502253
case EXTENDED_ARG:
22512254
opcode = NEXTOP();
2252-
oparg = oparg<<16 | NEXTARG();
2255+
oparg = oparg<<16 | OPARG();
2256+
next_instr += OPARG_SIZE;
22532257
goto dispatch_opcode;
22542258

22552259
default:

0 commit comments

Comments
 (0)