1*36410Ssklower /*********************************************************** 2*36410Ssklower Copyright IBM Corporation 1987 3*36410Ssklower 4*36410Ssklower All Rights Reserved 5*36410Ssklower 6*36410Ssklower Permission to use, copy, modify, and distribute this software and its 7*36410Ssklower documentation for any purpose and without fee is hereby granted, 8*36410Ssklower provided that the above copyright notice appear in all copies and that 9*36410Ssklower both that copyright notice and this permission notice appear in 10*36410Ssklower supporting documentation, and that the name of IBM not be 11*36410Ssklower used in advertising or publicity pertaining to distribution of the 12*36410Ssklower software without specific, written prior permission. 13*36410Ssklower 14*36410Ssklower IBM DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING 15*36410Ssklower ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL 16*36410Ssklower IBM BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR 17*36410Ssklower ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, 18*36410Ssklower WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, 19*36410Ssklower ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS 20*36410Ssklower SOFTWARE. 21*36410Ssklower 22*36410Ssklower ******************************************************************/ 23*36410Ssklower 24*36410Ssklower /* 25*36410Ssklower * ARGO Project, Computer Sciences Dept., University of Wisconsin - Madison 26*36410Ssklower */ 27*36410Ssklower /* 28*36410Ssklower * ARGO TP 29*36410Ssklower * 30*36410Ssklower * $Header: tp_seq.h,v 5.1 88/10/12 12:20:59 root Exp $ 31*36410Ssklower * $Source: /usr/argo/sys/netiso/RCS/tp_seq.h,v $ 32*36410Ssklower * 33*36410Ssklower * These macros perform sequence number arithmetic modulo (2**7 or 2**31). 34*36410Ssklower * The relevant fields in the tpcb are: 35*36410Ssklower * tp_seqmask : the mask of bits that define the sequence space. 36*36410Ssklower * tp_seqbit : 1 + tp_seqmask 37*36410Ssklower * tp_seqhalf : tp_seqbit / 2 or half the sequence space (rounded up) 38*36410Ssklower * Not exactly fast, but at least it's maintainable. 39*36410Ssklower */ 40*36410Ssklower 41*36410Ssklower #ifndef __TP_SEQ__ 42*36410Ssklower #define __TP_SEQ__ 43*36410Ssklower 44*36410Ssklower #define SEQ(tpcb,x) \ 45*36410Ssklower ((x) & (tpcb)->tp_seqmask) 46*36410Ssklower 47*36410Ssklower #define SEQ_GT(tpcb, seq, operand ) \ 48*36410Ssklower ( ((int)((seq)-(operand)) > 0)\ 49*36410Ssklower ? ((int)((seq)-(operand)) < (int)(tpcb)->tp_seqhalf)\ 50*36410Ssklower : !(-((int)(seq)-(operand)) < (int)(tpcb)->tp_seqhalf)) 51*36410Ssklower 52*36410Ssklower #define SEQ_GEQ(tpcb, seq, operand ) \ 53*36410Ssklower ( ((int)((seq)-(operand)) >= 0)\ 54*36410Ssklower ? ((int)((seq)-(operand)) < (int)(tpcb)->tp_seqhalf)\ 55*36410Ssklower : !((-((int)(seq)-(operand))) < (int)(tpcb)->tp_seqhalf)) 56*36410Ssklower 57*36410Ssklower #define SEQ_LEQ(tpcb, seq, operand ) \ 58*36410Ssklower ( ((int)((seq)-(operand)) <= 0)\ 59*36410Ssklower ? ((-(int)((seq)-(operand))) < (int)(tpcb)->tp_seqhalf)\ 60*36410Ssklower : !(((int)(seq)-(operand)) < (int)(tpcb)->tp_seqhalf)) 61*36410Ssklower 62*36410Ssklower #define SEQ_LT(tpcb, seq, operand ) \ 63*36410Ssklower ( ((int)((seq)-(operand)) < 0)\ 64*36410Ssklower ? ((-(int)((seq)-(operand))) < (int)(tpcb)->tp_seqhalf)\ 65*36410Ssklower : !(((int)(seq)-(operand)) < (int)(tpcb)->tp_seqhalf)) 66*36410Ssklower 67*36410Ssklower #define SEQ_INC(tpcb, Seq) ((++Seq), ((Seq) &= (tpcb)->tp_seqmask)) 68*36410Ssklower 69*36410Ssklower #define SEQ_DEC(tpcb, Seq)\ 70*36410Ssklower ((Seq) = (((Seq)+(unsigned)((int)(tpcb)->tp_seqbit - 1))&(tpcb)->tp_seqmask)) 71*36410Ssklower 72*36410Ssklower /* (amt) had better be less than the seq bit ! */ 73*36410Ssklower 74*36410Ssklower #define SEQ_SUB(tpcb, Seq, amt)\ 75*36410Ssklower (((Seq) + (unsigned)((int)(tpcb)->tp_seqbit - amt)) & (tpcb)->tp_seqmask) 76*36410Ssklower #define SEQ_ADD(tpcb, Seq, amt) (((Seq) + (unsigned)amt) & (tpcb)->tp_seqmask) 77*36410Ssklower 78*36410Ssklower 79*36410Ssklower #define IN_RWINDOW(tpcb, seq, lwe, uwe)\ 80*36410Ssklower ( SEQ_GEQ(tpcb, seq, lwe) && SEQ_LT(tpcb, seq, uwe) ) 81*36410Ssklower 82*36410Ssklower #define IN_SWINDOW(tpcb, seq, lwe, uwe)\ 83*36410Ssklower ( SEQ_GT(tpcb, seq, lwe) && SEQ_LEQ(tpcb, seq, uwe) ) 84*36410Ssklower 85*36410Ssklower #endif __TP_SEQ__ 86