mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-15 20:35:33 +03:00
Implement fast log2
This commit is contained in:
parent
cd2a259b14
commit
32480cf002
2 changed files with 4 additions and 2 deletions
|
@ -100,6 +100,8 @@ http://resnet.uoregon.edu/~gurney_j/jmpc/bitwise.html
|
|||
static inline int16_t cmp16(uint16_t a, uint16_t b) { return (int16_t)(a-b); }
|
||||
static inline int32_t cmp32(uint32_t a, uint32_t b) { return (int32_t)(a-b); }
|
||||
|
||||
static inline uint32_t llog2(uint32_t n) { return 31 - __builtin_clz(n | 1); }
|
||||
|
||||
// using memcpy_fn will force memcpy function call, instead of inlining it. In most cases function call takes fewer instructions
|
||||
// than inlined version (inlining is cheaper for very small moves < 8 bytes / 2 store instructions)
|
||||
#if defined(UNIT_TEST) || defined(SIMULATOR_BUILD)
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
#if defined(USE_GYRO_SPI_ICM42605) || defined(USE_GYRO_SPI_ICM42688P)
|
||||
|
||||
#include "common/axis.h"
|
||||
#include "common/maths.h"
|
||||
#include "common/utils.h"
|
||||
#include "build/debug.h"
|
||||
|
||||
#include "drivers/accgyro/accgyro.h"
|
||||
|
@ -208,7 +208,7 @@ void icm426xxGyroInit(gyroDev_t *gyro)
|
|||
|
||||
// Get desired output data rate
|
||||
uint8_t odrConfig;
|
||||
const uint8_t decim = LOG2_8BIT(gyro->mpuDividerDrops + 1);
|
||||
const unsigned decim = llog2(gyro->mpuDividerDrops + 1);
|
||||
if (gyro->gyroRateKHz && decim < ODR_CONFIG_COUNT) {
|
||||
odrConfig = odrLUT[decim];
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue