On Jan 25, 2013, at 1:19 AM, Albert Chun-Chieh Huang <alberthuang...@gmail.com> wrote: > After digging into this issue, I found an answer on MacPorts list, and > it's related to Apple's ancient assembler(version 1.38). In this post, > they try to replace Apple /usr/bin/as by clang's assembler. > > http://lists.macosforge.org/pipermail/macports-dev/2011-October/016335.html > > I tried this approach to compile gnuradio with gcc 4.7, it's still not > successful. But it seems to be an interesting and possible way -- to use > clang's assembler to optimize for AVX on MacOSX. GNU binutil on MacOSX > does not come with GNU assembler, so gcc 4.7 on MacOSX uses the built-in > GNU assembler, which is very old and does not support AVX. Only clang's > assembler on MacOSX provides support to AVX instruction set.
Hi Albert - Nice sleuthing! I don't generally read the MacPorts developers' list emails unless they are addressed to me; hence, that thread slipped through my reading. It seems like this issue has multiple parts: 1) Does the target compiler's assembler support the "xgetbv" instruction? 2) Does the target CPU support the "xgetbv" instruction? Here's my "hack" attempt. Add the following code to lib/volk/CMakeLists.txt:132 {{{ if(CPU_IS_x86) execute_process(COMMAND ${CMAKE_C_COMPILER} -o ${CMAKE_CURRENT_BINARY_DIR}/temp ${CMAKE_CURRENT_SOURCE_DIR}/test_xgetbv.c OUTPUT_QUIET ERROR_QUIET RESULT_VARIABLE avx_compile_result) if(NOT ${avx_compile_result} EQUAL 0) OVERRULE_ARCH(avx "Compiler missing xgetbv") else() message(STATUS "Executing temp") execute_process(COMMAND ${CMAKE_CURRENT_BINARY_DIR}/temp OUTPUT_QUIET ERROR_QUIET RESULT_VARIABLE avx_exe_result) if(NOT ${avx_exe_result} EQUAL 0) OVERRULE_ARCH(avx "CPU missing xgetbv") endif() endif() file(REMOVE ${CMAKE_CURRENT_BINARY_DIR}/temp) endif() }}} and add the file lib/volk/test_xgetbv.c : {{{ static inline unsigned long long _xgetbv(unsigned int index) { unsigned int eax, edx; __asm__ __volatile__("xgetbv" : "=a"(eax), "=d"(edx) : "c"(index)); return ((unsigned long long)edx << 32) | eax; } int main (void) { (void) _xgetbv(0); return (0); } }}} I tried to do this solely in cmake using "file(WRITE …)", but it never wrote the file (latest cmake, btw). Hence, using a separate file for the test. On my system, this test result in cmake output "Compiler missing xgetbv, Overruled arch avx" which is as desired. If I switch the __asm__ line to instead read: {{{ __asm__ (".byte 0x0f, 0x01, 0xd0" : "=a"(eax), "=d"(edx) : "c"(index)); }}} then this test results in "CPU missing xgetbv, Overruled arch avx", which is again as desired. It would also be good for someone to test this on a system which -does- support xgetbv to make sure it works successfully. I'll let the VOLK-powers-that-be determine if this test makes any sense to include, or something like it, but IMHO it's wiser to actually -test- for a feature when reasonably possible rather than assume it based on standard information such as program version. :) - MLD _______________________________________________ Discuss-gnuradio mailing list Discuss-gnuradio@gnu.org https://lists.gnu.org/mailman/listinfo/discuss-gnuradio