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