2003-12-26 Guilhem Lavaux <guilhem@kaffe.org>
[official-gcc.git] / gcc / config / ns32k / NOTES
blob32e9704d95f7d7048febad52223ebd36f1e6a742
1 Copyright (C) 2002
2 Free Software Foundation, Inc.
4                          Implementation Notes
5                          ====================
7 IEEE floating point comparisons
9 Ian Dall <ian@beware.dropbear.id.au>
10 ------------------------------------
12 The ns32x81 fpu handles most operands in hardware, but traps on NaN,
13 Inf and Denormalized numbers. The correct behavior can be handled by
14 the trap handler. This is mostly transparent to the compiler, but in
15 the case of floating point comparisons, the trap handler and the
16 compiler must co-operate.
18 Comparing a Nan with anything (including another Nan) is an unordered
19 comparison and a NE test should be true and any other test should be
20 false. There is nothing the trap handler can do to the condition codes
21 to make, for example ble and bgt (the machine instructions, not the
22 gcc insn's) both fail.
24 The L flag (normally used for unsigned comparisons) is cleared by a floating
25 point compare. So, it is possible for the trap handler to communicate that
26 it has seen a NaN by setting this flag.
28 This can get confusing so the following documents the reasoning. There
29 are only 3 flags of significance, N, Z and L. In what follows AB is
30 the conjunction of A and B ("and") A+B is the disjunction of A and B
31 ("or"), upper case represents true and lower case represents false. So
32 "Zl" is "Z AND (NOT L)".
34 Also, we can require that the trap handler clears N and Z, whenever it
35 sets L. This means that in many cases, we do not need to test if L is
36 set or clear. The operations we require are:
38         Operator        Expression      Check L
39         GT              Nl              No
40         LT              znl             Yes
41         GE              (Z+N)l          No
42         LE              nl              Yes
43         EQ              Zl              No
44         NE              z+L             No
47 For example, the emitted code for the case of LT is
49           bhi 0f
50           blt %0
51         0:
53 which is, in effect, "branch if ordered and less than."
55 We also need insns for the reverse branches. These have the PC and
56 the label ref operands reversed. Thus the reverse bgt has a pattern:
58  (set (pc)
59         (if_then_else (gt (cc0)
60                           (const_int 0))
61                       (pc)
62                       (label_ref (match_operand 0 "" ""))))
64 This is identical to a normal branch with the test complimented:
66  (set (pc)
67         (if_then_else (not (gt (cc0)
68                           (const_int 0)))
69                       (label_ref (match_operand 0 "" "")
70                       (pc))))
72 Thus we need a family of (NOT cond) tests. For integers this is easy,
73 a reverse blt becomes bge. However, the possibility of unordered
74 comparison complicates the floating point case. So, we need to
75 compliment the above expressions, using deMorgan's theorem, for the reverse
76 branch:
78         Operator        Expression      Check L
79         RGT             n+L             Yes
80         RLT             Z+N+L           Yes
81         RGE             zn+L            Yes
82         RLE             N+L             Yes
83         REQ             z+L             No
84         RNE             Zl              No
86 For example the emitted code for the case of RLT is
88    bge %0
89    bhi %0
91 which is, in effect "branch if not less than and not unordered."
93 These extra comparisons are safe if the trap handler doesn't set the
94 L flag, since in that case the additional "bhi" instructions are never
95 taken. Also, these extra branch instructions are controlled by the
96 "-mieee-compare" option.