Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Optimizing compiler
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Machine-independent vs. machine-dependent=== Many optimizations that operate on abstract programming concepts (loops, objects, structures) are independent of the machine targeted by the compiler, but many of the most effective optimizations are those that best exploit special features of the target platform. Examples are instructions that do several things at once, such as decrement register and branch if not zero. The following is an instance of a local machine-dependent optimization. To set a [[Processor register|register]] to 0, the obvious way is to use the constant '0' in an instruction that sets a register value to a constant. A less obvious way is to [[XOR]] a register with itself or subtract it from itself. It is up to the compiler to know which instruction variant to use. On many [[RISC]] machines, both instructions would be equally appropriate, since they would both be the same length and take the same time. On many other [[microprocessor]]s such as the [[Intel]] [[x86]] family, it turns out that the XOR variant is shorter and probably faster, as there will be no need to decode an immediate operand, nor use the internal "immediate operand register"; the same applies on [[IBM System/360]] and successors for the subtract variant.<ref>{{cite book |url=https://bitsavers.trailing-edge.com/pdf/ibm/360/training/GC20-1646-5_A_Programmers_Introduction_to_IBM_System360_Assembly_Language_196907.pdf |title=A Programmer's Introduction to IBM System/360 Assembly Language |page=42 |publisher=[[IBM]] |id=GC20-1645-5}}</ref> A potential problem with this is that XOR or subtract may introduce a data dependency on the previous value of the register, causing a [[instruction pipeline|pipeline]] stall, which occurs when the processor must delay execution of an instruction because it depends on the result of a previous instruction. However, processors often treat the XOR of a register with itself or the subtract of a register from itself as a special case that does not cause stalls.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)