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