On Fri, Mar 12, 2010 at 09:57:40PM +0100, Simon Wunderlich wrote:
#define seq_before(x,y) ((int8_t) (x - y) < 0) #define seq_after(x,y) seq_before(y,x)
Not so much bitshifting and may a little bit easier to understand, but also not general and does not pass Svens regression test ... :(
Wrong seq_before(0, 128) == true Wrong seq_after(0, 128) == true Wrong seq_before(1, 129) == true Wrong seq_after(1, 129) == true Wrong seq_before(2, 130) == true Wrong seq_after(2, 130) == true Wrong seq_before(3, 131) == true Wrong seq_after(3, 131) == true Wrong seq_before(4, 132) == true Wrong seq_after(4, 132) == true Wrong seq_before(5, 133) == true Wrong seq_after(5, 133) == true
What do you think? ;)
This is the version which also was mentioned by andrew - which has the advantage that it doesn't have "complicated" code, but isn't general purpose for unsigned ints. The only reason I started with the more complicated stuff was that Linus tried to make it easier to change the packet definition without ruining the code at different places.
That it doesn't pass the test is only the due to my symmetric definition of the operation. I am not really intrested in changing that code, but to support Linus.
Best regards, Sven