From ffd2eb5b147496afa6e0b76cc81c8e58b91038ae Mon Sep 17 00:00:00 2001 From: zhangyuan21 Date: Thu, 8 Dec 2022 19:43:18 +0800 Subject: [PATCH] arch/arm: only compare callee-saved registers for fpu Registers S0-S15 (D0-D7, Q0-Q3) do not need to be preserved. They can be used for passing arguments or returning results in standard procedure-call variants. Registers D16-D31 (Q8-Q15), do not need to be preserved. Signed-off-by: zhangyuan21 --- arch/arm/src/armv7-a/arm_fpucmp.c | 8 +++++++- arch/arm/src/armv7-m/arm_fpucmp.c | 8 +++++--- arch/arm/src/armv7-r/arm_fpucmp.c | 8 +++++++- arch/arm/src/armv8-m/arm_fpucmp.c | 8 +++++--- arch/arm64/src/common/arm64_fpu.c | 13 ++++++++++++- 5 files changed, 36 insertions(+), 9 deletions(-) diff --git a/arch/arm/src/armv7-a/arm_fpucmp.c b/arch/arm/src/armv7-a/arm_fpucmp.c index 00ee4ccafe..914818d536 100644 --- a/arch/arm/src/armv7-a/arm_fpucmp.c +++ b/arch/arm/src/armv7-a/arm_fpucmp.c @@ -36,6 +36,8 @@ #ifdef CONFIG_ARCH_FPU +# define FPU_CALLEE_REGS (16) + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -60,6 +62,10 @@ bool up_fpucmp(const void *saveregs1, const void *saveregs2) const uint32_t *regs1 = saveregs1; const uint32_t *regs2 = saveregs2; - return memcmp(®s1[REG_S0], ®s2[REG_S0], 4 * FPU_CONTEXT_REGS) == 0; + /* Only compare callee-saved registers, caller-saved registers do not + * need to be preserved. + */ + + return memcmp(®s1[REG_S16], ®s2[REG_S16], 4 * FPU_CALLEE_REGS) == 0; } #endif /* CONFIG_ARCH_FPU */ diff --git a/arch/arm/src/armv7-m/arm_fpucmp.c b/arch/arm/src/armv7-m/arm_fpucmp.c index dfed405645..4db5c35256 100644 --- a/arch/arm/src/armv7-m/arm_fpucmp.c +++ b/arch/arm/src/armv7-m/arm_fpucmp.c @@ -60,10 +60,12 @@ bool up_fpucmp(const void *saveregs1, const void *saveregs2) const uint32_t *regs1 = saveregs1; const uint32_t *regs2 = saveregs2; + /* Only compare callee-saved registers, caller-saved registers do not + * need to be preserved. + */ + /* compare of hardware fp registers should skip REG_FP_RESERVED */ - return memcmp(®s1[REG_S0], ®s2[REG_S0], - 4 * (HW_FPU_REGS - 1)) == 0 && - memcmp(®s1[REG_S16], ®s2[REG_S16], 4 * SW_FPU_REGS) == 0; + return memcmp(®s1[REG_S16], ®s2[REG_S16], 4 * SW_FPU_REGS) == 0; } #endif /* CONFIG_ARCH_FPU */ diff --git a/arch/arm/src/armv7-r/arm_fpucmp.c b/arch/arm/src/armv7-r/arm_fpucmp.c index bcc6ecb203..abc617d198 100644 --- a/arch/arm/src/armv7-r/arm_fpucmp.c +++ b/arch/arm/src/armv7-r/arm_fpucmp.c @@ -36,6 +36,8 @@ #ifdef CONFIG_ARCH_FPU +# define FPU_CALLEE_REGS (16) + /**************************************************************************** * Public Functions ****************************************************************************/ @@ -60,6 +62,10 @@ bool up_fpucmp(const void *saveregs1, const void *saveregs2) const uint32_t *regs1 = saveregs1; const uint32_t *regs2 = saveregs2; - return memcmp(®s1[REG_S0], ®s2[REG_S0], 4 * FPU_CONTEXT_REGS) == 0; + /* Only compare callee-saved registers, caller-saved registers do not + * need to be preserved. + */ + + return memcmp(®s1[REG_S16], ®s2[REG_S16], 4 * FPU_CALLEE_REGS) == 0; } #endif /* CONFIG_ARCH_FPU */ diff --git a/arch/arm/src/armv8-m/arm_fpucmp.c b/arch/arm/src/armv8-m/arm_fpucmp.c index 4c5e3bb2d3..1cbebe680a 100644 --- a/arch/arm/src/armv8-m/arm_fpucmp.c +++ b/arch/arm/src/armv8-m/arm_fpucmp.c @@ -60,10 +60,12 @@ bool up_fpucmp(const void *saveregs1, const void *saveregs2) const uint32_t *regs1 = saveregs1; const uint32_t *regs2 = saveregs2; + /* Only compare callee-saved registers, caller-saved registers do not + * need to be preserved. + */ + /* compare of hardware fp registers should skip REG_FP_RESERVED */ - return memcmp(®s1[REG_S0], ®s2[REG_S0], - 4 * (HW_FPU_REGS - 1)) == 0 && - memcmp(®s1[REG_S16], ®s2[REG_S16], 4 * SW_FPU_REGS) == 0; + return memcmp(®s1[REG_S16], ®s2[REG_S16], 4 * SW_FPU_REGS) == 0; } #endif /* CONFIG_ARCH_FPU */ diff --git a/arch/arm64/src/common/arm64_fpu.c b/arch/arm64/src/common/arm64_fpu.c index 9e6a43f5a1..88c28ff831 100644 --- a/arch/arm64/src/common/arm64_fpu.c +++ b/arch/arm64/src/common/arm64_fpu.c @@ -41,6 +41,12 @@ #include "arm64_fatal.h" #include "arm64_fpu.h" +/*************************************************************************** + * Pre-processor Definitions + ***************************************************************************/ + +#define FPU_CALLEE_REGS (8) + /*************************************************************************** * Private Data ***************************************************************************/ @@ -245,5 +251,10 @@ bool up_fpucmp(const void *saveregs1, const void *saveregs2) const uint64_t *regs1 = saveregs1 + XCPTCONTEXT_GP_SIZE; const uint64_t *regs2 = saveregs2 + XCPTCONTEXT_GP_SIZE; - return memcmp(regs1, regs2, 8 * XCPTCONTEXT_FPU_REGS) == 0; + /* Only compare callee-saved registers, caller-saved registers do not + * need to be preserved. + */ + + return memcmp(®s1[FPU_REG_Q4], ®s2[FPU_REG_Q4], + 8 * FPU_CALLEE_REGS) == 0; }