vaes* supports AVX-512

This commit is contained in:
MITSUNARI Shigeo 2017-12-30 16:41:14 +09:00
parent 7fde08e0f0
commit 9e16b40b06
4 changed files with 107 additions and 36 deletions

View file

@ -1258,10 +1258,10 @@ void put()
{ 0x7D, "hsubpd", T_0F | T_66 | T_YMM, 3 }, { 0x7D, "hsubpd", T_0F | T_66 | T_YMM, 3 },
{ 0x7D, "hsubps", T_0F | T_F2 | T_YMM, 3 }, { 0x7D, "hsubps", T_0F | T_F2 | T_YMM, 3 },
{ 0xDC, "aesenc", T_0F38 | T_66 | T_W0, 3 }, { 0xDC, "aesenc", T_0F38 | T_66 | T_YMM | T_EVEX, 3 },
{ 0xDD, "aesenclast", T_0F38 | T_66 | T_W0, 3 }, { 0xDD, "aesenclast", T_0F38 | T_66 | T_YMM | T_EVEX, 3 },
{ 0xDE, "aesdec", T_0F38 | T_66 | T_W0, 3 }, { 0xDE, "aesdec", T_0F38 | T_66 | T_YMM | T_EVEX, 3 },
{ 0xDF, "aesdeclast", T_0F38 | T_66 | T_W0, 3 }, { 0xDF, "aesdeclast", T_0F38 | T_66 | T_YMM | T_EVEX, 3 },
}; };
for (size_t i = 0; i < NUM_OF_ARRAY(tbl); i++) { for (size_t i = 0; i < NUM_OF_ARRAY(tbl); i++) {
const Tbl *p = &tbl[i]; const Tbl *p = &tbl[i];

View file

@ -86,13 +86,15 @@ public:
} }
fflush(stdout); fflush(stdout);
if (msg.empty()) { if (msg.empty()) {
int err = ngCount_ + exceptionCount_;
int total = okCount_ + err;
std::cout << "ctest:name=" << getBaseName(*argv) std::cout << "ctest:name=" << getBaseName(*argv)
<< ", module=" << list_.size() << ", module=" << list_.size()
<< ", total=" << (okCount_ + ngCount_ + exceptionCount_) << ", total=" << total
<< ", ok=" << okCount_ << ", ok=" << okCount_
<< ", ng=" << ngCount_ << ", ng=" << ngCount_
<< ", exception=" << exceptionCount_ << std::endl; << ", exception=" << exceptionCount_ << std::endl;
return 0; return err > 0 ? 1 : 0;
} else { } else {
std::cout << msg << std::endl; std::cout << msg << std::endl;
return 1; return 1;
@ -128,6 +130,15 @@ bool isEqual(const T& lhs, const U& rhs)
return lhs == rhs; return lhs == rhs;
} }
// avoid warning of comparision of integers of different signs
inline bool isEqual(size_t lhs, int rhs)
{
return lhs == size_t(rhs);
}
inline bool isEqual(int lhs, size_t rhs)
{
return size_t(lhs) == rhs;
}
inline bool isEqual(const char *lhs, const char *rhs) inline bool isEqual(const char *lhs, const char *rhs)
{ {
return strcmp(lhs, rhs) == 0; return strcmp(lhs, rhs) == 0;
@ -188,9 +199,9 @@ int main(int argc, char *argv[])
@param y [in] @param y [in]
*/ */
#define CYBOZU_TEST_EQUAL(x, y) { \ #define CYBOZU_TEST_EQUAL(x, y) { \
bool eq = cybozu::test::isEqual(x, y); \ bool _cybozu_eq = cybozu::test::isEqual(x, y); \
cybozu::test::test(eq, "CYBOZU_TEST_EQUAL", #x ", " #y, __FILE__, __LINE__); \ cybozu::test::test(_cybozu_eq, "CYBOZU_TEST_EQUAL", #x ", " #y, __FILE__, __LINE__); \
if (!eq) { \ if (!_cybozu_eq) { \
std::cout << "ctest: lhs=" << (x) << std::endl; \ std::cout << "ctest: lhs=" << (x) << std::endl; \
std::cout << "ctest: rhs=" << (y) << std::endl; \ std::cout << "ctest: rhs=" << (y) << std::endl; \
} \ } \
@ -201,22 +212,39 @@ int main(int argc, char *argv[])
@param y [in] @param y [in]
*/ */
#define CYBOZU_TEST_NEAR(x, y, eps) { \ #define CYBOZU_TEST_NEAR(x, y, eps) { \
bool isNear = fabs((x) - (y)) < eps; \ bool _cybozu_isNear = fabs((x) - (y)) < eps; \
cybozu::test::test(isNear, "CYBOZU_TEST_NEAR", #x ", " #y, __FILE__, __LINE__); \ cybozu::test::test(_cybozu_isNear, "CYBOZU_TEST_NEAR", #x ", " #y, __FILE__, __LINE__); \
if (!isNear) { \ if (!_cybozu_isNear) { \
std::cout << "ctest: lhs=" << (x) << std::endl; \ std::cout << "ctest: lhs=" << (x) << std::endl; \
std::cout << "ctest: rhs=" << (y) << std::endl; \ std::cout << "ctest: rhs=" << (y) << std::endl; \
} \ } \
} }
#define CYBOZU_TEST_EQUAL_POINTER(x, y) { \ #define CYBOZU_TEST_EQUAL_POINTER(x, y) { \
bool eq = x == y; \ bool _cybozu_eq = x == y; \
cybozu::test::test(eq, "CYBOZU_TEST_EQUAL_POINTER", #x ", " #y, __FILE__, __LINE__); \ cybozu::test::test(_cybozu_eq, "CYBOZU_TEST_EQUAL_POINTER", #x ", " #y, __FILE__, __LINE__); \
if (!eq) { \ if (!_cybozu_eq) { \
std::cout << "ctest: lhs=" << static_cast<const void*>(x) << std::endl; \ std::cout << "ctest: lhs=" << static_cast<const void*>(x) << std::endl; \
std::cout << "ctest: rhs=" << static_cast<const void*>(y) << std::endl; \ std::cout << "ctest: rhs=" << static_cast<const void*>(y) << std::endl; \
} \ } \
} }
/**
alert if x[] != y[]
@param x [in]
@param y [in]
@param n [in]
*/
#define CYBOZU_TEST_EQUAL_ARRAY(x, y, n) { \
for (size_t _cybozu_test_i = 0, _cybozu_ie = (size_t)(n); _cybozu_test_i < _cybozu_ie; _cybozu_test_i++) { \
bool _cybozu_eq = cybozu::test::isEqual((x)[_cybozu_test_i], (y)[_cybozu_test_i]); \
cybozu::test::test(_cybozu_eq, "CYBOZU_TEST_EQUAL_ARRAY", #x ", " #y ", " #n, __FILE__, __LINE__); \
if (!_cybozu_eq) { \
std::cout << "ctest: i=" << _cybozu_test_i << std::endl; \
std::cout << "ctest: lhs=" << (x)[_cybozu_test_i] << std::endl; \
std::cout << "ctest: rhs=" << (y)[_cybozu_test_i] << std::endl; \
} \
} \
}
/** /**
always alert always alert
@ -229,25 +257,25 @@ int main(int argc, char *argv[])
*/ */
#define CYBOZU_TEST_EXCEPTION_MESSAGE(statement, Exception, msg) \ #define CYBOZU_TEST_EXCEPTION_MESSAGE(statement, Exception, msg) \
{ \ { \
int ret = 0; \ int _cybozu_ret = 0; \
std::string errMsg; \ std::string _cybozu_errMsg; \
try { \ try { \
statement; \ statement; \
ret = 1; \ _cybozu_ret = 1; \
} catch (const Exception& e) { \ } catch (const Exception& _cybozu_e) { \
errMsg = e.what(); \ _cybozu_errMsg = _cybozu_e.what(); \
if (errMsg.find(msg) == std::string::npos) { \ if (_cybozu_errMsg.find(msg) == std::string::npos) { \
ret = 2; \ _cybozu_ret = 2; \
} \ } \
} catch (...) { \ } catch (...) { \
ret = 3; \ _cybozu_ret = 3; \
} \ } \
if (ret) { \ if (_cybozu_ret) { \
cybozu::test::test(false, "CYBOZU_TEST_EXCEPTION_MESSAGE", #statement ", " #Exception ", " #msg, __FILE__, __LINE__); \ cybozu::test::test(false, "CYBOZU_TEST_EXCEPTION_MESSAGE", #statement ", " #Exception ", " #msg, __FILE__, __LINE__); \
if (ret == 1) { \ if (_cybozu_ret == 1) { \
std::cout << "ctest: no exception" << std::endl; \ std::cout << "ctest: no exception" << std::endl; \
} else if (ret == 2) { \ } else if (_cybozu_ret == 2) { \
std::cout << "ctest: bad exception msg:" << errMsg << std::endl; \ std::cout << "ctest: bad exception msg:" << _cybozu_errMsg << std::endl; \
} else { \ } else { \
std::cout << "ctest: unexpected exception" << std::endl; \ std::cout << "ctest: unexpected exception" << std::endl; \
} \ } \
@ -258,17 +286,17 @@ int main(int argc, char *argv[])
#define CYBOZU_TEST_EXCEPTION(statement, Exception) \ #define CYBOZU_TEST_EXCEPTION(statement, Exception) \
{ \ { \
int ret = 0; \ int _cybozu_ret = 0; \
try { \ try { \
statement; \ statement; \
ret = 1; \ _cybozu_ret = 1; \
} catch (const Exception&) { \ } catch (const Exception&) { \
} catch (...) { \ } catch (...) { \
ret = 2; \ _cybozu_ret = 2; \
} \ } \
if (ret) { \ if (_cybozu_ret) { \
cybozu::test::test(false, "CYBOZU_TEST_EXCEPTION", #statement ", " #Exception, __FILE__, __LINE__); \ cybozu::test::test(false, "CYBOZU_TEST_EXCEPTION", #statement ", " #Exception, __FILE__, __LINE__); \
if (ret == 1) { \ if (_cybozu_ret == 1) { \
std::cout << "ctest: no exception" << std::endl; \ std::cout << "ctest: no exception" << std::endl; \
} else { \ } else { \
std::cout << "ctest: unexpected exception" << std::endl; \ std::cout << "ctest: unexpected exception" << std::endl; \

View file

@ -130,4 +130,47 @@ CYBOZU_TEST_AUTO(vfmaddps)
CYBOZU_TEST_EQUAL(c.getSize(), n); CYBOZU_TEST_EQUAL(c.getSize(), n);
CYBOZU_TEST_EQUAL_ARRAY(c.getCode(), tbl, n); CYBOZU_TEST_EQUAL_ARRAY(c.getCode(), tbl, n);
} }
CYBOZU_TEST_AUTO(vaes)
{
struct Code : Xbyak::CodeGenerator {
Code()
{
vaesdec(xmm20, xmm30, ptr [rcx + 64]);
vaesdec(ymm1, ymm2, ptr [rcx + 64]);
vaesdec(zmm1, zmm2, ptr [rcx + 64]);
vaesdeclast(xmm20, xmm30, ptr [rax + 64]);
vaesdeclast(ymm20, ymm30, ptr [rax + 64]);
vaesdeclast(zmm20, zmm30, ptr [rax + 64]);
vaesenc(xmm20, xmm30, ptr [rcx + 64]);
vaesenc(ymm1, ymm2, ptr [rcx + 64]);
vaesenc(zmm1, zmm2, ptr [rcx + 64]);
vaesenclast(xmm20, xmm30, ptr [rax + 64]);
vaesenclast(ymm20, ymm30, ptr [rax + 64]);
vaesenclast(zmm20, zmm30, ptr [rax + 64]);
}
} c;
const uint8_t tbl[] = {
0x62, 0xE2, 0x0D, 0x00, 0xDE, 0x61, 0x04,
0xC4, 0xE2, 0x6D, 0xDE, 0x49, 0x40,
0x62, 0xF2, 0x6D, 0x48, 0xDE, 0x49, 0x01,
0x62, 0xE2, 0x0D, 0x00, 0xDF, 0x60, 0x04,
0x62, 0xE2, 0x0D, 0x20, 0xDF, 0x60, 0x02,
0x62, 0xE2, 0x0D, 0x40, 0xDF, 0x60, 0x01,
0x62, 0xE2, 0x0D, 0x00, 0xDC, 0x61, 0x04,
0xC4, 0xE2, 0x6D, 0xDC, 0x49, 0x40,
0x62, 0xF2, 0x6D, 0x48, 0xDC, 0x49, 0x01,
0x62, 0xE2, 0x0D, 0x00, 0xDD, 0x60, 0x04,
0x62, 0xE2, 0x0D, 0x20, 0xDD, 0x60, 0x02,
0x62, 0xE2, 0x0D, 0x40, 0xDD, 0x60, 0x01,
};
const size_t n = sizeof(tbl) / sizeof(tbl[0]);
CYBOZU_TEST_EQUAL(c.getSize(), n);
CYBOZU_TEST_EQUAL_ARRAY(c.getCode(), tbl, n);
}
#endif #endif

View file

@ -759,10 +759,10 @@ void vaddsd(const Xmm& xmm, const Operand& op1, const Operand& op2 = Operand())
void vaddss(const Xmm& xmm, const Operand& op1, const Operand& op2 = Operand()) { opAVX_X_X_XM(xmm, op1, op2, T_0F | T_F3 | T_EW0 | T_EVEX | T_ER_Z | T_N4, 0x58); } void vaddss(const Xmm& xmm, const Operand& op1, const Operand& op2 = Operand()) { opAVX_X_X_XM(xmm, op1, op2, T_0F | T_F3 | T_EW0 | T_EVEX | T_ER_Z | T_N4, 0x58); }
void vaddsubpd(const Xmm& xmm, const Operand& op1, const Operand& op2 = Operand()) { opAVX_X_X_XM(xmm, op1, op2, T_66 | T_0F | T_YMM, 0xD0); } void vaddsubpd(const Xmm& xmm, const Operand& op1, const Operand& op2 = Operand()) { opAVX_X_X_XM(xmm, op1, op2, T_66 | T_0F | T_YMM, 0xD0); }
void vaddsubps(const Xmm& xmm, const Operand& op1, const Operand& op2 = Operand()) { opAVX_X_X_XM(xmm, op1, op2, T_F2 | T_0F | T_YMM, 0xD0); } void vaddsubps(const Xmm& xmm, const Operand& op1, const Operand& op2 = Operand()) { opAVX_X_X_XM(xmm, op1, op2, T_F2 | T_0F | T_YMM, 0xD0); }
void vaesdec(const Xmm& xmm, const Operand& op1, const Operand& op2 = Operand()) { opAVX_X_X_XM(xmm, op1, op2, T_66 | T_0F38 | T_W0, 0xDE); } void vaesdec(const Xmm& xmm, const Operand& op1, const Operand& op2 = Operand()) { opAVX_X_X_XM(xmm, op1, op2, T_66 | T_0F38 | T_YMM | T_EVEX, 0xDE); }
void vaesdeclast(const Xmm& xmm, const Operand& op1, const Operand& op2 = Operand()) { opAVX_X_X_XM(xmm, op1, op2, T_66 | T_0F38 | T_W0, 0xDF); } void vaesdeclast(const Xmm& xmm, const Operand& op1, const Operand& op2 = Operand()) { opAVX_X_X_XM(xmm, op1, op2, T_66 | T_0F38 | T_YMM | T_EVEX, 0xDF); }
void vaesenc(const Xmm& xmm, const Operand& op1, const Operand& op2 = Operand()) { opAVX_X_X_XM(xmm, op1, op2, T_66 | T_0F38 | T_W0, 0xDC); } void vaesenc(const Xmm& xmm, const Operand& op1, const Operand& op2 = Operand()) { opAVX_X_X_XM(xmm, op1, op2, T_66 | T_0F38 | T_YMM | T_EVEX, 0xDC); }
void vaesenclast(const Xmm& xmm, const Operand& op1, const Operand& op2 = Operand()) { opAVX_X_X_XM(xmm, op1, op2, T_66 | T_0F38 | T_W0, 0xDD); } void vaesenclast(const Xmm& xmm, const Operand& op1, const Operand& op2 = Operand()) { opAVX_X_X_XM(xmm, op1, op2, T_66 | T_0F38 | T_YMM | T_EVEX, 0xDD); }
void vaesimc(const Xmm& xm, const Operand& op) { opAVX_X_XM_IMM(xm, op, T_66 | T_0F38 | T_W0, 0xDB); } void vaesimc(const Xmm& xm, const Operand& op) { opAVX_X_XM_IMM(xm, op, T_66 | T_0F38 | T_W0, 0xDB); }
void vaeskeygenassist(const Xmm& xm, const Operand& op, uint8 imm) { opAVX_X_XM_IMM(xm, op, T_66 | T_0F3A, 0xDF, imm); } void vaeskeygenassist(const Xmm& xm, const Operand& op, uint8 imm) { opAVX_X_XM_IMM(xm, op, T_66 | T_0F3A, 0xDF, imm); }
void vandnpd(const Xmm& xmm, const Operand& op1, const Operand& op2 = Operand()) { opAVX_X_X_XM(xmm, op1, op2, T_0F | T_66 | T_EW1 | T_YMM | T_EVEX | T_ER_Z | T_B64, 0x55); } void vandnpd(const Xmm& xmm, const Operand& op1, const Operand& op2 = Operand()) { opAVX_X_X_XM(xmm, op1, op2, T_0F | T_66 | T_EW1 | T_YMM | T_EVEX | T_ER_Z | T_B64, 0x55); }