Changeset a1f7d7d in rtems


Ignore:
Timestamp:
Jul 24, 2018, 7:00:18 AM (16 months ago)
Author:
Sebastian Huber <sebastian.huber@…>
Branches:
master
Children:
5677883
Parents:
406dd62
git-author:
Sebastian Huber <sebastian.huber@…> (07/24/18 07:00:18)
git-committer:
Sebastian Huber <sebastian.huber@…> (07/25/18 08:07:42)
Message:

score: RTEMS_PREDICT_TRUE(), RTEMS_PREDICT_FALSE()

Add RTEMS_PREDICT_TRUE() and RTEMS_PREDICT_FALSE() for static branch
prediction hints.

Close #3475.

Files:
9 edited

Legend:

Unmodified
Added
Removed
  • cpukit/include/rtems/score/basedefs.h

    r406dd62 ra1f7d7d  
    280280#else
    281281  #define RTEMS_DEFINE_GLOBAL_SYMBOL( _name, _value )
     282#endif
     283
     284/**
     285 * @brief Returns the value of the specified integral expression and tells the
     286 * compiler that the predicted value is true (1).
     287 *
     288 * @param[in] _exp The expression.
     289 *
     290 * @return The value of the expression.
     291 */
     292#if defined(__GNUC__)
     293  #define RTEMS_PREDICT_TRUE( _exp ) __builtin_expect( ( _exp ), 1 )
     294#else
     295  #define RTEMS_PREDICT_TRUE( _exp ) ( _exp )
     296#endif
     297
     298/**
     299 * @brief Returns the value of the specified integral expression and tells the
     300 * compiler that the predicted value is false (0).
     301 *
     302 * @param[in] _exp The expression.
     303 *
     304 * @return The value of the expression.
     305 */
     306#if defined(__GNUC__)
     307  #define RTEMS_PREDICT_FALSE( _exp ) __builtin_expect( ( _exp ), 0 )
     308#else
     309  #define RTEMS_PREDICT_FALSE( _exp ) ( _exp )
    282310#endif
    283311
  • cpukit/posix/src/sempost.c

    r406dd62 ra1f7d7d  
    4141  count = sem->count;
    4242
    43   if ( __predict_true( heads == NULL && count < SEM_VALUE_MAX ) ) {
     43  if ( RTEMS_PREDICT_TRUE( heads == NULL && count < SEM_VALUE_MAX ) ) {
    4444    sem->count = count + 1;
    4545    _Sem_Queue_release( sem, level, &queue_context );
     
    4747  }
    4848
    49   if ( __predict_true( heads != NULL ) ) {
     49  if ( RTEMS_PREDICT_TRUE( heads != NULL ) ) {
    5050    const Thread_queue_Operations *operations;
    5151    Thread_Control *first;
  • cpukit/posix/src/semtimedwait.c

    r406dd62 ra1f7d7d  
    4747
    4848  count = sem->count;
    49   if ( __predict_true( count > 0 ) ) {
     49  if ( RTEMS_PREDICT_TRUE( count > 0 ) ) {
    5050    sem->count = count - 1;
    5151    _Sem_Queue_release( sem, level, &queue_context );
  • cpukit/posix/src/semtrywait.c

    r406dd62 ra1f7d7d  
    3636
    3737  count = sem->count;
    38   if ( __predict_true( count > 0 ) ) {
     38  if ( RTEMS_PREDICT_TRUE( count > 0 ) ) {
    3939    sem->count = count - 1;
    4040    _Sem_Queue_release( sem, level, &queue_context );
  • cpukit/score/src/condition.c

    r406dd62 ra1f7d7d  
    280280   * on the queue, so check this condition early.
    281281   */
    282   if ( __predict_true( _Thread_queue_Is_empty( &condition->Queue.Queue ) ) ) {
     282  if (
     283    RTEMS_PREDICT_TRUE( _Thread_queue_Is_empty( &condition->Queue.Queue ) )
     284  ) {
    283285    _Condition_Queue_release( condition, &context.Base );
    284286    return;
  • cpukit/score/src/futex.c

    r406dd62 ra1f7d7d  
    152152   * check this condition early.
    153153   */
    154   if ( __predict_true( _Thread_queue_Is_empty( &futex->Queue.Queue ) ) ) {
     154  if ( RTEMS_PREDICT_TRUE( _Thread_queue_Is_empty( &futex->Queue.Queue ) ) ) {
    155155    _Futex_Queue_release( futex, level, &context.Base );
    156156    return 0;
  • cpukit/score/src/mutex.c

    r406dd62 ra1f7d7d  
    129129  _Thread_Resource_count_decrement( executing );
    130130
    131   if ( __predict_true( heads == NULL ) ) {
     131  if ( RTEMS_PREDICT_TRUE( heads == NULL ) ) {
    132132    _Mutex_Queue_release( mutex, level, queue_context );
    133133  } else {
     
    158158  owner = mutex->Queue.Queue.owner;
    159159
    160   if ( __predict_true( owner == NULL ) ) {
     160  if ( RTEMS_PREDICT_TRUE( owner == NULL ) ) {
    161161    mutex->Queue.Queue.owner = executing;
    162162    _Thread_Resource_count_increment( executing );
     
    186186  owner = mutex->Queue.Queue.owner;
    187187
    188   if ( __predict_true( owner == NULL ) ) {
     188  if ( RTEMS_PREDICT_TRUE( owner == NULL ) ) {
    189189    mutex->Queue.Queue.owner = executing;
    190190    _Thread_Resource_count_increment( executing );
     
    219219  owner = mutex->Queue.Queue.owner;
    220220
    221   if ( __predict_true( owner == NULL ) ) {
     221  if ( RTEMS_PREDICT_TRUE( owner == NULL ) ) {
    222222    mutex->Queue.Queue.owner = executing;
    223223    _Thread_Resource_count_increment( executing );
     
    271271  owner = mutex->Mutex.Queue.Queue.owner;
    272272
    273   if ( __predict_true( owner == NULL ) ) {
     273  if ( RTEMS_PREDICT_TRUE( owner == NULL ) ) {
    274274    mutex->Mutex.Queue.Queue.owner = executing;
    275275    _Thread_Resource_count_increment( executing );
     
    302302  owner = mutex->Mutex.Queue.Queue.owner;
    303303
    304   if ( __predict_true( owner == NULL ) ) {
     304  if ( RTEMS_PREDICT_TRUE( owner == NULL ) ) {
    305305    mutex->Mutex.Queue.Queue.owner = executing;
    306306    _Thread_Resource_count_increment( executing );
     
    340340  owner = mutex->Mutex.Queue.Queue.owner;
    341341
    342   if ( __predict_true( owner == NULL ) ) {
     342  if ( RTEMS_PREDICT_TRUE( owner == NULL ) ) {
    343343    mutex->Mutex.Queue.Queue.owner = executing;
    344344    _Thread_Resource_count_increment( executing );
     
    373373  nest_level = mutex->nest_level;
    374374
    375   if ( __predict_true( nest_level == 0 ) ) {
     375  if ( RTEMS_PREDICT_TRUE( nest_level == 0 ) ) {
    376376    _Mutex_Release_critical( &mutex->Mutex, executing, level, &queue_context );
    377377  } else {
  • cpukit/score/src/semaphore.c

    r406dd62 ra1f7d7d  
    5454
    5555  count = sem->count;
    56   if ( __predict_true( count > 0 ) ) {
     56  if ( RTEMS_PREDICT_TRUE( count > 0 ) ) {
    5757    sem->count = count - 1;
    5858    _Sem_Queue_release( sem, level, &queue_context );
     
    8787
    8888  count = sem->count;
    89   if ( __predict_true( count > 0 ) ) {
     89  if ( RTEMS_PREDICT_TRUE( count > 0 ) ) {
    9090    sem->count = count - 1;
    9191    _Sem_Queue_release( sem, level, &queue_context );
     
    122122
    123123  count = sem->count;
    124   if ( __predict_true( count > 0 ) ) {
     124  if ( RTEMS_PREDICT_TRUE( count > 0 ) ) {
    125125    sem->count = count - 1;
    126126    eno = 0;
     
    146146
    147147  heads = sem->Queue.Queue.heads;
    148   if ( __predict_true( heads == NULL ) ) {
     148  if ( RTEMS_PREDICT_TRUE( heads == NULL ) ) {
    149149    ++sem->count;
    150150    _Sem_Queue_release( sem, level, &queue_context );
     
    179179
    180180  heads = sem->Queue.Queue.heads;
    181   if ( __predict_true( heads == NULL ) ) {
     181  if ( RTEMS_PREDICT_TRUE( heads == NULL ) ) {
    182182    sem->count = 1;
    183183    _Sem_Queue_release( sem, level, &queue_context );
  • testsuites/sptests/spmisc01/init.c

    r406dd62 ra1f7d7d  
    230230  rtems_test_assert(strcmp(RTEMS_STRING(str), "str") == 0);
    231231  rtems_test_assert(strcmp(RTEMS_XSTRING(STR), "ing") == 0);
     232
     233  if (RTEMS_PREDICT_TRUE(true)) {
     234    rtems_test_assert(true);
     235  } else {
     236    rtems_test_assert(false);
     237  }
     238
     239  if (RTEMS_PREDICT_FALSE(true)) {
     240    rtems_test_assert(true);
     241  } else {
     242    rtems_test_assert(false);
     243  }
     244
     245  if (RTEMS_PREDICT_TRUE(false)) {
     246    rtems_test_assert(false);
     247  } else {
     248    rtems_test_assert(true);
     249  }
     250
     251  if (RTEMS_PREDICT_FALSE(false)) {
     252    rtems_test_assert(false);
     253  } else {
     254    rtems_test_assert(true);
     255  }
     256
    232257  TEST_END();
    233258  rtems_test_exit(0);
Note: See TracChangeset for help on using the changeset viewer.