/*
* we want to test a refid format of:
* 254.x.y.x
*
* where x.y.z are 24 bits containing 2 (signed) integer bits
* and 22 fractional bits.
*
* we want functions to convert to/from this format, with unit tests.
*
* Interesting test cases include:
* 254.0.0.0
* 254.0.0.1
* 254.127.255.255
* 254.128.0.0
* 254.255.255.255
*/
/*
* The smear data in the refid is the bottom 3 bytes of the refid,
* 2 bits of integer
* 22 bits of fraction
*/
l_fp
convertRefIDToLFP(uint32_t r)
{
l_fp temp;
/* round the input with the highest bit to shift out from the
* fraction, then keep just two bits from the integral part.
*
* TODO: check for overflows; should we clamp/saturate or just
* complain?
*/
L_ADDUF(&num, 0x200);
num.l_ui &= 3;
/* combine integral and fractional part to 24 bits */
temp = (num.l_ui << 22) | (num.l_uf >> 10);
/* put in the leading 254.0.0.0 */
temp |= UINT32_C(0xFE000000);