machmode.h 33 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171
  1. /* Machine mode definitions for GCC; included by rtl.h and tree.h.
  2. Copyright (C) 1991-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 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 opt_mode () : m_mode (E_VOIDmode) {}
  198. ALWAYS_INLINE opt_mode (const T &m) : m_mode (m) {}
  199. template<typename U>
  200. ALWAYS_INLINE opt_mode (const U &m) : m_mode (T (m)) {}
  201. ALWAYS_INLINE opt_mode (from_int m) : m_mode (machine_mode (m)) {}
  202. machine_mode else_void () const;
  203. machine_mode else_blk () const;
  204. T require () const;
  205. bool exists () const;
  206. template<typename U> bool exists (U *) const;
  207. private:
  208. machine_mode m_mode;
  209. };
  210. /* If the object contains a T, return its enum value, otherwise return
  211. E_VOIDmode. */
  212. template<typename T>
  213. ALWAYS_INLINE machine_mode
  214. opt_mode<T>::else_void () const
  215. {
  216. return m_mode;
  217. }
  218. /* If the T exists, return its enum value, otherwise return E_BLKmode. */
  219. template<typename T>
  220. inline machine_mode
  221. opt_mode<T>::else_blk () const
  222. {
  223. return m_mode == E_VOIDmode ? E_BLKmode : m_mode;
  224. }
  225. /* Assert that the object contains a T and return it. */
  226. template<typename T>
  227. inline T
  228. opt_mode<T>::require () const
  229. {
  230. gcc_checking_assert (m_mode != E_VOIDmode);
  231. return typename mode_traits<T>::from_int (m_mode);
  232. }
  233. /* Return true if the object contains a T rather than nothing. */
  234. template<typename T>
  235. ALWAYS_INLINE bool
  236. opt_mode<T>::exists () const
  237. {
  238. return m_mode != E_VOIDmode;
  239. }
  240. /* Return true if the object contains a T, storing it in *MODE if so. */
  241. template<typename T>
  242. template<typename U>
  243. inline bool
  244. opt_mode<T>::exists (U *mode) const
  245. {
  246. if (m_mode != E_VOIDmode)
  247. {
  248. *mode = T (typename mode_traits<T>::from_int (m_mode));
  249. return true;
  250. }
  251. return false;
  252. }
  253. /* A POD version of mode class T. */
  254. template<typename T>
  255. struct pod_mode
  256. {
  257. typedef typename mode_traits<T>::from_int from_int;
  258. typedef typename T::measurement_type measurement_type;
  259. machine_mode m_mode;
  260. ALWAYS_INLINE operator machine_mode () const { return m_mode; }
  261. ALWAYS_INLINE operator T () const { return from_int (m_mode); }
  262. ALWAYS_INLINE pod_mode &operator = (const T &m) { m_mode = m; return *this; }
  263. };
  264. /* Return true if mode M has type T. */
  265. template<typename T>
  266. inline bool
  267. is_a (machine_mode m)
  268. {
  269. return T::includes_p (m);
  270. }
  271. template<typename T, typename U>
  272. inline bool
  273. is_a (const opt_mode<U> &m)
  274. {
  275. return T::includes_p (m.else_void ());
  276. }
  277. /* Assert that mode M has type T, and return it in that form. */
  278. template<typename T>
  279. inline T
  280. as_a (machine_mode m)
  281. {
  282. gcc_checking_assert (T::includes_p (m));
  283. return typename mode_traits<T>::from_int (m);
  284. }
  285. template<typename T, typename U>
  286. inline T
  287. as_a (const opt_mode<U> &m)
  288. {
  289. return as_a <T> (m.else_void ());
  290. }
  291. /* Convert M to an opt_mode<T>. */
  292. template<typename T>
  293. inline opt_mode<T>
  294. dyn_cast (machine_mode m)
  295. {
  296. if (T::includes_p (m))
  297. return T (typename mode_traits<T>::from_int (m));
  298. return opt_mode<T> ();
  299. }
  300. template<typename T, typename U>
  301. inline opt_mode<T>
  302. dyn_cast (const opt_mode<U> &m)
  303. {
  304. return dyn_cast <T> (m.else_void ());
  305. }
  306. /* Return true if mode M has type T, storing it as a T in *RESULT
  307. if so. */
  308. template<typename T, typename U>
  309. inline bool
  310. is_a (machine_mode m, U *result)
  311. {
  312. if (T::includes_p (m))
  313. {
  314. *result = T (typename mode_traits<T>::from_int (m));
  315. return true;
  316. }
  317. return false;
  318. }
  319. /* Represents a machine mode that is known to be a SCALAR_INT_MODE_P. */
  320. class scalar_int_mode
  321. {
  322. public:
  323. typedef mode_traits<scalar_int_mode>::from_int from_int;
  324. typedef unsigned short measurement_type;
  325. ALWAYS_INLINE scalar_int_mode () {}
  326. ALWAYS_INLINE scalar_int_mode (from_int m) : m_mode (machine_mode (m)) {}
  327. ALWAYS_INLINE operator machine_mode () const { return m_mode; }
  328. static bool includes_p (machine_mode);
  329. protected:
  330. machine_mode m_mode;
  331. };
  332. /* Return true if M is a scalar_int_mode. */
  333. inline bool
  334. scalar_int_mode::includes_p (machine_mode m)
  335. {
  336. return SCALAR_INT_MODE_P (m);
  337. }
  338. /* Represents a machine mode that is known to be a SCALAR_FLOAT_MODE_P. */
  339. class scalar_float_mode
  340. {
  341. public:
  342. typedef mode_traits<scalar_float_mode>::from_int from_int;
  343. typedef unsigned short measurement_type;
  344. ALWAYS_INLINE scalar_float_mode () {}
  345. ALWAYS_INLINE scalar_float_mode (from_int m) : m_mode (machine_mode (m)) {}
  346. ALWAYS_INLINE operator machine_mode () const { return m_mode; }
  347. static bool includes_p (machine_mode);
  348. protected:
  349. machine_mode m_mode;
  350. };
  351. /* Return true if M is a scalar_float_mode. */
  352. inline bool
  353. scalar_float_mode::includes_p (machine_mode m)
  354. {
  355. return SCALAR_FLOAT_MODE_P (m);
  356. }
  357. /* Represents a machine mode that is known to be scalar. */
  358. class scalar_mode
  359. {
  360. public:
  361. typedef mode_traits<scalar_mode>::from_int from_int;
  362. typedef unsigned short measurement_type;
  363. ALWAYS_INLINE scalar_mode () {}
  364. ALWAYS_INLINE scalar_mode (from_int m) : m_mode (machine_mode (m)) {}
  365. ALWAYS_INLINE scalar_mode (const scalar_int_mode &m) : m_mode (m) {}
  366. ALWAYS_INLINE scalar_mode (const scalar_float_mode &m) : m_mode (m) {}
  367. ALWAYS_INLINE scalar_mode (const scalar_int_mode_pod &m) : m_mode (m) {}
  368. ALWAYS_INLINE operator machine_mode () const { return m_mode; }
  369. static bool includes_p (machine_mode);
  370. protected:
  371. machine_mode m_mode;
  372. };
  373. /* Return true if M represents some kind of scalar value. */
  374. inline bool
  375. scalar_mode::includes_p (machine_mode m)
  376. {
  377. switch (GET_MODE_CLASS (m))
  378. {
  379. case MODE_INT:
  380. case MODE_PARTIAL_INT:
  381. case MODE_FRACT:
  382. case MODE_UFRACT:
  383. case MODE_ACCUM:
  384. case MODE_UACCUM:
  385. case MODE_FLOAT:
  386. case MODE_DECIMAL_FLOAT:
  387. return true;
  388. default:
  389. return false;
  390. }
  391. }
  392. /* Represents a machine mode that is known to be a COMPLEX_MODE_P. */
  393. class complex_mode
  394. {
  395. public:
  396. typedef mode_traits<complex_mode>::from_int from_int;
  397. typedef unsigned short measurement_type;
  398. ALWAYS_INLINE complex_mode () {}
  399. ALWAYS_INLINE complex_mode (from_int m) : m_mode (machine_mode (m)) {}
  400. ALWAYS_INLINE operator machine_mode () const { return m_mode; }
  401. static bool includes_p (machine_mode);
  402. protected:
  403. machine_mode m_mode;
  404. };
  405. /* Return true if M is a complex_mode. */
  406. inline bool
  407. complex_mode::includes_p (machine_mode m)
  408. {
  409. return COMPLEX_MODE_P (m);
  410. }
  411. /* Return the base GET_MODE_SIZE value for MODE. */
  412. ALWAYS_INLINE poly_uint16
  413. mode_to_bytes (machine_mode mode)
  414. {
  415. #if GCC_VERSION >= 4001
  416. return (__builtin_constant_p (mode)
  417. ? mode_size_inline (mode) : mode_size[mode]);
  418. #else
  419. return mode_size[mode];
  420. #endif
  421. }
  422. /* Return the base GET_MODE_BITSIZE value for MODE. */
  423. ALWAYS_INLINE poly_uint16
  424. mode_to_bits (machine_mode mode)
  425. {
  426. return mode_to_bytes (mode) * BITS_PER_UNIT;
  427. }
  428. /* Return the base GET_MODE_PRECISION value for MODE. */
  429. ALWAYS_INLINE poly_uint16
  430. mode_to_precision (machine_mode mode)
  431. {
  432. return mode_precision[mode];
  433. }
  434. /* Return the base GET_MODE_INNER value for MODE. */
  435. ALWAYS_INLINE scalar_mode
  436. mode_to_inner (machine_mode mode)
  437. {
  438. #if GCC_VERSION >= 4001
  439. return scalar_mode::from_int (__builtin_constant_p (mode)
  440. ? mode_inner_inline (mode)
  441. : mode_inner[mode]);
  442. #else
  443. return scalar_mode::from_int (mode_inner[mode]);
  444. #endif
  445. }
  446. /* Return the base GET_MODE_UNIT_SIZE value for MODE. */
  447. ALWAYS_INLINE unsigned char
  448. mode_to_unit_size (machine_mode mode)
  449. {
  450. #if GCC_VERSION >= 4001
  451. return (__builtin_constant_p (mode)
  452. ? mode_unit_size_inline (mode) : mode_unit_size[mode]);
  453. #else
  454. return mode_unit_size[mode];
  455. #endif
  456. }
  457. /* Return the base GET_MODE_UNIT_PRECISION value for MODE. */
  458. ALWAYS_INLINE unsigned short
  459. mode_to_unit_precision (machine_mode mode)
  460. {
  461. #if GCC_VERSION >= 4001
  462. return (__builtin_constant_p (mode)
  463. ? mode_unit_precision_inline (mode) : mode_unit_precision[mode]);
  464. #else
  465. return mode_unit_precision[mode];
  466. #endif
  467. }
  468. /* Return the base GET_MODE_NUNITS value for MODE. */
  469. ALWAYS_INLINE poly_uint16
  470. mode_to_nunits (machine_mode mode)
  471. {
  472. #if GCC_VERSION >= 4001
  473. return (__builtin_constant_p (mode)
  474. ? mode_nunits_inline (mode) : mode_nunits[mode]);
  475. #else
  476. return mode_nunits[mode];
  477. #endif
  478. }
  479. /* Get the size in bytes of an object of mode MODE. */
  480. #if ONLY_FIXED_SIZE_MODES
  481. #define GET_MODE_SIZE(MODE) ((unsigned short) mode_to_bytes (MODE).coeffs[0])
  482. #else
  483. ALWAYS_INLINE poly_uint16
  484. GET_MODE_SIZE (machine_mode mode)
  485. {
  486. return mode_to_bytes (mode);
  487. }
  488. template<typename T>
  489. ALWAYS_INLINE typename if_poly<typename T::measurement_type>::type
  490. GET_MODE_SIZE (const T &mode)
  491. {
  492. return mode_to_bytes (mode);
  493. }
  494. template<typename T>
  495. ALWAYS_INLINE typename if_nonpoly<typename T::measurement_type>::type
  496. GET_MODE_SIZE (const T &mode)
  497. {
  498. return mode_to_bytes (mode).coeffs[0];
  499. }
  500. #endif
  501. /* Get the size in bits of an object of mode MODE. */
  502. #if ONLY_FIXED_SIZE_MODES
  503. #define GET_MODE_BITSIZE(MODE) ((unsigned short) mode_to_bits (MODE).coeffs[0])
  504. #else
  505. ALWAYS_INLINE poly_uint16
  506. GET_MODE_BITSIZE (machine_mode mode)
  507. {
  508. return mode_to_bits (mode);
  509. }
  510. template<typename T>
  511. ALWAYS_INLINE typename if_poly<typename T::measurement_type>::type
  512. GET_MODE_BITSIZE (const T &mode)
  513. {
  514. return mode_to_bits (mode);
  515. }
  516. template<typename T>
  517. ALWAYS_INLINE typename if_nonpoly<typename T::measurement_type>::type
  518. GET_MODE_BITSIZE (const T &mode)
  519. {
  520. return mode_to_bits (mode).coeffs[0];
  521. }
  522. #endif
  523. /* Get the number of value bits of an object of mode MODE. */
  524. #if ONLY_FIXED_SIZE_MODES
  525. #define GET_MODE_PRECISION(MODE) \
  526. ((unsigned short) mode_to_precision (MODE).coeffs[0])
  527. #else
  528. ALWAYS_INLINE poly_uint16
  529. GET_MODE_PRECISION (machine_mode mode)
  530. {
  531. return mode_to_precision (mode);
  532. }
  533. template<typename T>
  534. ALWAYS_INLINE typename if_poly<typename T::measurement_type>::type
  535. GET_MODE_PRECISION (const T &mode)
  536. {
  537. return mode_to_precision (mode);
  538. }
  539. template<typename T>
  540. ALWAYS_INLINE typename if_nonpoly<typename T::measurement_type>::type
  541. GET_MODE_PRECISION (const T &mode)
  542. {
  543. return mode_to_precision (mode).coeffs[0];
  544. }
  545. #endif
  546. /* Get the number of integral bits of an object of mode MODE. */
  547. extern CONST_MODE_IBIT unsigned char mode_ibit[NUM_MACHINE_MODES];
  548. #define GET_MODE_IBIT(MODE) mode_ibit[MODE]
  549. /* Get the number of fractional bits of an object of mode MODE. */
  550. extern CONST_MODE_FBIT unsigned char mode_fbit[NUM_MACHINE_MODES];
  551. #define GET_MODE_FBIT(MODE) mode_fbit[MODE]
  552. /* Get a bitmask containing 1 for all bits in a word
  553. that fit within mode MODE. */
  554. extern const unsigned HOST_WIDE_INT mode_mask_array[NUM_MACHINE_MODES];
  555. #define GET_MODE_MASK(MODE) mode_mask_array[MODE]
  556. /* Return the mode of the basic parts of MODE. For vector modes this is the
  557. mode of the vector elements. For complex modes it is the mode of the real
  558. and imaginary parts. For other modes it is MODE itself. */
  559. #define GET_MODE_INNER(MODE) (mode_to_inner (MODE))
  560. /* Get the size in bytes or bits of the basic parts of an
  561. object of mode MODE. */
  562. #define GET_MODE_UNIT_SIZE(MODE) mode_to_unit_size (MODE)
  563. #define GET_MODE_UNIT_BITSIZE(MODE) \
  564. ((unsigned short) (GET_MODE_UNIT_SIZE (MODE) * BITS_PER_UNIT))
  565. #define GET_MODE_UNIT_PRECISION(MODE) (mode_to_unit_precision (MODE))
  566. /* Get the number of units in an object of mode MODE. This is 2 for
  567. complex modes and the number of elements for vector modes. */
  568. #if ONLY_FIXED_SIZE_MODES
  569. #define GET_MODE_NUNITS(MODE) (mode_to_nunits (MODE).coeffs[0])
  570. #else
  571. ALWAYS_INLINE poly_uint16
  572. GET_MODE_NUNITS (machine_mode mode)
  573. {
  574. return mode_to_nunits (mode);
  575. }
  576. template<typename T>
  577. ALWAYS_INLINE typename if_poly<typename T::measurement_type>::type
  578. GET_MODE_NUNITS (const T &mode)
  579. {
  580. return mode_to_nunits (mode);
  581. }
  582. template<typename T>
  583. ALWAYS_INLINE typename if_nonpoly<typename T::measurement_type>::type
  584. GET_MODE_NUNITS (const T &mode)
  585. {
  586. return mode_to_nunits (mode).coeffs[0];
  587. }
  588. #endif
  589. /* Get the next wider natural mode (eg, QI -> HI -> SI -> DI -> TI). */
  590. template<typename T>
  591. ALWAYS_INLINE opt_mode<T>
  592. GET_MODE_WIDER_MODE (const T &m)
  593. {
  594. return typename opt_mode<T>::from_int (mode_wider[m]);
  595. }
  596. /* For scalars, this is a mode with twice the precision. For vectors,
  597. this is a mode with the same inner mode but with twice the elements. */
  598. template<typename T>
  599. ALWAYS_INLINE opt_mode<T>
  600. GET_MODE_2XWIDER_MODE (const T &m)
  601. {
  602. return typename opt_mode<T>::from_int (mode_2xwider[m]);
  603. }
  604. /* Get the complex mode from the component mode. */
  605. extern const unsigned char mode_complex[NUM_MACHINE_MODES];
  606. #define GET_MODE_COMPLEX_MODE(MODE) ((machine_mode) mode_complex[MODE])
  607. /* Represents a machine mode that must have a fixed size. The main
  608. use of this class is to represent the modes of objects that always
  609. have static storage duration, such as constant pool entries.
  610. (No current target supports the concept of variable-size static data.) */
  611. class fixed_size_mode
  612. {
  613. public:
  614. typedef mode_traits<fixed_size_mode>::from_int from_int;
  615. typedef unsigned short measurement_type;
  616. ALWAYS_INLINE fixed_size_mode () {}
  617. ALWAYS_INLINE fixed_size_mode (from_int m) : m_mode (machine_mode (m)) {}
  618. ALWAYS_INLINE fixed_size_mode (const scalar_mode &m) : m_mode (m) {}
  619. ALWAYS_INLINE fixed_size_mode (const scalar_int_mode &m) : m_mode (m) {}
  620. ALWAYS_INLINE fixed_size_mode (const scalar_float_mode &m) : m_mode (m) {}
  621. ALWAYS_INLINE fixed_size_mode (const scalar_mode_pod &m) : m_mode (m) {}
  622. ALWAYS_INLINE fixed_size_mode (const scalar_int_mode_pod &m) : m_mode (m) {}
  623. ALWAYS_INLINE fixed_size_mode (const complex_mode &m) : m_mode (m) {}
  624. ALWAYS_INLINE operator machine_mode () const { return m_mode; }
  625. static bool includes_p (machine_mode);
  626. protected:
  627. machine_mode m_mode;
  628. };
  629. /* Return true if MODE has a fixed size. */
  630. inline bool
  631. fixed_size_mode::includes_p (machine_mode mode)
  632. {
  633. return mode_to_bytes (mode).is_constant ();
  634. }
  635. /* Wrapper for mode arguments to target macros, so that if a target
  636. doesn't need polynomial-sized modes, its header file can continue
  637. to treat everything as fixed_size_mode. This should go away once
  638. macros are moved to target hooks. It shouldn't be used in other
  639. contexts. */
  640. #if NUM_POLY_INT_COEFFS == 1
  641. #define MACRO_MODE(MODE) (as_a <fixed_size_mode> (MODE))
  642. #else
  643. #define MACRO_MODE(MODE) (MODE)
  644. #endif
  645. extern opt_machine_mode mode_for_size (poly_uint64, enum mode_class, int);
  646. /* Return the machine mode to use for a MODE_INT of SIZE bits, if one
  647. exists. If LIMIT is nonzero, modes wider than MAX_FIXED_MODE_SIZE
  648. will not be used. */
  649. inline opt_scalar_int_mode
  650. int_mode_for_size (poly_uint64 size, int limit)
  651. {
  652. return dyn_cast <scalar_int_mode> (mode_for_size (size, MODE_INT, limit));
  653. }
  654. /* Return the machine mode to use for a MODE_FLOAT of SIZE bits, if one
  655. exists. */
  656. inline opt_scalar_float_mode
  657. float_mode_for_size (poly_uint64 size)
  658. {
  659. return dyn_cast <scalar_float_mode> (mode_for_size (size, MODE_FLOAT, 0));
  660. }
  661. /* Likewise for MODE_DECIMAL_FLOAT. */
  662. inline opt_scalar_float_mode
  663. decimal_float_mode_for_size (unsigned int size)
  664. {
  665. return dyn_cast <scalar_float_mode>
  666. (mode_for_size (size, MODE_DECIMAL_FLOAT, 0));
  667. }
  668. extern machine_mode smallest_mode_for_size (poly_uint64, enum mode_class);
  669. /* Find the narrowest integer mode that contains at least SIZE bits.
  670. Such a mode must exist. */
  671. inline scalar_int_mode
  672. smallest_int_mode_for_size (poly_uint64 size)
  673. {
  674. return as_a <scalar_int_mode> (smallest_mode_for_size (size, MODE_INT));
  675. }
  676. extern opt_scalar_int_mode int_mode_for_mode (machine_mode);
  677. extern opt_machine_mode bitwise_mode_for_mode (machine_mode);
  678. extern opt_machine_mode mode_for_vector (scalar_mode, poly_uint64);
  679. extern opt_machine_mode mode_for_int_vector (unsigned int, poly_uint64);
  680. /* Return the integer vector equivalent of MODE, if one exists. In other
  681. words, return the mode for an integer vector that has the same number
  682. of bits as MODE and the same number of elements as MODE, with the
  683. latter being 1 if MODE is scalar. The returned mode can be either
  684. an integer mode or a vector mode. */
  685. inline opt_machine_mode
  686. mode_for_int_vector (machine_mode mode)
  687. {
  688. return mode_for_int_vector (GET_MODE_UNIT_BITSIZE (mode),
  689. GET_MODE_NUNITS (mode));
  690. }
  691. /* A class for iterating through possible bitfield modes. */
  692. class bit_field_mode_iterator
  693. {
  694. public:
  695. bit_field_mode_iterator (HOST_WIDE_INT, HOST_WIDE_INT,
  696. poly_int64, poly_int64,
  697. unsigned int, bool);
  698. bool next_mode (scalar_int_mode *);
  699. bool prefer_smaller_modes ();
  700. private:
  701. opt_scalar_int_mode m_mode;
  702. /* We use signed values here because the bit position can be negative
  703. for invalid input such as gcc.dg/pr48335-8.c. */
  704. HOST_WIDE_INT m_bitsize;
  705. HOST_WIDE_INT m_bitpos;
  706. poly_int64 m_bitregion_start;
  707. poly_int64 m_bitregion_end;
  708. unsigned int m_align;
  709. bool m_volatilep;
  710. int m_count;
  711. };
  712. /* Find the best mode to use to access a bit field. */
  713. extern bool get_best_mode (int, int, poly_uint64, poly_uint64, unsigned int,
  714. unsigned HOST_WIDE_INT, bool, scalar_int_mode *);
  715. /* Determine alignment, 1<=result<=BIGGEST_ALIGNMENT. */
  716. extern CONST_MODE_BASE_ALIGN unsigned short mode_base_align[NUM_MACHINE_MODES];
  717. extern unsigned get_mode_alignment (machine_mode);
  718. #define GET_MODE_ALIGNMENT(MODE) get_mode_alignment (MODE)
  719. /* For each class, get the narrowest mode in that class. */
  720. extern const unsigned char class_narrowest_mode[MAX_MODE_CLASS];
  721. #define GET_CLASS_NARROWEST_MODE(CLASS) \
  722. ((machine_mode) class_narrowest_mode[CLASS])
  723. /* The narrowest full integer mode available on the target. */
  724. #define NARROWEST_INT_MODE \
  725. (scalar_int_mode \
  726. (scalar_int_mode::from_int (class_narrowest_mode[MODE_INT])))
  727. /* Return the narrowest mode in T's class. */
  728. template<typename T>
  729. inline T
  730. get_narrowest_mode (T mode)
  731. {
  732. return typename mode_traits<T>::from_int
  733. (class_narrowest_mode[GET_MODE_CLASS (mode)]);
  734. }
  735. /* Define the integer modes whose sizes are BITS_PER_UNIT and BITS_PER_WORD
  736. and the mode whose class is Pmode and whose size is POINTER_SIZE. */
  737. extern scalar_int_mode byte_mode;
  738. extern scalar_int_mode word_mode;
  739. extern scalar_int_mode ptr_mode;
  740. /* Target-dependent machine mode initialization - in insn-modes.c. */
  741. extern void init_adjust_machine_modes (void);
  742. #define TRULY_NOOP_TRUNCATION_MODES_P(MODE1, MODE2) \
  743. (targetm.truly_noop_truncation (GET_MODE_PRECISION (MODE1), \
  744. GET_MODE_PRECISION (MODE2)))
  745. /* Return true if MODE is a scalar integer mode that fits in a
  746. HOST_WIDE_INT. */
  747. inline bool
  748. HWI_COMPUTABLE_MODE_P (machine_mode mode)
  749. {
  750. machine_mode mme = mode;
  751. return (SCALAR_INT_MODE_P (mme)
  752. && mode_to_precision (mme).coeffs[0] <= HOST_BITS_PER_WIDE_INT);
  753. }
  754. inline bool
  755. HWI_COMPUTABLE_MODE_P (scalar_int_mode mode)
  756. {
  757. return GET_MODE_PRECISION (mode) <= HOST_BITS_PER_WIDE_INT;
  758. }
  759. struct int_n_data_t {
  760. /* These parts are initailized by genmodes output */
  761. unsigned int bitsize;
  762. scalar_int_mode_pod m;
  763. /* RID_* is RID_INTN_BASE + index into this array */
  764. };
  765. /* This is also in tree.h. genmodes.c guarantees the're sorted from
  766. smallest bitsize to largest bitsize. */
  767. extern bool int_n_enabled_p[NUM_INT_N_ENTS];
  768. extern const int_n_data_t int_n_data[NUM_INT_N_ENTS];
  769. /* Return true if MODE has class MODE_INT, storing it as a scalar_int_mode
  770. in *INT_MODE if so. */
  771. template<typename T>
  772. inline bool
  773. is_int_mode (machine_mode mode, T *int_mode)
  774. {
  775. if (GET_MODE_CLASS (mode) == MODE_INT)
  776. {
  777. *int_mode = scalar_int_mode (scalar_int_mode::from_int (mode));
  778. return true;
  779. }
  780. return false;
  781. }
  782. /* Return true if MODE has class MODE_FLOAT, storing it as a
  783. scalar_float_mode in *FLOAT_MODE if so. */
  784. template<typename T>
  785. inline bool
  786. is_float_mode (machine_mode mode, T *float_mode)
  787. {
  788. if (GET_MODE_CLASS (mode) == MODE_FLOAT)
  789. {
  790. *float_mode = scalar_float_mode (scalar_float_mode::from_int (mode));
  791. return true;
  792. }
  793. return false;
  794. }
  795. /* Return true if MODE has class MODE_COMPLEX_INT, storing it as
  796. a complex_mode in *CMODE if so. */
  797. template<typename T>
  798. inline bool
  799. is_complex_int_mode (machine_mode mode, T *cmode)
  800. {
  801. if (GET_MODE_CLASS (mode) == MODE_COMPLEX_INT)
  802. {
  803. *cmode = complex_mode (complex_mode::from_int (mode));
  804. return true;
  805. }
  806. return false;
  807. }
  808. /* Return true if MODE has class MODE_COMPLEX_FLOAT, storing it as
  809. a complex_mode in *CMODE if so. */
  810. template<typename T>
  811. inline bool
  812. is_complex_float_mode (machine_mode mode, T *cmode)
  813. {
  814. if (GET_MODE_CLASS (mode) == MODE_COMPLEX_FLOAT)
  815. {
  816. *cmode = complex_mode (complex_mode::from_int (mode));
  817. return true;
  818. }
  819. return false;
  820. }
  821. /* Return true if MODE is a scalar integer mode with a precision
  822. smaller than LIMIT's precision. */
  823. inline bool
  824. is_narrower_int_mode (machine_mode mode, scalar_int_mode limit)
  825. {
  826. scalar_int_mode int_mode;
  827. return (is_a <scalar_int_mode> (mode, &int_mode)
  828. && GET_MODE_PRECISION (int_mode) < GET_MODE_PRECISION (limit));
  829. }
  830. namespace mode_iterator
  831. {
  832. /* Start mode iterator *ITER at the first mode in class MCLASS, if any. */
  833. template<typename T>
  834. inline void
  835. start (opt_mode<T> *iter, enum mode_class mclass)
  836. {
  837. if (GET_CLASS_NARROWEST_MODE (mclass) == E_VOIDmode)
  838. *iter = opt_mode<T> ();
  839. else
  840. *iter = as_a<T> (GET_CLASS_NARROWEST_MODE (mclass));
  841. }
  842. inline void
  843. start (machine_mode *iter, enum mode_class mclass)
  844. {
  845. *iter = GET_CLASS_NARROWEST_MODE (mclass);
  846. }
  847. /* Return true if mode iterator *ITER has not reached the end. */
  848. template<typename T>
  849. inline bool
  850. iterate_p (opt_mode<T> *iter)
  851. {
  852. return iter->exists ();
  853. }
  854. inline bool
  855. iterate_p (machine_mode *iter)
  856. {
  857. return *iter != E_VOIDmode;
  858. }
  859. /* Set mode iterator *ITER to the next widest mode in the same class,
  860. if any. */
  861. template<typename T>
  862. inline void
  863. get_wider (opt_mode<T> *iter)
  864. {
  865. *iter = GET_MODE_WIDER_MODE (iter->require ());
  866. }
  867. inline void
  868. get_wider (machine_mode *iter)
  869. {
  870. *iter = GET_MODE_WIDER_MODE (*iter).else_void ();
  871. }
  872. /* Set mode iterator *ITER to the next widest mode in the same class.
  873. Such a mode is known to exist. */
  874. template<typename T>
  875. inline void
  876. get_known_wider (T *iter)
  877. {
  878. *iter = GET_MODE_WIDER_MODE (*iter).require ();
  879. }
  880. /* Set mode iterator *ITER to the mode that is two times wider than the
  881. current one, if such a mode exists. */
  882. template<typename T>
  883. inline void
  884. get_2xwider (opt_mode<T> *iter)
  885. {
  886. *iter = GET_MODE_2XWIDER_MODE (iter->require ());
  887. }
  888. inline void
  889. get_2xwider (machine_mode *iter)
  890. {
  891. *iter = GET_MODE_2XWIDER_MODE (*iter).else_void ();
  892. }
  893. }
  894. /* Make ITERATOR iterate over all the modes in mode class CLASS,
  895. from narrowest to widest. */
  896. #define FOR_EACH_MODE_IN_CLASS(ITERATOR, CLASS) \
  897. for (mode_iterator::start (&(ITERATOR), CLASS); \
  898. mode_iterator::iterate_p (&(ITERATOR)); \
  899. mode_iterator::get_wider (&(ITERATOR)))
  900. /* Make ITERATOR iterate over all the modes in the range [START, END),
  901. in order of increasing width. */
  902. #define FOR_EACH_MODE(ITERATOR, START, END) \
  903. for ((ITERATOR) = (START); \
  904. (ITERATOR) != (END); \
  905. mode_iterator::get_known_wider (&(ITERATOR)))
  906. /* Make ITERATOR iterate over START and all wider modes in the same
  907. class, in order of increasing width. */
  908. #define FOR_EACH_MODE_FROM(ITERATOR, START) \
  909. for ((ITERATOR) = (START); \
  910. mode_iterator::iterate_p (&(ITERATOR)); \
  911. mode_iterator::get_wider (&(ITERATOR)))
  912. /* Make ITERATOR iterate over modes in the range [NARROWEST, END)
  913. in order of increasing width, where NARROWEST is the narrowest mode
  914. in END's class. */
  915. #define FOR_EACH_MODE_UNTIL(ITERATOR, END) \
  916. FOR_EACH_MODE (ITERATOR, get_narrowest_mode (END), END)
  917. /* Make ITERATOR iterate over modes in the same class as MODE, in order
  918. of increasing width. Start at the first mode wider than START,
  919. or don't iterate at all if there is no wider mode. */
  920. #define FOR_EACH_WIDER_MODE(ITERATOR, START) \
  921. for ((ITERATOR) = (START), mode_iterator::get_wider (&(ITERATOR)); \
  922. mode_iterator::iterate_p (&(ITERATOR)); \
  923. mode_iterator::get_wider (&(ITERATOR)))
  924. /* Make ITERATOR iterate over modes in the same class as MODE, in order
  925. of increasing width, and with each mode being twice the width of the
  926. previous mode. Start at the mode that is two times wider than START,
  927. or don't iterate at all if there is no such mode. */
  928. #define FOR_EACH_2XWIDER_MODE(ITERATOR, START) \
  929. for ((ITERATOR) = (START), mode_iterator::get_2xwider (&(ITERATOR)); \
  930. mode_iterator::iterate_p (&(ITERATOR)); \
  931. mode_iterator::get_2xwider (&(ITERATOR)))
  932. template<typename T>
  933. void
  934. gt_ggc_mx (pod_mode<T> *)
  935. {
  936. }
  937. template<typename T>
  938. void
  939. gt_pch_nx (pod_mode<T> *)
  940. {
  941. }
  942. template<typename T>
  943. void
  944. gt_pch_nx (pod_mode<T> *, void (*) (void *, void *), void *)
  945. {
  946. }
  947. #endif /* not HAVE_MACHINE_MODES */