/* $Id: macros.h,v 1.1.1.1 90/11/28 17:02:40 altenhof Exp $ */

/*
 * Copyright (C) 1990 by Digital Equipment Corporation.
 * 
 * Author: Michael P. Altenhofen, CEC Karlsruhe e-mail:
 * Altenhofen@kampus.enet.dec.com
 * 
 * This file ist part of Shared X
 * 
 * Permission to use, copy, modify, and distribute this software and its
 * documentation without fee is hereby granted, but only for non-profit  use
 * and distribution,  and provided  that the copyright notice and this notice
 * is preserved on all copies.
 * 
 * DIGITAL DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
 * ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
 * DIGITAL BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
 * ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
 * WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
 * ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
 * SOFTWARE.
 */
/*
 * we're using some code from the MIT sources
 */
#include "copyright.h"

#define lowbit( x ) ( ( x ) & ( ~( x ) + 1 ) )

/*
 * GetNextBitsOrBreak(bits, mask, base)  -- (Suggestion: First read the
 * macro, then read this explanation.
 * 
 * Either generate the next value to OR in to a pixel or break out of this
 * while loop
 * 
 * This macro is used when we're trying to generate all 2^n combinations of
 * bits in mask.  What we're doing here is counting in binary, except that the
 * bits we use to count may not be contiguous.  This macro will be called 2^n
 * times, returning a different value in bits each time. Then it will cause
 * us to break out of a surrounding loop. (It will always be called from
 * within a while loop.) On call: mask is the value we want to find all the
 * combinations for base has 1 bit set where the least significant bit of
 * mask is set
 * 
 * For example,if mask is 01010, base should be 0010 and we count like this:
 * 00010 (see this isn't so hard), then we add base to bits and get 0100.
 * (bits & ~mask) is (0100 & 0100) so we add that to bits getting (0100 +
 * 0100) = 01000 for our next value. then we add 0010 to get 01010 and we're
 * done (easy as 1, 2, 3)
 */

#define GetNextBitsOrBreak(bits, mask, base)	\
	    if((bits) == (mask)) 		\
		break;		 		\
	    (bits) += (base);		 	\
	    while((bits) & ~(mask))		\
		(bits) += ((bits) & ~(mask));
