[kservice] 优化RT_PRINTF_LONGLONG,减少重复代码
This commit is contained in:
parent
e055a00778
commit
6a863ef65c
10
src/Kconfig
10
src/Kconfig
|
@ -144,7 +144,11 @@ config RT_USING_ASM_MEMSET
|
||||||
default n
|
default n
|
||||||
|
|
||||||
config RT_USING_TINY_FFS
|
config RT_USING_TINY_FFS
|
||||||
bool "Enable kservice to use tiny ffs"
|
bool "Enable kservice to use tiny finding first bit set method"
|
||||||
|
default n
|
||||||
|
|
||||||
|
config RT_PRINTF_LONGLONG
|
||||||
|
bool "Enable rt_xprintf functions to support long long format"
|
||||||
default n
|
default n
|
||||||
|
|
||||||
endmenu
|
endmenu
|
||||||
|
@ -375,10 +379,6 @@ menu "Kernel Device Object"
|
||||||
config RT_CONSOLE_DEVICE_NAME
|
config RT_CONSOLE_DEVICE_NAME
|
||||||
string "the device name for console"
|
string "the device name for console"
|
||||||
default "uart"
|
default "uart"
|
||||||
|
|
||||||
config RT_PRINTF_LONGLONG
|
|
||||||
bool "rt_kprintf support long long"
|
|
||||||
default n
|
|
||||||
endif
|
endif
|
||||||
|
|
||||||
endmenu
|
endmenu
|
||||||
|
|
|
@ -593,7 +593,6 @@ RTM_EXPORT(rt_show_version);
|
||||||
/* private function */
|
/* private function */
|
||||||
#define _ISDIGIT(c) ((unsigned)((c) - '0') < 10)
|
#define _ISDIGIT(c) ((unsigned)((c) - '0') < 10)
|
||||||
|
|
||||||
#ifdef RT_PRINTF_LONGLONG
|
|
||||||
/**
|
/**
|
||||||
* This function will duplicate a string.
|
* This function will duplicate a string.
|
||||||
*
|
*
|
||||||
|
@ -603,44 +602,38 @@ RTM_EXPORT(rt_show_version);
|
||||||
*
|
*
|
||||||
* @return the duplicated string pointer.
|
* @return the duplicated string pointer.
|
||||||
*/
|
*/
|
||||||
|
#ifdef RT_PRINTF_LONGLONG
|
||||||
rt_inline int divide(long long *n, int base)
|
rt_inline int divide(long long *n, int base)
|
||||||
{
|
|
||||||
int res;
|
|
||||||
|
|
||||||
/* optimized for processor which does not support divide instructions. */
|
|
||||||
if (base == 10)
|
|
||||||
{
|
|
||||||
res = (int)(((unsigned long long)*n) % 10U);
|
|
||||||
*n = (long long)(((unsigned long long)*n) / 10U);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
res = (int)(((unsigned long long)*n) % 16U);
|
|
||||||
*n = (long long)(((unsigned long long)*n) / 16U);
|
|
||||||
}
|
|
||||||
|
|
||||||
return res;
|
|
||||||
}
|
|
||||||
#else
|
#else
|
||||||
rt_inline int divide(long *n, int base)
|
rt_inline int divide(long *n, int base)
|
||||||
|
#endif /* RT_PRINTF_LONGLONG */
|
||||||
{
|
{
|
||||||
int res;
|
int res;
|
||||||
|
|
||||||
/* optimized for processor which does not support divide instructions. */
|
/* optimized for processor which does not support divide instructions. */
|
||||||
if (base == 10)
|
if (base == 10)
|
||||||
{
|
{
|
||||||
|
#ifdef RT_PRINTF_LONGLONG
|
||||||
|
res = (int)(((unsigned long long)*n) % 10U);
|
||||||
|
*n = (long long)(((unsigned long long)*n) / 10U);
|
||||||
|
#else
|
||||||
res = (int)(((unsigned long)*n) % 10U);
|
res = (int)(((unsigned long)*n) % 10U);
|
||||||
*n = (long)(((unsigned long)*n) / 10U);
|
*n = (long)(((unsigned long)*n) / 10U);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
#ifdef RT_PRINTF_LONGLONG
|
||||||
|
res = (int)(((unsigned long long)*n) % 16U);
|
||||||
|
*n = (long long)(((unsigned long long)*n) / 16U);
|
||||||
|
#else
|
||||||
res = (int)(((unsigned long)*n) % 16U);
|
res = (int)(((unsigned long)*n) % 16U);
|
||||||
*n = (long)(((unsigned long)*n) / 16U);
|
*n = (long)(((unsigned long)*n) / 16U);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
#endif /* RT_PRINTF_LONGLONG */
|
|
||||||
|
|
||||||
rt_inline int skip_atoi(const char **s)
|
rt_inline int skip_atoi(const char **s)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue