您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

1202 行
33KB

  1. /* Machine mode definitions for GCC; included by rtl.h and tree.h.
  2. Copyright (C) 1991-2020 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. typedef opt_mode<machine_mode> opt_machine_mode;
  18. extern CONST_MODE_SIZE poly_uint16_pod mode_size[NUM_MACHINE_MODES];
  19. extern CONST_MODE_PRECISION poly_uint16_pod mode_precision[NUM_MACHINE_MODES];
  20. extern const unsigned char mode_inner[NUM_MACHINE_MODES];
  21. extern CONST_MODE_NUNITS poly_uint16_pod mode_nunits[NUM_MACHINE_MODES];
  22. extern CONST_MODE_UNIT_SIZE unsigned char mode_unit_size[NUM_MACHINE_MODES];
  23. extern const unsigned short mode_unit_precision[NUM_MACHINE_MODES];
  24. extern const unsigned char mode_wider[NUM_MACHINE_MODES];
  25. extern const unsigned char mode_2xwider[NUM_MACHINE_MODES];
  26. template<typename T>
  27. struct mode_traits
  28. {
  29. /* For use by the machmode support code only.
  30. There are cases in which the machmode support code needs to forcibly
  31. convert a machine_mode to a specific mode class T, and in which the
  32. context guarantees that this is valid without the need for an assert.
  33. This can be done using:
  34. return typename mode_traits<T>::from_int (mode);
  35. when returning a T and:
  36. res = T (typename mode_traits<T>::from_int (mode));
  37. when assigning to a value RES that must be assignment-compatible
  38. with (but possibly not the same as) T. */
  39. #ifdef USE_ENUM_MODES
  40. /* Allow direct conversion of enums to specific mode classes only
  41. when USE_ENUM_MODES is defined. This is only intended for use
  42. by gencondmd, so that it can tell more easily when .md conditions
  43. are always false. */
  44. typedef machine_mode from_int;
  45. #else
  46. /* Here we use an enum type distinct from machine_mode but with the
  47. same range as machine_mode. T should have a constructor that
  48. accepts this enum type; it should not have a constructor that
  49. accepts machine_mode.
  50. We use this somewhat indirect approach to avoid too many constructor
  51. calls when the compiler is built with -O0. For example, even in
  52. unoptimized code, the return statement above would construct the
  53. returned T directly from the numerical value of MODE. */
  54. enum from_int { dummy = MAX_MACHINE_MODE };
  55. #endif
  56. };
  57. template<>
  58. struct mode_traits<machine_mode>
  59. {
  60. /* machine_mode itself needs no conversion. */
  61. typedef machine_mode from_int;
  62. };
  63. /* Always treat machine modes as fixed-size while compiling code specific
  64. to targets that have no variable-size modes. */
  65. #if defined (IN_TARGET_CODE) && NUM_POLY_INT_COEFFS == 1
  66. #define ONLY_FIXED_SIZE_MODES 1
  67. #else
  68. #define ONLY_FIXED_SIZE_MODES 0
  69. #endif
  70. /* Get the name of mode MODE as a string. */
  71. extern const char * const mode_name[NUM_MACHINE_MODES];
  72. #define GET_MODE_NAME(MODE) mode_name[MODE]
  73. /* Mode classes. */
  74. #include "mode-classes.def"
  75. #define DEF_MODE_CLASS(M) M
  76. enum mode_class { MODE_CLASSES, MAX_MODE_CLASS };
  77. #undef DEF_MODE_CLASS
  78. #undef MODE_CLASSES
  79. /* Get the general kind of object that mode MODE represents
  80. (integer, floating, complex, etc.) */
  81. extern const unsigned char mode_class[NUM_MACHINE_MODES];
  82. #define GET_MODE_CLASS(MODE) ((enum mode_class) mode_class[MODE])
  83. /* Nonzero if MODE is an integral mode. */
  84. #define INTEGRAL_MODE_P(MODE) \
  85. (GET_MODE_CLASS (MODE) == MODE_INT \
  86. || GET_MODE_CLASS (MODE) == MODE_PARTIAL_INT \
  87. || GET_MODE_CLASS (MODE) == MODE_COMPLEX_INT \
  88. || GET_MODE_CLASS (MODE) == MODE_VECTOR_BOOL \
  89. || GET_MODE_CLASS (MODE) == MODE_VECTOR_INT)
  90. /* Nonzero if MODE is a floating-point mode. */
  91. #define FLOAT_MODE_P(MODE) \
  92. (GET_MODE_CLASS (MODE) == MODE_FLOAT \
  93. || GET_MODE_CLASS (MODE) == MODE_DECIMAL_FLOAT \
  94. || GET_MODE_CLASS (MODE) == MODE_COMPLEX_FLOAT \
  95. || GET_MODE_CLASS (MODE) == MODE_VECTOR_FLOAT)
  96. /* Nonzero if MODE is a complex mode. */
  97. #define COMPLEX_MODE_P(MODE) \
  98. (GET_MODE_CLASS (MODE) == MODE_COMPLEX_INT \
  99. || GET_MODE_CLASS (MODE) == MODE_COMPLEX_FLOAT)
  100. /* Nonzero if MODE is a vector mode. */
  101. #define VECTOR_MODE_P(MODE) \
  102. (GET_MODE_CLASS (MODE) == MODE_VECTOR_BOOL \
  103. || GET_MODE_CLASS (MODE) == MODE_VECTOR_INT \
  104. || GET_MODE_CLASS (MODE) == MODE_VECTOR_FLOAT \
  105. || GET_MODE_CLASS (MODE) == MODE_VECTOR_FRACT \
  106. || GET_MODE_CLASS (MODE) == MODE_VECTOR_UFRACT \
  107. || GET_MODE_CLASS (MODE) == MODE_VECTOR_ACCUM \
  108. || GET_MODE_CLASS (MODE) == MODE_VECTOR_UACCUM)
  109. /* Nonzero if MODE is a scalar integral mode. */
  110. #define SCALAR_INT_MODE_P(MODE) \
  111. (GET_MODE_CLASS (MODE) == MODE_INT \
  112. || GET_MODE_CLASS (MODE) == MODE_PARTIAL_INT)
  113. /* Nonzero if MODE is a scalar floating point mode. */
  114. #define SCALAR_FLOAT_MODE_P(MODE) \
  115. (GET_MODE_CLASS (MODE) == MODE_FLOAT \
  116. || GET_MODE_CLASS (MODE) == MODE_DECIMAL_FLOAT)
  117. /* Nonzero if MODE is a decimal floating point mode. */
  118. #define DECIMAL_FLOAT_MODE_P(MODE) \
  119. (GET_MODE_CLASS (MODE) == MODE_DECIMAL_FLOAT)
  120. /* Nonzero if MODE is a scalar fract mode. */
  121. #define SCALAR_FRACT_MODE_P(MODE) \
  122. (GET_MODE_CLASS (MODE) == MODE_FRACT)
  123. /* Nonzero if MODE is a scalar ufract mode. */
  124. #define SCALAR_UFRACT_MODE_P(MODE) \
  125. (GET_MODE_CLASS (MODE) == MODE_UFRACT)
  126. /* Nonzero if MODE is a scalar fract or ufract mode. */
  127. #define ALL_SCALAR_FRACT_MODE_P(MODE) \
  128. (SCALAR_FRACT_MODE_P (MODE) || SCALAR_UFRACT_MODE_P (MODE))
  129. /* Nonzero if MODE is a scalar accum mode. */
  130. #define SCALAR_ACCUM_MODE_P(MODE) \
  131. (GET_MODE_CLASS (MODE) == MODE_ACCUM)
  132. /* Nonzero if MODE is a scalar uaccum mode. */
  133. #define SCALAR_UACCUM_MODE_P(MODE) \
  134. (GET_MODE_CLASS (MODE) == MODE_UACCUM)
  135. /* Nonzero if MODE is a scalar accum or uaccum mode. */
  136. #define ALL_SCALAR_ACCUM_MODE_P(MODE) \
  137. (SCALAR_ACCUM_MODE_P (MODE) || SCALAR_UACCUM_MODE_P (MODE))
  138. /* Nonzero if MODE is a scalar fract or accum mode. */
  139. #define SIGNED_SCALAR_FIXED_POINT_MODE_P(MODE) \
  140. (SCALAR_FRACT_MODE_P (MODE) || SCALAR_ACCUM_MODE_P (MODE))
  141. /* Nonzero if MODE is a scalar ufract or uaccum mode. */
  142. #define UNSIGNED_SCALAR_FIXED_POINT_MODE_P(MODE) \
  143. (SCALAR_UFRACT_MODE_P (MODE) || SCALAR_UACCUM_MODE_P (MODE))
  144. /* Nonzero if MODE is a scalar fract, ufract, accum or uaccum mode. */
  145. #define ALL_SCALAR_FIXED_POINT_MODE_P(MODE) \
  146. (SIGNED_SCALAR_FIXED_POINT_MODE_P (MODE) \
  147. || UNSIGNED_SCALAR_FIXED_POINT_MODE_P (MODE))
  148. /* Nonzero if MODE is a scalar/vector fract mode. */
  149. #define FRACT_MODE_P(MODE) \
  150. (GET_MODE_CLASS (MODE) == MODE_FRACT \
  151. || GET_MODE_CLASS (MODE) == MODE_VECTOR_FRACT)
  152. /* Nonzero if MODE is a scalar/vector ufract mode. */
  153. #define UFRACT_MODE_P(MODE) \
  154. (GET_MODE_CLASS (MODE) == MODE_UFRACT \
  155. || GET_MODE_CLASS (MODE) == MODE_VECTOR_UFRACT)
  156. /* Nonzero if MODE is a scalar/vector fract or ufract mode. */
  157. #define ALL_FRACT_MODE_P(MODE) \
  158. (FRACT_MODE_P (MODE) || UFRACT_MODE_P (MODE))
  159. /* Nonzero if MODE is a scalar/vector accum mode. */
  160. #define ACCUM_MODE_P(MODE) \
  161. (GET_MODE_CLASS (MODE) == MODE_ACCUM \
  162. || GET_MODE_CLASS (MODE) == MODE_VECTOR_ACCUM)
  163. /* Nonzero if MODE is a scalar/vector uaccum mode. */
  164. #define UACCUM_MODE_P(MODE) \
  165. (GET_MODE_CLASS (MODE) == MODE_UACCUM \
  166. || GET_MODE_CLASS (MODE) == MODE_VECTOR_UACCUM)
  167. /* Nonzero if MODE is a scalar/vector accum or uaccum mode. */
  168. #define ALL_ACCUM_MODE_P(MODE) \
  169. (ACCUM_MODE_P (MODE) || UACCUM_MODE_P (MODE))
  170. /* Nonzero if MODE is a scalar/vector fract or accum mode. */
  171. #define SIGNED_FIXED_POINT_MODE_P(MODE) \
  172. (FRACT_MODE_P (MODE) || ACCUM_MODE_P (MODE))
  173. /* Nonzero if MODE is a scalar/vector ufract or uaccum mode. */
  174. #define UNSIGNED_FIXED_POINT_MODE_P(MODE) \
  175. (UFRACT_MODE_P (MODE) || UACCUM_MODE_P (MODE))
  176. /* Nonzero if MODE is a scalar/vector fract, ufract, accum or uaccum mode. */
  177. #define ALL_FIXED_POINT_MODE_P(MODE) \
  178. (SIGNED_FIXED_POINT_MODE_P (MODE) \
  179. || UNSIGNED_FIXED_POINT_MODE_P (MODE))
  180. /* Nonzero if CLASS modes can be widened. */
  181. #define CLASS_HAS_WIDER_MODES_P(CLASS) \
  182. (CLASS == MODE_INT \
  183. || CLASS == MODE_PARTIAL_INT \
  184. || CLASS == MODE_FLOAT \
  185. || CLASS == MODE_DECIMAL_FLOAT \
  186. || CLASS == MODE_COMPLEX_FLOAT \
  187. || CLASS == MODE_FRACT \
  188. || CLASS == MODE_UFRACT \
  189. || CLASS == MODE_ACCUM \
  190. || CLASS == MODE_UACCUM)
  191. /* An optional T (i.e. a T or nothing), where T is some form of mode class. */
  192. template<typename T>
  193. class opt_mode
  194. {
  195. public:
  196. enum from_int { dummy = MAX_MACHINE_MODE };
  197. ALWAYS_INLINE CONSTEXPR opt_mode () : m_mode (E_VOIDmode) {}
  198. ALWAYS_INLINE CONSTEXPR opt_mode (const T &m) : m_mode (m) {}
  199. template<typename U>
  200. ALWAYS_INLINE CONSTEXPR opt_mode (const U &m) : m_mode (T (m)) {}
  201. ALWAYS_INLINE CONSTEXPR opt_mode (from_int m) : m_mode (machine_mode (m)) {}
  202. machine_mode else_void () const;
  203. machine_mode else_blk () const { return else_mode (BLKmode); }
  204. machine_mode else_mode (machine_mode) const;
  205. T require () const;
  206. bool exists () const;
  207. template<typename U> bool exists (U *) const;
  208. bool operator== (const T &m) const { return m_mode == m; }
  209. bool operator!= (const T &m) const { return m_mode != m; }
  210. private:
  211. machine_mode m_mode;
  212. };
  213. /* If the object contains a T, return its enum value, otherwise return
  214. E_VOIDmode. */
  215. template<typename T>
  216. ALWAYS_INLINE machine_mode
  217. opt_mode<T>::else_void () const
  218. {
  219. return m_mode;
  220. }
  221. /* If the T exists, return its enum value, otherwise return FALLBACK. */
  222. template<typename T>
  223. inline machine_mode
  224. opt_mode<T>::else_mode (machine_mode fallback) const
  225. {
  226. return m_mode == E_VOIDmode ? fallback : m_mode;
  227. }
  228. /* Assert that the object contains a T and return it. */
  229. template<typename T>
  230. inline T
  231. opt_mode<T>::require () const
  232. {
  233. gcc_checking_assert (m_mode != E_VOIDmode);
  234. return typename mode_traits<T>::from_int (m_mode);
  235. }
  236. /* Return true if the object contains a T rather than nothing. */
  237. template<typename T>
  238. ALWAYS_INLINE bool
  239. opt_mode<T>::exists () const
  240. {
  241. return m_mode != E_VOIDmode;
  242. }
  243. /* Return true if the object contains a T, storing it in *MODE if so. */
  244. template<typename T>
  245. template<typename U>
  246. inline bool
  247. opt_mode<T>::exists (U *mode) const
  248. {
  249. if (m_mode != E_VOIDmode)
  250. {
  251. *mode = T (typename mode_traits<T>::from_int (m_mode));
  252. return true;
  253. }
  254. return false;
  255. }
  256. /* A POD version of mode class T. */
  257. template<typename T>
  258. struct pod_mode
  259. {
  260. typedef typename mode_traits<T>::from_int from_int;
  261. typedef typename T::measurement_type measurement_type;
  262. machine_mode m_mode;
  263. ALWAYS_INLINE CONSTEXPR
  264. operator machine_mode () const { return m_mode; }
  265. ALWAYS_INLINE CONSTEXPR
  266. operator T () const { return from_int (m_mode); }
  267. ALWAYS_INLINE pod_mode &operator = (const T &m) { m_mode = m; return *this; }
  268. };
  269. /* Return true if mode M has type T. */
  270. template<typename T>
  271. inline bool
  272. is_a (machine_mode m)
  273. {
  274. return T::includes_p (m);
  275. }
  276. template<typename T, typename U>
  277. inline bool
  278. is_a (const opt_mode<U> &m)
  279. {
  280. return T::includes_p (m.else_void ());
  281. }
  282. /* Assert that mode M has type T, and return it in that form. */
  283. template<typename T>
  284. inline T
  285. as_a (machine_mode m)
  286. {
  287. gcc_checking_assert (T::includes_p (m));
  288. return typename mode_traits<T>::from_int (m);
  289. }
  290. template<typename T, typename U>
  291. inline T
  292. as_a (const opt_mode<U> &m)
  293. {
  294. return as_a <T> (m.else_void ());
  295. }
  296. /* Convert M to an opt_mode<T>. */
  297. template<typename T>
  298. inline opt_mode<T>
  299. dyn_cast (machine_mode m)
  300. {
  301. if (T::includes_p (m))
  302. return T (typename mode_traits<T>::from_int (m));
  303. return opt_mode<T> ();
  304. }
  305. template<typename T, typename U>
  306. inline opt_mode<T>
  307. dyn_cast (const opt_mode<U> &m)
  308. {
  309. return dyn_cast <T> (m.else_void ());
  310. }
  311. /* Return true if mode M has type T, storing it as a T in *RESULT
  312. if so. */
  313. template<typename T, typename U>
  314. inline bool
  315. is_a (machine_mode m, U *result)
  316. {
  317. if (T::includes_p (m))
  318. {
  319. *result = T (typename mode_traits<T>::from_int (m));
  320. return true;
  321. }
  322. return false;
  323. }
  324. /* Represents a machine mode that is known to be a SCALAR_INT_MODE_P. */
  325. class scalar_int_mode
  326. {
  327. public:
  328. typedef mode_traits<scalar_int_mode>::from_int from_int;
  329. typedef unsigned short measurement_type;
  330. ALWAYS_INLINE scalar_int_mode () {}
  331. ALWAYS_INLINE CONSTEXPR
  332. scalar_int_mode (from_int m) : m_mode (machine_mode (m)) {}
  333. ALWAYS_INLINE CONSTEXPR operator machine_mode () const { return m_mode; }
  334. static bool includes_p (machine_mode);
  335. protected:
  336. machine_mode m_mode;
  337. };
  338. /* Return true if M is a scalar_int_mode. */
  339. inline bool
  340. scalar_int_mode::includes_p (machine_mode m)
  341. {
  342. return SCALAR_INT_MODE_P (m);
  343. }
  344. /* Represents a machine mode that is known to be a SCALAR_FLOAT_MODE_P. */
  345. class scalar_float_mode
  346. {
  347. public:
  348. typedef mode_traits<scalar_float_mode>::from_int from_int;
  349. typedef unsigned short measurement_type;
  350. ALWAYS_INLINE scalar_float_mode () {}
  351. ALWAYS_INLINE CONSTEXPR
  352. scalar_float_mode (from_int m) : m_mode (machine_mode (m)) {}
  353. ALWAYS_INLINE CONSTEXPR operator machine_mode () const { return m_mode; }
  354. static bool includes_p (machine_mode);
  355. protected:
  356. machine_mode m_mode;
  357. };
  358. /* Return true if M is a scalar_float_mode. */
  359. inline bool
  360. scalar_float_mode::includes_p (machine_mode m)
  361. {
  362. return SCALAR_FLOAT_MODE_P (m);
  363. }
  364. /* Represents a machine mode that is known to be scalar. */
  365. class scalar_mode
  366. {
  367. public:
  368. typedef mode_traits<scalar_mode>::from_int from_int;
  369. typedef unsigned short measurement_type;
  370. ALWAYS_INLINE scalar_mode () {}
  371. ALWAYS_INLINE CONSTEXPR
  372. scalar_mode (from_int m) : m_mode (machine_mode (m)) {}
  373. ALWAYS_INLINE CONSTEXPR
  374. scalar_mode (const scalar_int_mode &m) : m_mode (m) {}
  375. ALWAYS_INLINE CONSTEXPR
  376. scalar_mode (const scalar_float_mode &m) : m_mode (m) {}
  377. ALWAYS_INLINE CONSTEXPR
  378. scalar_mode (const scalar_int_mode_pod &m) : m_mode (m) {}
  379. ALWAYS_INLINE CONSTEXPR operator machine_mode () const { return m_mode; }
  380. static bool includes_p (machine_mode);
  381. protected:
  382. machine_mode m_mode;
  383. };
  384. /* Return true if M represents some kind of scalar value. */
  385. inline bool
  386. scalar_mode::includes_p (machine_mode m)
  387. {
  388. switch (GET_MODE_CLASS (m))
  389. {
  390. case MODE_INT:
  391. case MODE_PARTIAL_INT:
  392. case MODE_FRACT:
  393. case MODE_UFRACT:
  394. case MODE_ACCUM:
  395. case MODE_UACCUM:
  396. case MODE_FLOAT:
  397. case MODE_DECIMAL_FLOAT:
  398. return true;
  399. default:
  400. return false;
  401. }
  402. }
  403. /* Represents a machine mode that is known to be a COMPLEX_MODE_P. */
  404. class complex_mode
  405. {
  406. public:
  407. typedef mode_traits<complex_mode>::from_int from_int;
  408. typedef unsigned short measurement_type;
  409. ALWAYS_INLINE complex_mode () {}
  410. ALWAYS_INLINE CONSTEXPR
  411. complex_mode (from_int m) : m_mode (machine_mode (m)) {}
  412. ALWAYS_INLINE CONSTEXPR operator machine_mode () const { return m_mode; }
  413. static bool includes_p (machine_mode);
  414. protected:
  415. machine_mode m_mode;
  416. };
  417. /* Return true if M is a complex_mode. */
  418. inline bool
  419. complex_mode::includes_p (machine_mode m)
  420. {
  421. return COMPLEX_MODE_P (m);
  422. }
  423. /* Return the base GET_MODE_SIZE value for MODE. */
  424. ALWAYS_INLINE poly_uint16
  425. mode_to_bytes (machine_mode mode)
  426. {
  427. #if GCC_VERSION >= 4001
  428. return (__builtin_constant_p (mode)
  429. ? mode_size_inline (mode) : mode_size[mode]);
  430. #else
  431. return mode_size[mode];
  432. #endif
  433. }
  434. /* Return the base GET_MODE_BITSIZE value for MODE. */
  435. ALWAYS_INLINE poly_uint16
  436. mode_to_bits (machine_mode mode)
  437. {
  438. return mode_to_bytes (mode) * BITS_PER_UNIT;
  439. }
  440. /* Return the base GET_MODE_PRECISION value for MODE. */
  441. ALWAYS_INLINE poly_uint16
  442. mode_to_precision (machine_mode mode)
  443. {
  444. return mode_precision[mode];
  445. }
  446. /* Return the base GET_MODE_INNER value for MODE. */
  447. ALWAYS_INLINE scalar_mode
  448. mode_to_inner (machine_mode mode)
  449. {
  450. #if GCC_VERSION >= 4001
  451. return scalar_mode::from_int (__builtin_constant_p (mode)
  452. ? mode_inner_inline (mode)
  453. : mode_inner[mode]);
  454. #else
  455. return scalar_mode::from_int (mode_inner[mode]);
  456. #endif
  457. }
  458. /* Return the base GET_MODE_UNIT_SIZE value for MODE. */
  459. ALWAYS_INLINE unsigned char
  460. mode_to_unit_size (machine_mode mode)
  461. {
  462. #if GCC_VERSION >= 4001
  463. return (__builtin_constant_p (mode)
  464. ? mode_unit_size_inline (mode) : mode_unit_size[mode]);
  465. #else
  466. return mode_unit_size[mode];
  467. #endif
  468. }
  469. /* Return the base GET_MODE_UNIT_PRECISION value for MODE. */
  470. ALWAYS_INLINE unsigned short
  471. mode_to_unit_precision (machine_mode mode)
  472. {
  473. #if GCC_VERSION >= 4001
  474. return (__builtin_constant_p (mode)
  475. ? mode_unit_precision_inline (mode) : mode_unit_precision[mode]);
  476. #else
  477. return mode_unit_precision[mode];
  478. #endif
  479. }
  480. /* Return the base GET_MODE_NUNITS value for MODE. */
  481. ALWAYS_INLINE poly_uint16
  482. mode_to_nunits (machine_mode mode)
  483. {
  484. #if GCC_VERSION >= 4001
  485. return (__builtin_constant_p (mode)
  486. ? mode_nunits_inline (mode) : mode_nunits[mode]);
  487. #else
  488. return mode_nunits[mode];
  489. #endif
  490. }
  491. /* Get the size in bytes of an object of mode MODE. */
  492. #if ONLY_FIXED_SIZE_MODES
  493. #define GET_MODE_SIZE(MODE) ((unsigned short) mode_to_bytes (MODE).coeffs[0])
  494. #else
  495. ALWAYS_INLINE poly_uint16
  496. GET_MODE_SIZE (machine_mode mode)
  497. {
  498. return mode_to_bytes (mode);
  499. }
  500. template<typename T>
  501. ALWAYS_INLINE typename if_poly<typename T::measurement_type>::type
  502. GET_MODE_SIZE (const T &mode)
  503. {
  504. return mode_to_bytes (mode);
  505. }
  506. template<typename T>
  507. ALWAYS_INLINE typename if_nonpoly<typename T::measurement_type>::type
  508. GET_MODE_SIZE (const T &mode)
  509. {
  510. return mode_to_bytes (mode).coeffs[0];
  511. }
  512. #endif
  513. /* Get the size in bits of an object of mode MODE. */
  514. #if ONLY_FIXED_SIZE_MODES
  515. #define GET_MODE_BITSIZE(MODE) ((unsigned short) mode_to_bits (MODE).coeffs[0])
  516. #else
  517. ALWAYS_INLINE poly_uint16
  518. GET_MODE_BITSIZE (machine_mode mode)
  519. {
  520. return mode_to_bits (mode);
  521. }
  522. template<typename T>
  523. ALWAYS_INLINE typename if_poly<typename T::measurement_type>::type
  524. GET_MODE_BITSIZE (const T &mode)
  525. {
  526. return mode_to_bits (mode);
  527. }
  528. template<typename T>
  529. ALWAYS_INLINE typename if_nonpoly<typename T::measurement_type>::type
  530. GET_MODE_BITSIZE (const T &mode)
  531. {
  532. return mode_to_bits (mode).coeffs[0];
  533. }
  534. #endif
  535. /* Get the number of value bits of an object of mode MODE. */
  536. #if ONLY_FIXED_SIZE_MODES
  537. #define GET_MODE_PRECISION(MODE) \
  538. ((unsigned short) mode_to_precision (MODE).coeffs[0])
  539. #else
  540. ALWAYS_INLINE poly_uint16
  541. GET_MODE_PRECISION (machine_mode mode)
  542. {
  543. return mode_to_precision (mode);
  544. }
  545. template<typename T>
  546. ALWAYS_INLINE typename if_poly<typename T::measurement_type>::type
  547. GET_MODE_PRECISION (const T &mode)
  548. {
  549. return mode_to_precision (mode);
  550. }
  551. template<typename T>
  552. ALWAYS_INLINE typename if_nonpoly<typename T::measurement_type>::type
  553. GET_MODE_PRECISION (const T &mode)
  554. {
  555. return mode_to_precision (mode).coeffs[0];
  556. }
  557. #endif
  558. /* Get the number of integral bits of an object of mode MODE. */
  559. extern CONST_MODE_IBIT unsigned char mode_ibit[NUM_MACHINE_MODES];
  560. #define GET_MODE_IBIT(MODE) mode_ibit[MODE]
  561. /* Get the number of fractional bits of an object of mode MODE. */
  562. extern CONST_MODE_FBIT unsigned char mode_fbit[NUM_MACHINE_MODES];
  563. #define GET_MODE_FBIT(MODE) mode_fbit[MODE]
  564. /* Get a bitmask containing 1 for all bits in a word
  565. that fit within mode MODE. */
  566. extern const unsigned HOST_WIDE_INT mode_mask_array[NUM_MACHINE_MODES];
  567. #define GET_MODE_MASK(MODE) mode_mask_array[MODE]
  568. /* Return the mode of the basic parts of MODE. For vector modes this is the
  569. mode of the vector elements. For complex modes it is the mode of the real
  570. and imaginary parts. For other modes it is MODE itself. */
  571. #define GET_MODE_INNER(MODE) (mode_to_inner (MODE))
  572. /* Get the size in bytes or bits of the basic parts of an
  573. object of mode MODE. */
  574. #define GET_MODE_UNIT_SIZE(MODE) mode_to_unit_size (MODE)
  575. #define GET_MODE_UNIT_BITSIZE(MODE) \
  576. ((unsigned short) (GET_MODE_UNIT_SIZE (MODE) * BITS_PER_UNIT))
  577. #define GET_MODE_UNIT_PRECISION(MODE) (mode_to_unit_precision (MODE))
  578. /* Get the number of units in an object of mode MODE. This is 2 for
  579. complex modes and the number of elements for vector modes. */
  580. #if ONLY_FIXED_SIZE_MODES
  581. #define GET_MODE_NUNITS(MODE) (mode_to_nunits (MODE).coeffs[0])
  582. #else
  583. ALWAYS_INLINE poly_uint16
  584. GET_MODE_NUNITS (machine_mode mode)
  585. {
  586. return mode_to_nunits (mode);
  587. }
  588. template<typename T>
  589. ALWAYS_INLINE typename if_poly<typename T::measurement_type>::type
  590. GET_MODE_NUNITS (const T &mode)
  591. {
  592. return mode_to_nunits (mode);
  593. }
  594. template<typename T>
  595. ALWAYS_INLINE typename if_nonpoly<typename T::measurement_type>::type
  596. GET_MODE_NUNITS (const T &mode)
  597. {
  598. return mode_to_nunits (mode).coeffs[0];
  599. }
  600. #endif
  601. /* Get the next wider natural mode (eg, QI -> HI -> SI -> DI -> TI). */
  602. template<typename T>
  603. ALWAYS_INLINE opt_mode<T>
  604. GET_MODE_WIDER_MODE (const T &m)
  605. {
  606. return typename opt_mode<T>::from_int (mode_wider[m]);
  607. }
  608. /* For scalars, this is a mode with twice the precision. For vectors,
  609. this is a mode with the same inner mode but with twice the elements. */
  610. template<typename T>
  611. ALWAYS_INLINE opt_mode<T>
  612. GET_MODE_2XWIDER_MODE (const T &m)
  613. {
  614. return typename opt_mode<T>::from_int (mode_2xwider[m]);
  615. }
  616. /* Get the complex mode from the component mode. */
  617. extern const unsigned char mode_complex[NUM_MACHINE_MODES];
  618. #define GET_MODE_COMPLEX_MODE(MODE) ((machine_mode) mode_complex[MODE])
  619. /* Represents a machine mode that must have a fixed size. The main
  620. use of this class is to represent the modes of objects that always
  621. have static storage duration, such as constant pool entries.
  622. (No current target supports the concept of variable-size static data.) */
  623. class fixed_size_mode
  624. {
  625. public:
  626. typedef mode_traits<fixed_size_mode>::from_int from_int;
  627. typedef unsigned short measurement_type;
  628. ALWAYS_INLINE fixed_size_mode () {}
  629. ALWAYS_INLINE CONSTEXPR
  630. fixed_size_mode (from_int m) : m_mode (machine_mode (m)) {}
  631. ALWAYS_INLINE CONSTEXPR
  632. fixed_size_mode (const scalar_mode &m) : m_mode (m) {}
  633. ALWAYS_INLINE CONSTEXPR
  634. fixed_size_mode (const scalar_int_mode &m) : m_mode (m) {}
  635. ALWAYS_INLINE CONSTEXPR
  636. fixed_size_mode (const scalar_float_mode &m) : m_mode (m) {}
  637. ALWAYS_INLINE CONSTEXPR
  638. fixed_size_mode (const scalar_mode_pod &m) : m_mode (m) {}
  639. ALWAYS_INLINE CONSTEXPR
  640. fixed_size_mode (const scalar_int_mode_pod &m) : m_mode (m) {}
  641. ALWAYS_INLINE CONSTEXPR
  642. fixed_size_mode (const complex_mode &m) : m_mode (m) {}
  643. ALWAYS_INLINE CONSTEXPR operator machine_mode () const { return m_mode; }
  644. static bool includes_p (machine_mode);
  645. protected:
  646. machine_mode m_mode;
  647. };
  648. /* Return true if MODE has a fixed size. */
  649. inline bool
  650. fixed_size_mode::includes_p (machine_mode mode)
  651. {
  652. return mode_to_bytes (mode).is_constant ();
  653. }
  654. /* Wrapper for mode arguments to target macros, so that if a target
  655. doesn't need polynomial-sized modes, its header file can continue
  656. to treat everything as fixed_size_mode. This should go away once
  657. macros are moved to target hooks. It shouldn't be used in other
  658. contexts. */
  659. #if NUM_POLY_INT_COEFFS == 1
  660. #define MACRO_MODE(MODE) (as_a <fixed_size_mode> (MODE))
  661. #else
  662. #define MACRO_MODE(MODE) (MODE)
  663. #endif
  664. extern opt_machine_mode mode_for_size (poly_uint64, enum mode_class, int);
  665. /* Return the machine mode to use for a MODE_INT of SIZE bits, if one
  666. exists. If LIMIT is nonzero, modes wider than MAX_FIXED_MODE_SIZE
  667. will not be used. */
  668. inline opt_scalar_int_mode
  669. int_mode_for_size (poly_uint64 size, int limit)
  670. {
  671. return dyn_cast <scalar_int_mode> (mode_for_size (size, MODE_INT, limit));
  672. }
  673. /* Return the machine mode to use for a MODE_FLOAT of SIZE bits, if one
  674. exists. */
  675. inline opt_scalar_float_mode
  676. float_mode_for_size (poly_uint64 size)
  677. {
  678. return dyn_cast <scalar_float_mode> (mode_for_size (size, MODE_FLOAT, 0));
  679. }
  680. /* Likewise for MODE_DECIMAL_FLOAT. */
  681. inline opt_scalar_float_mode
  682. decimal_float_mode_for_size (unsigned int size)
  683. {
  684. return dyn_cast <scalar_float_mode>
  685. (mode_for_size (size, MODE_DECIMAL_FLOAT, 0));
  686. }
  687. extern machine_mode smallest_mode_for_size (poly_uint64, enum mode_class);
  688. /* Find the narrowest integer mode that contains at least SIZE bits.
  689. Such a mode must exist. */
  690. inline scalar_int_mode
  691. smallest_int_mode_for_size (poly_uint64 size)
  692. {
  693. return as_a <scalar_int_mode> (smallest_mode_for_size (size, MODE_INT));
  694. }
  695. extern opt_scalar_int_mode int_mode_for_mode (machine_mode);
  696. extern opt_machine_mode bitwise_mode_for_mode (machine_mode);
  697. extern opt_machine_mode mode_for_vector (scalar_mode, poly_uint64);
  698. extern opt_machine_mode related_vector_mode (machine_mode, scalar_mode,
  699. poly_uint64 = 0);
  700. extern opt_machine_mode related_int_vector_mode (machine_mode);
  701. /* A class for iterating through possible bitfield modes. */
  702. class bit_field_mode_iterator
  703. {
  704. public:
  705. bit_field_mode_iterator (HOST_WIDE_INT, HOST_WIDE_INT,
  706. poly_int64, poly_int64,
  707. unsigned int, bool);
  708. bool next_mode (scalar_int_mode *);
  709. bool prefer_smaller_modes ();
  710. private:
  711. opt_scalar_int_mode m_mode;
  712. /* We use signed values here because the bit position can be negative
  713. for invalid input such as gcc.dg/pr48335-8.c. */
  714. HOST_WIDE_INT m_bitsize;
  715. HOST_WIDE_INT m_bitpos;
  716. poly_int64 m_bitregion_start;
  717. poly_int64 m_bitregion_end;
  718. unsigned int m_align;
  719. bool m_volatilep;
  720. int m_count;
  721. };
  722. /* Find the best mode to use to access a bit field. */
  723. extern bool get_best_mode (int, int, poly_uint64, poly_uint64, unsigned int,
  724. unsigned HOST_WIDE_INT, bool, scalar_int_mode *);
  725. /* Determine alignment, 1<=result<=BIGGEST_ALIGNMENT. */
  726. extern CONST_MODE_BASE_ALIGN unsigned short mode_base_align[NUM_MACHINE_MODES];
  727. extern unsigned get_mode_alignment (machine_mode);
  728. #define GET_MODE_ALIGNMENT(MODE) get_mode_alignment (MODE)
  729. /* For each class, get the narrowest mode in that class. */
  730. extern const unsigned char class_narrowest_mode[MAX_MODE_CLASS];
  731. #define GET_CLASS_NARROWEST_MODE(CLASS) \
  732. ((machine_mode) class_narrowest_mode[CLASS])
  733. /* The narrowest full integer mode available on the target. */
  734. #define NARROWEST_INT_MODE \
  735. (scalar_int_mode \
  736. (scalar_int_mode::from_int (class_narrowest_mode[MODE_INT])))
  737. /* Return the narrowest mode in T's class. */
  738. template<typename T>
  739. inline T
  740. get_narrowest_mode (T mode)
  741. {
  742. return typename mode_traits<T>::from_int
  743. (class_narrowest_mode[GET_MODE_CLASS (mode)]);
  744. }
  745. /* Define the integer modes whose sizes are BITS_PER_UNIT and BITS_PER_WORD
  746. and the mode whose class is Pmode and whose size is POINTER_SIZE. */
  747. extern scalar_int_mode byte_mode;
  748. extern scalar_int_mode word_mode;
  749. extern scalar_int_mode ptr_mode;
  750. /* Target-dependent machine mode initialization - in insn-modes.c. */
  751. extern void init_adjust_machine_modes (void);
  752. #define TRULY_NOOP_TRUNCATION_MODES_P(MODE1, MODE2) \
  753. (targetm.truly_noop_truncation (GET_MODE_PRECISION (MODE1), \
  754. GET_MODE_PRECISION (MODE2)))
  755. /* Return true if MODE is a scalar integer mode that fits in a
  756. HOST_WIDE_INT. */
  757. inline bool
  758. HWI_COMPUTABLE_MODE_P (machine_mode mode)
  759. {
  760. machine_mode mme = mode;
  761. return (SCALAR_INT_MODE_P (mme)
  762. && mode_to_precision (mme).coeffs[0] <= HOST_BITS_PER_WIDE_INT);
  763. }
  764. inline bool
  765. HWI_COMPUTABLE_MODE_P (scalar_int_mode mode)
  766. {
  767. return GET_MODE_PRECISION (mode) <= HOST_BITS_PER_WIDE_INT;
  768. }
  769. struct int_n_data_t {
  770. /* These parts are initailized by genmodes output */
  771. unsigned int bitsize;
  772. scalar_int_mode_pod m;
  773. /* RID_* is RID_INTN_BASE + index into this array */
  774. };
  775. /* This is also in tree.h. genmodes.c guarantees the're sorted from
  776. smallest bitsize to largest bitsize. */
  777. extern bool int_n_enabled_p[NUM_INT_N_ENTS];
  778. extern const int_n_data_t int_n_data[NUM_INT_N_ENTS];
  779. /* Return true if MODE has class MODE_INT, storing it as a scalar_int_mode
  780. in *INT_MODE if so. */
  781. template<typename T>
  782. inline bool
  783. is_int_mode (machine_mode mode, T *int_mode)
  784. {
  785. if (GET_MODE_CLASS (mode) == MODE_INT)
  786. {
  787. *int_mode = scalar_int_mode (scalar_int_mode::from_int (mode));
  788. return true;
  789. }
  790. return false;
  791. }
  792. /* Return true if MODE has class MODE_FLOAT, storing it as a
  793. scalar_float_mode in *FLOAT_MODE if so. */
  794. template<typename T>
  795. inline bool
  796. is_float_mode (machine_mode mode, T *float_mode)
  797. {
  798. if (GET_MODE_CLASS (mode) == MODE_FLOAT)
  799. {
  800. *float_mode = scalar_float_mode (scalar_float_mode::from_int (mode));
  801. return true;
  802. }
  803. return false;
  804. }
  805. /* Return true if MODE has class MODE_COMPLEX_INT, storing it as
  806. a complex_mode in *CMODE if so. */
  807. template<typename T>
  808. inline bool
  809. is_complex_int_mode (machine_mode mode, T *cmode)
  810. {
  811. if (GET_MODE_CLASS (mode) == MODE_COMPLEX_INT)
  812. {
  813. *cmode = complex_mode (complex_mode::from_int (mode));
  814. return true;
  815. }
  816. return false;
  817. }
  818. /* Return true if MODE has class MODE_COMPLEX_FLOAT, storing it as
  819. a complex_mode in *CMODE if so. */
  820. template<typename T>
  821. inline bool
  822. is_complex_float_mode (machine_mode mode, T *cmode)
  823. {
  824. if (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT)
  825. {
  826. *cmode = complex_mode (complex_mode::from_int (mode));
  827. return true;
  828. }
  829. return false;
  830. }
  831. /* Return true if MODE is a scalar integer mode with a precision
  832. smaller than LIMIT's precision. */
  833. inline bool
  834. is_narrower_int_mode (machine_mode mode, scalar_int_mode limit)
  835. {
  836. scalar_int_mode int_mode;
  837. return (is_a <scalar_int_mode> (mode, &int_mode)
  838. && GET_MODE_PRECISION (int_mode) < GET_MODE_PRECISION (limit));
  839. }
  840. namespace mode_iterator
  841. {
  842. /* Start mode iterator *ITER at the first mode in class MCLASS, if any. */
  843. template<typename T>
  844. inline void
  845. start (opt_mode<T> *iter, enum mode_class mclass)
  846. {
  847. if (GET_CLASS_NARROWEST_MODE (mclass) == E_VOIDmode)
  848. *iter = opt_mode<T> ();
  849. else
  850. *iter = as_a<T> (GET_CLASS_NARROWEST_MODE (mclass));
  851. }
  852. inline void
  853. start (machine_mode *iter, enum mode_class mclass)
  854. {
  855. *iter = GET_CLASS_NARROWEST_MODE (mclass);
  856. }
  857. /* Return true if mode iterator *ITER has not reached the end. */
  858. template<typename T>
  859. inline bool
  860. iterate_p (opt_mode<T> *iter)
  861. {
  862. return iter->exists ();
  863. }
  864. inline bool
  865. iterate_p (machine_mode *iter)
  866. {
  867. return *iter != E_VOIDmode;
  868. }
  869. /* Set mode iterator *ITER to the next widest mode in the same class,
  870. if any. */
  871. template<typename T>
  872. inline void
  873. get_wider (opt_mode<T> *iter)
  874. {
  875. *iter = GET_MODE_WIDER_MODE (iter->require ());
  876. }
  877. inline void
  878. get_wider (machine_mode *iter)
  879. {
  880. *iter = GET_MODE_WIDER_MODE (*iter).else_void ();
  881. }
  882. /* Set mode iterator *ITER to the next widest mode in the same class.
  883. Such a mode is known to exist. */
  884. template<typename T>
  885. inline void
  886. get_known_wider (T *iter)
  887. {
  888. *iter = GET_MODE_WIDER_MODE (*iter).require ();
  889. }
  890. /* Set mode iterator *ITER to the mode that is two times wider than the
  891. current one, if such a mode exists. */
  892. template<typename T>
  893. inline void
  894. get_2xwider (opt_mode<T> *iter)
  895. {
  896. *iter = GET_MODE_2XWIDER_MODE (iter->require ());
  897. }
  898. inline void
  899. get_2xwider (machine_mode *iter)
  900. {
  901. *iter = GET_MODE_2XWIDER_MODE (*iter).else_void ();
  902. }
  903. }
  904. /* Make ITERATOR iterate over all the modes in mode class CLASS,
  905. from narrowest to widest. */
  906. #define FOR_EACH_MODE_IN_CLASS(ITERATOR, CLASS) \
  907. for (mode_iterator::start (&(ITERATOR), CLASS); \
  908. mode_iterator::iterate_p (&(ITERATOR)); \
  909. mode_iterator::get_wider (&(ITERATOR)))
  910. /* Make ITERATOR iterate over all the modes in the range [START, END),
  911. in order of increasing width. */
  912. #define FOR_EACH_MODE(ITERATOR, START, END) \
  913. for ((ITERATOR) = (START); \
  914. (ITERATOR) != (END); \
  915. mode_iterator::get_known_wider (&(ITERATOR)))
  916. /* Make ITERATOR iterate over START and all wider modes in the same
  917. class, in order of increasing width. */
  918. #define FOR_EACH_MODE_FROM(ITERATOR, START) \
  919. for ((ITERATOR) = (START); \
  920. mode_iterator::iterate_p (&(ITERATOR)); \
  921. mode_iterator::get_wider (&(ITERATOR)))
  922. /* Make ITERATOR iterate over modes in the range [NARROWEST, END)
  923. in order of increasing width, where NARROWEST is the narrowest mode
  924. in END's class. */
  925. #define FOR_EACH_MODE_UNTIL(ITERATOR, END) \
  926. FOR_EACH_MODE (ITERATOR, get_narrowest_mode (END), END)
  927. /* Make ITERATOR iterate over modes in the same class as MODE, in order
  928. of increasing width. Start at the first mode wider than START,
  929. or don't iterate at all if there is no wider mode. */
  930. #define FOR_EACH_WIDER_MODE(ITERATOR, START) \
  931. for ((ITERATOR) = (START), mode_iterator::get_wider (&(ITERATOR)); \
  932. mode_iterator::iterate_p (&(ITERATOR)); \
  933. mode_iterator::get_wider (&(ITERATOR)))
  934. /* Make ITERATOR iterate over modes in the same class as MODE, in order
  935. of increasing width, and with each mode being twice the width of the
  936. previous mode. Start at the mode that is two times wider than START,
  937. or don't iterate at all if there is no such mode. */
  938. #define FOR_EACH_2XWIDER_MODE(ITERATOR, START) \
  939. for ((ITERATOR) = (START), mode_iterator::get_2xwider (&(ITERATOR)); \
  940. mode_iterator::iterate_p (&(ITERATOR)); \
  941. mode_iterator::get_2xwider (&(ITERATOR)))
  942. template<typename T>
  943. void
  944. gt_ggc_mx (pod_mode<T> *)
  945. {
  946. }
  947. template<typename T>
  948. void
  949. gt_pch_nx (pod_mode<T> *)
  950. {
  951. }
  952. template<typename T>
  953. void
  954. gt_pch_nx (pod_mode<T> *, void (*) (void *, void *), void *)
  955. {
  956. }
  957. #endif /* not HAVE_MACHINE_MODES */