How to use AVX/pclmulqdq on Mac OS X

后端 未结 5 1529
耶瑟儿~
耶瑟儿~ 2020-12-03 05:09

I am trying to compile a program that uses the pclmulqdq instruction present in new Intel processors. I\'ve installed GCC 4.6 using macports but when I compile my program (w

相关标签:
5条回答
  • 2020-12-03 05:26

    The built in version of as is outdated. (In OS X 10.8.3)

    /usr/libexec/as/x86_64/as -v

    Apple Inc version cctools-839, GNU assembler version 1.38

    There does not seem to exist a version of gas for OS X. (See: Installing GNU Assembler in OSX)

    Using the clang assembler via a script hack (as pointed out by Conrado PLG) is one workaround. However, it does require administrator privileges and overwrites OS X-bundled executables, causing a risk of it being overwritten by a new (yet possibly outdated) version of as bundled with a future version of OS X.

    Is there then a better workaround?

    As noted on Why does cross gcc invoke native 'as'? it seems to be possible to specify which "as"-executable and flags to use (using "-specs=..."). A cleaner workaround to the problem seems to be to pass the correct "-specs" flags to invoke the clang assembler. This does not require admin privileges and does not risk being broken by an OS X update. The exact details of how to perform this remains to be found out (anyone?).

    If this workaround becomes trouble-free and transparent enough, it may be warranted to use those settings as a default (or at least variant) for the macport gcc (so that it supports "-march=native" and the like). There is such as configure.args setting ("--with-as=${prefix}/bin/as", as seen in https://trac.macports.org/browser/trunk/dports/lang/gcc48/Portfile ), which could be replaced.

    0 讨论(0)
  • 2020-12-03 05:27

    A simpler solution that fixed this problem for me was adding -Wa,-q to the compiler flags. From the man pages for as (version 1.38):

    -q

         Use the clang(1) integrated assembler instead of the GNU based system assembler.

    The -Wa part passes it from the compiler driver to the assembler, much like -Wl passes arguments to the linker.

    0 讨论(0)
  • 2020-12-03 05:30

    The GNU assembler (GAS) is not supported in Mac OS X.

    In order to use AVX, I had to:

    • Install GCC using MacPorts;
    • Replace the native OS X assembler (/usr/bin/as) by a script which calls the clang assembler.
    • Compile the program with the installed GCC (e.g. gcc-mp-4.7)

    The strange thing is that while the clang assembler supports AVX, the clang compiler does not recognize the AVX instrinsics, forcing the ugly workaround above.

    0 讨论(0)
  • 2020-12-03 05:31

    Just use

    as --version

    AVX appeared around version 2.18.50 in gas/binutils.

    0 讨论(0)
  • 2020-12-03 05:35

    It appears that I fixed my issue by using the gcc / asm syntax where asm{} function is passed a string consisting of assembler statements surrounded by quotes and separated by a backslash and newline or backslash and quoted string containing another assembler statement.

    https://www.ibiblio.org/gferg/ldp/GCC-Inline-Assembly-HOWTO.html#s3

    0 讨论(0)
提交回复
热议问题