guzba / nimsimd

Pleasant Nim bindings for SIMD instruction sets.
MIT License
73 stars 7 forks source link

Update neon.nim #24

Closed siriuslee69 closed 4 months ago

siriuslee69 commented 4 months ago

Added importc statements and some comments. Also added xor functions aka veorq statements for unsigned 128 bit registers.

Most of this was done with ChatGPT.

siriuslee69 commented 4 months ago

I was wondering if the importc pragmas were just forgotten or not necessary? I haven't really written any bindings yet so I was a bit confused since the importc pragmas were present in the AVX instruction sets.

Guzba, you wrote that there is a lot of versioning etc. to get into. Could you tell me why exactly and what problems one could encounter when using neon instructions without checking the respective compilers etc.? Are some compilers using different function names for their Neon instructions?

guzba commented 4 months ago

Adding more bindings is welcome.

The imporc is not necessary if the proc name matches the C name, which is always done in these bindings. Adding a redundant importc just adds another string that can contain typos.

The intrinsics names come from ARM https://developer.arm.com/architectures/instruction-sets/intrinsics/#f:@navigationhierarchiessimdisa=[Neon]&f:@navigationhierarchiesinstructiongroup=[Load,Stride] and I've not had issues with compilers not using those names.

If the compiler does not recognize a name it will fail with an error and there's not usually much that can be done. But if the intrinsic is not misnamed there are not issues unless one targets an older ARM version that does not have that instruction.

I keep it very simple: exact match the name to the ARM docs, match the parameter types, and compilers have not presented problems. Pretty straightforward but tedious process.

guzba commented 4 months ago

To add, the x64 intrinsics only include the importc due to the leading _ in the name not being valid in Nim.

siriuslee69 commented 4 months ago

Thanks for the fast response! Thank you for the explanation. I will delete the importc statements tomorrow and try to automate the bindings-writing with local AI models. Maybe the SVE instructions can be written that way as well, as they are completely missing afaik.

guzba commented 4 months ago

Thanks for the PR. This is tagged in release 1.2.10