1/* 2 * QEMU float support 3 * 4 * The code in this source file is derived from release 2a of the SoftFloat 5 * IEC/IEEE Floating-point Arithmetic Package. Those parts of the code (and 6 * some later contributions) are provided under that license, as detailed below. 7 * It has subsequently been modified by contributors to the QEMU Project, 8 * so some portions are provided under: 9 * the SoftFloat-2a license 10 * the BSD license 11 * GPL-v2-or-later 12 * 13 * This header holds definitions for code that might be dealing with 14 * softfloat types but not need access to the actual library functions. 15 */ 16/* 17=============================================================================== 18This C header file is part of the SoftFloat IEC/IEEE Floating-point 19Arithmetic Package, Release 2a. 20 21Written by John R. Hauser. This work was made possible in part by the 22International Computer Science Institute, located at Suite 600, 1947 Center 23Street, Berkeley, California 94704. Funding was partially provided by the 24National Science Foundation under grant MIP-9311980. The original version 25of this code was written as part of a project to build a fixed-point vector 26processor in collaboration with the University of California at Berkeley, 27overseen by Profs. Nelson Morgan and John Wawrzynek. More information 28is available through the Web page `http://HTTP.CS.Berkeley.EDU/~jhauser/ 29arithmetic/SoftFloat.html'. 30 31THIS SOFTWARE IS DISTRIBUTED AS IS, FOR FREE. Although reasonable effort 32has been made to avoid it, THIS SOFTWARE MAY CONTAIN FAULTS THAT WILL AT 33TIMES RESULT IN INCORRECT BEHAVIOR. USE OF THIS SOFTWARE IS RESTRICTED TO 34PERSONS AND ORGANIZATIONS WHO CAN AND WILL TAKE FULL RESPONSIBILITY FOR ANY 35AND ALL LOSSES, COSTS, OR OTHER PROBLEMS ARISING FROM ITS USE. 36 37Derivative works are acceptable, even for commercial purposes, so long as 38(1) they include prominent notice that the work is derivative, and (2) they 39include prominent notice akin to these four paragraphs for those parts of 40this code that are retained. 41 42=============================================================================== 43*/ 44 45/* BSD licensing: 46 * Copyright (c) 2006, Fabrice Bellard 47 * All rights reserved. 48 * 49 * Redistribution and use in source and binary forms, with or without 50 * modification, are permitted provided that the following conditions are met: 51 * 52 * 1. Redistributions of source code must retain the above copyright notice, 53 * this list of conditions and the following disclaimer. 54 * 55 * 2. Redistributions in binary form must reproduce the above copyright notice, 56 * this list of conditions and the following disclaimer in the documentation 57 * and/or other materials provided with the distribution. 58 * 59 * 3. Neither the name of the copyright holder nor the names of its contributors 60 * may be used to endorse or promote products derived from this software without 61 * specific prior written permission. 62 * 63 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" 64 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 65 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 66 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE 67 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 68 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 69 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 70 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 71 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 72 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF 73 * THE POSSIBILITY OF SUCH DAMAGE. 74 */ 75 76/* Portions of this work are licensed under the terms of the GNU GPL, 77 * version 2 or later. See the COPYING file in the top-level directory. 78 */ 79 80#ifndef SOFTFLOAT_TYPES_H 81#define SOFTFLOAT_TYPES_H 82 83/* This 'flag' type must be able to hold at least 0 and 1. It should 84 * probably be replaced with 'bool' but the uses would need to be audited 85 * to check that they weren't accidentally relying on it being a larger type. 86 */ 87typedef uint8_t flag; 88 89/* 90 * Software IEC/IEEE floating-point types. 91 */ 92 93typedef uint16_t float16; 94typedef uint32_t float32; 95typedef uint64_t float64; 96#define float16_val(x) (x) 97#define float32_val(x) (x) 98#define float64_val(x) (x) 99#define make_float16(x) (x) 100#define make_float32(x) (x) 101#define make_float64(x) (x) 102#define const_float16(x) (x) 103#define const_float32(x) (x) 104#define const_float64(x) (x) 105typedef struct { 106 uint64_t low; 107 uint16_t high; 108} floatx80; 109#define make_floatx80(exp, mant) ((floatx80) { mant, exp }) 110#define make_floatx80_init(exp, mant) { .low = mant, .high = exp } 111typedef struct { 112#ifdef HOST_WORDS_BIGENDIAN 113 uint64_t high, low; 114#else 115 uint64_t low, high; 116#endif 117} float128; 118#define make_float128(high_, low_) ((float128) { .high = high_, .low = low_ }) 119#define make_float128_init(high_, low_) { .high = high_, .low = low_ } 120 121/* 122 * Software IEC/IEEE floating-point underflow tininess-detection mode. 123 */ 124 125enum { 126 float_tininess_after_rounding = 0, 127 float_tininess_before_rounding = 1 128}; 129 130/* 131 *Software IEC/IEEE floating-point rounding mode. 132 */ 133 134enum { 135 float_round_nearest_even = 0, 136 float_round_down = 1, 137 float_round_up = 2, 138 float_round_to_zero = 3, 139 float_round_ties_away = 4, 140 /* Not an IEEE rounding mode: round to the closest odd mantissa value */ 141 float_round_to_odd = 5, 142}; 143 144/* 145 * Software IEC/IEEE floating-point exception flags. 146 */ 147 148enum { 149 float_flag_invalid = 1, 150 float_flag_divbyzero = 4, 151 float_flag_overflow = 8, 152 float_flag_underflow = 16, 153 float_flag_inexact = 32, 154 float_flag_input_denormal = 64, 155 float_flag_output_denormal = 128 156}; 157 158 159/* 160 * Floating Point Status. Individual architectures may maintain 161 * several versions of float_status for different functions. The 162 * correct status for the operation is then passed by reference to 163 * most of the softfloat functions. 164 */ 165 166typedef struct float_status { 167 signed char float_detect_tininess; 168 signed char float_rounding_mode; 169 uint8_t float_exception_flags; 170 signed char floatx80_rounding_precision; 171 /* should denormalised results go to zero and set the inexact flag? */ 172 flag flush_to_zero; 173 /* should denormalised inputs go to zero and set the input_denormal flag? */ 174 flag flush_inputs_to_zero; 175 flag default_nan_mode; 176 /* not always used -- see snan_bit_is_one() in softfloat-specialize.h */ 177 flag snan_bit_is_one; 178} float_status; 179 180#endif /* SOFTFLOAT_TYPES_H */ 181