1 /* fast int primitives. min,max,abs,samesign
3 * WARNING: Assumes 2's complement arithmetic.
7 #define fabsshift ((8*sizeof(unsigned int))-1)
9 static __inline__
int intmax( register int x
, register int y
)
18 static __inline__
int intmin( register int x
, register int y
)
27 static __inline__
int intabs( register int x
)
29 register int neg
= -x
;
32 : "+r" (x
) : "r" (neg
)
38 static __inline__
int intabs(int x
)
40 return ((x
)-(((unsigned int)(x
))>>fabsshift
)) ^ ((x
)>>fabsshift
);
43 static __inline__
int intmax(int x
, int y
)
45 return (((x
-y
)>>fabsshift
) & y
) | ((~((x
-y
)>>fabsshift
)) & x
);
48 static __inline__
int intmin(int x
,int y
)
50 return (((y
-x
)>>fabsshift
) & y
) | ((~((y
-x
)>>fabsshift
)) & x
);
55 #define signmask(x) (((int)x)>>fabsshift)
56 static __inline__
int intsamesign(int x
, int y
)
58 return (y
+(signmask(x
) & -(y
<<1)));