r125: This commit was manufactured by cvs2svn to create tag 'r1_1_7-last'.
[cinelerra_cv/mob.git] / hvirtual / mpeg2enc / fastintfns.h
bloba52614d03a171902642767212c36dac15df9b80f
1 /* fast int primitives. min,max,abs,samesign
3 * WARNING: Assumes 2's complement arithmetic.
5 */
7 #define fabsshift ((8*sizeof(unsigned int))-1)
8 #ifdef P6_CPU
9 static __inline__ int intmax( register int x, register int y )
11 asm( "cmpl %1, %0\n"
12 "cmovl %1, %0\n"
13 : "+r" (x) : "r" (y)
15 return x;
18 static __inline__ int intmin( register int x, register int y )
20 asm( "cmpl %1, %0\n"
21 "cmovg %1, %0\n"
22 : "+r" (x) : "rm" (y)
24 return x;
27 static __inline__ int intabs( register int x )
29 register int neg = -x;
30 asm( "cmpl %1, %0\n"
31 "cmovl %1, %0\n"
32 : "+r" (x) : "r" (neg)
34 return x;
36 #else
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);
53 #endif
55 #define signmask(x) (((int)x)>>fabsshift)
56 static __inline__ int intsamesign(int x, int y)
58 return (y+(signmask(x) & -(y<<1)));
60 #undef signmask
61 #undef fabsshift