tfpu4.pp 1.8 KB

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