Evening all,
Here's a brief chat with the interpretator:
Python 2.4.1 (#2, Mar 31 2005, 00:05:10)
[GCC 3.3 20030304 (Apple Computer, Inc. build 1666)] on darwin
Type "help", "copyright", "credits" or "license" for more information. def fib(x):
.... if (x == 1):
.... return 1
.... else:
.... return x * fib((x - 1))
.... import dis dis.dis(fib)
2 0 LOAD_FAST 0 (x)
3 LOAD_CONST 1 (1)
6 COMPARE_OP 2 (==)
9 JUMP_IF_FALSE 8 (to 20)
12 POP_TOP
3 13 LOAD_CONST 1 (1)
16 RETURN_VALUE
17 JUMP_FORWARD 19 (to 39) 20 POP_TOP
5 21 LOAD_FAST 0 (x)
24 LOAD_GLOBAL 1 (fib)
27 LOAD_FAST 0 (x)
30 LOAD_CONST 1 (1)
33 BINARY_SUBTRACT
34 CALL_FUNCTION 1
37 BINARY_MULTIPLY
38 RETURN_VALUE 39 LOAD_CONST 0 (None)
42 RETURN_VALUE
I'm no bytecode connoisseur, but having read
<http://docs.python.org/lib/bytecodes.html>, i more or less get this.
What puzzles me, though, are bytecodes 17, 39 and 42 - surely these aren't
reachable? Does the compiler just throw in a default 'return None'
epilogue, with routes there from every code path, even when it's not
needed? If so, why?
tom
--
News flash: there's no deep meaning or hidden message BECAUSE DAVID LYNCH IS INSANE 4 1626
On Mon, Oct 10, 2005 at 12:20:13AM +0100, Tom Anderson wrote: What puzzles me, though, are bytecodes 17, 39 and 42 - surely these aren't reachable? Does the compiler just throw in a default 'return None' epilogue, with routes there from every code path, even when it's not needed? If so, why?
I think the short answer is "yes". They're unreachable, and they're thrownin
by default.
It's possible that this could be fixed with a slightly smarter compiler, but
the performance difference is likely to be in the noise. What's one cache miss
(because the bytecode is slightly larger) compared to the total cycles used
in, say, the LOAD_GLOBAL 'fib'?
My bet is that this optimization would not pay off in measurable run-time
gains.
Jeff
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
iD8DBQFDSam1Jd01MZaTXX0RAlcrAJsHKk87wjAQmqSdwKNXLa GRQfZCLwCggROk
Y6Ai9/sgiTzOyZFIRhRo9Lo=
=MRzz
-----END PGP SIGNATURE-----
Tom Anderson wrote: Evening all,
Here's a brief chat with the interpretator:
[snip]
What puzzles me, though, are bytecodes 17, 39 and 42 - surely these aren't reachable? Does the compiler just throw in a default 'return None' epilogue, with routes there from every code path, even when it's not needed? If so, why?
I think the last RETURN_VALUE (None) isn't thrown in unless there is
some sort of conditional the precedes it as in this example.
As to why: it's easier and no one has done anything about fixing it.
If you (or anyone else) are interested, the code is in
Python/compile.c. Search for the optimize_code() function.
n
[Tom Anderson]: What puzzles me, though, are bytecodes 17, 39 and 42 - surely these aren't reachable? Does the compiler just throw in a default 'return None' epilogue, with routes there from every code path, even when it's not needed? If so, why?
Since unreachable code is never executed, there is no performance
payoff for optimizing it away. It is not hard to write a dead-code
elimination routine, but why bother? It would save a few bytes, slow
down compilation time, save nothing at runtime, and make the compiler
more complex/fragile.
FWIW, the peephole optimizer in Python/compile.c is mature -- the low
hanging fruit has already been harvested, leaving the field of
remaining optimizations somewhat barren.
Raymond
On Tue, 11 Oct 2005, Raymond Hettinger wrote: [Tom Anderson]:
What puzzles me, though, are bytecodes 17, 39 and 42 - surely these aren't reachable? Does the compiler just throw in a default 'return None' epilogue, with routes there from every code path, even when it's not needed? If so, why? Since unreachable code is never executed, there is no performance payoff for optimizing it away. It is not hard to write a dead-code elimination routine, but why bother?
Fair enough - it wasn't a criticism, i was just wondering if those
bytecodes were serving some crucial function i hadn't appreciated!
It would save a few bytes, slow down compilation time, save nothing at runtime, and make the compiler more complex/fragile.
I have this vague idea that a compiler could be written in such a way
that, rather than dead code being weeded out by some
extra-complexity-inducing component, it would simply never be generated in
the first place; that could perhaps even be simpler than the situation at
present. I have tree reduction and SSA graphs frolicking in soft focus in
my imagination. But, that said, i have no experience of actually writing
compilers, so maybe this SSA stuff is harder than it sounds!
tom
--
That's no moon! This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: sxanth |
last post by:
>What puzzles me, though, are bytecodes 17, 39 and 42 - surely these aren't
>reachable? Does the compiler just throw in a default 'return None'
>epilogue, with routes there from every code path,...
|
by: Frank Rizzo |
last post by:
I want to log the user out when there has been a period of inactivity in
the application. The key here is inactivity of the application, not the
system. I know that you can retrieve the...
|
by: bobueland |
last post by:
IDLE doesn't seem to honor PYTHONSTARTUP environment variable nor
sitecustomize.py
How do you then customize in IDLE?
(basically I want to execute the statement
from btools import *
each...
|
by: HillBilly |
last post by:
What does that error mean and why would each break statement be marked as
unreachable? It implies the return will --always-- return some --thing-- if
even null and no further processing can...
|
by: Charles Arthur |
last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
|
by: isladogs |
last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM).
In this session, we are pleased to welcome a new...
| |