From 4489c8dcefb764ecee779d838fc4eb9850a7a5fb Mon Sep 17 00:00:00 2001 From: Dave Rodgman Date: Wed, 24 May 2023 12:06:48 +0100 Subject: [PATCH] Disable bignum assembly for certain Arm M-class CPUs Signed-off-by: Dave Rodgman --- library/bn_mul.h | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/library/bn_mul.h b/library/bn_mul.h index ab59fbd64..c5124702b 100644 --- a/library/bn_mul.h +++ b/library/bn_mul.h @@ -673,6 +673,22 @@ #define MULADDC_CANNOT_USE_R7 #endif +/* + * Similarly, we need to disable the assembly below if: + * - compiler is armclang + * - optimisation is not -O0 + * - target is Thumb + * - target cpu is one of cortex-m0, cortex-m0plus, cortex-m1, cortex-m23, sc000 + * + * Checking for __ARM_ARCH_6M__ or __ARM_ARCH_8M_BASE__ seems to identify exactly these + * cpus and no others (tested against all values for -mcpu known to armclang 6.20). + */ +#if defined(__ARMCC_VERSION) && defined(__OPTIMIZE__) && defined(__thumb__) +#if defined(__ARM_ARCH_8M_BASE__) || defined(__ARM_ARCH_6M__) +#define MULADDC_CANNOT_USE_R7 +#endif +#endif + #if defined(__arm__) && !defined(MULADDC_CANNOT_USE_R7) #if defined(__thumb__) && !defined(__thumb2__)