RSSAmplifier

Blog

nicula.xyz blog

Recent content on nicula.xyz

nicula.xyzRSS feed ↗8 posts

Latest posts

Claude Code's poor time awareness

From some of my interactions with Claude Code 1 so far I’ve noticed that it seems to have a pretty glaring issue: it doesn’t really have a good sense of time-tracking built into it. Because of this, Claude 2 misses good choices that would help it finish some tasks significantly faster. The general form of those specific interactions of mine is essentially this: There is an executable…

Auto-vectorizing operations on buffers of unknown length

GCC isn’t yet capable of auto-vectorizing even simple search operations on buffers for which the length isn’t explicitly specified 1 . Take the classic example of strlen() : 1 2 3 4 5 6 7 size_t strlen ( const char * str ) { for ( size_t i = 0 ;; i ++ ) { if ( str [ i ] == '\0' ) { return i ; } } } This is the assembly output, compiled with -O3 -march=znver3 -ffreestanding 2 : 1 2 3 4…

Bypassing the branch predictor

A couple of days ago I was thinking about what you can do when the branch predictor is effectively working against you, and thus pessimizing your program instead of optimizing it. Let’s work with something relatively simple & concrete: consider that we want to write some kind of financial system (maybe a trading system) and all of our transaction requests arrive at a certain function before…

Improving on std::count_if()'s auto-vectorization

The problem Let’s consider the problem with the following description: We have an array of arbitrary length filled with uint8_t values; We want to count the number of even values in the array; Before doing the calculation we know that the number of even values in the array is between 0 and 255 1 . A typical solution To start off, we can leverage the STL for this calculation. std::count_if()…

Getting rid of unwanted branches with __builtin_unreachable()

Consider that we have an array of 8-bit unsigned integers and we want to calculate their sum modulo 256. In C++ we can do it like this: 1 2 3 4 uint8_t sum ( const uint8_t * data , size_t len ) { return std :: accumulate ( data , data + len , uint8_t ( 0 )); } When compiling with Clang 19.1.0 and flags -O3 -march=rocketlake -fno-unroll-loops , we get the following assembly: 1 2 3 4 5 6 7 8 9 10 11…

My approach to writing

Short (meta) blog post about what kind of educational materials I prefer, and why: I generally prefer learning material that is impersonal, and doesn’t contain author-specific idiosyncrasies. When I’m reading or watching something, I’m not interested in hearing the author give a ‘performance’, I’m typically interested strictly in the key information being…

A Clang regression related to switch statements and inlining

After my previous post, Eliminating redundant bound checks (read it for context if you haven’t already), I wanted to do a benchmark using the ‘optimized’ version of the increment() function, which didn’t contain any bound checks when compiled with Clang, even though we used .at() for indexing into the array. Here’s that last version of the function from the previous…

Eliminating redundant bound checks

Problem Consider that you have some mapping from indexes in the range [0, 255] to indexes in the range [0, 1023] . The requirements are: Write a function that takes an array of 1024 8-bit unsigned integers and increments the value at an arbitrary index. Only use safe methods of indexing that do bounds checking (e.g. using .at() in C++ instead of the subscript operator). Avoid constructs such as…