/*-1* Copyright (c) 1992, 19932* The Regents of the University of California. All rights reserved.3*4* This software was developed by the Computer Systems Engineering group5* at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and6* contributed to Berkeley.7*8* Redistribution and use in source and binary forms, with or without9* modification, are permitted provided that the following conditions10* are met:11* 1. Redistributions of source code must retain the above copyright12* notice, this list of conditions and the following disclaimer.13* 2. Redistributions in binary form must reproduce the above copyright14* notice, this list of conditions and the following disclaimer in the15* documentation and/or other materials provided with the distribution.16* 3. Neither the name of the University nor the names of its contributors17* may be used to endorse or promote products derived from this software18* without specific prior written permission.19*20* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND21* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE22* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE23* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE24* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL25* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS26* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)27* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT28* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY29* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF30* SUCH DAMAGE.31*32* From:33* @(#)quad.h 8.1 (Berkeley) 6/4/9334* NetBSD: quad.h,v 1.1 2005/12/20 20:29:40 christos Exp35*/3637/*38* Long long arithmetic.39*40* This library makes the following assumptions:41*42* - The type long long exists.43*44* - A long long variable is exactly twice as long as `int'.45*46* - The machine's arithmetic is two's complement.47*48* This library can provide 128-bit arithmetic on a machine with49* 128-bit long longs and 64-bit ints, for instance, or 96-bit50* arithmetic on machines with 48-bit ints.51*52* The names are built into gcc.53*/5455#if defined(_KERNEL)56#include <types.h>57#include <endian.h>58#else59#include <sys/types.h>60#include <sys/endian.h>61#endif6263#include <limits.h>6465/*66* Depending on the desired operation, we view a `long long' in67* one or more of the following formats.68*/69union uu {70long long ll; /* as a (signed) long long */71unsigned long long ull; /* as an unsigned long long */72int si[2]; /* as two (signed) ints */73unsigned int ui[2]; /* as two unsigned ints */74};7576/*77* Define high and low parts of a long long.78*/79#if _BYTE_ORDER == _LITTLE_ENDIAN80#define H 181#define L 082#endif8384#if _BYTE_ORDER == _BIG_ENDIAN85#define H 086#define L 187#endif888990/*91* Total number of bits in a long long and in the pieces that make it up.92* These are used for shifting, and also below for halfword extraction93* and assembly.94*/95#define LONGLONG_BITS (sizeof(long long) * CHAR_BIT)96#define INT_BITS (sizeof(int) * CHAR_BIT)97#define HALF_BITS (sizeof(int) * CHAR_BIT / 2)9899/*100* Extract high and low shortwords from longword, and move low shortword of101* longword to upper half of long, i.e., produce the upper longword of102* ((long long)(x) << (number_of_bits_in_int/2)).103* [`x' must actually be unsigned int.]104*105* These are used in the multiply code, to split a longword into upper106* and lower halves, and to reassemble a product as a long long, shifted107* left (sizeof(int)*CHAR_BIT/2).108*/109#define HHALF(x) ((unsigned int)(x) >> HALF_BITS)110#define LHALF(x) ((unsigned int)(x) & (((int)1 << HALF_BITS) - 1))111#define LHUP(x) ((unsigned int)(x) << HALF_BITS)112113long long __adddi3 ( long long, long long);114long long __anddi3 ( long long, long long);115long long __ashldi3 ( long long, unsigned int);116long long __ashrdi3 ( long long, unsigned int);117int __cmpdi2 ( long long, long long);118long long __divdi3 ( long long, long long);119long long __iordi3 ( long long, long long);120long long __lshldi3 ( long long, unsigned int);121long long __lshrdi3 ( long long, unsigned int);122long long __moddi3 ( long long, long long);123long long __muldi3 ( long long, long long);124long long __negdi2 ( long long);125long long __one_cmpldi2 ( long long);126long long __subdi3 ( long long, long long);127int __ucmpdi2 (unsigned long long, unsigned long long);128unsigned long long __udivdi3 (unsigned long long, unsigned long long);129unsigned long long __umoddi3 (unsigned long long, unsigned long long);130long long __xordi3 ( long long, long long);131132#ifndef _KERNEL133long long __fixdfdi (double);134long long __fixsfdi (float);135unsigned long long __fixunsdfdi (double);136unsigned long long __fixunssfdi (float);137double __floatdidf (long long);138float __floatdisf (long long);139double __floatunsdidf(unsigned long long);140#endif141142unsigned long long __qdivrem (unsigned long long, unsigned long long,143unsigned long long *);144145146