Index: src/OFSystemInfo.h ================================================================== --- src/OFSystemInfo.h +++ src/OFSystemInfo.h @@ -92,10 +92,14 @@ @property (class, readonly, nonatomic) bool supportsAVX512BFloat16Instructions; # endif # if defined(OF_POWERPC) || defined(OF_POWERPC64) || defined(DOXYGEN) @property (class, readonly, nonatomic) bool supportsAltiVec; # endif +# if defined(OF_LOONGARCH64) || defined(DOXYGEN) +@property (class, readonly, nonatomic) bool supportsLSX; +@property (class, readonly, nonatomic) bool supportsLASX; +# endif # if defined(OF_WINDOWS) || defined(DOXYGEN) @property (class, readonly, nonatomic, getter=isWindowsNT) bool windowsNT; # endif #endif @@ -528,10 +532,30 @@ * * @return Whether the CPU and OS support AltiVec */ + (bool)supportsAltiVec; #endif + +#if defined(OF_LOONGARCH64) || defined(DOXYGEN) +/** + * @brief Returns whether the CPU and OS support LSX. + * + * @note This method is only available on LoongArch 64! + * + * @return Whether the CPU and OS support LSX + */ ++ (bool)supportsLSX; + +/** + * @brief Returns whether the CPU and OS support LASX. + * + * @note This method is only available on LoongArch 64! + * + * @return Whether the CPU and OS support LASX + */ ++ (bool)supportsLASX; +#endif #if defined(OF_WINDOWS) || defined(DOXYGEN) /** * @brief Returns whether the application is running on Windows NT. * Index: src/OFSystemInfo.m ================================================================== --- src/OFSystemInfo.m +++ src/OFSystemInfo.m @@ -376,10 +376,26 @@ ); return regs; } #endif + +#ifdef OF_LOONGARCH64 +static uint32_t +cpucfg(uint32_t word) +{ + uint32_t ret; + + __asm__ ( + "cpucfg %0, %1" + : "=r" (ret) + : "r" (word) + ); + + return ret; +} +#endif @implementation OFSystemInfo + (void)initialize { long tmp; @@ -1025,10 +1041,22 @@ # endif return false; } #endif + +#ifdef OF_LOONGARCH64 ++ (bool)supportsLSX +{ + return cpucfg(2) & (1 << 6); +} + ++ (bool)supportsLASX +{ + return cpucfg(2) & (1 << 7); +} +#endif #ifdef OF_WINDOWS + (bool)isWindowsNT { return !(GetVersion() & 0x80000000); Index: tests/OFSystemInfoTests.m ================================================================== --- tests/OFSystemInfoTests.m +++ tests/OFSystemInfoTests.m @@ -133,10 +133,15 @@ #endif #ifdef OF_POWERPC ADD_BOOL(@"Supports AltiVec", [OFSystemInfo supportsAltiVec]); #endif + +#ifdef OF_LOONGARCH64 + ADD_BOOL(@"Supports LSX", [OFSystemInfo supportsLSX]); + ADD_BOOL(@"Supports LASX", [OFSystemInfo supportsLASX]); +#endif #undef ADD #undef ADD_UINT #undef ADD_ULONGLONG #undef ADD_BOOL