build: verify that the assembler can handle crc32 functions #10806

pull theuni wants to merge 1 commits into bitcoin:master from theuni:configure-check-asm changing 2 files +26 −3
  1. theuni commented at 5:18 PM on July 12, 2017: member

    Also, enable crc32 even if -msse4.2 wasn't added by us, as long as it works. This allows custom flags (such as -march=native) to work as expected.

    Addresses #10670.

  2. gmaxwell approved
  3. gmaxwell commented at 7:55 PM on July 12, 2017: contributor

    utACK

  4. sipa commented at 8:09 PM on July 12, 2017: member

    @theuni I'm confused why the old code wouldn't build the sse library with the correct flags?

  5. fanquake added the label Build system on Jul 12, 2017
  6. theuni commented at 5:28 AM on July 13, 2017: member

    @sipa This addresses 2 things:

    1. Disables crc32 on platforms where the assembler can't handle it
    2. Enables crc32 if cflags/cxxflags are overridden but the intrinsics still work.

    I think 2 is what you're asking about? If so, it wouldn't work before because, even though the user has specified -msse4.2 (or -march=native, or whatever it takes to get the intrinsics working), our build wouldn't have the necessary make option set here: https://github.com/bitcoin/bitcoin/blob/master/src/Makefile.leveldb.include#L145, so the necessary define wouldn't be added.

  7. laanwj commented at 1:00 PM on July 13, 2017: member

    Going to test.

  8. laanwj commented at 3:32 PM on July 13, 2017: member

    Interesting. On OpenBSD 6.1:

    configure:18285: checking whether C++ compiler accepts -msse4.2  
    configure:18304: eg++ -std=c++11 -c -g -O2 -Wall -Wextra -Wformat -Wvla -Wformat-security -Wno-unused-parameter -Werror -msse4.2  conftest.cpp >&5
    configure:18304: $? = 0
    configure:18313: result: yes
    configure:18326: checking for assembler crc32 support  
    configure:18351: eg++ -std=c++11 -c -g -O2 -Wall -Wextra -Wformat -Wvla -Wformat-security -Wno-unused-parameter -msse4.2  conftest.cpp >&5
    conftest.cpp: In function 'int main()':
    conftest.cpp:34:14: warning: variable 'l' set but not used [-Wunused-but-set-variable]
         uint64_t l = 0;
                  ^
    configure:18351: $? = 0
    configure:18352: result: yes
    configure:20040: checking for pk
    

    Then when running gmake:

    leveldb/port/port_posix_sse.cc: In function 'uint32_t leveldb::port::AcceleratedCRC32C(uint32_t, const char*, size_t)':
    leveldb/port/port_posix_sse.cc:59:15: warning: 'ecx' may be used uninitialized in this function [-Wmaybe-uninitialized]
       return (ecx & (1 << 20)) != 0;
                   ^
    leveldb/port/port_posix_sse.cc:57:26: note: 'ecx' was declared here
       unsigned int eax, ebx, ecx, edx;
                              ^
    /tmp//cc5NhjN4.s: Assembler messages:
    /tmp//cc5NhjN4.s:95: Error: no such instruction: `crc32b -1(%rbp),%eax'
    /tmp//cc5NhjN4.s:121: Error: no such instruction: `crc32q -8(%rbp),%rax'
    /tmp//cc5NhjN4.s:148: Error: no such instruction: `crc32b -1(%rbp),%eax'
    :312: Error: no such instruction: `crc32l 0(%rbp),%eax'
    gmake[2]: *** [Makefile:4923: leveldb/port/leveldb_libleveldb_sse42_a-port_posix_sse.o] Error 1
    

    So somehow it works while running configure, but not while building confused.

  9. theuni commented at 4:01 PM on July 13, 2017: member

    @laanwj Grr, I checked an asm dump of the test to make sure that the crc32s are actually emitted, but it looks like I forgot to test with -O2. Indeed with optims on, they're optimized out. I'll add something to use the result.

  10. laanwj commented at 4:10 PM on July 13, 2017: member

    @theuni this solves it:

    diff --git a/configure.ac b/configure.ac
    index 5c3dac648..6b5d891fa 100644
    --- a/configure.ac
    +++ b/configure.ac
    @@ -262,9 +262,10 @@ AC_COMPILE_IFELSE([AC_LANG_PROGRAM([[
         #endif
       ]],[[
         uint64_t l = 0;
    -    l = _mm_crc32_u8(0, 0);
    -    l = _mm_crc32_u32(0, 0);
    -    l = _mm_crc32_u64(0, 0);
    +    l = _mm_crc32_u8(l, 0);
    +    l = _mm_crc32_u32(l, 0);
    +    l = _mm_crc32_u64(l, 0);
    +    return l;
       ]])],
      [ AC_MSG_RESULT(yes); enable_hwcrc32=yes],
      [ AC_MSG_RESULT(no)]
    
  11. theuni force-pushed on Jul 13, 2017
  12. build: verify that the assembler can handle crc32 functions
    Also, enable crc32 even if -msse4.2 wasn't added by us, as long as it works.
    This allows custom flags (such as -march=native) to work as expected.
    d34d77a51b
  13. theuni commented at 4:49 PM on July 13, 2017: member

    @laanwj Aha. I was messing with printf to force it to stay around, I didn't realize that the test function was "int main()". That makes total sense and is really good to know!

    Pushed with your fix.

  14. laanwj commented at 7:22 AM on July 14, 2017: member

    Tested ACK d34d77a

  15. laanwj merged this on Jul 14, 2017
  16. laanwj closed this on Jul 14, 2017

  17. laanwj referenced this in commit db825d293b on Jul 14, 2017
  18. sickpig referenced this in commit 2da740663b on Aug 17, 2017
  19. PastaPastaPasta referenced this in commit 1b866be7a9 on Jul 6, 2019
  20. PastaPastaPasta referenced this in commit f96259a74b on Jul 8, 2019
  21. PastaPastaPasta referenced this in commit 33099aa81d on Jul 9, 2019
  22. PastaPastaPasta referenced this in commit 38a51b8348 on Jul 11, 2019
  23. PastaPastaPasta referenced this in commit 546a983988 on Jul 13, 2019
  24. PastaPastaPasta referenced this in commit d529ce0f2d on Jul 17, 2019
  25. PastaPastaPasta referenced this in commit 934210fa76 on Jul 17, 2019
  26. PastaPastaPasta referenced this in commit a0ff957d18 on Jul 18, 2019
  27. barrystyle referenced this in commit 3d993a93c3 on Jan 22, 2020
  28. zkbot referenced this in commit 59d6a92e7d on Sep 22, 2020
  29. zkbot referenced this in commit 514d868179 on Sep 25, 2020
  30. DrahtBot locked this on Sep 8, 2021

github-metadata-mirror

This is a metadata mirror of the GitHub repository bitcoin/bitcoin. This site is not affiliated with GitHub. Content is generated from a GitHub metadata backup.
generated: 2026-04-13 18:15 UTC

This site is hosted by @0xB10C
More mirrored repositories can be found on mirror.b10c.me