libsmart.c
/* Convert an 128-bit unsigned integer to a string */
Convert an 128-bit unsigned integer to a string
Convert an 128 - bit unsigned integer to a string
static char *
__smart_u128_str(smart_attr_t *sa)
{
#define MAX_LEN (128 / 3 + 1 + 1)
	static char s[MAX_LEN];
	char *p = s + MAX_LEN - 1;
	uint32_t *a = (uint32_t *)sa->raw;
	uint64_t r, d;
	uint32_t last = 0;
	*p-- = '\0';
	do {
		r = a[3];
		d = r / 10;
		r = ((r - d * 10) << 32) + a[2];
		a[3] = d;
		d = r / 10;
		r = ((r - d * 10) << 32) + a[1];
		a[2] = d;
		d = r / 10;
		r = ((r - d * 10) << 32) + a[0];
		a[1] = d;
		d = r / 10;
		r = r - d * 10;
		a[0] = d;
		*p-- = '0' + r;
	} while (a[0] || a[1] || a[2] || a[3]);
	p++;
	while ((*p == '0') && (p < &s[sizeof(s) - 2]))
		p++;
	return p;
}
static char * __smart_u128_str ( smart_attr_t * sa ) { #define MAX_LEN  (128 / 3 + 1 + 1) static char s [ MAX_LEN ] ; char * p = s + MAX_LEN - 1 ; uint32_t * a = ( uint32_t * ) sa -> raw ; uint64_t r , d ; uint32_t last = 0 ; * p -- = ' \0 ' ; do { r = a [ 3 ] ; d = r / 10 ; r = ( ( r - d * 10 ) << 32 ) + a [ 2 ] ; a [ 3 ] = d ; d = r / 10 ; r = ( ( r - d * 10 ) << 32 ) + a [ 1 ] ; a [ 2 ] = d ; d = r / 10 ; r = ( ( r - d * 10 ) << 32 ) + a [ 0 ] ; a [ 1 ] = d ; d = r / 10 ; r = r - d * 10 ; a [ 0 ] = d ; * p -- = ' ' + r ; } while ( a [ 0 ] || a [ 1 ] || a [ 2 ] || a [ 3 ] ) ; p ++ ; while ( ( * p == ' ' ) && ( p < & s [ sizeof ( s ) - 2 ] ) ) p ++ ; return p ; }
Convert an 128-bit unsigned integer to a string
Convert an 128 - bit unsigned integer to a string
/* Max size is log10(x) = log2(x) / log2(10) ~= log2(x) / 3.322 */