Skip to content

Commit 6a863ef

Browse files
committed
[kservice] 优化RT_PRINTF_LONGLONG,减少重复代码
1 parent e055a00 commit 6a863ef

File tree

2 files changed

+16
-23
lines changed

2 files changed

+16
-23
lines changed

src/Kconfig

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,11 @@ config RT_USING_ASM_MEMSET
144144
default n
145145

146146
config RT_USING_TINY_FFS
147-
bool "Enable kservice to use tiny ffs"
147+
bool "Enable kservice to use tiny finding first bit set method"
148+
default n
149+
150+
config RT_PRINTF_LONGLONG
151+
bool "Enable rt_xprintf functions to support long long format"
148152
default n
149153

150154
endmenu
@@ -375,10 +379,6 @@ menu "Kernel Device Object"
375379
config RT_CONSOLE_DEVICE_NAME
376380
string "the device name for console"
377381
default "uart"
378-
379-
config RT_PRINTF_LONGLONG
380-
bool "rt_kprintf support long long"
381-
default n
382382
endif
383383

384384
endmenu

src/kservice.c

Lines changed: 11 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -593,7 +593,6 @@ RTM_EXPORT(rt_show_version);
593593
/* private function */
594594
#define _ISDIGIT(c) ((unsigned)((c) - '0') < 10)
595595

596-
#ifdef RT_PRINTF_LONGLONG
597596
/**
598597
* This function will duplicate a string.
599598
*
@@ -603,44 +602,38 @@ RTM_EXPORT(rt_show_version);
603602
*
604603
* @return the duplicated string pointer.
605604
*/
605+
#ifdef RT_PRINTF_LONGLONG
606606
rt_inline int divide(long long *n, int base)
607+
#else
608+
rt_inline int divide(long *n, int base)
609+
#endif /* RT_PRINTF_LONGLONG */
607610
{
608611
int res;
609612

610613
/* optimized for processor which does not support divide instructions. */
611614
if (base == 10)
612615
{
616+
#ifdef RT_PRINTF_LONGLONG
613617
res = (int)(((unsigned long long)*n) % 10U);
614618
*n = (long long)(((unsigned long long)*n) / 10U);
615-
}
616-
else
617-
{
618-
res = (int)(((unsigned long long)*n) % 16U);
619-
*n = (long long)(((unsigned long long)*n) / 16U);
620-
}
621-
622-
return res;
623-
}
624619
#else
625-
rt_inline int divide(long *n, int base)
626-
{
627-
int res;
628-
629-
/* optimized for processor which does not support divide instructions. */
630-
if (base == 10)
631-
{
632620
res = (int)(((unsigned long)*n) % 10U);
633621
*n = (long)(((unsigned long)*n) / 10U);
622+
#endif
634623
}
635624
else
636625
{
626+
#ifdef RT_PRINTF_LONGLONG
627+
res = (int)(((unsigned long long)*n) % 16U);
628+
*n = (long long)(((unsigned long long)*n) / 16U);
629+
#else
637630
res = (int)(((unsigned long)*n) % 16U);
638631
*n = (long)(((unsigned long)*n) / 16U);
632+
#endif
639633
}
640634

641635
return res;
642636
}
643-
#endif /* RT_PRINTF_LONGLONG */
644637

645638
rt_inline int skip_atoi(const char **s)
646639
{

0 commit comments

Comments
 (0)