xiaoxiang781216 commented on code in PR #20996:
URL: https://github.com/apache/nuttx/pull/20996#discussion_r4384608855
##########
libs/libc/stream/lib_ultoa_invert.c:
##########
@@ -53,12 +57,32 @@ FAR char *__ultoa_invert(unsigned long long val, FAR char
*str, int base)
base &= ~XTOA_UPPER;
}
+ DEBUGASSERT(base > 1 && (base == 10 || (base & (base - 1)) == 0));
+
do
{
int v;
+#if !defined(CONFIG_ARCH_64BIT) && defined(__GNUC__)
Review Comment:
why not simple:
```
switch (base)
{
case 8:
q = div64_const32(val, 8);
break;
case 10:
q = div64_const32(val, 10);
break;
case 16:
q = div64_const32(val, 16);
break;
default:
DEBUGASSERT(false);
}
v = (int)(val - q * 10);
val = q;
```
##########
libs/libc/stream/lib_ultoa_invert.c:
##########
@@ -53,12 +57,32 @@ FAR char *__ultoa_invert(unsigned long long val, FAR char
*str, int base)
base &= ~XTOA_UPPER;
}
+ DEBUGASSERT(base > 1 && (base == 10 || (base & (base - 1)) == 0));
+
do
{
int v;
+#if !defined(CONFIG_ARCH_64BIT) && defined(__GNUC__)
+ if (base == 10)
+ {
+ unsigned long long q;
+
+ q = div64_const32(val, 10);
+ v = (int)(val - q * 10);
+ val = q;
+ }
+ else
+ {
+ unsigned int b = (unsigned int)base;
+
+ v = (int)(val & (b - 1));
+ val >>= ffs(base);
+ }
+#else
Review Comment:
why need #if/#else/#endif
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]