Live data from Hacker News

Branchless Rust: Making a Filter 4x Faster by Removing an If

greyblake.com

41–50 of 124 posts

Re: Branchless Rust: Making a Filter 4x Faster by Removing an If

#41
post #12

This article is 100% AI written. The data was interesting, the commentary overly verbose and hard to gain useful insights from.

idk why this is getting downvoted, I also got this sense, plugged it into Pangram and indeed, 80% AI-written score. I guess that's fine, but after awhile I get a spidey-sense reading something that feels like a Claude session.

Sad to see you getting voted down. But I guess both the pro-AI crowd and anti-AI crowd hate Pangram.

Re: Branchless Rust: Making a Filter 4x Faster by Removing an If

#42
post #18

This article is 100% AI written. The data was interesting, the commentary overly verbose and hard to gain useful insights from.

I'm apparently not good at spotting it. I was put off by the overly dramatic presentation. It gets tiring that the author apparently finds this more exciting than I do, and writes like it's enthralling. I just assumed it was an excess of enthusiasm or the first experience with this kind of thing. If it's AI, I'm way behind the game noticing it.

> I was put off by the overly dramatic presentation. It gets tiring that the author apparently finds this more exciting than I do, and writes like it's enthralling.

That's one of the main tells that AI wrote this. All the stylistic tics that people usually point out combine to make the writing seem more important than it is.

Re: Branchless Rust: Making a Filter 4x Faster by Removing an If

#44

This article is 100% AI written. The data was interesting, the commentary overly verbose and hard to gain useful insights from.

Click on their blog index page, see posts going back to early 2010s and use the same writing style. He must have been time travelling and using AI all this time!

I had a look at their blog page out of curiosity, not that you can prove much from the purported dates and text on a blog, which could be edited at any time.

The blog posts from 2010s are in a completely different style and written by a human: https://www.greyblake.com/blog/vim-preview-plugin/ https://www.greyblake.com/blog/how-to-install-firefox-icewea... https://www.greyblake.com/blog/unexpected-ruby-behaviour/ ...

This new blog post is clearly AI edited (probably 'improved' with AI), the old ones are not.

Re: Branchless Rust: Making a Filter 4x Faster by Removing an If

#45
post #12

This article is 100% AI written. The data was interesting, the commentary overly verbose and hard to gain useful insights from.

idk why this is getting downvoted, I also got this sense, plugged it into Pangram and indeed, 80% AI-written score. I guess that's fine, but after awhile I get a spidey-sense reading something that feels like a Claude session.

A good part of the article feels like it was written by Claude indeed:

- "The reallocations were real, but they were never the bottleneck."

- "Note that the villain is not the branch itself. It is the branch that [..]"

- "Same million floats. Same threshold. Same function."

- "Notice the price we paid though."

Re: Branchless Rust: Making a Filter 4x Faster by Removing an If

#46

Nice post! You can do even a bit better if you're willing to use intrinsics. In particular this kind of operation is well-suited for compress-type operations, available as a first-class operation in at least AVX512, SVE and RVV; you can also emulate them reasonably quickly on NEON and AVX2. Here's an example, building on the OP's work: pub fn filter_compress(input: &[f64], threshold: f64) -> Vec { use std::arch::x86_…

I heard there's a way to arrange code such that the compiler can autobectorize easier. I wonder if there's a way to do that here? Would probably have to pass `-C target-cpu=native` to cargo so that llvm is allowed to use AVX512.

Good question. I personally doubt that the compress instruction is easy to coax compilers into generating, as there are many edge cases to consider.

For example, you'll notice here that we perform a full vector store of 8 elements unconditionally, even if only a few of the elements are active. This is safe, though, because the output buffer is as large as the input buffer, and we're chunking by 8, so we'll never trash memory past the end; but this is a tricky analysis. Performance-wise, we rely on the CPU's store buffer to make these overlapping stores cheap.

Instead, you might think that you could just store the elements which are actually active, using a masked store. In fact there is also an intrinsic for this purpose (_mm512_mask_compressstoreu_pd), but it is extremely slow on some CPUs, namely Zen 4, so it's dangerous to use unless you know exactly what CPU you're using. (In my testing, there also seems to be some weird hazard on Zen 5 where multiple memory-destination compress instructions to nearby, even non-overlapping, addresses are serialized. But I haven't looked closer at this.)

Re: Branchless Rust: Making a Filter 4x Faster by Removing an If

#48
post #25
post #15

Earlier quoted context omitted.

I think the Pentium is more or less the first microprocessor with branch prediction. Certainly the most mainstream. PowerPC 601 arrived at more or less the same time, and the Alpha 21064 was a year earlier. There were a few minicomputers and mainframes before that with branch predictors. Arguably the 486 could have done with a branch predictor (even a single entry loop predictor would have helped), and maybe the 386…

> I get the impression that CPU designers in the 80s and early 90s massively underestimated just how beneficial even a small predictor can be. It's got a lot to do with how cpu clock speeds were getting way faster, but ram wasn't. That's what makes deeper pipelines attractive, and if you give a cpu a deeper pipeline, it's gonna want a good branch predictor.

I'm more thinking about how MIPS were quite late to branch predictors.

They were shipping the high-performance R4000 and R4400 with 8 stage pipelines and no branch predictors.

They could have really done with a branch predictor, each branch took three cycles (and the branch delay slot could fill only one instruction, often a useless NOP).

The Pentium only had a 5 stage pipeline and massively benefited from its branch predictor. IBM was slapping branch predictors on PowerPC designs with 4 stage integer pipelines. You simply don't need a long pipeline to justify the benefits of a branch predictor.

Re: Branchless Rust: Making a Filter 4x Faster by Removing an If

#49

This article is 100% AI written. The data was interesting, the commentary overly verbose and hard to gain useful insights from.

Click on their blog index page, see posts going back to early 2010s and use the same writing style. He must have been time travelling and using AI all this time!

> the same writing style

It's "fake corporate enthusiasm" style. LLMs were just trained in it.

Re: Branchless Rust: Making a Filter 4x Faster by Removing an If

#50
post #6

I've been doing leetcode in Janet in a (sometimes) tacit (variabless), branchless way: (def find-shared-gcd (comp (fn [e] (max ;(map (fn [d] (* d ;(map |(- 1 (min 1 (mod $ d))) e))) (range 1 (+ 1 (min ;e)))))) |((juxt* max min) ;$))) (defn max-diff `where elements increase` [& numbs] (reduce max -1 (filter |( numbs)) (map - numbs (accumulate2 min numbs)))))

[dead]
Post reply on HN