Vector Class Discussion

 
thread patch: xgetbv on gcc<4.4 - Greg Allen - 2014-04-22
last replythread patch: xgetbv on gcc<4.4 - Agner - 2014-04-22
last reply patch: xgetbv on gcc<4.4 - Greg Allen - 2014-04-23
 
patch: xgetbv on gcc<4.4
Author:  Date: 2014-04-22 11:45
This is a tiny patch to compile on gcc<4.4, where xgetbv doesn't exist. That includes RHEL5.

diff --git a/instrset_detect.cpp b/instrset_detect.cpp
--- a/instrset_detect.cpp
+++ b/instrset_detect.cpp
@@ -54,7 +54,11 @@
#elif defined(__GNUC__) // use inline assembly, Gnu/AT&T syntax

uint32_t a, d;
+#if __GNUC_PREREQ(4,4)
__asm("xgetbv" : "=a"(a),"=d"(d) : "c"(ctr) : );
+#else
+ a = d = 0;
+#endif
return a | (uint64_t(d) << 32);

#else // #elif defined (_WIN32) // other compiler. try inline assembly with masm/intel/MS syntax

   
patch: xgetbv on gcc<4.4
Author: Agner Date: 2014-04-22 23:37
This would disable the use of the AVX instruction set, which would be bad for the performance of your code. If the CPU has XGETBV but the compiler doesn't, then mayby you can use EMIT to generate the XGETBV instruction?
   
patch: xgetbv on gcc<4.4
Author:  Date: 2014-04-23 13:20
I think this is what you want. The __GNUC_PREREQ caused a Mac/clang problem. I've tested on Mac 10.9.2, RHEL5, and RHEL6.

diff --git a/instrset_detect.cpp b/instrset_detect.cpp
--- a/instrset_detect.cpp
+++ b/instrset_detect.cpp
@@ -54,7 +54,11 @@
#elif defined(__GNUC__) // use inline assembly, Gnu/AT&T syntax

uint32_t a, d;
+#if __GNUC__ > 4 || __GNUC__ == 4 && __GNUC_MINOR__ >= 4
__asm("xgetbv" : "=a"(a),"=d"(d) : "c"(ctr) : );
+#else
+ __asm(".byte 0x0f, 0x01, 0xd0" : "=a"(a),"=d"(d) : "c"(ctr) : );
+#endif
return a | (uint64_t(d) << 32);