Skip to content

Commit 2162ad6

Browse files
authored
sw: Ensure inline asm output register allocation in FPU fence (#233)
The FPU fence uses a dummy variable to synchronize on the FPU pipeline. This dummy variable is passed to an inline asm block as in/output. In case there are more than one in/output the compiler will allocate the dummy variable to the same register as any other in/output because the unused variable is optimized away. We can ensure a separate register by marking it as volatile.
1 parent 48aebb1 commit 2162ad6

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

sw/snRuntime/src/ssr.h

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,9 @@
3737
* @brief Synchronize the integer and float pipelines.
3838
*/
3939
inline void snrt_fpu_fence() {
40-
unsigned tmp;
40+
// We should use volatile otherwise the compiler can mess things up
41+
// especially if there are multiple asm block output variables.
42+
unsigned volatile tmp;
4143
asm volatile(
4244
"fmv.x.w %0, fa0\n"
4345
"mv %0, %0\n"

0 commit comments

Comments
 (0)