xref: /openbsd-src/sys/arch/hppa/spmath/fpbits.h (revision 449b444aa9c7d5428e3352b273ef6caa05cc93f5)
1*449b444aSmickey /*	$OpenBSD: fpbits.h,v 1.6 2002/09/20 19:26:59 mickey Exp $	*/
28a472b3eSmickey /*
3c2feb252Smickey   (c) Copyright 1986 HEWLETT-PACKARD COMPANY
4c2feb252Smickey   To anyone who acknowledges that this file is provided "AS IS"
5c2feb252Smickey   without any express or implied warranty:
6c2feb252Smickey       permission to use, copy, modify, and distribute this file
7c2feb252Smickey   for any purpose is hereby granted without fee, provided that
8c2feb252Smickey   the above copyright notice and this notice appears in all
9c2feb252Smickey   copies, and that the name of Hewlett-Packard Company not be
10c2feb252Smickey   used in advertising or publicity pertaining to distribution
11c2feb252Smickey   of the software without specific, written prior permission.
12c2feb252Smickey   Hewlett-Packard Company makes no representations about the
13c2feb252Smickey   suitability of this software for any purpose.
148a472b3eSmickey */
15c2feb252Smickey /* @(#)fpbits.h: Revision: 1.6.88.1 Date: 93/12/07 15:06:21 */
168a472b3eSmickey 
178a472b3eSmickey /*
188a472b3eSmickey  *  These macros are designed to be portable to all machines that have
198a472b3eSmickey  *  a wordsize greater than or equal to 32 bits that support the portable
208a472b3eSmickey  *  C compiler and the standard C preprocessor.  Wordsize (default 32)
218a472b3eSmickey  *  and bitfield assignment (default left-to-right,  unlike VAX, PDP-11)
228a472b3eSmickey  *  should be predefined using the constants HOSTWDSZ and BITFRL and
238a472b3eSmickey  *  the C compiler "-D" flag (e.g., -DHOSTWDSZ=36 -DBITFLR for the DEC-20).
248a472b3eSmickey  *  Note that the macro arguments assume that the integer being referenced
258a472b3eSmickey  *  is a 32-bit integer (right-justified on the 20) and that bit 0 is the
268a472b3eSmickey  *  most significant bit.
278a472b3eSmickey  */
288a472b3eSmickey 
298a472b3eSmickey #ifndef HOSTWDSZ
308a472b3eSmickey #define	HOSTWDSZ	32
318a472b3eSmickey #endif
328a472b3eSmickey 
338a472b3eSmickey 
348a472b3eSmickey /*###########################  Macros  ######################################*/
358a472b3eSmickey 
368a472b3eSmickey /*-------------------------------------------------------------------------
378a472b3eSmickey  * NewDeclareBitField_Reference - Declare a structure similar to the simulator
388a472b3eSmickey  * function "DeclBitfR" except its use is restricted to occur within a larger
398a472b3eSmickey  * enclosing structure or union definition.  This declaration is an unnamed
408a472b3eSmickey  * structure with the argument, name, as the member name and the argument,
418a472b3eSmickey  * uname, as the element name.
428a472b3eSmickey  *----------------------------------------------------------------------- */
438a472b3eSmickey #define Bitfield_extract(start, length, object)		\
448a472b3eSmickey     ((object) >> (HOSTWDSZ - (start) - (length)) &	\
458a472b3eSmickey     ((unsigned)-1 >> (HOSTWDSZ - (length))))
468a472b3eSmickey 
478a472b3eSmickey #define Bitfield_signed_extract(start, length, object) \
488a472b3eSmickey     ((int)((object) << start) >> (HOSTWDSZ - (length)))
498a472b3eSmickey 
508a472b3eSmickey #define Bitfield_mask(start, len, object)		\
518a472b3eSmickey     ((object) & (((unsigned)-1 >> (HOSTWDSZ-len)) << (HOSTWDSZ-start-len)))
528a472b3eSmickey 
538a472b3eSmickey #define Bitfield_deposit(value,start,len,object)  object = \
54b94afd46Smickey     ((object) & ~(((unsigned)-1 >> (HOSTWDSZ-(len))) << (HOSTWDSZ-(start)-(len)))) | \
55b94afd46Smickey     (((value) & ((unsigned)-1 >> (HOSTWDSZ-(len)))) << (HOSTWDSZ-(start)-(len)))
56