tfpu3.pp 1.8 KB

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