fixed-value.h 4.1 KB

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