1 ;; Decimal Floating Point (DFP) patterns.
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/>.
23 (define_expand "negdd2"
24 [(set (match_operand:DD 0 "gpc_reg_operand" "")
25 (neg:DD (match_operand:DD 1 "gpc_reg_operand" "")))]
26 "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
29 (define_insn "*negdd2_fpr"
30 [(set (match_operand:DD 0 "gpc_reg_operand" "=f")
31 (neg:DD (match_operand:DD 1 "gpc_reg_operand" "f")))]
32 "TARGET_HARD_FLOAT && TARGET_FPRS"
34 [(set_attr "type" "fp")])
36 (define_expand "absdd2"
37 [(set (match_operand:DD 0 "gpc_reg_operand" "")
38 (abs:DD (match_operand:DD 1 "gpc_reg_operand" "")))]
39 "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
42 (define_insn "*absdd2_fpr"
43 [(set (match_operand:DD 0 "gpc_reg_operand" "=f")
44 (abs:DD (match_operand:DD 1 "gpc_reg_operand" "f")))]
45 "TARGET_HARD_FLOAT && TARGET_FPRS"
47 [(set_attr "type" "fp")])
49 (define_insn "*nabsdd2_fpr"
50 [(set (match_operand:DD 0 "gpc_reg_operand" "=f")
51 (neg:DD (abs:DD (match_operand:DF 1 "gpc_reg_operand" "f"))))]
52 "TARGET_HARD_FLOAT && TARGET_FPRS"
54 [(set_attr "type" "fp")])
56 (define_expand "movdd"
57 [(set (match_operand:DD 0 "nonimmediate_operand" "")
58 (match_operand:DD 1 "any_operand" ""))]
60 "{ rs6000_emit_move (operands[0], operands[1], DDmode); DONE; }")
63 [(set (match_operand:DD 0 "gpc_reg_operand" "")
64 (match_operand:DD 1 "const_int_operand" ""))]
65 "! TARGET_POWERPC64 && reload_completed
66 && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
67 || (GET_CODE (operands[0]) == SUBREG
68 && GET_CODE (SUBREG_REG (operands[0])) == REG
69 && REGNO (SUBREG_REG (operands[0])) <= 31))"
70 [(set (match_dup 2) (match_dup 4))
71 (set (match_dup 3) (match_dup 1))]
74 int endian = (WORDS_BIG_ENDIAN == 0);
75 HOST_WIDE_INT value = INTVAL (operands[1]);
77 operands[2] = operand_subword (operands[0], endian, 0, DDmode);
78 operands[3] = operand_subword (operands[0], 1 - endian, 0, DDmode);
79 #if HOST_BITS_PER_WIDE_INT == 32
80 operands[4] = (value & 0x80000000) ? constm1_rtx : const0_rtx;
82 operands[4] = GEN_INT (value >> 32);
83 operands[1] = GEN_INT (((value & 0xffffffff) ^ 0x80000000) - 0x80000000);
88 [(set (match_operand:DD 0 "gpc_reg_operand" "")
89 (match_operand:DD 1 "const_double_operand" ""))]
90 "! TARGET_POWERPC64 && reload_completed
91 && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
92 || (GET_CODE (operands[0]) == SUBREG
93 && GET_CODE (SUBREG_REG (operands[0])) == REG
94 && REGNO (SUBREG_REG (operands[0])) <= 31))"
95 [(set (match_dup 2) (match_dup 4))
96 (set (match_dup 3) (match_dup 5))]
99 int endian = (WORDS_BIG_ENDIAN == 0);
103 REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
104 REAL_VALUE_TO_TARGET_DECIMAL64 (rv, l);
106 operands[2] = operand_subword (operands[0], endian, 0, DDmode);
107 operands[3] = operand_subword (operands[0], 1 - endian, 0, DDmode);
108 operands[4] = gen_int_mode (l[endian], SImode);
109 operands[5] = gen_int_mode (l[1 - endian], SImode);
113 [(set (match_operand:DD 0 "gpc_reg_operand" "")
114 (match_operand:DD 1 "const_double_operand" ""))]
115 "TARGET_POWERPC64 && reload_completed
116 && ((GET_CODE (operands[0]) == REG && REGNO (operands[0]) <= 31)
117 || (GET_CODE (operands[0]) == SUBREG
118 && GET_CODE (SUBREG_REG (operands[0])) == REG
119 && REGNO (SUBREG_REG (operands[0])) <= 31))"
120 [(set (match_dup 2) (match_dup 3))]
123 int endian = (WORDS_BIG_ENDIAN == 0);
126 #if HOST_BITS_PER_WIDE_INT >= 64
130 REAL_VALUE_FROM_CONST_DOUBLE (rv, operands[1]);
131 REAL_VALUE_TO_TARGET_DECIMAL64 (rv, l);
133 operands[2] = gen_lowpart (DImode, operands[0]);
134 /* HIGHPART is lower memory address when WORDS_BIG_ENDIAN. */
135 #if HOST_BITS_PER_WIDE_INT >= 64
136 val = ((HOST_WIDE_INT)(unsigned long)l[endian] << 32
137 | ((HOST_WIDE_INT)(unsigned long)l[1 - endian]));
139 operands[3] = gen_int_mode (val, DImode);
141 operands[3] = immed_double_const (l[1 - endian], l[endian], DImode);
145 ;; Don't have reload use general registers to load a constant. First,
146 ;; it might not work if the output operand is the equivalent of
147 ;; a non-offsettable memref, but also it is less efficient than loading
148 ;; the constant into an FP register, since it will probably be used there.
149 ;; The "??" is a kludge until we can figure out a more reasonable way
150 ;; of handling these non-offsettable values.
151 (define_insn "*movdd_hardfloat32"
152 [(set (match_operand:DD 0 "nonimmediate_operand" "=!r,??r,m,f,f,m,!r,!r,!r")
153 (match_operand:DD 1 "input_operand" "r,m,r,f,m,f,G,H,F"))]
154 "! TARGET_POWERPC64 && TARGET_HARD_FLOAT && TARGET_FPRS
155 && (gpc_reg_operand (operands[0], DDmode)
156 || gpc_reg_operand (operands[1], DDmode))"
159 switch (which_alternative)
164 /* We normally copy the low-numbered register first. However, if
165 the first register operand 0 is the same as the second register
166 of operand 1, we must copy in the opposite order. */
167 if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
168 return \"mr %L0,%L1\;mr %0,%1\";
170 return \"mr %0,%1\;mr %L0,%L1\";
172 if (rs6000_offsettable_memref_p (operands[1])
173 || (GET_CODE (operands[1]) == MEM
174 && (GET_CODE (XEXP (operands[1], 0)) == LO_SUM
175 || GET_CODE (XEXP (operands[1], 0)) == PRE_INC
176 || GET_CODE (XEXP (operands[1], 0)) == PRE_DEC)))
178 /* If the low-address word is used in the address, we must load
179 it last. Otherwise, load it first. Note that we cannot have
180 auto-increment in that case since the address register is
182 if (refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
184 return \"{l|lwz} %L0,%L1\;{l|lwz} %0,%1\";
186 return \"{l%U1|lwz%U1} %0,%1\;{l|lwz} %L0,%L1\";
192 addreg = find_addr_reg (XEXP (operands[1], 0));
193 if (refers_to_regno_p (REGNO (operands[0]),
194 REGNO (operands[0]) + 1,
197 output_asm_insn (\"{cal|la} %0,4(%0)\", &addreg);
198 output_asm_insn (\"{lx|lwzx} %L0,%1\", operands);
199 output_asm_insn (\"{cal|la} %0,-4(%0)\", &addreg);
200 return \"{lx|lwzx} %0,%1\";
204 output_asm_insn (\"{lx|lwzx} %0,%1\", operands);
205 output_asm_insn (\"{cal|la} %0,4(%0)\", &addreg);
206 output_asm_insn (\"{lx|lwzx} %L0,%1\", operands);
207 output_asm_insn (\"{cal|la} %0,-4(%0)\", &addreg);
212 if (rs6000_offsettable_memref_p (operands[0])
213 || (GET_CODE (operands[0]) == MEM
214 && (GET_CODE (XEXP (operands[0], 0)) == LO_SUM
215 || GET_CODE (XEXP (operands[0], 0)) == PRE_INC
216 || GET_CODE (XEXP (operands[0], 0)) == PRE_DEC)))
217 return \"{st%U0|stw%U0} %1,%0\;{st|stw} %L1,%L0\";
222 addreg = find_addr_reg (XEXP (operands[0], 0));
223 output_asm_insn (\"{stx|stwx} %1,%0\", operands);
224 output_asm_insn (\"{cal|la} %0,4(%0)\", &addreg);
225 output_asm_insn (\"{stx|stwx} %L1,%0\", operands);
226 output_asm_insn (\"{cal|la} %0,-4(%0)\", &addreg);
230 return \"fmr %0,%1\";
232 return \"lfd%U1%X1 %0,%1\";
234 return \"stfd%U0%X0 %1,%0\";
241 [(set_attr "type" "two,load,store,fp,fpload,fpstore,*,*,*")
242 (set_attr "length" "8,16,16,4,4,4,8,12,16")])
244 (define_insn "*movdd_softfloat32"
245 [(set (match_operand:DD 0 "nonimmediate_operand" "=r,r,m,r,r,r")
246 (match_operand:DD 1 "input_operand" "r,m,r,G,H,F"))]
247 "! TARGET_POWERPC64 && TARGET_SOFT_FLOAT
248 && (gpc_reg_operand (operands[0], DDmode)
249 || gpc_reg_operand (operands[1], DDmode))"
252 switch (which_alternative)
257 /* We normally copy the low-numbered register first. However, if
258 the first register operand 0 is the same as the second register of
259 operand 1, we must copy in the opposite order. */
260 if (REGNO (operands[0]) == REGNO (operands[1]) + 1)
261 return \"mr %L0,%L1\;mr %0,%1\";
263 return \"mr %0,%1\;mr %L0,%L1\";
265 /* If the low-address word is used in the address, we must load
266 it last. Otherwise, load it first. Note that we cannot have
267 auto-increment in that case since the address register is
269 if (refers_to_regno_p (REGNO (operands[0]), REGNO (operands[0]) + 1,
271 return \"{l|lwz} %L0,%L1\;{l|lwz} %0,%1\";
273 return \"{l%U1|lwz%U1} %0,%1\;{l|lwz} %L0,%L1\";
275 return \"{st%U0|stw%U0} %1,%0\;{st|stw} %L1,%L0\";
282 [(set_attr "type" "two,load,store,*,*,*")
283 (set_attr "length" "8,8,8,8,12,16")])
285 ; ld/std require word-aligned displacements -> 'Y' constraint.
286 ; List Y->r and r->Y before r->r for reload.
287 (define_insn "*movdd_hardfloat64_mfpgpr"
288 [(set (match_operand:DD 0 "nonimmediate_operand" "=Y,r,!r,f,f,m,*c*l,!r,*h,!r,!r,!r,r,f")
289 (match_operand:DD 1 "input_operand" "r,Y,r,f,m,f,r,h,0,G,H,F,f,r"))]
290 "TARGET_POWERPC64 && TARGET_MFPGPR && TARGET_HARD_FLOAT && TARGET_FPRS
291 && (gpc_reg_operand (operands[0], DDmode)
292 || gpc_reg_operand (operands[1], DDmode))"
308 [(set_attr "type" "store,load,*,fp,fpload,fpstore,mtjmpr,mfjmpr,*,*,*,*,mftgpr,mffgpr")
309 (set_attr "length" "4,4,4,4,4,4,4,4,4,8,12,16,4,4")])
311 ; ld/std require word-aligned displacements -> 'Y' constraint.
312 ; List Y->r and r->Y before r->r for reload.(define_insn "*movdd_hardfloat64"
313 (define_insn "*movdd_hardfloat64"
314 [(set (match_operand:DD 0 "nonimmediate_operand" "=Y,r,!r,f,f,m,*c*l,!r,*h,!r,!r,!r")
315 (match_operand:DD 1 "input_operand" "r,Y,r,f,m,f,r,h,0,G,H,F"))]
316 "TARGET_POWERPC64 && !TARGET_MFPGPR && TARGET_HARD_FLOAT && TARGET_FPRS
317 && (gpc_reg_operand (operands[0], DDmode)
318 || gpc_reg_operand (operands[1], DDmode))"
332 [(set_attr "type" "store,load,*,fp,fpload,fpstore,mtjmpr,mfjmpr,*,*,*,*")
333 (set_attr "length" "4,4,4,4,4,4,4,4,4,8,12,16")])
335 (define_insn "*movdd_softfloat64"
336 [(set (match_operand:DD 0 "nonimmediate_operand" "=r,Y,r,cl,r,r,r,r,*h")
337 (match_operand:DD 1 "input_operand" "Y,r,r,r,h,G,H,F,0"))]
338 "TARGET_POWERPC64 && (TARGET_SOFT_FLOAT || !TARGET_FPRS)
339 && (gpc_reg_operand (operands[0], DDmode)
340 || gpc_reg_operand (operands[1], DDmode))"
351 [(set_attr "type" "load,store,*,mtjmpr,mfjmpr,*,*,*,*")
352 (set_attr "length" "4,4,4,4,4,8,12,16,4")])
354 (define_expand "negtd2"
355 [(set (match_operand:TD 0 "gpc_reg_operand" "")
356 (neg:TD (match_operand:TD 1 "gpc_reg_operand" "")))]
357 "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
360 (define_insn "*negtd2_fpr"
361 [(set (match_operand:TD 0 "gpc_reg_operand" "=f")
362 (neg:TD (match_operand:TD 1 "gpc_reg_operand" "f")))]
363 "TARGET_HARD_FLOAT && TARGET_FPRS"
365 [(set_attr "type" "fp")])
367 (define_expand "abstd2"
368 [(set (match_operand:TD 0 "gpc_reg_operand" "")
369 (abs:TD (match_operand:TD 1 "gpc_reg_operand" "")))]
370 "TARGET_HARD_FLOAT && (TARGET_FPRS || TARGET_E500_DOUBLE)"
373 (define_insn "*abstd2_fpr"
374 [(set (match_operand:TD 0 "gpc_reg_operand" "=f")
375 (abs:TD (match_operand:TD 1 "gpc_reg_operand" "f")))]
376 "TARGET_HARD_FLOAT && TARGET_FPRS"
378 [(set_attr "type" "fp")])
380 (define_insn "*nabstd2_fpr"
381 [(set (match_operand:TD 0 "gpc_reg_operand" "=f")
382 (neg:TD (abs:TD (match_operand:DF 1 "gpc_reg_operand" "f"))))]
383 "TARGET_HARD_FLOAT && TARGET_FPRS"
385 [(set_attr "type" "fp")])
387 (define_expand "movtd"
388 [(set (match_operand:TD 0 "general_operand" "")
389 (match_operand:TD 1 "any_operand" ""))]
390 "TARGET_HARD_FLOAT && TARGET_FPRS"
391 "{ rs6000_emit_move (operands[0], operands[1], TDmode); DONE; }")
393 ; It's important to list the o->f and f->o moves before f->f because
394 ; otherwise reload, given m->f, will try to pick f->f and reload it,
395 ; which doesn't make progress. Likewise r->Y must be before r->r.
396 (define_insn_and_split "*movtd_internal"
397 [(set (match_operand:TD 0 "nonimmediate_operand" "=o,f,f,r,Y,r")
398 (match_operand:TD 1 "input_operand" "f,o,f,YGHF,r,r"))]
399 "TARGET_HARD_FLOAT && TARGET_FPRS
400 && (gpc_reg_operand (operands[0], TDmode)
401 || gpc_reg_operand (operands[1], TDmode))"
403 "&& reload_completed"
405 { rs6000_split_multireg_move (operands[0], operands[1]); DONE; }
406 [(set_attr "length" "8,8,8,20,20,16")])
408 ;; Hardware support for decimal floating point operations.
410 (define_insn "extendddtd2"
411 [(set (match_operand:TD 0 "gpc_reg_operand" "=f")
412 (float_extend:TD (match_operand:DD 1 "gpc_reg_operand" "f")))]
415 [(set_attr "type" "fp")])
417 ;; The result of drdpq is an even/odd register pair with the converted
418 ;; value in the even register and zero in the odd register.
419 ;; FIXME: Avoid the register move by using a reload constraint to ensure
420 ;; that the result is the first of the pair receiving the result of drdpq.
422 (define_insn "trunctddd2"
423 [(set (match_operand:DD 0 "gpc_reg_operand" "=f")
424 (float_truncate:DD (match_operand:TD 1 "gpc_reg_operand" "f")))
425 (clobber (match_scratch:TD 2 "=f"))]
427 "drdpq %2,%1\;fmr %0,%2"
428 [(set_attr "type" "fp")])
430 (define_insn "adddd3"
431 [(set (match_operand:DD 0 "gpc_reg_operand" "=f")
432 (plus:DD (match_operand:DD 1 "gpc_reg_operand" "%f")
433 (match_operand:DD 2 "gpc_reg_operand" "f")))]
436 [(set_attr "type" "fp")])
438 (define_insn "addtd3"
439 [(set (match_operand:TD 0 "gpc_reg_operand" "=f")
440 (plus:TD (match_operand:TD 1 "gpc_reg_operand" "%f")
441 (match_operand:TD 2 "gpc_reg_operand" "f")))]
444 [(set_attr "type" "fp")])
446 (define_insn "subdd3"
447 [(set (match_operand:DD 0 "gpc_reg_operand" "=f")
448 (minus:DD (match_operand:DD 1 "gpc_reg_operand" "f")
449 (match_operand:DD 2 "gpc_reg_operand" "f")))]
452 [(set_attr "type" "fp")])
454 (define_insn "subtd3"
455 [(set (match_operand:TD 0 "gpc_reg_operand" "=f")
456 (minus:TD (match_operand:TD 1 "gpc_reg_operand" "f")
457 (match_operand:TD 2 "gpc_reg_operand" "f")))]
460 [(set_attr "type" "fp")])
462 (define_insn "muldd3"
463 [(set (match_operand:DD 0 "gpc_reg_operand" "=f")
464 (mult:DD (match_operand:DD 1 "gpc_reg_operand" "%f")
465 (match_operand:DD 2 "gpc_reg_operand" "f")))]
468 [(set_attr "type" "fp")])
470 (define_insn "multd3"
471 [(set (match_operand:TD 0 "gpc_reg_operand" "=f")
472 (mult:TD (match_operand:TD 1 "gpc_reg_operand" "%f")
473 (match_operand:TD 2 "gpc_reg_operand" "f")))]
476 [(set_attr "type" "fp")])
478 (define_insn "divdd3"
479 [(set (match_operand:DD 0 "gpc_reg_operand" "=f")
480 (div:DD (match_operand:DD 1 "gpc_reg_operand" "f")
481 (match_operand:DD 2 "gpc_reg_operand" "f")))]
484 [(set_attr "type" "fp")])
486 (define_insn "divtd3"
487 [(set (match_operand:TD 0 "gpc_reg_operand" "=f")
488 (div:TD (match_operand:TD 1 "gpc_reg_operand" "f")
489 (match_operand:TD 2 "gpc_reg_operand" "f")))]
492 [(set_attr "type" "fp")])
494 (define_insn "*cmpdd_internal1"
495 [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
496 (compare:CCFP (match_operand:DD 1 "gpc_reg_operand" "f")
497 (match_operand:DD 2 "gpc_reg_operand" "f")))]
500 [(set_attr "type" "fpcompare")])
502 (define_insn "*cmptd_internal1"
503 [(set (match_operand:CCFP 0 "cc_reg_operand" "=y")
504 (compare:CCFP (match_operand:TD 1 "gpc_reg_operand" "f")
505 (match_operand:TD 2 "gpc_reg_operand" "f")))]
508 [(set_attr "type" "fpcompare")])
510 (define_insn "floatditd2"
511 [(set (match_operand:TD 0 "gpc_reg_operand" "=f")
512 (float:TD (match_operand:DI 1 "gpc_reg_operand" "f")))]
515 [(set_attr "type" "fp")])
517 ;; Convert a decimal64 to a decimal64 whose value is an integer.
518 ;; This is the first stage of converting it to an integer type.
520 (define_insn "ftruncdd2"
521 [(set (match_operand:DD 0 "gpc_reg_operand" "=f")
522 (fix:DD (match_operand:DD 1 "gpc_reg_operand" "f")))]
525 [(set_attr "type" "fp")])
527 ;; Convert a decimal64 whose value is an integer to an actual integer.
528 ;; This is the second stage of converting decimal float to integer type.
530 (define_insn "fixdddi2"
531 [(set (match_operand:DI 0 "gpc_reg_operand" "=f")
532 (fix:DI (match_operand:DD 1 "gpc_reg_operand" "f")))]
535 [(set_attr "type" "fp")])
537 ;; Convert a decimal128 to a decimal128 whose value is an integer.
538 ;; This is the first stage of converting it to an integer type.
540 (define_insn "ftrunctd2"
541 [(set (match_operand:TD 0 "gpc_reg_operand" "=f")
542 (fix:TD (match_operand:TD 1 "gpc_reg_operand" "f")))]
545 [(set_attr "type" "fp")])
547 ;; Convert a decimal128 whose value is an integer to an actual integer.
548 ;; This is the second stage of converting decimal float to integer type.
550 (define_insn "fixtddi2"
551 [(set (match_operand:DI 0 "gpc_reg_operand" "=f")
552 (fix:DI (match_operand:TD 1 "gpc_reg_operand" "f")))]
555 [(set_attr "type" "fp")])