Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

Oh man, the memories. It was such a revelation discovering how much faster it was to POKE pixels directly into memory in QB rather than use the PSET built-in. And then much of that knowledge was directly transferable to Turbo Pascal and later C.

it really boggled the mind that it was possible to blt a sprite in rows rather than a pixel at a time, and under the hood, the computer was actually copying 4 bytes per instruction. Anyone else remember implementing the 320 row offset as the sum of two bit shifts? By the early 2000s, I seriously doubt that was any faster, but we all did it anyway for "performance".

And don't even get me started on palette hacks— redefining the 256 colors into bars of dark-to-light runs of a single colour, so that you could do smoke or halo effects by just shifting every affected pixel by one or two in either direction.

I don't know if he's around these days on HN, but a shout-out to Mark Sibly (Blitz) for bringing a lot of this stuff to the QBasicNews forum back in the day.



y << 8 + y << 6 + x

(I think the bit shifting and addition trick would still win over an IMUL.)

Edit: also, wasn't there a way of (ab-)using LEA to do some of this?


It seems clang-7 agrees with you— it compiles the multiplication down to shl+add, so the perf is completely identical, see:

http://quick-bench.com/CdxqB_qPD3VS5H7igB31FFoqLLo


But you are also right that it is not a huge difference :) In no-optimization mode, it keeps the imul in for Multiply. the result is 1.2477 vs. 1.2668, relative to Noop.

The site is really cool, thanks for pointing me to it!


Interestingly, gcc-8 does some really weird stuff. Its version of Multiply is 1.4 times slower than its version of Shift, but according to the disassembly, the Shift implementation is actually using an imul, whereas the Multiply implementation is doing a lea/shl.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: