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