From f1115a2ce9dde3d15bb72ba4c8aee4baf400371b Mon Sep 17 00:00:00 2001 From: Tomasz Sowa Date: Thu, 23 Oct 2008 20:17:40 +0000 Subject: [PATCH] added: test of the LAHF and SAHF instructions (on a 64bit platform) git-svn-id: svn://ttmath.org/publicrep/ttmath/trunk@81 e52654a7-88a9-db11-a3e9-0013d4bc506e --- tests/main.cpp | 55 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/tests/main.cpp b/tests/main.cpp index 52f31f6..ed2482e 100644 --- a/tests/main.cpp +++ b/tests/main.cpp @@ -44,6 +44,58 @@ const char uint_tests_file[] = "tests.uint32"; + +bool test_lahf() +{ +#ifdef TTMATH_PLATFORM64 + + + #ifndef __GNUC__ + #error "another compiler than GCC is currently not supported in 64bit mode" + #endif + + + std::cout << "Processor 64bit: checking LAHF and SAHF instructions...."; + + unsigned long int is_lahf; + + + __asm__ __volatile__ ( + + "push %%rax \n" + "push %%rcx \n" + "push %%rdx \n" + + "mov $0x80000001, %%rax \n" + "CPUID \n" + "test $1, %%rcx \n" + "setnz %%al \n" + "movzx %%al, %%rbx \n" + + "pop %%rdx \n" + "pop %%rcx \n" + "pop %%rax \n" + + : "=b" (is_lahf) + : + : "cc" + ); + + if( is_lahf ) + { + std::cout << "ok" << std::endl; + return true; + } + + std::cout << "fail" << std::endl; + + +#endif + +return false; +} + + void test_uint() { UIntTest test; @@ -58,6 +110,9 @@ int main() { using namespace ttmath; + if( !test_lahf() ) + return 1; + test_uint();