Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(191)

Issue 20064: condbranches-plus2.patch (Closed)

Can't Edit
Can't Publish+Mail
Start Review
Created:
15 years, 10 months ago by Jeffrey Yasskin
Modified:
15 years, 5 months ago
Reviewers:
Collin Winter
Base URL:
http://svn.python.org/view/*checkout*/python/branches/py3k/
Visibility:
Public.

Description

http://bugs.python.org/issue4715 This patch by Antoine Pitrou optimizes the bytecode for conditional branches. For example, the list comprehension "[x for x in l if not x]" produced the following bytecode: 1 0 BUILD_LIST 0 3 LOAD_FAST 0 (.0) >> 6 FOR_ITER 23 (to 32) 9 STORE_FAST 1 (x) 12 LOAD_FAST 1 (x) 15 JUMP_IF_TRUE 10 (to 28) 18 POP_TOP 19 LOAD_FAST 1 (x) 22 LIST_APPEND 2 25 JUMP_ABSOLUTE 6 >> 28 POP_TOP 29 JUMP_ABSOLUTE 6 >> 32 RETURN_VALUE but after the patch it produces the following bytecode: 1 0 BUILD_LIST 0 3 LOAD_FAST 0 (.0) >> 6 FOR_ITER 18 (to 27) 9 STORE_FAST 1 (x) 12 LOAD_FAST 1 (x) 15 POP_JUMP_IF_TRUE 6 18 LOAD_FAST 1 (x) 21 LIST_APPEND 2 24 JUMP_ABSOLUTE 6 >> 27 RETURN_VALUE Notice that not only the code is shorter, but the conditional jump (POP_JUMP_IF_TRUE) jumps right to the start of the loop instead of going through the JUMP_ABSOLUTE at the end. "continue" statements are helped similarly. Furthermore, the old jump opcodes (JUMP_IF_FALSE, JUMP_IF_TRUE) have been replaced by two new opcodes: - JUMP_IF_TRUE_OR_POP, which jumps if true and pops otherwise - JUMP_IF_FALSE_OR_POP, which jumps if false and pops otherwise

Patch Set 1 #

Patch Set 2 : Backport to trunk #

Patch Set 3 : Fixing Collin's comments #

Unified diffs Side-by-side diffs Delta from patch set Stats (+227 lines, -177 lines) Patch
M Doc/library/dis.rst View 1 2 1 chunk +16 lines, -6 lines 0 comments Download
M Include/opcode.h View 1 2 1 chunk +6 lines, -3 lines 0 comments Download
M Lib/compiler/pyassem.py View 2 1 chunk +3 lines, -0 lines 0 comments Download
M Lib/compiler/pycodegen.py View 2 12 chunks +12 lines, -35 lines 0 comments Download
M Lib/opcode.py View 1 2 1 chunk +5 lines, -3 lines 0 comments Download
M Lib/test/test_dis.py View 2 1 chunk +16 lines, -18 lines 0 comments Download
M Lib/test/test_peepholer.py View 1 2 2 chunks +5 lines, -6 lines 0 comments Download
M Python/ceval.c View 1 2 5 chunks +67 lines, -17 lines 0 comments Download
M Python/compile.c View 1 2 18 chunks +33 lines, -53 lines 0 comments Download
M Python/import.c View 1 2 1 chunk +3 lines, -1 line 0 comments Download
M Python/peephole.c View 1 2 6 chunks +61 lines, -35 lines 0 comments Download

Messages

Total messages: 2
Jeffrey Yasskin
15 years, 10 months ago (2009-02-28 01:38:53 UTC) #1
Collin Winter
15 years, 10 months ago (2009-03-01 20:08:03 UTC) #2
LGTM
Sign in to reply to this message.

Powered by Google App Engine
RSS Feeds Recent Issues | This issue
This is Rietveld f62528b