From 7576cd572f3ab5f6543a70dcc606e131110dbcd8 Mon Sep 17 00:00:00 2001 From: Henrik Gramner Date: Fri, 3 Jun 2022 19:19:25 +0200 Subject: checkasm: Print the cpu model and cpuid signature on x86 --- tests/checkasm/checkasm.c | 11 ++++++--- tests/checkasm/x86/checkasm.asm | 54 +++++++++++++++++++++++++++++++++++++---- 2 files changed, 57 insertions(+), 8 deletions(-) diff --git a/tests/checkasm/checkasm.c b/tests/checkasm/checkasm.c index e60011c..e0aebaf 100644 --- a/tests/checkasm/checkasm.c +++ b/tests/checkasm/checkasm.c @@ -589,7 +589,6 @@ int main(int argc, char *argv[]) { int ret = 0; if (!state.function_listing) { - fprintf(stderr, "checkasm: using random seed %u\n", state.seed); #if ARCH_X86_64 void checkasm_warmup_avx2(void); void checkasm_warmup_avx512(void); @@ -601,8 +600,14 @@ int main(int argc, char *argv[]) { checkasm_simd_warmup(); #endif #if ARCH_X86 - void checkasm_init_x86(void); - checkasm_init_x86(); + unsigned checkasm_init_x86(char *name); + char name[48]; + const unsigned cpuid = checkasm_init_x86(name); + for (size_t len = strlen(name); len && name[len-1] == ' '; len--) + name[len-1] = '\0'; /* trim trailing whitespace */ + fprintf(stderr, "checkasm: %s (%08X) using random seed %u\n", name, cpuid, state.seed); +#else + fprintf(stderr, "checkasm: using random seed %u\n", state.seed); #endif } diff --git a/tests/checkasm/x86/checkasm.asm b/tests/checkasm/x86/checkasm.asm index 2972fa4..313a127 100644 --- a/tests/checkasm/x86/checkasm.asm +++ b/tests/checkasm/x86/checkasm.asm @@ -69,22 +69,64 @@ cextern fail_func ; (max_args % 4) must equal 3 for stack alignment %define max_args 15 +%if UNIX64 + DECLARE_REG_TMP 0 +%else + DECLARE_REG_TMP 4 +%endif + ;----------------------------------------------------------------------------- -; void checkasm_init_x86(void) +; unsigned checkasm_init_x86(char *name) ;----------------------------------------------------------------------------- -cglobal init_x86, 0, 4 +cglobal init_x86, 0, 5 %if ARCH_X86_64 push rbx %endif + movifnidn t0, r0mp + mov eax, 0x80000000 + cpuid + cmp eax, 0x80000004 + jb .no_brand ; processor brand string not supported + mov eax, 0x80000002 + cpuid + mov [t0+4* 0], eax + mov [t0+4* 1], ebx + mov [t0+4* 2], ecx + mov [t0+4* 3], edx + mov eax, 0x80000003 + cpuid + mov [t0+4* 4], eax + mov [t0+4* 5], ebx + mov [t0+4* 6], ecx + mov [t0+4* 7], edx + mov eax, 0x80000004 + cpuid + mov [t0+4* 8], eax + mov [t0+4* 9], ebx + mov [t0+4*10], ecx + mov [t0+4*11], edx + xor eax, eax + cpuid + jmp .check_xcr1 +.no_brand: ; use manufacturer id as a fallback xor eax, eax + mov [t0+4*3], eax cpuid - cmp eax, 13 - jb .end ; leaf 13 not supported + mov [t0+4*0], ebx + mov [t0+4*1], edx + mov [t0+4*2], ecx +.check_xcr1: + test eax, eax + jz .end2 ; cpuid leaf 1 not supported + mov t0d, eax ; max leaf mov eax, 1 cpuid and ecx, 0x18000000 cmp ecx, 0x18000000 - jne .end ; osxsave/avx not supported + jne .end2 ; osxsave/avx not supported + cmp t0d, 13 ; cpuid leaf 13 not supported + jb .end2 + mov t0d, eax ; cpuid signature mov eax, 13 mov ecx, 1 cpuid @@ -101,6 +143,8 @@ cglobal init_x86, 0, 4 mov [check_vzeroupper], ecx %endif .end: + mov eax, t0d +.end2: %if ARCH_X86_64 pop rbx %endif -- cgit v1.2.3