mirror of
https://github.com/Fishwaldo/bl_mcu_sdk.git
synced 2025-07-08 13:58:35 +00:00
[feat][common] add arch_ffsll、arch_ctzll、arch_clzll function
This commit is contained in:
parent
b51bfd7b14
commit
a9ea715135
2 changed files with 43 additions and 4 deletions
|
@ -188,6 +188,46 @@ void fifocopy_to_mem(void *fifo_addr, uint8_t *data, uint32_t length)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/****************************************************************************/ /**
|
||||||
|
* @brief get u64 first number 1 from right to left
|
||||||
|
*
|
||||||
|
* @param val: target value
|
||||||
|
* @param bit: first 1 in bit
|
||||||
|
*
|
||||||
|
* @return SUCCESS or ERROR
|
||||||
|
*
|
||||||
|
*******************************************************************************/
|
||||||
|
int arch_ffsll(uint64_t *val, uint32_t *bit)
|
||||||
|
{
|
||||||
|
if (!*val) {
|
||||||
|
return ERROR;
|
||||||
|
}
|
||||||
|
|
||||||
|
*bit = __builtin_ffsll(*val) - 1;
|
||||||
|
*val &= ~((1ULL) << (*bit));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int arch_ctzll(uint64_t *val, uint32_t *bit)
|
||||||
|
{
|
||||||
|
if (!*val)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
*bit = __builtin_ctzll(*val);
|
||||||
|
*val &= ~((1ULL) << (*bit));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
int arch_clzll(uint64_t *val, uint32_t *bit)
|
||||||
|
{
|
||||||
|
if (!*val)
|
||||||
|
return -1;
|
||||||
|
|
||||||
|
*bit = __builtin_clzll(*val);
|
||||||
|
*val &= ~((1ULL) << (*bit));
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef DEBUG
|
#ifdef DEBUG
|
||||||
/*******************************************************************************
|
/*******************************************************************************
|
||||||
* @brief Reports the name of the source file and the source line number
|
* @brief Reports the name of the source file and the source line number
|
||||||
|
|
|
@ -39,10 +39,6 @@
|
||||||
#define BIT(n) (1UL << (n))
|
#define BIT(n) (1UL << (n))
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef CHECK_PARAM
|
|
||||||
#define CHECK_PARAM(expr) ((void)0)
|
|
||||||
#endif
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Null Type definition
|
* @brief Null Type definition
|
||||||
*/
|
*/
|
||||||
|
@ -129,4 +125,7 @@ void *arch_memcpy_fast(void *pdst, const void *psrc, uint32_t n);
|
||||||
uint32_t *arch_memset4(uint32_t *dst, const uint32_t val, uint32_t n);
|
uint32_t *arch_memset4(uint32_t *dst, const uint32_t val, uint32_t n);
|
||||||
void memcopy_to_fifo(void *fifo_addr, uint8_t *data, uint32_t length);
|
void memcopy_to_fifo(void *fifo_addr, uint8_t *data, uint32_t length);
|
||||||
void fifocopy_to_mem(void *fifo_addr, uint8_t *data, uint32_t length);
|
void fifocopy_to_mem(void *fifo_addr, uint8_t *data, uint32_t length);
|
||||||
|
int arch_ctzll(uint64_t *val, uint32_t *bit);
|
||||||
|
int arch_clzll(uint64_t *val, uint32_t *bit);
|
||||||
|
int arch_ffsll(uint64_t *val, uint32_t *bit);
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue