[gem5-dev] Change in gem5/gem5[develop]: arch-power: Fix extended opcode based decoding

2021-05-02 Thread Boris Shingarov (Gerrit) via gem5-dev
Boris Shingarov has submitted this change. (  
https://gem5-review.googlesource.com/c/public/gem5/+/40885 )


Change subject: arch-power: Fix extended opcode based decoding
..

arch-power: Fix extended opcode based decoding

When multiple instructions share the same primary opcode,
the decoder can distinguish between them by looking at the
extended opcode field. However, the length and position of
the extended opcode field can slightly vary depending on
the instruction form.

This ensures that the correct extended opcode fields are
used for decoding such instructions.

Change-Id: I8207568ac975587377abba8a9b221ca3097b8488
Signed-off-by: Sandipan Das 
Reviewed-on: https://gem5-review.googlesource.com/c/public/gem5/+/40885
Reviewed-by: Boris Shingarov 
Maintainer: Gabe Black 
Tested-by: kokoro 
---
M src/arch/power/isa/decoder.isa
1 file changed, 170 insertions(+), 162 deletions(-)

Approvals:
  Boris Shingarov: Looks good to me, approved
  Gabe Black: Looks good to me, approved
  kokoro: Regressions pass



diff --git a/src/arch/power/isa/decoder.isa b/src/arch/power/isa/decoder.isa
index 1a8b375..8ffe007 100644
--- a/src/arch/power/isa/decoder.isa
+++ b/src/arch/power/isa/decoder.isa
@@ -97,7 +97,7 @@
 1: BranchNonPCRel::ba({{ NIA = targetAddr; }});
 }

-19: decode XO_XO {
+19: decode XL_XO {

 0: CondMoveOp::mcrf({{
 uint32_t crBfa = bits(CR, 31 - bfa*4, 28 - bfa*4);
@@ -181,12 +181,18 @@
 29: andis_({{ Ra = Rs & (uimm << 16); }}, true);
 }

-// Some instructions use bits 21 - 30, others 22 - 30. We have to use
-// the larger size to account for all opcodes. For those that use the
-// smaller value, the OE bit is bit 21. Therefore, we have two versions
-// of each instruction: 1 with OE set, the other without. For an
-// example see 'add' and 'addo'.
-31: decode XO_XO {
+// There are a large number of instructions that have the same primary
+// opcode (PO) of 31. In this case, the instructions are of different
+// forms. For every form, the XO fields may vary in position and width.
+// The X, XFL, XFX and XL form instructions use bits 21 - 30 and the
+// XO form instructions use bits 22 - 30 as extended opcode (XO). To
+// avoid conflicts, instructions of each form have to be defined under
+// separate decode blocks. However, only a single decode block can be
+// associated with a particular PO and it will recognize only one type
+// of XO field. A solution for associating decode blocks for the other
+// types of XO fields with the same PO is to have the other blocks as
+// nested default cases.
+31: decode X_XO {

 0: IntOp::cmp({{
 Xer xer = XER;
@@ -194,16 +200,6 @@
 CR = insertCRField(CR, BF, cr);
 }});

-8: IntSumOp::subfc({{ ~Ra }}, {{ Rb }}, {{ 1 }}, true);
-10: IntSumOp::addc({{ Ra }}, {{ Rb }}, computeCA = true);
-
-11: IntArithOp::mulhwu({{
-uint64_t prod = Ra_ud * Rb_ud;
-Rt = prod >> 32;
-}});
-
-19: IntOp::mfcr({{ Rt = CR; }});
-
 format LoadIndexOp {
 20: lwarx({{ Rt = Mem_sw; Rsv = 1; RsvLen = 4; RsvAddr = EA;  
}});

 23: lwzx({{ Rt = Mem; }});
@@ -228,35 +224,12 @@
 CR = insertCRField(CR, BF, cr);
 }});

-40: IntSumOp::subf({{ ~Ra }}, {{ Rb }}, {{ 1 }});
 55: LoadIndexUpdateOp::lwzux({{ Rt = Mem; }});
 60: IntLogicOp::andc({{ Ra = Rs & ~Rb; }});
-
-75: IntArithOp::mulhw({{
-int64_t prod = Ra_sd * Rb_sd;
-Rt = prod >> 32;
-}});
-
 87: LoadIndexOp::lbzx({{ Rt = Mem_ub; }});
-104: IntSumOp::neg({{ ~Ra }}, {{ 1 }});
 119: LoadIndexUpdateOp::lbzux({{ Rt = Mem_ub; }});
 124: IntLogicOp::nor({{ Ra = ~(Rs | Rb); }});

-format IntSumOp {
-136: subfe({{ ~Ra }}, {{ Rb }}, {{ xer.ca }}, true);
-138: adde({{ Ra }}, {{ Rb }}, {{ xer.ca }}, true);
-}
-
-144: IntOp::mtcrf({{
-uint32_t mask = 0;
-for (int i = 0; i < 8; ++i) {
-if (((FXM >> i) & 0x1) == 0x1) {
-mask |= 0xf << (4 * i);
-}
-}
-CR = (Rs & mask) | (CR & ~mask);
-}});
-
 format StoreIndexOp {
 150: stwcx({{
 bool store_performed = false;
@@ -279,51 +252,15 @@
 }

 183: StoreIndexUpdateOp::stwux({{ Mem = Rs; }});
-
-format IntSumOp {
-200: subfze({{ ~Ra }}, {{ xer.ca }}, computeCA = true);
-202: addze({{ Ra }}, {{ xer.ca }}, computeCA = true);
-}
-
 215: StoreIndexOp::stbx({{ Mem_ub = Rs_ub; }});
-
-format IntSumOp {
-232: subfme({{ ~Ra }}, {{ (uint32_t)-1 }}, {{ xer.ca }}, true);
-234: addme({{ Ra }}, {{ (uint32_t)-1 }}, {{ 

[gem5-dev] Change in gem5/gem5[develop]: arch-power: Fix extended opcode based decoding

2021-02-07 Thread Sandipan Das (Gerrit) via gem5-dev
Sandipan Das has uploaded this change for review. (  
https://gem5-review.googlesource.com/c/public/gem5/+/40885 )



Change subject: arch-power: Fix extended opcode based decoding
..

arch-power: Fix extended opcode based decoding

When multiple instructions share the same primary opcode,
they are distinguished by the decoder by looking at the
extended opcode. However, the length and position of the
extended opcode field can vary based on instruction form.

This ensures that the correct extended opcode fields are
used for decoding such instructions.

Change-Id: I8207568ac975587377abba8a9b221ca3097b8488
Signed-off-by: Sandipan Das 
---
M src/arch/power/isa/decoder.isa
1 file changed, 168 insertions(+), 139 deletions(-)



diff --git a/src/arch/power/isa/decoder.isa b/src/arch/power/isa/decoder.isa
index fa6c9cb..478b254 100644
--- a/src/arch/power/isa/decoder.isa
+++ b/src/arch/power/isa/decoder.isa
@@ -62,7 +62,7 @@
 }
 }

-19: decode XO_XO {
+19: decode XL_XO {

 // Conditionally branch to address in LR based on CR and CTR.
 format BranchLrCondCtr {
@@ -144,9 +144,14 @@
 40: lhz({{ Rt = Mem_uh; }});
 42: lha({{ Rt = Mem_sh; }});
 32: lwz({{ Rt = Mem; }});
-58: lwa({{ Rt = Mem_sw; }},
-{{ EA = Ra + (disp & 0xfffc); }},
-{{ EA = disp & 0xfffc; }});
+}
+
+58: decode DS_XO {
+format LoadDispOp {
+2: lwa({{ Rt = Mem_sw; }},
+   {{ EA = Ra + (disp & 0xfffc); }},
+   {{ EA = disp & 0xfffc; }});
+}
 }

 format LoadDispUpdateOp {
@@ -224,12 +229,18 @@
(Ra & ~fullMask); }});
 }

-// Some instructions use bits 21 - 30, others 22 - 30. We have to use
-// the larger size to account for all opcodes. For those that use the
-// smaller value, the OE bit is bit 21. Therefore, we have two versions
-// of each instruction: 1 with OE set, the other without. For an
-// example see 'add' and 'addo'.
-31: decode XO_XO {
+// There are a large number of instructions that have the same primary
+// opcode (PO) of 31. In this case, the instructions are of different
+// forms. For every form, the XO fields may vary in position and width.
+// The X, XFL, XFX and XL form instructions use bits 21 - 30 and the
+// XO form instructions use bits 22 - 30 as extended opcode (XO). To
+// avoid conflicts, instructions of each form have to be defined under
+// separate decode blocks. However, only a single decode block can be
+// associated with a particular PO and it will recognize only one type
+// of XO field. A solution for associating decode blocks for the other
+// types of XO fields with the same PO is to have the other blocks as
+// nested default cases.
+31: decode X_XO {

 // All loads with an index register. The non-update versions
 // all use the value 0 if Ra == R0, not the value contained in
@@ -285,94 +296,6 @@
 183: stwux({{ Mem = Rs; }});
 }

-// These instructions can all be reduced to the form
-// Rt = src1 + src2 [+ CA], therefore we just give src1 and src2
-// (and, if necessary, CA) definitions and let the python script
-// deal with setting things up correctly. We also give flags to
-// say which control registers to set.
-format IntSumOp {
-266: add({{ Ra }}, {{ Rb }});
-40: subf({{ ~Ra }}, {{ Rb }}, {{ 1 }});
-10: addc({{ Ra }}, {{ Rb }},
- computeCA = true);
-8: subfc({{ ~Ra }}, {{ Rb }}, {{ 1 }},
- true);
-104: neg({{ ~Ra }}, {{ 1 }});
-138: adde({{ Ra }}, {{ Rb }}, {{ xer.ca }},
-  true);
-234: addme({{ Ra }}, {{ (uint32_t)-1 }}, {{ xer.ca }},
-   true);
-136: subfe({{ ~Ra }}, {{ Rb }}, {{ xer.ca }},
-   true);
-232: subfme({{ ~Ra }}, {{ (uint32_t)-1 }}, {{ xer.ca }},
-true);
-202: addze({{ Ra }}, {{ xer.ca }},
-   computeCA = true);
-200: subfze({{ ~Ra }}, {{ xer.ca }},
-computeCA = true);
-}
-
-// Arithmetic instructions all use source registers Ra and Rb,
-// with destination register Rt.
-format IntArithOp {
-75: mulhw({{ int64_t prod = Ra_sd * Rb_sd; Rt = prod >> 32;  
}});
-11: mulhwu({{ uint64_t prod = Ra_ud * Rb_ud; Rt = prod >> 32;  
}});

-235: mullw({{ int64_t prod = Ra_sd * Rb_sd; Rt = prod; }});
-747: mullwo({{
-int64_t src1 = Ra_sd;
-int64_t src2 = Rb;
-int64_t prod = src1 * src2;
-Rt = prod;
-}},
-