[PATCH] testsuites/unit: Add tests for compiler builtins

2024-04-08 Thread Sebastian Huber
On the arm target, __udivmoddi4() cannot be fully tested through normal
integer divisions.

Update #3716.
---
 testsuites/unit/tc-compiler-builtins.c | 221 +++--
 1 file changed, 207 insertions(+), 14 deletions(-)

diff --git a/testsuites/unit/tc-compiler-builtins.c 
b/testsuites/unit/tc-compiler-builtins.c
index 3beebe06fa..7a470b6632 100644
--- a/testsuites/unit/tc-compiler-builtins.c
+++ b/testsuites/unit/tc-compiler-builtins.c
@@ -130,6 +130,16 @@
 uint64_t __udivmoddi4( uint64_t n, uint64_t d, uint64_t *r );
 #endif
 
+#if defined(TEST_UDIVMODDI4) && defined(__arm__)
+/*
+ * Here __aeabi_uldivmod() may be used to carry out integer division
+ * operations even though the reminder is unused.  This function is
+ * implemented by __udivmoddi4() which may never get called without a
+ * reminder for compiler generated code.
+ */
+#define TEST_UDIVMODDI4_WITHOUT_REMINDER
+#endif
+
 static bool do_longjmp;
 
 static jmp_buf exception_return_context;
@@ -174,6 +184,9 @@ static void CompilerUnitBuiltins_Action_0( void )
 {
   volatile unsigned int n;
 
+  n = 0;
+  RTEMS_OBFUSCATE_VARIABLE( n );
+
   n = 1U;
   T_eq_int( __builtin_clz( n ), 31 );
 
@@ -192,6 +205,9 @@ static void CompilerUnitBuiltins_Action_1( void )
 {
   volatile unsigned long long n;
 
+  n = 0;
+  RTEMS_OBFUSCATE_VARIABLE( n );
+
   n = 1ULL;
   T_eq_int( __builtin_clzll( n ), 63 );
 
@@ -215,6 +231,9 @@ static void CompilerUnitBuiltins_Action_2( void )
 {
   volatile unsigned int n;
 
+  n = 0;
+  RTEMS_OBFUSCATE_VARIABLE( n );
+
   n = 1U;
   T_eq_int( __builtin_ctz( n ), 0 );
 
@@ -233,6 +252,9 @@ static void CompilerUnitBuiltins_Action_3( void )
 {
   volatile unsigned long long n;
 
+  n = 0;
+  RTEMS_OBFUSCATE_VARIABLE( n );
+
   n = 1ULL;
   T_eq_int( __builtin_ctzll( n ), 0 );
 
@@ -256,6 +278,9 @@ static void CompilerUnitBuiltins_Action_4( void )
 {
   volatile unsigned int n;
 
+  n = 0;
+  RTEMS_OBFUSCATE_VARIABLE( n );
+
   n = 1U;
   T_eq_int( __builtin_ffs( n ), 1 );
 
@@ -274,6 +299,9 @@ static void CompilerUnitBuiltins_Action_5( void )
 {
   volatile unsigned long long n;
 
+  n = 0;
+  RTEMS_OBFUSCATE_VARIABLE( n );
+
   n = 1ULL;
   T_eq_int( __builtin_ffsll( n ), 1 );
 
@@ -298,6 +326,9 @@ static void CompilerUnitBuiltins_Action_6( void )
 {
   volatile unsigned int n;
 
+  n = 0;
+  RTEMS_OBFUSCATE_VARIABLE( n );
+
   n = 1U;
   T_eq_int( __builtin_parity( n ), 1 );
 
@@ -313,6 +344,9 @@ static void CompilerUnitBuiltins_Action_7( void )
 {
   volatile unsigned long long n;
 
+  n = 0;
+  RTEMS_OBFUSCATE_VARIABLE( n );
+
   n = 1ULL;
   T_eq_int( __builtin_parityll( n ), 1 );
 
@@ -328,6 +362,9 @@ static void CompilerUnitBuiltins_Action_8( void )
 {
   volatile unsigned int n;
 
+  n = 0;
+  RTEMS_OBFUSCATE_VARIABLE( n );
+
   n = 0U;
   T_eq_int( __builtin_popcount( n ), 0 );
 
@@ -346,6 +383,9 @@ static void CompilerUnitBuiltins_Action_9( void )
 {
   volatile unsigned long long n;
 
+  n = 0;
+  RTEMS_OBFUSCATE_VARIABLE( n );
+
   n = 0ULL;
   T_eq_int( __builtin_popcountll( n ), 0 );
 
@@ -364,6 +404,9 @@ static void CompilerUnitBuiltins_Action_10( void )
 {
   volatile uint32_t n;
 
+  n = 0;
+  RTEMS_OBFUSCATE_VARIABLE( n );
+
   n = UINT32_C( 0 );
   T_eq_u32( __builtin_bswap32( n ), n );
 
@@ -385,6 +428,9 @@ static void CompilerUnitBuiltins_Action_11( void )
 {
   volatile uint64_t n;
 
+  n = 0;
+  RTEMS_OBFUSCATE_VARIABLE( n );
+
   n = UINT64_C( 0 );
   T_eq_u64( __builtin_bswap64( n ), n );
 
@@ -406,6 +452,11 @@ static void CompilerUnitBuiltins_Action_12( void )
   volatile int64_t a;
   volatile int64_t b;
 
+  a = 0;
+  RTEMS_OBFUSCATE_VARIABLE( a );
+  b = 0;
+  RTEMS_OBFUSCATE_VARIABLE( b );
+
   a = INT64_C( 0 );
   b = INT64_C( 0 );
   T_false( a < b );
@@ -431,6 +482,11 @@ static void CompilerUnitBuiltins_Action_13( void )
   volatile uint64_t a;
   volatile uint64_t b;
 
+  a = 0;
+  RTEMS_OBFUSCATE_VARIABLE( a );
+  b = 0;
+  RTEMS_OBFUSCATE_VARIABLE( b );
+
   a = UINT64_C( 0 );
   b = UINT64_C( 0 );
   T_false( a < b );
@@ -456,6 +512,11 @@ static void CompilerUnitBuiltins_Action_14( void )
   volatile int64_t i;
   volatile int s;
 
+  i = 0;
+  RTEMS_OBFUSCATE_VARIABLE( i );
+  s = 0;
+  RTEMS_OBFUSCATE_VARIABLE( s );
+
   i = INT64_C( 1 );
   s = 0;
   T_eq_i64( i << s, INT64_C( 1 ) );
@@ -482,6 +543,11 @@ static void CompilerUnitBuiltins_Action_15( void )
   volatile int64_t i;
   volatile int s;
 
+  i = 0;
+  RTEMS_OBFUSCATE_VARIABLE( i );
+  s = 0;
+  RTEMS_OBFUSCATE_VARIABLE( s );
+
   i = INT64_C( 1 );
   s = 0;
   T_eq_i64( i >> s, INT64_C( 1 ) );
@@ -507,6 +573,11 @@ static void CompilerUnitBuiltins_Action_16( void )
   volatile uint64_t i;
   volatile int s;
 
+  i = 0;
+  RTEMS_OBFUSCATE_VARIABLE( i );
+  s = 0;
+  RTEMS_OBFUSCATE_VARIABLE( s );
+
   i = UINT64_C( 1 );
   s = 0;
   T_eq_u64( i >> s, UINT64_C( 1 ) );
@@ -532,6 +603,11 @@ static void CompilerUnitBuiltins_Action_17( void )
   volatile int64_t a;
   volatile int64_t b;
 
+  a = 0;
+  

Re: [PATCH] testsuites/unit: Add tests for compiler builtins

2023-11-02 Thread Sebastian Huber

On 02.11.23 15:57, Joel Sherrill wrote:

I noted a few cases where I don't think the value used is interesting
enough or an edge case. Hopefully I caught them all.


Thanks for the review, I added some checks.

--
embedded brains GmbH
Herr Sebastian HUBER
Dornierstr. 4
82178 Puchheim
Germany
email: sebastian.hu...@embedded-brains.de
phone: +49-89-18 94 741 - 16
fax:   +49-89-18 94 741 - 08

Registergericht: Amtsgericht München
Registernummer: HRB 157899
Vertretungsberechtigte Geschäftsführer: Peter Rasmussen, Thomas Dörfler
Unsere Datenschutzerklärung finden Sie hier:
https://embedded-brains.de/datenschutzerklaerung/
___
devel mailing list
devel@rtems.org
http://lists.rtems.org/mailman/listinfo/devel

Re: [PATCH] testsuites/unit: Add tests for compiler builtins

2023-11-02 Thread Joel Sherrill
I noted a few cases where I don't think the value used is interesting
enough or an edge case. Hopefully I caught them all.

On Thu, Nov 2, 2023 at 7:12 AM Sebastian Huber <
sebastian.hu...@embedded-brains.de> wrote:

> Test more compiler builtins which may use integer library routins:
>

routines.

>
> https://gcc.gnu.org/onlinedocs/gccint/Integer-library-routines.html
>
> Update #3716.
> ---
>  testsuites/unit/tc-compiler-builtins.c | 377 -
>  1 file changed, 369 insertions(+), 8 deletions(-)
>
> diff --git a/testsuites/unit/tc-compiler-builtins.c
> b/testsuites/unit/tc-compiler-builtins.c
> index 13a9c4a248..4bf8570eb0 100644
> --- a/testsuites/unit/tc-compiler-builtins.c
> +++ b/testsuites/unit/tc-compiler-builtins.c
> @@ -78,6 +78,39 @@
>   *
>   * - Check the return value of __builtin_ctz() for a sample set of inputs.
>   *
> + * - Check the return value of __builtin_ctzll() for a sample set of
> inputs.
> + *
> + * - Check the return value of __builtin_ffs() for a sample set of inputs.
> + *
> + * - Check the return value of __builtin_ffsll() for a sample set of
> inputs.
> + *
> + * - Check the return value of __builtin_parity() for a sample set of
> inputs.
> + *
> + * - Check the return value of __builtin_parityll() for a sample set of
> inputs.
> + *
> + * - Check the return value of __builtin_popcount() for a sample set of
> inputs.
> + *
> + * - Check the return value of __builtin_popcountll() for a sample set of
> + *   inputs.
> + *
> + * - Check the return value of __builtin_bswap32() for a sample set of
> inputs.
> + *
> + * - Check the return value of __builtin_bswap64() for a sample set of
> inputs.
> + *
> + * - Check signed 64-bit comparisons for a sample set of values.
> + *
> + * - Check unsigned 64-bit comparisons for a sample set of values.
> + *
> + * - Check signed 64-bit arithmetic left shift for a sample set of values.
> + *
> + * - Check signed 64-bit arithmetic right shift for a sample set of
> values.
> + *
> + * - Check unsigned 64-bit logical right shift for a sample set of values.
> + *
> + * - Check signed 64-bit multiplication for a sample set of values.
> + *
> + * - Check signed 64-bit negation for a sample set of values.
> + *
>   * - Check signed 64-bit divisions for a sample set of values.
>   *
>   * - Check unsigned 64-bit divisions for a sample set of values.
> @@ -180,22 +213,334 @@ static void CompilerUnitBuiltins_Action_1( void )
>   */
>  static void CompilerUnitBuiltins_Action_2( void )
>  {
> -  volatile int n;
> +  volatile unsigned int n;
>
> -  n = 1;
> +  n = 1U;
>T_eq_int( __builtin_ctz( n ), 0 );
>
> -  n = 1 << 31;
> +  n = 1U << 31;
>T_eq_int( __builtin_ctz( n ), 31 );
>
> -  n = ~0;
> +  n = ~0U;
>T_eq_int( __builtin_ctz( n ), 0 );
>  }
>
>  /**
> - * @brief Check signed 64-bit divisions for a sample set of values.
> + * @brief Check the return value of __builtin_ctzll() for a sample set of
> + *   inputs.
>   */
>  static void CompilerUnitBuiltins_Action_3( void )
> +{
> +  volatile unsigned long long n;
> +
> +  n = 1ULL;
> +  T_eq_int( __builtin_ctzll( n ), 0 );
> +
> +  n = 1ULL << 31;
> +  T_eq_int( __builtin_ctzll( n ), 31 );
> +
> +  n = 1ULL << 32;
> +  T_eq_int( __builtin_ctzll( n ), 32 );
> +
> +  n = 1ULL << 63;
> +  T_eq_int( __builtin_ctzll( n ), 63 );
> +
> +  n = ~0ULL;
> +  T_eq_int( __builtin_ctzll( n ), 0 );
> +}
> +
> +/**
> + * @brief Check the return value of __builtin_ffs() for a sample set of
> inputs.
> + */
> +static void CompilerUnitBuiltins_Action_4( void )
> +{
> +  volatile unsigned int n;
> +
> +  n = 1U;
> +  T_eq_int( __builtin_ffs( n ), 1 );
> +
> +  n = 1U << 31;
> +  T_eq_int( __builtin_ffs( n ), 32 );
> +
> +  n = 0U;
> +  T_eq_int( __builtin_ffs( n ), 0 );
> +}
> +
> +/**
> + * @brief Check the return value of __builtin_ffsll() for a sample set of
> + *   inputs.
> + */
> +static void CompilerUnitBuiltins_Action_5( void )
> +{
> +  volatile unsigned long long n;
> +
> +  n = 1ULL;
> +  T_eq_int( __builtin_ffsll( n ), 1 );
> +
> +  n = 1ULL << 31;
> +  T_eq_int( __builtin_ffsll( n ), 32 );
> +
> +  n = 1ULL << 32;
> +  T_eq_int( __builtin_ffsll( n ), 33 );
> +
> +  n = 1ULL << 63;
> +  T_eq_int( __builtin_ffsll( n ), 64 );
> +
> +  n = 0ULL;
> +  T_eq_int( __builtin_ffsll( n ), 0 );
> +}
> +
> +/**
> + * @brief Check the return value of __builtin_parity() for a sample set of
> + *   inputs.
> + */
> +static void CompilerUnitBuiltins_Action_6( void )
> +{
> +  volatile unsigned int n;
> +
> +  n = 1U;
> +  T_eq_int( __builtin_parity( n ), 1 );
> +
> +  n = ~0U;
> +  T_eq_int( __builtin_parity( n ), 0 );
> +}
> +
> +/**
> + * @brief Check the return value of __builtin_parityll() for a sample set
> of
> + *   inputs.
> + */
> +static void CompilerUnitBuiltins_Action_7( void )
> +{
> +  volatile unsigned long long n;
> +
> +  n = 1ULL;
> +  T_eq_int( __builtin_parityll( n ), 1 );
> +
> +  n = ~0ULL;
> +  T_eq_int( __builtin_parityll( n ), 0 );
> +}
> +
> +/**
> + * @brief Check 

[PATCH] testsuites/unit: Add tests for compiler builtins

2023-11-02 Thread Sebastian Huber
Test more compiler builtins which may use integer library routins:

https://gcc.gnu.org/onlinedocs/gccint/Integer-library-routines.html

Update #3716.
---
 testsuites/unit/tc-compiler-builtins.c | 377 -
 1 file changed, 369 insertions(+), 8 deletions(-)

diff --git a/testsuites/unit/tc-compiler-builtins.c 
b/testsuites/unit/tc-compiler-builtins.c
index 13a9c4a248..4bf8570eb0 100644
--- a/testsuites/unit/tc-compiler-builtins.c
+++ b/testsuites/unit/tc-compiler-builtins.c
@@ -78,6 +78,39 @@
  *
  * - Check the return value of __builtin_ctz() for a sample set of inputs.
  *
+ * - Check the return value of __builtin_ctzll() for a sample set of inputs.
+ *
+ * - Check the return value of __builtin_ffs() for a sample set of inputs.
+ *
+ * - Check the return value of __builtin_ffsll() for a sample set of inputs.
+ *
+ * - Check the return value of __builtin_parity() for a sample set of inputs.
+ *
+ * - Check the return value of __builtin_parityll() for a sample set of inputs.
+ *
+ * - Check the return value of __builtin_popcount() for a sample set of inputs.
+ *
+ * - Check the return value of __builtin_popcountll() for a sample set of
+ *   inputs.
+ *
+ * - Check the return value of __builtin_bswap32() for a sample set of inputs.
+ *
+ * - Check the return value of __builtin_bswap64() for a sample set of inputs.
+ *
+ * - Check signed 64-bit comparisons for a sample set of values.
+ *
+ * - Check unsigned 64-bit comparisons for a sample set of values.
+ *
+ * - Check signed 64-bit arithmetic left shift for a sample set of values.
+ *
+ * - Check signed 64-bit arithmetic right shift for a sample set of values.
+ *
+ * - Check unsigned 64-bit logical right shift for a sample set of values.
+ *
+ * - Check signed 64-bit multiplication for a sample set of values.
+ *
+ * - Check signed 64-bit negation for a sample set of values.
+ *
  * - Check signed 64-bit divisions for a sample set of values.
  *
  * - Check unsigned 64-bit divisions for a sample set of values.
@@ -180,22 +213,334 @@ static void CompilerUnitBuiltins_Action_1( void )
  */
 static void CompilerUnitBuiltins_Action_2( void )
 {
-  volatile int n;
+  volatile unsigned int n;
 
-  n = 1;
+  n = 1U;
   T_eq_int( __builtin_ctz( n ), 0 );
 
-  n = 1 << 31;
+  n = 1U << 31;
   T_eq_int( __builtin_ctz( n ), 31 );
 
-  n = ~0;
+  n = ~0U;
   T_eq_int( __builtin_ctz( n ), 0 );
 }
 
 /**
- * @brief Check signed 64-bit divisions for a sample set of values.
+ * @brief Check the return value of __builtin_ctzll() for a sample set of
+ *   inputs.
  */
 static void CompilerUnitBuiltins_Action_3( void )
+{
+  volatile unsigned long long n;
+
+  n = 1ULL;
+  T_eq_int( __builtin_ctzll( n ), 0 );
+
+  n = 1ULL << 31;
+  T_eq_int( __builtin_ctzll( n ), 31 );
+
+  n = 1ULL << 32;
+  T_eq_int( __builtin_ctzll( n ), 32 );
+
+  n = 1ULL << 63;
+  T_eq_int( __builtin_ctzll( n ), 63 );
+
+  n = ~0ULL;
+  T_eq_int( __builtin_ctzll( n ), 0 );
+}
+
+/**
+ * @brief Check the return value of __builtin_ffs() for a sample set of inputs.
+ */
+static void CompilerUnitBuiltins_Action_4( void )
+{
+  volatile unsigned int n;
+
+  n = 1U;
+  T_eq_int( __builtin_ffs( n ), 1 );
+
+  n = 1U << 31;
+  T_eq_int( __builtin_ffs( n ), 32 );
+
+  n = 0U;
+  T_eq_int( __builtin_ffs( n ), 0 );
+}
+
+/**
+ * @brief Check the return value of __builtin_ffsll() for a sample set of
+ *   inputs.
+ */
+static void CompilerUnitBuiltins_Action_5( void )
+{
+  volatile unsigned long long n;
+
+  n = 1ULL;
+  T_eq_int( __builtin_ffsll( n ), 1 );
+
+  n = 1ULL << 31;
+  T_eq_int( __builtin_ffsll( n ), 32 );
+
+  n = 1ULL << 32;
+  T_eq_int( __builtin_ffsll( n ), 33 );
+
+  n = 1ULL << 63;
+  T_eq_int( __builtin_ffsll( n ), 64 );
+
+  n = 0ULL;
+  T_eq_int( __builtin_ffsll( n ), 0 );
+}
+
+/**
+ * @brief Check the return value of __builtin_parity() for a sample set of
+ *   inputs.
+ */
+static void CompilerUnitBuiltins_Action_6( void )
+{
+  volatile unsigned int n;
+
+  n = 1U;
+  T_eq_int( __builtin_parity( n ), 1 );
+
+  n = ~0U;
+  T_eq_int( __builtin_parity( n ), 0 );
+}
+
+/**
+ * @brief Check the return value of __builtin_parityll() for a sample set of
+ *   inputs.
+ */
+static void CompilerUnitBuiltins_Action_7( void )
+{
+  volatile unsigned long long n;
+
+  n = 1ULL;
+  T_eq_int( __builtin_parityll( n ), 1 );
+
+  n = ~0ULL;
+  T_eq_int( __builtin_parityll( n ), 0 );
+}
+
+/**
+ * @brief Check the return value of __builtin_popcount() for a sample set of
+ *   inputs.
+ */
+static void CompilerUnitBuiltins_Action_8( void )
+{
+  volatile unsigned int n;
+
+  n = 0U;
+  T_eq_int( __builtin_popcount( n ), 0 );
+
+  n = 1U;
+  T_eq_int( __builtin_popcount( n ), 1 );
+
+  n = ~0U;
+  T_eq_int( __builtin_popcount( n ), 32 );
+}
+
+/**
+ * @brief Check the return value of __builtin_popcountll() for a sample set of
+ *   inputs.
+ */
+static void CompilerUnitBuiltins_Action_9( void )
+{
+  volatile unsigned long long n;
+
+  n = 0ULL;
+  T_eq_int( __builtin_popcountll( n ), 0 

[PATCH] testsuites/unit: Add tests for compiler builtins

2023-09-29 Thread Sebastian Huber
---
 .../build/testsuites/unit/unit-no-clock-0.yml |   1 +
 testsuites/unit/tc-compiler-builtins.c| 557 ++
 2 files changed, 558 insertions(+)
 create mode 100644 testsuites/unit/tc-compiler-builtins.c

diff --git a/spec/build/testsuites/unit/unit-no-clock-0.yml 
b/spec/build/testsuites/unit/unit-no-clock-0.yml
index 797e4cbd8a..5d15bf52b7 100644
--- a/spec/build/testsuites/unit/unit-no-clock-0.yml
+++ b/spec/build/testsuites/unit/unit-no-clock-0.yml
@@ -11,6 +11,7 @@ includes: []
 ldflags: []
 links: []
 source:
+- testsuites/unit/tc-compiler-builtins.c
 - testsuites/unit/tc-config.c
 - testsuites/unit/tc-misaligned-builtin-memcpy.c
 - testsuites/unit/tc-score-msgq.c
diff --git a/testsuites/unit/tc-compiler-builtins.c 
b/testsuites/unit/tc-compiler-builtins.c
new file mode 100644
index 00..3b9816264b
--- /dev/null
+++ b/testsuites/unit/tc-compiler-builtins.c
@@ -0,0 +1,557 @@
+/* SPDX-License-Identifier: BSD-2-Clause */
+
+/**
+ * @file
+ *
+ * @ingroup CompilerUnitBuiltins
+ */
+
+/*
+ * Copyright (C) 2023 embedded brains GmbH & Co. KG
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ *notice, this list of conditions and the following disclaimer.
+ * 2. Redistributions in binary form must reproduce the above copyright
+ *notice, this list of conditions and the following disclaimer in the
+ *documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+ * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+ * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+ * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+ * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+ * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+ * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+ * POSSIBILITY OF SUCH DAMAGE.
+ */
+
+/*
+ * This file is part of the RTEMS quality process and was automatically
+ * generated.  If you find something that needs to be fixed or
+ * worded better please post a report or patch to an RTEMS mailing list
+ * or raise a bug report:
+ *
+ * https://www.rtems.org/bugs.html
+ *
+ * For information on updating and regenerating please refer to the How-To
+ * section in the Software Requirements Engineering chapter of the
+ * RTEMS Software Engineering manual.  The manual is provided as a part of
+ * a release.  For development sources please refer to the online
+ * documentation at:
+ *
+ * https://docs.rtems.org
+ */
+
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
+#include 
+#include 
+
+#include "tx-support.h"
+
+#include 
+
+/**
+ * @defgroup CompilerUnitBuiltins spec:/compiler/unit/builtins
+ *
+ * @ingroup TestsuitesUnitNoClock0
+ *
+ * @brief These unit tests check compiler builtins.
+ *
+ * This test case performs the following actions:
+ *
+ * - Check the return value of __builtin_clz() for a sample set of inputs.
+ *
+ * - Check the return value of __builtin_clzll() for a sample set of inputs.
+ *
+ * - Check the return value of __builtin_ctz() for a sample set of inputs.
+ *
+ * - Check signed 64-bit divisions for a sample set of values.
+ *
+ * - Check unsigned 64-bit divisions for a sample set of values.
+ *
+ * - Check signed 64-bit modulo operations for a sample set of values.
+ *
+ * - Check unsigned 64-bit modulo operations for a sample set of values.
+ *
+ * @{
+ */
+
+#if __LONG_MAX__ == 0x7fffL
+uint64_t __udivmoddi4( uint64_t n, uint64_t d, uint64_t *r );
+#endif
+
+static bool do_longjmp;
+
+static jmp_buf exception_return_context;
+
+static void Fatal(
+  rtems_fatal_source source,
+  rtems_fatal_code   code,
+  void  *arg
+)
+{
+  (void) code;
+
+  if ( source == RTEMS_FATAL_SOURCE_EXCEPTION && do_longjmp ) {
+do_longjmp = false;
+_ISR_Set_level( 0 );
+longjmp( arg, 1 );
+  }
+}
+
+static void CompilerUnitBuiltins_Setup( void *ctx )
+{
+  SetFatalHandler( Fatal, exception_return_context );
+}
+
+static void CompilerUnitBuiltins_Teardown( void *ctx )
+{
+  SetFatalHandler( NULL, NULL );
+}
+
+static T_fixture CompilerUnitBuiltins_Fixture = {
+  .setup = CompilerUnitBuiltins_Setup,
+  .stop = NULL,
+  .teardown = CompilerUnitBuiltins_Teardown,
+  .scope = NULL,
+  .initial_context = NULL
+};
+
+/**
+ * @brief Check the return value of __builtin_clz() for a sample set of inputs.
+ */
+static void CompilerUnitBuiltins_Action_0( void )
+{
+  volatile unsigned int n;
+
+  n =