1117395Skan/* Definitions of target machine for GNU compiler, for IBM S/390
2169689Skan   Copyright (C) 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
3117395Skan   Contributed by Hartmut Penner (hpenner@de.ibm.com) and
4117395Skan                  Ulrich Weigand (uweigand@de.ibm.com).
5117395Skan
6132718SkanThis file is part of GCC.
7117395Skan
8132718SkanGCC is free software; you can redistribute it and/or modify it under
9132718Skanthe terms of the GNU General Public License as published by the Free
10132718SkanSoftware Foundation; either version 2, or (at your option) any later
11132718Skanversion.
12117395Skan
13132718SkanGCC is distributed in the hope that it will be useful, but WITHOUT ANY
14132718SkanWARRANTY; without even the implied warranty of MERCHANTABILITY or
15132718SkanFITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
16132718Skanfor more details.
17132718Skan
18117395SkanYou should have received a copy of the GNU General Public License
19132718Skanalong with GCC; see the file COPYING.  If not, write to the Free
20169689SkanSoftware Foundation, 51 Franklin Street, Fifth Floor, Boston, MA
21169689Skan02110-1301, USA.  */
22117395Skan
23132718Skan/* 256-bit integer mode is needed for STACK_SAVEAREA_MODE.  */
24132718SkanINT_MODE (OI, 32);
25132718Skan
26169689Skan/* Define TFmode to work around reload problem PR 20927.  */
27169689SkanFLOAT_MODE (TF, 16, ieee_quad_format);
28169689Skan
29117395Skan/* Add any extra modes needed to represent the condition code.  */
30117395Skan
31169689Skan/*
32169689Skan
33169689SkanCondition Codes
34169689Skan
35169689SkanCheck for zero
36169689Skan
37169689SkanCCZ:  EQ          NE           NE          NE
38169689SkanCCZ1: EQ          NE                                  (CS)
39169689Skan
40169689SkanUnsigned compares
41169689Skan
42169689SkanCCU:  EQ          LTU          GTU         NE         (CLG/R, CL/R/Y, CLM/Y, CLI/Y)
43169689SkanCCUR: EQ          GTU          LTU         NE         (CLGF/R)
44169689Skan
45169689SkanSigned compares
46169689Skan
47169689SkanCCS:  EQ          LT           GT          UNORDERED  (LTGFR, LTGR, LTR, ICM/Y,
48169689Skan                                                       LTDBR, LTDR, LTEBR, LTER,
49169689Skan                                                       CG/R, C/R/Y, CGHI, CHI, 
50169689Skan                                                       CDB/R, CD/R, CEB/R, CE/R, 
51169689Skan                                                       ADB/R, AEB/R, SDB/R, SEB/R,
52169689Skan                                                       SRAG, SRA, SRDA)
53169689SkanCCSR: EQ          GT           LT          UNORDERED  (CGF/R, CH/Y)
54169689Skan
55169689SkanCondition codes resulting from add with overflow
56169689Skan
57169689SkanCCA:  EQ          LT           GT          Overflow
58169689SkanCCAP: EQ          LT           GT          LT         (AGHI, AHI)
59169689SkanCCAN: EQ          LT           GT          GT         (AGHI, AHI)
60169689Skan
61169689SkanCondition codes of unsigned adds and subs
62169689Skan
63169689SkanCCL:  EQ          NE           EQ          NE         (ALGF/R, ALG/R, AL/R/Y,
64169689Skan                                                       ALCG/R, ALC/R, 
65169689Skan                                                       SLGF/R, SLG/R, SL/R/Y,
66169689Skan                                                       SLBG/R, SLB/R)
67169689SkanCCL1: GEU         GEU          LTU         LTU        (ALG/R, AL/R/Y)
68169689SkanCCL2: GTU         GTU          LEU         LEU        (SLG/R, SL/R/Y)
69169689SkanCCL3: EQ          LTU          EQ          GTU        (SLG/R, SL/R/Y)
70169689Skan
71169689SkanTest under mask checks
72169689Skan
73169689SkanCCT:  EQ          NE           NE          NE         (ICM/Y, TML, CG/R, CGHI, 
74169689Skan                                                       C/R/Y, CHI, NG/R, N/R/Y,
75169689Skan                                                       OG/R, O/R/Y, XG/R, X/R/Y)
76169689SkanCCT1: NE          EQ           NE          NE         (TMH, TML)
77169689SkanCCT2: NE          NE           EQ          NE         (TMH, TML)
78169689SkanCCT3: NE          NE           NE          EQ         (TMH, TML)
79169689Skan
80169689SkanCCA and CCT modes are request only modes. These modes are never returned by 
81169689Skans390_select_cc_mode. They are only intended to match other modes.
82169689Skan
83169689SkanRequested mode            -> Destination CC register mode
84169689Skan
85169689SkanCCS, CCU, CCT, CCSR, CCUR -> CCZ
86169689SkanCCA                       -> CCAP, CCAN
87169689Skan
88169689Skan
89169689Skan*** Comments ***
90169689Skan
91169689SkanCCAP, CCAN
92169689Skan
93169689SkanThe CC obtained from add instruction usually can't be used for comparisons 
94169689Skanbecause its coupling with overflow flag. In case of an overflow the
95169689Skanless than/greater than data are lost. Nevertheless a comparison can be done
96169689Skanwhenever immediate values are involved because they are known at compile time.
97169689SkanIf you know whether the used constant is positive or negative you can predict 
98169689Skanthe sign of the result even in case of an overflow.
99169689Skan
100169689Skan
101169689SkanCCT, CCT1, CCT2, CCT3
102169689Skan
103169689SkanIf bits of an integer masked with an AND instruction are checked, the test under
104169689Skanmask instructions turn out to be very handy for a set of special cases.
105169689SkanThe simple cases are checks whether all masked bits are zero or ones:
106169689Skan
107169689Skan  int a; 
108169689Skan  if ((a & (16 + 128)) == 0)          -> CCT/CCZ
109169689Skan  if ((a & (16 + 128)) == 16 + 128)   -> CCT3
110169689Skan
111169689SkanUsing two extra modes makes it possible to do complete checks on two bits of an
112169689Skaninteger (This is possible on register operands only. TM does not provide the
113169689Skaninformation necessary for CCT1 and CCT2 modes.):
114169689Skan
115169689Skan  int a;
116169689Skan  if ((a & (16 + 128)) == 16)         -> CCT1
117169689Skan  if ((a & (16 + 128)) == 128)        -> CCT2
118169689Skan
119169689Skan
120169689SkanCCSR, CCUR
121169689Skan
122169689SkanThere are several instructions comparing 32 bit with 64 bit unsigned/signed
123169689Skanvalues. Such instructions can be considered to have a builtin zero/sign_extend.
124169689SkanThe problem is that in the RTL (to be canonical) the zero/sign extended operand 
125169689Skanhas to be the first one but the machine instructions like it the other way 
126169689Skanaround. The following both modes can be considered as CCS and CCU modes with 
127169689Skanexchanged operands.
128169689Skan
129169689Skan
130169689SkanCCL1, CCL2
131169689Skan
132169689SkanThese modes represent the result of overflow checks. 
133169689Skan
134169689Skanif (a + b < a) -> CCL1 state of the carry bit   (CC2 | CC3)
135169689Skanif (a - b > a) -> CCL2 state of the borrow bit  (CC0 | CC1)
136169689Skan
137169689SkanThey are used when multi word numbers are computed dealing one SImode part after
138169689Skananother or whenever manual overflow checks like the examples above are
139169689Skancompiled.
140169689Skan
141169689Skan
142169689SkanCCL3
143169689Skan
144169689SkanA logical subtract instruction sets the borrow bit in case of an overflow.
145169689SkanThe resulting condition code of those instructions is represented by the
146169689SkanCCL3 mode. Together with the CCU mode this mode is used for jumpless 
147169689Skanimplementations of several if-constructs - see s390_expand_addcc for more
148169689Skandetails.
149169689Skan
150169689SkanCCZ1
151169689Skan
152169689SkanThe compare and swap instructions sets the condition code to 0/1 if the
153169689Skanoperands were equal/unequal. The CCZ1 mode ensures the result can be
154169689Skaneffectively placed into a register.
155169689Skan
156169689Skan*/   
157169689Skan
158169689Skan
159132718SkanCC_MODE (CCZ);
160169689SkanCC_MODE (CCZ1);
161132718SkanCC_MODE (CCA);
162132718SkanCC_MODE (CCAP);
163132718SkanCC_MODE (CCAN);
164132718SkanCC_MODE (CCL);
165132718SkanCC_MODE (CCL1);
166132718SkanCC_MODE (CCL2);
167169689SkanCC_MODE (CCL3);
168132718SkanCC_MODE (CCU);
169132718SkanCC_MODE (CCUR);
170132718SkanCC_MODE (CCS);
171132718SkanCC_MODE (CCSR);
172132718SkanCC_MODE (CCT);
173132718SkanCC_MODE (CCT1);
174132718SkanCC_MODE (CCT2);
175132718SkanCC_MODE (CCT3);
176