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