-
Notifications
You must be signed in to change notification settings - Fork 58
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
41 additions
and
4 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
sw/deps/patches/musl/0005-math-Add-safe-asuint64-function.patch
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
From f468669a93f85ac490418217213e4aa211b51e31 Mon Sep 17 00:00:00 2001 | ||
From: Luca Colagrande <[email protected]> | ||
Date: Thu, 16 Nov 2023 10:07:46 +0100 | ||
Subject: [PATCH] math: Add safe `asuint64` function | ||
|
||
--- | ||
src/internal/libm.h | 11 +++++++---- | ||
1 file changed, 7 insertions(+), 4 deletions(-) | ||
|
||
diff --git a/src/internal/libm.h b/src/internal/libm.h | ||
index c96c0ece..5bcad979 100644 | ||
--- a/src/internal/libm.h | ||
+++ b/src/internal/libm.h | ||
@@ -138,10 +138,13 @@ inline void snrt_fpu_fence() { | ||
|
||
/* Synch-secure double to uint64 conversion functions. */ | ||
static inline uint64_t asuint64(double f) { | ||
- uint64_t result; | ||
- snrt_fpu_fence(); | ||
- result = *(uint64_t *)&f; | ||
- return result; | ||
+ uint64_t *ptr; | ||
+ asm volatile("fsd %[f], 0(%[ptr]) \n" | ||
+ "fld ft3, 0(%[ptr]) \n" | ||
+ "fmv.x.w t0, ft3 \n" | ||
+ "mv t0, t0 \n" | ||
+ : : [f]"f"(f), [ptr]"r"(ptr): "ft3", "t0", "memory"); | ||
+ return *result; | ||
} | ||
|
||
/* Synch-secure float to uint conversion functions. */ | ||
-- | ||
2.31.1 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters