fixed-value.h 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. /* Fixed-point arithmetic support.
  2. Copyright (C) 2006-2015 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. #include "machmode.h"
  18. #include "real.h"
  19. #include "double-int.h"
  20. struct GTY(()) fixed_value
  21. {
  22. double_int data; /* Store data up to 2 wide integers. */
  23. machine_mode mode; /* Use machine mode to know IBIT and FBIT. */
  24. };
  25. #define FIXED_VALUE_TYPE struct fixed_value
  26. #define MAX_FCONST0 18 /* For storing 18 fixed-point zeros per
  27. fract, ufract, accum, and uaccum modes . */
  28. #define MAX_FCONST1 8 /* For storing 8 fixed-point ones per accum
  29. and uaccum modes. */
  30. /* Constant fixed-point values 0 and 1. */
  31. extern FIXED_VALUE_TYPE fconst0[MAX_FCONST0];
  32. extern FIXED_VALUE_TYPE fconst1[MAX_FCONST1];
  33. /* Macros to access fconst0 and fconst1 via machine modes. */
  34. #define FCONST0(mode) fconst0[mode - QQmode]
  35. #define FCONST1(mode) fconst1[mode - HAmode]
  36. /* Return a CONST_FIXED with value R and mode M. */
  37. #define CONST_FIXED_FROM_FIXED_VALUE(r, m) \
  38. const_fixed_from_fixed_value (r, m)
  39. extern rtx const_fixed_from_fixed_value (FIXED_VALUE_TYPE, machine_mode);
  40. /* Construct a FIXED_VALUE from a bit payload and machine mode MODE.
  41. The bits in PAYLOAD are sign-extended/zero-extended according to MODE. */
  42. extern FIXED_VALUE_TYPE fixed_from_double_int (double_int,
  43. machine_mode);
  44. /* Return a CONST_FIXED from a bit payload and machine mode MODE.
  45. The bits in PAYLOAD are sign-extended/zero-extended according to MODE. */
  46. static inline rtx
  47. const_fixed_from_double_int (double_int payload,
  48. machine_mode mode)
  49. {
  50. return
  51. const_fixed_from_fixed_value (fixed_from_double_int (payload, mode),
  52. mode);
  53. }
  54. /* Initialize from a decimal or hexadecimal string. */
  55. extern void fixed_from_string (FIXED_VALUE_TYPE *, const char *,
  56. machine_mode);
  57. /* In tree.c: wrap up a FIXED_VALUE_TYPE in a tree node. */
  58. extern tree build_fixed (tree, FIXED_VALUE_TYPE);
  59. /* Extend or truncate to a new mode. */
  60. extern bool fixed_convert (FIXED_VALUE_TYPE *, machine_mode,
  61. const FIXED_VALUE_TYPE *, bool);
  62. /* Convert to a fixed-point mode from an integer. */
  63. extern bool fixed_convert_from_int (FIXED_VALUE_TYPE *, machine_mode,
  64. double_int, bool, bool);
  65. /* Convert to a fixed-point mode from a real. */
  66. extern bool fixed_convert_from_real (FIXED_VALUE_TYPE *, machine_mode,
  67. const REAL_VALUE_TYPE *, bool);
  68. /* Convert to a real mode from a fixed-point. */
  69. extern void real_convert_from_fixed (REAL_VALUE_TYPE *, machine_mode,
  70. const FIXED_VALUE_TYPE *);
  71. /* Compare two fixed-point objects for bitwise identity. */
  72. extern bool fixed_identical (const FIXED_VALUE_TYPE *, const FIXED_VALUE_TYPE *);
  73. /* Calculate a hash value. */
  74. extern unsigned int fixed_hash (const FIXED_VALUE_TYPE *);
  75. #define FIXED_VALUES_IDENTICAL(x, y) fixed_identical (&(x), &(y))
  76. /* Determine whether a fixed-point value X is negative. */
  77. #define FIXED_VALUE_NEGATIVE(x) fixed_isneg (&(x))
  78. /* Render F as a decimal floating point constant. */
  79. extern void fixed_to_decimal (char *str, const FIXED_VALUE_TYPE *, size_t);
  80. /* Binary or unary arithmetic on tree_code. */
  81. extern bool fixed_arithmetic (FIXED_VALUE_TYPE *, int, const FIXED_VALUE_TYPE *,
  82. const FIXED_VALUE_TYPE *, bool);
  83. /* Compare fixed-point values by tree_code. */
  84. extern bool fixed_compare (int, const FIXED_VALUE_TYPE *,
  85. const FIXED_VALUE_TYPE *);
  86. /* Determine whether a fixed-point value X is negative. */
  87. extern bool fixed_isneg (const FIXED_VALUE_TYPE *);
  88. #endif /* GCC_FIXED_VALUE_H */