Home | History | Annotate | Line # | Download | only in quad
quad.h revision 1.4.2.1
      1  1.4.2.1      yamt /*	$NetBSD: quad.h,v 1.4.2.1 2012/04/17 00:01:40 yamt 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.4.2.1      yamt #define	LHALF(x)	((u_int)(x) & (((int)1 << (u_int)HALF_BITS) - 1))
     98  1.4.2.1      yamt #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.4.2.1      yamt quad_t __adddi3(quad_t, quad_t);
    114  1.4.2.1      yamt quad_t __anddi3(quad_t, quad_t);
    115  1.4.2.1      yamt quad_t __ashldi3(quad_t, qshift_t);
    116  1.4.2.1      yamt quad_t __ashrdi3(quad_t, qshift_t);
    117  1.4.2.1      yamt int __cmpdi2(quad_t, quad_t);
    118  1.4.2.1      yamt quad_t __divdi3(quad_t, quad_t);
    119  1.4.2.1      yamt quad_t __fixtfdi(long double);
    120  1.4.2.1      yamt quad_t __fixdfdi(double);
    121  1.4.2.1      yamt quad_t __fixsfdi(float);
    122  1.4.2.1      yamt u_quad_t __fixunstfdi(long double);
    123  1.4.2.1      yamt u_quad_t __fixunsdfdi(double);
    124  1.4.2.1      yamt u_quad_t __fixunssfdi(float);
    125  1.4.2.1      yamt long double __floatditf(quad_t);
    126  1.4.2.1      yamt double __floatdidf(quad_t);
    127  1.4.2.1      yamt float __floatdisf(quad_t);
    128  1.4.2.1      yamt long double __floatunditf(u_quad_t);
    129  1.4.2.1      yamt double __floatundidf(u_quad_t);
    130  1.4.2.1      yamt float __floatundisf(u_quad_t);
    131  1.4.2.1      yamt quad_t __iordi3(quad_t, quad_t);
    132  1.4.2.1      yamt quad_t __lshldi3(quad_t, qshift_t);
    133  1.4.2.1      yamt quad_t __lshrdi3(quad_t, qshift_t);
    134  1.4.2.1      yamt quad_t __moddi3(quad_t, quad_t);
    135  1.4.2.1      yamt quad_t __muldi3(quad_t, quad_t);
    136  1.4.2.1      yamt quad_t __negdi2(quad_t);
    137  1.4.2.1      yamt quad_t __one_cmpldi2(quad_t);
    138  1.4.2.1      yamt u_quad_t __qdivrem(u_quad_t, u_quad_t, u_quad_t *);
    139  1.4.2.1      yamt quad_t __subdi3(quad_t, quad_t);
    140  1.4.2.1      yamt int __ucmpdi2(u_quad_t, u_quad_t);
    141  1.4.2.1      yamt u_quad_t __udivdi3(u_quad_t, u_quad_t );
    142  1.4.2.1      yamt u_quad_t __umoddi3(u_quad_t, u_quad_t );
    143  1.4.2.1      yamt quad_t __xordi3(quad_t, quad_t);
    144      1.1  christos __END_DECLS
    145