| 1 |
;; Generic for binary logicals across the supported integer modes |
| 2 |
(define_expand "<code><mode>3" |
| 3 |
[(set (match_operand:QHSI 0 "register_operand" "") |
| 4 |
(logicals:QHSI (match_operand:QHSI 1 "register_operand" "") |
| 5 |
(match_operand:QHSI 2 "h8300_src_operand" "")))] |
| 6 |
"" |
| 7 |
" |
| 8 |
{ |
| 9 |
enum machine_mode mode = GET_MODE (operands[0]); |
| 10 |
/* DImodes are not considered tieable, as a result operations involving |
| 11 |
subregs of DImode objects are considered expensive which can prevent |
| 12 |
CSE from doing obvious simplifications. |
| 13 |
|
| 14 |
We may ultimately change what is tieable, but this is an immediate |
| 15 |
workaround while we evaluate changes to tieable modes. |
| 16 |
|
| 17 |
The key in terms of what we want to handle is then the result of |
| 18 |
the operation is not a constant. */ |
| 19 |
if ((<CODE> == AND && operands[2] == CONSTM1_RTX (mode)) |
| 20 |
|| (<CODE> == IOR && operands[2] == CONST0_RTX (mode)) |
| 21 |
|| (<CODE> == XOR && operands[2] == CONST0_RTX (mode)) |
| 22 |
|| ((<CODE> == AND || <CODE> == IOR) && operands[1] == operands[2])) |
| 23 |
{ |
| 24 |
emit_move_insn (operands[0], operands[1]); |
| 25 |
DONE; |
| 26 |
} |
| 27 |
}") |
| 28 |
|
| 29 |
;; There's a ton of cleanup to do from here below. |
| 30 |
;; ---------------------------------------------------------------------- |
| 31 |
;; AND INSTRUCTIONS |
| 32 |
;; ---------------------------------------------------------------------- |
| 33 |
|
| 34 |
(define_insn_and_split "*andqi3_2" |
| 35 |
[(set (match_operand:QI 0 "bit_operand" "=rU,rQ,r") |
| 36 |
(and:QI (match_operand:QI 1 "bit_operand" "%0,0,WU") |
| 37 |
(match_operand:QI 2 "h8300_src_operand" "Y0,rQi,IP1>X")))] |
| 38 |
"TARGET_H8300SX" |
| 39 |
"#" |
| 40 |
"&& reload_completed" |
| 41 |
[(parallel [(set (match_dup 0) (and:QI (match_dup 1) (match_dup 2))) |
| 42 |
(clobber (reg:CC CC_REG))])]) |
| 43 |
|
| 44 |
(define_insn "*andqi3_2_clobber_flags" |
| 45 |
[(set (match_operand:QI 0 "bit_operand" "=rU,rQ,r") |
| 46 |
(and:QI (match_operand:QI 1 "bit_operand" "%0,0,WU") |
| 47 |
(match_operand:QI 2 "h8300_src_operand" "Y0,rQi,IP1>X"))) |
| 48 |
(clobber (reg:CC CC_REG))] |
| 49 |
"TARGET_H8300SX" |
| 50 |
"@ |
| 51 |
bclr\\t %W2,%R0 |
| 52 |
and %X2,%X0 |
| 53 |
bfld %2,%1,%R0" |
| 54 |
[(set_attr "length" "8,*,8") |
| 55 |
(set_attr "length_table" "*,logicb,*")]) |
| 56 |
|
| 57 |
(define_insn_and_split "andqi3_1" |
| 58 |
[(set (match_operand:QI 0 "bit_operand" "=rU,r") |
| 59 |
(and:QI (match_operand:QI 1 "bit_operand" "%0,0") |
| 60 |
(match_operand:QI 2 "h8300_src_operand" "Y0,rn")))] |
| 61 |
"register_operand (operands[0], QImode) |
| 62 |
|| single_zero_operand (operands[2], QImode)" |
| 63 |
"bclr %W2,%R0" |
| 64 |
"&& reload_completed && !single_zero_operand (operands[2], QImode)" |
| 65 |
[(parallel [(set (match_dup 0) (and:QI (match_dup 1) (match_dup 2))) |
| 66 |
(clobber (reg:CC CC_REG))])] |
| 67 |
"" |
| 68 |
[(set_attr "length" "8,2")]) |
| 69 |
|
| 70 |
|
| 71 |
(define_insn_and_split "*andor<mode>3" |
| 72 |
[(set (match_operand:QHSI 0 "register_operand" "=r") |
| 73 |
(ior:QHSI (and:QHSI (match_operand:QHSI 2 "register_operand" "r") |
| 74 |
(match_operand:QHSI 3 "single_one_operand" "n")) |
| 75 |
(match_operand:QHSI 1 "register_operand" "0")))] |
| 76 |
"(<MODE>mode == QImode |
| 77 |
|| <MODE>mode == HImode |
| 78 |
|| (<MODE>mode == SImode |
| 79 |
&& (INTVAL (operands[3]) & 0xffff) != 0))" |
| 80 |
"#" |
| 81 |
"&& reload_completed" |
| 82 |
[(parallel [(set (match_dup 0) (ior:QHSI (and:QHSI (match_dup 2) |
| 83 |
(match_dup 3)) |
| 84 |
(match_dup 1))) |
| 85 |
(clobber (reg:CC CC_REG))])]) |
| 86 |
|
| 87 |
(define_insn "*andor<mode>3_clobber_flags" |
| 88 |
[(set (match_operand:QHSI 0 "register_operand" "=r") |
| 89 |
(ior:QHSI (and:QHSI (match_operand:QHSI 2 "register_operand" "r") |
| 90 |
(match_operand:QHSI 3 "single_one_operand" "n")) |
| 91 |
(match_operand:QHSI 1 "register_operand" "0"))) |
| 92 |
(clobber (reg:CC CC_REG))] |
| 93 |
"(<MODE>mode == QImode |
| 94 |
|| <MODE>mode == HImode |
| 95 |
|| (<MODE>mode == SImode |
| 96 |
&& (INTVAL (operands[3]) & 0xffff) != 0))" |
| 97 |
{ |
| 98 |
if (<MODE>mode == QImode) |
| 99 |
return "bld\\t%V3,%X2\;bor\\t%V3,%X0\;bst\\t%V3,%X0"; |
| 100 |
|
| 101 |
if (<MODE>mode == HImode) |
| 102 |
{ |
| 103 |
operands[3] = GEN_INT (INTVAL (operands[3]) & 0xffff); |
| 104 |
if (INTVAL (operands[3]) > 128) |
| 105 |
{ |
| 106 |
operands[3] = GEN_INT (INTVAL (operands[3]) >> 8); |
| 107 |
return "bld\\t%V3,%t2\;bor\\t%V3,%t0\;bst\\t%V3,%t0"; |
| 108 |
} |
| 109 |
return "bld\\t%V3,%s2\;bor\\t%V3,%s0\;bst\\t%V3,%s0"; |
| 110 |
} |
| 111 |
|
| 112 |
if (<MODE>mode == SImode) |
| 113 |
{ |
| 114 |
operands[3] = GEN_INT (INTVAL (operands[3]) & 0xffff); |
| 115 |
if (INTVAL (operands[3]) > 128) |
| 116 |
{ |
| 117 |
operands[3] = GEN_INT (INTVAL (operands[3]) >> 8); |
| 118 |
return "bld\\t%V3,%x2\;bor\\t%V3,%x0\;bst\\t%V3,%x0"; |
| 119 |
} |
| 120 |
return "bld\\t%V3,%w2\;bor\\t%V3,%w0\;bst\\t%V3,%w0"; |
| 121 |
} |
| 122 |
|
| 123 |
gcc_unreachable (); |
| 124 |
|
| 125 |
} |
| 126 |
[(set_attr "length" "6")]) |
| 127 |
|
| 128 |
(define_insn_and_split "*andorsi3_shift_8" |
| 129 |
[(set (match_operand:SI 0 "register_operand" "=r") |
| 130 |
(ior:SI (and:SI (ashift:SI (match_operand:SI 2 "register_operand" "r") |
| 131 |
(const_int 8)) |
| 132 |
(const_int 65280)) |
| 133 |
(match_operand:SI 1 "register_operand" "0")))] |
| 134 |
"" |
| 135 |
"#" |
| 136 |
"&& reload_completed" |
| 137 |
[(parallel [(set (match_dup 0) (ior:SI (and:SI (ashift:SI (match_dup 2) |
| 138 |
(const_int 8)) |
| 139 |
(const_int 65280)) |
| 140 |
(match_dup 1))) |
| 141 |
(clobber (reg:CC CC_REG))])]) |
| 142 |
|
| 143 |
(define_insn "*andorsi3_shift_8_clobber_flags" |
| 144 |
[(set (match_operand:SI 0 "register_operand" "=r") |
| 145 |
(ior:SI (and:SI (ashift:SI (match_operand:SI 2 "register_operand" "r") |
| 146 |
(const_int 8)) |
| 147 |
(const_int 65280)) |
| 148 |
(match_operand:SI 1 "register_operand" "0"))) |
| 149 |
(clobber (reg:CC CC_REG))] |
| 150 |
"" |
| 151 |
"or.b\\t%w2,%x0" |
| 152 |
[(set_attr "length" "2")]) |
| 153 |
|
| 154 |
;; ---------------------------------------------------------------------- |
| 155 |
;; OR/XOR INSTRUCTIONS |
| 156 |
;; ---------------------------------------------------------------------- |
| 157 |
|
| 158 |
(define_insn_and_split "<code>qi3_1" |
| 159 |
[(set (match_operand:QI 0 "bit_operand" "=rU,rQ") |
| 160 |
(ors:QI (match_operand:QI 1 "bit_operand" "%0,0") |
| 161 |
(match_operand:QI 2 "h8300_src_operand" "Y2,rQi")))] |
| 162 |
"TARGET_H8300SX || register_operand (operands[0], QImode) |
| 163 |
|| single_one_operand (operands[2], QImode)" |
| 164 |
{ return <CODE> == IOR ? "bset\\t%V2,%R0" : "bnot\\t%V2,%R0"; } |
| 165 |
"&& reload_completed && !single_one_operand (operands[2], QImode)" |
| 166 |
[(parallel [(set (match_dup 0) (ors:QI (match_dup 1) (match_dup 2))) |
| 167 |
(clobber (reg:CC CC_REG))])] |
| 168 |
"" |
| 169 |
[(set_attr "length" "8")]) |
| 170 |
|
| 171 |
(define_insn "*<code>qi3_1<cczn>" |
| 172 |
[(set (match_operand:QI 0 "bit_operand" "=rQ") |
| 173 |
(ors:QI (match_operand:QI 1 "bit_operand" "%0") |
| 174 |
(match_operand:QI 2 "h8300_src_operand" "rQi"))) |
| 175 |
(clobber (reg:CC CC_REG))] |
| 176 |
"TARGET_H8300SX" |
| 177 |
{ return <CODE> == IOR ? "or\\t%X2,%X0" : "xor\\t%X2,%X0"; } |
| 178 |
[(set_attr "length" "*") |
| 179 |
(set_attr "length_table" "logicb")]) |
| 180 |
|
| 181 |
(define_insn "*<code>qi3_1<cczn>" |
| 182 |
[(set (match_operand:QI 0 "register_operand" "=r") |
| 183 |
(ors:QI (match_operand:QI 1 "register_operand" "%0") |
| 184 |
(match_operand:QI 2 "h8300_src_operand" "ri"))) |
| 185 |
(clobber (reg:CC CC_REG))] |
| 186 |
"TARGET_H8300SX" |
| 187 |
{ return <CODE> == IOR ? "or\\t%X2,%X0" : "xor\\t%X2,%X0"; } |
| 188 |
[(set_attr "length" "*") |
| 189 |
(set_attr "length_table" "logicb")]) |
| 190 |
|
| 191 |
(define_insn "*<code>qi3_1<cczn>" |
| 192 |
[(set (match_operand:QI 0 "register_operand" "=r") |
| 193 |
(logicals:QI (match_operand:QI 1 "register_operand" "%0") |
| 194 |
(match_operand:QI 2 "h8300_src_operand" "rn"))) |
| 195 |
(clobber (reg:CC CC_REG))] |
| 196 |
"" |
| 197 |
{ |
| 198 |
if (<CODE> == IOR) |
| 199 |
return "or\\t%X2,%X0"; |
| 200 |
else if (<CODE> == XOR) |
| 201 |
return "xor\\t%X2,%X0"; |
| 202 |
else if (<CODE> == AND) |
| 203 |
return "and\\t%X2,%X0"; |
| 204 |
gcc_unreachable (); |
| 205 |
} |
| 206 |
[(set_attr "length" "2")]) |
| 207 |
|
| 208 |
;; ---------------------------------------------------------------------- |
| 209 |
;; {AND,IOR,XOR}{HI3,SI3} PATTERNS |
| 210 |
;; ---------------------------------------------------------------------- |
| 211 |
|
| 212 |
(define_insn_and_split "*logical<mode>3" |
| 213 |
[(set (match_operand:QHSI 0 "h8300_dst_operand" "=rQ") |
| 214 |
(logicals:QHSI |
| 215 |
(match_operand:QHSI 1 "h8300_dst_operand" "%0") |
| 216 |
(match_operand:QHSI 2 "h8300_src_operand" "rQi")))] |
| 217 |
"h8300_operands_match_p (operands)" |
| 218 |
"#" |
| 219 |
"&& reload_completed" |
| 220 |
[(parallel [(set (match_dup 0) |
| 221 |
(logicals:QHSI (match_dup 1) (match_dup 2))) |
| 222 |
(clobber (reg:CC CC_REG))])]) |
| 223 |
|
| 224 |
(define_insn "*<code><mode>3<cczn>" |
| 225 |
[(set (match_operand:QHSI 0 "h8300_dst_operand" "=rQ") |
| 226 |
(logicals:QHSI |
| 227 |
(match_operand:QHSI 1 "h8300_dst_operand" "%0") |
| 228 |
(match_operand:QHSI 2 "h8300_src_operand" "rQi"))) |
| 229 |
(clobber (reg:CC CC_REG))] |
| 230 |
"h8300_operands_match_p (operands)" |
| 231 |
{ return output_logical_op (<MODE>mode, <CODE>, operands, insn); } |
| 232 |
[(set (attr "length") |
| 233 |
(symbol_ref "compute_logical_op_length (<MODE>mode, <CODE>, operands, insn)"))]) |
| 234 |
|
| 235 |
;; ---------------------------------------------------------------------- |
| 236 |
;; NOT INSTRUCTIONS |
| 237 |
;; ---------------------------------------------------------------------- |
| 238 |
|
| 239 |
(define_insn_and_split "one_cmpl<mode>2" |
| 240 |
[(set (match_operand:QHSI 0 "h8300_dst_operand" "=rQ") |
| 241 |
(not:QHSI (match_operand:QHSI 1 "h8300_dst_operand" "0")))] |
| 242 |
"" |
| 243 |
"#" |
| 244 |
"&& reload_completed" |
| 245 |
[(parallel [(set (match_dup 0) (not:QHSI (match_dup 1))) |
| 246 |
(clobber (reg:CC CC_REG))])]) |
| 247 |
|
| 248 |
(define_insn "one_cmpl<mode>2_<cczn>" |
| 249 |
[(set (match_operand:QHSI 0 "h8300_dst_operand" "=rQ") |
| 250 |
(not:QHSI (match_operand:QHSI 1 "h8300_dst_operand" "0"))) |
| 251 |
(clobber (reg:CC CC_REG))] |
| 252 |
"" |
| 253 |
{ |
| 254 |
if (<MODE>mode == E_QImode) |
| 255 |
return "not %X0"; |
| 256 |
if (<MODE>mode == E_HImode) |
| 257 |
return "not.w %T0"; |
| 258 |
if (<MODE>mode == E_SImode) |
| 259 |
return "not.l %S0"; |
| 260 |
gcc_unreachable (); |
| 261 |
} |
| 262 |
[(set_attr "length_table" "unary")]) |
| 263 |
|
| 264 |
;; The next four peephole2's will try to transform |
| 265 |
;; |
| 266 |
;; mov.b A,r0l (or mov.l A,er0) |
| 267 |
;; and.l #CST,er0 |
| 268 |
;; |
| 269 |
;; into |
| 270 |
;; |
| 271 |
;; sub.l er0 |
| 272 |
;; mov.b A,r0l |
| 273 |
;; and.b #CST,r0l (if CST is not 255) |
| 274 |
|
| 275 |
(define_peephole2 |
| 276 |
[(parallel [(set (match_operand:QI 0 "register_operand" "") |
| 277 |
(match_operand:QI 1 "general_operand" "")) |
| 278 |
(clobber (reg:CC CC_REG))]) |
| 279 |
(parallel [(set (match_operand:SI 2 "register_operand" "") |
| 280 |
(and:SI (match_dup 2) (const_int 255))) |
| 281 |
(clobber (reg:CC CC_REG))])] |
| 282 |
"!reg_overlap_mentioned_p (operands[2], operands[1]) |
| 283 |
&& REGNO (operands[0]) == REGNO (operands[2])" |
| 284 |
[(parallel [(set (match_dup 2) (const_int 0)) |
| 285 |
(clobber (reg:CC CC_REG))]) |
| 286 |
(parallel [(set (strict_low_part (match_dup 0)) (match_dup 1)) |
| 287 |
(clobber (reg:CC CC_REG))])]) |
| 288 |
|
| 289 |
(define_peephole2 |
| 290 |
[(parallel [(set (match_operand:SI 0 "register_operand" "") |
| 291 |
(match_operand:SI 1 "nonimmediate_operand" "")) |
| 292 |
(clobber (reg:CC CC_REG))]) |
| 293 |
(parallel [(set (match_dup 0) |
| 294 |
(and:SI (match_dup 0) (const_int 255))) |
| 295 |
(clobber (reg:CC CC_REG))])] |
| 296 |
"!reg_overlap_mentioned_p (operands[0], operands[1]) |
| 297 |
&& !(GET_CODE (operands[1]) == MEM && !offsettable_memref_p (operands[1])) |
| 298 |
&& !(GET_CODE (operands[1]) == MEM && MEM_VOLATILE_P (operands[1]))" |
| 299 |
[(parallel [(set (match_dup 0) (const_int 0)) |
| 300 |
(clobber (reg:CC CC_REG))]) |
| 301 |
(parallel [(set (strict_low_part (match_dup 2)) (match_dup 3)) |
| 302 |
(clobber (reg:CC CC_REG))])] |
| 303 |
{ |
| 304 |
operands[2] = gen_lowpart (QImode, operands[0]); |
| 305 |
operands[3] = gen_lowpart (QImode, operands[1]); |
| 306 |
}) |
| 307 |
|
| 308 |
(define_peephole2 |
| 309 |
[(parallel [(set (match_operand 0 "register_operand" "") |
| 310 |
(match_operand 1 "nonimmediate_operand" "")) |
| 311 |
(clobber (reg:CC CC_REG))]) |
| 312 |
(parallel [(set (match_operand:SI 2 "register_operand" "") |
| 313 |
(and:SI (match_dup 2) |
| 314 |
(match_operand:SI 3 "const_int_qi_operand" ""))) |
| 315 |
(clobber (reg:CC CC_REG))])] |
| 316 |
"(GET_MODE (operands[0]) == QImode |
| 317 |
|| GET_MODE (operands[0]) == HImode |
| 318 |
|| GET_MODE (operands[0]) == SImode) |
| 319 |
&& GET_MODE (operands[0]) == GET_MODE (operands[1]) |
| 320 |
&& REGNO (operands[0]) == REGNO (operands[2]) |
| 321 |
&& !reg_overlap_mentioned_p (operands[2], operands[1]) |
| 322 |
&& !(GET_MODE (operands[1]) != QImode |
| 323 |
&& GET_CODE (operands[1]) == MEM |
| 324 |
&& !offsettable_memref_p (operands[1])) |
| 325 |
&& !(GET_MODE (operands[1]) != QImode |
| 326 |
&& GET_CODE (operands[1]) == MEM |
| 327 |
&& MEM_VOLATILE_P (operands[1]))" |
| 328 |
[(parallel [(set (match_dup 2) (const_int 0)) |
| 329 |
(clobber (reg:CC CC_REG))]) |
| 330 |
(parallel [(set (strict_low_part (match_dup 4)) (match_dup 5)) |
| 331 |
(clobber (reg:CC CC_REG))]) |
| 332 |
(parallel [(set (match_dup 2) (and:SI (match_dup 2) (match_dup 6))) |
| 333 |
(clobber (reg:CC CC_REG))])] |
| 334 |
{ |
| 335 |
operands[4] = gen_lowpart (QImode, operands[0]); |
| 336 |
operands[5] = gen_lowpart (QImode, operands[1]); |
| 337 |
operands[6] = GEN_INT (~0xff | INTVAL (operands[3])); |
| 338 |
}) |
| 339 |
|
| 340 |
(define_peephole2 |
| 341 |
[(parallel [(set (match_operand:SI 0 "register_operand" "") |
| 342 |
(match_operand:SI 1 "register_operand" "")) |
| 343 |
(clobber (reg:CC CC_REG))]) |
| 344 |
(parallel [(set (match_dup 0) (and:SI (match_dup 0) (const_int 65280))) |
| 345 |
(clobber (reg:CC CC_REG))])] |
| 346 |
"!reg_overlap_mentioned_p (operands[0], operands[1])" |
| 347 |
[(parallel [(set (match_dup 0) (const_int 0)) |
| 348 |
(clobber (reg:CC CC_REG))]) |
| 349 |
(parallel [(set (zero_extract:SI (match_dup 0) (const_int 8) (const_int 8)) |
| 350 |
(lshiftrt:SI (match_dup 1) (const_int 8))) |
| 351 |
(clobber (reg:CC CC_REG))])]) |