← Commit list

0fea54a98

Denys Vlasenko
Denys Vlasenko
2025-08-01
SUCCESS Duration: 152s

Subject

libbb/dump: much faster formatting of %_u on x86

Binary

No binary (build failed)

Architecture & Compiler Flags

Architecture: x86_64-linux-gnu Compiler: gcc (Ubuntu 11.4.0-1ubuntu1~22.04.3) 11.4.0

—

Build Log

(log yok)

Commit Diff GitHub →

include/platform.h+1 -1
@@ -187,7 +187,7 @@
#elif defined(BYTE_ORDER) && BYTE_ORDER == LITTLE_ENDIAN
# define BB_BIG_ENDIAN 0
# define BB_LITTLE_ENDIAN 1
-#elif defined(__386__)
+#elif defined(__i386__)
# define BB_BIG_ENDIAN 0
# define BB_LITTLE_ENDIAN 1
#else
libbb/dump.c+18 -2
@@ -494,12 +494,28 @@ static void conv_c(PR *pr, unsigned char *p)
*pr->cchar = 'c';
printf(pr->fmt, *p);
} else {
-#if 1
+#if defined(__i386__) || defined(__x86_64__)
+ /* Abuse partial register operations */
+ uint32_t buf;
+ unsigned n = *p;
+ asm ( //00000000 00000000 00000000 aabbbccc
+"\n shll $10,%%eax" //00000000 000000aa bbbccc00 00000000
+"\n shrw $5,%%ax" //00000000 000000aa 00000bbb ccc00000
+"\n shrb $5,%%al" //00000000 000000aa 00000bbb 00000ccc
+"\n shll $8,%%eax" //000000aa 00000bbb 00000ccc 00000000
+"\n bswapl %%eax" //00000000 00000ccc 00000bbb 000000aa
+"\n addl $0x303030,%%eax"
+"\n" : "=a" (n)
+ : "0" (n)
+ );
+ buf = n;
+ str = (void*)&buf;
+#elif 1
char buf[4];
/* gcc-8.0.1 needs lots of casts to shut up */
sprintf(buf, "%03o", (unsigned)(uint8_t)*p);
str = buf;
-#else // use faster version? +20 bytes of code
+#else // use faster version? +20 bytes of code relative to sprintf() method
char buf[4];
buf[3] = '\0';
ch = *p;