136410Ssklower /*********************************************************** 236410Ssklower Copyright IBM Corporation 1987 336410Ssklower 436410Ssklower All Rights Reserved 536410Ssklower 636410Ssklower Permission to use, copy, modify, and distribute this software and its 736410Ssklower documentation for any purpose and without fee is hereby granted, 836410Ssklower provided that the above copyright notice appear in all copies and that 936410Ssklower both that copyright notice and this permission notice appear in 1036410Ssklower supporting documentation, and that the name of IBM not be 1136410Ssklower used in advertising or publicity pertaining to distribution of the 1236410Ssklower software without specific, written prior permission. 1336410Ssklower 1436410Ssklower IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 1536410Ssklower ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 1636410Ssklower IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 1736410Ssklower ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 1836410Ssklower WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 1936410Ssklower ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 2036410Ssklower SOFTWARE. 2136410Ssklower 2236410Ssklower ******************************************************************/ 2336410Ssklower 2436410Ssklower /* 2536410Ssklower * ARGO Project, Computer Sciences Dept., University of Wisconsin - Madison 2636410Ssklower */ 2736410Ssklower /* 2836410Ssklower * ARGO TP 2936410Ssklower * 3036410Ssklower * $Header: tp_seq.h,v 5.1 88/10/12 12:20:59 root Exp $ 3136410Ssklower * $Source: /usr/argo/sys/netiso/RCS/tp_seq.h,v $ 32*39918Ssklower * @(#)tp_seq.h 7.4 (Berkeley) 01/16/90 * 3336410Ssklower * 3436410Ssklower * These macros perform sequence number arithmetic modulo (2**7 or 2**31). 3536410Ssklower * The relevant fields in the tpcb are: 3636410Ssklower * tp_seqmask : the mask of bits that define the sequence space. 3736410Ssklower * tp_seqbit : 1 + tp_seqmask 3836410Ssklower * tp_seqhalf : tp_seqbit / 2 or half the sequence space (rounded up) 3936410Ssklower * Not exactly fast, but at least it's maintainable. 4036410Ssklower */ 4136410Ssklower 4236410Ssklower #ifndef __TP_SEQ__ 4336410Ssklower #define __TP_SEQ__ 4436410Ssklower 4536410Ssklower #define SEQ(tpcb,x) \ 4636410Ssklower ((x) & (tpcb)->tp_seqmask) 4736410Ssklower 4836410Ssklower #define SEQ_GT(tpcb, seq, operand ) \ 4936410Ssklower ( ((int)((seq)-(operand)) > 0)\ 5036410Ssklower ? ((int)((seq)-(operand)) < (int)(tpcb)->tp_seqhalf)\ 5136410Ssklower : !(-((int)(seq)-(operand)) < (int)(tpcb)->tp_seqhalf)) 5236410Ssklower 5336410Ssklower #define SEQ_GEQ(tpcb, seq, operand ) \ 5436410Ssklower ( ((int)((seq)-(operand)) >= 0)\ 5536410Ssklower ? ((int)((seq)-(operand)) < (int)(tpcb)->tp_seqhalf)\ 5636410Ssklower : !((-((int)(seq)-(operand))) < (int)(tpcb)->tp_seqhalf)) 5736410Ssklower 5836410Ssklower #define SEQ_LEQ(tpcb, seq, operand ) \ 5936410Ssklower ( ((int)((seq)-(operand)) <= 0)\ 6036410Ssklower ? ((-(int)((seq)-(operand))) < (int)(tpcb)->tp_seqhalf)\ 6136410Ssklower : !(((int)(seq)-(operand)) < (int)(tpcb)->tp_seqhalf)) 6236410Ssklower 6336410Ssklower #define SEQ_LT(tpcb, seq, operand ) \ 6436410Ssklower ( ((int)((seq)-(operand)) < 0)\ 6536410Ssklower ? ((-(int)((seq)-(operand))) < (int)(tpcb)->tp_seqhalf)\ 6636410Ssklower : !(((int)(seq)-(operand)) < (int)(tpcb)->tp_seqhalf)) 6736410Ssklower 68*39918Ssklower #define SEQ_MIN(tpcb, a, b) ( SEQ_GT(tpcb, a, b) ? b : a) 69*39918Ssklower 70*39918Ssklower #define SEQ_MAX(tpcb, a, b) ( SEQ_GT(tpcb, a, b) ? a : b) 71*39918Ssklower 7236410Ssklower #define SEQ_INC(tpcb, Seq) ((++Seq), ((Seq) &= (tpcb)->tp_seqmask)) 7336410Ssklower 7436410Ssklower #define SEQ_DEC(tpcb, Seq)\ 7536410Ssklower ((Seq) = (((Seq)+(unsigned)((int)(tpcb)->tp_seqbit - 1))&(tpcb)->tp_seqmask)) 7636410Ssklower 7736410Ssklower /* (amt) had better be less than the seq bit ! */ 7836410Ssklower 7936410Ssklower #define SEQ_SUB(tpcb, Seq, amt)\ 8036410Ssklower (((Seq) + (unsigned)((int)(tpcb)->tp_seqbit - amt)) & (tpcb)->tp_seqmask) 8136410Ssklower #define SEQ_ADD(tpcb, Seq, amt) (((Seq) + (unsigned)amt) & (tpcb)->tp_seqmask) 8236410Ssklower 8336410Ssklower 8436410Ssklower #define IN_RWINDOW(tpcb, seq, lwe, uwe)\ 8536410Ssklower ( SEQ_GEQ(tpcb, seq, lwe) && SEQ_LT(tpcb, seq, uwe) ) 8636410Ssklower 8736410Ssklower #define IN_SWINDOW(tpcb, seq, lwe, uwe)\ 8836410Ssklower ( SEQ_GT(tpcb, seq, lwe) && SEQ_LEQ(tpcb, seq, uwe) ) 8936410Ssklower 9036410Ssklower #endif __TP_SEQ__ 91