Hacker Newsnew | past | comments | ask | show | jobs | submit | EmberTwin's commentslogin

The SWAR (SIMD-within-a-register) numbers are strictly better than the SIMD versions as well as the standard library baseline. Why is that? SIMD should be strictly faster if the machine supports it, since the SWAR max bitwidth is 64, while SIMD starts at 128 bits.

The Java SIMD API used here must not result in using actual SIMD machine code.


Author here!

Thanks for the great point. This is actually the main topic I'm working on for the next post.

It's understandable to expect SIMD to win purely because it's wider, but in practice the end-to-end cost matters more than raw VL.

With the Java Vector API, the equality compare can indeed be compiled down to real SIMD instructions, yet the overall path may still lose if turning a VectorMask into a scalar bitmask is expensive. The "best case" is a vector compare followed by a single instruction that packs the result into a bitmask; if the JIT doesn't hit that lowering, it can fall back to extra work such as materializing the mask and repacking it in scalar code. From what I can tell, they have been working on intrinsic for VectorMask.toLong (https://bugs.openjdk.org/browse/JDK-8273949).

Also, SWAR avoids that entire transition by staying in GPR and producing the bitmask directly with a small, predictable sequence of bit operations. For small fixed-size probes, that simplicity often outweighs SIMD's theoretical advantage, and on some CPUs heavier vector usage can even come with frequency effects that further narrow the gap. So, I guess the more likely explanation isn't that the Vector API never uses SIMD.

I'll take a closer look at how it compiles down to machine code and share what I find.

P.S. Benchmark results can vary a lot depending on the environment (OS, CPU and JDK/JIT version and flags), so it’s also possible the benchmark picture changes on a different setup.


ChatGPT is not de-obfuscating this code. For one thing:

> basic cellular automaton algorithm

is completely wrong. A cellular automaton is a standard approach to level-generation in a roguelike, but this code implements a different approach, the rooms-and-corridors one.

Another issue here is that ChatGPT is using a few key context clues to make its (incorrect but plausible) guess. Robert Nystrom, aka munificient, is well-known in the roguelikedev community for his game programming tutorials. I confirmed that ChatGPT knows who he is by asking "Who is @munificentbob and what is he known for?" The name of the function, "cave", that carves rooms makes it clear that this is some kind of level-generation algorithm - in fact, that's probably where the incorrect guess about cellular automata came from, because those algorithms are often used for "caves" (versus "dungeons" made with rooms-and-corridors). The characters printed are also roguelike standards.

If I remove @munificient's name and rename "cave" to "X", ChatGPT's output is worse. It says: "This code is a compact implementation of a simple game where characters move around a grid.", which is...vaguely in the ballpark.


HHVM is not a drop-in replacement for a PHP interpreter. The semantics of Hack and PHP have diverged, typically in the direction of eliminating dynamic behavior from Hack that existed in PHP (examples: string -> function coercion, the PHP dual vector-hash-table array type, and non-throwing out-of-bounds array accesses are all gone from Hack). The semantics changes both simplify static analysis and make it easier to JIT fast code.


Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: