anonymoushn
My own solution which is ~1ms faster uses some other pattern that was found experimentally, but I cannot seem to get it to go any faster by tuning the parameters, and the #1 spot remains slightly out of reach.

Alexander Monakov has called the attention of the highload Telegram chat to this paper[0], saying:

  Haswell is tricky for memory bw tuning, as even at fixed core frequency, uncore frequency is not fixed, and depends on factors such as hardware-measured stall cycles:

  > According to the respective patent [15], the uncore frequency depends on the stall cycles of the cores, the EPB of the cores, and c-states

  > ... uncore frequencies–in addition to EPB and stall cycles–depend on the core frequency of the fastest active core on the system. Moreover, the uncore frequency is also a target of power limitations.
So one wonders if it's not really a matter of reading the RAM in the right pattern to appease the prefetchers but of using values in the right pattern to create the right pattern of stalls to get the highest frequency.

[0]: https://tu-dresden.de/zih/forschung/ressourcen/dateien/proje...

sYnfo
FYI vien [0] figured out that simply compiling with "-static -fno-pie" and _exit(0)-ing at the end puts the solution presented here to 15000 points and hence #4 on the leaderboard. Pretty funny.

[0] https://news.ycombinator.com/user?id=vient

dinobones
Is there a path forward for compilers to eek out these optimization gains eventually? Is there even a path?

550x gains with some C ++ / mixed gnarly low level assembly vs standard C++ is pretty shocking to me.

maxbond
Usually, it's fair game to use all of the information presented in an exam-style question to derive your answer.

With that in mind, I propose the following solution.

`print(976563)`

lumb63
Does anyone have any tips for similar wizardry-level SIMD optimization on ARM?
rini17
Can this optimization be applied to matmult for us, critters who are running llama on cpu? XD
_a_a_a_
"The solution presented here is ~550x faster than the following naive program."

   ... std::cin >> v; ...
Oh come on! That's I/O for every item, I'm surprised it's not even slower.
TacticalCoder
Le met hazard a guess: that blog post was not written by a LLM!?