os161-1.99
 All Data Structures
longlong.h
00001 /*-
00002  * Copyright (c) 1992, 1993
00003  *      The Regents of the University of California.  All rights reserved.
00004  *
00005  * This software was developed by the Computer Systems Engineering group
00006  * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and
00007  * contributed to Berkeley.
00008  *
00009  * Redistribution and use in source and binary forms, with or without
00010  * modification, are permitted provided that the following conditions
00011  * are met:
00012  * 1. Redistributions of source code must retain the above copyright
00013  *    notice, this list of conditions and the following disclaimer.
00014  * 2. Redistributions in binary form must reproduce the above copyright
00015  *    notice, this list of conditions and the following disclaimer in the
00016  *    documentation and/or other materials provided with the distribution.
00017  * 3. Neither the name of the University nor the names of its contributors
00018  *    may be used to endorse or promote products derived from this software
00019  *    without specific prior written permission.
00020  *
00021  * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
00022  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
00023  * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
00024  * ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
00025  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
00026  * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
00027  * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
00028  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
00029  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
00030  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
00031  * SUCH DAMAGE.
00032  *
00033  * From:
00034  *      @(#)quad.h      8.1 (Berkeley) 6/4/93
00035  *      NetBSD: quad.h,v 1.1 2005/12/20 20:29:40 christos Exp
00036  */
00037 
00038 /*
00039  * Long long arithmetic.
00040  *
00041  * This library makes the following assumptions:
00042  *
00043  *  - The type long long exists.
00044  *
00045  *  - A long long variable is exactly twice as long as `int'.
00046  *
00047  *  - The machine's arithmetic is two's complement.
00048  *
00049  * This library can provide 128-bit arithmetic on a machine with
00050  * 128-bit long longs and 64-bit ints, for instance, or 96-bit
00051  * arithmetic on machines with 48-bit ints.
00052  *
00053  * The names are built into gcc.
00054  */
00055 
00056 #if defined(_KERNEL)
00057 #include <types.h>
00058 #include <endian.h>
00059 #else
00060 #include <sys/types.h>
00061 #include <sys/endian.h>
00062 #endif
00063 
00064 #include <limits.h>
00065 
00066 /*
00067  * Depending on the desired operation, we view a `long long' in
00068  * one or more of the following formats.
00069  */
00070 union uu {
00071         long long          ll;          /* as a (signed) long long */
00072         unsigned long long ull;         /* as an unsigned long long */
00073         int                si[2];       /* as two (signed) ints */
00074         unsigned int       ui[2];       /* as two unsigned ints */
00075 };
00076 
00077 /*
00078  * Define high and low parts of a long long.
00079  */
00080 #if _BYTE_ORDER == _LITTLE_ENDIAN
00081 #define H 1
00082 #define L 0
00083 #endif
00084 
00085 #if _BYTE_ORDER == _BIG_ENDIAN
00086 #define H 0
00087 #define L 1
00088 #endif
00089 
00090 
00091 /*
00092  * Total number of bits in a long long and in the pieces that make it up.
00093  * These are used for shifting, and also below for halfword extraction
00094  * and assembly.
00095  */
00096 #define LONGLONG_BITS   (sizeof(long long) * CHAR_BIT)
00097 #define INT_BITS        (sizeof(int) * CHAR_BIT)
00098 #define HALF_BITS       (sizeof(int) * CHAR_BIT / 2)
00099 
00100 /*
00101  * Extract high and low shortwords from longword, and move low shortword of
00102  * longword to upper half of long, i.e., produce the upper longword of
00103  * ((long long)(x) << (number_of_bits_in_int/2)).
00104  * [`x' must actually be unsigned int.]
00105  *
00106  * These are used in the multiply code, to split a longword into upper
00107  * and lower halves, and to reassemble a product as a long long, shifted
00108  * left (sizeof(int)*CHAR_BIT/2).
00109  */
00110 #define HHALF(x)        ((unsigned int)(x) >> HALF_BITS)
00111 #define LHALF(x)        ((unsigned int)(x) & (((int)1 << HALF_BITS) - 1))
00112 #define LHUP(x)         ((unsigned int)(x) << HALF_BITS)
00113 
00114 long long          __adddi3      (         long long,          long long);
00115 long long          __anddi3      (         long long,          long long);
00116 long long          __ashldi3     (         long long, unsigned int);
00117 long long          __ashrdi3     (         long long, unsigned int);
00118 int                __cmpdi2      (         long long,          long long);
00119 long long          __divdi3      (         long long,          long long);
00120 long long          __iordi3      (         long long,          long long);
00121 long long          __lshldi3     (         long long, unsigned int);
00122 long long          __lshrdi3     (         long long, unsigned int);
00123 long long          __moddi3      (         long long,          long long);
00124 long long          __muldi3      (         long long,          long long);
00125 long long          __negdi2      (         long long);
00126 long long          __one_cmpldi2 (         long long);
00127 long long          __subdi3      (         long long,          long long);
00128 int                __ucmpdi2     (unsigned long long, unsigned long long);
00129 unsigned long long __udivdi3     (unsigned long long, unsigned long long);
00130 unsigned long long __umoddi3     (unsigned long long, unsigned long long);
00131 long long          __xordi3      (         long long,          long long);
00132 
00133 #ifndef _KERNEL
00134 long long          __fixdfdi     (double);
00135 long long          __fixsfdi     (float);
00136 unsigned long long __fixunsdfdi  (double);
00137 unsigned long long __fixunssfdi  (float);
00138 double             __floatdidf   (long long);
00139 float              __floatdisf   (long long);
00140 double             __floatunsdidf(unsigned long long);
00141 #endif
00142 
00143 unsigned long long __qdivrem     (unsigned long long, unsigned long long,
00144                                   unsigned long long *);
 All Data Structures