Home | History | Annotate | Line # | Download | only in quad
quad.h revision 1.5
      1  1.5  christos /*	$NetBSD: quad.h,v 1.5 2012/03/09 15:41:16 christos Exp $	*/
      2  1.1  christos 
      3  1.1  christos /*-
      4  1.1  christos  * Copyright (c) 1992, 1993
      5  1.1  christos  *	The Regents of the University of California.  All rights reserved.
      6  1.1  christos  *
      7  1.1  christos  * This software was developed by the Computer Systems Engineering group
      8  1.1  christos  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
      9  1.1  christos  * contributed to Berkeley.
     10  1.1  christos  *
     11  1.1  christos  * Redistribution and use in source and binary forms, with or without
     12  1.1  christos  * modification, are permitted provided that the following conditions
     13  1.1  christos  * are met:
     14  1.1  christos  * 1. Redistributions of source code must retain the above copyright
     15  1.1  christos  *    notice, this list of conditions and the following disclaimer.
     16  1.1  christos  * 2. Redistributions in binary form must reproduce the above copyright
     17  1.1  christos  *    notice, this list of conditions and the following disclaimer in the
     18  1.1  christos  *    documentation and/or other materials provided with the distribution.
     19  1.1  christos  * 3. Neither the name of the University nor the names of its contributors
     20  1.1  christos  *    may be used to endorse or promote products derived from this software
     21  1.1  christos  *    without specific prior written permission.
     22  1.1  christos  *
     23  1.1  christos  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
     24  1.1  christos  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
     25  1.1  christos  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
     26  1.1  christos  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
     27  1.1  christos  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
     28  1.1  christos  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
     29  1.1  christos  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
     30  1.1  christos  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
     31  1.1  christos  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     32  1.1  christos  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     33  1.1  christos  * SUCH DAMAGE.
     34  1.1  christos  *
     35  1.1  christos  *	@(#)quad.h	8.1 (Berkeley) 6/4/93
     36  1.1  christos  */
     37  1.1  christos 
     38  1.1  christos /*
     39  1.1  christos  * Quad arithmetic.
     40  1.1  christos  *
     41  1.1  christos  * This library makes the following assumptions:
     42  1.1  christos  *
     43  1.1  christos  *  - The type long long (aka quad_t) exists.
     44  1.1  christos  *
     45  1.1  christos  *  - A quad variable is exactly twice as long as `int'.
     46  1.1  christos  *
     47  1.1  christos  *  - The machine's arithmetic is two's complement.
     48  1.1  christos  *
     49  1.1  christos  * This library can provide 128-bit arithmetic on a machine with 128-bit
     50  1.1  christos  * quads and 64-bit ints, for instance, or 96-bit arithmetic on machines
     51  1.1  christos  * with 48-bit ints.
     52  1.1  christos  */
     53  1.1  christos 
     54  1.1  christos #include <sys/types.h>
     55  1.1  christos #if !defined(_KERNEL) && !defined(_STANDALONE)
     56  1.1  christos #include <limits.h>
     57  1.1  christos #else
     58  1.1  christos #include <machine/limits.h>
     59  1.1  christos #endif
     60  1.1  christos 
     61  1.1  christos /*
     62  1.1  christos  * Depending on the desired operation, we view a `long long' (aka quad_t) in
     63  1.1  christos  * one or more of the following formats.
     64  1.1  christos  */
     65  1.1  christos union uu {
     66  1.1  christos 	quad_t	q;		/* as a (signed) quad */
     67  1.1  christos 	u_quad_t uq;		/* as an unsigned quad */
     68  1.1  christos 	int	sl[2];		/* as two signed ints */
     69  1.1  christos 	u_int	ul[2];		/* as two unsigned ints */
     70  1.1  christos };
     71  1.1  christos 
     72  1.1  christos /*
     73  1.1  christos  * Define high and low parts of a quad_t.
     74  1.1  christos  */
     75  1.1  christos #define	H		_QUAD_HIGHWORD
     76  1.1  christos #define	L		_QUAD_LOWWORD
     77  1.1  christos 
     78  1.1  christos /*
     79  1.1  christos  * Total number of bits in a quad_t and in the pieces that make it up.
     80  1.1  christos  * These are used for shifting, and also below for halfword extraction
     81  1.1  christos  * and assembly.
     82  1.1  christos  */
     83  1.1  christos #define	QUAD_BITS	(sizeof(quad_t) * CHAR_BIT)
     84  1.1  christos #define	INT_BITS	(sizeof(int) * CHAR_BIT)
     85  1.1  christos #define	HALF_BITS	(sizeof(int) * CHAR_BIT / 2)
     86  1.1  christos 
     87  1.1  christos /*
     88  1.1  christos  * Extract high and low shortwords from longword, and move low shortword of
     89  1.1  christos  * longword to upper half of long, i.e., produce the upper longword of
     90  1.1  christos  * ((quad_t)(x) << (number_of_bits_in_int/2)).  (`x' must actually be u_int.)
     91  1.1  christos  *
     92  1.1  christos  * These are used in the multiply code, to split a longword into upper
     93  1.1  christos  * and lower halves, and to reassemble a product as a quad_t, shifted left
     94  1.1  christos  * (sizeof(int)*CHAR_BIT/2).
     95  1.1  christos  */
     96  1.1  christos #define	HHALF(x)	((u_int)(x) >> HALF_BITS)
     97  1.5  christos #define	LHALF(x)	((u_int)(x) & (((int)1 << (u_int)HALF_BITS) - 1))
     98  1.5  christos #define	LHUP(x)		((u_int)(x) << (u_int)HALF_BITS)
     99  1.1  christos 
    100  1.1  christos /*
    101  1.1  christos  * XXX
    102  1.1  christos  * Compensate for gcc 1 vs gcc 2.  Gcc 1 defines ?sh?di3's second argument
    103  1.1  christos  * as u_quad_t, while gcc 2 correctly uses int.  Unfortunately, we still use
    104  1.1  christos  * both compilers.
    105  1.1  christos  */
    106  1.1  christos #if __GNUC_PREREQ__(2, 0) || defined(lint)
    107  1.1  christos typedef unsigned int	qshift_t;
    108  1.1  christos #else
    109  1.1  christos typedef u_quad_t	qshift_t;
    110  1.1  christos #endif
    111  1.1  christos 
    112  1.1  christos __BEGIN_DECLS
    113  1.1  christos quad_t __adddi3 __P((quad_t, quad_t));
    114  1.1  christos quad_t __anddi3 __P((quad_t, quad_t));
    115  1.1  christos quad_t __ashldi3 __P((quad_t, qshift_t));
    116  1.1  christos quad_t __ashrdi3 __P((quad_t, qshift_t));
    117  1.1  christos int __cmpdi2 __P((quad_t, quad_t));
    118  1.1  christos quad_t __divdi3 __P((quad_t, quad_t));
    119  1.4      matt quad_t __fixtfdi __P((long double));
    120  1.1  christos quad_t __fixdfdi __P((double));
    121  1.1  christos quad_t __fixsfdi __P((float));
    122  1.4      matt u_quad_t __fixunstfdi __P((long double));
    123  1.1  christos u_quad_t __fixunsdfdi __P((double));
    124  1.1  christos u_quad_t __fixunssfdi __P((float));
    125  1.4      matt long double __floatditf __P((quad_t));
    126  1.1  christos double __floatdidf __P((quad_t));
    127  1.1  christos float __floatdisf __P((quad_t));
    128  1.4      matt long double __floatunditf __P((u_quad_t));
    129  1.2      matt double __floatundidf __P((u_quad_t));
    130  1.3       mrg float __floatundisf __P((u_quad_t));
    131  1.1  christos quad_t __iordi3 __P((quad_t, quad_t));
    132  1.1  christos quad_t __lshldi3 __P((quad_t, qshift_t));
    133  1.1  christos quad_t __lshrdi3 __P((quad_t, qshift_t));
    134  1.1  christos quad_t __moddi3 __P((quad_t, quad_t));
    135  1.1  christos quad_t __muldi3 __P((quad_t, quad_t));
    136  1.1  christos quad_t __negdi2 __P((quad_t));
    137  1.1  christos quad_t __one_cmpldi2 __P((quad_t));
    138  1.1  christos u_quad_t __qdivrem __P((u_quad_t, u_quad_t, u_quad_t *));
    139  1.1  christos quad_t __subdi3 __P((quad_t, quad_t));
    140  1.1  christos int __ucmpdi2 __P((u_quad_t, u_quad_t));
    141  1.1  christos u_quad_t __udivdi3 __P((u_quad_t, u_quad_t ));
    142  1.1  christos u_quad_t __umoddi3 __P((u_quad_t, u_quad_t ));
    143  1.1  christos quad_t __xordi3 __P((quad_t, quad_t));
    144  1.1  christos __END_DECLS
    145