align.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. /* Alignment-related classes.
  2. Copyright (C) 2018-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. /* Align flags tuple with alignment in log form and with a maximum skip. */
  16. struct align_flags_tuple
  17. {
  18. /* Values of the -falign-* flags: how much to align labels in code.
  19. log is "align to 2^log" (so 0 means no alignment).
  20. maxskip is the maximum allowed amount of padding to insert. */
  21. int log;
  22. int maxskip;
  23. /* Normalize filled values so that maxskip is not bigger than 1 << log. */
  24. void normalize ()
  25. {
  26. int n = (1 << log);
  27. if (maxskip > n)
  28. maxskip = n - 1;
  29. }
  30. /* Return original value of an alignment flag. */
  31. int get_value ()
  32. {
  33. return maxskip + 1;
  34. }
  35. };
  36. /* Alignment flags is structure used as value of -align-* options.
  37. It's used in target-dependant code. */
  38. struct align_flags
  39. {
  40. /* Default constructor. */
  41. align_flags (int log0 = 0, int maxskip0 = 0, int log1 = 0, int maxskip1 = 0)
  42. {
  43. levels[0].log = log0;
  44. levels[0].maxskip = maxskip0;
  45. levels[1].log = log1;
  46. levels[1].maxskip = maxskip1;
  47. normalize ();
  48. }
  49. /* Normalize both components of align_flags. */
  50. void normalize ()
  51. {
  52. for (unsigned i = 0; i < 2; i++)
  53. levels[i].normalize ();
  54. }
  55. /* Get alignment that is common bigger alignment of alignments F0 and F1. */
  56. static align_flags max (const align_flags f0, const align_flags f1)
  57. {
  58. int log0 = MAX (f0.levels[0].log, f1.levels[0].log);
  59. int maxskip0 = MAX (f0.levels[0].maxskip, f1.levels[0].maxskip);
  60. int log1 = MAX (f0.levels[1].log, f1.levels[1].log);
  61. int maxskip1 = MAX (f0.levels[1].maxskip, f1.levels[1].maxskip);
  62. return align_flags (log0, maxskip0, log1, maxskip1);
  63. }
  64. align_flags_tuple levels[2];
  65. };
  66. /* Define maximum supported code alignment. */
  67. #define MAX_CODE_ALIGN 16
  68. #define MAX_CODE_ALIGN_VALUE (1 << MAX_CODE_ALIGN)