diff --git a/README.md b/README.md index b1cbf5c..72c8f2a 100644 --- a/README.md +++ b/README.md @@ -6,7 +6,7 @@ Detect CPU ISA features with single-file
CPU | ✅ x86, x86-64 ✅ arm, aarch64 ✅ mips ✅ powerpc ✅ s390x ✅ loongarch ✅ risc-v | + |
CPU | ✅ x86, x86-64 ✅ arm, aarch64 ✅ mips ✅ powerpc ✅ s390x ✅ loongarch ✅ risc-v ✅ openrisc | ```c #define RUAPU_IMPLEMENTATION @@ -267,6 +267,7 @@ _`fma4` on zen1, ISA in hypervisor, etc._ |s390x|`zvector`| |loongarch|`lsx` `lasx`| |risc-v|`i` `m` `a` `f` `d` `c` `zfa` `zfh` `zfhmin` `zicsr` `zifencei` `zmmul` | +|openrisc| `orbis32` `orbis64` `orfpx32` `orfpx64` `orvdx64` | ## Techniques inside ruapu ruapu is implemented in C language to ensure the widest possible portability. diff --git a/main.c b/main.c index 5363a4d..31ab095 100644 --- a/main.c +++ b/main.c @@ -104,6 +104,13 @@ int main() PRINT_ISA_SUPPORT(zicsr) PRINT_ISA_SUPPORT(zifencei) +#elif __openrisc__ + PRINT_ISA_SUPPORT(orbis32) + PRINT_ISA_SUPPORT(orbis64) + PRINT_ISA_SUPPORT(orfpx32) + PRINT_ISA_SUPPORT(orfpx64) + PRINT_ISA_SUPPORT(orvdx64) + #endif return 0; diff --git a/ruapu.h b/ruapu.h index 59c791b..91e991a 100644 --- a/ruapu.h +++ b/ruapu.h @@ -358,11 +358,31 @@ RUAPU_ISAENTRY(zicsr) RUAPU_ISAENTRY(zifencei) RUAPU_ISAENTRY(zmmul) +#elif __openrisc__ +RUAPU_ISAENTRY(orbis32) +RUAPU_ISAENTRY(orbis64) +RUAPU_ISAENTRY(orfpx32) +RUAPU_ISAENTRY(orfpx64) +RUAPU_ISAENTRY(orvdx64) + #endif }; #undef RUAPU_ISAENTRY +#if defined __openrisc__ +static void ruapu_detect_openrisc_isa() +{ + uint32_t value; + uint16_t addr = U(0x0000); + asm volatile ("l.mfspr %0, r0, %1" : "=r" (value) : "K" (addr)); + for (size_t i = 0; i < sizeof(g_ruapu_isa_map) / sizeof(g_ruapu_isa_map[0]); i++) + { + g_ruapu_isa_map[0].capable = ((value) >> (5 + i)) & 0x1; + } +} +#endif + void ruapu_init() { #if defined _WIN32 || defined __ANDROID__ || defined __linux__ || defined __APPLE__ || defined __FreeBSD__ || defined __NetBSD__ || defined __OpenBSD__ @@ -370,7 +390,9 @@ void ruapu_init() { g_ruapu_isa_map[i].capable = ruapu_detect_isa(g_ruapu_isa_map[i].inst); } -#else +#elif defined __openrisc__ + ruapu_detect_openrisc_isa(); +#else // initialize g_ruapu_isa_map for baremetal here, default all zero // there is still ruapu_some_XYZ() functions available // but you have to work out your own signal handling |