11dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project/*- 21dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * Copyright (c) 2003 Mike Barcroft <mike@FreeBSD.org> 31dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * Copyright (c) 2002 David Schultz <das@FreeBSD.ORG> 41dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * All rights reserved. 51dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * 61dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * Redistribution and use in source and binary forms, with or without 71dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * modification, are permitted provided that the following conditions 81dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * are met: 91dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * 1. Redistributions of source code must retain the above copyright 101dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * notice, this list of conditions and the following disclaimer. 111dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * 2. Redistributions in binary form must reproduce the above copyright 121dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * notice, this list of conditions and the following disclaimer in the 131dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * documentation and/or other materials provided with the distribution. 141dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * 151dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 161dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 171dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 181dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 191dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 201dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 211dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 221dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 231dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 241dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 251dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * SUCH DAMAGE. 261dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project * 270f95a553227da1807df4a9bf962434ef79a3e108Elliott Hughes * $FreeBSD$ 281dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project */ 291dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 301abc9ff6a5b5f8a9925f1b8d9d333bc5bc7d407fCalin Juravle// ANDROID changed: 311abc9ff6a5b5f8a9925f1b8d9d333bc5bc7d407fCalin Juravle// - keep only little endian variants as they're the only one supported. 321abc9ff6a5b5f8a9925f1b8d9d333bc5bc7d407fCalin Juravle// - add long double structures here instead of _fpmath.h. 331abc9ff6a5b5f8a9925f1b8d9d333bc5bc7d407fCalin Juravle// - android uses 128 bits long doubles for LP64, so the structure and macros 341abc9ff6a5b5f8a9925f1b8d9d333bc5bc7d407fCalin Juravle// were reworked for the quad precision ieee representation. 351abc9ff6a5b5f8a9925f1b8d9d333bc5bc7d407fCalin Juravle 364d77c1151c40010d137e4a2fa8629bff4bea72b0Calin Juravle#ifndef _FPMATH_ 374d77c1151c40010d137e4a2fa8629bff4bea72b0Calin Juravle#define _FPMATH_ 384d77c1151c40010d137e4a2fa8629bff4bea72b0Calin Juravle 391dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project#include <endian.h> 400f95a553227da1807df4a9bf962434ef79a3e108Elliott Hughes 411dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectunion IEEEf2bits { 421abc9ff6a5b5f8a9925f1b8d9d333bc5bc7d407fCalin Juravle float f; 431abc9ff6a5b5f8a9925f1b8d9d333bc5bc7d407fCalin Juravle struct { 441abc9ff6a5b5f8a9925f1b8d9d333bc5bc7d407fCalin Juravle unsigned int man :23; 451abc9ff6a5b5f8a9925f1b8d9d333bc5bc7d407fCalin Juravle unsigned int exp :8; 461abc9ff6a5b5f8a9925f1b8d9d333bc5bc7d407fCalin Juravle unsigned int sign :1; 471abc9ff6a5b5f8a9925f1b8d9d333bc5bc7d407fCalin Juravle } bits; 481dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project}; 491dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 501abc9ff6a5b5f8a9925f1b8d9d333bc5bc7d407fCalin Juravle#define DBL_MANH_SIZE 20 511abc9ff6a5b5f8a9925f1b8d9d333bc5bc7d407fCalin Juravle#define DBL_MANL_SIZE 32 521dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project 531dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Projectunion IEEEd2bits { 541abc9ff6a5b5f8a9925f1b8d9d333bc5bc7d407fCalin Juravle double d; 551abc9ff6a5b5f8a9925f1b8d9d333bc5bc7d407fCalin Juravle struct { 561abc9ff6a5b5f8a9925f1b8d9d333bc5bc7d407fCalin Juravle unsigned int manl :32; 571abc9ff6a5b5f8a9925f1b8d9d333bc5bc7d407fCalin Juravle unsigned int manh :20; 581abc9ff6a5b5f8a9925f1b8d9d333bc5bc7d407fCalin Juravle unsigned int exp :11; 591abc9ff6a5b5f8a9925f1b8d9d333bc5bc7d407fCalin Juravle unsigned int sign :1; 601abc9ff6a5b5f8a9925f1b8d9d333bc5bc7d407fCalin Juravle } bits; 611dc9e472e19acfe6dc7f41e429236e7eef7ceda1The Android Open Source Project}; 62a0ee07829a9ba7e99ef68e8c12551301cc797f0fElliott Hughes 631abc9ff6a5b5f8a9925f1b8d9d333bc5bc7d407fCalin Juravle#ifdef __LP64__ 641abc9ff6a5b5f8a9925f1b8d9d333bc5bc7d407fCalin Juravle 651abc9ff6a5b5f8a9925f1b8d9d333bc5bc7d407fCalin Juravleunion IEEEl2bits { 661abc9ff6a5b5f8a9925f1b8d9d333bc5bc7d407fCalin Juravle long double e; 671abc9ff6a5b5f8a9925f1b8d9d333bc5bc7d407fCalin Juravle struct { 681abc9ff6a5b5f8a9925f1b8d9d333bc5bc7d407fCalin Juravle unsigned long manl :64; 691abc9ff6a5b5f8a9925f1b8d9d333bc5bc7d407fCalin Juravle unsigned long manh :48; 701abc9ff6a5b5f8a9925f1b8d9d333bc5bc7d407fCalin Juravle unsigned int exp :15; 711abc9ff6a5b5f8a9925f1b8d9d333bc5bc7d407fCalin Juravle unsigned int sign :1; 721abc9ff6a5b5f8a9925f1b8d9d333bc5bc7d407fCalin Juravle } bits; 731abc9ff6a5b5f8a9925f1b8d9d333bc5bc7d407fCalin Juravle struct { 741abc9ff6a5b5f8a9925f1b8d9d333bc5bc7d407fCalin Juravle unsigned long manl :64; 751abc9ff6a5b5f8a9925f1b8d9d333bc5bc7d407fCalin Juravle unsigned long manh :48; 761abc9ff6a5b5f8a9925f1b8d9d333bc5bc7d407fCalin Juravle unsigned int expsign :16; 771abc9ff6a5b5f8a9925f1b8d9d333bc5bc7d407fCalin Juravle } xbits; 781abc9ff6a5b5f8a9925f1b8d9d333bc5bc7d407fCalin Juravle}; 791abc9ff6a5b5f8a9925f1b8d9d333bc5bc7d407fCalin Juravle 801abc9ff6a5b5f8a9925f1b8d9d333bc5bc7d407fCalin Juravle#define LDBL_NBIT 0 811abc9ff6a5b5f8a9925f1b8d9d333bc5bc7d407fCalin Juravle#define LDBL_IMPLICIT_NBIT 821abc9ff6a5b5f8a9925f1b8d9d333bc5bc7d407fCalin Juravle#define mask_nbit_l(u) ((void)0) 831abc9ff6a5b5f8a9925f1b8d9d333bc5bc7d407fCalin Juravle 841abc9ff6a5b5f8a9925f1b8d9d333bc5bc7d407fCalin Juravle#define LDBL_MANH_SIZE 48 851abc9ff6a5b5f8a9925f1b8d9d333bc5bc7d407fCalin Juravle#define LDBL_MANL_SIZE 64 864d77c1151c40010d137e4a2fa8629bff4bea72b0Calin Juravle 871abc9ff6a5b5f8a9925f1b8d9d333bc5bc7d407fCalin Juravle#define LDBL_TO_ARRAY32(u, a) do { \ 881abc9ff6a5b5f8a9925f1b8d9d333bc5bc7d407fCalin Juravle (a)[0] = (uint32_t)(u).bits.manl; \ 891abc9ff6a5b5f8a9925f1b8d9d333bc5bc7d407fCalin Juravle (a)[1] = (uint32_t)((u).bits.manl >> 32); \ 901abc9ff6a5b5f8a9925f1b8d9d333bc5bc7d407fCalin Juravle (a)[2] = (uint32_t)(u).bits.manh; \ 911abc9ff6a5b5f8a9925f1b8d9d333bc5bc7d407fCalin Juravle (a)[3] = (uint32_t)((u).bits.manh >> 32); \ 921abc9ff6a5b5f8a9925f1b8d9d333bc5bc7d407fCalin Juravle} while(0) 934d77c1151c40010d137e4a2fa8629bff4bea72b0Calin Juravle 944d77c1151c40010d137e4a2fa8629bff4bea72b0Calin Juravle#endif // __LP64__ 954d77c1151c40010d137e4a2fa8629bff4bea72b0Calin Juravle 964d77c1151c40010d137e4a2fa8629bff4bea72b0Calin Juravle#endif // _FPMATH_ 97