[rtems-central commit] spec: Add tests for compiler builtins

Sebastian Huber sebh at rtems.org
Wed Apr 17 09:27:23 UTC 2024


Module:    rtems-central
Branch:    master
Commit:    aaa2491a617132dd193247e3a83a8978fe702f83
Changeset: http://git.rtems.org/rtems-central/commit/?id=aaa2491a617132dd193247e3a83a8978fe702f83

Author:    Sebastian Huber <sebastian.huber at embedded-brains.de>
Date:      Wed Mar 20 11:37:37 2024 +0100

spec: Add tests for compiler builtins

On the arm target, __udivmoddi4() cannot be fully tested through normal
integer divisions.

Update #3716.

---

 spec/compiler/unit/builtins.yml | 221 +++++++++++++++++++++++++++++++++++++---
 1 file changed, 207 insertions(+), 14 deletions(-)

diff --git a/spec/compiler/unit/builtins.yml b/spec/compiler/unit/builtins.yml
index cad01f41..a1dbe9b0 100644
--- a/spec/compiler/unit/builtins.yml
+++ b/spec/compiler/unit/builtins.yml
@@ -11,6 +11,9 @@ test-actions:
   action-code: |
     volatile unsigned int n;
 
+    n = 0;
+    RTEMS_OBFUSCATE_VARIABLE( n );
+
     n = 1U;
     T_eq_int( __builtin_clz( n ), 31 );
 
@@ -29,6 +32,9 @@ test-actions:
   action-code: |
     volatile unsigned long long n;
 
+    n = 0;
+    RTEMS_OBFUSCATE_VARIABLE( n );
+
     n = 1ULL;
     T_eq_int( __builtin_clzll( n ), 63 );
 
@@ -53,6 +59,9 @@ test-actions:
   action-code: |
     volatile unsigned int n;
 
+    n = 0;
+    RTEMS_OBFUSCATE_VARIABLE( n );
+
     n = 1U;
     T_eq_int( __builtin_ctz( n ), 0 );
 
@@ -71,6 +80,9 @@ test-actions:
   action-code: |
     volatile unsigned long long n;
 
+    n = 0;
+    RTEMS_OBFUSCATE_VARIABLE( n );
+
     n = 1ULL;
     T_eq_int( __builtin_ctzll( n ), 0 );
 
@@ -95,6 +107,9 @@ test-actions:
   action-code: |
     volatile unsigned int n;
 
+    n = 0;
+    RTEMS_OBFUSCATE_VARIABLE( n );
+
     n = 1U;
     T_eq_int( __builtin_ffs( n ), 1 );
 
@@ -113,6 +128,9 @@ test-actions:
   action-code: |
     volatile unsigned long long n;
 
+    n = 0;
+    RTEMS_OBFUSCATE_VARIABLE( n );
+
     n = 1ULL;
     T_eq_int( __builtin_ffsll( n ), 1 );
 
@@ -137,6 +155,9 @@ test-actions:
   action-code: |
     volatile unsigned int n;
 
+    n = 0;
+    RTEMS_OBFUSCATE_VARIABLE( n );
+
     n = 1U;
     T_eq_int( __builtin_parity( n ), 1 );
 
@@ -152,6 +173,9 @@ test-actions:
   action-code: |
     volatile unsigned long long n;
 
+    n = 0;
+    RTEMS_OBFUSCATE_VARIABLE( n );
+
     n = 1ULL;
     T_eq_int( __builtin_parityll( n ), 1 );
 
@@ -167,6 +191,9 @@ test-actions:
   action-code: |
     volatile unsigned int n;
 
+    n = 0;
+    RTEMS_OBFUSCATE_VARIABLE( n );
+
     n = 0U;
     T_eq_int( __builtin_popcount( n ), 0 );
 
@@ -185,6 +212,9 @@ test-actions:
   action-code: |
     volatile unsigned long long n;
 
+    n = 0;
+    RTEMS_OBFUSCATE_VARIABLE( n );
+
     n = 0ULL;
     T_eq_int( __builtin_popcountll( n ), 0 );
 
@@ -203,6 +233,9 @@ test-actions:
   action-code: |
     volatile uint32_t n;
 
+    n = 0;
+    RTEMS_OBFUSCATE_VARIABLE( n );
+
     n = UINT32_C( 0 );
     T_eq_u32( __builtin_bswap32( n ), n );
 
@@ -224,6 +257,9 @@ test-actions:
   action-code: |
     volatile uint64_t n;
 
+    n = 0;
+    RTEMS_OBFUSCATE_VARIABLE( n );
+
     n = UINT64_C( 0 );
     T_eq_u64( __builtin_bswap64( n ), n );
 
@@ -246,6 +282,11 @@ test-actions:
     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 );
@@ -272,6 +313,11 @@ test-actions:
     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 );
@@ -298,6 +344,11 @@ test-actions:
     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 ) );
@@ -324,6 +375,11 @@ test-actions:
     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 ) );
@@ -350,6 +406,11 @@ test-actions:
     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 ) );
@@ -376,6 +437,11 @@ test-actions:
     volatile int64_t a;
     volatile int64_t b;
 
+    a = 0;
+    RTEMS_OBFUSCATE_VARIABLE( a );
+    b = 0;
+    RTEMS_OBFUSCATE_VARIABLE( b );
+
     a = INT64_C( 1 );
     b = INT64_C( 1 );
     T_eq_i64( a * b, INT64_C( 1 ) );
@@ -397,6 +463,9 @@ test-actions:
   action-code: |
     volatile int64_t i;
 
+    i = 0;
+    RTEMS_OBFUSCATE_VARIABLE( i );
+
     i = INT64_C( 1 );
     T_eq_i64( -i, -INT64_C( 1 ) );
 
@@ -412,13 +481,21 @@ test-actions:
   action-code: |
     volatile int64_t n;
     volatile int64_t d;
+    volatile int64_t x;
+
+    n = 0;
+    RTEMS_OBFUSCATE_VARIABLE( n );
+    d = 0;
+    RTEMS_OBFUSCATE_VARIABLE( d );
+    x = 0;
+    RTEMS_OBFUSCATE_VARIABLE( x );
 
     n = INT64_C( 0 );
     d = INT64_C( 0 );
     do_longjmp = true;
 
     if ( setjmp( exception_return_context ) == 0 ) {
-      n = n / d;
+      x = n / d;
     }
 
     n = INT64_C( 1 );
@@ -426,7 +503,7 @@ test-actions:
     do_longjmp = true;
 
     if ( setjmp( exception_return_context ) == 0 ) {
-      n = n / d;
+      x = n / d;
     }
 
     n = INT64_C( 0x7fffffffffffffff );
@@ -434,7 +511,7 @@ test-actions:
     do_longjmp = true;
 
     if ( setjmp( exception_return_context ) == 0 ) {
-      n = n / d;
+      x = n / d;
     }
 
     n = INT64_C( 0x7fffffff00000000 );
@@ -442,7 +519,7 @@ test-actions:
     do_longjmp = true;
 
     if ( setjmp( exception_return_context ) == 0 ) {
-      n = n / d;
+      x = n / d;
     }
 
     n = INT64_C( 0 );
@@ -522,74 +599,164 @@ test-actions:
   action-code: |
     volatile uint64_t n;
     volatile uint64_t d;
+    volatile uint64_t x;
+
+    n = 0;
+    RTEMS_OBFUSCATE_VARIABLE( n );
+    d = 0;
+    RTEMS_OBFUSCATE_VARIABLE( d );
+    x = 0;
+    RTEMS_OBFUSCATE_VARIABLE( x );
 
     n = UINT64_C( 0 );
     d = UINT64_C( 0 );
     do_longjmp = true;
 
     if ( setjmp( exception_return_context ) == 0 ) {
-      n = n / d;
+      x = n / d;
     }
 
+    #if defined(TEST_UDIVMODDI4_WITHOUT_REMINDER)
+    do_longjmp = true;
+
+    if ( setjmp( exception_return_context ) == 0 ) {
+      __udivmoddi4( n, d, NULL );
+    }
+    #endif
+
     n = UINT64_C( 1 );
     d = UINT64_C( 0 );
     do_longjmp = true;
 
     if ( setjmp( exception_return_context ) == 0 ) {
-      n = n / d;
+      x = n / d;
     }
 
+    #if defined(TEST_UDIVMODDI4_WITHOUT_REMINDER)
+    do_longjmp = true;
+
+    if ( setjmp( exception_return_context ) == 0 ) {
+      __udivmoddi4( n, d, NULL );
+    }
+    #endif
+
     n = UINT64_C( 0x7fffffffffffffff );
     d = UINT64_C( 0 );
     do_longjmp = true;
 
     if ( setjmp( exception_return_context ) == 0 ) {
-      n = n / d;
+      x = n / d;
+    }
+
+    #if defined(TEST_UDIVMODDI4_WITHOUT_REMINDER)
+    do_longjmp = true;
+
+    if ( setjmp( exception_return_context ) == 0 ) {
+      __udivmoddi4( n, d, NULL );
     }
+    #endif
 
     n = UINT64_C( 0x7fffffff00000000 );
     d = UINT64_C( 0 );
     do_longjmp = true;
 
     if ( setjmp( exception_return_context ) == 0 ) {
-      n = n / d;
+      x = n / d;
+    }
+
+    #if defined(TEST_UDIVMODDI4_WITHOUT_REMINDER)
+    do_longjmp = true;
+
+    if ( setjmp( exception_return_context ) == 0 ) {
+      __udivmoddi4( n, d, NULL );
+    }
+    #endif
+
+    n = UINT64_C( 0x7fffffff00000000 );
+    d = UINT64_C( 0x7fffffff00000000 );
+    do_longjmp = true;
+
+    if ( setjmp( exception_return_context ) == 0 ) {
+      x = n / d;
+    }
+
+    #if defined(TEST_UDIVMODDI4_WITHOUT_REMINDER)
+    do_longjmp = true;
+
+    if ( setjmp( exception_return_context ) == 0 ) {
+      __udivmoddi4( n, d, NULL );
     }
+    #endif
 
     n = UINT64_C( 0 );
     d = UINT64_C( 1 );
     T_eq_u64( n / d, UINT64_C( 0 ) );
+    #if defined(TEST_UDIVMODDI4_WITHOUT_REMINDER)
+    T_eq_u64( __udivmoddi4( n, d, NULL ), UINT64_C( 0 ) );
+    #endif
 
     n = UINT64_C( 1 );
     d = UINT64_C( 1 );
     T_eq_u64( n / d, UINT64_C( 1 ) );
+    #if defined(TEST_UDIVMODDI4_WITHOUT_REMINDER)
+    T_eq_u64( __udivmoddi4( n, d, NULL ), UINT64_C( 1 ) );
+    #endif
 
     n = UINT64_C( 0xffffffffffffffff );
     d = UINT64_C( 1 );
     T_eq_u64( n / d, UINT64_C( 0xffffffffffffffff ) );
+    #if defined(TEST_UDIVMODDI4_WITHOUT_REMINDER)
+    T_eq_u64( __udivmoddi4( n, d, NULL ), UINT64_C( 0xffffffffffffffff ) );
+    #endif
 
     n = UINT64_C( 2 );
     d = UINT64_C( 1 );
     T_eq_u64( n / d, UINT64_C( 2 ) );
+    #if defined(TEST_UDIVMODDI4_WITHOUT_REMINDER)
+    T_eq_u64( __udivmoddi4( n, d, NULL ), UINT64_C( 2 ) );
+    #endif
 
     n = UINT64_C( 1 );
     d = UINT64_C( 0xffffffffffffffff );
     T_eq_u64( n / d, UINT64_C( 0 ) );
+    #if defined(TEST_UDIVMODDI4_WITHOUT_REMINDER)
+    T_eq_u64( __udivmoddi4( n, d, NULL ), UINT64_C( 0 ) );
+    #endif
 
     n = UINT64_C( 0xffffffffffffffff );
     d = UINT64_C( 0xffffffffffffffff );
     T_eq_u64( n / d, UINT64_C( 1 ) );
+    #if defined(TEST_UDIVMODDI4_WITHOUT_REMINDER)
+    T_eq_u64( __udivmoddi4( n, d, NULL ), UINT64_C( 1 ) );
+    #endif
 
     n = UINT64_C( 0xffffffffffffffff );
     d = UINT64_C( 0x8000000000000000 );
     T_eq_u64( n / d, UINT64_C( 1 ) );
+    #if defined(TEST_UDIVMODDI4_WITHOUT_REMINDER)
+    T_eq_u64( __udivmoddi4( n, d, NULL ), UINT64_C( 1 ) );
+    #endif
 
     n = UINT64_C( 0x0000000100000001 );
     d = UINT64_C( 0x0000000f00000000 );
     T_eq_u64( n / d, UINT64_C( 0 ) );
+    #if defined(TEST_UDIVMODDI4_WITHOUT_REMINDER)
+    T_eq_u64( __udivmoddi4( n, d, NULL ), UINT64_C( 0 ) );
+    #endif
+
+    n = UINT64_C( 0x0000000100000000 );
+    d = UINT64_C( 0x0000000f00000001 );
+    T_eq_u64( n / d, UINT64_C( 0 ) );
+    #if defined(TEST_UDIVMODDI4_WITHOUT_REMINDER)
+    T_eq_u64( __udivmoddi4( n, d, NULL ), UINT64_C( 0 ) );
+    #endif
 
     n = UINT64_C( 0xffffffff0000000f );
     d = UINT64_C( 0x000000010000000f );
     T_eq_u64( n / d, UINT64_C( 4294967280 ) );
+    #if defined(TEST_UDIVMODDI4_WITHOUT_REMINDER)
+    T_eq_u64( __udivmoddi4( n, d, NULL ), UINT64_C( 4294967280 ) );
+    #endif
   checks: []
   links:
   - name: __udivdi3
@@ -600,13 +767,21 @@ test-actions:
   action-code: |
     volatile int64_t n;
     volatile int64_t d;
+    volatile int64_t x;
+
+    n = 0;
+    RTEMS_OBFUSCATE_VARIABLE( n );
+    d = 0;
+    RTEMS_OBFUSCATE_VARIABLE( d );
+    x = 0;
+    RTEMS_OBFUSCATE_VARIABLE( x );
 
     n = INT64_C( 0 );
     d = INT64_C( 0 );
     do_longjmp = true;
 
     if ( setjmp( exception_return_context ) == 0 ) {
-      n = n % d;
+      x = n % d;
     }
 
     n = INT64_C( 1 );
@@ -614,7 +789,7 @@ test-actions:
     do_longjmp = true;
 
     if ( setjmp( exception_return_context ) == 0 ) {
-      n = n % d;
+      x = n % d;
     }
 
     n = INT64_C( 0x7fffffffffffffff );
@@ -622,7 +797,7 @@ test-actions:
     do_longjmp = true;
 
     if ( setjmp( exception_return_context ) == 0 ) {
-      n = n % d;
+      x = n % d;
     }
 
     n = INT64_C( 0x7fffffff00000000 );
@@ -630,7 +805,7 @@ test-actions:
     do_longjmp = true;
 
     if ( setjmp( exception_return_context ) == 0 ) {
-      n = n % d;
+      x = n % d;
     }
 
     n = INT64_C( 0 );
@@ -722,13 +897,21 @@ test-actions:
   action-code: |
     volatile uint64_t n;
     volatile uint64_t d;
+    volatile uint64_t x;
+
+    n = 0;
+    RTEMS_OBFUSCATE_VARIABLE( n );
+    d = 0;
+    RTEMS_OBFUSCATE_VARIABLE( d );
+    x = 0;
+    RTEMS_OBFUSCATE_VARIABLE( x );
 
     n = UINT64_C( 0 );
     d = UINT64_C( 0 );
     do_longjmp = true;
 
     if ( setjmp( exception_return_context ) == 0 ) {
-      n = n % d;
+      x = n % d;
     }
 
     n = UINT64_C( 1 );
@@ -736,7 +919,7 @@ test-actions:
     do_longjmp = true;
 
     if ( setjmp( exception_return_context ) == 0 ) {
-      n = n % d;
+      x = n % d;
     }
 
     n = UINT64_C( 0 );
@@ -796,6 +979,16 @@ test-support: |
   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;



More information about the vc mailing list