aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--gen/gen_code.cpp28
-rw-r--r--test/apx.cpp28
-rw-r--r--xbyak/xbyak.h12
-rw-r--r--xbyak/xbyak_mnemonic.h14
4 files changed, 67 insertions, 15 deletions
diff --git a/gen/gen_code.cpp b/gen/gen_code.cpp
index 892fdbc..71bd13c 100644
--- a/gen/gen_code.cpp
+++ b/gen/gen_code.cpp
@@ -1402,14 +1402,6 @@ void put()
{ 0x2E, "ucomisd", T_0F | T_66 | T_EVEX | T_EW1 | T_SAE_X | T_N8, false, 2 },
{ 0x2E, "ucomiss", T_0F | T_EVEX | T_EW0 | T_SAE_X | T_N4, false, 2 },
-
- { 0xCC, "sha1rnds4", T_0F3A, true, 1 },
- { 0xC8, "sha1nexte", T_0F38, false, 1 },
- { 0xC9, "sha1msg1", T_0F38, false, 1 },
- { 0xCA, "sha1msg2", T_0F38, false, 1 },
- { 0xCB, "sha256rnds2", T_0F38, false, 1 },
- { 0xCC, "sha256msg1", T_0F38, false, 1 },
- { 0xCD, "sha256msg2", T_0F38, false, 1 },
};
for (size_t i = 0; i < NUM_OF_ARRAY(tbl); i++) {
const Tbl *p = &tbl[i];
@@ -1425,6 +1417,26 @@ void put()
}
}
}
+ // sha
+ {
+ const struct Tbl {
+ uint8_t code;
+ uint8_t code2;
+ const char *name;
+ } tbl[] = {
+ { 0xC8, 0xD8, "sha1nexte" },
+ { 0xC9, 0xD9, "sha1msg1" },
+ { 0xCA, 0xDA, "sha1msg2" },
+ { 0xCB, 0xDB, "sha256rnds2" },
+ { 0xCC, 0xDC, "sha256msg1" },
+ { 0xCD, 0xDD, "sha256msg2" },
+ };
+ for (size_t i = 0; i < NUM_OF_ARRAY(tbl); i++) {
+ const Tbl *p = &tbl[i];
+ printf("void %s(const Xmm& x, const Operand& op) { opSHA(x, op, T_0F38, 0x%02X, 0x%02X); }\n", p->name, p->code, p->code2);
+ }
+ puts("void sha1rnds4(const Xmm& x, const Operand& op, uint8_t imm) { opSHA(x, op, T_0F3A, 0xCC, 0xD4, imm); }");
+ }
// (m, x), (m, y)
{
const struct Tbl {
diff --git a/test/apx.cpp b/test/apx.cpp
index b2675b8..207389c 100644
--- a/test/apx.cpp
+++ b/test/apx.cpp
@@ -1870,3 +1870,31 @@ CYBOZU_TEST_AUTO(encodekey)
CYBOZU_TEST_EQUAL_ARRAY(c.getCode(), tbl, n);
}
+CYBOZU_TEST_AUTO(sha)
+{
+ struct Code : Xbyak::CodeGenerator {
+ Code()
+ {
+ sha1msg1(xmm15, ptr [r30+r29*8+0x12]);
+ sha1msg2(xmm15, ptr [r30+r29*8+0x12]);
+ sha1nexte(xmm15, ptr [r30+r29*8+0x12]);
+ sha256msg1(xmm15, ptr [r30+r29*8+0x12]);
+ sha256msg2(xmm15, ptr [r30+r29*8+0x12]);
+ sha256rnds2(xmm15, ptr [r30+r29*8+0x12]);
+ sha1rnds4(xmm15, ptr [r30+r29*8+0x12], 0x23);
+ }
+ } c;
+ const uint8_t tbl[] = {
+ 0x62, 0x1c, 0x78, 0x08, 0xd9, 0x7c, 0xee, 0x12,
+ 0x62, 0x1c, 0x78, 0x08, 0xda, 0x7c, 0xee, 0x12,
+ 0x62, 0x1c, 0x78, 0x08, 0xd8, 0x7c, 0xee, 0x12,
+ 0x62, 0x1c, 0x78, 0x08, 0xdc, 0x7c, 0xee, 0x12,
+ 0x62, 0x1c, 0x78, 0x08, 0xdd, 0x7c, 0xee, 0x12,
+ 0x62, 0x1c, 0x78, 0x08, 0xdb, 0x7c, 0xee, 0x12,
+ 0x62, 0x1c, 0x78, 0x08, 0xd4, 0x7c, 0xee, 0x12, 0x23,
+ };
+ const size_t n = sizeof(tbl);
+ CYBOZU_TEST_EQUAL(c.getSize(), n);
+ CYBOZU_TEST_EQUAL_ARRAY(c.getCode(), tbl, n);
+}
+
diff --git a/xbyak/xbyak.h b/xbyak/xbyak.h
index 8c633ca..ac20b16 100644
--- a/xbyak/xbyak.h
+++ b/xbyak/xbyak.h
@@ -2755,6 +2755,14 @@ private:
}
opROO(Reg(), r2, r1, T_MUST_EVEX|T_F3, code2);
}
+ void opSHA(const Xmm& x, const Operand& op, uint64_t type, uint8_t code1, uint8_t code2, int imm = NONE)
+ {
+ if (x.getIdx() <= 15 && op.hasRex2() && opROO(Reg(), op, x, T_MUST_EVEX, code2, imm != NONE ? 1 : 0)) {
+ if (imm != NONE) db(imm);
+ return;
+ }
+ opSSE(x, op, type, code1, isXMM_XMMorMEM, imm);
+ }
public:
unsigned int getVersion() const { return VERSION; }
using CodeArray::db;
@@ -3139,6 +3147,10 @@ public:
// set default encoding to select Vex or Evex
void setDefaultEncoding(PreferredEncoding encoding) { defaultEncoding_ = encoding; }
+ void sha1msg12(const Xmm& x, const Operand& op)
+ {
+ opROO(Reg(), op, x, T_MUST_EVEX, 0xD9);
+ }
/*
use single byte nop if useMultiByteNop = false
*/
diff --git a/xbyak/xbyak_mnemonic.h b/xbyak/xbyak_mnemonic.h
index 196f5d4..9b41d81 100644
--- a/xbyak/xbyak_mnemonic.h
+++ b/xbyak/xbyak_mnemonic.h
@@ -988,13 +988,13 @@ void setpo(const Operand& op) { if (opROO(Reg(), op, Reg(), T_APX|T_ZU|T_F2, 0x4
void sets(const Operand& op) { if (opROO(Reg(), op, Reg(), T_APX|T_ZU|T_F2, 0x40 | 8)) return; opRext(op, 8, 0, T_0F, 0x90 | 8); }//-V524
void setz(const Operand& op) { if (opROO(Reg(), op, Reg(), T_APX|T_ZU|T_F2, 0x40 | 4)) return; opRext(op, 8, 0, T_0F, 0x90 | 4); }//-V524
void sfence() { db(0x0F); db(0xAE); db(0xF8); }
-void sha1msg1(const Xmm& xmm, const Operand& op) { opSSE(xmm, op, T_0F38, 0xC9, isXMM_XMMorMEM, NONE); }
-void sha1msg2(const Xmm& xmm, const Operand& op) { opSSE(xmm, op, T_0F38, 0xCA, isXMM_XMMorMEM, NONE); }
-void sha1nexte(const Xmm& xmm, const Operand& op) { opSSE(xmm, op, T_0F38, 0xC8, isXMM_XMMorMEM, NONE); }
-void sha1rnds4(const Xmm& xmm, const Operand& op, uint8_t imm) { opSSE(xmm, op, T_0F3A, 0xCC, isXMM_XMMorMEM, imm); }
-void sha256msg1(const Xmm& xmm, const Operand& op) { opSSE(xmm, op, T_0F38, 0xCC, isXMM_XMMorMEM, NONE); }
-void sha256msg2(const Xmm& xmm, const Operand& op) { opSSE(xmm, op, T_0F38, 0xCD, isXMM_XMMorMEM, NONE); }
-void sha256rnds2(const Xmm& xmm, const Operand& op) { opSSE(xmm, op, T_0F38, 0xCB, isXMM_XMMorMEM, NONE); }
+void sha1msg1(const Xmm& x, const Operand& op) { opSHA(x, op, T_0F38, 0xC9, 0xD9); }
+void sha1msg2(const Xmm& x, const Operand& op) { opSHA(x, op, T_0F38, 0xCA, 0xDA); }
+void sha1nexte(const Xmm& x, const Operand& op) { opSHA(x, op, T_0F38, 0xC8, 0xD8); }
+void sha1rnds4(const Xmm& x, const Operand& op, uint8_t imm) { opSHA(x, op, T_0F3A, 0xCC, 0xD4, imm); }
+void sha256msg1(const Xmm& x, const Operand& op) { opSHA(x, op, T_0F38, 0xCC, 0xDC); }
+void sha256msg2(const Xmm& x, const Operand& op) { opSHA(x, op, T_0F38, 0xCD, 0xDD); }
+void sha256rnds2(const Xmm& x, const Operand& op) { opSHA(x, op, T_0F38, 0xCB, 0xDB); }
void shl(const Operand& op, const Reg8& _cl) { opShift(op, _cl, 12); }
void shl(const Operand& op, int imm) { opShift(op, imm, 12); }
void shl(const Reg& d, const Operand& op, const Reg8& _cl) { opShift(op, _cl, 12, &d); }