machmode.h 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363
  1. /* Machine mode definitions for GCC; included by rtl.h and tree.h.
  2. Copyright (C) 1991-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 HAVE_MACHINE_MODES
  16. #define HAVE_MACHINE_MODES
  17. /* Make an enum class that gives all the machine modes. */
  18. #include "insn-modes.h"
  19. /* Get the name of mode MODE as a string. */
  20. extern const char * const mode_name[NUM_MACHINE_MODES];
  21. #define GET_MODE_NAME(MODE) mode_name[MODE]
  22. /* Mode classes. */
  23. #include "mode-classes.def"
  24. #define DEF_MODE_CLASS(M) M
  25. enum mode_class { MODE_CLASSES, MAX_MODE_CLASS };
  26. #undef DEF_MODE_CLASS
  27. #undef MODE_CLASSES
  28. /* Get the general kind of object that mode MODE represents
  29. (integer, floating, complex, etc.) */
  30. extern const unsigned char mode_class[NUM_MACHINE_MODES];
  31. #define GET_MODE_CLASS(MODE) ((enum mode_class) mode_class[MODE])
  32. /* Nonzero if MODE is an integral mode. */
  33. #define INTEGRAL_MODE_P(MODE) \
  34. (GET_MODE_CLASS (MODE) == MODE_INT \
  35. || GET_MODE_CLASS (MODE) == MODE_PARTIAL_INT \
  36. || GET_MODE_CLASS (MODE) == MODE_COMPLEX_INT \
  37. || GET_MODE_CLASS (MODE) == MODE_VECTOR_INT)
  38. /* Nonzero if MODE is a floating-point mode. */
  39. #define FLOAT_MODE_P(MODE) \
  40. (GET_MODE_CLASS (MODE) == MODE_FLOAT \
  41. || GET_MODE_CLASS (MODE) == MODE_DECIMAL_FLOAT \
  42. || GET_MODE_CLASS (MODE) == MODE_COMPLEX_FLOAT \
  43. || GET_MODE_CLASS (MODE) == MODE_VECTOR_FLOAT)
  44. /* Nonzero if MODE is a complex mode. */
  45. #define COMPLEX_MODE_P(MODE) \
  46. (GET_MODE_CLASS (MODE) == MODE_COMPLEX_INT \
  47. || GET_MODE_CLASS (MODE) == MODE_COMPLEX_FLOAT)
  48. /* Nonzero if MODE is a vector mode. */
  49. #define VECTOR_MODE_P(MODE) \
  50. (GET_MODE_CLASS (MODE) == MODE_VECTOR_INT \
  51. || GET_MODE_CLASS (MODE) == MODE_VECTOR_FLOAT \
  52. || GET_MODE_CLASS (MODE) == MODE_VECTOR_FRACT \
  53. || GET_MODE_CLASS (MODE) == MODE_VECTOR_UFRACT \
  54. || GET_MODE_CLASS (MODE) == MODE_VECTOR_ACCUM \
  55. || GET_MODE_CLASS (MODE) == MODE_VECTOR_UACCUM)
  56. /* Nonzero if MODE is a scalar integral mode. */
  57. #define SCALAR_INT_MODE_P(MODE) \
  58. (GET_MODE_CLASS (MODE) == MODE_INT \
  59. || GET_MODE_CLASS (MODE) == MODE_PARTIAL_INT)
  60. /* Nonzero if MODE is a scalar floating point mode. */
  61. #define SCALAR_FLOAT_MODE_P(MODE) \
  62. (GET_MODE_CLASS (MODE) == MODE_FLOAT \
  63. || GET_MODE_CLASS (MODE) == MODE_DECIMAL_FLOAT)
  64. /* Nonzero if MODE is a decimal floating point mode. */
  65. #define DECIMAL_FLOAT_MODE_P(MODE) \
  66. (GET_MODE_CLASS (MODE) == MODE_DECIMAL_FLOAT)
  67. /* Nonzero if MODE is a scalar fract mode. */
  68. #define SCALAR_FRACT_MODE_P(MODE) \
  69. (GET_MODE_CLASS (MODE) == MODE_FRACT)
  70. /* Nonzero if MODE is a scalar ufract mode. */
  71. #define SCALAR_UFRACT_MODE_P(MODE) \
  72. (GET_MODE_CLASS (MODE) == MODE_UFRACT)
  73. /* Nonzero if MODE is a scalar fract or ufract mode. */
  74. #define ALL_SCALAR_FRACT_MODE_P(MODE) \
  75. (SCALAR_FRACT_MODE_P (MODE) || SCALAR_UFRACT_MODE_P (MODE))
  76. /* Nonzero if MODE is a scalar accum mode. */
  77. #define SCALAR_ACCUM_MODE_P(MODE) \
  78. (GET_MODE_CLASS (MODE) == MODE_ACCUM)
  79. /* Nonzero if MODE is a scalar uaccum mode. */
  80. #define SCALAR_UACCUM_MODE_P(MODE) \
  81. (GET_MODE_CLASS (MODE) == MODE_UACCUM)
  82. /* Nonzero if MODE is a scalar accum or uaccum mode. */
  83. #define ALL_SCALAR_ACCUM_MODE_P(MODE) \
  84. (SCALAR_ACCUM_MODE_P (MODE) || SCALAR_UACCUM_MODE_P (MODE))
  85. /* Nonzero if MODE is a scalar fract or accum mode. */
  86. #define SIGNED_SCALAR_FIXED_POINT_MODE_P(MODE) \
  87. (SCALAR_FRACT_MODE_P (MODE) || SCALAR_ACCUM_MODE_P (MODE))
  88. /* Nonzero if MODE is a scalar ufract or uaccum mode. */
  89. #define UNSIGNED_SCALAR_FIXED_POINT_MODE_P(MODE) \
  90. (SCALAR_UFRACT_MODE_P (MODE) || SCALAR_UACCUM_MODE_P (MODE))
  91. /* Nonzero if MODE is a scalar fract, ufract, accum or uaccum mode. */
  92. #define ALL_SCALAR_FIXED_POINT_MODE_P(MODE) \
  93. (SIGNED_SCALAR_FIXED_POINT_MODE_P (MODE) \
  94. || UNSIGNED_SCALAR_FIXED_POINT_MODE_P (MODE))
  95. /* Nonzero if MODE is a scalar/vector fract mode. */
  96. #define FRACT_MODE_P(MODE) \
  97. (GET_MODE_CLASS (MODE) == MODE_FRACT \
  98. || GET_MODE_CLASS (MODE) == MODE_VECTOR_FRACT)
  99. /* Nonzero if MODE is a scalar/vector ufract mode. */
  100. #define UFRACT_MODE_P(MODE) \
  101. (GET_MODE_CLASS (MODE) == MODE_UFRACT \
  102. || GET_MODE_CLASS (MODE) == MODE_VECTOR_UFRACT)
  103. /* Nonzero if MODE is a scalar/vector fract or ufract mode. */
  104. #define ALL_FRACT_MODE_P(MODE) \
  105. (FRACT_MODE_P (MODE) || UFRACT_MODE_P (MODE))
  106. /* Nonzero if MODE is a scalar/vector accum mode. */
  107. #define ACCUM_MODE_P(MODE) \
  108. (GET_MODE_CLASS (MODE) == MODE_ACCUM \
  109. || GET_MODE_CLASS (MODE) == MODE_VECTOR_ACCUM)
  110. /* Nonzero if MODE is a scalar/vector uaccum mode. */
  111. #define UACCUM_MODE_P(MODE) \
  112. (GET_MODE_CLASS (MODE) == MODE_UACCUM \
  113. || GET_MODE_CLASS (MODE) == MODE_VECTOR_UACCUM)
  114. /* Nonzero if MODE is a scalar/vector accum or uaccum mode. */
  115. #define ALL_ACCUM_MODE_P(MODE) \
  116. (ACCUM_MODE_P (MODE) || UACCUM_MODE_P (MODE))
  117. /* Nonzero if MODE is a scalar/vector fract or accum mode. */
  118. #define SIGNED_FIXED_POINT_MODE_P(MODE) \
  119. (FRACT_MODE_P (MODE) || ACCUM_MODE_P (MODE))
  120. /* Nonzero if MODE is a scalar/vector ufract or uaccum mode. */
  121. #define UNSIGNED_FIXED_POINT_MODE_P(MODE) \
  122. (UFRACT_MODE_P (MODE) || UACCUM_MODE_P (MODE))
  123. /* Nonzero if MODE is a scalar/vector fract, ufract, accum or uaccum mode. */
  124. #define ALL_FIXED_POINT_MODE_P(MODE) \
  125. (SIGNED_FIXED_POINT_MODE_P (MODE) \
  126. || UNSIGNED_FIXED_POINT_MODE_P (MODE))
  127. /* Nonzero if CLASS modes can be widened. */
  128. #define CLASS_HAS_WIDER_MODES_P(CLASS) \
  129. (CLASS == MODE_INT \
  130. || CLASS == MODE_PARTIAL_INT \
  131. || CLASS == MODE_FLOAT \
  132. || CLASS == MODE_DECIMAL_FLOAT \
  133. || CLASS == MODE_COMPLEX_FLOAT \
  134. || CLASS == MODE_FRACT \
  135. || CLASS == MODE_UFRACT \
  136. || CLASS == MODE_ACCUM \
  137. || CLASS == MODE_UACCUM)
  138. #define POINTER_BOUNDS_MODE_P(MODE) \
  139. (GET_MODE_CLASS (MODE) == MODE_POINTER_BOUNDS)
  140. /* Get the size in bytes and bits of an object of mode MODE. */
  141. extern CONST_MODE_SIZE unsigned char mode_size[NUM_MACHINE_MODES];
  142. #if GCC_VERSION >= 4001
  143. #define GET_MODE_SIZE(MODE) \
  144. ((unsigned short) (__builtin_constant_p (MODE) \
  145. ? mode_size_inline (MODE) : mode_size[MODE]))
  146. #else
  147. #define GET_MODE_SIZE(MODE) ((unsigned short) mode_size[MODE])
  148. #endif
  149. #define GET_MODE_BITSIZE(MODE) \
  150. ((unsigned short) (GET_MODE_SIZE (MODE) * BITS_PER_UNIT))
  151. /* Get the number of value bits of an object of mode MODE. */
  152. extern const unsigned short mode_precision[NUM_MACHINE_MODES];
  153. #define GET_MODE_PRECISION(MODE) mode_precision[MODE]
  154. /* Get the number of integral bits of an object of mode MODE. */
  155. extern CONST_MODE_IBIT unsigned char mode_ibit[NUM_MACHINE_MODES];
  156. #define GET_MODE_IBIT(MODE) mode_ibit[MODE]
  157. /* Get the number of fractional bits of an object of mode MODE. */
  158. extern CONST_MODE_FBIT unsigned char mode_fbit[NUM_MACHINE_MODES];
  159. #define GET_MODE_FBIT(MODE) mode_fbit[MODE]
  160. /* Get a bitmask containing 1 for all bits in a word
  161. that fit within mode MODE. */
  162. extern const unsigned HOST_WIDE_INT mode_mask_array[NUM_MACHINE_MODES];
  163. #define GET_MODE_MASK(MODE) mode_mask_array[MODE]
  164. /* Return the mode of the inner elements in a vector. */
  165. extern const unsigned char mode_inner[NUM_MACHINE_MODES];
  166. #if GCC_VERSION >= 4001
  167. #define GET_MODE_INNER(MODE) \
  168. ((machine_mode) (__builtin_constant_p (MODE) \
  169. ? mode_inner_inline (MODE) : mode_inner[MODE]))
  170. #else
  171. #define GET_MODE_INNER(MODE) ((machine_mode) mode_inner[MODE])
  172. #endif
  173. /* Get the size in bytes or bites of the basic parts of an
  174. object of mode MODE. */
  175. #define GET_MODE_UNIT_SIZE(MODE) \
  176. (GET_MODE_INNER (MODE) == VOIDmode \
  177. ? GET_MODE_SIZE (MODE) \
  178. : GET_MODE_SIZE (GET_MODE_INNER (MODE)))
  179. #define GET_MODE_UNIT_BITSIZE(MODE) \
  180. ((unsigned short) (GET_MODE_UNIT_SIZE (MODE) * BITS_PER_UNIT))
  181. #define GET_MODE_UNIT_PRECISION(MODE) \
  182. (GET_MODE_INNER (MODE) == VOIDmode \
  183. ? GET_MODE_PRECISION (MODE) \
  184. : GET_MODE_PRECISION (GET_MODE_INNER (MODE)))
  185. /* Get the number of units in the object. */
  186. extern const unsigned char mode_nunits[NUM_MACHINE_MODES];
  187. #if GCC_VERSION >= 4001
  188. #define GET_MODE_NUNITS(MODE) \
  189. ((unsigned char) (__builtin_constant_p (MODE) \
  190. ? mode_nunits_inline (MODE) : mode_nunits[MODE]))
  191. #else
  192. #define GET_MODE_NUNITS(MODE) mode_nunits[MODE]
  193. #endif
  194. /* Get the next wider natural mode (eg, QI -> HI -> SI -> DI -> TI). */
  195. extern const unsigned char mode_wider[NUM_MACHINE_MODES];
  196. #define GET_MODE_WIDER_MODE(MODE) ((machine_mode) mode_wider[MODE])
  197. /* For scalars, this is a mode with twice the precision. For vectors,
  198. this is a mode with the same inner mode but with twice the elements. */
  199. extern const unsigned char mode_2xwider[NUM_MACHINE_MODES];
  200. #define GET_MODE_2XWIDER_MODE(MODE) ((machine_mode) mode_2xwider[MODE])
  201. /* Return the mode for data of a given size SIZE and mode class CLASS.
  202. If LIMIT is nonzero, then don't use modes bigger than MAX_FIXED_MODE_SIZE.
  203. The value is BLKmode if no other mode is found. */
  204. extern machine_mode mode_for_size (unsigned int, enum mode_class, int);
  205. /* Similar, but find the smallest mode for a given width. */
  206. extern machine_mode smallest_mode_for_size (unsigned int,
  207. enum mode_class);
  208. /* Return an integer mode of the exact same size as the input mode,
  209. or BLKmode on failure. */
  210. extern machine_mode int_mode_for_mode (machine_mode);
  211. extern machine_mode bitwise_mode_for_mode (machine_mode);
  212. /* Return a mode that is suitable for representing a vector,
  213. or BLKmode on failure. */
  214. extern machine_mode mode_for_vector (machine_mode, unsigned);
  215. /* A class for iterating through possible bitfield modes. */
  216. class bit_field_mode_iterator
  217. {
  218. public:
  219. bit_field_mode_iterator (HOST_WIDE_INT, HOST_WIDE_INT,
  220. HOST_WIDE_INT, HOST_WIDE_INT,
  221. unsigned int, bool);
  222. bool next_mode (machine_mode *);
  223. bool prefer_smaller_modes ();
  224. private:
  225. machine_mode m_mode;
  226. /* We use signed values here because the bit position can be negative
  227. for invalid input such as gcc.dg/pr48335-8.c. */
  228. HOST_WIDE_INT m_bitsize;
  229. HOST_WIDE_INT m_bitpos;
  230. HOST_WIDE_INT m_bitregion_start;
  231. HOST_WIDE_INT m_bitregion_end;
  232. unsigned int m_align;
  233. bool m_volatilep;
  234. int m_count;
  235. };
  236. /* Find the best mode to use to access a bit field. */
  237. extern machine_mode get_best_mode (int, int,
  238. unsigned HOST_WIDE_INT,
  239. unsigned HOST_WIDE_INT,
  240. unsigned int,
  241. machine_mode, bool);
  242. /* Determine alignment, 1<=result<=BIGGEST_ALIGNMENT. */
  243. extern CONST_MODE_BASE_ALIGN unsigned char mode_base_align[NUM_MACHINE_MODES];
  244. extern unsigned get_mode_alignment (machine_mode);
  245. #define GET_MODE_ALIGNMENT(MODE) get_mode_alignment (MODE)
  246. /* Get the precision of the mode or its inner mode if it has one. */
  247. extern unsigned int element_precision (machine_mode);
  248. /* For each class, get the narrowest mode in that class. */
  249. extern const unsigned char class_narrowest_mode[MAX_MODE_CLASS];
  250. #define GET_CLASS_NARROWEST_MODE(CLASS) \
  251. ((machine_mode) class_narrowest_mode[CLASS])
  252. /* Define the integer modes whose sizes are BITS_PER_UNIT and BITS_PER_WORD
  253. and the mode whose class is Pmode and whose size is POINTER_SIZE. */
  254. extern machine_mode byte_mode;
  255. extern machine_mode word_mode;
  256. extern machine_mode ptr_mode;
  257. /* Target-dependent machine mode initialization - in insn-modes.c. */
  258. extern void init_adjust_machine_modes (void);
  259. #define TRULY_NOOP_TRUNCATION_MODES_P(MODE1, MODE2) \
  260. TRULY_NOOP_TRUNCATION (GET_MODE_PRECISION (MODE1), \
  261. GET_MODE_PRECISION (MODE2))
  262. #define HWI_COMPUTABLE_MODE_P(MODE) \
  263. (SCALAR_INT_MODE_P (MODE) \
  264. && GET_MODE_PRECISION (MODE) <= HOST_BITS_PER_WIDE_INT)
  265. typedef struct {
  266. /* These parts are initailized by genmodes output */
  267. unsigned int bitsize;
  268. machine_mode m;
  269. /* RID_* is RID_INTN_BASE + index into this array */
  270. } int_n_data_t;
  271. /* This is also in tree.h. genmodes.c guarantees the're sorted from
  272. smallest bitsize to largest bitsize. */
  273. extern bool int_n_enabled_p[NUM_INT_N_ENTS];
  274. extern const int_n_data_t int_n_data[NUM_INT_N_ENTS];
  275. #endif /* not HAVE_MACHINE_MODES */