Settings

Theme

One Line, Three Tricks: Unpacking a Quake 1 Gem

sepi.me

3 points by sepisoad 10 months ago · 2 comments

Reader

ferguess_k 10 months ago

My question is: is it going to produce more efficient assembly code when compiled? Guess I'll have to run it through Godbolt.

  • sepisoadOP 10 months ago

    i put together something in godbolt and here is the result:

    https://godbolt.org/z/sbzPT33nq

    “quake” version uses “lea" to pre-increment pointers before storing values. “normal” version uses “add" after storing values.

    The “lea" instruction is often faster because it performs an addition in a single cycle without modifying flags, whereas “add" may introduce a dependency.

    “quake” version might have a slight edge due to better pipeline efficiency.

    “lea" is often preferred over “add" in performance-critical code because it is a single-cycle instruction on modern x86 CPUs.

Keyboard Shortcuts

j
Next item
k
Previous item
o / Enter
Open selected item
?
Show this help
Esc
Close modal / clear selection