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