FreeBSD/sys/kern/kern_acct.c
/*
 * Convert the elements of a timeval into a 32-bit word holding
 * the bits of a IEEE-754 float.
 * The float value represents the timeval's value in microsecond units.
 */
Convert the elements of a timeval into a 32-bit word holding
the bits of a IEEE-754 float.
The float value represents the timeval's value in microsecond units.
Convert the elements of a timeval into a 32 - bit word holding the bits of a IEEE - 754 float . The float value represents the timeval ' s value in microsecond units .
static uint32_t
encode_timeval(struct timeval tv)
{
	int log2_s;
	int val, exp;	
	int norm_exp;	
	int shift;
	if (tv.tv_sec == 0) {
		if (tv.tv_usec == 0)
			return (0);
		exp = 0;
		val = tv.tv_usec;
	} else {
		log2_s = fls(tv.tv_sec) - 1;
		if (log2_s + LOG2_1M < CALC_BITS) {
			exp = 0;
			val = 1000000 * tv.tv_sec + tv.tv_usec;
		} else {
			exp = log2_s + LOG2_1M - CALC_BITS;
			val = (unsigned int)(((uint64_t)1000000 * tv.tv_sec +
			    tv.tv_usec) >> exp);
		}
	}
	norm_exp = fls(val) - 1;
	shift = FLT_MANT_DIG - norm_exp - 1;
#ifdef ACCT_DEBUG
	printf("val=%d exp=%d shift=%d log2(val)=%d\n",
	    val, exp, shift, norm_exp);
	printf("exp=%x mant=%x\n", FLT_MAX_EXP - 1 + exp + norm_exp,
	    ((shift > 0 ? (val << shift) : (val >> -shift)) & MANT_MASK));
#endif
	return (((FLT_MAX_EXP - 1 + exp + norm_exp) << (FLT_MANT_DIG - 1)) |
	    ((shift > 0 ? val << shift : val >> -shift) & MANT_MASK));
}
static uint32_t encode_timeval ( struct timeval tv ) { int log2_s ; int val , exp ; int norm_exp ; int shift ; if ( tv . tv_sec == 0 ) { if ( tv . tv_usec == 0 ) return ( 0 ) ; exp = 0 ; val = tv . tv_usec ; } else { log2_s = fls ( tv . tv_sec ) - 1 ; if ( log2_s + LOG2_1M < CALC_BITS ) { exp = 0 ; val = 1000000 * tv . tv_sec + tv . tv_usec ; } else { exp = log2_s + LOG2_1M - CALC_BITS ; val = ( unsigned int ) ( ( ( uint64_t ) 1000000 * tv . tv_sec + tv . tv_usec ) >> exp ) ; } } norm_exp = fls ( val ) - 1 ; shift = FLT_MANT_DIG - norm_exp - 1 ; #ifdef ACCT_DEBUG printf ( " \n " , val , exp , shift , norm_exp ) ; printf ( " \n " , FLT_MAX_EXP - 1 + exp + norm_exp , ( ( shift > 0 ? ( val << shift ) : ( val >> - shift ) ) & MANT_MASK ) ) ; #endif return ( ( ( FLT_MAX_EXP - 1 + exp + norm_exp ) << ( FLT_MANT_DIG - 1 ) ) | ( ( shift > 0 ? val << shift : val >> - shift ) & MANT_MASK ) ) ; }
Convert the elements of a timeval into a 32-bit word holding
 the bits of a IEEE-754 float.
Convert the elements of a timeval into a 32 - bit word holding the bits of a IEEE - 754 float .
/* Unnormalized value and exponent */ /* Normalized exponent */ /*
	 * First calculate value and exponent to about CALC_BITS precision.
	 * Note that the following conditionals have been ordered so that
	 * the most common cases appear first.
	 */ /*
		 * Calculate the value to a precision of approximately
		 * CALC_BITS.
		 */ /* Now normalize and pack the value into an IEEE-754 float. */