From 99c4b245d0e056aac239eb99d15fce6a4d3bf959 Mon Sep 17 00:00:00 2001
From: Alberto Nidasio <nidasioalberto@gmail.com>
Date: Mon, 1 Jul 2024 14:38:21 +0200
Subject: [PATCH] When compiling `ll2timespec` function with clang, we fallback
 to the non-optimized implementation

The problem is that Clang does not support assigning specific registers to variables.
This commit is a quick fix to solve this problem while adding support for Clang
---
 miosix/stdlib_integration/libc_integration.h | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/miosix/stdlib_integration/libc_integration.h b/miosix/stdlib_integration/libc_integration.h
index 8e60d294..117cc7e2 100644
--- a/miosix/stdlib_integration/libc_integration.h
+++ b/miosix/stdlib_integration/libc_integration.h
@@ -78,7 +78,7 @@ inline long long timespec2ll(const struct timespec *tp)
  */
 inline void ll2timespec(long long ns, struct timespec *tp)
 {
-    #ifdef __ARM_EABI__
+    #if defined(__ARM_EABI__) && defined(__GNUC__) && !defined(__clang__)
     // Despite there being a single intrinsic, __aeabi_ldivmod, that computes
     // both the result of the / and % operator, GCC 9.2.0 isn't smart enough and
     // calls the intrinsic twice. This asm implementation takes ~188 cycles
@@ -91,11 +91,11 @@ inline void ll2timespec(long long ns, struct timespec *tp)
     asm volatile("bl	__aeabi_ldivmod" : "+r"(a), "+r"(b) :: "lr");
     tp->tv_sec = a;
     tp->tv_nsec = static_cast<long>(b);
-    #else //__ARM_EABI__
+    #else
     #warning Warning POSIX time API not optimized for this platform
     tp->tv_sec = ns / nsPerSec;
     tp->tv_nsec = static_cast<long>(ns % nsPerSec);
-    #endif //__ARM_EABI__
+    #endif
 }
 
 } //namespace miosix
-- 
GitLab