Mbed Online does not recognize ARM Intrinsic Function __rbit()

I am programming a STM32F411 on the Online Compiler.
I am using the UIT_FFT_Real Library that uses some ARM Intrinsics. The code worked fine until last year!
But after some Mbed update, I started to get the error:

Error: Use of undeclared identifier ‘__rbit’ in “UIT_FFT_Real/fftReal.cpp”, Line: 36, Col: 26

From the Documentation, I am guessing that the compiler stopped to recognize the __rbit intrinsic:

https://developer.arm.com/documentation/dui0472/k/Compiler-specific-Features/--rbit-intrinsic?lang=en

Any ideias on how to solve that and why my code stopped working?

Kind Regards!

Hello Bruna_Souza_Morais,

Try to replace __rbit with __RBIT.

WARNING : Beware that the __RBIT function takes and returns an uint32_t value, rather than an unsigned int! So additional modifications might be needed.

The __RBIT is defined in the
mbed-os/cmsis/CMSIS_5/CMSIS/TARGET_CORTEX_M/Include/cmsis_armcc.h file as follows:

/**
  \brief   Reverse bit order of value
  \details Reverses the bit order of the given value.
  \param [in]    value  Value to reverse
  \return               Reversed value
 */
#if ((defined (__ARM_ARCH_7M__ ) && (__ARM_ARCH_7M__  == 1)) || \
     (defined (__ARM_ARCH_7EM__) && (__ARM_ARCH_7EM__ == 1))     )
  #define __RBIT                          __rbit
#else
__attribute__((always_inline)) __STATIC_INLINE uint32_t __RBIT(uint32_t value)
{
  uint32_t result;
  uint32_t s = (4U /*sizeof(v)*/ * 8U) - 1U; /* extra shift needed at end */

  result = value;                      /* r will be reversed bits of v; first get LSB of v */
  for (value >>= 1U; value != 0U; value >>= 1U)
  {
    result <<= 1U;
    result |= value & 1U;
    s--;
  }
  result <<= s;                        /* shift when v's highest bits are zero */
  return result;
}
#endif
1 Like

It worked like a charm! :grin:

Thank you very much Zoltan Hudak! You helped me a lot!