1 /* $OpenBSD: fpbits.h,v 1.4 2001/03/29 03:58:18 mickey Exp $ */ 2 3 /* 4 * Copyright 1996 1995 by Open Software Foundation, Inc. 5 * All Rights Reserved 6 * 7 * Permission to use, copy, modify, and distribute this software and 8 * its documentation for any purpose and without fee is hereby granted, 9 * provided that the above copyright notice appears in all copies and 10 * that both the copyright notice and this permission notice appear in 11 * supporting documentation. 12 * 13 * OSF DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE 14 * INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS 15 * FOR A PARTICULAR PURPOSE. 16 * 17 * IN NO EVENT SHALL OSF BE LIABLE FOR ANY SPECIAL, INDIRECT, OR 18 * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM 19 * LOSS OF USE, DATA OR PROFITS, WHETHER IN ACTION OF CONTRACT, 20 * NEGLIGENCE, OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION 21 * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 22 */ 23 /* 24 * pmk1.1 25 */ 26 /* 27 * (c) Copyright 1986 HEWLETT-PACKARD COMPANY 28 * 29 * To anyone who acknowledges that this file is provided "AS IS" 30 * without any express or implied warranty: 31 * permission to use, copy, modify, and distribute this file 32 * for any purpose is hereby granted without fee, provided that 33 * the above copyright notice and this notice appears in all 34 * copies, and that the name of Hewlett-Packard Company not be 35 * used in advertising or publicity pertaining to distribution 36 * of the software without specific, written prior permission. 37 * Hewlett-Packard Company makes no representations about the 38 * suitability of this software for any purpose. 39 */ 40 41 /* 42 * These macros are designed to be portable to all machines that have 43 * a wordsize greater than or equal to 32 bits that support the portable 44 * C compiler and the standard C preprocessor. Wordsize (default 32) 45 * and bitfield assignment (default left-to-right, unlike VAX, PDP-11) 46 * should be predefined using the constants HOSTWDSZ and BITFRL and 47 * the C compiler "-D" flag (e.g., -DHOSTWDSZ=36 -DBITFLR for the DEC-20). 48 * Note that the macro arguments assume that the integer being referenced 49 * is a 32-bit integer (right-justified on the 20) and that bit 0 is the 50 * most significant bit. 51 */ 52 53 #ifndef HOSTWDSZ 54 #define HOSTWDSZ 32 55 #endif 56 57 58 /*########################### Macros ######################################*/ 59 60 /*------------------------------------------------------------------------- 61 * NewDeclareBitField_Reference - Declare a structure similar to the simulator 62 * function "DeclBitfR" except its use is restricted to occur within a larger 63 * enclosing structure or union definition. This declaration is an unnamed 64 * structure with the argument, name, as the member name and the argument, 65 * uname, as the element name. 66 *----------------------------------------------------------------------- */ 67 #define Bitfield_extract(start, length, object) \ 68 ((object) >> (HOSTWDSZ - (start) - (length)) & \ 69 ((unsigned)-1 >> (HOSTWDSZ - (length)))) 70 71 #define Bitfield_signed_extract(start, length, object) \ 72 ((int)((object) << start) >> (HOSTWDSZ - (length))) 73 74 #define Bitfield_mask(start, len, object) \ 75 ((object) & (((unsigned)-1 >> (HOSTWDSZ-len)) << (HOSTWDSZ-start-len))) 76 77 #define Bitfield_deposit(value,start,len,object) object = \ 78 ((object) & ~(((unsigned)-1 >> (HOSTWDSZ-(len))) << (HOSTWDSZ-(start)-(len)))) | \ 79 (((value) & ((unsigned)-1 >> (HOSTWDSZ-(len)))) << (HOSTWDSZ-(start)-(len))) 80 81