1*e2b9512bSmatt /* $NetBSD: quad.h,v 1.7 2012/08/06 02:31:54 matt Exp $ */ 2275e8bb9Schristos 3275e8bb9Schristos /*- 4275e8bb9Schristos * Copyright (c) 1992, 1993 5275e8bb9Schristos * The Regents of the University of California. All rights reserved. 6275e8bb9Schristos * 7275e8bb9Schristos * This software was developed by the Computer Systems Engineering group 8275e8bb9Schristos * at Lawrence Berkeley Laboratory under DARPA contract BG 91-66 and 9275e8bb9Schristos * contributed to Berkeley. 10275e8bb9Schristos * 11275e8bb9Schristos * Redistribution and use in source and binary forms, with or without 12275e8bb9Schristos * modification, are permitted provided that the following conditions 13275e8bb9Schristos * are met: 14275e8bb9Schristos * 1. Redistributions of source code must retain the above copyright 15275e8bb9Schristos * notice, this list of conditions and the following disclaimer. 16275e8bb9Schristos * 2. Redistributions in binary form must reproduce the above copyright 17275e8bb9Schristos * notice, this list of conditions and the following disclaimer in the 18275e8bb9Schristos * documentation and/or other materials provided with the distribution. 19275e8bb9Schristos * 3. Neither the name of the University nor the names of its contributors 20275e8bb9Schristos * may be used to endorse or promote products derived from this software 21275e8bb9Schristos * without specific prior written permission. 22275e8bb9Schristos * 23275e8bb9Schristos * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 24275e8bb9Schristos * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 25275e8bb9Schristos * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 26275e8bb9Schristos * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 27275e8bb9Schristos * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 28275e8bb9Schristos * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 29275e8bb9Schristos * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 30275e8bb9Schristos * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 31275e8bb9Schristos * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 32275e8bb9Schristos * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 33275e8bb9Schristos * SUCH DAMAGE. 34275e8bb9Schristos * 35275e8bb9Schristos * @(#)quad.h 8.1 (Berkeley) 6/4/93 36275e8bb9Schristos */ 37275e8bb9Schristos 38275e8bb9Schristos /* 39275e8bb9Schristos * Quad arithmetic. 40275e8bb9Schristos * 41275e8bb9Schristos * This library makes the following assumptions: 42275e8bb9Schristos * 43275e8bb9Schristos * - The type long long (aka quad_t) exists. 44275e8bb9Schristos * 45275e8bb9Schristos * - A quad variable is exactly twice as long as `int'. 46275e8bb9Schristos * 47275e8bb9Schristos * - The machine's arithmetic is two's complement. 48275e8bb9Schristos * 49275e8bb9Schristos * This library can provide 128-bit arithmetic on a machine with 128-bit 50275e8bb9Schristos * quads and 64-bit ints, for instance, or 96-bit arithmetic on machines 51275e8bb9Schristos * with 48-bit ints. 52275e8bb9Schristos */ 53275e8bb9Schristos 54275e8bb9Schristos #include <sys/types.h> 55275e8bb9Schristos #if !defined(_KERNEL) && !defined(_STANDALONE) 56275e8bb9Schristos #include <limits.h> 57275e8bb9Schristos #else 58275e8bb9Schristos #include <machine/limits.h> 59275e8bb9Schristos #endif 60275e8bb9Schristos 61*e2b9512bSmatt #if defined(__ARM_EABI__) && !defined(lint) 62*e2b9512bSmatt #define ARM_EABI_ALIAS(alias,sym) __strong_alias(alias,sym); 63*e2b9512bSmatt #else 64*e2b9512bSmatt #define ARM_EABI_ALIAS(alias,sym) /* nothing */ 65*e2b9512bSmatt #endif 66*e2b9512bSmatt 67275e8bb9Schristos /* 68275e8bb9Schristos * Depending on the desired operation, we view a `long long' (aka quad_t) in 69275e8bb9Schristos * one or more of the following formats. 70275e8bb9Schristos */ 71275e8bb9Schristos union uu { 72275e8bb9Schristos quad_t q; /* as a (signed) quad */ 73275e8bb9Schristos u_quad_t uq; /* as an unsigned quad */ 74275e8bb9Schristos int sl[2]; /* as two signed ints */ 75275e8bb9Schristos u_int ul[2]; /* as two unsigned ints */ 76275e8bb9Schristos }; 77275e8bb9Schristos 78275e8bb9Schristos /* 79275e8bb9Schristos * Define high and low parts of a quad_t. 80275e8bb9Schristos */ 81275e8bb9Schristos #define H _QUAD_HIGHWORD 82275e8bb9Schristos #define L _QUAD_LOWWORD 83275e8bb9Schristos 84275e8bb9Schristos /* 85275e8bb9Schristos * Total number of bits in a quad_t and in the pieces that make it up. 86275e8bb9Schristos * These are used for shifting, and also below for halfword extraction 87275e8bb9Schristos * and assembly. 88275e8bb9Schristos */ 89275e8bb9Schristos #define QUAD_BITS (sizeof(quad_t) * CHAR_BIT) 90275e8bb9Schristos #define INT_BITS (sizeof(int) * CHAR_BIT) 91275e8bb9Schristos #define HALF_BITS (sizeof(int) * CHAR_BIT / 2) 92275e8bb9Schristos 93275e8bb9Schristos /* 94275e8bb9Schristos * Extract high and low shortwords from longword, and move low shortword of 95275e8bb9Schristos * longword to upper half of long, i.e., produce the upper longword of 96275e8bb9Schristos * ((quad_t)(x) << (number_of_bits_in_int/2)). (`x' must actually be u_int.) 97275e8bb9Schristos * 98275e8bb9Schristos * These are used in the multiply code, to split a longword into upper 99275e8bb9Schristos * and lower halves, and to reassemble a product as a quad_t, shifted left 100275e8bb9Schristos * (sizeof(int)*CHAR_BIT/2). 101275e8bb9Schristos */ 102275e8bb9Schristos #define HHALF(x) ((u_int)(x) >> HALF_BITS) 103a5fd370aSchristos #define LHALF(x) ((u_int)(x) & (((int)1 << (u_int)HALF_BITS) - 1)) 104a5fd370aSchristos #define LHUP(x) ((u_int)(x) << (u_int)HALF_BITS) 105275e8bb9Schristos 106275e8bb9Schristos /* 107275e8bb9Schristos * XXX 108275e8bb9Schristos * Compensate for gcc 1 vs gcc 2. Gcc 1 defines ?sh?di3's second argument 109275e8bb9Schristos * as u_quad_t, while gcc 2 correctly uses int. Unfortunately, we still use 110275e8bb9Schristos * both compilers. 111275e8bb9Schristos */ 112275e8bb9Schristos #if __GNUC_PREREQ__(2, 0) || defined(lint) 113275e8bb9Schristos typedef unsigned int qshift_t; 114275e8bb9Schristos #else 115275e8bb9Schristos typedef u_quad_t qshift_t; 116275e8bb9Schristos #endif 117275e8bb9Schristos 118275e8bb9Schristos __BEGIN_DECLS 119567219e1Smatt quad_t __adddi3(quad_t, quad_t); 120567219e1Smatt quad_t __anddi3(quad_t, quad_t); 121567219e1Smatt quad_t __ashldi3(quad_t, qshift_t); 122567219e1Smatt quad_t __ashrdi3(quad_t, qshift_t); 123567219e1Smatt int __cmpdi2(quad_t, quad_t); 124567219e1Smatt quad_t __divdi3(quad_t, quad_t); 125567219e1Smatt quad_t __fixtfdi(long double); 126567219e1Smatt quad_t __fixdfdi(double); 127567219e1Smatt quad_t __fixsfdi(float); 128567219e1Smatt u_quad_t __fixunstfdi(long double); 129567219e1Smatt u_quad_t __fixunsdfdi(double); 130567219e1Smatt u_quad_t __fixunssfdi(float); 131567219e1Smatt long double __floatditf(quad_t); 132567219e1Smatt double __floatdidf(quad_t); 133567219e1Smatt float __floatdisf(quad_t); 134567219e1Smatt long double __floatunditf(u_quad_t); 135567219e1Smatt double __floatundidf(u_quad_t); 136567219e1Smatt float __floatundisf(u_quad_t); 137567219e1Smatt quad_t __iordi3(quad_t, quad_t); 138567219e1Smatt quad_t __lshldi3(quad_t, qshift_t); 139567219e1Smatt quad_t __lshrdi3(quad_t, qshift_t); 140567219e1Smatt quad_t __moddi3(quad_t, quad_t); 141567219e1Smatt quad_t __muldi3(quad_t, quad_t); 142567219e1Smatt quad_t __negdi2(quad_t); 143567219e1Smatt quad_t __one_cmpldi2(quad_t); 144567219e1Smatt u_quad_t __qdivrem(u_quad_t, u_quad_t, u_quad_t *); 145567219e1Smatt quad_t __subdi3(quad_t, quad_t); 146567219e1Smatt int __ucmpdi2(u_quad_t, u_quad_t); 147567219e1Smatt u_quad_t __udivdi3(u_quad_t, u_quad_t ); 148567219e1Smatt u_quad_t __umoddi3(u_quad_t, u_quad_t ); 149567219e1Smatt quad_t __xordi3(quad_t, quad_t); 150275e8bb9Schristos __END_DECLS 151