| 1 |
;; Machine Description for TI PRU. |
| 2 |
;; Copyright (C) 2014-2025 Free Software Foundation, Inc. |
| 3 |
;; Contributed by Dimitar Dimitrov <[email protected]> |
| 4 |
;; Based on the NIOS2 GCC port. |
| 5 |
;; |
| 6 |
;; This file is part of GCC. |
| 7 |
;; |
| 8 |
;; GCC is free software; you can redistribute it and/or modify |
| 9 |
;; it under the terms of the GNU General Public License as published by |
| 10 |
;; the Free Software Foundation; either version 3, or (at your option) |
| 11 |
;; any later version. |
| 12 |
;; |
| 13 |
;; GCC is distributed in the hope that it will be useful, |
| 14 |
;; but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 |
;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 |
;; GNU General Public License for more details. |
| 17 |
;; |
| 18 |
;; You should have received a copy of the GNU General Public License |
| 19 |
;; along with GCC; see the file COPYING3. If not see |
| 20 |
;; <http://www.gnu.org/licenses/>. |
| 21 |
|
| 22 |
;; Register numbers. |
| 23 |
(define_constants |
| 24 |
[ |
| 25 |
(FIRST_ARG_REGNUM 56) ; Argument registers. |
| 26 |
(LAST_ARG_REGNUM 119) ; |
| 27 |
(FIRST_RETVAL_REGNUM 56) ; Return value registers. |
| 28 |
(LAST_RETVAL_REGNUM 60) ; |
| 29 |
(FIRST_CALLEE_SAVED_REGNUM 12) ; Callee saved registers. |
| 30 |
(LAST_CALEE_SAVED_REGNUM 55) ; |
| 31 |
(PROLOGUE_TEMP_REGNUM 4) ; Temporary register to use in prologue. |
| 32 |
|
| 33 |
(RA_REGNUM 14) ; Return address register r3.w2. |
| 34 |
(FP_REGNUM 16) ; Frame pointer register. |
| 35 |
(MULDST_REGNUM 104) ; Multiply destination register. |
| 36 |
(MULSRC0_REGNUM 112) ; Multiply source register. |
| 37 |
(MULSRC1_REGNUM 116) ; Multiply source register. |
| 38 |
(LAST_NONIO_GP_REGNUM 119) ; Last non-I/O general purpose register. |
| 39 |
(R30_REGNUM 120) ; R30 I/O register. |
| 40 |
(R31_REGNUM 124) ; R31 I/O register. |
| 41 |
(LOOPCNTR_REGNUM 128) ; internal LOOP counter register |
| 42 |
(LAST_GP_REGNUM 132) ; Last general purpose register. |
| 43 |
|
| 44 |
;; Target register definitions. |
| 45 |
(STACK_POINTER_REGNUM 8) |
| 46 |
(HARD_FRAME_POINTER_REGNUM FP_REGNUM) |
| 47 |
(PC_REGNUM 132) |
| 48 |
(FRAME_POINTER_REGNUM 136) |
| 49 |
(ARG_POINTER_REGNUM 140) |
| 50 |
(FIRST_PSEUDO_REGISTER 144) |
| 51 |
] |
| 52 |
) |
| 53 |
|
| 54 |
;; Enumerate address spaces. |
| 55 |
(define_constants |
| 56 |
[ |
| 57 |
(ADDR_SPACE_REGIO 1) ; Access to R30 and R31 I/O registers. |
| 58 |
] |
| 59 |
) |
| 60 |
|
| 61 |
;; Enumeration of UNSPECs. |
| 62 |
|
| 63 |
(define_c_enum "unspec" [ |
| 64 |
UNSPEC_LMBD |
| 65 |
]) |
| 66 |
|
| 67 |
(define_c_enum "unspecv" [ |
| 68 |
UNSPECV_DELAY_CYCLES_START |
| 69 |
UNSPECV_DELAY_CYCLES_END |
| 70 |
UNSPECV_DELAY_CYCLES_2X_HI |
| 71 |
UNSPECV_DELAY_CYCLES_2X_SI |
| 72 |
UNSPECV_DELAY_CYCLES_1 |
| 73 |
|
| 74 |
UNSPECV_LOOP_BEGIN |
| 75 |
UNSPECV_LOOP_END |
| 76 |
|
| 77 |
UNSPECV_HALT |
| 78 |
|
| 79 |
UNSPECV_BLOCKAGE |
| 80 |
|
| 81 |
UNSPECV_REGIO_READ |
| 82 |
UNSPECV_REGIO_WRITE |
| 83 |
]) |
| 84 |
|
| 85 |
; Length of an instruction (in bytes). |
| 86 |
(define_attr "length" "" (const_int 4)) |
| 87 |
(define_attr "type" |
| 88 |
"unknown,complex,control,alu,cond_alu,st,ld,shift" |
| 89 |
(const_string "complex")) |
| 90 |
|
| 91 |
(define_asm_attributes |
| 92 |
[(set_attr "length" "4") |
| 93 |
(set_attr "type" "complex")]) |
| 94 |
|
| 95 |
; There is no pipeline, so our scheduling description is simple. |
| 96 |
(define_automaton "pru") |
| 97 |
(define_cpu_unit "cpu" "pru") |
| 98 |
|
| 99 |
(define_insn_reservation "everything" 1 (match_test "true") "cpu") |
| 100 |
|
| 101 |
(include "predicates.md") |
| 102 |
(include "constraints.md") |
| 103 |
|
| 104 |
;; All supported direct move-modes |
| 105 |
(define_mode_iterator MOV8_16_32 [QI QQ UQQ |
| 106 |
HI HQ UHQ HA UHA |
| 107 |
SI SQ USQ SA USA SF SD]) |
| 108 |
|
| 109 |
(define_mode_iterator MOV8_16 [QI QQ UQQ |
| 110 |
HI HQ UHQ HA UHA]) |
| 111 |
(define_mode_iterator MOV32 [SI SQ USQ SA USA SF SD]) |
| 112 |
(define_mode_iterator MOV64 [DI DF DD DQ UDQ]) |
| 113 |
(define_mode_iterator QISI [QI HI SI]) |
| 114 |
(define_mode_iterator HISI [HI SI]) |
| 115 |
(define_mode_iterator HIDI [HI SI DI]) |
| 116 |
(define_mode_iterator SFDF [SF DF]) |
| 117 |
|
| 118 |
;; EQS0/1 for extension source 0/1 and EQD for extension destination patterns. |
| 119 |
(define_mode_iterator EQS0 [QI HI SI]) |
| 120 |
(define_mode_iterator EQS1 [QI HI SI]) |
| 121 |
(define_mode_iterator EQD [QI HI SI]) |
| 122 |
(define_mode_iterator EQDHIDI [HI SI DI]) |
| 123 |
|
| 124 |
;; GCC sign-extends its integer constants. Hence 0x80 will be represented |
| 125 |
;; as -128 for QI mode and 128 for HI and SI modes. To cope with this, |
| 126 |
;; use different constraints to match UBYTE in different modes. |
| 127 |
;; |
| 128 |
;; Wherever this iterator is used, the corresponding operand has the 'u' |
| 129 |
;; print format modifier. That is how the QI signedness is cured, and |
| 130 |
;; the generated assembly contains unsigned constants. |
| 131 |
;; |
| 132 |
;; If the pattern has no QI operands, then this iterator need not be used. |
| 133 |
;; |
| 134 |
;; Note that we do not require "uhword_constr" since ALU instructions |
| 135 |
;; can use only UBYTE constants. The MOV patterns are already separately |
| 136 |
;; defined for each size, hence no need for an iterator. |
| 137 |
(define_mode_attr ubyte_constr [(QI "O") (HI "I") (SI "I")]) |
| 138 |
|
| 139 |
;; Move instructions |
| 140 |
|
| 141 |
(define_expand "mov<mode>" |
| 142 |
[(set (match_operand:MOV8_16_32 0 "nonimmediate_operand") |
| 143 |
(match_operand:MOV8_16_32 1 "general_operand"))] |
| 144 |
"" |
| 145 |
{ |
| 146 |
if (MEM_P (operands[0]) |
| 147 |
&& MEM_ADDR_SPACE (operands[0]) == ADDR_SPACE_REGIO) |
| 148 |
|
| 149 |
{ |
| 150 |
/* Intercept writes to the SImode register I/O "address space". */ |
| 151 |
gcc_assert (<MODE>mode == SImode); |
| 152 |
|
| 153 |
if (!SYMBOL_REF_P (XEXP (operands[0], 0))) |
| 154 |
{ |
| 155 |
error ("invalid access to %<__regio_symbol%> address space"); |
| 156 |
FAIL; |
| 157 |
} |
| 158 |
|
| 159 |
if (!REG_P (operands[1])) |
| 160 |
operands[1] = force_reg (<MODE>mode, operands[1]); |
| 161 |
|
| 162 |
int regiono = pru_symref2ioregno (XEXP (operands[0], 0)); |
| 163 |
gcc_assert (regiono >= 0); |
| 164 |
rtx regio = gen_rtx_REG (<MODE>mode, regiono); |
| 165 |
rtx unspecv = gen_rtx_UNSPEC_VOLATILE (<MODE>mode, |
| 166 |
gen_rtvec (1, operands[1]), |
| 167 |
UNSPECV_REGIO_WRITE); |
| 168 |
emit_insn (gen_rtx_SET (regio, unspecv)); |
| 169 |
DONE; |
| 170 |
} |
| 171 |
else if (MEM_P (operands[1]) |
| 172 |
&& MEM_ADDR_SPACE (operands[1]) == ADDR_SPACE_REGIO) |
| 173 |
{ |
| 174 |
/* Intercept reads from the SImode register I/O "address space". */ |
| 175 |
gcc_assert (<MODE>mode == SImode); |
| 176 |
|
| 177 |
if (!SYMBOL_REF_P (XEXP (operands[1], 0))) |
| 178 |
{ |
| 179 |
error ("invalid access to %<__regio_symbol%> address space"); |
| 180 |
FAIL; |
| 181 |
} |
| 182 |
|
| 183 |
if (MEM_P (operands[0])) |
| 184 |
operands[0] = force_reg (<MODE>mode, operands[0]); |
| 185 |
|
| 186 |
int regiono = pru_symref2ioregno (XEXP (operands[1], 0)); |
| 187 |
gcc_assert (regiono >= 0); |
| 188 |
rtx regio = gen_rtx_REG (<MODE>mode, regiono); |
| 189 |
rtx unspecv = gen_rtx_UNSPEC_VOLATILE (<MODE>mode, |
| 190 |
gen_rtvec (1, regio), |
| 191 |
UNSPECV_REGIO_READ); |
| 192 |
emit_insn (gen_rtx_SET (operands[0], unspecv)); |
| 193 |
DONE; |
| 194 |
} |
| 195 |
else if (MEM_P (operands[0])) |
| 196 |
{ |
| 197 |
/* It helps to split constant loading and memory access |
| 198 |
early, so that the LDI/LDI32 instructions can be hoisted |
| 199 |
outside a loop body. */ |
| 200 |
operands[1] = force_reg (<MODE>mode, operands[1]); |
| 201 |
} |
| 202 |
}) |
| 203 |
|
| 204 |
;; Keep a single pattern for 32 bit MOV operations. LRA requires that the |
| 205 |
;; movXX patterns be unified for any given mode. |
| 206 |
;; |
| 207 |
;; Note: Assume that Program Mem (T constraint) can fit in 16 bits! |
| 208 |
(define_insn "prumov<mode>" |
| 209 |
[(set (match_operand:MOV32 0 "nonimmediate_operand" "=m,r,r,r,r,r,r") |
| 210 |
(match_operand:MOV32 1 "general_operand" "r,m,r,T,J,Um,iF"))] |
| 211 |
"" |
| 212 |
"@ |
| 213 |
sb%B0o\\t%b1, %0, %S0 |
| 214 |
lb%B1o\\t%b0, %1, %S1 |
| 215 |
mov\\t%0, %1 |
| 216 |
ldi\\t%0, %%pmem(%1) |
| 217 |
ldi\\t%0, %1 |
| 218 |
fill\\t%0, 4 |
| 219 |
ldi32\\t%0, %1" |
| 220 |
[(set_attr "type" "st,ld,alu,alu,alu,alu,alu") |
| 221 |
(set_attr "length" "4,4,4,4,4,4,8")]) |
| 222 |
|
| 223 |
|
| 224 |
;; Separate pattern for 8 and 16 bit moves, since LDI32 pseudo instruction |
| 225 |
;; cannot handle byte and word-sized registers. |
| 226 |
;; |
| 227 |
;; Note: Constraint N is fine for both QI and HI mode, since it is used |
| 228 |
;; in the context of 16 bit constant integer. |
| 229 |
(define_insn "prumov<mode>" |
| 230 |
[(set (match_operand:MOV8_16 0 "nonimmediate_operand" "=m,r,r,r,r") |
| 231 |
(match_operand:MOV8_16 1 "general_operand" "r,m,r,T,N"))] |
| 232 |
"" |
| 233 |
"@ |
| 234 |
sb%B0o\\t%b1, %0, %S0 |
| 235 |
lb%B1o\\t%b0, %1, %S1 |
| 236 |
mov\\t%0, %1 |
| 237 |
ldi\\t%0, %%pmem(%1) |
| 238 |
ldi\\t%0, (%1) & 0xffff" |
| 239 |
[(set_attr "type" "st,ld,alu,alu,alu") |
| 240 |
(set_attr "length" "4")]) |
| 241 |
|
| 242 |
|
| 243 |
; Pmode is 32 bits for PRU so symbolic constants cannot be 64 bits. Hence |
| 244 |
; this pattern handles only numeric constants. |
| 245 |
; |
| 246 |
; Note: Unlike the arithmetics, here we cannot use "&" output modifier. |
| 247 |
; GCC expects to be able to move registers around "no matter what". |
| 248 |
; Forcing DI reg alignment (akin to microblaze's HARD_REGNO_MODE_OK) |
| 249 |
; does not seem efficient, and will violate TI ABI. |
| 250 |
(define_insn "mov<mode>" |
| 251 |
[(set (match_operand:MOV64 0 "nonimmediate_operand" "=m,r,r,r,r,r,r,r") |
| 252 |
(match_operand:MOV64 1 "general_operand" "r,m,Z,Um,r,T,J,nF"))] |
| 253 |
"" |
| 254 |
{ |
| 255 |
switch (which_alternative) |
| 256 |
{ |
| 257 |
case 0: |
| 258 |
return "sb%B0o\\t%b1, %0, %S0"; |
| 259 |
case 1: |
| 260 |
return "lb%B1o\\t%b0, %1, %S1"; |
| 261 |
case 2: |
| 262 |
return "zero\\t%F0, 8"; |
| 263 |
case 3: |
| 264 |
return "fill\\t%F0, 8"; |
| 265 |
case 4: |
| 266 |
/* careful with overlapping source and destination regs. */ |
| 267 |
gcc_assert (GP_REG_P (REGNO (operands[0]))); |
| 268 |
gcc_assert (GP_REG_P (REGNO (operands[1]))); |
| 269 |
if (REGNO (operands[0]) == (REGNO (operands[1]) + 4)) |
| 270 |
return "mov\\t%N0, %N1\;mov\\t%F0, %F1"; |
| 271 |
else |
| 272 |
return "mov\\t%F0, %F1\;mov\\t%N0, %N1"; |
| 273 |
case 5: |
| 274 |
return "ldi\\t%F0, %%pmem(%1)\;ldi\\t%N0, 0"; |
| 275 |
case 6: |
| 276 |
return "ldi\\t%F0, %1\;ldi\\t%N0, 0"; |
| 277 |
case 7: |
| 278 |
return "ldi32\\t%F0, %w1\;ldi32\\t%N0, %W1"; |
| 279 |
default: |
| 280 |
gcc_unreachable (); |
| 281 |
} |
| 282 |
} |
| 283 |
[(set_attr "type" "st,ld,alu,alu,alu,alu,alu,alu") |
| 284 |
(set_attr "length" "4,4,4,4,8,8,8,16")]) |
| 285 |
|
| 286 |
; |
| 287 |
; load_multiple pattern(s). |
| 288 |
; |
| 289 |
; ??? Due to reload problems with replacing registers inside match_parallel |
| 290 |
; we currently support load_multiple/store_multiple only after reload. |
| 291 |
; |
| 292 |
; Idea taken from the s390 port. |
| 293 |
|
| 294 |
(define_expand "load_multiple" |
| 295 |
[(match_par_dup 3 [(set (match_operand 0 "") |
| 296 |
(match_operand 1 "")) |
| 297 |
(use (match_operand 2 ""))])] |
| 298 |
"reload_completed" |
| 299 |
{ |
| 300 |
machine_mode mode; |
| 301 |
int regno; |
| 302 |
int count; |
| 303 |
rtx base_reg; |
| 304 |
poly_int64 base_offs; |
| 305 |
int i; |
| 306 |
|
| 307 |
/* Support only loading a constant number of fixed-point registers from |
| 308 |
memory. */ |
| 309 |
if (GET_CODE (operands[2]) != CONST_INT |
| 310 |
|| GET_CODE (operands[1]) != MEM |
| 311 |
|| GET_CODE (operands[0]) != REG) |
| 312 |
FAIL; |
| 313 |
|
| 314 |
count = INTVAL (operands[2]); |
| 315 |
regno = REGNO (operands[0]); |
| 316 |
mode = GET_MODE (operands[0]); |
| 317 |
if (mode != QImode) |
| 318 |
FAIL; |
| 319 |
|
| 320 |
operands[3] = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count)); |
| 321 |
|
| 322 |
gcc_assert (!can_create_pseudo_p ()); |
| 323 |
|
| 324 |
base_reg = strip_offset (XEXP (operands[1], 0), &base_offs); |
| 325 |
if (GET_CODE (base_reg) != REG) |
| 326 |
FAIL; |
| 327 |
|
| 328 |
for (i = 0; i < count; i++) |
| 329 |
XVECEXP (operands[3], 0, i) |
| 330 |
= gen_rtx_SET (gen_rtx_REG (mode, regno + i), |
| 331 |
change_address (operands[1], mode, |
| 332 |
plus_constant (Pmode, base_reg, |
| 333 |
base_offs + i * GET_MODE_SIZE (mode)))); |
| 334 |
}) |
| 335 |
|
| 336 |
(define_insn "*pru_load_multiple" |
| 337 |
[(match_parallel 0 "load_multiple_operation" |
| 338 |
[(set (match_operand:QI 1 "register_operand" "=r") |
| 339 |
(match_operand:QI 2 "memory_operand" "m"))])] |
| 340 |
"reload_completed" |
| 341 |
{ |
| 342 |
int nregs = XVECLEN (operands[0], 0); |
| 343 |
operands[0] = GEN_INT (nregs); |
| 344 |
return "lb%B2o\\t%b1, %2, %0"; |
| 345 |
} |
| 346 |
[(set_attr "type" "ld")]) |
| 347 |
|
| 348 |
; |
| 349 |
; store multiple pattern(s). |
| 350 |
; |
| 351 |
|
| 352 |
(define_expand "store_multiple" |
| 353 |
[(match_par_dup 3 [(set (match_operand 0 "") |
| 354 |
(match_operand 1 "")) |
| 355 |
(use (match_operand 2 ""))])] |
| 356 |
"reload_completed" |
| 357 |
{ |
| 358 |
machine_mode mode; |
| 359 |
int regno; |
| 360 |
int count; |
| 361 |
rtx base_reg; |
| 362 |
poly_int64 base_offs; |
| 363 |
int i; |
| 364 |
|
| 365 |
/* Support only storing a constant number of fixed-point registers to |
| 366 |
memory. */ |
| 367 |
if (GET_CODE (operands[2]) != CONST_INT |
| 368 |
|| GET_CODE (operands[0]) != MEM |
| 369 |
|| GET_CODE (operands[1]) != REG) |
| 370 |
FAIL; |
| 371 |
|
| 372 |
count = INTVAL (operands[2]); |
| 373 |
regno = REGNO (operands[1]); |
| 374 |
mode = GET_MODE (operands[1]); |
| 375 |
if (mode != QImode) |
| 376 |
FAIL; |
| 377 |
|
| 378 |
operands[3] = gen_rtx_PARALLEL (VOIDmode, rtvec_alloc (count)); |
| 379 |
|
| 380 |
gcc_assert (!can_create_pseudo_p ()); |
| 381 |
|
| 382 |
base_reg = strip_offset (XEXP (operands[0], 0), &base_offs); |
| 383 |
if (GET_CODE (base_reg) != REG) |
| 384 |
FAIL; |
| 385 |
|
| 386 |
for (i = 0; i < count; i++) |
| 387 |
XVECEXP (operands[3], 0, i) |
| 388 |
= gen_rtx_SET (change_address (operands[0], mode, |
| 389 |
plus_constant (Pmode, base_reg, |
| 390 |
base_offs + i * GET_MODE_SIZE (mode))), |
| 391 |
gen_rtx_REG (mode, regno + i)); |
| 392 |
}) |
| 393 |
|
| 394 |
(define_insn "*pru_store_multiple" |
| 395 |
[(match_parallel 0 "store_multiple_operation" |
| 396 |
[(set (match_operand:QI 1 "memory_operand" "=m") |
| 397 |
(match_operand:QI 2 "register_operand" "r"))])] |
| 398 |
"reload_completed" |
| 399 |
{ |
| 400 |
int nregs = XVECLEN (operands[0], 0); |
| 401 |
operands[0] = GEN_INT (nregs); |
| 402 |
return "sb%B1o\\t%b2, %1, %0"; |
| 403 |
} |
| 404 |
[(set_attr "type" "st")]) |
| 405 |
|
| 406 |
;; Zero extension patterns |
| 407 |
;; |
| 408 |
;; Unfortunately we cannot use lbbo to load AND zero-extent a value. |
| 409 |
;; The burst length parameter of the LBBO instruction designates not only |
| 410 |
;; the number of memory data bytes fetched, but also the number of register |
| 411 |
;; byte fields written. |
| 412 |
(define_expand "zero_extend<EQS0:mode><EQD:mode>2" |
| 413 |
[(set (match_operand:EQD 0 "register_operand") |
| 414 |
(zero_extend:EQD (match_operand:EQS0 1 "register_operand")))] |
| 415 |
"" |
| 416 |
"") |
| 417 |
|
| 418 |
(define_insn "*zero_extend<EQS0:mode><EQD:mode>2" |
| 419 |
[(set (match_operand:EQD 0 "register_operand" "=r") |
| 420 |
(zero_extend:EQD (match_operand:EQS0 1 "register_operand" "r")))] |
| 421 |
"" |
| 422 |
"mov\\t%0, %1" |
| 423 |
[(set_attr "type" "alu")]) |
| 424 |
|
| 425 |
(define_insn "zero_extendqidi2" |
| 426 |
[(set (match_operand:DI 0 "register_operand" "=r,r") |
| 427 |
(zero_extend:DI (match_operand:QI 1 "register_operand" "0,r")))] |
| 428 |
"" |
| 429 |
"@ |
| 430 |
zero\\t%F0.b1, 7 |
| 431 |
mov\\t%F0.b0, %1\;zero\\t%F0.b1, 7" |
| 432 |
[(set_attr "type" "alu,alu") |
| 433 |
(set_attr "length" "4,8")]) |
| 434 |
|
| 435 |
(define_insn "zero_extendhidi2" |
| 436 |
[(set (match_operand:DI 0 "register_operand" "=r,r") |
| 437 |
(zero_extend:DI (match_operand:HI 1 "register_operand" "0,r")))] |
| 438 |
"" |
| 439 |
"@ |
| 440 |
zero\\t%F0.b2, 6 |
| 441 |
mov\\t%F0.w0, %1\;zero\\t%F0.b2, 6" |
| 442 |
[(set_attr "type" "alu,alu") |
| 443 |
(set_attr "length" "4,8")]) |
| 444 |
|
| 445 |
(define_insn "zero_extendsidi2" |
| 446 |
[(set (match_operand:DI 0 "register_operand" "=r,r") |
| 447 |
(zero_extend:DI (match_operand:SI 1 "register_operand" "0,r")))] |
| 448 |
"" |
| 449 |
"@ |
| 450 |
zero\\t%N0, 4 |
| 451 |
mov\\t%F0, %1\;zero\\t%N0, 4" |
| 452 |
[(set_attr "type" "alu,alu") |
| 453 |
(set_attr "length" "4,8")]) |
| 454 |
|
| 455 |
;; Sign extension pattern. We have to emulate it due to lack of |
| 456 |
;; signed operations in PRU's ALU. |
| 457 |
|
| 458 |
(define_expand "extend<EQS0:mode><EQDHIDI:mode>2" |
| 459 |
[(set (match_operand:EQDHIDI 0 "register_operand" "=r") |
| 460 |
(sign_extend:EQDHIDI (match_operand:EQS0 1 "register_operand" "r")))] |
| 461 |
"" |
| 462 |
{ |
| 463 |
rtx_code_label *skip_hiset_label; |
| 464 |
|
| 465 |
/* Clear the higher bits to temporarily make the value positive. */ |
| 466 |
emit_insn (gen_rtx_SET (operands[0], |
| 467 |
gen_rtx_ZERO_EXTEND (<EQDHIDI:MODE>mode, |
| 468 |
operands[1]))); |
| 469 |
|
| 470 |
/* Now check if the result must be made negative. */ |
| 471 |
skip_hiset_label = gen_label_rtx (); |
| 472 |
const int op1_size = GET_MODE_SIZE (<EQS0:MODE>mode); |
| 473 |
const int op1_sign_bit = op1_size * BITS_PER_UNIT - 1; |
| 474 |
emit_jump_insn (gen_cbranch_qbbx_const (EQ, |
| 475 |
<EQDHIDI:MODE>mode, |
| 476 |
operands[0], |
| 477 |
GEN_INT (op1_sign_bit), |
| 478 |
skip_hiset_label)); |
| 479 |
emit_insn (gen_ior<EQDHIDI:mode>3 ( |
| 480 |
operands[0], |
| 481 |
operands[0], |
| 482 |
GEN_INT (~GET_MODE_MASK (<EQS0:MODE>mode)))); |
| 483 |
emit_label (skip_hiset_label); |
| 484 |
|
| 485 |
DONE; |
| 486 |
}) |
| 487 |
|
| 488 |
;; Bit extraction |
| 489 |
;; One reason to define it is to allow combine to choose SImode |
| 490 |
;; for word mode when trying to match our cbranch_qbbx_* insn. |
| 491 |
;; |
| 492 |
;; Check how combine.cc:make_extraction() uses |
| 493 |
;; get_best_reg_extraction_insn() to select the op size. |
| 494 |
(define_expand "extzv<mode>" |
| 495 |
[(set (match_operand:QISI 0 "register_operand") |
| 496 |
(zero_extract:QISI |
| 497 |
(match_operand:QISI 1 "register_operand") |
| 498 |
(match_operand:QISI 2 "const_int_operand") |
| 499 |
(match_operand:QISI 3 "const_int_operand")))] |
| 500 |
"" |
| 501 |
{ |
| 502 |
const int nbits = INTVAL (operands[2]); |
| 503 |
const int bitpos = INTVAL (operands[3]); |
| 504 |
const int trailing_bits = GET_MODE_BITSIZE (<MODE>mode) - nbits - bitpos; |
| 505 |
|
| 506 |
if (bitpos == 0 && nbits <= 7) |
| 507 |
{ |
| 508 |
emit_insn (gen_and<mode>3 (operands[0], |
| 509 |
operands[1], |
| 510 |
gen_int_mode ((HOST_WIDE_INT_1U << nbits) - 1, |
| 511 |
<MODE>mode))); |
| 512 |
DONE; |
| 513 |
} |
| 514 |
|
| 515 |
rtx src = operands[1]; |
| 516 |
if (trailing_bits != 0) |
| 517 |
{ |
| 518 |
emit_insn (gen_ashl<mode>3 (operands[0], |
| 519 |
operands[1], |
| 520 |
GEN_INT (trailing_bits))); |
| 521 |
src = operands[0]; |
| 522 |
} |
| 523 |
emit_insn (gen_lshr<mode>3 (operands[0], |
| 524 |
src, |
| 525 |
GEN_INT (trailing_bits + bitpos))); |
| 526 |
DONE; |
| 527 |
}) |
| 528 |
|
| 529 |
;; Bit-field insert. |
| 530 |
(define_expand "insv<mode>" |
| 531 |
[(set (zero_extract:QISI |
| 532 |
(match_operand:QISI 0 "register_operand") |
| 533 |
(match_operand:QISI 1 "const_int_operand") |
| 534 |
(match_operand:QISI 2 "const_int_operand")) |
| 535 |
(match_operand:QISI 3 "reg_or_ubyte_operand"))] |
| 536 |
"" |
| 537 |
{ |
| 538 |
const int nbits = INTVAL (operands[1]); |
| 539 |
const int bitpos = INTVAL (operands[2]); |
| 540 |
|
| 541 |
if (nbits == 1) |
| 542 |
{ |
| 543 |
rtx j; |
| 544 |
rtx src = gen_reg_rtx (<MODE>mode); |
| 545 |
rtx dst = operands[0]; |
| 546 |
|
| 547 |
emit_move_insn (src, operands[3]); |
| 548 |
|
| 549 |
emit_insn (gen_and<mode>3 (dst, |
| 550 |
dst, |
| 551 |
gen_int_mode (~(HOST_WIDE_INT_1U << bitpos), |
| 552 |
<MODE>mode))); |
| 553 |
|
| 554 |
rtx_code_label *skip_set_label = gen_label_rtx (); |
| 555 |
j = emit_jump_insn (gen_cbranch_qbbx_eq<mode><mode><mode>4 ( |
| 556 |
src, |
| 557 |
GEN_INT (0), |
| 558 |
skip_set_label)); |
| 559 |
JUMP_LABEL (j) = skip_set_label; |
| 560 |
LABEL_NUSES (skip_set_label)++; |
| 561 |
|
| 562 |
emit_insn (gen_ior<mode>3 (dst, |
| 563 |
dst, |
| 564 |
gen_int_mode (HOST_WIDE_INT_1U << bitpos, |
| 565 |
<MODE>mode))); |
| 566 |
emit_label (skip_set_label); |
| 567 |
|
| 568 |
DONE; |
| 569 |
} |
| 570 |
|
| 571 |
/* Explicitly expand in order to avoid using word_mode for PRU, and instead |
| 572 |
use SI and HI modes as applicable. */ |
| 573 |
rtx dst = operands[0]; |
| 574 |
rtx src = gen_reg_rtx (<MODE>mode); |
| 575 |
emit_insn (gen_and<mode>3 (src, |
| 576 |
force_reg (<MODE>mode, operands[3]), |
| 577 |
gen_int_mode ((HOST_WIDE_INT_1U << nbits) - 1, |
| 578 |
<MODE>mode))); |
| 579 |
if (bitpos > 0) |
| 580 |
emit_insn (gen_ashl<mode>3 (src, src, gen_int_mode (bitpos, <MODE>mode))); |
| 581 |
|
| 582 |
HOST_WIDE_INT vmask = ~(((HOST_WIDE_INT_1U << nbits) - 1) << bitpos); |
| 583 |
emit_insn (gen_and<mode>3 (dst, |
| 584 |
dst, |
| 585 |
gen_int_mode (vmask, <MODE>mode))); |
| 586 |
|
| 587 |
emit_insn (gen_ior<mode>3 (dst, dst, src)); |
| 588 |
|
| 589 |
DONE; |
| 590 |
}) |
| 591 |
|
| 592 |
|
| 593 |
;; Arithmetic Operations |
| 594 |
|
| 595 |
(define_expand "add<mode>3" |
| 596 |
[(set (match_operand:QISI 0 "register_operand") |
| 597 |
(plus:QISI (match_operand:QISI 1 "register_operand") |
| 598 |
(match_operand:QISI 2 "nonmemory_operand")))] |
| 599 |
"" |
| 600 |
"") |
| 601 |
|
| 602 |
(define_insn "adddi3" |
| 603 |
[(set (match_operand:DI 0 "register_operand" "=&r,&r,&r") |
| 604 |
(plus:DI (match_operand:DI 1 "register_operand" "%r,r,r") |
| 605 |
(match_operand:DI 2 "reg_or_ubyte_operand" "r,I,M")))] |
| 606 |
"" |
| 607 |
"@ |
| 608 |
add\\t%F0, %F1, %F2\;adc\\t%N0, %N1, %N2 |
| 609 |
add\\t%F0, %F1, %2\;adc\\t%N0, %N1, 0 |
| 610 |
sub\\t%F0, %F1, %n2\;suc\\t%N0, %N1, 0" |
| 611 |
[(set_attr "type" "alu") |
| 612 |
(set_attr "length" "8")]) |
| 613 |
|
| 614 |
(define_expand "sub<mode>3" |
| 615 |
[(set (match_operand:QISI 0 "register_operand") |
| 616 |
(minus:QISI (match_operand:QISI 1 "reg_or_ubyte_operand") |
| 617 |
(match_operand:QISI 2 "reg_or_ubyte_operand")))] |
| 618 |
"" |
| 619 |
"") |
| 620 |
|
| 621 |
(define_insn "subdi3" |
| 622 |
[(set (match_operand:DI 0 "register_operand" "=&r,&r") |
| 623 |
(minus:DI (match_operand:DI 1 "reg_or_ubyte_operand" "r,I") |
| 624 |
(match_operand:DI 2 "register_operand" "r,r")))] |
| 625 |
"" |
| 626 |
"@ |
| 627 |
sub\\t%F0, %F1, %F2\;suc\\t%N0, %N1, %N2 |
| 628 |
rsb\\t%F0, %F2, %1\;rsc\\t%N0, %N2, 0" |
| 629 |
[(set_attr "type" "alu") |
| 630 |
(set_attr "length" "8")]) |
| 631 |
|
| 632 |
;; Negate and ones complement |
| 633 |
|
| 634 |
(define_expand "neg<mode>2" |
| 635 |
[(set (match_operand:QISI 0 "register_operand") |
| 636 |
(neg:QISI (match_operand:QISI 1 "register_operand")))] |
| 637 |
"" |
| 638 |
"") |
| 639 |
|
| 640 |
(define_expand "one_cmpl<mode>2" |
| 641 |
[(set (match_operand:QISI 0 "register_operand") |
| 642 |
(not:QISI (match_operand:QISI 1 "register_operand")))] |
| 643 |
"" |
| 644 |
"") |
| 645 |
|
| 646 |
;; Integer logical Operations |
| 647 |
;; |
| 648 |
;; TODO - add optimized cases that exploit the fact that we can get away |
| 649 |
;; with a single machine op for special constants, e.g. UBYTE << (0/8/16/24) |
| 650 |
|
| 651 |
(define_code_iterator LOGICAL [and ior xor umin umax]) |
| 652 |
(define_code_attr logical_asm [(and "and") (ior "or") (xor "xor") (umin "min") (umax "max")]) |
| 653 |
|
| 654 |
(define_code_iterator LOGICAL_BITOP [and ior xor]) |
| 655 |
(define_code_attr logical_bitop_asm [(and "and") (ior "or") (xor "xor")]) |
| 656 |
|
| 657 |
(define_expand "<code><mode>3" |
| 658 |
[(set (match_operand:QISI 0 "register_operand") |
| 659 |
(LOGICAL:QISI (match_operand:QISI 1 "register_operand") |
| 660 |
(match_operand:QISI 2 "reg_or_ubyte_operand")))] |
| 661 |
"" |
| 662 |
"") |
| 663 |
|
| 664 |
;; Specialised IOR pattern, which can emit an efficient FILL instruction. |
| 665 |
(define_insn "@pru_ior_fillbytes<mode>" |
| 666 |
[(set (match_operand:HIDI 0 "register_operand" "=r") |
| 667 |
(ior:HIDI |
| 668 |
(match_operand:HIDI 1 "register_operand" "0") |
| 669 |
(match_operand:HIDI 2 "const_fillbytes_operand" "Uf")))] |
| 670 |
"" |
| 671 |
{ |
| 672 |
static char line[64]; |
| 673 |
pru_byterange r; |
| 674 |
|
| 675 |
r = pru_calc_byterange (INTVAL (operands[2]), <MODE>mode); |
| 676 |
gcc_assert (r.start >=0 && r.nbytes > 0); |
| 677 |
gcc_assert ((r.start + r.nbytes) <= GET_MODE_SIZE (<MODE>mode)); |
| 678 |
|
| 679 |
const int regno = REGNO (operands[0]) + r.start; |
| 680 |
|
| 681 |
sprintf (line, "fill\\tr%d.b%d, %d", regno / 4, regno % 4, r.nbytes); |
| 682 |
return line; |
| 683 |
} |
| 684 |
[(set_attr "type" "alu") |
| 685 |
(set_attr "length" "4")]) |
| 686 |
|
| 687 |
;; Specialised AND pattern, which can emit an efficient ZERO instruction. |
| 688 |
(define_insn "@pru_and_zerobytes<mode>" |
| 689 |
[(set (match_operand:HIDI 0 "register_operand" "=r") |
| 690 |
(and:HIDI |
| 691 |
(match_operand:HIDI 1 "register_operand" "0") |
| 692 |
(match_operand:HIDI 2 "const_zerobytes_operand" "Uz")))] |
| 693 |
"" |
| 694 |
{ |
| 695 |
static char line[64]; |
| 696 |
pru_byterange r; |
| 697 |
|
| 698 |
r = pru_calc_byterange (~INTVAL (operands[2]), <MODE>mode); |
| 699 |
gcc_assert (r.start >=0 && r.nbytes > 0); |
| 700 |
gcc_assert ((r.start + r.nbytes) <= GET_MODE_SIZE (<MODE>mode)); |
| 701 |
|
| 702 |
const int regno = REGNO (operands[0]) + r.start; |
| 703 |
|
| 704 |
sprintf (line, "zero\\tr%d.b%d, %d", regno / 4, regno % 4, r.nbytes); |
| 705 |
return line; |
| 706 |
} |
| 707 |
[(set_attr "type" "alu") |
| 708 |
(set_attr "length" "4")]) |
| 709 |
|
| 710 |
;; Shift instructions |
| 711 |
|
| 712 |
(define_code_iterator SHIFT [ashift lshiftrt]) |
| 713 |
(define_code_attr shift_op [(ashift "ashl") (lshiftrt "lshr")]) |
| 714 |
(define_code_attr shift_asm [(ashift "lsl") (lshiftrt "lsr")]) |
| 715 |
|
| 716 |
(define_expand "<shift_op><mode>3" |
| 717 |
[(set (match_operand:QISI 0 "register_operand") |
| 718 |
(SHIFT:QISI (match_operand:QISI 1 "register_operand") |
| 719 |
(match_operand:QISI 2 "shift_operand")))] |
| 720 |
"" |
| 721 |
"") |
| 722 |
|
| 723 |
; Expand to a loop of single-position arithmetic shifts, which |
| 724 |
; we can handle. Pseudo code: |
| 725 |
; tmpval = src; |
| 726 |
; QImode cntr = nshifts & 0xff; |
| 727 |
; while (cntr) |
| 728 |
; { |
| 729 |
; tmpval >>= 1; |
| 730 |
; cntr--; |
| 731 |
; } |
| 732 |
; dst = tmpval; |
| 733 |
; |
| 734 |
; Note that the number of shifts is truncated to QImode. This is a fair |
| 735 |
; assumption for a loop-based shifting implementation. |
| 736 |
(define_expand "ashr<mode>3" |
| 737 |
[(set (match_operand:QISI 0 "register_operand") |
| 738 |
(ashiftrt:QISI |
| 739 |
(match_operand:QISI 1 "register_operand") |
| 740 |
(match_operand:QI 2 "reg_or_const_1_operand")))] |
| 741 |
"" |
| 742 |
{ |
| 743 |
rtx dst = operands[0]; |
| 744 |
rtx src = operands[1]; |
| 745 |
rtx nshifts = operands[2]; |
| 746 |
rtx_code_label *loop_label; |
| 747 |
rtx_code_label *ashr_end_label; |
| 748 |
rtx test, tmpval, cntr; |
| 749 |
|
| 750 |
if (const_1_operand (nshifts, VOIDmode)) |
| 751 |
{ |
| 752 |
emit_insn (gen_ashr<mode>3_single (dst, src, nshifts)); |
| 753 |
DONE; |
| 754 |
} |
| 755 |
|
| 756 |
tmpval = gen_reg_rtx (<MODE>mode); |
| 757 |
emit_move_insn (tmpval, src); |
| 758 |
|
| 759 |
cntr = gen_reg_rtx (QImode); |
| 760 |
emit_move_insn (cntr, nshifts); |
| 761 |
|
| 762 |
loop_label = gen_label_rtx (); |
| 763 |
ashr_end_label = gen_label_rtx (); |
| 764 |
|
| 765 |
emit_label (loop_label); |
| 766 |
test = gen_rtx_EQ (VOIDmode, cntr, const0_rtx); |
| 767 |
emit_jump_insn (gen_cbranchqi4 (test, cntr, const0_rtx, ashr_end_label)); |
| 768 |
|
| 769 |
emit_insn (gen_ashr<mode>3_single (tmpval, tmpval, const1_rtx)); |
| 770 |
emit_insn (gen_addqi3 (cntr, cntr, GEN_INT (-1))); |
| 771 |
|
| 772 |
emit_jump_insn (gen_jump (loop_label)); |
| 773 |
JUMP_LABEL (get_last_insn ()) = loop_label; |
| 774 |
LABEL_NUSES (loop_label)++; |
| 775 |
emit_barrier (); |
| 776 |
|
| 777 |
emit_label (ashr_end_label); |
| 778 |
|
| 779 |
emit_move_insn (dst, tmpval); |
| 780 |
|
| 781 |
DONE; |
| 782 |
}) |
| 783 |
|
| 784 |
(define_insn "ashr<mode>3_single" |
| 785 |
[(set (match_operand:QISI 0 "register_operand" "=r") |
| 786 |
(ashiftrt:QISI |
| 787 |
(match_operand:QISI 1 "register_operand" "r") |
| 788 |
(match_operand:QI 2 "const_1_operand" "P")))] |
| 789 |
"" |
| 790 |
"lsr\\t%0, %1, 1\;qbbc LSIGN%=, %0, (%S0 * 8) - 2\;set %0, %0, (%S0 * 8) - 1\;LSIGN%=:" |
| 791 |
[(set_attr "type" "alu") |
| 792 |
(set_attr "length" "12")]) |
| 793 |
|
| 794 |
|
| 795 |
; 64-bit LSHIFTRT with a constant shift count can be expanded into |
| 796 |
; more efficient code sequence than a variable register shift. |
| 797 |
; |
| 798 |
; 1. For shift >= 32: |
| 799 |
; dst_lo = (src_hi >> (shift - 32)) |
| 800 |
; dst_hi = 0 |
| 801 |
; |
| 802 |
; 2. For shift==1 there is no need for a temporary: |
| 803 |
; dst_lo = (src_lo >> 1) |
| 804 |
; if (src_hi & 1) |
| 805 |
; dst_lo |= (1 << 31) |
| 806 |
; dst_hi = (src_hi >> 1) |
| 807 |
; |
| 808 |
; 3. For shift < 32: |
| 809 |
; dst_lo = (src_lo >> shift) |
| 810 |
; tmp = (src_hi << (32 - shift) |
| 811 |
; dst_lo |= tmp |
| 812 |
; dst_hi = (src_hi >> shift) |
| 813 |
; |
| 814 |
; 4. For shift in a register: |
| 815 |
; Fall back to calling libgcc. |
| 816 |
(define_expand "lshrdi3" |
| 817 |
[(set (match_operand:DI 0 "register_operand") |
| 818 |
(lshiftrt:DI |
| 819 |
(match_operand:DI 1 "register_operand") |
| 820 |
(match_operand:QI 2 "const_int_operand")))] |
| 821 |
"" |
| 822 |
{ |
| 823 |
gcc_assert (CONST_INT_P (operands[2])); |
| 824 |
|
| 825 |
const int nshifts = INTVAL (operands[2]); |
| 826 |
rtx dst_lo = simplify_gen_subreg (SImode, operands[0], DImode, 0); |
| 827 |
rtx dst_hi = simplify_gen_subreg (SImode, operands[0], DImode, 4); |
| 828 |
rtx src_lo = simplify_gen_subreg (SImode, operands[1], DImode, 0); |
| 829 |
rtx src_hi = simplify_gen_subreg (SImode, operands[1], DImode, 4); |
| 830 |
|
| 831 |
if (nshifts >= 32) |
| 832 |
{ |
| 833 |
emit_insn (gen_rtx_SET (dst_lo, |
| 834 |
gen_rtx_LSHIFTRT (SImode, |
| 835 |
src_hi, |
| 836 |
GEN_INT (nshifts - 32)))); |
| 837 |
emit_insn (gen_rtx_SET (dst_hi, const0_rtx)); |
| 838 |
DONE; |
| 839 |
} |
| 840 |
|
| 841 |
gcc_assert (can_create_pseudo_p ()); |
| 842 |
|
| 843 |
/* The expansions which follow are safe only if DST_LO and SRC_HI |
| 844 |
do not overlap. If they do, then fix by using a temporary register. |
| 845 |
Overlapping of DST_HI and SRC_LO is safe because by the time DST_HI |
| 846 |
is set, SRC_LO is no longer live. */ |
| 847 |
if (reg_overlap_mentioned_p (dst_lo, src_hi)) |
| 848 |
{ |
| 849 |
rtx new_src_hi = gen_reg_rtx (SImode); |
| 850 |
|
| 851 |
emit_move_insn (new_src_hi, src_hi); |
| 852 |
src_hi = new_src_hi; |
| 853 |
} |
| 854 |
|
| 855 |
if (nshifts == 1) |
| 856 |
{ |
| 857 |
rtx_code_label *skip_hiset_label; |
| 858 |
rtx j; |
| 859 |
|
| 860 |
emit_insn (gen_rtx_SET (dst_lo, |
| 861 |
gen_rtx_LSHIFTRT (SImode, src_lo, const1_rtx))); |
| 862 |
|
| 863 |
/* The code generated by `genemit' would create a LABEL_REF. */ |
| 864 |
skip_hiset_label = gen_label_rtx (); |
| 865 |
j = emit_jump_insn (gen_cbranch_qbbx_const (EQ, |
| 866 |
SImode, |
| 867 |
src_hi, |
| 868 |
GEN_INT (0), |
| 869 |
skip_hiset_label)); |
| 870 |
JUMP_LABEL (j) = skip_hiset_label; |
| 871 |
LABEL_NUSES (skip_hiset_label)++; |
| 872 |
|
| 873 |
const HOST_WIDE_INT bit31_mask = HOST_WIDE_INT_1U << 31; |
| 874 |
emit_insn (gen_iorsi3 (dst_lo, dst_lo, GEN_INT (bit31_mask))); |
| 875 |
emit_label (skip_hiset_label); |
| 876 |
emit_insn (gen_rtx_SET (dst_hi, |
| 877 |
gen_rtx_LSHIFTRT (SImode, src_hi, const1_rtx))); |
| 878 |
DONE; |
| 879 |
} |
| 880 |
|
| 881 |
if (nshifts < 32) |
| 882 |
{ |
| 883 |
rtx tmpval = gen_reg_rtx (SImode); |
| 884 |
|
| 885 |
emit_insn (gen_rtx_SET (dst_lo, |
| 886 |
gen_rtx_LSHIFTRT (SImode, |
| 887 |
src_lo, |
| 888 |
GEN_INT (nshifts)))); |
| 889 |
emit_insn (gen_rtx_SET (tmpval, |
| 890 |
gen_rtx_ASHIFT (SImode, |
| 891 |
src_hi, |
| 892 |
GEN_INT (32 - nshifts)))); |
| 893 |
emit_insn (gen_iorsi3 (dst_lo, dst_lo, tmpval)); |
| 894 |
emit_insn (gen_rtx_SET (dst_hi, |
| 895 |
gen_rtx_LSHIFTRT (SImode, |
| 896 |
src_hi, |
| 897 |
GEN_INT (nshifts)))); |
| 898 |
DONE; |
| 899 |
} |
| 900 |
gcc_unreachable (); |
| 901 |
}) |
| 902 |
|
| 903 |
; 64-bit ASHIFT with a constant shift count can be expanded into |
| 904 |
; more efficient code sequence than the libgcc call required by |
| 905 |
; a variable shift in a register. |
| 906 |
|
| 907 |
(define_expand "ashldi3" |
| 908 |
[(set (match_operand:DI 0 "register_operand") |
| 909 |
(ashift:DI |
| 910 |
(match_operand:DI 1 "register_operand") |
| 911 |
(match_operand:QI 2 "const_int_operand")))] |
| 912 |
"" |
| 913 |
{ |
| 914 |
gcc_assert (CONST_INT_P (operands[2])); |
| 915 |
|
| 916 |
const int nshifts = INTVAL (operands[2]); |
| 917 |
rtx dst_lo = simplify_gen_subreg (SImode, operands[0], DImode, 0); |
| 918 |
rtx dst_hi = simplify_gen_subreg (SImode, operands[0], DImode, 4); |
| 919 |
rtx src_lo = simplify_gen_subreg (SImode, operands[1], DImode, 0); |
| 920 |
rtx src_hi = simplify_gen_subreg (SImode, operands[1], DImode, 4); |
| 921 |
|
| 922 |
if (nshifts >= 32) |
| 923 |
{ |
| 924 |
emit_insn (gen_rtx_SET (dst_hi, |
| 925 |
gen_rtx_ASHIFT (SImode, |
| 926 |
src_lo, |
| 927 |
GEN_INT (nshifts - 32)))); |
| 928 |
emit_insn (gen_rtx_SET (dst_lo, const0_rtx)); |
| 929 |
DONE; |
| 930 |
} |
| 931 |
|
| 932 |
gcc_assert (can_create_pseudo_p ()); |
| 933 |
|
| 934 |
/* The expansions which follow are safe only if DST_HI and SRC_LO |
| 935 |
do not overlap. If they do, then fix by using a temporary register. |
| 936 |
Overlapping of DST_LO and SRC_HI is safe because by the time DST_LO |
| 937 |
is set, SRC_HI is no longer live. */ |
| 938 |
if (reg_overlap_mentioned_p (dst_hi, src_lo)) |
| 939 |
{ |
| 940 |
rtx new_src_lo = gen_reg_rtx (SImode); |
| 941 |
|
| 942 |
emit_move_insn (new_src_lo, src_lo); |
| 943 |
src_lo = new_src_lo; |
| 944 |
} |
| 945 |
|
| 946 |
if (nshifts == 1) |
| 947 |
{ |
| 948 |
rtx_code_label *skip_hiset_label; |
| 949 |
rtx j; |
| 950 |
|
| 951 |
emit_insn (gen_rtx_SET (dst_hi, |
| 952 |
gen_rtx_ASHIFT (SImode, src_hi, const1_rtx))); |
| 953 |
|
| 954 |
skip_hiset_label = gen_label_rtx (); |
| 955 |
j = emit_jump_insn (gen_cbranch_qbbx_const (EQ, |
| 956 |
SImode, |
| 957 |
src_lo, |
| 958 |
GEN_INT (31), |
| 959 |
skip_hiset_label)); |
| 960 |
JUMP_LABEL (j) = skip_hiset_label; |
| 961 |
LABEL_NUSES (skip_hiset_label)++; |
| 962 |
|
| 963 |
const HOST_WIDE_INT bit0_mask = HOST_WIDE_INT_1U << 0; |
| 964 |
emit_insn (gen_iorsi3 (dst_hi, dst_hi, GEN_INT (bit0_mask))); |
| 965 |
emit_label (skip_hiset_label); |
| 966 |
emit_insn (gen_rtx_SET (dst_lo, |
| 967 |
gen_rtx_ASHIFT (SImode, src_lo, const1_rtx))); |
| 968 |
DONE; |
| 969 |
} |
| 970 |
|
| 971 |
if (nshifts < 32) |
| 972 |
{ |
| 973 |
rtx tmpval = gen_reg_rtx (SImode); |
| 974 |
|
| 975 |
emit_insn (gen_rtx_SET (dst_hi, |
| 976 |
gen_rtx_ASHIFT (SImode, |
| 977 |
src_hi, |
| 978 |
GEN_INT (nshifts)))); |
| 979 |
emit_insn (gen_rtx_SET (tmpval, |
| 980 |
gen_rtx_LSHIFTRT (SImode, |
| 981 |
src_lo, |
| 982 |
GEN_INT (32 - nshifts)))); |
| 983 |
emit_insn (gen_iorsi3 (dst_hi, dst_hi, tmpval)); |
| 984 |
emit_insn (gen_rtx_SET (dst_lo, |
| 985 |
gen_rtx_ASHIFT (SImode, |
| 986 |
src_lo, |
| 987 |
GEN_INT (nshifts)))); |
| 988 |
DONE; |
| 989 |
} |
| 990 |
gcc_unreachable (); |
| 991 |
}) |
| 992 |
|
| 993 |
;; Include ALU patterns with zero-extension of operands. That's where |
| 994 |
;; the real insns are defined. |
| 995 |
|
| 996 |
(include "alu-zext.md") |
| 997 |
|
| 998 |
;; Patterns for accessing the R30/R31 I/O registers. |
| 999 |
|
| 1000 |
(define_insn "*regio_readsi" |
| 1001 |
[(set (match_operand:SI 0 "register_operand" "=r") |
| 1002 |
(unspec_volatile:SI |
| 1003 |
[(match_operand:SI 1 "regio_operand" "Rrio")] |
| 1004 |
UNSPECV_REGIO_READ))] |
| 1005 |
"" |
| 1006 |
"mov\\t%0, %1" |
| 1007 |
[(set_attr "type" "alu")]) |
| 1008 |
|
| 1009 |
(define_insn "*regio_nozext_writesi" |
| 1010 |
[(set (match_operand:SI 0 "regio_operand" "=Rrio") |
| 1011 |
(unspec_volatile:SI |
| 1012 |
[(match_operand:SI 1 "register_operand" "r")] |
| 1013 |
UNSPECV_REGIO_WRITE))] |
| 1014 |
"" |
| 1015 |
"mov\\t%0, %1" |
| 1016 |
[(set_attr "type" "alu")]) |
| 1017 |
|
| 1018 |
(define_insn "*regio_zext_write_r30<EQS0:mode>" |
| 1019 |
[(set (match_operand:SI 0 "regio_operand" "=Rrio") |
| 1020 |
(unspec_volatile:SI |
| 1021 |
[(zero_extend:SI (match_operand:EQS0 1 "register_operand" "r"))] |
| 1022 |
UNSPECV_REGIO_WRITE))] |
| 1023 |
"" |
| 1024 |
"mov\\t%0, %1" |
| 1025 |
[(set_attr "type" "alu")]) |
| 1026 |
|
| 1027 |
;; DI logical ops could be automatically split into WORD-mode ops in |
| 1028 |
;; expand_binop(). But then we'll miss an opportunity to use SI mode |
| 1029 |
;; operations, since WORD mode for PRU is QI. |
| 1030 |
(define_expand "<code>di3" |
| 1031 |
[(set (match_operand:DI 0 "register_operand") |
| 1032 |
(LOGICAL_BITOP:DI |
| 1033 |
(match_operand:DI 1 "register_operand") |
| 1034 |
(match_operand:DI 2 "reg_or_const_int_operand")))] |
| 1035 |
"" |
| 1036 |
{ |
| 1037 |
/* Try with the more efficient zero/fill patterns first. */ |
| 1038 |
if (<LOGICAL_BITOP:CODE> == IOR |
| 1039 |
&& CONST_INT_P (operands[2]) |
| 1040 |
&& const_fillbytes_operand (operands[2], DImode)) |
| 1041 |
{ |
| 1042 |
rtx insn = maybe_gen_pru_ior_fillbytes (DImode, |
| 1043 |
operands[0], |
| 1044 |
operands[0], |
| 1045 |
operands[2]); |
| 1046 |
if (insn != nullptr) |
| 1047 |
{ |
| 1048 |
if (REGNO (operands[0]) != REGNO (operands[1])) |
| 1049 |
emit_move_insn (operands[0], operands[1]); |
| 1050 |
emit_insn (insn); |
| 1051 |
DONE; |
| 1052 |
} |
| 1053 |
} |
| 1054 |
if (<LOGICAL_BITOP:CODE> == AND |
| 1055 |
&& CONST_INT_P (operands[2]) |
| 1056 |
&& const_zerobytes_operand (operands[2], DImode)) |
| 1057 |
{ |
| 1058 |
rtx insn = maybe_gen_pru_and_zerobytes (DImode, |
| 1059 |
operands[0], |
| 1060 |
operands[0], |
| 1061 |
operands[2]); |
| 1062 |
if (insn != nullptr) |
| 1063 |
{ |
| 1064 |
if (REGNO (operands[0]) != REGNO (operands[1])) |
| 1065 |
emit_move_insn (operands[0], operands[1]); |
| 1066 |
emit_insn (insn); |
| 1067 |
DONE; |
| 1068 |
} |
| 1069 |
} |
| 1070 |
/* No optimized case found. Rely on the two-instruction pattern below. */ |
| 1071 |
if (!reg_or_ubyte_operand (operands[2], DImode)) |
| 1072 |
operands[2] = force_reg (DImode, operands[2]); |
| 1073 |
}) |
| 1074 |
|
| 1075 |
;; 64-bit pattern for logical operations. |
| 1076 |
(define_insn "pru_<code>di3" |
| 1077 |
[(set (match_operand:DI 0 "register_operand" "=r,&r,r") |
| 1078 |
(LOGICAL_BITOP:DI |
| 1079 |
(match_operand:DI 1 "register_operand" "%0,r,r") |
| 1080 |
(match_operand:DI 2 "reg_or_ubyte_operand" "r,r,I")))] |
| 1081 |
"" |
| 1082 |
{ |
| 1083 |
switch (which_alternative) |
| 1084 |
{ |
| 1085 |
case 0: |
| 1086 |
if (REGNO (operands[0]) == (REGNO (operands[2]) + 4)) |
| 1087 |
return "<logical_bitop_asm>\\t%N0, %N0, %N2\;" |
| 1088 |
"<logical_bitop_asm>\\t%F0, %F0, %F2"; |
| 1089 |
else |
| 1090 |
return "<logical_bitop_asm>\\t%F0, %F0, %F2\;" |
| 1091 |
"<logical_bitop_asm>\\t%N0, %N0, %N2"; |
| 1092 |
case 1: |
| 1093 |
/* With the three-register variant there is no way to handle the case |
| 1094 |
when OP0 overlaps both OP1 and OP2. Example: |
| 1095 |
OP0_lo == OP1_hi |
| 1096 |
OP0_hi == OP2_lo |
| 1097 |
Hence this variant's OP0 must be marked as an earlyclobber. */ |
| 1098 |
return "<logical_bitop_asm>\\t%F0, %F1, %F2\;" |
| 1099 |
"<logical_bitop_asm>\\t%N0, %N1, %N2"; |
| 1100 |
case 2: |
| 1101 |
if (REGNO (operands[0]) == (REGNO (operands[1]) + 4)) |
| 1102 |
return "<logical_bitop_asm>\\t%N0, %N1, 0\;" |
| 1103 |
"<logical_bitop_asm>\\t%F0, %F1, %2"; |
| 1104 |
else |
| 1105 |
return "<logical_bitop_asm>\\t%F0, %F1, %2\;" |
| 1106 |
"<logical_bitop_asm>\\t%N0, %N1, 0"; |
| 1107 |
default: |
| 1108 |
gcc_unreachable (); |
| 1109 |
} |
| 1110 |
} |
| 1111 |
[(set_attr "type" "alu") |
| 1112 |
(set_attr "length" "8")]) |
| 1113 |
|
| 1114 |
(define_insn "one_cmpldi2" |
| 1115 |
[(set (match_operand:DI 0 "register_operand" "=r") |
| 1116 |
(not:DI (match_operand:DI 1 "register_operand" "r")))] |
| 1117 |
"" |
| 1118 |
{ |
| 1119 |
/* careful with overlapping source and destination regs. */ |
| 1120 |
gcc_assert (GP_REG_P (REGNO (operands[0]))); |
| 1121 |
gcc_assert (GP_REG_P (REGNO (operands[1]))); |
| 1122 |
if (REGNO (operands[0]) == (REGNO (operands[1]) + 4)) |
| 1123 |
return "not\\t%N0, %N1\;not\\t%F0, %F1"; |
| 1124 |
else |
| 1125 |
return "not\\t%F0, %F1\;not\\t%N0, %N1"; |
| 1126 |
} |
| 1127 |
[(set_attr "type" "alu") |
| 1128 |
(set_attr "length" "8")]) |
| 1129 |
|
| 1130 |
;; Multiply instruction. The nop is required to ensure that Rmd0 and Rms0 |
| 1131 |
;; registers are sampled and multiplication is executed on those values. |
| 1132 |
;; Only after that one cycle can xin obtain the result. |
| 1133 |
|
| 1134 |
(define_insn "mulsi3" |
| 1135 |
[(set (match_operand:SI 0 "pru_muldst_operand" "=Rmd0") |
| 1136 |
(mult:SI (match_operand:SI 1 "pru_mulsrc0_operand" "%Rms0") |
| 1137 |
(match_operand:SI 2 "pru_mulsrc1_operand" "Rms1")))] |
| 1138 |
"" |
| 1139 |
"nop\;xin\\t0, %0, 4" |
| 1140 |
[(set_attr "type" "alu") |
| 1141 |
(set_attr "length" "8")]) |
| 1142 |
|
| 1143 |
;; Prologue, Epilogue and Return |
| 1144 |
|
| 1145 |
(define_expand "prologue" |
| 1146 |
[(const_int 1)] |
| 1147 |
"" |
| 1148 |
{ |
| 1149 |
pru_expand_prologue (); |
| 1150 |
DONE; |
| 1151 |
}) |
| 1152 |
|
| 1153 |
(define_expand "epilogue" |
| 1154 |
[(return)] |
| 1155 |
"" |
| 1156 |
{ |
| 1157 |
pru_expand_epilogue (false); |
| 1158 |
DONE; |
| 1159 |
}) |
| 1160 |
|
| 1161 |
(define_expand "sibcall_epilogue" |
| 1162 |
[(return)] |
| 1163 |
"" |
| 1164 |
{ |
| 1165 |
pru_expand_epilogue (true); |
| 1166 |
DONE; |
| 1167 |
}) |
| 1168 |
|
| 1169 |
(define_insn "return" |
| 1170 |
[(simple_return)] |
| 1171 |
"pru_can_use_return_insn ()" |
| 1172 |
"ret") |
| 1173 |
|
| 1174 |
(define_insn "simple_return" |
| 1175 |
[(simple_return)] |
| 1176 |
"" |
| 1177 |
"ret") |
| 1178 |
|
| 1179 |
;; Block any insns from being moved before this point, since the |
| 1180 |
;; profiling call to mcount can use various registers that aren't |
| 1181 |
;; saved or used to pass arguments. |
| 1182 |
|
| 1183 |
(define_insn "blockage" |
| 1184 |
[(unspec_volatile [(const_int 0)] UNSPECV_BLOCKAGE)] |
| 1185 |
"" |
| 1186 |
"" |
| 1187 |
[(set_attr "type" "unknown") |
| 1188 |
(set_attr "length" "0")]) |
| 1189 |
|
| 1190 |
;; Jumps and calls |
| 1191 |
|
| 1192 |
(define_insn "indirect_jump" |
| 1193 |
[(set (pc) (match_operand:SI 0 "register_operand" "r"))] |
| 1194 |
"" |
| 1195 |
"jmp\\t%0" |
| 1196 |
[(set_attr "type" "control")]) |
| 1197 |
|
| 1198 |
(define_insn "jump" |
| 1199 |
[(set (pc) |
| 1200 |
(label_ref (match_operand 0)))] |
| 1201 |
"" |
| 1202 |
"jmp\\t%%label(%l0)" |
| 1203 |
[(set_attr "type" "control")]) |
| 1204 |
|
| 1205 |
|
| 1206 |
(define_expand "call" |
| 1207 |
[(parallel [(call (match_operand 0 "") |
| 1208 |
(match_operand 1 "")) |
| 1209 |
(clobber (reg:HI RA_REGNUM))])] |
| 1210 |
"" |
| 1211 |
"") |
| 1212 |
|
| 1213 |
(define_expand "call_value" |
| 1214 |
[(parallel [(set (match_operand 0 "") |
| 1215 |
(call (match_operand 1 "") |
| 1216 |
(match_operand 2 ""))) |
| 1217 |
(clobber (reg:HI RA_REGNUM))])] |
| 1218 |
"" |
| 1219 |
"") |
| 1220 |
|
| 1221 |
(define_insn "*call" |
| 1222 |
[(call (mem:SI (match_operand:SI 0 "call_operand" "i,r")) |
| 1223 |
(match_operand 1)) |
| 1224 |
(clobber (reg:HI RA_REGNUM))] |
| 1225 |
"" |
| 1226 |
"@ |
| 1227 |
call\\t%%label(%0) |
| 1228 |
call\\t%0" |
| 1229 |
[(set_attr "type" "control")]) |
| 1230 |
|
| 1231 |
(define_insn "*call_value" |
| 1232 |
[(set (match_operand 0) |
| 1233 |
(call (mem:SI (match_operand:SI 1 "call_operand" "i,r")) |
| 1234 |
(match_operand 2))) |
| 1235 |
(clobber (reg:HI RA_REGNUM))] |
| 1236 |
"" |
| 1237 |
"@ |
| 1238 |
call\\t%%label(%1) |
| 1239 |
call\\t%1" |
| 1240 |
[(set_attr "type" "control")]) |
| 1241 |
|
| 1242 |
(define_expand "sibcall" |
| 1243 |
[(parallel [(call (match_operand 0 "") |
| 1244 |
(match_operand 1 "")) |
| 1245 |
(return)])] |
| 1246 |
"" |
| 1247 |
"") |
| 1248 |
|
| 1249 |
(define_expand "sibcall_value" |
| 1250 |
[(parallel [(set (match_operand 0 "") |
| 1251 |
(call (match_operand 1 "") |
| 1252 |
(match_operand 2 ""))) |
| 1253 |
(return)])] |
| 1254 |
"" |
| 1255 |
"") |
| 1256 |
|
| 1257 |
(define_insn "*sibcall" |
| 1258 |
[(call (mem:SI (match_operand:SI 0 "call_operand" "i,Rsib")) |
| 1259 |
(match_operand 1)) |
| 1260 |
(return)] |
| 1261 |
"SIBLING_CALL_P (insn)" |
| 1262 |
"@ |
| 1263 |
jmp\\t%%label(%0) |
| 1264 |
jmp\\t%0" |
| 1265 |
[(set_attr "type" "control")]) |
| 1266 |
|
| 1267 |
(define_insn "*sibcall_value" |
| 1268 |
[(set (match_operand 0 "register_operand" "") |
| 1269 |
(call (mem:SI (match_operand:SI 1 "call_operand" "i,Rsib")) |
| 1270 |
(match_operand 2))) |
| 1271 |
(return)] |
| 1272 |
"SIBLING_CALL_P (insn)" |
| 1273 |
"@ |
| 1274 |
jmp\\t%%label(%1) |
| 1275 |
jmp\\t%1" |
| 1276 |
[(set_attr "type" "control")]) |
| 1277 |
|
| 1278 |
(define_insn "*tablejump" |
| 1279 |
[(set (pc) |
| 1280 |
(match_operand:SI 0 "register_operand" "r")) |
| 1281 |
(use (label_ref (match_operand 1)))] |
| 1282 |
"" |
| 1283 |
"jmp\\t%0" |
| 1284 |
[(set_attr "type" "control")]) |
| 1285 |
|
| 1286 |
;; Expand the cbranch pattern in order to assign different constraints for |
| 1287 |
;; signed and unsigned comparisons. |
| 1288 |
(define_expand "cbranch<mode>4" |
| 1289 |
[(set (pc) |
| 1290 |
(if_then_else |
| 1291 |
(match_operator 0 "ordered_comparison_operator" |
| 1292 |
[(match_operand:QISI 1 "register_operand") |
| 1293 |
(match_operand:QISI 2 "reg_or_const_int_operand")]) |
| 1294 |
(label_ref (match_operand 3 "")) |
| 1295 |
(pc)))] |
| 1296 |
"" |
| 1297 |
{ |
| 1298 |
/* Ensure our patterns will be able to handle the particular const_int. */ |
| 1299 |
if (CONST_INT_P (operands[2])) |
| 1300 |
{ |
| 1301 |
HOST_WIDE_INT ival = INTVAL (operands[2]); |
| 1302 |
|
| 1303 |
/* For signed comparisons, we cannot play games with the const_int's |
| 1304 |
sign. PRU patterns do not support negative integer constants. */ |
| 1305 |
if (pru_signed_cmp_operator (operands[0], VOIDmode) && !UBYTE_INT (ival)) |
| 1306 |
{ |
| 1307 |
if (can_create_pseudo_p ()) |
| 1308 |
operands[2] = force_reg (<MODE>mode, operands[2]); |
| 1309 |
else |
| 1310 |
FAIL; |
| 1311 |
} |
| 1312 |
|
| 1313 |
/* For unsigned comparisons, be prepared to handle the QI quirk. */ |
| 1314 |
if (pru_cmp_operator (operands[0], VOIDmode) |
| 1315 |
&& !const_ubyte_operand (operands[2], <MODE>mode)) |
| 1316 |
{ |
| 1317 |
if (can_create_pseudo_p ()) |
| 1318 |
operands[2] = force_reg (<MODE>mode, operands[2]); |
| 1319 |
else |
| 1320 |
FAIL; |
| 1321 |
} |
| 1322 |
} |
| 1323 |
}) |
| 1324 |
|
| 1325 |
(define_insn "cbranch<mode>4_unsigned" |
| 1326 |
[(set (pc) |
| 1327 |
(if_then_else |
| 1328 |
(match_operator 0 "pru_cmp_operator" |
| 1329 |
[(match_operand:QISI 1 "register_operand" "r") |
| 1330 |
(match_operand:QISI 2 "reg_or_ubyte_operand" "r<QISI:ubyte_constr>")]) |
| 1331 |
(label_ref (match_operand 3)) |
| 1332 |
(pc)))] |
| 1333 |
"" |
| 1334 |
{ |
| 1335 |
const bool is_near = (get_attr_length (insn) == 4); |
| 1336 |
|
| 1337 |
/* PRU comparisons reverse the operand order (OP2 cmp OP1), |
| 1338 |
so swap the condition. */ |
| 1339 |
if (is_near) |
| 1340 |
return "qb%P0\t%l3, %1, %u2"; |
| 1341 |
else |
| 1342 |
return "qb%Q0\t.+8, %1, %u2\;jmp\t%%label(%l3)"; |
| 1343 |
} |
| 1344 |
[(set_attr "type" "control") |
| 1345 |
(set (attr "length") |
| 1346 |
(if_then_else |
| 1347 |
(and (ge (minus (match_dup 3) (pc)) (const_int -2040)) |
| 1348 |
(le (minus (match_dup 3) (pc)) (const_int 2036))) |
| 1349 |
(const_int 4) |
| 1350 |
(const_int 8)))]) |
| 1351 |
|
| 1352 |
;; Unlike ALU operations, the const_int's sign here is important. So we |
| 1353 |
;; cannot use ubyte_constr. |
| 1354 |
;; |
| 1355 |
;; NOTE: The short branch check has no typo! We must be conservative and |
| 1356 |
;; take into account the worst case of having a signed comparison with a |
| 1357 |
;; "far taken branch" label, which amounts to 7 instructions. |
| 1358 |
(define_insn "cbranch<mode>4_signed" |
| 1359 |
[(set (pc) |
| 1360 |
(if_then_else |
| 1361 |
(match_operator 0 "pru_signed_cmp_operator" |
| 1362 |
[(match_operand:QISI 1 "register_operand" "r,r,r") |
| 1363 |
(match_operand:QISI 2 "reg_or_ubyte_operand" "r,Z,I")]) |
| 1364 |
(label_ref (match_operand 3)) |
| 1365 |
(pc)))] |
| 1366 |
"" |
| 1367 |
{ |
| 1368 |
const int length = (get_attr_length (insn)); |
| 1369 |
const bool is_near = (length == 20); |
| 1370 |
enum rtx_code code = GET_CODE (operands[0]); |
| 1371 |
|
| 1372 |
if (which_alternative == 0) |
| 1373 |
return pru_output_signed_cbranch (operands, is_near); |
| 1374 |
else if (which_alternative == 1 && (code == LT || code == GE)) |
| 1375 |
return pru_output_signed_cbranch_zeroop2 (operands, is_near); |
| 1376 |
else |
| 1377 |
return pru_output_signed_cbranch_ubyteop2 (operands, is_near); |
| 1378 |
} |
| 1379 |
[(set_attr "type" "control") |
| 1380 |
(set (attr "length") |
| 1381 |
(if_then_else |
| 1382 |
(and (ge (minus (match_dup 3) (pc)) (const_int -2020)) |
| 1383 |
(le (minus (match_dup 3) (pc)) (const_int 2016))) |
| 1384 |
(const_int 20) |
| 1385 |
(const_int 28)))]) |
| 1386 |
|
| 1387 |
(define_expand "cbranch<mode>4" |
| 1388 |
[(set (pc) |
| 1389 |
(if_then_else (match_operator 0 "pru_fp_comparison_operator" |
| 1390 |
[(match_operand:SFDF 1 "register_operand") |
| 1391 |
(match_operand:SFDF 2 "register_operand")]) |
| 1392 |
(label_ref (match_operand 3 "")) |
| 1393 |
(pc)))] |
| 1394 |
"" |
| 1395 |
{ |
| 1396 |
rtx t = pru_expand_fp_compare (operands[0], VOIDmode); |
| 1397 |
operands[0] = t; |
| 1398 |
operands[1] = XEXP (t, 0); |
| 1399 |
operands[2] = XEXP (t, 1); |
| 1400 |
}) |
| 1401 |
|
| 1402 |
;; Expand the cbranchdi pattern in order to avoid the default |
| 1403 |
;; expansion into word_mode operations, which is not efficient for PRU. |
| 1404 |
;; In pseudocode this expansion outputs: |
| 1405 |
;; |
| 1406 |
;; /* EQ */ |
| 1407 |
;; if (OP1_hi {reverse_condition (cmp)} OP2_hi) |
| 1408 |
;; goto fallthrough |
| 1409 |
;; if (OP1_lo {cmp} OP2_lo) |
| 1410 |
;; goto label3 |
| 1411 |
;; fallthrough: |
| 1412 |
;; |
| 1413 |
;; /* NE */ |
| 1414 |
;; if (OP1_hi {cmp} OP2_hi) |
| 1415 |
;; goto label3 |
| 1416 |
;; if (OP1_lo {cmp} OP2_lo) |
| 1417 |
;; goto label3 |
| 1418 |
;; |
| 1419 |
;; The LT comparisons with zero take one machine instruction to simply |
| 1420 |
;; check the sign bit. The GT comparisons with zero take two - one |
| 1421 |
;; to check the sign bit, and one to check for zero. Hence arrange |
| 1422 |
;; the expand such that only LT comparison is used for OP1_HI, because |
| 1423 |
;; OP2_HI is const0_rtx. |
| 1424 |
;; |
| 1425 |
;; The LTU comparisons with zero will be removed by subsequent passes. |
| 1426 |
;; |
| 1427 |
;; /* LT/LTU/LE/LEU */ |
| 1428 |
;; if (OP1_hi {noteq_condition (cmp)} OP2_hi) |
| 1429 |
;; goto label3 /* DI comparison obviously true. */ |
| 1430 |
;; if (OP1_hi != OP2_hi) |
| 1431 |
;; goto fallthrough /* DI comparison obviously not true. */ |
| 1432 |
;; if (OP1_lo {unsigned_condition (cmp)} OP2_lo) |
| 1433 |
;; goto label3 /* Comparison was deferred to lo parts. */ |
| 1434 |
;; fallthrough: |
| 1435 |
|
| 1436 |
;; /* GT/GTU/GE/GEU */ |
| 1437 |
;; if (OP1_hi {reverse_condition (noteq_condition (cmp))} OP2_hi) |
| 1438 |
;; goto fallthrough /* DI comparison obviously not true. */ |
| 1439 |
;; if (OP1_hi != OP2_hi) |
| 1440 |
;; goto label3 /* DI comparison obviously true. */ |
| 1441 |
;; if (OP1_lo {unsigned_condition (cmp)} OP2_lo) |
| 1442 |
;; goto label3 /* Comparison was deferred to lo parts. */ |
| 1443 |
;; fallthrough: |
| 1444 |
|
| 1445 |
(define_expand "cbranchdi4" |
| 1446 |
[(set (pc) |
| 1447 |
(if_then_else |
| 1448 |
(match_operator 0 "ordered_comparison_operator" |
| 1449 |
[(match_operand:DI 1 "register_operand") |
| 1450 |
(match_operand:DI 2 "reg_or_ubyte_operand")]) |
| 1451 |
(label_ref (match_operand 3 "")) |
| 1452 |
(pc)))] |
| 1453 |
"" |
| 1454 |
{ |
| 1455 |
const enum rtx_code code = GET_CODE (operands[0]); |
| 1456 |
rtx label3 = operands[3]; |
| 1457 |
rtx op1_lo = simplify_gen_subreg (SImode, operands[1], DImode, 0); |
| 1458 |
rtx op1_hi = simplify_gen_subreg (SImode, operands[1], DImode, 4); |
| 1459 |
rtx op2_lo = simplify_gen_subreg (SImode, operands[2], DImode, 0); |
| 1460 |
rtx op2_hi = simplify_gen_subreg (SImode, operands[2], DImode, 4); |
| 1461 |
rtx j; |
| 1462 |
|
| 1463 |
if (code == EQ) |
| 1464 |
{ |
| 1465 |
rtx label_fallthrough = gen_label_rtx (); |
| 1466 |
rtx label_fallthrough_ref = gen_rtx_LABEL_REF (Pmode, label_fallthrough); |
| 1467 |
|
| 1468 |
rtx cond_hi = gen_rtx_fmt_ee (NE, VOIDmode, op1_hi, op2_hi); |
| 1469 |
rtx check_hi = gen_rtx_IF_THEN_ELSE (VOIDmode, cond_hi, |
| 1470 |
label_fallthrough_ref, pc_rtx); |
| 1471 |
j = emit_jump_insn (gen_rtx_SET (pc_rtx, check_hi)); |
| 1472 |
JUMP_LABEL (j) = label_fallthrough; |
| 1473 |
LABEL_NUSES (label_fallthrough)++; |
| 1474 |
|
| 1475 |
rtx label3_ref = gen_rtx_LABEL_REF (Pmode, label3); |
| 1476 |
rtx cond_lo = gen_rtx_fmt_ee (EQ, VOIDmode, op1_lo, op2_lo); |
| 1477 |
rtx check_lo = gen_rtx_IF_THEN_ELSE (VOIDmode, cond_lo, |
| 1478 |
label3_ref, pc_rtx); |
| 1479 |
j = emit_jump_insn (gen_rtx_SET (pc_rtx, check_lo)); |
| 1480 |
JUMP_LABEL (j) = label3; |
| 1481 |
LABEL_NUSES (label3)++; |
| 1482 |
|
| 1483 |
emit_label (label_fallthrough); |
| 1484 |
DONE; |
| 1485 |
} |
| 1486 |
if (code == NE) |
| 1487 |
{ |
| 1488 |
rtx label3_ref1 = gen_rtx_LABEL_REF (Pmode, label3); |
| 1489 |
rtx cond_hi = gen_rtx_fmt_ee (NE, VOIDmode, op1_hi, op2_hi); |
| 1490 |
rtx check_hi = gen_rtx_IF_THEN_ELSE (VOIDmode, cond_hi, |
| 1491 |
label3_ref1, pc_rtx); |
| 1492 |
j = emit_jump_insn (gen_rtx_SET (pc_rtx, check_hi)); |
| 1493 |
JUMP_LABEL (j) = label3; |
| 1494 |
LABEL_NUSES (label3)++; |
| 1495 |
|
| 1496 |
rtx label3_ref2 = gen_rtx_LABEL_REF (Pmode, label3); |
| 1497 |
rtx cond_lo = gen_rtx_fmt_ee (NE, VOIDmode, op1_lo, op2_lo); |
| 1498 |
rtx check_lo = gen_rtx_IF_THEN_ELSE (VOIDmode, cond_lo, |
| 1499 |
label3_ref2, pc_rtx); |
| 1500 |
j = emit_jump_insn (gen_rtx_SET (pc_rtx, check_lo)); |
| 1501 |
JUMP_LABEL (j) = label3; |
| 1502 |
LABEL_NUSES (label3)++; |
| 1503 |
|
| 1504 |
DONE; |
| 1505 |
} |
| 1506 |
|
| 1507 |
if (code == LT || code == LTU || code == LE || code == LEU) |
| 1508 |
{ |
| 1509 |
/* Check for "DI comparison obviously true". */ |
| 1510 |
rtx label3_ref1 = gen_rtx_LABEL_REF (Pmode, label3); |
| 1511 |
rtx cond_hi = gen_rtx_fmt_ee (pru_noteq_condition (code), |
| 1512 |
VOIDmode, op1_hi, op2_hi); |
| 1513 |
rtx check_hi = gen_rtx_IF_THEN_ELSE (VOIDmode, cond_hi, |
| 1514 |
label3_ref1, pc_rtx); |
| 1515 |
j = emit_jump_insn (gen_rtx_SET (pc_rtx, check_hi)); |
| 1516 |
JUMP_LABEL (j) = label3; |
| 1517 |
LABEL_NUSES (label3)++; |
| 1518 |
|
| 1519 |
/* Check for "DI comparison obviously not true". */ |
| 1520 |
rtx label_fallthrough = gen_label_rtx (); |
| 1521 |
rtx label_fallthrough_ref = gen_rtx_LABEL_REF (Pmode, label_fallthrough); |
| 1522 |
rtx cond_hine = gen_rtx_fmt_ee (NE, VOIDmode, op1_hi, op2_hi); |
| 1523 |
rtx check_hine = gen_rtx_IF_THEN_ELSE (VOIDmode, cond_hine, |
| 1524 |
label_fallthrough_ref, pc_rtx); |
| 1525 |
j = emit_jump_insn (gen_rtx_SET (pc_rtx, check_hine)); |
| 1526 |
JUMP_LABEL (j) = label_fallthrough; |
| 1527 |
LABEL_NUSES (label_fallthrough)++; |
| 1528 |
|
| 1529 |
/* Comparison deferred to the lo parts. */ |
| 1530 |
rtx label3_ref2 = gen_rtx_LABEL_REF (Pmode, label3); |
| 1531 |
rtx cond_lo = gen_rtx_fmt_ee (unsigned_condition (code), |
| 1532 |
VOIDmode, op1_lo, op2_lo); |
| 1533 |
rtx check_lo = gen_rtx_IF_THEN_ELSE (VOIDmode, cond_lo, |
| 1534 |
label3_ref2, pc_rtx); |
| 1535 |
j = emit_jump_insn (gen_rtx_SET (pc_rtx, check_lo)); |
| 1536 |
JUMP_LABEL (j) = label3; |
| 1537 |
LABEL_NUSES (label3)++; |
| 1538 |
|
| 1539 |
emit_label (label_fallthrough); |
| 1540 |
DONE; |
| 1541 |
} |
| 1542 |
|
| 1543 |
if (code == GT || code == GTU || code == GE || code == GEU) |
| 1544 |
{ |
| 1545 |
/* Check for "DI comparison obviously not true". */ |
| 1546 |
const enum rtx_code reversed_code = reverse_condition (code); |
| 1547 |
rtx label_fallthrough = gen_label_rtx (); |
| 1548 |
rtx label_fallthrough_ref = gen_rtx_LABEL_REF (Pmode, label_fallthrough); |
| 1549 |
rtx cond_hi = gen_rtx_fmt_ee (pru_noteq_condition (reversed_code), |
| 1550 |
VOIDmode, op1_hi, op2_hi); |
| 1551 |
rtx check_hi = gen_rtx_IF_THEN_ELSE (VOIDmode, cond_hi, |
| 1552 |
label_fallthrough_ref, pc_rtx); |
| 1553 |
j = emit_jump_insn (gen_rtx_SET (pc_rtx, check_hi)); |
| 1554 |
JUMP_LABEL (j) = label_fallthrough; |
| 1555 |
LABEL_NUSES (label_fallthrough)++; |
| 1556 |
|
| 1557 |
/* Check for "DI comparison obviously true". */ |
| 1558 |
rtx label3_ref1 = gen_rtx_LABEL_REF (Pmode, label3); |
| 1559 |
rtx cond_hine = gen_rtx_fmt_ee (NE, VOIDmode, op1_hi, op2_hi); |
| 1560 |
rtx check_hine = gen_rtx_IF_THEN_ELSE (VOIDmode, cond_hine, |
| 1561 |
label3_ref1, pc_rtx); |
| 1562 |
j = emit_jump_insn (gen_rtx_SET (pc_rtx, check_hine)); |
| 1563 |
JUMP_LABEL (j) = label3; |
| 1564 |
LABEL_NUSES (label3)++; |
| 1565 |
|
| 1566 |
/* Comparison deferred to the lo parts. */ |
| 1567 |
rtx label3_ref2 = gen_rtx_LABEL_REF (Pmode, label3); |
| 1568 |
rtx cond_lo = gen_rtx_fmt_ee (unsigned_condition (code), |
| 1569 |
VOIDmode, op1_lo, op2_lo); |
| 1570 |
rtx check_lo = gen_rtx_IF_THEN_ELSE (VOIDmode, cond_lo, |
| 1571 |
label3_ref2, pc_rtx); |
| 1572 |
j = emit_jump_insn (gen_rtx_SET (pc_rtx, check_lo)); |
| 1573 |
JUMP_LABEL (j) = label3; |
| 1574 |
LABEL_NUSES (label3)++; |
| 1575 |
|
| 1576 |
emit_label (label_fallthrough); |
| 1577 |
DONE; |
| 1578 |
} |
| 1579 |
gcc_unreachable (); |
| 1580 |
}) |
| 1581 |
|
| 1582 |
;; Emit efficient code for two specific cstore cases: |
| 1583 |
;; X == 0 |
| 1584 |
;; X != 0 |
| 1585 |
;; |
| 1586 |
;; These can be efficiently compiled on the PRU using the umin |
| 1587 |
;; instruction. |
| 1588 |
;; |
| 1589 |
;; This expansion does not handle "X > 0 unsigned" and "X >= 1 unsigned" |
| 1590 |
;; because it is assumed that those would have been replaced with the |
| 1591 |
;; canonical "X != 0". |
| 1592 |
(define_expand "cstore<mode>4" |
| 1593 |
[(set (match_operand:QISI 0 "register_operand") |
| 1594 |
(match_operator:QISI 1 "pru_cstore_comparison_operator" |
| 1595 |
[(match_operand:QISI 2 "register_operand") |
| 1596 |
(match_operand:QISI 3 "const_0_operand")]))] |
| 1597 |
"" |
| 1598 |
{ |
| 1599 |
const enum rtx_code op1code = GET_CODE (operands[1]); |
| 1600 |
|
| 1601 |
/* Crash if OP1 is GTU. It would mean that "X > 0 unsigned" |
| 1602 |
had not been canonicalized before calling this expansion. */ |
| 1603 |
gcc_assert (op1code == NE || op1code == EQ); |
| 1604 |
gcc_assert (CONST_INT_P (operands[3]) && INTVAL (operands[3]) == 0); |
| 1605 |
|
| 1606 |
if (op1code == NE) |
| 1607 |
{ |
| 1608 |
emit_insn (gen_umin<mode>3 (operands[0], operands[2], const1_rtx)); |
| 1609 |
DONE; |
| 1610 |
} |
| 1611 |
else if (op1code == EQ) |
| 1612 |
{ |
| 1613 |
rtx tmpval = gen_reg_rtx (<MODE>mode); |
| 1614 |
emit_insn (gen_umin<mode>3 (tmpval, operands[2], const1_rtx)); |
| 1615 |
emit_insn (gen_xor<mode>3 (operands[0], tmpval, const1_rtx)); |
| 1616 |
DONE; |
| 1617 |
} |
| 1618 |
|
| 1619 |
gcc_unreachable (); |
| 1620 |
}) |
| 1621 |
|
| 1622 |
(define_expand "cstoredi4" |
| 1623 |
[(set (match_operand:SI 0 "register_operand") |
| 1624 |
(match_operator:SI 1 "pru_cstore_comparison_operator" |
| 1625 |
[(match_operand:DI 2 "register_operand") |
| 1626 |
(match_operand:DI 3 "const_0_operand")]))] |
| 1627 |
"" |
| 1628 |
{ |
| 1629 |
/* Combining the two SImode suboperands with IOR works only for |
| 1630 |
the currently supported set of cstoresi3 operations. */ |
| 1631 |
const enum rtx_code op1code = GET_CODE (operands[1]); |
| 1632 |
gcc_assert (op1code == NE || op1code == EQ); |
| 1633 |
gcc_assert (CONST_INT_P (operands[3]) && INTVAL (operands[3]) == 0); |
| 1634 |
|
| 1635 |
rtx tmpval = gen_reg_rtx (SImode); |
| 1636 |
rtx src_lo = simplify_gen_subreg (SImode, operands[2], DImode, 0); |
| 1637 |
rtx src_hi = simplify_gen_subreg (SImode, operands[2], DImode, 4); |
| 1638 |
emit_insn (gen_iorsi3 (tmpval, src_lo, src_hi)); |
| 1639 |
emit_insn (gen_cstoresi4 (operands[0], operands[1], tmpval, const0_rtx)); |
| 1640 |
|
| 1641 |
DONE; |
| 1642 |
}) |
| 1643 |
|
| 1644 |
; |
| 1645 |
; Bit test branch |
| 1646 |
|
| 1647 |
(define_code_iterator BIT_TEST [eq ne]) |
| 1648 |
(define_code_attr qbbx_op [(eq "qbbc") (ne "qbbs")]) |
| 1649 |
(define_code_attr qbbx_negop [(eq "qbbs") (ne "qbbc")]) |
| 1650 |
|
| 1651 |
(define_insn "cbranch_qbbx_<BIT_TEST:code><EQS0:mode><EQS1:mode><EQD:mode>4" |
| 1652 |
[(set (pc) |
| 1653 |
(if_then_else |
| 1654 |
(BIT_TEST (zero_extract:EQD |
| 1655 |
(match_operand:EQS0 0 "register_operand" "r") |
| 1656 |
(const_int 1) |
| 1657 |
(match_operand:EQS1 1 "reg_or_ubyte_operand" "r<EQS1:ubyte_constr>")) |
| 1658 |
(const_int 0)) |
| 1659 |
(label_ref (match_operand 2)) |
| 1660 |
(pc)))] |
| 1661 |
"" |
| 1662 |
{ |
| 1663 |
const int length = (get_attr_length (insn)); |
| 1664 |
const bool is_near = (length == 4); |
| 1665 |
if (is_near) |
| 1666 |
return "<BIT_TEST:qbbx_op>\\t%l2, %0, %u1"; |
| 1667 |
else |
| 1668 |
return "<BIT_TEST:qbbx_negop>\\t.+8, %0, %u1\;jmp\\t%%label(%l2)"; |
| 1669 |
} |
| 1670 |
[(set_attr "type" "control") |
| 1671 |
(set (attr "length") |
| 1672 |
(if_then_else |
| 1673 |
(and (ge (minus (match_dup 2) (pc)) (const_int -2048)) |
| 1674 |
(le (minus (match_dup 2) (pc)) (const_int 2044))) |
| 1675 |
(const_int 4) |
| 1676 |
(const_int 8)))]) |
| 1677 |
|
| 1678 |
;; Bit test conditional branch, but only for constant bit positions. |
| 1679 |
;; This restriction allows an efficient code for DImode operands. |
| 1680 |
;; |
| 1681 |
;; QImode is already handled by the pattern variant above. |
| 1682 |
(define_insn "@cbranch_qbbx_const_<BIT_TEST:code><HIDI:mode>" |
| 1683 |
[(set (pc) |
| 1684 |
(if_then_else |
| 1685 |
(BIT_TEST (zero_extract:HIDI |
| 1686 |
(match_operand:HIDI 0 "register_operand" "r") |
| 1687 |
(const_int 1) |
| 1688 |
(match_operand:VOID 1 "const_int_operand" "i")) |
| 1689 |
(const_int 0)) |
| 1690 |
(label_ref (match_operand 2)) |
| 1691 |
(pc)))] |
| 1692 |
"" |
| 1693 |
{ |
| 1694 |
const int length = (get_attr_length (insn)); |
| 1695 |
const bool is_near = (length == 4); |
| 1696 |
|
| 1697 |
if (<HIDI:MODE>mode == DImode && INTVAL (operands[1]) <= 31) |
| 1698 |
{ |
| 1699 |
if (is_near) |
| 1700 |
return "<BIT_TEST:qbbx_op>\\t%l2, %F0, %1"; |
| 1701 |
else |
| 1702 |
return "<BIT_TEST:qbbx_negop>\\t.+8, %F0, %1\;jmp\\t%%label(%l2)"; |
| 1703 |
} |
| 1704 |
else if (<HIDI:MODE>mode == DImode) |
| 1705 |
{ |
| 1706 |
if (is_near) |
| 1707 |
return "<BIT_TEST:qbbx_op>\\t%l2, %N0, %1 - 32"; |
| 1708 |
else |
| 1709 |
return "<BIT_TEST:qbbx_negop>\\t.+8, %N0, %1 - 32\;jmp\\t%%label(%l2)"; |
| 1710 |
} |
| 1711 |
else |
| 1712 |
{ |
| 1713 |
if (is_near) |
| 1714 |
return "<BIT_TEST:qbbx_op>\\t%l2, %0, %1"; |
| 1715 |
else |
| 1716 |
return "<BIT_TEST:qbbx_negop>\\t.+8, %0, %1\;jmp\\t%%label(%l2)"; |
| 1717 |
} |
| 1718 |
} |
| 1719 |
[(set_attr "type" "control") |
| 1720 |
(set (attr "length") |
| 1721 |
(if_then_else |
| 1722 |
(and (ge (minus (match_dup 2) (pc)) (const_int -2048)) |
| 1723 |
(le (minus (match_dup 2) (pc)) (const_int 2044))) |
| 1724 |
(const_int 4) |
| 1725 |
(const_int 8)))]) |
| 1726 |
|
| 1727 |
;; :::::::::::::::::::: |
| 1728 |
;; :: |
| 1729 |
;; :: Low Overhead Looping - idea "borrowed" from MEP |
| 1730 |
;; :: |
| 1731 |
;; :::::::::::::::::::: |
| 1732 |
|
| 1733 |
;; This insn is volatile because we'd like it to stay in its original |
| 1734 |
;; position, just before the loop header. If it stays there, we might |
| 1735 |
;; be able to convert it into a "loop" insn. |
| 1736 |
(define_insn "@doloop_begin_internal<mode>" |
| 1737 |
[(set (match_operand:HISI 0 "register_operand" "=r") |
| 1738 |
(unspec_volatile:HISI |
| 1739 |
[(match_operand:HISI 1 "reg_or_ubyte_operand" "rI") |
| 1740 |
(match_operand 2 "const_int_operand" "")] UNSPECV_LOOP_BEGIN))] |
| 1741 |
"" |
| 1742 |
{ |
| 1743 |
gcc_unreachable (); |
| 1744 |
}) |
| 1745 |
|
| 1746 |
(define_expand "doloop_begin" |
| 1747 |
[(use (match_operand 0 "register_operand")) |
| 1748 |
(use (match_operand 1 ""))] |
| 1749 |
"TARGET_OPT_LOOP" |
| 1750 |
{ |
| 1751 |
pru_emit_doloop (operands, 0); |
| 1752 |
DONE; |
| 1753 |
}) |
| 1754 |
|
| 1755 |
; Note: "JUMP_INSNs and CALL_INSNs are not allowed to have any output |
| 1756 |
; reloads;". Hence this insn must be prepared for a counter that is |
| 1757 |
; not a register. |
| 1758 |
(define_insn "@doloop_end_internal<mode>" |
| 1759 |
[(set (pc) |
| 1760 |
(if_then_else (ne (match_operand:HISI 0 "nonimmediate_operand" "+r,*m") |
| 1761 |
(const_int 1)) |
| 1762 |
(label_ref (match_operand 1)) |
| 1763 |
(pc))) |
| 1764 |
(set (match_dup 0) |
| 1765 |
(plus:HISI (match_dup 0) |
| 1766 |
(const_int -1))) |
| 1767 |
(unspec [(match_operand 2 "const_int_operand" "")] UNSPECV_LOOP_END) |
| 1768 |
(clobber (match_scratch:HISI 3 "=X,&r"))] |
| 1769 |
"" |
| 1770 |
{ |
| 1771 |
gcc_unreachable (); |
| 1772 |
} |
| 1773 |
;; Worst case length: |
| 1774 |
;; |
| 1775 |
;; lbbo op3_reg, op3_ptr 4' |
| 1776 |
;; sub <op3_reg>, 1 4 |
| 1777 |
;; qbeq .+8, <op3_reg>, 0 4 |
| 1778 |
;; jmp <op1> 4 |
| 1779 |
;; sbbo op3_reg, op3_ptr 4 |
| 1780 |
[(set (attr "length") |
| 1781 |
(if_then_else |
| 1782 |
(and (ge (minus (pc) (match_dup 1)) (const_int 0)) |
| 1783 |
(le (minus (pc) (match_dup 1)) (const_int 1020))) |
| 1784 |
(cond [(eq_attr "alternative" "0") (const_int 4)] |
| 1785 |
(const_int 12)) |
| 1786 |
(cond [(eq_attr "alternative" "0") (const_int 12)] |
| 1787 |
(const_int 20))))]) |
| 1788 |
|
| 1789 |
(define_expand "doloop_end" |
| 1790 |
[(use (match_operand 0 "nonimmediate_operand")) |
| 1791 |
(use (label_ref (match_operand 1 "")))] |
| 1792 |
"TARGET_OPT_LOOP" |
| 1793 |
{ |
| 1794 |
if (GET_CODE (operands[0]) == REG && GET_MODE (operands[0]) == QImode) |
| 1795 |
FAIL; |
| 1796 |
pru_emit_doloop (operands, 1); |
| 1797 |
DONE; |
| 1798 |
}) |
| 1799 |
|
| 1800 |
(define_insn "@pruloop<mode>" |
| 1801 |
[(set (reg:HISI LOOPCNTR_REGNUM) |
| 1802 |
(unspec:HISI [(match_operand:HISI 0 "reg_or_ubyte_operand" "rI") |
| 1803 |
(label_ref (match_operand 1))] |
| 1804 |
UNSPECV_LOOP_BEGIN))] |
| 1805 |
"" |
| 1806 |
"loop\\t%l1, %0") |
| 1807 |
|
| 1808 |
(define_insn "pruloop_end" |
| 1809 |
[(unspec [(const_int 0)] UNSPECV_LOOP_END)] |
| 1810 |
"" |
| 1811 |
"# loop end" |
| 1812 |
[(set_attr "length" "0")]) |
| 1813 |
|
| 1814 |
|
| 1815 |
;; Misc patterns |
| 1816 |
|
| 1817 |
(define_insn "delay_cycles_start" |
| 1818 |
[(unspec_volatile [(match_operand 0 "immediate_operand" "i")] |
| 1819 |
UNSPECV_DELAY_CYCLES_START)] |
| 1820 |
"" |
| 1821 |
"/* Begin %0 cycle delay. */" |
| 1822 |
[(set_attr "length" "0")]) |
| 1823 |
|
| 1824 |
(define_insn "delay_cycles_end" |
| 1825 |
[(unspec_volatile [(match_operand 0 "immediate_operand" "i")] |
| 1826 |
UNSPECV_DELAY_CYCLES_END)] |
| 1827 |
"" |
| 1828 |
"/* End %0 cycle delay. */" |
| 1829 |
[(set_attr "length" "0")]) |
| 1830 |
|
| 1831 |
|
| 1832 |
(define_insn "delay_cycles_2x_plus1_hi" |
| 1833 |
[(unspec_volatile [(match_operand:SI 0 "const_uhword_operand" "J")] |
| 1834 |
UNSPECV_DELAY_CYCLES_2X_HI) |
| 1835 |
(clobber (match_scratch:SI 1 "=&r"))] |
| 1836 |
"" |
| 1837 |
"ldi\\t%1, %0\;sub\\t%1, %1, 1\;qbne\\t.-4, %1, 0" |
| 1838 |
[(set_attr "length" "12")]) |
| 1839 |
|
| 1840 |
|
| 1841 |
; Do not use LDI32 here because we do not want |
| 1842 |
; to accidentally loose one instruction cycle. |
| 1843 |
(define_insn "delay_cycles_2x_plus2_si" |
| 1844 |
[(unspec_volatile [(match_operand:SI 0 "const_int_operand" "n")] |
| 1845 |
UNSPECV_DELAY_CYCLES_2X_SI) |
| 1846 |
(clobber (match_scratch:SI 1 "=&r"))] |
| 1847 |
"" |
| 1848 |
"ldi\\t%1.w0, %L0\;ldi\\t%1.w2, %H0\;sub\\t%1, %1, 1\;qbne\\t.-4, %1, 0" |
| 1849 |
[(set_attr "length" "16")]) |
| 1850 |
|
| 1851 |
(define_insn "delay_cycles_1" |
| 1852 |
[(unspec_volatile [(const_int 0) ] UNSPECV_DELAY_CYCLES_1)] |
| 1853 |
"" |
| 1854 |
"nop\\t# delay_cycles_1" |
| 1855 |
) |
| 1856 |
|
| 1857 |
|
| 1858 |
(define_insn "nop" |
| 1859 |
[(const_int 0)] |
| 1860 |
"" |
| 1861 |
"nop" |
| 1862 |
[(set_attr "type" "alu")]) |
| 1863 |
|
| 1864 |
(define_insn "nop_loop_guard" |
| 1865 |
[(const_int 0)] |
| 1866 |
"" |
| 1867 |
"nop\\t# Loop end guard" |
| 1868 |
[(set_attr "type" "alu")]) |
| 1869 |
|
| 1870 |
;; HALT instruction. |
| 1871 |
(define_insn "pru_halt" |
| 1872 |
[(unspec_volatile [(const_int 0)] UNSPECV_HALT)] |
| 1873 |
"" |
| 1874 |
"halt" |
| 1875 |
[(set_attr "type" "control")]) |
| 1876 |
|
| 1877 |
;; Count Leading Zeros implemented using LMBD. |
| 1878 |
;; |
| 1879 |
;; LMBD returns 32 if bit value is not present, for any kind of input MODE. |
| 1880 |
;; The LMBD's search result for a "1" bit is subtracted from the |
| 1881 |
;; mode bit size minus one, in order to get CLZ. |
| 1882 |
;; |
| 1883 |
;; Hence for SImode we get a defined value -1 for CLZ_DEFINED_VALUE_AT_ZERO. |
| 1884 |
;; |
| 1885 |
;; The QImode and HImode defined values for zero inputs end up to be |
| 1886 |
;; non-standard (-25 and -17). But this is considered acceptable in |
| 1887 |
;; order to keep the CLZ expansion to only two instructions. |
| 1888 |
(define_expand "clz<mode>2" |
| 1889 |
[(set (match_operand:QISI 0 "register_operand") |
| 1890 |
(clz:QISI (match_operand:QISI 1 "register_operand")))] |
| 1891 |
"" |
| 1892 |
{ |
| 1893 |
rtx dst = operands[0]; |
| 1894 |
rtx src = operands[1]; |
| 1895 |
rtx tmpval = gen_reg_rtx (<MODE>mode); |
| 1896 |
|
| 1897 |
emit_insn (gen_pru_lmbd (<MODE>mode, tmpval, src, const1_rtx)); |
| 1898 |
int msb_bitn = GET_MODE_BITSIZE (<MODE>mode) - 1; |
| 1899 |
emit_insn (gen_sub3_insn (dst, GEN_INT (msb_bitn), tmpval)); |
| 1900 |
DONE; |
| 1901 |
}) |
| 1902 |
|
| 1903 |
;; Left Most Bit Detect operation, which maps to a single instruction. |
| 1904 |
(define_expand "@pru_lmbd<mode>" |
| 1905 |
[(set (match_operand:QISI 0 "register_operand") |
| 1906 |
(unspec:QISI |
| 1907 |
[(match_operand:QISI 1 "register_operand") |
| 1908 |
(match_operand:QISI 2 "reg_or_ubyte_operand")] |
| 1909 |
UNSPEC_LMBD))] |
| 1910 |
"" |
| 1911 |
"") |