Skip to content
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
17 changes: 17 additions & 0 deletions snmalloc/riscv64.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
diff --git PKGBUILD PKGBUILD
index 22adf65..8c9710f 100644
--- PKGBUILD
+++ PKGBUILD
@@ -46,3 +46,12 @@
DESTDIR="$pkgdir" cmake --install build
install -vDm 644 $pkgname-$pkgver/LICENSE -t "$pkgdir/usr/share/licenses/$pkgname/"
}
+
+source_riscv64=("$pkgname-riscv-rdtime.patch")
+sha512sums_riscv64=('04f5f4e070e94d3ec519e756d5c25b2a8f3c5cd5687895423f09deee5d17cd8bf000d0065181a3100547f41a6a690e8336c9bde1e1a3ada5b4b026bbb22c2c1a')
+b2sums_riscv64=('a27a8fcfe4279cf6e364d9414654861c35f3ec9492e2a1345a48d9ed61359771a43ca36cc2c74eb59e949b3921c889970f2e20c50b1d0189fa2cd84a879bc092')
+
+prepare() {
+ cd "$pkgname-$pkgver"
+ patch -Np1 -i ../$pkgname-riscv-rdtime.patch
+}
43 changes: 43 additions & 0 deletions snmalloc/snmalloc-riscv-rdtime.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
diff --git a/src/snmalloc/aal/aal.h b/src/snmalloc/aal/aal.h
index f0d1207..3ce0703 100644
--- a/src/snmalloc/aal/aal.h
+++ b/src/snmalloc/aal/aal.h
@@ -173,6 +173,7 @@ namespace snmalloc
else
{
#if __has_builtin(__builtin_readcyclecounter) && !defined(__APPLE__) && \
+ !defined(__riscv) && \
!defined(SNMALLOC_NO_AAL_BUILTINS)
return __builtin_readcyclecounter();
#else
diff --git a/src/snmalloc/aal/aal_riscv.h b/src/snmalloc/aal/aal_riscv.h
index 42d510c..b3dba74 100644
--- a/src/snmalloc/aal/aal_riscv.h
+++ b/src/snmalloc/aal/aal_riscv.h
@@ -21,6 +21,26 @@ namespace snmalloc

static constexpr AalName aal_name = RISCV;

+ static inline uint64_t tick() noexcept
+ {
+#if __riscv_xlen == 64
+ uint64_t t;
+ __asm__ volatile("rdtime %0" : "=r"(t));
+ return t;
+#else
+ uint32_t hi;
+ uint32_t hi2;
+ uint32_t lo;
+ do
+ {
+ __asm__ volatile("rdtimeh %0" : "=r"(hi));
+ __asm__ volatile("rdtime %0" : "=r"(lo));
+ __asm__ volatile("rdtimeh %0" : "=r"(hi2));
+ } while (hi != hi2);
+ return (static_cast<uint64_t>(hi) << 32) | lo;
+#endif
+ }
+
static void inline pause()
{
/*