xbyak/sample/test_util.cpp

168 lines
4.8 KiB
C++
Raw Normal View History

2010-04-15 18:33:04 -07:00
#include <stdio.h>
#include "xbyak/xbyak_util.h"
#define NUM_OF_ARRAY(x) (sizeof(x) / sizeof(x[0]))
2011-02-04 00:22:38 -07:00
struct PopCountTest : public Xbyak::CodeGenerator {
PopCountTest(int n)
2021-01-01 19:40:41 -07:00
: Xbyak::CodeGenerator(4096, Xbyak::DontSetProtectRWE)
2011-02-04 00:22:38 -07:00
{
mov(eax, n);
popcnt(eax, eax);
ret();
}
};
2022-05-26 02:09:03 -07:00
void putCPUinfo(bool onlyCpuidFeature)
2010-04-15 18:33:04 -07:00
{
using namespace Xbyak::util;
Cpu cpu;
printf("vendor %s\n", cpu.has(Cpu::tINTEL) ? "intel" : "amd");
static const struct {
Cpu::Type type;
const char *str;
} tbl[] = {
{ Cpu::tMMX, "mmx" },
{ Cpu::tMMX2, "mmx2" },
{ Cpu::tCMOV, "cmov" },
{ Cpu::tSSE, "sse" },
{ Cpu::tSSE2, "sse2" },
{ Cpu::tSSE3, "sse3" },
{ Cpu::tSSSE3, "ssse3" },
{ Cpu::tSSE41, "sse41" },
{ Cpu::tSSE42, "sse42" },
2023-12-19 02:44:12 -07:00
{ Cpu::tSSE4a, "sse4a" },
2010-04-15 18:33:04 -07:00
{ Cpu::tPOPCNT, "popcnt" },
{ Cpu::t3DN, "3dn" },
{ Cpu::tE3DN, "e3dn" },
2011-02-04 00:22:38 -07:00
{ Cpu::tAESNI, "aesni" },
{ Cpu::tRDTSCP, "rdtscp" },
{ Cpu::tXSAVE, "xsave(xgetvb)" },
{ Cpu::tOSXSAVE, "osxsave" },
2011-02-04 00:22:38 -07:00
{ Cpu::tPCLMULQDQ, "pclmulqdq" },
{ Cpu::tAVX, "avx" },
{ Cpu::tFMA, "fma" },
2013-05-30 00:46:13 -07:00
{ Cpu::tAVX2, "avx2" },
{ Cpu::tBMI1, "bmi1" },
{ Cpu::tBMI2, "bmi2" },
{ Cpu::tLZCNT, "lzcnt" },
2017-08-07 15:13:35 -07:00
{ Cpu::tPREFETCHW, "prefetchw" },
2013-09-05 06:10:49 -07:00
{ Cpu::tENHANCED_REP, "enh_rep" },
{ Cpu::tRDRAND, "rdrand" },
2015-01-27 20:38:08 -07:00
{ Cpu::tADX, "adx" },
2015-01-27 21:05:24 -07:00
{ Cpu::tRDSEED, "rdseed" },
{ Cpu::tSMAP, "smap" },
{ Cpu::tHLE, "hle" },
2015-01-27 21:16:44 -07:00
{ Cpu::tRTM, "rtm" },
2017-08-08 03:08:41 -07:00
{ Cpu::tMPX, "mpx" },
{ Cpu::tSHA, "sha" },
2017-01-25 14:38:59 -07:00
{ Cpu::tPREFETCHWT1, "prefetchwt1" },
2015-05-23 22:44:45 -07:00
{ Cpu::tF16C, "f16c" },
2015-06-15 19:43:09 -07:00
{ Cpu::tMOVBE, "movbe" },
2016-05-04 20:14:04 -07:00
{ Cpu::tAVX512F, "avx512f" },
{ Cpu::tAVX512DQ, "avx512dq" },
{ Cpu::tAVX512IFMA, "avx512_ifma" },
2016-05-04 20:14:04 -07:00
{ Cpu::tAVX512PF, "avx512pf" },
{ Cpu::tAVX512ER, "avx512er" },
{ Cpu::tAVX512CD, "avx512cd" },
{ Cpu::tAVX512BW, "avx512bw" },
{ Cpu::tAVX512VL, "avx512vl" },
{ Cpu::tAVX512VBMI, "avx512_vbmi" },
2016-11-26 18:11:06 -07:00
{ Cpu::tAVX512_4VNNIW, "avx512_4vnniw" },
{ Cpu::tAVX512_4FMAPS, "avx512_4fmaps" },
{ Cpu::tAVX512_VBMI2, "avx512_vbmi2" },
{ Cpu::tGFNI, "gfni" },
{ Cpu::tVAES, "vaes" },
{ Cpu::tVPCLMULQDQ, "vpclmulqdq" },
{ Cpu::tAVX512_VNNI, "avx512_vnni" },
{ Cpu::tAVX512_BITALG, "avx512_bitalg" },
{ Cpu::tAVX512_VPOPCNTDQ, "avx512_vpopcntdq" },
2019-05-23 23:08:19 -07:00
{ Cpu::tAVX512_BF16, "avx512_bf16" },
{ Cpu::tAVX512_VP2INTERSECT, "avx512_vp2intersect" },
2020-10-19 02:39:10 -07:00
{ Cpu::tAMX_TILE, "amx(tile)" },
{ Cpu::tAMX_INT8, "amx(int8)" },
{ Cpu::tAMX_BF16, "amx(bf16)" },
{ Cpu::tAVX_VNNI, "avx_vnni" },
2021-08-29 22:16:08 -07:00
{ Cpu::tAVX512_FP16, "avx512_fp16" },
2022-04-04 23:12:04 -07:00
{ Cpu::tWAITPKG, "waitpkg" },
2022-05-10 22:04:22 -07:00
{ Cpu::tCLFLUSHOPT, "clflushopt" },
2022-05-11 01:11:50 -07:00
{ Cpu::tCLDEMOTE, "cldemote" },
2023-12-19 02:44:12 -07:00
{ Cpu::tCLWB, "clwb" },
2022-05-11 18:56:13 -07:00
{ Cpu::tMOVDIRI, "movdiri" },
{ Cpu::tMOVDIR64B, "movdir64b" },
2023-02-19 17:13:49 -07:00
{ Cpu::tUINTR, "uintr" },
2023-02-19 17:10:10 -07:00
{ Cpu::tSERIALIZE, "serialize" },
2022-05-23 15:56:01 -07:00
{ Cpu::tCLZERO, "clzero" },
{ Cpu::tAMX_FP16, "amx_fp16" },
{ Cpu::tAVX_VNNI_INT8, "avx_vnni_int8" },
{ Cpu::tAVX_NE_CONVERT, "avx_ne_convert" },
2022-10-05 17:35:51 -07:00
{ Cpu::tAVX_IFMA, "avx_ifma" },
2022-11-25 00:21:33 -07:00
{ Cpu::tRAO_INT, "rao-int" },
2022-11-29 20:08:10 -07:00
{ Cpu::tCMPCCXADD, "cmpccxadd" },
2022-12-07 00:09:18 -07:00
{ Cpu::tPREFETCHITI, "prefetchiti" },
2023-08-05 17:57:45 -07:00
{ Cpu::tSHA512, "sha512" },
{ Cpu::tSM3, "sm3" },
{ Cpu::tSM4, "sm4" },
2023-08-06 18:11:54 -07:00
{ Cpu::tAVX_VNNI_INT16, "avx_vnni_int16" },
2023-12-14 01:26:26 -07:00
{ Cpu::tAPX_F, "apx_f" },
{ Cpu::tAVX10, "avx10" },
2023-12-19 01:24:11 -07:00
{ Cpu::tAESKLE, "aeskle" },
{ Cpu::tWIDE_KL, "wide_kl" },
{ Cpu::tKEYLOCKER, "keylocker" },
{ Cpu::tKEYLOCKER_WIDE, "keylocker_wide" },
2024-06-11 00:45:37 -07:00
{ Cpu::tTSXLDTRK, "tsxldtrk" },
2010-04-15 18:33:04 -07:00
};
for (size_t i = 0; i < NUM_OF_ARRAY(tbl); i++) {
if (cpu.has(tbl[i].type)) printf(" %s", tbl[i].str);
}
printf("\n");
2022-05-26 02:09:03 -07:00
if (onlyCpuidFeature) return;
2023-12-14 01:26:26 -07:00
if (cpu.has(Cpu::tAVX10)) {
printf("AVX10 version %d\n", cpu.getAVX10version());
}
2011-02-04 00:22:38 -07:00
if (cpu.has(Cpu::tPOPCNT)) {
const int n = 0x12345678; // bitcount = 13
const int ok = 13;
2021-01-01 19:40:41 -07:00
PopCountTest code(n);
code.setProtectModeRE();
int (*f)() = code.getCode<int (*)()>();
int r = f();
2011-02-04 00:22:38 -07:00
if (r == ok) {
puts("popcnt ok");
} else {
printf("popcnt ng %d %d\n", r, ok);
}
2021-01-01 19:40:41 -07:00
code.setProtectModeRW();
2011-02-04 00:22:38 -07:00
}
2013-04-10 18:07:58 -07:00
/*
displayFamily displayModel
Opteron 2376 10 4
Core2 Duo T7100 6 F
Core i3-2120T 6 2A
Core i7-2600 6 2A
Xeon X5650 6 2C
Core i7-3517 6 3A
Core i7-3930K 6 2D
*/
cpu.putFamily();
for (unsigned int i = 0; i < cpu.getDataCacheLevels(); i++) {
printf("cache level=%u data cache size=%u cores sharing data cache=%u\n", i, cpu.getDataCacheSize(i), cpu.getCoresSharingDataCache(i));
}
2019-01-16 21:45:25 -07:00
printf("SmtLevel =%u\n", cpu.getNumCores(Xbyak::util::SmtLevel));
printf("CoreLevel=%u\n", cpu.getNumCores(Xbyak::util::CoreLevel));
2010-04-15 18:33:04 -07:00
}
2022-05-26 02:09:03 -07:00
int main(int argc, char *argv[])
2010-04-15 18:33:04 -07:00
{
2022-05-26 02:09:03 -07:00
bool onlyCpuidFeature = argc == 2 && strcmp(argv[1], "-cpuid") == 0;
if (!onlyCpuidFeature) {
2010-04-15 18:33:04 -07:00
#ifdef XBYAK32
2022-05-26 02:09:03 -07:00
puts("32bit");
2010-04-15 18:33:04 -07:00
#else
2022-05-26 02:09:03 -07:00
puts("64bit");
2010-04-15 18:33:04 -07:00
#endif
2022-05-26 02:09:03 -07:00
}
putCPUinfo(onlyCpuidFeature);
2010-04-15 18:33:04 -07:00
}