@@ -32,6 +32,10 @@ def uimm1 : Operand<i32>, PatLeaf<(imm), [{
32
32
def uimm6 : Operand<i32>, PatLeaf<(imm), [{
33
33
return isUInt<6>(N->getZExtValue()); }]>;
34
34
35
+ // uimm7 - Generic immediate value.
36
+ def uimm7 : Operand<i32>, PatLeaf<(imm), [{
37
+ return isUInt<7>(N->getZExtValue()); }]>;
38
+
35
39
// simm7 - Generic immediate value.
36
40
def LO7 : SDNodeXForm<imm, [{
37
41
return CurDAG->getTargetConstant(SignExtend32(N->getSExtValue(), 7),
@@ -423,69 +427,27 @@ multiclass RRFm<string opcStr, bits<8>opc,
423
427
RRNDmrm<opcStr, opc, RC, Ty, RC, Ty, mOp, null_frag>,
424
428
RRNDmim<opcStr, opc, RC, Ty, RC, Ty, immOp, mOp, null_frag>;
425
429
426
- // Multiclass for RR type instructions
427
- // Used by sra, sla, sll, and similar instructions
428
- // The order of operands are "$sx, $sz, $sy"
429
-
430
+ // Generic RR multiclass for shift instructions with 2 arguments.
431
+ // e.g. SLL, SRL, SLAWSX, and etc.
432
+ let hasSideEffects = 0 in
430
433
multiclass RRIm<string opcStr, bits<8>opc,
431
434
RegisterClass RC, ValueType Ty,
432
- Operand immOp, Operand immOp2,
433
- SDPatternOperator OpNode=null_frag> {
434
- def rr : RR<
435
- opc, (outs RC:$sx), (ins RC:$sz, I32:$sy),
436
- !strconcat(opcStr, " $sx, $sz, $sy"),
437
- [(set Ty:$sx, (OpNode Ty:$sz, i32:$sy))]> {
438
- let cy = 1;
439
- let cz = 1;
440
- let hasSideEffects = 0;
441
- }
442
- def ri : RR<
443
- opc, (outs RC:$sx), (ins RC:$sz, immOp:$sy),
444
- !strconcat(opcStr, " $sx, $sz, $sy"),
445
- [(set Ty:$sx, (OpNode Ty:$sz, (i32 simm7:$sy)))]> {
446
- let cy = 0;
447
- let cz = 1;
448
- let hasSideEffects = 0;
449
- }
450
- def rm0 : RR<
451
- opc, (outs RC:$sx), (ins immOp2:$sz, I32:$sy),
452
- !strconcat(opcStr, " $sx, (${sz})0, $sy")> {
453
- let cy = 1;
454
- let cz = 0;
455
- let sz{6} = 1;
456
- let hasSideEffects = 0;
457
- }
458
- def rm1 : RR<
459
- opc, (outs RC:$sx), (ins immOp2:$sz, I32:$sy),
460
- !strconcat(opcStr, " $sx, (${sz})1, $sy")> {
461
- let cy = 1;
462
- let cz = 0;
463
- let hasSideEffects = 0;
464
- }
465
- def im0 : RR<
466
- opc, (outs RC:$sx), (ins immOp2:$sz, immOp:$sy),
467
- !strconcat(opcStr, " $sx, (${sz})0, $sy")> {
468
- let cy = 0;
469
- let cz = 0;
470
- let sz{6} = 1;
471
- let hasSideEffects = 0;
472
- }
473
- def im1 : RR<
474
- opc, (outs RC:$sx), (ins immOp2:$sz, immOp:$sy),
475
- !strconcat(opcStr, " $sx, (${sz})1, $sy")> {
476
- let cy = 0;
477
- let cz = 0;
478
- let hasSideEffects = 0;
479
- }
480
- def zi : RR<
481
- opc, (outs RC:$sx), (ins immOp:$sy),
482
- !strconcat(opcStr, " $sx, $sy"),
483
- [(set Ty:$sx, (OpNode 0, (i32 simm7:$sy)))]> {
484
- let cy = 0;
485
- let cz = 0;
486
- let sz = 0;
487
- let hasSideEffects = 0;
488
- }
435
+ SDPatternOperator OpNode = null_frag> {
436
+ def rr : RR<opc, (outs RC:$sx), (ins RC:$sz, I32:$sy),
437
+ !strconcat(opcStr, " $sx, $sz, $sy"),
438
+ [(set Ty:$sx, (OpNode Ty:$sz, i32:$sy))]>;
439
+ let cz = 0 in
440
+ def mr : RR<opc, (outs RC:$sx), (ins mimm:$sz, I32:$sy),
441
+ !strconcat(opcStr, " $sx, $sz, $sy"),
442
+ [(set Ty:$sx, (OpNode (Ty mimm:$sz), i32:$sy))]>;
443
+ let cy = 0 in
444
+ def ri : RR<opc, (outs RC:$sx), (ins RC:$sz, uimm7:$sy),
445
+ !strconcat(opcStr, " $sx, $sz, $sy"),
446
+ [(set Ty:$sx, (OpNode Ty:$sz, (i32 uimm7:$sy)))]>;
447
+ let cy = 0, cz = 0 in
448
+ def mi : RR<opc, (outs RC:$sx), (ins mimm:$sz, uimm7:$sy),
449
+ !strconcat(opcStr, " $sx, $sz, $sy"),
450
+ [(set Ty:$sx, (OpNode (Ty mimm:$sz), (i32 uimm7:$sy)))]>;
489
451
}
490
452
491
453
// Generic RR multiclass with an argument.
@@ -898,23 +860,32 @@ let cw = 1, cw2 = 0 in defm CMOVW : RRCMOVm<"cmov.w.${cfw}", 0x3B, I32, i32>;
898
860
let cw = 0, cw2 = 1 in defm CMOVD : RRCMOVm<"cmov.d.${cfw}", 0x3B, I64, f64>;
899
861
let cw = 1, cw2 = 1 in defm CMOVS : RRCMOVm<"cmov.s.${cfw}", 0x3B, F32, f32>;
900
862
901
- // 5.3.2.4 Shift Instructions
863
+ //-----------------------------------------------------------------------------
864
+ // Section 8.6 - Shift Operation Instructions
865
+ //-----------------------------------------------------------------------------
902
866
903
- let cx = 0 in
904
- defm SRAX : RRIm<"sra.l", 0x77, I64, i64, simm7, uimm6, sra>;
905
- let cx = 0 in
906
- defm SRA : RRIm<"sra.w.sx", 0x76, I32, i32, simm7, uimm6, sra>;
907
- let cx = 1 in
908
- defm SRAU : RRIm<"sra.w.zx", 0x76, I32, i32, simm7, uimm6>;
867
+ // Section 8.6.1 - SLL (Shift Left Logical)
868
+ defm SLL : RRIm<"sll", 0x65, I64, i64, shl>;
909
869
910
- let cx = 0 in
911
- defm SLL : RRIm<"sll", 0x65, I64, i64, simm7, uimm6, shl>;
912
- let cx = 0 in
913
- defm SLA : RRIm<"sla.w.sx", 0x66, I32, i32, simm7, uimm6, shl>;
914
- let cx = 1 in
915
- defm SLAU : RRIm<"sla.w.zx", 0x66, I32, i32, simm7, uimm6>;
916
- let cx = 0 in
917
- defm SRL : RRIm<"srl", 0x75, I64, i64, simm7, uimm6, srl>;
870
+ // Section 8.6.2 - SLD (Shift Left Double)
871
+
872
+ // Section 8.6.3 - SRL (Shift Right Logical)
873
+ defm SRL : RRIm<"srl", 0x75, I64, i64, srl>;
874
+
875
+ // Section 8.6.4 - SRD (Shift Right Double)
876
+
877
+ // Section 8.6.5 - SLA (Shift Left Arithmetic)
878
+ defm SLAWSX : RRIm<"sla.w.sx", 0x66, I32, i32, shl>;
879
+ let cx = 1 in defm SLAWZX : RRIm<"sla.w.zx", 0x66, I32, i32>;
880
+
881
+ // Section 8.6.6 - SLAX (Shift Left Arithmetic)
882
+
883
+ // Section 8.6.7 - SRA (Shift Right Arithmetic)
884
+ defm SRAWSX : RRIm<"sra.w.sx", 0x76, I32, i32, sra>;
885
+ let cx = 1 in defm SRAWZX : RRIm<"sra.w.zx", 0x76, I32, i32>;
886
+
887
+ // Section 8.6.8 - SRAX (Shift Right Arithmetic)
888
+ defm SRAL : RRIm<"sra.l", 0x77, I64, i64, sra>;
918
889
919
890
def : Pat<(i32 (srl i32:$src, (i32 simm7:$val))),
920
891
(EXTRACT_SUBREG (SRLri (ANDrm (INSERT_SUBREG (i64 (IMPLICIT_DEF)),
@@ -1113,27 +1084,27 @@ def : Pat<(f64 fpimm:$val),
1113
1084
1114
1085
// Cast to i1
1115
1086
def : Pat<(sext_inreg I32:$src, i1),
1116
- (SRAri (SLAri $src, 31), 31)>;
1087
+ (SRAWSXri (SLAWSXri $src, 31), 31)>;
1117
1088
def : Pat<(sext_inreg I64:$src, i1),
1118
- (SRAXri (SLLri $src, 63), 63)>;
1089
+ (SRALri (SLLri $src, 63), 63)>;
1119
1090
1120
1091
// Cast to i8
1121
1092
def : Pat<(sext_inreg I32:$src, i8),
1122
- (SRAri (SLAri $src, 24), 24)>;
1093
+ (SRAWSXri (SLAWSXri $src, 24), 24)>;
1123
1094
def : Pat<(sext_inreg I64:$src, i8),
1124
- (SRAXri (SLLri $src, 56), 56)>;
1095
+ (SRALri (SLLri $src, 56), 56)>;
1125
1096
def : Pat<(sext_inreg (i32 (trunc i64:$src)), i8),
1126
- (EXTRACT_SUBREG (SRAXri (SLLri $src, 56), 56), sub_i32)>;
1097
+ (EXTRACT_SUBREG (SRALri (SLLri $src, 56), 56), sub_i32)>;
1127
1098
def : Pat<(and (trunc i64:$src), 0xff),
1128
1099
(AND32rm (EXTRACT_SUBREG $src, sub_i32), !add(56, 64))>;
1129
1100
1130
1101
// Cast to i16
1131
1102
def : Pat<(sext_inreg I32:$src, i16),
1132
- (SRAri (SLAri $src, 16), 16)>;
1103
+ (SRAWSXri (SLAWSXri $src, 16), 16)>;
1133
1104
def : Pat<(sext_inreg I64:$src, i16),
1134
- (SRAXri (SLLri $src, 48), 48)>;
1105
+ (SRALri (SLLri $src, 48), 48)>;
1135
1106
def : Pat<(sext_inreg (i32 (trunc i64:$src)), i16),
1136
- (EXTRACT_SUBREG (SRAXri (SLLri $src, 48), 48), sub_i32)>;
1107
+ (EXTRACT_SUBREG (SRALri (SLLri $src, 48), 48), sub_i32)>;
1137
1108
def : Pat<(and (trunc i64:$src), 0xffff),
1138
1109
(AND32rm (EXTRACT_SUBREG $src, sub_i32), !add(48, 64))>;
1139
1110
@@ -1553,7 +1524,7 @@ def : Pat<(f64 (bitconvert i64:$src)), (COPY_TO_REGCLASS $src, I64)>;
1553
1524
def : Pat<(i64 (bitconvert f64:$src)), (COPY_TO_REGCLASS $src, I64)>;
1554
1525
1555
1526
def : Pat<(i32 (bitconvert f32:$op)),
1556
- (EXTRACT_SUBREG (SRAXri (INSERT_SUBREG (i64 (IMPLICIT_DEF)),
1527
+ (EXTRACT_SUBREG (SRALri (INSERT_SUBREG (i64 (IMPLICIT_DEF)),
1557
1528
$op, sub_f32), 32), sub_i32)>;
1558
1529
def : Pat<(f32 (bitconvert i32:$op)),
1559
1530
(EXTRACT_SUBREG (SLLri (INSERT_SUBREG (i64 (IMPLICIT_DEF)),
0 commit comments