Skip to content

[scudo] Add support for LoongArch hardware CRC32 checksumming #83113

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 additions & 0 deletions compiler-rt/lib/scudo/standalone/checksum.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@
#else
#include <sys/auxv.h>
#endif
#elif defined(__loongarch__)
#include <sys/auxv.h>
#endif

namespace scudo {
Expand Down Expand Up @@ -75,6 +77,20 @@ bool hasHardwareCRC32() {
return !!(getauxval(AT_HWCAP) & HWCAP_CRC32);
#endif // SCUDO_FUCHSIA
}
#elif defined(__loongarch__)
// The definition is only pulled in by <sys/auxv.h> since glibc 2.38, so
// supply it if missing.
#ifndef HWCAP_LOONGARCH_CRC32
#define HWCAP_LOONGARCH_CRC32 (1 << 6)
#endif
// Query HWCAP for platform capability, according to *Software Development and
// Build Convention for LoongArch Architectures* v0.1, Section 9.1.
//
// Link:
// https://github.com/loongson/la-softdev-convention/blob/v0.1/la-softdev-convention.adoc#kernel-development
bool hasHardwareCRC32() {
return !!(getauxval(AT_HWCAP) & HWCAP_LOONGARCH_CRC32);
}
#else
// No hardware CRC32 implemented in Scudo for other architectures.
bool hasHardwareCRC32() { return false; }
Expand Down
4 changes: 4 additions & 0 deletions compiler-rt/lib/scudo/standalone/checksum.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@
#include <arm_acle.h>
#define CRC32_INTRINSIC FIRST_32_SECOND_64(__crc32cw, __crc32cd)
#endif
#ifdef __loongarch__
#include <larchintrin.h>
#define CRC32_INTRINSIC FIRST_32_SECOND_64(__crcc_w_w_w, __crcc_w_d_w)
#endif

namespace scudo {

Expand Down
9 changes: 9 additions & 0 deletions compiler-rt/lib/scudo/standalone/crc32_hw.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,13 @@ u32 computeHardwareCRC32(u32 Crc, uptr Data) {
#endif // defined(__CRC32__) || defined(__SSE4_2__) ||
// defined(__ARM_FEATURE_CRC32)

#if defined(__loongarch__)
u32 computeHardwareCRC32(u32 Crc, uptr Data) {
// The LoongArch CRC intrinsics have the two input arguments swapped, and
// expect them to be signed.
return static_cast<u32>(
CRC32_INTRINSIC(static_cast<long>(Data), static_cast<int>(Crc)));
}
#endif // defined(__loongarch__)

} // namespace scudo