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