1 ;; Decimal Floating Point (DFP) patterns.
2 ;; Copyright (C) 2007, 2008, 2010
3 ;; Free Software Foundation, Inc.
4 ;; Contributed by Ben Elliston (bje@au.ibm.com) and Peter Bergner
5 ;; (bergner@vnet.ibm.com).
7 ;; This file is part of GCC.
9 ;; GCC is free software; you can redistribute it and/or modify it
10 ;; under the terms of the GNU General Public License as published
11 ;; by the Free Software Foundation; either version 3, or (at your
12 ;; option) any later version.
14 ;; GCC is distributed in the hope that it will be useful, but WITHOUT
15 ;; ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16 ;; or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
17 ;; License for more details.
19 ;; You should have received a copy of the GNU General Public License
20 ;; along with GCC; see the file COPYING3. If not see
21 ;; <http://www.gnu.org/licenses/>.
28 [(UNSPEC_MOVSD_LOAD 400)
29 (UNSPEC_MOVSD_STORE 401)
33 (define_expand "movsd"
34 [(set (match_operand:SD 0 "nonimmediate_operand" "")
35 (match_operand:SD 1 "any_operand" ""))]
36 "TARGET_HARD_FLOAT && TARGET_FPRS"
37 "{ rs6000_emit_move (operands[0], operands[1], SDmode); DONE; }")
40 [(set (match_operand:SD 0 "gpc_reg_operand" "")
41 (match_operand:SD 1 "const_double_operand" ""))]
43 && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
44 || (GET_CODE (operands[0]) == SUBREG
45 && GET_CODE (SUBREG_REG (operands[0])) == REG
46 && REGNO (SUBREG_REG (operands[0])) <= 31))"
47 [(set (match_dup 2) (match_dup 3))]
53 REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
54 REAL_VALUE_TO_TARGET_DECIMAL32 (rv, l);
56 if (! TARGET_POWERPC64)
57 operands[2] = operand_subword (operands[0], 0, 0, SDmode);
59 operands[2] = gen_lowpart (SImode, operands[0]);
61 operands[3] = gen_int_mode (l, SImode);
64 (define_insn "movsd_hardfloat"
65 [(set (match_operand:SD 0 "nonimmediate_operand" "=r,r,m,f,*c*l,*q,!r,*h,!r,!r")
66 (match_operand:SD 1 "input_operand" "r,m,r,f,r,r,h,0,G,Fn"))]
67 "(gpc_reg_operand (operands[0], SDmode)
68 || gpc_reg_operand (operands[1], SDmode))
69 && (TARGET_HARD_FLOAT && TARGET_FPRS)"
72 {l%U1%X1|lwz%U1%X1} %0,%1
73 {st%U0%X0|stw%U0%X0} %1,%0
81 [(set_attr "type" "*,load,store,fp,mtjmpr,*,mfjmpr,*,*,*")
82 (set_attr "length" "4,4,4,4,4,4,4,4,4,8")])
84 (define_insn "movsd_softfloat"
85 [(set (match_operand:SD 0 "nonimmediate_operand" "=r,cl,q,r,r,m,r,r,r,r,r,*h")
86 (match_operand:SD 1 "input_operand" "r,r,r,h,m,r,I,L,R,G,Fn,0"))]
87 "(gpc_reg_operand (operands[0], SDmode)
88 || gpc_reg_operand (operands[1], SDmode))
89 && (TARGET_SOFT_FLOAT || !TARGET_FPRS)"
95 {l%U1%X1|lwz%U1%X1} %0,%1
96 {st%U0%X0|stw%U0%X0} %1,%0
103 [(set_attr "type" "*,mtjmpr,*,mfjmpr,load,store,*,*,*,*,*,*")
104 (set_attr "length" "4,4,4,4,4,4,4,4,4,4,8,4")])
106 (define_insn "movsd_store"
107 [(set (match_operand:DD 0 "nonimmediate_operand" "=m")
108 (unspec:DD [(match_operand:SD 1 "input_operand" "d")]
109 UNSPEC_MOVSD_STORE))]
110 "(gpc_reg_operand (operands[0], DDmode)
111 || gpc_reg_operand (operands[1], SDmode))
112 && TARGET_HARD_FLOAT && TARGET_FPRS"
114 [(set_attr "type" "fpstore")
115 (set_attr "length" "4")])
117 (define_insn "movsd_load"
118 [(set (match_operand:SD 0 "nonimmediate_operand" "=f")
119 (unspec:SD [(match_operand:DD 1 "input_operand" "m")]
121 "(gpc_reg_operand (operands[0], SDmode)
122 || gpc_reg_operand (operands[1], DDmode))
123 && TARGET_HARD_FLOAT && TARGET_FPRS"
125 [(set_attr "type" "fpload")
126 (set_attr "length" "4")])
128 ;; Hardware support for decimal floating point operations.
130 (define_insn "extendsddd2"
131 [(set (match_operand:DD 0 "gpc_reg_operand" "=d")
132 (float_extend:DD (match_operand:SD 1 "gpc_reg_operand" "f")))]
135 [(set_attr "type" "fp")])
137 (define_expand "extendsdtd2"
138 [(set (match_operand:TD 0 "gpc_reg_operand" "=d")
139 (float_extend:TD (match_operand:SD 1 "gpc_reg_operand" "d")))]
142 rtx tmp = gen_reg_rtx (DDmode);
143 emit_insn (gen_extendsddd2 (tmp, operands[1]));
144 emit_insn (gen_extendddtd2 (operands[0], tmp));
148 (define_insn "truncddsd2"
149 [(set (match_operand:SD 0 "gpc_reg_operand" "=f")
150 (float_truncate:SD (match_operand:DD 1 "gpc_reg_operand" "d")))]
153 [(set_attr "type" "fp")])
155 (define_expand "negdd2"
156 [(set (match_operand:DD 0 "gpc_reg_operand" "")
157 (neg:DD (match_operand:DD 1 "gpc_reg_operand" "")))]
158 "TARGET_HARD_FLOAT && TARGET_FPRS"
161 (define_insn "*negdd2_fpr"
162 [(set (match_operand:DD 0 "gpc_reg_operand" "=d")
163 (neg:DD (match_operand:DD 1 "gpc_reg_operand" "d")))]
164 "TARGET_HARD_FLOAT && TARGET_FPRS"
166 [(set_attr "type" "fp")])
168 (define_expand "absdd2"
169 [(set (match_operand:DD 0 "gpc_reg_operand" "")
170 (abs:DD (match_operand:DD 1 "gpc_reg_operand" "")))]
171 "TARGET_HARD_FLOAT && TARGET_FPRS"
174 (define_insn "*absdd2_fpr"
175 [(set (match_operand:DD 0 "gpc_reg_operand" "=d")
176 (abs:DD (match_operand:DD 1 "gpc_reg_operand" "d")))]
177 "TARGET_HARD_FLOAT && TARGET_FPRS"
179 [(set_attr "type" "fp")])
181 (define_insn "*nabsdd2_fpr"
182 [(set (match_operand:DD 0 "gpc_reg_operand" "=d")
183 (neg:DD (abs:DD (match_operand:DD 1 "gpc_reg_operand" "d"))))]
184 "TARGET_HARD_FLOAT && TARGET_FPRS"
186 [(set_attr "type" "fp")])
188 (define_expand "movdd"
189 [(set (match_operand:DD 0 "nonimmediate_operand" "")
190 (match_operand:DD 1 "any_operand" ""))]
192 "{ rs6000_emit_move (operands[0], operands[1], DDmode); DONE; }")
195 [(set (match_operand:DD 0 "gpc_reg_operand" "")
196 (match_operand:DD 1 "const_int_operand" ""))]
197 "! TARGET_POWERPC64 && reload_completed
198 && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
199 || (GET_CODE (operands[0]) == SUBREG
200 && GET_CODE (SUBREG_REG (operands[0])) == REG
201 && REGNO (SUBREG_REG (operands[0])) <= 31))"
202 [(set (match_dup 2) (match_dup 4))
203 (set (match_dup 3) (match_dup 1))]
206 int endian = (WORDS_BIG_ENDIAN == 0);
207 HOST_WIDE_INT value = INTVAL (operands[1]);
209 operands[2] = operand_subword (operands[0], endian, 0, DDmode);
210 operands[3] = operand_subword (operands[0], 1 - endian, 0, DDmode);
211 #if HOST_BITS_PER_WIDE_INT == 32
212 operands[4] = (value & 0x80000000) ? constm1_rtx : const0_rtx;
214 operands[4] = GEN_INT (value >> 32);
215 operands[1] = GEN_INT (((value & 0xffffffff) ^ 0x80000000) - 0x80000000);
220 [(set (match_operand:DD 0 "gpc_reg_operand" "")
221 (match_operand:DD 1 "const_double_operand" ""))]
222 "! TARGET_POWERPC64 && reload_completed
223 && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
224 || (GET_CODE (operands[0]) == SUBREG
225 && GET_CODE (SUBREG_REG (operands[0])) == REG
226 && REGNO (SUBREG_REG (operands[0])) <= 31))"
227 [(set (match_dup 2) (match_dup 4))
228 (set (match_dup 3) (match_dup 5))]
231 int endian = (WORDS_BIG_ENDIAN == 0);
235 REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
236 REAL_VALUE_TO_TARGET_DECIMAL64 (rv, l);
238 operands[2] = operand_subword (operands[0], endian, 0, DDmode);
239 operands[3] = operand_subword (operands[0], 1 - endian, 0, DDmode);
240 operands[4] = gen_int_mode (l[endian], SImode);
241 operands[5] = gen_int_mode (l[1 - endian], SImode);
245 [(set (match_operand:DD 0 "gpc_reg_operand" "")
246 (match_operand:DD 1 "const_double_operand" ""))]
247 "TARGET_POWERPC64 && reload_completed
248 && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
249 || (GET_CODE (operands[0]) == SUBREG
250 && GET_CODE (SUBREG_REG (operands[0])) == REG
251 && REGNO (SUBREG_REG (operands[0])) <= 31))"
252 [(set (match_dup 2) (match_dup 3))]
255 int endian = (WORDS_BIG_ENDIAN == 0);
258 #if HOST_BITS_PER_WIDE_INT >= 64
262 REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
263 REAL_VALUE_TO_TARGET_DECIMAL64 (rv, l);
265 operands[2] = gen_lowpart (DImode, operands[0]);
266 /* HIGHPART is lower memory address when WORDS_BIG_ENDIAN. */
267 #if HOST_BITS_PER_WIDE_INT >= 64
268 val = ((HOST_WIDE_INT)(unsigned long)l[endian] << 32
269 | ((HOST_WIDE_INT)(unsigned long)l[1 - endian]));
271 operands[3] = gen_int_mode (val, DImode);
273 operands[3] = immed_double_const (l[1 - endian], l[endian], DImode);
277 ;; Don't have reload use general registers to load a constant. First,
278 ;; it might not work if the output operand is the equivalent of
279 ;; a non-offsettable memref, but also it is less efficient than loading
280 ;; the constant into an FP register, since it will probably be used there.
281 ;; The "??" is a kludge until we can figure out a more reasonable way
282 ;; of handling these non-offsettable values.
283 (define_insn "*movdd_hardfloat32"
284 [(set (match_operand:DD 0 "nonimmediate_operand" "=!r,??r,m,d,d,m,!r,!r,!r")
285 (match_operand:DD 1 "input_operand" "r,m,r,d,m,d,G,H,F"))]
286 "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS
287 && (gpc_reg_operand (operands[0], DDmode)
288 || gpc_reg_operand (operands[1], DDmode))"
291 switch (which_alternative)
300 return \"fmr %0,%1\";
302 return \"lfd%U1%X1 %0,%1\";
304 return \"stfd%U0%X0 %1,%0\";
311 [(set_attr "type" "two,load,store,fp,fpload,fpstore,*,*,*")
312 (set_attr "length" "8,16,16,4,4,4,8,12,16")])
314 (define_insn "*movdd_softfloat32"
315 [(set (match_operand:DD 0 "nonimmediate_operand" "=r,r,m,r,r,r")
316 (match_operand:DD 1 "input_operand" "r,m,r,G,H,F"))]
317 "! TARGET_POWERPC64 && (TARGET_SOFT_FLOAT || !TARGET_FPRS)
318 && (gpc_reg_operand (operands[0], DDmode)
319 || gpc_reg_operand (operands[1], DDmode))"
321 [(set_attr "type" "two,load,store,*,*,*")
322 (set_attr "length" "8,8,8,8,12,16")])
324 ; ld/std require word-aligned displacements -> 'Y' constraint.
325 ; List Y->r and r->Y before r->r for reload.
326 (define_insn "*movdd_hardfloat64_mfpgpr"
327 [(set (match_operand:DD 0 "nonimmediate_operand" "=Y,r,!r,d,d,m,*c*l,!r,*h,!r,!r,!r,r,d")
328 (match_operand:DD 1 "input_operand" "r,Y,r,d,m,d,r,h,0,G,H,F,d,r"))]
329 "TARGET_POWERPC64 && TARGET_MFPGPR && TARGET_HARD_FLOAT && TARGET_FPRS
330 && (gpc_reg_operand (operands[0], DDmode)
331 || gpc_reg_operand (operands[1], DDmode))"
347 [(set_attr "type" "store,load,*,fp,fpload,fpstore,mtjmpr,mfjmpr,*,*,*,*,mftgpr,mffgpr")
348 (set_attr "length" "4,4,4,4,4,4,4,4,4,8,12,16,4,4")])
350 ; ld/std require word-aligned displacements -> 'Y' constraint.
351 ; List Y->r and r->Y before r->r for reload.
352 (define_insn "*movdd_hardfloat64"
353 [(set (match_operand:DD 0 "nonimmediate_operand" "=Y,r,!r,d,d,m,*c*l,!r,*h,!r,!r,!r")
354 (match_operand:DD 1 "input_operand" "r,Y,r,d,m,d,r,h,0,G,H,F"))]
355 "TARGET_POWERPC64 && !TARGET_MFPGPR && TARGET_HARD_FLOAT && TARGET_FPRS
356 && (gpc_reg_operand (operands[0], DDmode)
357 || gpc_reg_operand (operands[1], DDmode))"
371 [(set_attr "type" "store,load,*,fp,fpload,fpstore,mtjmpr,mfjmpr,*,*,*,*")
372 (set_attr "length" "4,4,4,4,4,4,4,4,4,8,12,16")])
374 (define_insn "*movdd_softfloat64"
375 [(set (match_operand:DD 0 "nonimmediate_operand" "=r,Y,r,cl,r,r,r,r,*h")
376 (match_operand:DD 1 "input_operand" "Y,r,r,r,h,G,H,F,0"))]
377 "TARGET_POWERPC64 && (TARGET_SOFT_FLOAT || !TARGET_FPRS)
378 && (gpc_reg_operand (operands[0], DDmode)
379 || gpc_reg_operand (operands[1], DDmode))"
390 [(set_attr "type" "load,store,*,mtjmpr,mfjmpr,*,*,*,*")
391 (set_attr "length" "4,4,4,4,4,8,12,16,4")])
393 (define_expand "negtd2"
394 [(set (match_operand:TD 0 "gpc_reg_operand" "")
395 (neg:TD (match_operand:TD 1 "gpc_reg_operand" "")))]
396 "TARGET_HARD_FLOAT && TARGET_FPRS"
399 (define_insn "*negtd2_fpr"
400 [(set (match_operand:TD 0 "gpc_reg_operand" "=d")
401 (neg:TD (match_operand:TD 1 "gpc_reg_operand" "d")))]
402 "TARGET_HARD_FLOAT && TARGET_FPRS"
404 [(set_attr "type" "fp")])
406 (define_expand "abstd2"
407 [(set (match_operand:TD 0 "gpc_reg_operand" "")
408 (abs:TD (match_operand:TD 1 "gpc_reg_operand" "")))]
409 "TARGET_HARD_FLOAT && TARGET_FPRS"
412 (define_insn "*abstd2_fpr"
413 [(set (match_operand:TD 0 "gpc_reg_operand" "=d")
414 (abs:TD (match_operand:TD 1 "gpc_reg_operand" "d")))]
415 "TARGET_HARD_FLOAT && TARGET_FPRS"
417 [(set_attr "type" "fp")])
419 (define_insn "*nabstd2_fpr"
420 [(set (match_operand:TD 0 "gpc_reg_operand" "=d")
421 (neg:TD (abs:TD (match_operand:TD 1 "gpc_reg_operand" "d"))))]
422 "TARGET_HARD_FLOAT && TARGET_FPRS"
424 [(set_attr "type" "fp")])
426 (define_expand "movtd"
427 [(set (match_operand:TD 0 "general_operand" "")
428 (match_operand:TD 1 "any_operand" ""))]
429 "TARGET_HARD_FLOAT && TARGET_FPRS"
430 "{ rs6000_emit_move (operands[0], operands[1], TDmode); DONE; }")
432 ; It's important to list the o->f and f->o moves before f->f because
433 ; otherwise reload, given m->f, will try to pick f->f and reload it,
434 ; which doesn't make progress. Likewise r->Y must be before r->r.
435 (define_insn_and_split "*movtd_internal"
436 [(set (match_operand:TD 0 "nonimmediate_operand" "=o,d,d,r,Y,r")
437 (match_operand:TD 1 "input_operand" "d,o,d,YGHF,r,r"))]
438 "TARGET_HARD_FLOAT && TARGET_FPRS
439 && (gpc_reg_operand (operands[0], TDmode)
440 || gpc_reg_operand (operands[1], TDmode))"
442 "&& reload_completed"
444 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; }
445 [(set_attr "length" "8,8,8,20,20,16")])
447 ;; Hardware support for decimal floating point operations.
449 (define_insn "extendddtd2"
450 [(set (match_operand:TD 0 "gpc_reg_operand" "=d")
451 (float_extend:TD (match_operand:DD 1 "gpc_reg_operand" "d")))]
454 [(set_attr "type" "fp")])
456 ;; The result of drdpq is an even/odd register pair with the converted
457 ;; value in the even register and zero in the odd register.
458 ;; FIXME: Avoid the register move by using a reload constraint to ensure
459 ;; that the result is the first of the pair receiving the result of drdpq.
461 (define_insn "trunctddd2"
462 [(set (match_operand:DD 0 "gpc_reg_operand" "=d")
463 (float_truncate:DD (match_operand:TD 1 "gpc_reg_operand" "d")))
464 (clobber (match_scratch:TD 2 "=d"))]
466 "drdpq %2,%1\;fmr %0,%2"
467 [(set_attr "type" "fp")])
469 (define_insn "adddd3"
470 [(set (match_operand:DD 0 "gpc_reg_operand" "=d")
471 (plus:DD (match_operand:DD 1 "gpc_reg_operand" "%d")
472 (match_operand:DD 2 "gpc_reg_operand" "d")))]
475 [(set_attr "type" "fp")])
477 (define_insn "addtd3"
478 [(set (match_operand:TD 0 "gpc_reg_operand" "=d")
479 (plus:TD (match_operand:TD 1 "gpc_reg_operand" "%d")
480 (match_operand:TD 2 "gpc_reg_operand" "d")))]
483 [(set_attr "type" "fp")])
485 (define_insn "subdd3"
486 [(set (match_operand:DD 0 "gpc_reg_operand" "=d")
487 (minus:DD (match_operand:DD 1 "gpc_reg_operand" "d")
488 (match_operand:DD 2 "gpc_reg_operand" "d")))]
491 [(set_attr "type" "fp")])
493 (define_insn "subtd3"
494 [(set (match_operand:TD 0 "gpc_reg_operand" "=d")
495 (minus:TD (match_operand:TD 1 "gpc_reg_operand" "d")
496 (match_operand:TD 2 "gpc_reg_operand" "d")))]
499 [(set_attr "type" "fp")])
501 (define_insn "muldd3"
502 [(set (match_operand:DD 0 "gpc_reg_operand" "=d")
503 (mult:DD (match_operand:DD 1 "gpc_reg_operand" "%d")
504 (match_operand:DD 2 "gpc_reg_operand" "d")))]
507 [(set_attr "type" "fp")])
509 (define_insn "multd3"
510 [(set (match_operand:TD 0 "gpc_reg_operand" "=d")
511 (mult:TD (match_operand:TD 1 "gpc_reg_operand" "%d")
512 (match_operand:TD 2 "gpc_reg_operand" "d")))]
515 [(set_attr "type" "fp")])
517 (define_insn "divdd3"
518 [(set (match_operand:DD 0 "gpc_reg_operand" "=d")
519 (div:DD (match_operand:DD 1 "gpc_reg_operand" "d")
520 (match_operand:DD 2 "gpc_reg_operand" "d")))]
523 [(set_attr "type" "fp")])
525 (define_insn "divtd3"
526 [(set (match_operand:TD 0 "gpc_reg_operand" "=d")
527 (div:TD (match_operand:TD 1 "gpc_reg_operand" "d")
528 (match_operand:TD 2 "gpc_reg_operand" "d")))]
531 [(set_attr "type" "fp")])
533 (define_insn "*cmpdd_internal1"
534 [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
535 (compare:CCFP (match_operand:DD 1 "gpc_reg_operand" "d")
536 (match_operand:DD 2 "gpc_reg_operand" "d")))]
539 [(set_attr "type" "fpcompare")])
541 (define_insn "*cmptd_internal1"
542 [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
543 (compare:CCFP (match_operand:TD 1 "gpc_reg_operand" "d")
544 (match_operand:TD 2 "gpc_reg_operand" "d")))]
547 [(set_attr "type" "fpcompare")])
549 (define_insn "floatditd2"
550 [(set (match_operand:TD 0 "gpc_reg_operand" "=d")
551 (float:TD (match_operand:DI 1 "gpc_reg_operand" "d")))]
554 [(set_attr "type" "fp")])
556 ;; Convert a decimal64 to a decimal64 whose value is an integer.
557 ;; This is the first stage of converting it to an integer type.
559 (define_insn "ftruncdd2"
560 [(set (match_operand:DD 0 "gpc_reg_operand" "=d")
561 (fix:DD (match_operand:DD 1 "gpc_reg_operand" "d")))]
564 [(set_attr "type" "fp")])
566 ;; Convert a decimal64 whose value is an integer to an actual integer.
567 ;; This is the second stage of converting decimal float to integer type.
569 (define_insn "fixdddi2"
570 [(set (match_operand:DI 0 "gpc_reg_operand" "=d")
571 (fix:DI (match_operand:DD 1 "gpc_reg_operand" "d")))]
574 [(set_attr "type" "fp")])
576 ;; Convert a decimal128 to a decimal128 whose value is an integer.
577 ;; This is the first stage of converting it to an integer type.
579 (define_insn "ftrunctd2"
580 [(set (match_operand:TD 0 "gpc_reg_operand" "=d")
581 (fix:TD (match_operand:TD 1 "gpc_reg_operand" "d")))]
584 [(set_attr "type" "fp")])
586 ;; Convert a decimal128 whose value is an integer to an actual integer.
587 ;; This is the second stage of converting decimal float to integer type.
589 (define_insn "fixtddi2"
590 [(set (match_operand:DI 0 "gpc_reg_operand" "=d")
591 (fix:DI (match_operand:TD 1 "gpc_reg_operand" "d")))]
594 [(set_attr "type" "fp")])