Back to home page

LXR

 
 

    


File indexing completed on 2025-05-11 08:24:50

0001 /* SPDX-License-Identifier: BSD-2-Clause */
0002 
0003 /**
0004  * @file
0005  *
0006  * @ingroup CompilerUnitBuiltins
0007  */
0008 
0009 /*
0010  * Copyright (C) 2023 embedded brains GmbH & Co. KG
0011  *
0012  * Redistribution and use in source and binary forms, with or without
0013  * modification, are permitted provided that the following conditions
0014  * are met:
0015  * 1. Redistributions of source code must retain the above copyright
0016  *    notice, this list of conditions and the following disclaimer.
0017  * 2. Redistributions in binary form must reproduce the above copyright
0018  *    notice, this list of conditions and the following disclaimer in the
0019  *    documentation and/or other materials provided with the distribution.
0020  *
0021  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
0022  * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
0023  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
0024  * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
0025  * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
0026  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
0027  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
0028  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
0029  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
0030  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
0031  * POSSIBILITY OF SUCH DAMAGE.
0032  */
0033 
0034 /*
0035  * This file is part of the RTEMS quality process and was automatically
0036  * generated.  If you find something that needs to be fixed or
0037  * worded better please post a report or patch to an RTEMS mailing list
0038  * or raise a bug report:
0039  *
0040  * https://www.rtems.org/bugs.html
0041  *
0042  * For information on updating and regenerating please refer to the How-To
0043  * section in the Software Requirements Engineering chapter of the
0044  * RTEMS Software Engineering manual.  The manual is provided as a part of
0045  * a release.  For development sources please refer to the online
0046  * documentation at:
0047  *
0048  * https://docs.rtems.org
0049  */
0050 
0051 #ifdef HAVE_CONFIG_H
0052 #include "config.h"
0053 #endif
0054 
0055 #include <setjmp.h>
0056 #include <stdint.h>
0057 
0058 #include "../validation/tx-support.h"
0059 
0060 #include <rtems/test.h>
0061 
0062 /**
0063  * @defgroup CompilerUnitBuiltins spec:/compiler/unit/builtins
0064  *
0065  * @ingroup TestsuitesUnitNoClock0
0066  *
0067  * @brief These unit tests check compiler builtins.
0068  *
0069  * Explicitly test the 64-bit integer division and modulo operations.  They are
0070  * essential for the timekeeping services.  On most 32-bit targets, they need a
0071  * software implementation.
0072  *
0073  * This test case performs the following actions:
0074  *
0075  * - Check the return value of __builtin_clz() for a sample set of inputs.
0076  *
0077  * - Check the return value of __builtin_clzll() for a sample set of inputs.
0078  *
0079  * - Check the return value of __builtin_ctz() for a sample set of inputs.
0080  *
0081  * - Check the return value of __builtin_ctzll() for a sample set of inputs.
0082  *
0083  * - Check the return value of __builtin_ffs() for a sample set of inputs.
0084  *
0085  * - Check the return value of __builtin_ffsll() for a sample set of inputs.
0086  *
0087  * - Check the return value of __builtin_parity() for a sample set of inputs.
0088  *
0089  * - Check the return value of __builtin_parityll() for a sample set of inputs.
0090  *
0091  * - Check the return value of __builtin_popcount() for a sample set of inputs.
0092  *
0093  * - Check the return value of __builtin_popcountll() for a sample set of
0094  *   inputs.
0095  *
0096  * - Check the return value of __builtin_bswap32() for a sample set of inputs.
0097  *
0098  * - Check the return value of __builtin_bswap64() for a sample set of inputs.
0099  *
0100  * - Check signed 64-bit comparisons for a sample set of values.
0101  *
0102  * - Check unsigned 64-bit comparisons for a sample set of values.
0103  *
0104  * - Check signed 64-bit arithmetic left shift for a sample set of values.
0105  *
0106  * - Check signed 64-bit arithmetic right shift for a sample set of values.
0107  *
0108  * - Check unsigned 64-bit logical right shift for a sample set of values.
0109  *
0110  * - Check signed 64-bit multiplication for a sample set of values.
0111  *
0112  * - Check signed 64-bit negation for a sample set of values.
0113  *
0114  * - Check signed 64-bit divisions for a sample set of values.
0115  *
0116  * - Check unsigned 64-bit divisions for a sample set of values.
0117  *
0118  * - Check signed 64-bit modulo operations for a sample set of values.
0119  *
0120  * - Check unsigned 64-bit modulo operations for a sample set of values.
0121  *
0122  * @{
0123  */
0124 
0125 #if __LONG_MAX__ == 0x7fffffffL && !defined(__aarch64__)
0126 #define TEST_UDIVMODDI4
0127 #endif
0128 
0129 #if defined(TEST_UDIVMODDI4)
0130 uint64_t __udivmoddi4( uint64_t n, uint64_t d, uint64_t *r );
0131 #endif
0132 
0133 #if defined(TEST_UDIVMODDI4) && defined(__arm__)
0134 /*
0135  * Here __aeabi_uldivmod() may be used to carry out integer division
0136  * operations even though the reminder is unused.  This function is
0137  * implemented by __udivmoddi4() which may never get called without a
0138  * reminder for compiler generated code.
0139  */
0140 #define TEST_UDIVMODDI4_WITHOUT_REMINDER
0141 #endif
0142 
0143 static bool do_longjmp;
0144 
0145 static jmp_buf exception_return_context;
0146 
0147 static void Fatal(
0148   rtems_fatal_source source,
0149   rtems_fatal_code   code,
0150   void              *arg
0151 )
0152 {
0153   (void) code;
0154 
0155   if ( source == RTEMS_FATAL_SOURCE_EXCEPTION && do_longjmp ) {
0156     do_longjmp = false;
0157     _ISR_Set_level( 0 );
0158     longjmp( arg, 1 );
0159   }
0160 }
0161 
0162 static void CompilerUnitBuiltins_Setup( void *ctx )
0163 {
0164   SetFatalHandler( Fatal, exception_return_context );
0165 }
0166 
0167 static void CompilerUnitBuiltins_Teardown( void *ctx )
0168 {
0169   SetFatalHandler( NULL, NULL );
0170 }
0171 
0172 static T_fixture CompilerUnitBuiltins_Fixture = {
0173   .setup = CompilerUnitBuiltins_Setup,
0174   .stop = NULL,
0175   .teardown = CompilerUnitBuiltins_Teardown,
0176   .scope = NULL,
0177   .initial_context = NULL
0178 };
0179 
0180 /**
0181  * @brief Check the return value of __builtin_clz() for a sample set of inputs.
0182  */
0183 static void CompilerUnitBuiltins_Action_0( void )
0184 {
0185   volatile unsigned int n;
0186 
0187   n = 0;
0188   RTEMS_OBFUSCATE_VARIABLE( n );
0189 
0190   n = 1U;
0191   T_eq_int( __builtin_clz( n ), 31 );
0192 
0193   n = 1U << 31;
0194   T_eq_int( __builtin_clz( n ), 0 );
0195 
0196   n = ~0U;
0197   T_eq_int( __builtin_clz( n ), 0 );
0198 }
0199 
0200 /**
0201  * @brief Check the return value of __builtin_clzll() for a sample set of
0202  *   inputs.
0203  */
0204 static void CompilerUnitBuiltins_Action_1( void )
0205 {
0206   volatile unsigned long long n;
0207 
0208   n = 0;
0209   RTEMS_OBFUSCATE_VARIABLE( n );
0210 
0211   n = 1ULL;
0212   T_eq_int( __builtin_clzll( n ), 63 );
0213 
0214   n = 1ULL << 31;
0215   T_eq_int( __builtin_clzll( n ), 32 );
0216 
0217   n = 1ULL << 32;
0218   T_eq_int( __builtin_clzll( n ), 31 );
0219 
0220   n = 1ULL << 63;
0221   T_eq_int( __builtin_clzll( n ), 0 );
0222 
0223   n = ~0ULL;
0224   T_eq_int( __builtin_clzll( n ), 0 );
0225 }
0226 
0227 /**
0228  * @brief Check the return value of __builtin_ctz() for a sample set of inputs.
0229  */
0230 static void CompilerUnitBuiltins_Action_2( void )
0231 {
0232   volatile unsigned int n;
0233 
0234   n = 0;
0235   RTEMS_OBFUSCATE_VARIABLE( n );
0236 
0237   n = 1U;
0238   T_eq_int( __builtin_ctz( n ), 0 );
0239 
0240   n = 1U << 31;
0241   T_eq_int( __builtin_ctz( n ), 31 );
0242 
0243   n = ~0U;
0244   T_eq_int( __builtin_ctz( n ), 0 );
0245 }
0246 
0247 /**
0248  * @brief Check the return value of __builtin_ctzll() for a sample set of
0249  *   inputs.
0250  */
0251 static void CompilerUnitBuiltins_Action_3( void )
0252 {
0253   volatile unsigned long long n;
0254 
0255   n = 0;
0256   RTEMS_OBFUSCATE_VARIABLE( n );
0257 
0258   n = 1ULL;
0259   T_eq_int( __builtin_ctzll( n ), 0 );
0260 
0261   n = 1ULL << 31;
0262   T_eq_int( __builtin_ctzll( n ), 31 );
0263 
0264   n = 1ULL << 32;
0265   T_eq_int( __builtin_ctzll( n ), 32 );
0266 
0267   n = 1ULL << 63;
0268   T_eq_int( __builtin_ctzll( n ), 63 );
0269 
0270   n = ~0ULL;
0271   T_eq_int( __builtin_ctzll( n ), 0 );
0272 }
0273 
0274 /**
0275  * @brief Check the return value of __builtin_ffs() for a sample set of inputs.
0276  */
0277 static void CompilerUnitBuiltins_Action_4( void )
0278 {
0279   volatile unsigned int n;
0280 
0281   n = 0;
0282   RTEMS_OBFUSCATE_VARIABLE( n );
0283 
0284   n = 1U;
0285   T_eq_int( __builtin_ffs( n ), 1 );
0286 
0287   n = 1U << 31;
0288   T_eq_int( __builtin_ffs( n ), 32 );
0289 
0290   n = 0U;
0291   T_eq_int( __builtin_ffs( n ), 0 );
0292 }
0293 
0294 /**
0295  * @brief Check the return value of __builtin_ffsll() for a sample set of
0296  *   inputs.
0297  */
0298 static void CompilerUnitBuiltins_Action_5( void )
0299 {
0300   volatile unsigned long long n;
0301 
0302   n = 0;
0303   RTEMS_OBFUSCATE_VARIABLE( n );
0304 
0305   n = 1ULL;
0306   T_eq_int( __builtin_ffsll( n ), 1 );
0307 
0308   n = 1ULL << 31;
0309   T_eq_int( __builtin_ffsll( n ), 32 );
0310 
0311   n = 1ULL << 32;
0312   T_eq_int( __builtin_ffsll( n ), 33 );
0313 
0314   n = 1ULL << 63;
0315   T_eq_int( __builtin_ffsll( n ), 64 );
0316 
0317   n = 0ULL;
0318   T_eq_int( __builtin_ffsll( n ), 0 );
0319 }
0320 
0321 /**
0322  * @brief Check the return value of __builtin_parity() for a sample set of
0323  *   inputs.
0324  */
0325 static void CompilerUnitBuiltins_Action_6( void )
0326 {
0327   volatile unsigned int n;
0328 
0329   n = 0;
0330   RTEMS_OBFUSCATE_VARIABLE( n );
0331 
0332   n = 1U;
0333   T_eq_int( __builtin_parity( n ), 1 );
0334 
0335   n = ~0U;
0336   T_eq_int( __builtin_parity( n ), 0 );
0337 }
0338 
0339 /**
0340  * @brief Check the return value of __builtin_parityll() for a sample set of
0341  *   inputs.
0342  */
0343 static void CompilerUnitBuiltins_Action_7( void )
0344 {
0345   volatile unsigned long long n;
0346 
0347   n = 0;
0348   RTEMS_OBFUSCATE_VARIABLE( n );
0349 
0350   n = 1ULL;
0351   T_eq_int( __builtin_parityll( n ), 1 );
0352 
0353   n = ~0ULL;
0354   T_eq_int( __builtin_parityll( n ), 0 );
0355 }
0356 
0357 /**
0358  * @brief Check the return value of __builtin_popcount() for a sample set of
0359  *   inputs.
0360  */
0361 static void CompilerUnitBuiltins_Action_8( void )
0362 {
0363   volatile unsigned int n;
0364 
0365   n = 0;
0366   RTEMS_OBFUSCATE_VARIABLE( n );
0367 
0368   n = 0U;
0369   T_eq_int( __builtin_popcount( n ), 0 );
0370 
0371   n = 1U;
0372   T_eq_int( __builtin_popcount( n ), 1 );
0373 
0374   n = ~0U;
0375   T_eq_int( __builtin_popcount( n ), 32 );
0376 }
0377 
0378 /**
0379  * @brief Check the return value of __builtin_popcountll() for a sample set of
0380  *   inputs.
0381  */
0382 static void CompilerUnitBuiltins_Action_9( void )
0383 {
0384   volatile unsigned long long n;
0385 
0386   n = 0;
0387   RTEMS_OBFUSCATE_VARIABLE( n );
0388 
0389   n = 0ULL;
0390   T_eq_int( __builtin_popcountll( n ), 0 );
0391 
0392   n = 1ULL;
0393   T_eq_int( __builtin_popcountll( n ), 1 );
0394 
0395   n = ~0ULL;
0396   T_eq_int( __builtin_popcountll( n ), 64 );
0397 }
0398 
0399 /**
0400  * @brief Check the return value of __builtin_bswap32() for a sample set of
0401  *   inputs.
0402  */
0403 static void CompilerUnitBuiltins_Action_10( void )
0404 {
0405   volatile uint32_t n;
0406 
0407   n = 0;
0408   RTEMS_OBFUSCATE_VARIABLE( n );
0409 
0410   n = UINT32_C( 0 );
0411   T_eq_u32( __builtin_bswap32( n ), n );
0412 
0413   n = UINT32_C( 1 );
0414   T_eq_u32( __builtin_bswap32( n ), n << 24 );
0415 
0416   n = UINT32_C( 0x12345678 );
0417   T_eq_u32( __builtin_bswap32( n ), UINT32_C( 0x78563412 ) );
0418 
0419   n = ~UINT32_C( 0 );
0420   T_eq_u32( __builtin_bswap32( n ), n );
0421 }
0422 
0423 /**
0424  * @brief Check the return value of __builtin_bswap64() for a sample set of
0425  *   inputs.
0426  */
0427 static void CompilerUnitBuiltins_Action_11( void )
0428 {
0429   volatile uint64_t n;
0430 
0431   n = 0;
0432   RTEMS_OBFUSCATE_VARIABLE( n );
0433 
0434   n = UINT64_C( 0 );
0435   T_eq_u64( __builtin_bswap64( n ), n );
0436 
0437   n = UINT64_C( 1 );
0438   T_eq_u64( __builtin_bswap64( n ), n << 56 );
0439 
0440   n = UINT64_C( 0x123456789abcdef0 );
0441   T_eq_u64( __builtin_bswap64( n ), UINT64_C( 0xf0debc9a78563412 ) );
0442 
0443   n = ~UINT64_C( 0 );
0444   T_eq_u64( __builtin_bswap64( n ), n );
0445 }
0446 
0447 /**
0448  * @brief Check signed 64-bit comparisons for a sample set of values.
0449  */
0450 static void CompilerUnitBuiltins_Action_12( void )
0451 {
0452   volatile int64_t a;
0453   volatile int64_t b;
0454 
0455   a = 0;
0456   RTEMS_OBFUSCATE_VARIABLE( a );
0457   b = 0;
0458   RTEMS_OBFUSCATE_VARIABLE( b );
0459 
0460   a = INT64_C( 0 );
0461   b = INT64_C( 0 );
0462   T_false( a < b );
0463 
0464   a = INT64_C( 0 );
0465   b = INT64_C( 1 );
0466   T_true( a < b );
0467 
0468   a = INT64_C( 0x123456789abcdef0 );
0469   b = INT64_C( 0xf0debc9a78563412 );
0470   T_false( a < b );
0471 
0472   a = INT64_C( 0xf0debc9a78563412 );
0473   b = INT64_C( 0x123456789abcdef0 );
0474   T_true( a < b );
0475 }
0476 
0477 /**
0478  * @brief Check unsigned 64-bit comparisons for a sample set of values.
0479  */
0480 static void CompilerUnitBuiltins_Action_13( void )
0481 {
0482   volatile uint64_t a;
0483   volatile uint64_t b;
0484 
0485   a = 0;
0486   RTEMS_OBFUSCATE_VARIABLE( a );
0487   b = 0;
0488   RTEMS_OBFUSCATE_VARIABLE( b );
0489 
0490   a = UINT64_C( 0 );
0491   b = UINT64_C( 0 );
0492   T_false( a < b );
0493 
0494   a = UINT64_C( 0 );
0495   b = UINT64_C( 1 );
0496   T_true( a < b );
0497 
0498   a = UINT64_C( 0x123456789abcdef0 );
0499   b = UINT64_C( 0xf0debc9a78563412 );
0500   T_true( a < b );
0501 
0502   a = UINT64_C( 0xf0debc9a78563412 );
0503   b = UINT64_C( 0x123456789abcdef0 );
0504   T_false( a < b );
0505 }
0506 
0507 /**
0508  * @brief Check signed 64-bit arithmetic left shift for a sample set of values.
0509  */
0510 static void CompilerUnitBuiltins_Action_14( void )
0511 {
0512   volatile int64_t i;
0513   volatile int s;
0514 
0515   i = 0;
0516   RTEMS_OBFUSCATE_VARIABLE( i );
0517   s = 0;
0518   RTEMS_OBFUSCATE_VARIABLE( s );
0519 
0520   i = INT64_C( 1 );
0521   s = 0;
0522   T_eq_i64( i << s, INT64_C( 1 ) );
0523 
0524   i = -INT64_C( 1 );
0525   s = 0;
0526   T_eq_i64( i << s, -INT64_C( 1 ) );
0527 
0528   i = INT64_C( 1 );
0529   s = 1;
0530   T_eq_i64( i << s, INT64_C( 2 ) );
0531 
0532   i = -INT64_C( 1 );
0533   s = 1;
0534   T_eq_i64( i << s, -INT64_C( 2 ) );
0535 }
0536 
0537 /**
0538  * @brief Check signed 64-bit arithmetic right shift for a sample set of
0539  *   values.
0540  */
0541 static void CompilerUnitBuiltins_Action_15( void )
0542 {
0543   volatile int64_t i;
0544   volatile int s;
0545 
0546   i = 0;
0547   RTEMS_OBFUSCATE_VARIABLE( i );
0548   s = 0;
0549   RTEMS_OBFUSCATE_VARIABLE( s );
0550 
0551   i = INT64_C( 1 );
0552   s = 0;
0553   T_eq_i64( i >> s, INT64_C( 1 ) );
0554 
0555   i = -INT64_C( 1 );
0556   s = 0;
0557   T_eq_i64( i >> s, -INT64_C( 1 ) );
0558 
0559   i = INT64_C( 2 );
0560   s = 1;
0561   T_eq_i64( i >> s, INT64_C( 1 ) );
0562 
0563   i = -INT64_C( 2 );
0564   s = 1;
0565   T_eq_i64( i >> s, -INT64_C( 1 ) );
0566 }
0567 
0568 /**
0569  * @brief Check unsigned 64-bit logical right shift for a sample set of values.
0570  */
0571 static void CompilerUnitBuiltins_Action_16( void )
0572 {
0573   volatile uint64_t i;
0574   volatile int s;
0575 
0576   i = 0;
0577   RTEMS_OBFUSCATE_VARIABLE( i );
0578   s = 0;
0579   RTEMS_OBFUSCATE_VARIABLE( s );
0580 
0581   i = UINT64_C( 1 );
0582   s = 0;
0583   T_eq_u64( i >> s, UINT64_C( 1 ) );
0584 
0585   i = -UINT64_C( 1 );
0586   s = 0;
0587   T_eq_u64( i >> s, UINT64_C( 0xffffffffffffffff ) );
0588 
0589   i = UINT64_C( 2 );
0590   s = 1;
0591   T_eq_u64( i >> s, UINT64_C( 1 ) );
0592 
0593   i = -UINT64_C( 2 );
0594   s = 1;
0595   T_eq_u64( i >> s, UINT64_C( 0x7fffffffffffffff ) );
0596 }
0597 
0598 /**
0599  * @brief Check signed 64-bit multiplication for a sample set of values.
0600  */
0601 static void CompilerUnitBuiltins_Action_17( void )
0602 {
0603   volatile int64_t a;
0604   volatile int64_t b;
0605 
0606   a = 0;
0607   RTEMS_OBFUSCATE_VARIABLE( a );
0608   b = 0;
0609   RTEMS_OBFUSCATE_VARIABLE( b );
0610 
0611   a = INT64_C( 1 );
0612   b = INT64_C( 1 );
0613   T_eq_i64( a * b, INT64_C( 1 ) );
0614 
0615   a = INT64_C( 1 );
0616   b = INT64_C( 0 );
0617   T_eq_i64( a * b, INT64_C( 0 ) );
0618 
0619   a = INT64_C( 0 );
0620   b = INT64_C( 1 );
0621   T_eq_i64( a * b, INT64_C( 0 ) );
0622 }
0623 
0624 /**
0625  * @brief Check signed 64-bit negation for a sample set of values.
0626  */
0627 static void CompilerUnitBuiltins_Action_18( void )
0628 {
0629   volatile int64_t i;
0630 
0631   i = 0;
0632   RTEMS_OBFUSCATE_VARIABLE( i );
0633 
0634   i = INT64_C( 1 );
0635   T_eq_i64( -i, -INT64_C( 1 ) );
0636 
0637   i = -INT64_C( 1 );
0638   T_eq_i64( -i, INT64_C( 1 ) );
0639 }
0640 
0641 /**
0642  * @brief Check signed 64-bit divisions for a sample set of values.
0643  */
0644 static void CompilerUnitBuiltins_Action_19( void )
0645 {
0646   volatile int64_t n;
0647   volatile int64_t d;
0648   volatile int64_t x;
0649 
0650   n = 0;
0651   RTEMS_OBFUSCATE_VARIABLE( n );
0652   d = 0;
0653   RTEMS_OBFUSCATE_VARIABLE( d );
0654   x = 0;
0655   RTEMS_OBFUSCATE_VARIABLE( x );
0656 
0657   n = INT64_C( 0 );
0658   d = INT64_C( 0 );
0659   do_longjmp = true;
0660 
0661   if ( setjmp( exception_return_context ) == 0 ) {
0662     x = n / d;
0663   }
0664 
0665   n = INT64_C( 1 );
0666   d = INT64_C( 0 );
0667   do_longjmp = true;
0668 
0669   if ( setjmp( exception_return_context ) == 0 ) {
0670     x = n / d;
0671   }
0672 
0673   n = INT64_C( 0x7fffffffffffffff );
0674   d = INT64_C( 0 );
0675   do_longjmp = true;
0676 
0677   if ( setjmp( exception_return_context ) == 0 ) {
0678     x = n / d;
0679   }
0680 
0681   n = INT64_C( 0x7fffffff00000000 );
0682   d = INT64_C( 0 );
0683   do_longjmp = true;
0684 
0685   if ( setjmp( exception_return_context ) == 0 ) {
0686     x = n / d;
0687   }
0688 
0689   n = INT64_C( 0 );
0690   d = INT64_C( 1 );
0691   T_eq_i64( n / d, INT64_C( 0 ) );
0692 
0693   n = INT64_C( 1 );
0694   d = INT64_C( 1 );
0695   T_eq_i64( n / d, INT64_C( 1 ) );
0696 
0697   n = INT64_C( 0x7fffffffffffffff );
0698   d = INT64_C( 1 );
0699   T_eq_i64( n / d, INT64_C( 9223372036854775807 ) );
0700 
0701   n = INT64_C( 2 );
0702   d = INT64_C( 1 );
0703   T_eq_i64( n / d, INT64_C( 2 ) );
0704 
0705   n = INT64_C( 2 );
0706   d = INT64_C( 1 );
0707   T_eq_i64( n / d, INT64_C( 2 ) );
0708 
0709   n = INT64_C( 1 );
0710   d = INT64_C( 0x7fffffffffffffff );
0711   T_eq_i64( n / d, INT64_C( 0 ) );
0712 
0713   n = INT64_C( 0x7fffffffffffffff );
0714   d = INT64_C( 0x7fffffffffffffff );
0715   T_eq_i64( n / d, INT64_C( 1 ) );
0716 
0717   n = INT64_C( 1 );
0718   d = INT64_C( 0x7fffffff00000000 );
0719   T_eq_i64( n / d, INT64_C( 0 ) );
0720 
0721   n = INT64_C( 0x7fffffff00000000 );
0722   d = INT64_C( 0x7fffffff00000000 );
0723   T_eq_i64( n / d, INT64_C( 1 ) );
0724 
0725   n = INT64_C( 0x7fffffffffffffff );
0726   d = INT64_C( 0x7fffffff00000000 );
0727   T_eq_i64( n / d, INT64_C( 1 ) );
0728 
0729   n = INT64_C( 0x7fffffffffffffff );
0730   d = INT64_C( 0x8000000000000000 );
0731   T_eq_i64( n / d, INT64_C( 0 ) );
0732 
0733   n = INT64_C( 0x7fffffffffffffff );
0734   d = INT64_C( 0x0000000080000000 );
0735   T_eq_i64( n / d, INT64_C( 0xffffffff ) );
0736 
0737   n = INT64_C( 0x7fffffffffffffff );
0738   d = INT64_C( 0x00000000f0000000 );
0739   T_eq_i64( n / d, INT64_C( 2290649224 ) );
0740 
0741   n = INT64_C( 0x00000001ffffffff );
0742   d = INT64_C( 0x00000000f0000000 );
0743   T_eq_i64( n / d, INT64_C( 2 ) );
0744 
0745   n = INT64_C( 0x0000000fffffffff );
0746   d = INT64_C( 0x000000000000000f );
0747   T_eq_i64( n / d, INT64_C( 4581298449 ) );
0748 
0749   n = INT64_C( 0x0000000100000001 );
0750   d = INT64_C( 0x0000000f00000000 );
0751   T_eq_i64( n / d, INT64_C( 0 ) );
0752 
0753   n = INT64_C( 0x0000000f0000000f );
0754   d = INT64_C( 0x000000ff0000000f );
0755   T_eq_i64( n / d, INT64_C( 0 ) );
0756 }
0757 
0758 /**
0759  * @brief Check unsigned 64-bit divisions for a sample set of values.
0760  */
0761 static void CompilerUnitBuiltins_Action_20( void )
0762 {
0763   volatile uint64_t n;
0764   volatile uint64_t d;
0765   volatile uint64_t x;
0766 
0767   n = 0;
0768   RTEMS_OBFUSCATE_VARIABLE( n );
0769   d = 0;
0770   RTEMS_OBFUSCATE_VARIABLE( d );
0771   x = 0;
0772   RTEMS_OBFUSCATE_VARIABLE( x );
0773 
0774   n = UINT64_C( 0 );
0775   d = UINT64_C( 0 );
0776   do_longjmp = true;
0777 
0778   if ( setjmp( exception_return_context ) == 0 ) {
0779     x = n / d;
0780   }
0781 
0782   #if defined(TEST_UDIVMODDI4_WITHOUT_REMINDER)
0783   do_longjmp = true;
0784 
0785   if ( setjmp( exception_return_context ) == 0 ) {
0786     __udivmoddi4( n, d, NULL );
0787   }
0788   #endif
0789 
0790   n = UINT64_C( 1 );
0791   d = UINT64_C( 0 );
0792   do_longjmp = true;
0793 
0794   if ( setjmp( exception_return_context ) == 0 ) {
0795     x = n / d;
0796   }
0797 
0798   #if defined(TEST_UDIVMODDI4_WITHOUT_REMINDER)
0799   do_longjmp = true;
0800 
0801   if ( setjmp( exception_return_context ) == 0 ) {
0802     __udivmoddi4( n, d, NULL );
0803   }
0804   #endif
0805 
0806   n = UINT64_C( 0x7fffffffffffffff );
0807   d = UINT64_C( 0 );
0808   do_longjmp = true;
0809 
0810   if ( setjmp( exception_return_context ) == 0 ) {
0811     x = n / d;
0812   }
0813 
0814   #if defined(TEST_UDIVMODDI4_WITHOUT_REMINDER)
0815   do_longjmp = true;
0816 
0817   if ( setjmp( exception_return_context ) == 0 ) {
0818     __udivmoddi4( n, d, NULL );
0819   }
0820   #endif
0821 
0822   n = UINT64_C( 0x7fffffff00000000 );
0823   d = UINT64_C( 0 );
0824   do_longjmp = true;
0825 
0826   if ( setjmp( exception_return_context ) == 0 ) {
0827     x = n / d;
0828   }
0829 
0830   #if defined(TEST_UDIVMODDI4_WITHOUT_REMINDER)
0831   do_longjmp = true;
0832 
0833   if ( setjmp( exception_return_context ) == 0 ) {
0834     __udivmoddi4( n, d, NULL );
0835   }
0836   #endif
0837 
0838   n = UINT64_C( 0x7fffffff00000000 );
0839   d = UINT64_C( 0x7fffffff00000000 );
0840   do_longjmp = true;
0841 
0842   if ( setjmp( exception_return_context ) == 0 ) {
0843     x = n / d;
0844   }
0845 
0846   #if defined(TEST_UDIVMODDI4_WITHOUT_REMINDER)
0847   do_longjmp = true;
0848 
0849   if ( setjmp( exception_return_context ) == 0 ) {
0850     __udivmoddi4( n, d, NULL );
0851   }
0852   #endif
0853 
0854   n = UINT64_C( 0 );
0855   d = UINT64_C( 1 );
0856   T_eq_u64( n / d, UINT64_C( 0 ) );
0857   #if defined(TEST_UDIVMODDI4_WITHOUT_REMINDER)
0858   T_eq_u64( __udivmoddi4( n, d, NULL ), UINT64_C( 0 ) );
0859   #endif
0860 
0861   n = UINT64_C( 1 );
0862   d = UINT64_C( 1 );
0863   T_eq_u64( n / d, UINT64_C( 1 ) );
0864   #if defined(TEST_UDIVMODDI4_WITHOUT_REMINDER)
0865   T_eq_u64( __udivmoddi4( n, d, NULL ), UINT64_C( 1 ) );
0866   #endif
0867 
0868   n = UINT64_C( 0xffffffffffffffff );
0869   d = UINT64_C( 1 );
0870   T_eq_u64( n / d, UINT64_C( 0xffffffffffffffff ) );
0871   #if defined(TEST_UDIVMODDI4_WITHOUT_REMINDER)
0872   T_eq_u64( __udivmoddi4( n, d, NULL ), UINT64_C( 0xffffffffffffffff ) );
0873   #endif
0874 
0875   n = UINT64_C( 2 );
0876   d = UINT64_C( 1 );
0877   T_eq_u64( n / d, UINT64_C( 2 ) );
0878   #if defined(TEST_UDIVMODDI4_WITHOUT_REMINDER)
0879   T_eq_u64( __udivmoddi4( n, d, NULL ), UINT64_C( 2 ) );
0880   #endif
0881 
0882   n = UINT64_C( 1 );
0883   d = UINT64_C( 0xffffffffffffffff );
0884   T_eq_u64( n / d, UINT64_C( 0 ) );
0885   #if defined(TEST_UDIVMODDI4_WITHOUT_REMINDER)
0886   T_eq_u64( __udivmoddi4( n, d, NULL ), UINT64_C( 0 ) );
0887   #endif
0888 
0889   n = UINT64_C( 0xffffffffffffffff );
0890   d = UINT64_C( 0xffffffffffffffff );
0891   T_eq_u64( n / d, UINT64_C( 1 ) );
0892   #if defined(TEST_UDIVMODDI4_WITHOUT_REMINDER)
0893   T_eq_u64( __udivmoddi4( n, d, NULL ), UINT64_C( 1 ) );
0894   #endif
0895 
0896   n = UINT64_C( 0xffffffffffffffff );
0897   d = UINT64_C( 0x8000000000000000 );
0898   T_eq_u64( n / d, UINT64_C( 1 ) );
0899   #if defined(TEST_UDIVMODDI4_WITHOUT_REMINDER)
0900   T_eq_u64( __udivmoddi4( n, d, NULL ), UINT64_C( 1 ) );
0901   #endif
0902 
0903   n = UINT64_C( 0x0000000100000001 );
0904   d = UINT64_C( 0x0000000f00000000 );
0905   T_eq_u64( n / d, UINT64_C( 0 ) );
0906   #if defined(TEST_UDIVMODDI4_WITHOUT_REMINDER)
0907   T_eq_u64( __udivmoddi4( n, d, NULL ), UINT64_C( 0 ) );
0908   #endif
0909 
0910   n = UINT64_C( 0x0000000100000000 );
0911   d = UINT64_C( 0x0000000f00000001 );
0912   T_eq_u64( n / d, UINT64_C( 0 ) );
0913   #if defined(TEST_UDIVMODDI4_WITHOUT_REMINDER)
0914   T_eq_u64( __udivmoddi4( n, d, NULL ), UINT64_C( 0 ) );
0915   #endif
0916 
0917   n = UINT64_C( 0xffffffff0000000f );
0918   d = UINT64_C( 0x000000010000000f );
0919   T_eq_u64( n / d, UINT64_C( 4294967280 ) );
0920   #if defined(TEST_UDIVMODDI4_WITHOUT_REMINDER)
0921   T_eq_u64( __udivmoddi4( n, d, NULL ), UINT64_C( 4294967280 ) );
0922   #endif
0923 }
0924 
0925 /**
0926  * @brief Check signed 64-bit modulo operations for a sample set of values.
0927  */
0928 static void CompilerUnitBuiltins_Action_21( void )
0929 {
0930   volatile int64_t n;
0931   volatile int64_t d;
0932   volatile int64_t x;
0933 
0934   n = 0;
0935   RTEMS_OBFUSCATE_VARIABLE( n );
0936   d = 0;
0937   RTEMS_OBFUSCATE_VARIABLE( d );
0938   x = 0;
0939   RTEMS_OBFUSCATE_VARIABLE( x );
0940 
0941   n = INT64_C( 0 );
0942   d = INT64_C( 0 );
0943   do_longjmp = true;
0944 
0945   if ( setjmp( exception_return_context ) == 0 ) {
0946     x = n % d;
0947   }
0948 
0949   n = INT64_C( 1 );
0950   d = INT64_C( 0 );
0951   do_longjmp = true;
0952 
0953   if ( setjmp( exception_return_context ) == 0 ) {
0954     x = n % d;
0955   }
0956 
0957   n = INT64_C( 0x7fffffffffffffff );
0958   d = INT64_C( 0 );
0959   do_longjmp = true;
0960 
0961   if ( setjmp( exception_return_context ) == 0 ) {
0962     x = n % d;
0963   }
0964 
0965   n = INT64_C( 0x7fffffff00000000 );
0966   d = INT64_C( 0 );
0967   do_longjmp = true;
0968 
0969   if ( setjmp( exception_return_context ) == 0 ) {
0970     x = n % d;
0971   }
0972 
0973   n = INT64_C( 0 );
0974   d = INT64_C( 1 );
0975   T_eq_i64( n % d, INT64_C( 0 ) );
0976 
0977   n = INT64_C( 1 );
0978   d = INT64_C( 1 );
0979   T_eq_i64( n % d, INT64_C( 0 ) );
0980 
0981   n = INT64_C( 0x7fffffffffffffff );
0982   d = INT64_C( 1 );
0983   T_eq_i64( n % d, INT64_C( 0 ) );
0984 
0985   n = INT64_C( 2 );
0986   d = INT64_C( 1 );
0987   T_eq_i64( n % d, INT64_C( 0 ) );
0988 
0989   n = INT64_C( 2 );
0990   d = INT64_C( 1 );
0991   T_eq_i64( n % d, INT64_C( 0 ) );
0992 
0993   n = INT64_C( 1 );
0994   d = INT64_C( 0x7fffffffffffffff );
0995   T_eq_i64( n % d, INT64_C( 1 ) );
0996 
0997   n = INT64_C( 0x7fffffffffffffff );
0998   d = INT64_C( 0x7fffffffffffffff );
0999   T_eq_i64( n % d, INT64_C( 0 ) );
1000 
1001   n = INT64_C( 1 );
1002   d = INT64_C( 0x7fffffff00000000 );
1003   T_eq_i64( n % d, INT64_C( 1 ) );
1004 
1005   n = INT64_C( 0x7fffffff00000000 );
1006   d = INT64_C( 0x7fffffff00000000 );
1007   T_eq_i64( n % d, INT64_C( 0 ) );
1008 
1009   n = INT64_C( 0x7fffffffffffffff );
1010   d = INT64_C( 0x7fffffff00000000 );
1011   T_eq_i64( n % d, INT64_C( 0xffffffff ) );
1012 
1013   n = INT64_C( 0x7fffffffffffffff );
1014   d = INT64_C( 0x8000000000000000 );
1015   T_eq_i64( n % d, INT64_C( 0x7fffffffffffffff ) );
1016 
1017   n = INT64_C( 0x7fffffffffffffff );
1018   d = INT64_C( 0x0000000080000000 );
1019   T_eq_i64( n % d, INT64_C( 2147483647 ) );
1020 
1021   n = INT64_C( 0x7fffffffffffffff );
1022   d = INT64_C( 0x00000000f0000000 );
1023   T_eq_i64( n % d, INT64_C( 2147483647 ) );
1024 
1025   n = INT64_C( 0x00000001ffffffff );
1026   d = INT64_C( 0x00000000f0000000 );
1027   T_eq_i64( n % d, INT64_C( 536870911 ) );
1028 
1029   n = INT64_C( 0x0000000fffffffff );
1030   d = INT64_C( 0x000000000000000f );
1031   T_eq_i64( n % d, INT64_C( 0 ) );
1032 
1033   n = INT64_C( 0x0000000100000001 );
1034   d = INT64_C( 0x0000000f00000000 );
1035   T_eq_i64( n % d, INT64_C( 4294967297 ) );
1036 
1037   n = INT64_C( 0x0000000f0000000f );
1038   d = INT64_C( 0x000000ff0000000f );
1039   T_eq_i64( n % d, INT64_C( 64424509455 ) );
1040 
1041   #if defined(TEST_UDIVMODDI4)
1042   /*
1043    * The above test cases may use __udivmoddi4().  However, the below
1044    * parameter values for __udivmoddi4() cannot be obtained through the
1045    * signed modulo or division operations.  On some targets, calls to
1046    * __udivmoddi4() may result from complex optimizations.
1047    */
1048   n = INT64_C( 0xffffffff0000000f );
1049   d = INT64_C( 0x000000010000000f );
1050   T_eq_u64( __udivmoddi4( n, d, NULL ), INT64_C( 4294967280 ) );
1051   #endif
1052 }
1053 
1054 /**
1055  * @brief Check unsigned 64-bit modulo operations for a sample set of values.
1056  */
1057 static void CompilerUnitBuiltins_Action_22( void )
1058 {
1059   volatile uint64_t n;
1060   volatile uint64_t d;
1061   volatile uint64_t x;
1062 
1063   n = 0;
1064   RTEMS_OBFUSCATE_VARIABLE( n );
1065   d = 0;
1066   RTEMS_OBFUSCATE_VARIABLE( d );
1067   x = 0;
1068   RTEMS_OBFUSCATE_VARIABLE( x );
1069 
1070   n = UINT64_C( 0 );
1071   d = UINT64_C( 0 );
1072   do_longjmp = true;
1073 
1074   if ( setjmp( exception_return_context ) == 0 ) {
1075     x = n % d;
1076   }
1077 
1078   n = UINT64_C( 1 );
1079   d = UINT64_C( 0 );
1080   do_longjmp = true;
1081 
1082   if ( setjmp( exception_return_context ) == 0 ) {
1083     x = n % d;
1084   }
1085 
1086   n = UINT64_C( 0 );
1087   d = UINT64_C( 1 );
1088   T_eq_u64( n % d, UINT64_C( 0 ) );
1089 
1090   n = UINT64_C( 1 );
1091   d = UINT64_C( 1 );
1092   T_eq_u64( n % d, UINT64_C( 0 ) );
1093 
1094   n = UINT64_C( 0xffffffffffffffff );
1095   d = UINT64_C( 1 );
1096   T_eq_u64( n % d, UINT64_C( 0 ) );
1097 
1098   n = UINT64_C( 2 );
1099   d = UINT64_C( 1 );
1100   T_eq_u64( n % d, UINT64_C( 0 ) );
1101 
1102   n = UINT64_C( 1 );
1103   d = UINT64_C( 0xffffffffffffffff );
1104   T_eq_u64( n % d, UINT64_C( 1 ) );
1105 
1106   n = UINT64_C( 0xffffffffffffffff );
1107   d = UINT64_C( 0xffffffffffffffff );
1108   T_eq_u64( n % d, UINT64_C( 0 ) );
1109 }
1110 
1111 /**
1112  * @fn void T_case_body_CompilerUnitBuiltins( void )
1113  */
1114 T_TEST_CASE_FIXTURE( CompilerUnitBuiltins, &CompilerUnitBuiltins_Fixture )
1115 {
1116   CompilerUnitBuiltins_Action_0();
1117   CompilerUnitBuiltins_Action_1();
1118   CompilerUnitBuiltins_Action_2();
1119   CompilerUnitBuiltins_Action_3();
1120   CompilerUnitBuiltins_Action_4();
1121   CompilerUnitBuiltins_Action_5();
1122   CompilerUnitBuiltins_Action_6();
1123   CompilerUnitBuiltins_Action_7();
1124   CompilerUnitBuiltins_Action_8();
1125   CompilerUnitBuiltins_Action_9();
1126   CompilerUnitBuiltins_Action_10();
1127   CompilerUnitBuiltins_Action_11();
1128   CompilerUnitBuiltins_Action_12();
1129   CompilerUnitBuiltins_Action_13();
1130   CompilerUnitBuiltins_Action_14();
1131   CompilerUnitBuiltins_Action_15();
1132   CompilerUnitBuiltins_Action_16();
1133   CompilerUnitBuiltins_Action_17();
1134   CompilerUnitBuiltins_Action_18();
1135   CompilerUnitBuiltins_Action_19();
1136   CompilerUnitBuiltins_Action_20();
1137   CompilerUnitBuiltins_Action_21();
1138   CompilerUnitBuiltins_Action_22();
1139 }
1140 
1141 /** @} */