PCRE2Project / pcre2

PCRE2 development is now based here.
Other
922 stars 194 forks source link

jit: Add LoongArch SX 128 bit SIMD Support. #290

Closed lrzlin closed 1 year ago

lrzlin commented 1 year ago

This patch enables SIMD support on LoongArch platform, already tested on real hardware and qemu.

lrzlin commented 1 year ago

@carenas Thanks for your advice! I have not noticed that the sljit has already introduced SIMD support, in that case I'll add support for LoongArch SX in sljit repo for future changes.

carenas commented 1 year ago

@lrzlin do you have an update on at least adding sljit_has_cpu_feature(SLJIT_HAS_SIMD) to sljit so it could be used here to avoid unnecessary crashes with old software?

lrzlin commented 1 year ago

@lrzlin do you have an update on at least adding sljit_has_cpu_feature(SLJIT_HAS_SIMD) to sljit so it could be used here to avoid unnecessary crashes with old software?

Added here, however this change will cause the sljit_test in sljit repo failed (because SLJIT_HAS_SIMD implies SIMD support), should I commit this change now or at the time that I have finished all sljit SIMD functions?

carenas commented 1 year ago

however this change will cause the sljit_test in sljit repo failed

usually to avoid those issues, and while the code is still in development, it is just #ifdef out with the test skipping (see test92 for atomics, which are also not yet used by PCRE).

IMHO and since you already have a working "legacy" SIMD implementation it will be better to get this version out first that way.

eitherway, all sljit changes go first to that repository and they are merged back from there.

lrzlin commented 1 year ago

eitherway, all sljit changes go first to that repository and they are merged back from there.

In that case, I think the best way is putting the LSX detection here, until I have finished all LoongArch sljit SIMD support. Also it would convinent if we need to drop the legacy SIMD support and switch to sljit SIMD implement.

zherczeg commented 1 year ago

I am ok with this code. I cannot maintain it though. So if no more style issues, I can land it. Moving to sljit simd will take a longer time.

lrzlin commented 1 year ago

I am ok with this code. I cannot maintain it though. So if no more style issues, I can land it. Moving to sljit simd will take a longer time.

Thanks for that! I think there is no more style issues. Also I'll maintain the LoongArch SIMD code if there are any issues.

carenas commented 1 year ago

It is missing an autoconf/cmake detection for getauxval() and having the code #ifdef around it; presume that the fallback defaulting to 1 would be ok since all internationally available hardware and the latest release of qemu have LSX support.

lrzlin commented 1 year ago

It is missing an autoconf/cmake detection for getauxval() and having the code #ifdef around it; presume that the fallback defauting to 1 would be ok since all available hardware and the latest release of qemu have LSX support.

@carenas Is the #ifdef __linux__ guard okay? AFAIK, the Linux getauxval syscall and glibc wrapper are available since day one for LoongArch. Also, some embedded LoongArch SOCs (such as Loongson 2K500) do not support LSX extension, so it would be safer to disable LSX if the detection fails.

carenas commented 1 year ago

Interesting, would require changes later if uclibc (or other libc except musl and bionic) are supported by Linux in LoongArch but should be fine for now.

UPDATE: latest uClibc has also getauxval()