From 51580bb846e23e742f861b843f6363c705b500d2 Mon Sep 17 00:00:00 2001 From: apio Date: Sun, 23 Oct 2022 11:10:26 +0200 Subject: [PATCH] libc: Add abs(), labs() and llabs() Just needed to alias them to GCC builtins. --- libs/libc/include/stdlib.h | 9 +++++++++ libs/libc/src/stdlib.cpp | 15 +++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/libs/libc/include/stdlib.h b/libs/libc/include/stdlib.h index cb49672d..25bab5b1 100644 --- a/libs/libc/include/stdlib.h +++ b/libs/libc/include/stdlib.h @@ -65,6 +65,15 @@ extern "C" /* Seeds the random number generator with the specified seed. */ void srand(unsigned int seed); + /* Returns the absolute value of an integer. */ + int abs(int val); + + /* Returns the absolute value of an integer. */ + long labs(long val); + + /* Returns the absolute value of an integer. */ + long long llabs(long long val); + #ifdef __cplusplus } #endif diff --git a/libs/libc/src/stdlib.cpp b/libs/libc/src/stdlib.cpp index 9bb532cc..addc8fd9 100644 --- a/libs/libc/src/stdlib.cpp +++ b/libs/libc/src/stdlib.cpp @@ -63,4 +63,19 @@ extern "C" syscall(SYS_exit, status); __lc_unreachable(); } + + int abs(int val) + { + return __builtin_abs(val); + } + + long labs(long val) + { + return __builtin_labs(val); + } + + long long llabs(long long val) + { + return __builtin_llabs(val); + } } \ No newline at end of file