armpara.pas 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  1. {
  2. Copyright (c) 2019 by Jonas Maebe
  3. ARM and AArch64 common parameter helpers
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 2 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program; if not, write to the Free Software
  14. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  15. ****************************************************************************
  16. }
  17. unit armpara;
  18. {$mode objfpc}
  19. interface
  20. uses
  21. symtype,
  22. paramgr;
  23. type
  24. tarmgenparamanager = class(tparamanager)
  25. protected
  26. { Returns whether a def is a "homogeneous float array" at the machine level.
  27. This means that in the memory layout, the def only consists of maximally
  28. 4 floating point values that appear consecutively in memory }
  29. function is_hfa(p: tdef; out basedef: tdef) : boolean;
  30. private
  31. function is_hfa_internal(p: tdef; var basedef: tdef; var elecount: longint): boolean;
  32. end;
  33. implementation
  34. uses
  35. symconst,symdef,symsym,defutil;
  36. function tarmgenparamanager.is_hfa(p: tdef; out basedef: tdef): boolean;
  37. var
  38. elecount: longint;
  39. begin
  40. result:=false;
  41. basedef:=nil;
  42. elecount:=0;
  43. result:=is_hfa_internal(p,basedef,elecount);
  44. result:=
  45. result and
  46. (elecount>0) and
  47. (elecount<=4) and
  48. (p.size=basedef.size*elecount)
  49. end;
  50. function tarmgenparamanager.is_hfa_internal(p: tdef; var basedef: tdef; var elecount: longint): boolean;
  51. var
  52. i: longint;
  53. sym: tsym;
  54. tmpelecount: longint;
  55. begin
  56. result:=false;
  57. case p.typ of
  58. arraydef:
  59. begin
  60. if is_special_array(p) then
  61. exit;
  62. { an array of empty records has no influence }
  63. if tarraydef(p).elementdef.size=0 then
  64. begin
  65. result:=true;
  66. exit
  67. end;
  68. tmpelecount:=0;
  69. if not is_hfa_internal(tarraydef(p).elementdef,basedef,tmpelecount) then
  70. exit;
  71. { tmpelecount now contains the number of hfa elements in a
  72. single array element (e.g. 2 if it's an array of a record
  73. containing two singles) -> multiply by number of elements
  74. in the array }
  75. inc(elecount,tarraydef(p).elecount*tmpelecount);
  76. if elecount>4 then
  77. exit;
  78. result:=true;
  79. end;
  80. floatdef:
  81. begin
  82. if not assigned(basedef) then
  83. basedef:=p
  84. else if basedef<>p then
  85. exit;
  86. inc(elecount);
  87. result:=true;
  88. end;
  89. recorddef:
  90. begin
  91. for i:=0 to tabstractrecorddef(p).symtable.symlist.count-1 do
  92. begin
  93. sym:=tsym(tabstractrecorddef(p).symtable.symlist[i]);
  94. if sym.typ<>fieldvarsym then
  95. continue;
  96. if not is_hfa_internal(tfieldvarsym(sym).vardef,basedef,elecount) then
  97. exit
  98. end;
  99. result:=true;
  100. end;
  101. else
  102. exit
  103. end;
  104. end;
  105. end.