summaryrefslogtreecommitdiff
path: root/fpcsrc/tests/tbs/tb0267.pp
blob: 165d273432bddd94a3c3f03faa55df3162b7579c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
{ %CPU=i386 }
{ %OPT=-Cg- }
{ Old file: tbs0309.pp }
{ problem with ATT assembler written by bin writer     OK 0.99.14 (PFV) }

{ This code was first written by Florian
  to test the GDB output for FPU
  he thought first that FPU output was wrong
  but in fact it is a bug in FPC :( }
program bug0309;

var
   a,b : double;
   _as,bs : single;
   al,bl : extended;
   aw,bw : integer;
   ai,bi : longint;
   ac : comp;
begin
{$ifdef CPU86}
{$asmmode att}
   asm
      fninit;
   end;
   a:=1;
   b:=2;
   asm
      movl  $1,%eax
      fldl  a
      fldl  b
      faddp %st,%st(1)
      fstpl a
   end;
   { the above generates wrong code in binary writer
     fldl is replaced by flds !!
     if using -alt option to force assembler output
     all works correctly PM }
   writeln('a = ',a,' should be 3');
   if a<>3.0 then
     Halt(1);
   a:=1.0;
   a:=a+b;
   writeln('a = ',a,' should be 3');
   _as:=0;
   al:=0;
   asm
     fldl a
     fsts _as
     fstpt al
   end;
   if (_as<>3.0) or (al<>3.0) then
     Halt(1);
   ai:=5;
   bi:=5;
   asm
     fildl ai
     fstpl a
   end;
   if a<>5.0 then
     Halt(1);

   ac:=5;
   asm
     fildl ai
     fstpl a
   end;
   if a<>5.0 then
     Halt(1);
   aw:=-4;
   bw:=45;
   asm
     filds aw
     fstpl a
   end;
   if a<>-4.0 then
     Halt(1);
   ac:=345;
   asm
     fildq ac
     fstpl a
   end;
   if a<>345.0 then
     Halt(1);

{$endif CPU86}
end.