n386con.pas 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142
  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,globtype,
  31. cpubase,
  32. cga,cginfo,cgbase,rgobj,rgcpu;
  33. {*****************************************************************************
  34. TI386REALCONSTNODE
  35. *****************************************************************************}
  36. function ti386realconstnode.pass_1 : tnode;
  37. begin
  38. result:=nil;
  39. if (value_real=1.0) or (value_real=0.0) then
  40. begin
  41. expectloc:=LOC_FPUREGISTER;
  42. registersfpu:=1;
  43. end
  44. else
  45. expectloc:=LOC_CREFERENCE;
  46. end;
  47. procedure ti386realconstnode.pass_2;
  48. begin
  49. if (value_real=1.0) then
  50. begin
  51. emit_none(A_FLD1,S_NO);
  52. location_reset(location,LOC_FPUREGISTER,def_cgsize(resulttype.def));
  53. location.register:=NR_ST;
  54. inc(trgcpu(rg).fpuvaroffset);
  55. end
  56. else if (value_real=0.0) then
  57. begin
  58. emit_none(A_FLDZ,S_NO);
  59. location_reset(location,LOC_FPUREGISTER,def_cgsize(resulttype.def));
  60. location.register:=NR_ST;
  61. inc(trgcpu(rg).fpuvaroffset);
  62. end
  63. else
  64. inherited pass_2;
  65. end;
  66. begin
  67. crealconstnode:=ti386realconstnode;
  68. end.
  69. {
  70. $Log$
  71. Revision 1.20 2003-09-03 15:55:01 peter
  72. * NEWRA branch merged
  73. Revision 1.19.2.1 2003/08/29 17:29:00 peter
  74. * next batch of updates
  75. Revision 1.19 2003/04/22 23:50:23 peter
  76. * firstpass uses expectloc
  77. * checks if there are differences between the expectloc and
  78. location.loc from secondpass in EXTDEBUG
  79. Revision 1.18 2003/04/22 09:54:18 peter
  80. * use location_reset
  81. Revision 1.17 2003/01/08 18:43:57 daniel
  82. * Tregister changed into a record
  83. Revision 1.16 2002/05/18 13:34:25 peter
  84. * readded missing revisions
  85. Revision 1.15 2002/05/16 19:46:51 carl
  86. + defines.inc -> fpcdefs.inc to avoid conflicts if compiling by hand
  87. + try to fix temp allocation (still in ifdef)
  88. + generic constructor calls
  89. + start of tassembler / tmodulebase class cleanup
  90. Revision 1.13 2002/04/02 17:11:36 peter
  91. * tlocation,treference update
  92. * LOC_CONSTANT added for better constant handling
  93. * secondadd splitted in multiple routines
  94. * location_force_reg added for loading a location to a register
  95. of a specified size
  96. * secondassignment parses now first the right and then the left node
  97. (this is compatible with Kylix). This saves a lot of push/pop especially
  98. with string operations
  99. * adapted some routines to use the new cg methods
  100. Revision 1.12 2002/03/31 20:26:38 jonas
  101. + a_loadfpu_* and a_loadmm_* methods in tcg
  102. * register allocation is now handled by a class and is mostly processor
  103. independent (+rgobj.pas and i386/rgcpu.pas)
  104. * temp allocation is now handled by a class (+tgobj.pas, -i386\tgcpu.pas)
  105. * some small improvements and fixes to the optimizer
  106. * some register allocation fixes
  107. * some fpuvaroffset fixes in the unary minus node
  108. * push/popusedregisters is now called rg.save/restoreusedregisters and
  109. (for i386) uses temps instead of push/pop's when using -Op3 (that code is
  110. also better optimizable)
  111. * fixed and optimized register saving/restoring for new/dispose nodes
  112. * LOC_FPU locations now also require their "register" field to be set to
  113. R_ST, not R_ST0 (the latter is used for LOC_CFPUREGISTER locations only)
  114. - list field removed of the tnode class because it's not used currently
  115. and can cause hard-to-find bugs
  116. }