tfpu3.pp 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120
  1. { %CPU=i386 }
  2. { %OPT=-Cg- }
  3. { %NOTE= this test requires that nasm assembler is installed }
  4. { testfdiv variant with NASM output forced }
  5. {$ifdef go32v2}
  6. {$output_format nasmcoff}
  7. {$endif}
  8. {$ifdef win32}
  9. {$output_format nasmwin32}
  10. {$endif}
  11. {$ifdef Unix}
  12. {$output_format nasmelf}
  13. {$endif}
  14. { This test program deals with the
  15. the delicate problem of
  16. non commutative FPU instruction
  17. where the destination register
  18. is ST(1) to ST(7)
  19. Whereas Intel interprets
  20. fdiv st(1),st
  21. as
  22. st(1):=st(1) / st
  23. The ATT read
  24. fdiv %st,%st(1)
  25. as
  26. st(1):=st/st(1)
  27. Should be tested with
  28. different output styles :
  29. for go32v2
  30. -Aas -Acoff and -Anasmcoff
  31. for win32
  32. -Aas -Apecoff and -Anasmwin32
  33. for linux
  34. -Aas and -Anasmelf
  35. }
  36. program test_nasm_div;
  37. var
  38. x,y,z : double;
  39. begin
  40. x:=4;
  41. y:=2;
  42. Writeln('4/2=',x/y:0:2);
  43. if x/y <> 2.0 then
  44. Halt(1);
  45. {$asmmode att}
  46. asm
  47. fldl y
  48. fldl x
  49. fdivp %st,%st(1)
  50. fstpl z
  51. end;
  52. Writeln('ATT result of 4/2=',z:0:2);
  53. if z <> 2.0 then
  54. Halt(1);
  55. asm
  56. fldl y
  57. fldl x
  58. fdiv %st(1),%st
  59. fstpl z
  60. fstp %st
  61. end;
  62. Writeln('ATT result of 4/2=',z:0:2);
  63. if z <> 2.0 then
  64. Halt(1);
  65. asm
  66. fldl y
  67. fldl x
  68. fdiv %st,%st(1)
  69. fstp %st
  70. fstpl z
  71. end;
  72. Writeln('ATT result of 4/2=',z:0:2);
  73. if z <> 2.0 then
  74. Halt(1);
  75. asm
  76. fldl y
  77. fldl x
  78. fadd
  79. fstpl z
  80. end;
  81. Writeln('ATT result of 4+2=',z:0:2);
  82. if z <> 6.0 then
  83. Halt(1);
  84. {$asmmode intel}
  85. asm
  86. fld x
  87. fld y
  88. fdivp st(1),st
  89. fstp z
  90. end;
  91. Writeln('Intel result of 4/2=',z:0:2);
  92. if z <> 2.0 then
  93. Halt(1);
  94. asm
  95. fld y
  96. fld x
  97. fdiv st,st(1)
  98. fstp z
  99. fstp st
  100. end;
  101. Writeln('Intel result of 4/2=',z:0:2);
  102. if z <> 2.0 then
  103. Halt(1);
  104. asm
  105. fld y
  106. fld x
  107. fadd
  108. fstp z
  109. end;
  110. Writeln('Intel result of 4+2=',z:0:2);
  111. if z <> 6.0 then
  112. Halt(1);
  113. Writeln('All tests completed successfully!');
  114. end.