/*-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#ifndef _LIBKERN_QUAD_H_36#define _LIBKERN_QUAD_H_3738/*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 `long'.46*47* - The machine's arithmetic is two's complement.48*49* This library can provide 128-bit arithmetic on a machine with 128-bit50* quads and 64-bit longs, for instance, or 96-bit arithmetic on machines51* with 48-bit longs.52*/5354#include <sys/types.h>55#include <sys/limits.h>56#include <sys/syslimits.h>5758/*59* Depending on the desired operation, we view a `long long' (aka quad_t) in60* one or more of the following formats.61*/62union uu {63quad_t q; /* as a (signed) quad */64quad_t uq; /* as an unsigned quad */65long sl[2]; /* as two signed longs */66u_long ul[2]; /* as two unsigned longs */67};6869/*70* Define high and low longwords.71*/72#define H _QUAD_HIGHWORD73#define L _QUAD_LOWWORD7475/*76* Total number of bits in a quad_t and in the pieces that make it up.77* These are used for shifting, and also below for halfword extraction78* and assembly.79*/80#define QUAD_BITS (sizeof(quad_t) * CHAR_BIT)81#define LONG_BITS (sizeof(long) * CHAR_BIT)82#define HALF_BITS (sizeof(long) * CHAR_BIT / 2)8384/*85* Extract high and low shortwords from longword, and move low shortword of86* longword to upper half of long, i.e., produce the upper longword of87* ((quad_t)(x) << (number_of_bits_in_long/2)). (`x' must actually be u_long.)88*89* These are used in the multiply code, to split a longword into upper90* and lower halves, and to reassemble a product as a quad_t, shifted left91* (sizeof(long)*CHAR_BIT/2).92*/93#define HHALF(x) ((x) >> HALF_BITS)94#define LHALF(x) ((x) & ((1 << HALF_BITS) - 1))95#define LHUP(x) ((x) << HALF_BITS)9697typedef unsigned int qshift_t;9899quad_t __ashldi3(quad_t, qshift_t);100quad_t __ashrdi3(quad_t, qshift_t);101int __cmpdi2(quad_t a, quad_t b);102quad_t __divdi3(quad_t a, quad_t b);103quad_t __divmoddi4(quad_t a, quad_t b, quad_t *rem);104quad_t __lshrdi3(quad_t, qshift_t);105quad_t __moddi3(quad_t a, quad_t b);106u_quad_t __qdivrem(u_quad_t u, u_quad_t v, u_quad_t *rem);107u_quad_t __udivdi3(u_quad_t a, u_quad_t b);108u_quad_t __udivmoddi4(u_quad_t a, u_quad_t b, u_quad_t *rem);109u_quad_t __umoddi3(u_quad_t a, u_quad_t b);110int __ucmpdi2(u_quad_t a, u_quad_t b);111112/* ARM EABI support functions. */113#ifdef __ARM_EABI__114int __aeabi_ulcmp(unsigned long long, unsigned long long);115#endif116117#endif /* !_LIBKERN_QUAD_H_ */118119120