Skip to content

Commit b7815b3

Browse files
committed
[scudo] Add support for LoongArch hardware CRC32 checksumming
The support is available for processors implementing the LoongArch64 subset, but one still has to probe for platform capability prior to use, according to LoongArch documentation.
1 parent 575bf33 commit b7815b3

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

compiler-rt/lib/scudo/standalone/checksum.cpp

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
#else
2020
#include <sys/auxv.h>
2121
#endif
22+
#elif defined(__loongarch_lp64)
23+
#include <sys/auxv.h>
2224
#endif
2325

2426
namespace scudo {
@@ -75,6 +77,15 @@ bool hasHardwareCRC32() {
7577
return !!(getauxval(AT_HWCAP) & HWCAP_CRC32);
7678
#endif // SCUDO_FUCHSIA
7779
}
80+
#elif defined(__loongarch_lp64)
81+
// Query HWCAP for platform capability, according to *Software Development and
82+
// Build Convention for LoongArch Architectures* v0.1, Section 9.1.
83+
//
84+
// Link:
85+
// https://github.com/loongson/la-softdev-convention/blob/v0.1/la-softdev-convention.adoc#kernel-development
86+
bool hasHardwareCRC32() {
87+
return !!(getauxval(AT_HWCAP) & HWCAP_LOONGARCH_CRC32);
88+
}
7889
#else
7990
// No hardware CRC32 implemented in Scudo for other architectures.
8091
bool hasHardwareCRC32() { return false; }

compiler-rt/lib/scudo/standalone/checksum.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,10 @@
3030
#include <arm_acle.h>
3131
#define CRC32_INTRINSIC FIRST_32_SECOND_64(__crc32cw, __crc32cd)
3232
#endif
33+
#ifdef __loongarch_lp64
34+
#include <larchintrin.h>
35+
#define CRC32_INTRINSIC FIRST_32_SECOND_64(__crcc_w_w_w, __crcc_w_d_w)
36+
#endif
3337

3438
namespace scudo {
3539

compiler-rt/lib/scudo/standalone/crc32_hw.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,4 +17,11 @@ u32 computeHardwareCRC32(u32 Crc, uptr Data) {
1717
#endif // defined(__CRC32__) || defined(__SSE4_2__) ||
1818
// defined(__ARM_FEATURE_CRC32)
1919

20+
#if defined(__loongarch_lp64)
21+
u32 computeHardwareCRC32(u32 Crc, uptr Data) {
22+
// The LoongArch CRC intrinsics have the two input arguments swapped.
23+
return static_cast<u32>(CRC32_INTRINSIC(Data, Crc));
24+
}
25+
#endif // defined(__loongarch_lp64)
26+
2027
} // namespace scudo

0 commit comments

Comments
 (0)