n386con.pas 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. {
  2. $Id$
  3. Copyright (c) 1998-2002 by Florian Klaempfl
  4. Generate i386 assembler for constants
  5. This program is free software; you can redistribute it and/or modify
  6. it under the terms of the GNU General Public License as published by
  7. the Free Software Foundation; either version 2 of the License, or
  8. (at your option) any later version.
  9. This program is distributed in the hope that it will be useful,
  10. but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. GNU General Public License for more details.
  13. You should have received a copy of the GNU General Public License
  14. along with this program; if not, write to the Free Software
  15. Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
  16. ****************************************************************************
  17. }
  18. unit n386con;
  19. {$i fpcdefs.inc}
  20. interface
  21. uses
  22. node,ncon,ncgcon;
  23. type
  24. ti386realconstnode = class(tcgrealconstnode)
  25. function pass_1 : tnode;override;
  26. procedure pass_2;override;
  27. end;
  28. implementation
  29. uses
  30. systems,globals,
  31. defutil,
  32. cpubase,
  33. cga,cgx86,cgobj,cgbase;
  34. {*****************************************************************************
  35. TI386REALCONSTNODE
  36. *****************************************************************************}
  37. function ti386realconstnode.pass_1 : tnode;
  38. begin
  39. result:=nil;
  40. if is_number_float(value_real) and (value_real=1.0) or (value_real=0.0) then
  41. begin
  42. expectloc:=LOC_FPUREGISTER;
  43. registersfpu:=1;
  44. end
  45. else
  46. expectloc:=LOC_CREFERENCE;
  47. end;
  48. procedure ti386realconstnode.pass_2;
  49. begin
  50. if is_number_float(value_real) then
  51. begin
  52. if (value_real=1.0) then
  53. begin
  54. emit_none(A_FLD1,S_NO);
  55. location_reset(location,LOC_FPUREGISTER,def_cgsize(resulttype.def));
  56. location.register:=NR_ST;
  57. tcgx86(cg).inc_fpu_stack;
  58. end
  59. else if (value_real=0.0) then
  60. begin
  61. emit_none(A_FLDZ,S_NO);
  62. location_reset(location,LOC_FPUREGISTER,def_cgsize(resulttype.def));
  63. location.register:=NR_ST;
  64. tcgx86(cg).inc_fpu_stack;
  65. end
  66. else
  67. inherited pass_2;
  68. end
  69. else
  70. inherited pass_2;
  71. end;
  72. begin
  73. crealconstnode:=ti386realconstnode;
  74. end.
  75. {
  76. $Log$
  77. Revision 1.24 2003-10-10 17:48:14 peter
  78. * old trgobj moved to x86/rgcpu and renamed to trgx86fpu
  79. * tregisteralloctor renamed to trgobj
  80. * removed rgobj from a lot of units
  81. * moved location_* and reference_* to cgobj
  82. * first things for mmx register allocation
  83. Revision 1.23 2003/10/09 21:31:37 daniel
  84. * Register allocator splitted, ans abstract now
  85. Revision 1.22 2003/10/01 20:34:49 peter
  86. * procinfo unit contains tprocinfo
  87. * cginfo renamed to cgbase
  88. * moved cgmessage to verbose
  89. * fixed ppc and sparc compiles
  90. Revision 1.21 2003/09/06 16:47:24 florian
  91. + support of NaN and Inf in the compiler as values of real constants
  92. Revision 1.20 2003/09/03 15:55:01 peter
  93. * NEWRA branch merged
  94. Revision 1.19.2.1 2003/08/29 17:29:00 peter
  95. * next batch of updates
  96. Revision 1.19 2003/04/22 23:50:23 peter
  97. * firstpass uses expectloc
  98. * checks if there are differences between the expectloc and
  99. location.loc from secondpass in EXTDEBUG
  100. Revision 1.18 2003/04/22 09:54:18 peter
  101. * use location_reset
  102. Revision 1.17 2003/01/08 18:43:57 daniel
  103. * Tregister changed into a record
  104. Revision 1.16 2002/05/18 13:34:25 peter
  105. * readded missing revisions
  106. Revision 1.15 2002/05/16 19:46:51 carl
  107. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  108. + try to fix temp allocation (still in ifdef)
  109. + generic constructor calls
  110. + start of tassembler / tmodulebase class cleanup
  111. Revision 1.13 2002/04/02 17:11:36 peter
  112. * tlocation,treference update
  113. * LOC_CONSTANT added for better constant handling
  114. * secondadd splitted in multiple routines
  115. * location_force_reg added for loading a location to a register
  116. of a specified size
  117. * secondassignment parses now first the right and then the left node
  118. (this is compatible with Kylix). This saves a lot of push/pop especially
  119. with string operations
  120. * adapted some routines to use the new cg methods
  121. Revision 1.12 2002/03/31 20:26:38 jonas
  122. + a_loadfpu_* and a_loadmm_* methods in tcg
  123. * register allocation is now handled by a class and is mostly processor
  124. independent (+rgobj.pas and i386/rgcpu.pas)
  125. * temp allocation is now handled by a class (+tgobj.pas, -i386\tgcpu.pas)
  126. * some small improvements and fixes to the optimizer
  127. * some register allocation fixes
  128. * some fpuvaroffset fixes in the unary minus node
  129. * push/popusedregisters is now called rg.save/restoreusedregisters and
  130. (for i386) uses temps instead of push/pop's when using -Op3 (that code is
  131. also better optimizable)
  132. * fixed and optimized register saving/restoring for new/dispose nodes
  133. * LOC_FPU locations now also require their "register" field to be set to
  134. R_ST, not R_ST0 (the latter is used for LOC_CFPUREGISTER locations only)
  135. - list field removed of the tnode class because it's not used currently
  136. and can cause hard-to-find bugs
  137. }