Hacker News new | ask | show | jobs
by eachro 712 days ago
This is cool that simd primitives exist in the std lib of rust. I've wanted wanted to mess around a bit more with simd in python but I don't think that native support exists. Or your have to go down to C/C++ bindings to actually mess around with it (last I checked at least, please correct me if I'm wrong).
3 comments

I feel like most languages could use simd in the standard library. We have all this power in the vector units of our CPUs that compilers struggle to use but yet we also don't make it easy to do manually
C# is the language that is doing this exact thing, with the next two close options being Swift and, from my understanding, Mojo.

Without easy to use SIMD abstraction, many* of .NET's CoreLib functions would have been significantly slower.

* UTF-8 validation, text encoding/decoding, conversion to/from hex bytes, copying data, zeroing, various checksum and hash functions, text/element counting, searching, advanced text search with multiple algorithms under SearchValues type used by Regex engine, etc.

D as well.
Quick search turned up this:

SIMD in Pure Python

https://www.da.vidbuchanan.co.uk/blog/python-swar.html

Don't let the "SIMD in Python" section fool you, it's a short stop on Numpy before putting it aside.

What would native SIMD support entail in a language without first party JIT or AOT compilation?
At some point bytecode still turns into CPU instructions, so if you added syntax or special functions that went to parts of the interpreter that are SIMD you could certainly add it to a purely interpreted language.
If we're talking low level SIMD, like opcode level, I'm really struggling to see the use case for interpreted bytecode. The cost of type checking operands to dynamically dispatch down a SIMD path would almost certainly outweigh the savings of the SIMD path itself.

JIT is different because in function-level JIT, you can check types just once at the opening of the function, then you stay on the SIMD happy path for the rest of the function. And in AOT, you may able to elide the checks entirely.

There is certainly a space for higher level SIMD functionality. Numpy is one example.