aboutsummaryrefslogtreecommitdiff
path: root/gcc/config/rs6000/dfp.md
blob: c84059557c7b4f9fabc66ccacb383e0f48af041c (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
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
;; Decimal Floating Point (DFP) patterns.
;; Copyright (C) 2007-2022 Free Software Foundation, Inc.
;; Contributed by Ben Elliston (bje@au.ibm.com) and Peter Bergner
;; (bergner@vnet.ibm.com).

;; This file is part of GCC.

;; GCC is free software; you can redistribute it and/or modify it
;; under the terms of the GNU General Public License as published
;; by the Free Software Foundation; either version 3, or (at your
;; option) any later version.

;; GCC is distributed in the hope that it will be useful, but WITHOUT
;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
;; or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public
;; License for more details.

;; You should have received a copy of the GNU General Public License
;; along with GCC; see the file COPYING3.  If not see
;; <http://www.gnu.org/licenses/>.

;;
;; UNSPEC usage
;;

(define_c_enum "unspec"
  [UNSPEC_MOVSD_LOAD
   UNSPEC_MOVSD_STORE
  ])

; Either of the two decimal modes.
(define_mode_iterator DDTD [DD TD])

(define_mode_attr q [(DD "") (TD "q")])


(define_insn "movsd_store"
  [(set (match_operand:DD 0 "nonimmediate_operand" "=m")
	(unspec:DD [(match_operand:SD 1 "input_operand" "d")]
		   UNSPEC_MOVSD_STORE))]
  "(gpc_reg_operand (operands[0], DDmode)
   || gpc_reg_operand (operands[1], SDmode))
   && TARGET_HARD_FLOAT"
  "stfd%U0%X0 %1,%0"
  [(set_attr "type" "fpstore")])

(define_insn "movsd_load"
  [(set (match_operand:SD 0 "nonimmediate_operand" "=f")
	(unspec:SD [(match_operand:DD 1 "input_operand" "m")]
		   UNSPEC_MOVSD_LOAD))]
  "(gpc_reg_operand (operands[0], SDmode)
   || gpc_reg_operand (operands[1], DDmode))
   && TARGET_HARD_FLOAT"
  "lfd%U1%X1 %0,%1"
  [(set_attr "type" "fpload")])

;; Hardware support for decimal floating point operations.

(define_insn "extendsddd2"
  [(set (match_operand:DD 0 "gpc_reg_operand" "=d")
	(float_extend:DD (match_operand:SD 1 "gpc_reg_operand" "f")))]
  "TARGET_DFP"
  "dctdp %0,%1"
  [(set_attr "type" "dfp")])

(define_expand "extendsdtd2"
  [(set (match_operand:TD 0 "gpc_reg_operand" "=d")
	(float_extend:TD (match_operand:SD 1 "gpc_reg_operand" "d")))]
  "TARGET_DFP"
{
  rtx tmp = gen_reg_rtx (DDmode);
  emit_insn (gen_extendsddd2 (tmp, operands[1]));
  emit_insn (gen_extendddtd2 (operands[0], tmp));
  DONE;
})

(define_insn "truncddsd2"
  [(set (match_operand:SD 0 "gpc_reg_operand" "=f")
	(float_truncate:SD (match_operand:DD 1 "gpc_reg_operand" "d")))]
  "TARGET_DFP"
  "drsp %0,%1"
  [(set_attr "type" "dfp")])

(define_insn "negdd2"
  [(set (match_operand:DD 0 "gpc_reg_operand" "=d")
	(neg:DD (match_operand:DD 1 "gpc_reg_operand" "d")))]
  "TARGET_HARD_FLOAT"
  "fneg %0,%1"
  [(set_attr "type" "fpsimple")])

(define_insn "absdd2"
  [(set (match_operand:DD 0 "gpc_reg_operand" "=d")
	(abs:DD (match_operand:DD 1 "gpc_reg_operand" "d")))]
  "TARGET_HARD_FLOAT"
  "fabs %0,%1"
  [(set_attr "type" "fpsimple")])

(define_insn "*nabsdd2_fpr"
  [(set (match_operand:DD 0 "gpc_reg_operand" "=d")
	(neg:DD (abs:DD (match_operand:DD 1 "gpc_reg_operand" "d"))))]
  "TARGET_HARD_FLOAT"
  "fnabs %0,%1"
  [(set_attr "type" "fpsimple")])

(define_insn "negtd2"
  [(set (match_operand:TD 0 "gpc_reg_operand" "=d,d")
	(neg:TD (match_operand:TD 1 "gpc_reg_operand" "0,d")))]
  "TARGET_HARD_FLOAT"
  "@
   fneg %0,%1
   fneg %0,%1\;fmr %L0,%L1"
  [(set_attr "type" "fpsimple")
   (set_attr "length" "4,8")])

(define_insn "abstd2"
  [(set (match_operand:TD 0 "gpc_reg_operand" "=d,d")
	(abs:TD (match_operand:TD 1 "gpc_reg_operand" "0,d")))]
  "TARGET_HARD_FLOAT"
  "@
   fabs %0,%1
   fabs %0,%1\;fmr %L0,%L1"
  [(set_attr "type" "fpsimple")
   (set_attr "length" "4,8")])

(define_insn "*nabstd2_fpr"
  [(set (match_operand:TD 0 "gpc_reg_operand" "=d,d")
	(neg:TD (abs:TD (match_operand:TD 1 "gpc_reg_operand" "0,d"))))]
  "TARGET_HARD_FLOAT"
  "@
   fnabs %0,%1
   fnabs %0,%1\;fmr %L0,%L1"
  [(set_attr "type" "fpsimple")
   (set_attr "length" "4,8")])

;; Hardware support for decimal floating point operations.

(define_insn "extendddtd2"
  [(set (match_operand:TD 0 "gpc_reg_operand" "=d")
	(float_extend:TD (match_operand:DD 1 "gpc_reg_operand" "d")))]
  "TARGET_DFP"
  "dctqpq %0,%1"
  [(set_attr "type" "dfp")
   (set_attr "size" "128")])

;; The result of drdpq is an even/odd register pair with the converted
;; value in the even register and zero in the odd register.
;; FIXME: Avoid the register move by using a reload constraint to ensure
;; that the result is the first of the pair receiving the result of drdpq.

(define_insn "trunctddd2"
  [(set (match_operand:DD 0 "gpc_reg_operand" "=d")
	(float_truncate:DD (match_operand:TD 1 "gpc_reg_operand" "d")))
   (clobber (match_scratch:TD 2 "=d"))]
  "TARGET_DFP"
  "drdpq %2,%1\;fmr %0,%2"
  [(set_attr "type" "dfp")
   (set_attr "size" "128")
   (set_attr "length" "8")])

(define_insn "trunctdsd2"
  [(set (match_operand:SD 0 "gpc_reg_operand" "=d,d")
	(float_truncate:SD (match_operand:TD 1 "gpc_reg_operand" "d,d")))
   (clobber (match_scratch:TD 2 "=&d,&d"))
   (clobber (match_scratch:DF 3 "=&d,&d"))]
  "TARGET_DFP"
  "@
   mffscdrni %3,7\;drdpq %2,%1\;mffscdrn %3,%3\;drsp %0,%2
   mffs %3\;mtfsfi 7,7,1\;drdpq %2,%1\;mtfsf 0xff,%3,1,0\;drsp %0,%2"
  [(set_attr "type" "dfp")
   (set_attr "isa" "p9,*")
   (set_attr "length" "16,20")])

(define_insn "add<mode>3"
  [(set (match_operand:DDTD 0 "gpc_reg_operand" "=d")
	(plus:DDTD (match_operand:DDTD 1 "gpc_reg_operand" "%d")
		   (match_operand:DDTD 2 "gpc_reg_operand" "d")))]
  "TARGET_DFP"
  "dadd<q> %0,%1,%2"
  [(set_attr "type" "dfp")])

(define_insn "sub<mode>3"
  [(set (match_operand:DDTD 0 "gpc_reg_operand" "=d")
	(minus:DDTD (match_operand:DDTD 1 "gpc_reg_operand" "d")
		    (match_operand:DDTD 2 "gpc_reg_operand" "d")))]
  "TARGET_DFP"
  "dsub<q> %0,%1,%2"
  [(set_attr "type" "dfp")])

(define_insn "mul<mode>3"
  [(set (match_operand:DDTD 0 "gpc_reg_operand" "=d")
	(mult:DDTD (match_operand:DDTD 1 "gpc_reg_operand" "%d")
		   (match_operand:DDTD 2 "gpc_reg_operand" "d")))]
  "TARGET_DFP"
  "dmul<q> %0,%1,%2"
  [(set_attr "type" "dfp")])

(define_insn "div<mode>3"
  [(set (match_operand:DDTD 0 "gpc_reg_operand" "=d")
	(div:DDTD (match_operand:DDTD 1 "gpc_reg_operand" "d")
		  (match_operand:DDTD 2 "gpc_reg_operand" "d")))]
  "TARGET_DFP"
  "ddiv<q> %0,%1,%2"
  [(set_attr "type" "dfp")])

(define_insn "*cmp<mode>_internal1"
  [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
	(compare:CCFP (match_operand:DDTD 1 "gpc_reg_operand" "d")
		      (match_operand:DDTD 2 "gpc_reg_operand" "d")))]
  "TARGET_DFP"
  "dcmpu<q> %0,%1,%2"
  [(set_attr "type" "dfp")
   (set_attr "size" "<bits>")])

(define_insn "floatdidd2"
  [(set (match_operand:DD 0 "gpc_reg_operand" "=d")
	(float:DD (match_operand:DI 1 "gpc_reg_operand" "d")))]
  "TARGET_DFP && TARGET_POPCNTD"
  "dcffix %0,%1"
  [(set_attr "type" "dfp")])

(define_insn "floatditd2"
  [(set (match_operand:TD 0 "gpc_reg_operand" "=d")
	(float:TD (match_operand:DI 1 "gpc_reg_operand" "d")))]
  "TARGET_DFP"
  "dcffixq %0,%1"
  [(set_attr "type" "dfp")
   (set_attr "size" "128")])

(define_insn "floattitd2"
  [(set (match_operand:TD 0 "gpc_reg_operand" "=d")
	(float:TD (match_operand:TI 1 "gpc_reg_operand" "v")))]
  "TARGET_POWER10"
  "dcffixqq %0,%1"
  [(set_attr "type" "dfp")])

;; Convert a decimal64/128 to a decimal64/128 whose value is an integer.
;; This is the first stage of converting it to an integer type.

(define_insn "ftrunc<mode>2"
  [(set (match_operand:DDTD 0 "gpc_reg_operand" "=d")
	(fix:DDTD (match_operand:DDTD 1 "gpc_reg_operand" "d")))]
  "TARGET_DFP"
  "drintn<q>. 0,%0,%1,1"
  [(set_attr "type" "dfp")
   (set_attr "size" "<bits>")])

;; Convert a decimal64/128 whose value is an integer to an actual integer.
;; This is the second stage of converting decimal float to integer type.

(define_insn "fix<mode>di2"
  [(set (match_operand:DI 0 "gpc_reg_operand" "=d")
	(fix:DI (match_operand:DDTD 1 "gpc_reg_operand" "d")))]
  "TARGET_DFP"
  "dctfix<q> %0,%1"
  [(set_attr "type" "dfp")
   (set_attr "size" "<bits>")])

(define_insn "fixtdti2"
  [(set (match_operand:TI 0 "gpc_reg_operand" "=v")
	(fix:TI (match_operand:TD 1 "gpc_reg_operand" "d")))]
  "TARGET_POWER10"
  "dctfixqq %0,%1"
  [(set_attr "type" "dfp")])

;; Decimal builtin support

(define_c_enum "unspec"
  [UNSPEC_DDEDPD
   UNSPEC_DENBCD
   UNSPEC_DXEX
   UNSPEC_DIEX
   UNSPEC_DSCLI
   UNSPEC_DTSTSFI
   UNSPEC_DSCRI])

(define_code_iterator DFP_TEST [eq lt gt unordered])

(define_insn "dfp_ddedpd_<mode>"
  [(set (match_operand:DDTD 0 "gpc_reg_operand" "=d")
	(unspec:DDTD [(match_operand:QI 1 "const_0_to_3_operand" "i")
		      (match_operand:DDTD 2 "gpc_reg_operand" "d")]
		     UNSPEC_DDEDPD))]
  "TARGET_DFP"
  "ddedpd<q> %1,%0,%2"
  [(set_attr "type" "dfp")
   (set_attr "size" "<bits>")])

(define_insn "dfp_denbcd_<mode>"
  [(set (match_operand:DDTD 0 "gpc_reg_operand" "=d")
	(unspec:DDTD [(match_operand:QI 1 "const_0_to_1_operand" "i")
		      (match_operand:DDTD 2 "gpc_reg_operand" "d")]
		     UNSPEC_DENBCD))]
  "TARGET_DFP"
  "denbcd<q> %1,%0,%2"
  [(set_attr "type" "dfp")
   (set_attr "size" "<bits>")])

(define_insn "dfp_denbcd_v16qi_inst"
  [(set (match_operand:TD 0 "gpc_reg_operand" "=d")
	(unspec:TD [(match_operand:QI 1 "const_0_to_1_operand" "i")
		    (match_operand:V16QI 2 "register_operand" "d")]
		   UNSPEC_DENBCD))]
  "TARGET_DFP"
  "denbcdq %1,%0,%2"
  [(set_attr "type" "dfp")])

(define_expand "dfp_denbcd_v16qi"
  [(set (match_operand:TD 0 "gpc_reg_operand" "=d")
	(unspec:TD [(match_operand:V16QI 1 "register_operand" "v")]
		   UNSPEC_DENBCD))]
  "TARGET_DFP"
 {
   // Move vs128 upper 64-bits and lower 64-bits to fp register pair
   convert_move (operands[0], operands[1], true);
   emit_insn (gen_dfp_denbcd_v16qi_inst (operands[0], GEN_INT(1),
					 operands[0]));
   DONE;
 })

(define_insn "dfp_dxex_<mode>"
  [(set (match_operand:DI 0 "gpc_reg_operand" "=d")
	(unspec:DI [(match_operand:DDTD 1 "gpc_reg_operand" "d")]
		   UNSPEC_DXEX))]
  "TARGET_DFP"
  "dxex<q> %0,%1"
  [(set_attr "type" "dfp")
   (set_attr "size" "<bits>")])

(define_insn "dfp_diex_<mode>"
  [(set (match_operand:DDTD 0 "gpc_reg_operand" "=d")
	(unspec:DDTD [(match_operand:DI 1 "gpc_reg_operand" "d")
		      (match_operand:DDTD 2 "gpc_reg_operand" "d")]
		     UNSPEC_DXEX))]
  "TARGET_DFP"
  "diex<q> %0,%1,%2"
  [(set_attr "type" "dfp")
   (set_attr "size" "<bits>")])

(define_expand "dfptstsfi_<code>_<mode>"
  [(set (match_dup 3)
	(compare:CCFP (unspec:DDTD [(match_operand:SI 1 "const_int_operand")
				    (match_operand:DDTD 2 "gpc_reg_operand")]
				   UNSPEC_DTSTSFI)
		      (const_int 0)))
   (set (match_operand:SI 0 "register_operand")
	(DFP_TEST:SI (match_dup 3)
		     (const_int 0)))
  ]
  "TARGET_P9_MISC"
{
  if (<CODE> == UNORDERED && !HONOR_NANS (<MODE>mode))
    {
      emit_move_insn (operands[0], const0_rtx);
      DONE;
    }

  operands[3] = gen_reg_rtx (CCFPmode);
})

(define_insn "*dfp_sgnfcnc_<mode>"
  [(set (match_operand:CCFP 0 "" "=y")
	(compare:CCFP
	 (unspec:DDTD [(match_operand:SI 1 "const_int_operand" "n")
		       (match_operand:DDTD 2 "gpc_reg_operand" "d")]
		      UNSPEC_DTSTSFI)
	 (match_operand:SI 3 "zero_constant" "j")))]
  "TARGET_P9_MISC"
{
  /* If immediate operand is greater than 63, it will behave as if
     the value had been 63.  The code generator does not support
     immediate operand values greater than 63.  */
  if (!(IN_RANGE (INTVAL (operands[1]), 0, 63)))
    operands[1] = GEN_INT (63);
  return "dtstsfi<q> %0,%1,%2";
}
  [(set_attr "type" "fp")
   (set_attr "size" "<bits>")])

(define_insn "dfp_dscli_<mode>"
  [(set (match_operand:DDTD 0 "gpc_reg_operand" "=d")
	(unspec:DDTD [(match_operand:DDTD 1 "gpc_reg_operand" "d")
		      (match_operand:QI 2 "immediate_operand" "i")]
		     UNSPEC_DSCLI))]
  "TARGET_DFP"
  "dscli<q> %0,%1,%2"
  [(set_attr "type" "dfp")
   (set_attr "size" "<bits>")])

(define_insn "dfp_dscri_<mode>"
  [(set (match_operand:DDTD 0 "gpc_reg_operand" "=d")
	(unspec:DDTD [(match_operand:DDTD 1 "gpc_reg_operand" "d")
		      (match_operand:QI 2 "immediate_operand" "i")]
		     UNSPEC_DSCRI))]
  "TARGET_DFP"
  "dscri<q> %0,%1,%2"
  [(set_attr "type" "dfp")
   (set_attr "size" "<bits>")])