Commit | Line | Data |
---|---|---|
3fe275b2 | 1 | /*- |
f7e479c4 KB |
2 | * Copyright (c) 1992, 1993 |
3 | * The Regents of the University of California. All rights reserved. | |
3fe275b2 | 4 | * |
80316a78 KB |
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. | |
3fe275b2 | 8 | * |
80316a78 | 9 | * %sccs.include.redist.c% |
aa84920b | 10 | * |
f7e479c4 | 11 | * @(#)quad.h 8.1 (Berkeley) %G% |
3fe275b2 KB |
12 | */ |
13 | ||
80316a78 KB |
14 | /* |
15 | * Quad arithmetic. | |
16 | * | |
17 | * This library makes the following assumptions: | |
18 | * | |
0f92e33b | 19 | * - The type long long (aka quad_t) exists. |
80316a78 KB |
20 | * |
21 | * - A quad variable is exactly twice as long as `long'. | |
22 | * | |
23 | * - The machine's arithmetic is two's complement. | |
24 | * | |
0f92e33b KB |
25 | * This library can provide 128-bit arithmetic on a machine with 128-bit |
26 | * quads and 64-bit longs, for instance, or 96-bit arithmetic on machines | |
27 | * with 48-bit longs. | |
80316a78 | 28 | */ |
1d7b9c94 | 29 | |
0f92e33b | 30 | #include <sys/types.h> |
80316a78 | 31 | #include <limits.h> |
3fe275b2 | 32 | |
80316a78 | 33 | /* |
0f92e33b | 34 | * Depending on the desired operation, we view a `long long' (aka quad_t) in |
80316a78 KB |
35 | * one or more of the following formats. |
36 | */ | |
37 | union uu { | |
0f92e33b KB |
38 | quad_t q; /* as a (signed) quad */ |
39 | quad_t uq; /* as an unsigned quad */ | |
80316a78 KB |
40 | long sl[2]; /* as two signed longs */ |
41 | u_long ul[2]; /* as two unsigned longs */ | |
42 | }; | |
b6267125 | 43 | |
80316a78 KB |
44 | /* |
45 | * Define high and low longwords. | |
46 | */ | |
47 | #define H _QUAD_HIGHWORD | |
48 | #define L _QUAD_LOWWORD | |
3fe275b2 | 49 | |
80316a78 | 50 | /* |
0f92e33b | 51 | * Total number of bits in a quad_t and in the pieces that make it up. |
80316a78 KB |
52 | * These are used for shifting, and also below for halfword extraction |
53 | * and assembly. | |
54 | */ | |
0f92e33b | 55 | #define QUAD_BITS (sizeof(quad_t) * CHAR_BIT) |
80316a78 KB |
56 | #define LONG_BITS (sizeof(long) * CHAR_BIT) |
57 | #define HALF_BITS (sizeof(long) * CHAR_BIT / 2) | |
3fe275b2 | 58 | |
80316a78 KB |
59 | /* |
60 | * Extract high and low shortwords from longword, and move low shortword of | |
61 | * longword to upper half of long, i.e., produce the upper longword of | |
0f92e33b | 62 | * ((quad_t)(x) << (number_of_bits_in_long/2)). (`x' must actually be u_long.) |
80316a78 KB |
63 | * |
64 | * These are used in the multiply code, to split a longword into upper | |
0f92e33b | 65 | * and lower halves, and to reassemble a product as a quad_t, shifted left |
80316a78 KB |
66 | * (sizeof(long)*CHAR_BIT/2). |
67 | */ | |
68 | #define HHALF(x) ((x) >> HALF_BITS) | |
69 | #define LHALF(x) ((x) & ((1 << HALF_BITS) - 1)) | |
70 | #define LHUP(x) ((x) << HALF_BITS) | |
3fe275b2 | 71 | |
0f92e33b | 72 | extern u_quad_t __qdivrem __P((u_quad_t u, u_quad_t v, u_quad_t *rem)); |
22ffce3b KB |
73 | |
74 | /* | |
75 | * XXX | |
76 | * Compensate for gcc 1 vs gcc 2. Gcc 1 defines ?sh?di3's second argument | |
0f92e33b | 77 | * as u_quad_t, while gcc 2 correctly uses int. Unfortunately, we still use |
22ffce3b KB |
78 | * both compilers. |
79 | */ | |
ce46cb75 | 80 | #if __GNUC__ >= 2 |
22ffce3b KB |
81 | typedef unsigned int qshift_t; |
82 | #else | |
0f92e33b | 83 | typedef u_quad_t qshift_t; |
22ffce3b | 84 | #endif |