Tong Shen has uploaded this change for review. (
https://gem5-review.googlesource.com/c/public/gem5/+/39615 )
Change subject: arch-x86: implement POPCNT instruction.
......................................................................
arch-x86: implement POPCNT instruction.
Change-Id: Id6ddc1245c81a17720885f9038d55d0811ef7f4d
---
M src/arch/x86/decoder_tables.cc
M src/arch/x86/isa/decoder/two_byte_opcodes.isa
M src/arch/x86/isa/insts/general_purpose/compare_and_test/bit_scan.py
M src/arch/x86/isa/microops/regop.isa
4 files changed, 36 insertions(+), 3 deletions(-)
diff --git a/src/arch/x86/decoder_tables.cc b/src/arch/x86/decoder_tables.cc
index 7ee5e01..db749cf 100644
--- a/src/arch/x86/decoder_tables.cc
+++ b/src/arch/x86/decoder_tables.cc
@@ -115,7 +115,7 @@
/* 8 */ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0,
/* 9 */ 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1,
/* A */ 0 , 0 , 0 , 1 , 1 , 1 , 1 , 1 , 0 , 0 , 0 , 1 , 1 , 1 , 1 , 1,
-/* B */ 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 0 , 0 , 1 , 1 , 1 , 1 , 1 , 1,
+/* B */ 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 0 , 1 , 1 , 1 , 1 , 1 , 1,
/* C */ 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0,
/* D */ 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1,
/* E */ 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1 , 1,
@@ -234,7 +234,7 @@
/* 8 */ ZW, ZW, ZW, ZW, ZW, ZW, ZW, ZW, ZW, ZW, ZW, ZW, ZW, ZW, ZW, ZW,
/* 9 */ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
/* A */ 0 , 0 , 0 , 0 , BY, 0 , 0 , 0 , 0 , 0 , 0 , 0 , BY, 0 , 0 , 0 ,
-/* B */ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , ZW, 0 , BY, 0 , 0 , 0 , 0 , 0 ,
+/* B */ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , BY, 0 , 0 , 0 , 0 , 0 ,
/* C */ 0 , 0 , BY, 0 , BY, BY, BY, 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
/* D */ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
/* E */ 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 , 0 ,
diff --git a/src/arch/x86/isa/decoder/two_byte_opcodes.isa
b/src/arch/x86/isa/decoder/two_byte_opcodes.isa
index f70e7bd..1dfd228 100644
--- a/src/arch/x86/isa/decoder/two_byte_opcodes.isa
+++ b/src/arch/x86/isa/decoder/two_byte_opcodes.isa
@@ -755,7 +755,7 @@
0x17: decode OPCODE_OP_BOTTOM3 {
0x0: decode LEGACY_REP {
0x0: WarnUnimpl::jmpe_Jz();
- 0x1: WarnUnimpl::popcnt_Gv_Ev();
+ 0x1: POPCNT(Gv,Ev);
}
//0x1: group10_UD2();
0x1: UD2();
diff --git
a/src/arch/x86/isa/insts/general_purpose/compare_and_test/bit_scan.py
b/src/arch/x86/isa/insts/general_purpose/compare_and_test/bit_scan.py
index a755d25..7d80e5c 100644
--- a/src/arch/x86/isa/insts/general_purpose/compare_and_test/bit_scan.py
+++ b/src/arch/x86/isa/insts/general_purpose/compare_and_test/bit_scan.py
@@ -350,4 +350,19 @@
end:
fault "NoFault"
};
+
+def macroop POPCNT_R_R {
+ popcnt reg, regm, reg
+};
+
+def macroop POPCNT_R_M {
+ ld t1, seg, sib, disp
+ popcnt reg, t1, reg
+};
+
+def macroop POPCNT_R_P {
+ rdip t7
+ ld t1, seg, riprel, disp
+ popcnt reg, t1, reg
+};
'''
diff --git a/src/arch/x86/isa/microops/regop.isa
b/src/arch/x86/isa/microops/regop.isa
index da1f9ae..4079ca5 100644
--- a/src/arch/x86/isa/microops/regop.isa
+++ b/src/arch/x86/isa/microops/regop.isa
@@ -1765,4 +1765,22 @@
code = '''
DestReg = X86ISA::convX87TagsToXTags(FTW);
'''
+
+ class Popcnt(RegOp):
+ code = '''
+ uint64_t result = 0;
+ for (int i = 0; i < 64; i++) {
+ if (bits(SrcReg1, i)) {
+ result++;
+ }
+ }
+ DestReg = result;
+ '''
+ flag_code = '''
+ ccFlagBits = ccFlagBits & ~(SFBit | AFBit | ZFBit | PFBit);
+ if (SrcReg1 == 0) {
+ ccFlagBits = ccFlagBits | ZFBit;
+ }
+ cfofBits = cfofBits & ~(OFBit | CFBit);
+ '''
}};
--
To view, visit https://gem5-review.googlesource.com/c/public/gem5/+/39615
To unsubscribe, or for help writing mail filters, visit
https://gem5-review.googlesource.com/settings
Gerrit-Project: public/gem5
Gerrit-Branch: develop
Gerrit-Change-Id: Id6ddc1245c81a17720885f9038d55d0811ef7f4d
Gerrit-Change-Number: 39615
Gerrit-PatchSet: 1
Gerrit-Owner: Tong Shen <[email protected]>
Gerrit-MessageType: newchange
_______________________________________________
gem5-dev mailing list -- [email protected]
To unsubscribe send an email to [email protected]
%(web_page_url)slistinfo%(cgiext)s/%(_internal_name)s