frontpage.
newsnewestaskshowjobs

Made with ♥ by @iamnishanth

Open Source @Github

Open in hackernews

I Ported SAP to a 1976 CPU. It Wasn't That Slow

https://github.com/oisee/zvdb-z80/blob/master/ZVDB-Z80-ABAP.md
28•weinzierl•5h ago

Comments

U1F984•4h ago
From the article: Lookup tables are always faster than calculation - is that true? I'd think that while in the distant past maybe today due to memory being much slower than CPU the picture is different nowadays. If you're calculating a very expensive function over a small domain so the lookup fits in L1 Cache then I can see it would be faster, but you can do a lot of calculating in the time needed for a single main memory access.
haiku2077•4h ago
> Lookup tables are always faster than calculation - is that true?

I know it's not always true on the Nintendo 64, because it shared a single bus between the RAM and "GPU": https://youtu.be/t_rzYnXEQlE?t=94, https://youtu.be/Ca1hHC2EctY?t=827

bayindirh•3h ago
Depends on the hardware and what you are making with that hardware. Some processors can do complicated things stupidly fast (e.g. when SIMD done right), and for some hardware platforms, a mundane operation can be very costly since they are designed for other things primarily.

My favorite story is an embedded processor which I forgot its ISA. The gist was, there was a time budget, and doing a normal memory access would consume 90% of that budget alone. The trick was to use the obscure DMA engine to pump data into the processor caches asynchronously. This way, moving data was only ~4% of the same budget, and they have beaten their performance targets by a large margin.

ay•3h ago
You will need to first sit and ballpark, and then sit and benchmark, and discover your ballpark was probably wrong anyhow:-)

Some (for me) useful pointers to that regard for both:

1. https://www.agner.org/optimize/instruction_tables.pdf - an extremely nice resource on micro architectural impacts of instructions

2. https://llvm.org/docs/CommandGuide/llvm-mca.html - tooling from Intel that allows to see some of these in real machine code

3. https://www.intel.com/content/www/us/en/developer/articles/t... - shows you whether the above is matching the reality (besides the CPU alone, more often than not your bottleneck is actually memory accesses; at least on the first access which wasn’t triggered by a hardware prefetcher or a hint to it. On Linux it would be staring at “perf top” results.

So, the answer is as is very often - “it depends”.

bayindirh•3h ago
...and we always circle back to "premature optimization is the root of all evil", since processors are a wee bit more intelligent with our instructions than we thought. :)
yorwba•3h ago
In this case, the lookup table is used for popcount, and there's a comment in the Z80 assembly that says "One lookup vs eight bit tests." If the code could make use of a hardware popcount instruction, the lookup table would lose, but if that isn't available, a 256-byte lookup table could be faster. So it's less "lookup tables are always faster" and more "lookup tables can be faster, this is one such case."
whizzter•2h ago
The article does mention cache friendly access patterns in the same context.

But yes, you're right. Back when I started with optimizations in the mid 90s memory _latencies_ were fairly minor compared to complex instructions so most things that wasn't additions (and multiplications on the Pentium) would be faster from a lookup table, over time memory latencies grew and grew as clock speeds and other improvements made the distance to the physical memory an actual factor and lookup tables less useful compared to recomputing things.

Still today there are things that are expensive enough that can be fit in a lookup table that is small enough that it doesn't get evicted from cache during computation, but they're few.

devnullbrain•2h ago
You are correct and I've even ran into a situation where build-time evaluation was slower than runtime calculation, thanks to code size.
mananaysiempre•2h ago
> Lookup tables are always faster than calculation - is that true?

Maybe on the Z80. Contemporary RAM was quite fast compared to it, by our sad standards.

A table lookup per byte will see you hit a pretty hard limit of about 1 cycle per byte on all x86 CPUs of the last decade. If you’re doing a state machine or a multistage table[1] where the next table index depends on both the next byte and the previous table value, you’ll be lucky to see half that. Outracing your SSD[2] you’re not, with this approach.

If instead you can load a 64-bit chunk (or several!) at a time, you’ll have quite a bit of leeway to do some computation to it before you’re losing to the lookup table, especially considering you’ve got fast shifts and even multiplies (another difference from the Z80). And if you’re doing 128- or 256-bit vectors, you’ve got even more compute budget—but you’re also going to spend a good portion of it just shuffling the right bytes into the right positions. Ultimately, though, one of your best tools there is going to be ... an instruction that does 16 resp. 32 lookups in a 16-entry table at a time[3].

So no, if you want to be fast on longer pieces of data, in-memory tables are not your friend. On smaller data, with just a couple of lookups, they could be[4]. In any case, you need to be thinking about your code’s performance in detail for these things to matter—I can’t think of a situation where “prefer a lookup table” is a useful heuristic. “Consider a lookup table” (then measure), maybe.

[1] https://www.unicode.org/versions/latest/ch05.pdf

[2] https://lemire.me/en/talk/perfsummit2020/

[3] http://0x80.pl/notesen/2008-05-24-sse-popcount.html

[4] https://tia.mat.br/posts/2014/06/23/integer_to_string_conver...

Taniwha•2h ago
I'm a sometimes CPU architect and came here to argue just this - modern CPUs have far far slower memory access (in clocks) than z80 memory access. To be fair you can probably fit any z80 table you're using into modern L1 cache, but even so you're looking at multiple clocks rather than 1.
flohofwoe•1h ago
On the Z80 any memory access had a fixed cost of 3 clock cycles (in reality the memory system could inject wait cycles, but that was an esoteric case). Together with the instruction fetch of 4 clock cycles the fastest instruction to load an 8-bit value from an address that's already in a 16-bit register (like LD A,(HL)) takes 7 clock cycles.

The fastest instructions that didn't access memory (like adding two 8-bit registers) were 4 clock cycles, so there's really not much room to beat a memory access with computation.

Today "it depends", I still use lookup tables in some places in my home computer emulators, but only after benchmarking showed that the table is actually slightly faster.

peteforde•4h ago
I have only one question: does the author know anything about coding ABAP like it's a Z80? I wish that they'd addressed this.
ooisee•14m ago
yes, it is addressed in another repo https://github.com/oisee/zvdb

and another article about zvdb-abap from ~1.5 years ago.

bravesoul2•2h ago
It's amusing that the writing style is akin to a LinkedIn what XYZ taught me about B2B sales.
_notreallyme_•2h ago
Optimizing code on MMU-less processor versus MMU and even NUMA capable processor is vastly different.

The fact that the author achieves only a 3 to 6 times speedup on a processor running at a frequency 857 faster should have led to the conclusion that old optimizations tricks are awfully slow on modern architecture.

To be fair, execution pipeline optimization still works the same, but not taking into account the different layers of cache, the way the memory management works and even how and when actual RAM is queried will only lead to suboptimal code.

orbifold•1h ago
Writing style and length of paragraphs strongly suggest that this is AI generated in full.

Get instant alerts when someone clicks your link

https://blazeurl.xyz/TdXG2G
1•gojam•37s ago•1 comments

Dior's Women at Dior Initiative Is Supporting Young Female Talent

https://www.forbes.com/sites/stephaniehirschmiller/2025/07/07/how-diors-women-at-dior-initiative-is-supporting-young-female-talent/
1•Bluestein•2m ago•0 comments

Ask HN: How do you define Vibe Coding?

1•johncole•2m ago•0 comments

Show HN: Instant Steam ID Lookup, Profile Comparison, and AI Game Suggestions

https://steamid.one
1•alexcolewrites•5m ago•0 comments

Art and Science in a Grain of Sand

https://nautil.us/art-and-science-in-a-grain-of-sand-1222283/
1•dnetesn•6m ago•0 comments

Doregaku now study with Doraemon Anime.. Science and Technology studies made fun

1•Kunal_Aher•9m ago•0 comments

1 Month – $118/m: What I Learned

https://promptdc.com/
1•pvisilias•10m ago•3 comments

Show HN: Multi Search Booster – Open multiple websites with one search

https://chromewebstore.google.com/detail/multi-search-booster/kcmfnehklmflhlmcjmjpkeccclijefag
1•vasudevsoni2001•10m ago•0 comments

Show HN: I got my first SaaS Beta Signup

https://imgur.com/a/iTlY2h2
1•WarcrimeActual•11m ago•0 comments

Rogue holes – inverse phenomenon of a rogue wave

https://brilliantmaps.com/rogue-holes-waves/
1•slowhand09•13m ago•0 comments

The First AI Coding Style Guide

https://github.com/lidangzzz/AI-Coding-Style-Guides
1•lidangzzz•17m ago•0 comments

Learn how to disable Gemini AI on Android

https://tuta.com/blog/how-to-disable-gemini-on-android
8•nabla9•18m ago•0 comments

Hacker News is my digital home – why I left X but stayed here

4•FerkiHN•21m ago•4 comments

Qantas contacted by suspected cyber criminal

https://www.theguardian.com/business/2025/jul/07/qantas-contacted-by-suspected-cyber-criminal-but-airline-wont-confirm-if-hacking-ransom-demanded
1•Bluestein•22m ago•0 comments

WhatsApp for iOS to get threaded replies for clearer conversations

https://www.neowin.net/news/whatsapp-for-ios-to-get-threaded-replies-for-clearer-conversations/
1•Bluestein•26m ago•0 comments

How a big shift in training LLMs led to a capability explosion

https://arstechnica.com/ai/2025/07/how-a-big-shift-in-training-llms-led-to-a-capability-explosion/
1•pseudolus•26m ago•0 comments

EVM-UI – visual tool to interact with EVM-based smart contracts

2•magnusgraviti•29m ago•2 comments

Atlassian migrated 4M Postgres databases to shrink AWS bill

https://www.atlassian.com/blog/atlassian-engineering/migrating-jira-database-platform-to-aws-aurora
1•maxloh•32m ago•0 comments

Report on China Eastern 5735 Crash Withheld over National Security Concerns

https://airlinegeeks.com/2025/06/27/report-on-deadly-crash-withheld-over-national-security-concerns/
2•agubelu•33m ago•0 comments

Show HN: CPU Shit Drawer – AI Generates JSON Coordinates, CPU Renders with PIL

https://poops-draw.site/
2•thunderlab•35m ago•0 comments

Ultracite – Zero-config Biome preset for JavaScript

https://github.com/haydenbleasel/ultracite
1•fmerian•36m ago•0 comments

Ask HN: How to create a website to express bad product experience?

1•hownotcensored•36m ago•0 comments

Interaction with megafauna in S. America earlier than widely accepted theory

https://archaeologymag.com/2025/07/sloth-bone-shows-possible-human-inflicted-trauma/
1•gametorch•37m ago•0 comments

VMware's rivals ramp up their efforts to create alternative stacks

https://www.theregister.com/2025/07/07/vmware_rivals_ramp_virtualization_efforts/
1•rntn•43m ago•0 comments

Show HN: Tallya – The minimal UX foundation for count labels

https://github.com/faizanu94/tallya
1•faizanu94•44m ago•0 comments

Why Matt Mullenweg went to war over WordPress

https://www.theverge.com/decoder-podcast-with-nilay-patel/693052/automattic-ceo-matt-mullenweg-wordpress-drama-wp-engine-open-source
3•donohoe•44m ago•0 comments

VibeTunnel: Turn Any Browser into Your Mac's Terminal

https://steipete.me/posts/2025/vibetunnel-turn-any-browser-into-your-mac-terminal
1•teehemkay•47m ago•0 comments

Show HN: Promptbuild.ai – Version control for LLM prompts

https://www.promptbuild.ai
1•error7891•48m ago•0 comments

PhantomGPU: GPU performance emulator to benchmark ML models on virtual GPUs

https://github.com/bugthesystem/PhantomGPU
3•ziyasal•50m ago•2 comments

The untold story about how Olive Garden's most popular special came to be

https://www.cnn.com/2025/07/05/food/olive-garden-never-ending-breadsticks-story
2•mooreds•52m ago•0 comments