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