/*
* isTmax - returns 1 if x is the maximum, two's complement number,
* and 0 otherwise
* Legal ops: ! ~ & ^ | +
* Max ops: 10
* Rating: 1
*/intisTmax(intx){// If x is 0x7fffffff or 0xffffffff, then i is 1, else 0
inti=!(~x^(x+1));// If x == 0xffffffff, then !~x is 1, else 0
returni&!!~x;}
/*
* allOddBits - return 1 if all odd-numbered bits in word set to 1
* where bits are numbered from 0 (least significant) to 31 (most significant)
* Examples allOddBits(0xFFFFFFFD) = 0, allOddBits(0xAAAAAAAA) = 1
* Legal ops: ! ~ & ^ | + << >>
* Max ops: 12
* Rating: 2
*/intallOddBits(intx){intmask=0xaa;mask=(mask<<8)|mask;mask=(mask<<16)|mask;return!((x&mask)^mask);}
/*
* floatScale2 - Return bit-level equivalent of expression 2*f for
* floating point argument f.
* Both the argument and result are passed as unsigned int's, but
* they are to be interpreted as the bit-level representation of
* single-precision floating point values.
* When argument is NaN, return argument
* Legal ops: Any integer/unsigned operations incl. ||, &&. also if, while
* Max ops: 30
* Rating: 4
*/unsignedfloatScale2(unsigneduf){unsignedsign=uf&0x80000000,exp=uf&0x7f800000,frac=uf&0x007fffff;// 0 or denorm
if(exp==0)returnsign|uf<<1;// inf or NaN
if(exp==0x7f800000)returnuf;// norm
exp+=0x00800000;// large number becomes inf
if(exp==0x7f800000)frac=0;returnsign|exp|frac;}
/*
* floatFloat2Int - Return bit-level equivalent of expression (int) f
* for floating point argument f.
* Argument is passed as unsigned int, but
* it is to be interpreted as the bit-level representation of a
* single-precision floating point value.
* Anything out of range (including NaN and infinity) should return
* 0x80000000u.
* Legal ops: Any integer/unsigned operations incl. ||, &&. also if, while
* Max ops: 30
* Rating: 4
*/intfloatFloat2Int(unsigneduf){intsign=uf>>31,exp=((uf>>23)&0xff)-127,frac=(uf&0x007fffff)|0x00800000,value=0;if(exp<0)return0;if(exp>30)return0x80000000;if(exp<23)value=frac>>(23-exp);elseif(exp>23)value=frac<<(exp-23);returnsign?-value:value;}
/*
* floatPower2 - Return bit-level equivalent of the expression 2.0^x
* (2.0 raised to the power x) for any 32-bit integer x.
*
* The unsigned value that is returned should have the identical bit
* representation as the single-precision floating-point number 2.0^x.
* If the result is too small to be represented as a denorm, return
* 0. If too large, return +INF.
*
* Legal ops: Any integer/unsigned operations incl. ||, &&. Also if, while
* Max ops: 30
* Rating: 4
*/unsignedfloatPower2(intx){if(x<-149)return0;// denorm
if(x<-126)return1<<(149+x);// norm
if(x<128)return(x+127)<<23;// inf
return0x7f800000;}