1*e4b17023SJohn Marino /* Fixed-point arithmetic support. 2*e4b17023SJohn Marino Copyright (C) 2006, 2007, 2009 Free Software Foundation, Inc. 3*e4b17023SJohn Marino 4*e4b17023SJohn Marino This file is part of GCC. 5*e4b17023SJohn Marino 6*e4b17023SJohn Marino GCC is free software; you can redistribute it and/or modify it under 7*e4b17023SJohn Marino the terms of the GNU General Public License as published by the Free 8*e4b17023SJohn Marino Software Foundation; either version 3, or (at your option) any later 9*e4b17023SJohn Marino version. 10*e4b17023SJohn Marino 11*e4b17023SJohn Marino GCC is distributed in the hope that it will be useful, but WITHOUT ANY 12*e4b17023SJohn Marino WARRANTY; without even the implied warranty of MERCHANTABILITY or 13*e4b17023SJohn Marino FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License 14*e4b17023SJohn Marino for more details. 15*e4b17023SJohn Marino 16*e4b17023SJohn Marino You should have received a copy of the GNU General Public License 17*e4b17023SJohn Marino along with GCC; see the file COPYING3. If not see 18*e4b17023SJohn Marino <http://www.gnu.org/licenses/>. */ 19*e4b17023SJohn Marino 20*e4b17023SJohn Marino #ifndef GCC_FIXED_VALUE_H 21*e4b17023SJohn Marino #define GCC_FIXED_VALUE_H 22*e4b17023SJohn Marino 23*e4b17023SJohn Marino #include "machmode.h" 24*e4b17023SJohn Marino #include "real.h" 25*e4b17023SJohn Marino #include "double-int.h" 26*e4b17023SJohn Marino 27*e4b17023SJohn Marino struct GTY(()) fixed_value 28*e4b17023SJohn Marino { 29*e4b17023SJohn Marino double_int data; /* Store data up to 2 wide integers. */ 30*e4b17023SJohn Marino enum machine_mode mode; /* Use machine mode to know IBIT and FBIT. */ 31*e4b17023SJohn Marino }; 32*e4b17023SJohn Marino 33*e4b17023SJohn Marino #define FIXED_VALUE_TYPE struct fixed_value 34*e4b17023SJohn Marino 35*e4b17023SJohn Marino #define MAX_FCONST0 18 /* For storing 18 fixed-point zeros per 36*e4b17023SJohn Marino fract, ufract, accum, and uaccum modes . */ 37*e4b17023SJohn Marino #define MAX_FCONST1 8 /* For storing 8 fixed-point ones per accum 38*e4b17023SJohn Marino and uaccum modes. */ 39*e4b17023SJohn Marino /* Constant fixed-point values 0 and 1. */ 40*e4b17023SJohn Marino extern FIXED_VALUE_TYPE fconst0[MAX_FCONST0]; 41*e4b17023SJohn Marino extern FIXED_VALUE_TYPE fconst1[MAX_FCONST1]; 42*e4b17023SJohn Marino 43*e4b17023SJohn Marino /* Macros to access fconst0 and fconst1 via machine modes. */ 44*e4b17023SJohn Marino #define FCONST0(mode) fconst0[mode - QQmode] 45*e4b17023SJohn Marino #define FCONST1(mode) fconst1[mode - HAmode] 46*e4b17023SJohn Marino 47*e4b17023SJohn Marino /* Return a CONST_FIXED with value R and mode M. */ 48*e4b17023SJohn Marino #define CONST_FIXED_FROM_FIXED_VALUE(r, m) \ 49*e4b17023SJohn Marino const_fixed_from_fixed_value (r, m) 50*e4b17023SJohn Marino extern rtx const_fixed_from_fixed_value (FIXED_VALUE_TYPE, enum machine_mode); 51*e4b17023SJohn Marino 52*e4b17023SJohn Marino /* Initialize from a decimal or hexadecimal string. */ 53*e4b17023SJohn Marino extern void fixed_from_string (FIXED_VALUE_TYPE *, const char *, 54*e4b17023SJohn Marino enum machine_mode); 55*e4b17023SJohn Marino 56*e4b17023SJohn Marino /* In tree.c: wrap up a FIXED_VALUE_TYPE in a tree node. */ 57*e4b17023SJohn Marino extern tree build_fixed (tree, FIXED_VALUE_TYPE); 58*e4b17023SJohn Marino 59*e4b17023SJohn Marino /* Extend or truncate to a new mode. */ 60*e4b17023SJohn Marino extern bool fixed_convert (FIXED_VALUE_TYPE *, enum machine_mode, 61*e4b17023SJohn Marino const FIXED_VALUE_TYPE *, bool); 62*e4b17023SJohn Marino 63*e4b17023SJohn Marino /* Convert to a fixed-point mode from an integer. */ 64*e4b17023SJohn Marino extern bool fixed_convert_from_int (FIXED_VALUE_TYPE *, enum machine_mode, 65*e4b17023SJohn Marino double_int, bool, bool); 66*e4b17023SJohn Marino 67*e4b17023SJohn Marino /* Convert to a fixed-point mode from a real. */ 68*e4b17023SJohn Marino extern bool fixed_convert_from_real (FIXED_VALUE_TYPE *, enum machine_mode, 69*e4b17023SJohn Marino const REAL_VALUE_TYPE *, bool); 70*e4b17023SJohn Marino 71*e4b17023SJohn Marino /* Convert to a real mode from a fixed-point. */ 72*e4b17023SJohn Marino extern void real_convert_from_fixed (REAL_VALUE_TYPE *, enum machine_mode, 73*e4b17023SJohn Marino const FIXED_VALUE_TYPE *); 74*e4b17023SJohn Marino 75*e4b17023SJohn Marino /* Compare two fixed-point objects for bitwise identity. */ 76*e4b17023SJohn Marino extern bool fixed_identical (const FIXED_VALUE_TYPE *, const FIXED_VALUE_TYPE *); 77*e4b17023SJohn Marino 78*e4b17023SJohn Marino /* Calculate a hash value. */ 79*e4b17023SJohn Marino extern unsigned int fixed_hash (const FIXED_VALUE_TYPE *); 80*e4b17023SJohn Marino 81*e4b17023SJohn Marino #define FIXED_VALUES_IDENTICAL(x, y) fixed_identical (&(x), &(y)) 82*e4b17023SJohn Marino 83*e4b17023SJohn Marino /* Determine whether a fixed-point value X is negative. */ 84*e4b17023SJohn Marino #define FIXED_VALUE_NEGATIVE(x) fixed_isneg (&(x)) 85*e4b17023SJohn Marino 86*e4b17023SJohn Marino /* Render F as a decimal floating point constant. */ 87*e4b17023SJohn Marino extern void fixed_to_decimal (char *str, const FIXED_VALUE_TYPE *, size_t); 88*e4b17023SJohn Marino 89*e4b17023SJohn Marino /* Binary or unary arithmetic on tree_code. */ 90*e4b17023SJohn Marino extern bool fixed_arithmetic (FIXED_VALUE_TYPE *, int, const FIXED_VALUE_TYPE *, 91*e4b17023SJohn Marino const FIXED_VALUE_TYPE *, bool); 92*e4b17023SJohn Marino 93*e4b17023SJohn Marino /* Compare fixed-point values by tree_code. */ 94*e4b17023SJohn Marino extern bool fixed_compare (int, const FIXED_VALUE_TYPE *, 95*e4b17023SJohn Marino const FIXED_VALUE_TYPE *); 96*e4b17023SJohn Marino 97*e4b17023SJohn Marino /* Determine whether a fixed-point value X is negative. */ 98*e4b17023SJohn Marino extern bool fixed_isneg (const FIXED_VALUE_TYPE *); 99*e4b17023SJohn Marino 100*e4b17023SJohn Marino #endif /* GCC_FIXED_VALUE_H */ 101