/*-1* SPDX-License-Identifier: BSD-3-Clause2*3* Copyright (c) 1992, 19934* The Regents of the University of California. All rights reserved.5*6* This software was developed by the Computer Systems Engineering group7* at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and8* contributed to Berkeley.9*10* Redistribution and use in source and binary forms, with or without11* modification, are permitted provided that the following conditions12* are met:13* 1. Redistributions of source code must retain the above copyright14* notice, this list of conditions and the following disclaimer.15* 2. Redistributions in binary form must reproduce the above copyright16* notice, this list of conditions and the following disclaimer in the17* documentation and/or other materials provided with the distribution.18* 3. Neither the name of the University nor the names of its contributors19* may be used to endorse or promote products derived from this software20* without specific prior written permission.21*22* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND23* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE24* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE25* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE26* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL27* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS28* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)29* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT30* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY31* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF32* SUCH DAMAGE.33*/3435/*36* Quad arithmetic.37*38* This library makes the following assumptions:39*40* - The type long long (aka quad_t) exists.41*42* - A quad variable is exactly twice as long as `long'.43*44* - The machine's arithmetic is two's complement.45*46* This library can provide 128-bit arithmetic on a machine with 128-bit47* quads and 64-bit longs, for instance, or 96-bit arithmetic on machines48* with 48-bit longs.49*/5051#include <sys/types.h>52#include <limits.h>5354/*55* Depending on the desired operation, we view a `long long' (aka quad_t) in56* one or more of the following formats.57*/58union uu {59quad_t q; /* as a (signed) quad */60quad_t uq; /* as an unsigned quad */61long sl[2]; /* as two signed longs */62u_long ul[2]; /* as two unsigned longs */63};6465/*66* Define high and low longwords.67*/68#define H _QUAD_HIGHWORD69#define L _QUAD_LOWWORD7071/*72* Total number of bits in a quad_t and in the pieces that make it up.73* These are used for shifting, and also below for halfword extraction74* and assembly.75*/76#define QUAD_BITS (sizeof(quad_t) * CHAR_BIT)77#define LONG_BITS (sizeof(long) * CHAR_BIT)78#define HALF_BITS (sizeof(long) * CHAR_BIT / 2)7980/*81* Extract high and low shortwords from longword, and move low shortword of82* longword to upper half of long, i.e., produce the upper longword of83* ((quad_t)(x) << (number_of_bits_in_long/2)). (`x' must actually be u_long.)84*85* These are used in the multiply code, to split a longword into upper86* and lower halves, and to reassemble a product as a quad_t, shifted left87* (sizeof(long)*CHAR_BIT/2).88*/89#define HHALF(x) ((x) >> HALF_BITS)90#define LHALF(x) ((x) & ((1L << HALF_BITS) - 1))91#define LHUP(x) ((x) << HALF_BITS)9293int __cmpdi2(quad_t a, quad_t b);94quad_t __divdi3(quad_t a, quad_t b);95quad_t __moddi3(quad_t a, quad_t b);96u_quad_t __qdivrem(u_quad_t u, u_quad_t v, u_quad_t *rem);97int __ucmpdi2(u_quad_t a, u_quad_t b);98u_quad_t __udivdi3(u_quad_t a, u_quad_t b);99u_quad_t __umoddi3(u_quad_t a, u_quad_t b);100101typedef unsigned int qshift_t;102103104