4 ms·
Related: It's possible to simplify things using bitmaps: https://github.com/antirez/adventofcode2022/blob/main/day-3/2.c https://github.com/antirez/adventofcode
by antirez 4y ago
Related: It's possible to simplify things using bitmaps: https://github.com/antirez/adventofcode2022/blob/main/day-3/2.c https://github.com/antirez/adventofcode2022/blob/main/day-3/...
- neonsunset 4y agoHey, just noticed our impls. for Day 2 look very similar. If you’re curious, Day 2 can be further improved by using modulo + 2 (or 1 if compiler is smart enough) branches instead of lookup table: https://github.com/neon-sunset/AOC2022/blob/main/Day2/Program.cs https://github.com/neon-sunset/AOC2022/blob/main/Day2/Progra...
- ZoomZoomZoom 4y agoIn which way do you reckon doing modular arithmetic is an improvement over two 3x3 look-up tables?
- neonsunset 4y agoThe rationale is as following - if the compiler cannot fold the lookup table, then math with 1-2 branches will be much cheaper because it involves no memory access and has constant (low) latency (keep in mind that when for example selecting a literal, a conditional select might be emitted which is usually cheaper than a regular branch e.g. Aarch64). In addition, unlike in C, in many other languages indexing into array will involve bounds check if the compiler cannot prove that the access is always in bounds. Obviously most branches will be predicted but branch retire throughput is always lower than math operations throughput.
- ZoomZoomZoom 4y agoThanks for the reply. The bounds checking is a valid reason I haven't thought of. In my case, using 3x3 array is roughly 3-4 times faster.