Closed jaganmn closed 1 week ago
Looks like you are using Clang, so you should be using longlong_asm_clang.h
. Can you confirm this? (You can do some bogus inside that header file to generate an error to see that you are using this.)
If this is the case, we are only using builtins for sub_dddmmmsss
such as __builtin_subcl
. Therefore I suspect a compiler bug. Do you use XCode or something as well? Could you give us the version string for Clang along with XCode?
Yes, I am using the native Clang from Apple's Command Line Tools for Xcode 14.3.1.
$ pkgutil --pkg-info=com.apple.pkg.CLTools_Executables
package-id: com.apple.pkg.CLTools_Executables
version: 14.3.1.0.1.1683849156
volume: /
location: /
install-time: 1707543067
$ clang --version
Apple clang version 14.0.3 (clang-1403.0.22.14.1)
Target: arm64-apple-darwin22.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
$ make
CC generic_files/clz_tab.c
In file included from src/generic_files/clz_tab.c:27:
In file included from ./src/flint.h:197:
In file included from ./src/longlong.h:54:
./src/longlong_asm_clang.h:15:2: error: "using longlong_asm_clang.h"
#error "using longlong_asm_clang.h"
^
1 error generated.
make: *** [Makefile:616: build/generic_files/clz_tab.lo] Error 1
Could you try with the main branch? I don't know what else to do as both of our macOS runners passes the tests (https://github.com/flintlib/flint/actions/runs/10020998926/job/27699172814 and https://github.com/flintlib/flint/actions/runs/10020998926/job/27699172881).
Still failing on the main branch. I'll try upgrading my toolchain to get a version closer to the runner's ...
Yeah, please update us if you get the chance. As you may see, it seemingly fails to subtract the last borrow via sub_dddmmmsss
, which would be pretty severe.
What version of GMP are you using?
All tests pass after upgrading my toolchain and making static the d_randtest2
in double_interval.h
. I've been building against the latest GMP 6.3.0 and MPFR 4.2.1.
$ pkgutil --pkg-info=com.apple.pkg.CLTools_Executables
package-id: com.apple.pkg.CLTools_Executables
version: 15.3.0.0.1.1708646388
volume: /
location: /
install-time: 1724853172
$ clang --version
Apple clang version 15.0.0 (clang-1500.3.9.4)
Target: arm64-apple-darwin23.6.0
Thread model: posix
InstalledDir: /Library/Developer/CommandLineTools/usr/bin
Okay, I will check the generated assembly. Do the following:
#include <gmp.h>
into src/test/t-sub_dddmmmsss.c
.CC
, TESTCFLAGS
and CPPFLAGS
into your shell environment.${CC} ${TESTCFLAGS} ${CPPFLAGS} -S -fverbose-asm src/test/t-sub_dddmmmsss.c -o t-sub_dddmmmsss.s
t-sub_dddmmmsss.s
here, or mail it to me (you can find my email in the README).I strongly suspect Clang generates something wrong here. If not, it should at least show why the wrong result is obtained.
By the way, how did you obtain GMP? Did you build from source? If true, did you check the build?
I have been building GMP and MPFR from sources, in both cases with CFLAGS
containing:
-g -O2 -mmacosx-version-min=`sw_vers --productVersion | sed 's/\..*/.0/'` -march=native -falign-functions=8 -fpic
Both builds passed their checks. FLINT passed its checks only when built with the newer Clang. As requested:
old_t-sub_dddmmmsss.s.txt new_t-sub_dddmmmsss.s.txt
I can regenerate the assembly with fewer obfuscating flags, if needed ...
Alright, I believe this is 100% a compiler bug. Let me explain why.
As pointed to by the verbose assembly for sub_dddmmmsss
starts at line 181 in both files. These correspond to
str b2, [bp, #16] ; b2 already in register
ldp a0, a1, [ap]
ldp b0, b1, [bp]
subs s0, a0, b0
sbcs s1, a1, b1
cset R32(cy), FLAG
ldr a2, [ap, #16]
sub a2, a2, b2
sub s2, a2, cy
However, the only thing that differs is FLAG
. On the newer toolchain, it is lo
(i.e. cc
), which is the correct flag for subtraction with borrow. However, on the older one, it is hs
(i.e. cs
), which is not correct for this operation (it would be correct if we would do an addition with carry, however).
So this is 100% a compiler bug.
I will close this. Feel free to reopen if you believe it still comes from us.