aklomp / base64

Fast Base64 stream encoder/decoder in C99, with SIMD acceleration
BSD 2-Clause "Simplified" License
865 stars 162 forks source link

build failure using mingw32: `error: 'asm' operand has impossible constraints` #131

Closed mayeut closed 7 months ago

mayeut commented 7 months ago

The assembly code fails to build on mingw32:

cmake -B out -Werror=dev -DBASE64_BUILD_TESTS=ON -DCMAKE_BUILD_TYPE=Release -DBASE64_WITH_AVX512=OFF
...
cmake --build out --config Release --verbose
Run Build Command(s): D:/a/_temp/msys64/mingw32/bin/ninja.exe -v
[1/18] D:\a\_temp\msys64\mingw32\bin\cc.exe -DBASE64_STATIC_DEFINE -ID:/a/base64/base64/include -ID:/a/base64/base64/out -O3 -DNDEBUG -std=c99 -Wall -Wextra -Wpedantic -Werror -mssse3 -MD -MT CMakeFiles/base64.dir/lib/arch/ssse3/codec.c.obj -MF CMakeFiles\base64.dir\lib\arch\ssse3\codec.c.obj.d -o CMakeFiles/base64.dir/lib/arch/ssse3/codec.c.obj -c D:/a/base64/base64/lib/arch/ssse3/codec.c
FAILED: CMakeFiles/base64.dir/lib/arch/ssse3/codec.c.obj 
D:\a\_temp\msys64\mingw32\bin\cc.exe -DBASE64_STATIC_DEFINE -ID:/a/base64/base64/include -ID:/a/base64/base64/out -O3 -DNDEBUG -std=c99 -Wall -Wextra -Wpedantic -Werror -mssse3 -MD -MT CMakeFiles/base64.dir/lib/arch/ssse3/codec.c.obj -MF CMakeFiles\base64.dir\lib\arch\ssse3\codec.c.obj.d -o CMakeFiles/base64.dir/lib/arch/ssse3/codec.c.obj -c D:/a/base64/base64/lib/arch/ssse3/codec.c
In file included from D:/a/base64/base64/lib/arch/ssse3/codec.c:29:
In function 'enc_loop_ssse3',
    inlined from 'base64_stream_encode_ssse3' at D:/a/base64/base64/lib/arch/ssse3/codec.c:42:2:
D:/a/base64/base64/lib/arch/ssse3/enc_loop_asm.c:160:9: error: 'asm' operand has impossible constraints
  160 |         __asm__ volatile (
      |         ^~~~~~~
[2/18] D:\a\_temp\msys64\mingw32\bin\cc.exe -DBASE64_STATIC_DEFINE -ID:/a/base64/base64/include -ID:/a/base64/base64/out -O3 -DNDEBUG -std=c99 -Wall -Wextra -Wpedantic -Werror -msse4.1 -MD -MT CMakeFiles/base64.dir/lib/arch/sse41/codec.c.obj -MF CMakeFiles\base64.dir\lib\arch\sse41\codec.c.obj.d -o CMakeFiles/base64.dir/lib/arch/sse41/codec.c.obj -c D:/a/base64/base64/lib/arch/sse41/codec.c
FAILED: CMakeFiles/base64.dir/lib/arch/sse41/codec.c.obj 
D:\a\_temp\msys64\mingw32\bin\cc.exe -DBASE64_STATIC_DEFINE -ID:/a/base64/base64/include -ID:/a/base64/base64/out -O3 -DNDEBUG -std=c99 -Wall -Wextra -Wpedantic -Werror -msse4.1 -MD -MT CMakeFiles/base64.dir/lib/arch/sse41/codec.c.obj -MF CMakeFiles\base64.dir\lib\arch\sse41\codec.c.obj.d -o CMakeFiles/base64.dir/lib/arch/sse41/codec.c.obj -c D:/a/base64/base64/lib/arch/sse41/codec.c
In file included from D:/a/base64/base64/lib/arch/sse41/codec.c:27:
In function 'enc_loop_ssse3',
    inlined from 'base64_stream_encode_sse41' at D:/a/base64/base64/lib/arch/sse41/codec.c:40:2:
D:/a/base64/base64/lib/arch/ssse3/enc_loop_asm.c:160:9: error: 'asm' operand has impossible constraints
  160 |         __asm__ volatile (
      |         ^~~~~~~
[3/18] D:\a\_temp\msys64\mingw32\bin\cc.exe -DBASE64_STATIC_DEFINE -ID:/a/base64/base64/include -ID:/a/base64/base64/out -O3 -DNDEBUG -std=c99 -Wall -Wextra -Wpedantic -Werror -MD -MT CMakeFiles/base64.dir/lib/codec_choose.c.obj -MF CMakeFiles\base64.dir\lib\codec_choose.c.obj.d -o CMakeFiles/base64.dir/lib/codec_choose.c.obj -c D:/a/base64/base64/lib/codec_choose.c
[4/18] D:\a\_temp\msys64\mingw32\bin\cc.exe -DBASE64_STATIC_DEFINE -ID:/a/base64/base64/include -ID:/a/base64/base64/out -O3 -DNDEBUG -std=c99 -Wall -Wextra -Wpedantic -Werror -MD -MT CMakeFiles/base64.dir/lib/tables/tables.c.obj -MF CMakeFiles\base64.dir\lib\tables\tables.c.obj.d -o CMakeFiles/base64.dir/lib/tables/tables.c.obj -c D:/a/base64/base64/lib/tables/tables.c
[5/18] D:\a\_temp\msys64\mingw32\bin\cc.exe -DBASE64_STATIC_DEFINE -ID:/a/base64/base64/include -ID:/a/base64/base64/out -O3 -DNDEBUG -std=c99 -Wall -Wextra -Wpedantic -Werror -MD -MT CMakeFiles/base64.dir/lib/lib.c.obj -MF CMakeFiles\base64.dir\lib\lib.c.obj.d -o CMakeFiles/base64.dir/lib/lib.c.obj -c D:/a/base64/base64/lib/lib.c
[6/18] D:\a\_temp\msys64\mingw32\bin\cc.exe -DBASE64_STATIC_DEFINE -ID:/a/base64/base64/include -ID:/a/base64/base64/out -O3 -DNDEBUG -std=c99 -Wall -Wextra -Wpedantic -Werror -MD -MT CMakeFiles/base64.dir/lib/arch/generic/codec.c.obj -MF CMakeFiles\base64.dir\lib\arch\generic\codec.c.obj.d -o CMakeFiles/base64.dir/lib/arch/generic/codec.c.obj -c D:/a/base64/base64/lib/arch/generic/codec.c
ninja: build stopped: subcommand failed.
aklomp commented 7 months ago

Hm, constraint errors happen when compiling the SSSE3 asm implementation on a 32-bit CPU, because 32-bit CPUs with SSE support do not have the same number of SIMD registers as 64-bit CPUs. (Such crazy hardware exists in the wild, for example the Atom N270.) It's a known limitation and therefore the asm implementation is only used when BASE64_WORDSIZE == 64.

So what I think is happening is that mingw32 somehow sets BASE64_WORDSIZE to 64, yet compiles code in 32-bit mode. That would mean that the cause is somewhere in this block. Could it be that mingw32 defines __x86_64__?

mayeut commented 7 months ago

Given Windows is targeted, I could check that #123 / #125 fixes the issue (only checked #125 but same underlying issue fixed by both PR).

aklomp commented 7 months ago

@mayeut #125 is now merged, can you confirm that it fixed this issue?

mayeut commented 7 months ago

Fixed by 88607feedaa57abd382d6ceb4b296629c6626f08