1 /* Id: softfloat.h,v 1.2 2015/11/13 12:47:09 ragge Exp */ 2 /* $NetBSD: softfloat.h,v 1.1.1.1 2016/02/09 20:29:20 plunky Exp $ */ 3 4 /* 5 * Copyright (c) 2015 Anders Magnusson. All rights reserved. 6 * 7 * Redistribution and use in source and binary forms, with or without 8 * modification, are permitted provided that the following conditions 9 * are met: 10 * 1. Redistributions of source code must retain the above copyright 11 * notice, this list of conditions and the following disclaimer. 12 * 2. Redistributions in binary form must reproduce the above copyright 13 * notice, this list of conditions and the following disclaimer in the 14 * documentation and/or other materials provided with the distribution. 15 * 16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR 17 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES 18 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. 19 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, 20 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 21 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 22 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 23 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 24 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 25 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 26 */ 27 28 /* 29 * Definitions for softfloat routines. 30 */ 31 32 33 #define NFAARG ((SZLDOUBLE+SZINT+(SZINT-1))/SZINT) 34 #define FP_TOP (NFAARG-1) 35 union flt { 36 long double fp; 37 int fa[NFAARG]; /* one more than fp size */ 38 }; 39 40 41 union flt flt_zero; 42 43 #ifdef SOFTFLOAT 44 typedef struct softfloat SF; 45 SF soft_neg(SF); 46 SF soft_cast(CONSZ v, TWORD); 47 SF soft_plus(SF, SF); 48 SF soft_minus(SF, SF); 49 SF soft_mul(SF, SF); 50 SF soft_div(SF, SF); 51 int soft_cmp_eq(SF, SF); 52 int soft_cmp_ne(SF, SF); 53 int soft_cmp_ge(SF, SF); 54 int soft_cmp_gt(SF, SF); 55 int soft_cmp_le(SF, SF); 56 int soft_cmp_lt(SF, SF); 57 int soft_isz(SF); 58 CONSZ soft_val(SF); 59 #define FLOAT_NEG(sf) soft_neg(sf) 60 #define FLOAT_CAST(v,t) soft_cast(v, t) 61 #define FLOAT_PLUS(x1,x2) soft_plus(x1, x2) 62 #define FLOAT_MINUS(x1,x2) soft_minus(x1, x2) 63 #define FLOAT_MUL(x1,x2) soft_mul(x1, x2) 64 #define FLOAT_DIV(x1,x2) soft_div(x1, x2) 65 #define FLOAT_ISZERO(sf) soft_isz(sf) 66 #define FLOAT_VAL(sf) soft_val(sf) 67 #define FLOAT_EQ(x1,x2) soft_cmp_eq(x1, x2) 68 #define FLOAT_NE(x1,x2) soft_cmp_ne(x1, x2) 69 #define FLOAT_GE(x1,x2) soft_cmp_ge(x1, x2) 70 #define FLOAT_GT(x1,x2) soft_cmp_gt(x1, x2) 71 #define FLOAT_LE(x1,x2) soft_cmp_le(x1, x2) 72 #define FLOAT_LT(x1,x2) soft_cmp_lt(x1, x2) 73 #else 74 #define FLOAT_NEG(p) (p->fp = -p->fp) 75 #define FLOAT_INT2FP(d,p,v) (ISUNSIGNED(v) ? \ 76 (d->fp = (long double)(U_CONSZ)(p)) : (d->fp = (long double)(CONSZ)(p))) 77 #define FLOAT_FP2INT(i,d,t) (ISUNSIGNED(t) ? \ 78 (i = (U_CONSZ)(d->fp)) : (i = d->fp)) 79 #define FLOAT_FP2FP(d,t) (d->fp = (t == FLOAT ? (float)d->fp : \ 80 t == DOUBLE ? (double)d->fp : d->fp)) 81 #define FLOAT_PLUS(x,x1,x2) (x->fp = (x1)->fp + (x2)->fp) 82 #define FLOAT_MINUS(x,x1,x2) (x->fp = (x1)->fp - (x2)->fp) 83 #define FLOAT_MUL(x,x1,x2) (x->fp = (x1)->fp * (x2)->fp) 84 #define FLOAT_DIV(x,x1,x2) (x->fp = (x1)->fp / (x2)->fp) 85 #define FLOAT_ISZERO(p) ((p)->fp == 0.0) 86 #define FLOAT_VAL(p) (CONSZ)(p) 87 #define FLOAT_EQ(x1,x2) ((x1)->fp == (x2)->fp) 88 #define FLOAT_NE(x1,x2) ((x1)->fp != (x2)->fp) 89 #define FLOAT_GE(x1,x2) ((x1)->fp >= (x2)->fp) 90 #define FLOAT_GT(x1,x2) ((x1)->fp > (x2)->fp) 91 #define FLOAT_LE(x1,x2) ((x1)->fp <= (x2)->fp) 92 #define FLOAT_LT(x1,x2) ((x1)->fp < (x2)->fp) 93 #define FLOAT_ZERO (&flt_zero) 94 #endif 95 96