flintlib / flint

FLINT (Fast Library for Number Theory)
http://www.flintlib.org
GNU Lesser General Public License v3.0
422 stars 239 forks source link

`make check` failing at `sub_dddmmmsss` under macOS (aarch64-apple-darwin22.6.0) #2048

Closed jaganmn closed 1 week ago

jaganmn commented 3 weeks ago
$ tar -x -f flint-3.1.3.tar.xz
$ cd flint-3.1.3
$ LIBTOOLIZE=glibtoolize ./bootstrap.sh
autoreconf: export WARNINGS=all
autoreconf: Entering directory '.'
autoreconf: configure.ac: not using Gettext
autoreconf: running: aclocal --force 
autoreconf: configure.ac: tracing
autoreconf: running: glibtoolize --copy --force
glibtoolize: putting auxiliary files in AC_CONFIG_AUX_DIR, 'config'.
glibtoolize: copying file 'config/ltmain.sh'
glibtoolize: Consider adding 'AC_CONFIG_MACRO_DIRS([m4])' to configure.ac,
glibtoolize: and rerunning glibtoolize and aclocal.
glibtoolize: Consider adding '-I m4' to ACLOCAL_AMFLAGS in Makefile.am.
autoreconf: configure.ac: not using Intltool
autoreconf: configure.ac: not using Gtkdoc
autoreconf: running: aclocal --force 
autoreconf: running: /usr/local/bin/autoconf --force
autoreconf: running: /usr/local/bin/autoheader --force
autoreconf: configure.ac: not using Automake
autoreconf: Leaving directory '.'
$ ./configure --disable-assembly
checking build system type... aarch64-apple-darwin22.6.0
checking host system type... aarch64-apple-darwin22.6.0
checking how to print strings... printf
checking for gcc... gcc
checking whether the C compiler works... yes
checking for C compiler default output file name... a.out
checking for suffix of executables... 
checking whether we are cross compiling... no
checking for suffix of object files... o
checking whether the compiler supports GNU C... yes
checking whether gcc accepts -g... yes
checking for gcc option to enable C11 features... none needed
checking for a sed that does not truncate output... /usr/bin/sed
checking for grep that handles long lines and -e... /usr/bin/grep
checking for egrep... /usr/bin/grep -E
checking for fgrep... /usr/bin/grep -F
checking for ld used by gcc... /Library/Developer/CommandLineTools/usr/bin/ld
checking if the linker (/Library/Developer/CommandLineTools/usr/bin/ld) is GNU ld... no
checking for BSD- or MS-compatible name lister (nm)... /usr/bin/nm -B
checking the name lister (/usr/bin/nm -B) interface... BSD nm
checking whether ln -s works... yes
checking the maximum length of command line arguments... 786432
checking how to convert aarch64-apple-darwin22.6.0 file names to aarch64-apple-darwin22.6.0 format... func_convert_file_noop
checking how to convert aarch64-apple-darwin22.6.0 file names to toolchain format... func_convert_file_noop
checking for /Library/Developer/CommandLineTools/usr/bin/ld option to reload object files... -r
checking for file... file
checking for objdump... objdump
checking how to recognize dependent libraries... pass_all
checking for dlltool... no
checking how to associate runtime and link libraries... printf %s\n
checking for ar... ar
checking for archiver @FILE support... no
checking for strip... strip
checking for ranlib... ranlib
checking for gawk... no
checking for mawk... no
checking for nawk... no
checking for awk... awk
checking command to parse /usr/bin/nm -B output from gcc object... ok
checking for sysroot... no
checking for a working dd... /usr/local/bin/dd
checking how to truncate binary pipes... /usr/local/bin/dd bs=4096 count=1
checking for mt... no
checking if : is a manifest tool... no
checking for dsymutil... dsymutil
checking for nmedit... nmedit
checking for lipo... lipo
checking for otool... otool
checking for otool64... no
checking for -single_module linker flag... yes
checking for -exported_symbols_list linker flag... yes
checking for -force_load linker flag... yes
checking for stdio.h... yes
checking for stdlib.h... yes
checking for string.h... yes
checking for inttypes.h... yes
checking for stdint.h... yes
checking for strings.h... yes
checking for sys/stat.h... yes
checking for sys/types.h... yes
checking for unistd.h... yes
checking for dlfcn.h... yes
checking for objdir... .libs
checking if gcc supports -fno-rtti -fno-exceptions... yes
checking for gcc option to produce PIC... -fno-common -DPIC
checking if gcc PIC flag -fno-common -DPIC works... yes
checking if gcc static flag -static works... no
checking if gcc supports -c -o file.o... yes
checking if gcc supports -c -o file.o... (cached) yes
checking whether the gcc linker (/Library/Developer/CommandLineTools/usr/bin/ld) supports shared libraries... yes
checking dynamic linker characteristics... darwin22.6.0 dyld
checking how to hardcode library paths into programs... immediate
checking whether stripping libraries is possible... yes
checking if libtool supports shared libraries... yes
checking whether to build shared libraries... yes
checking whether to build static libraries... yes
checking for a race-free mkdir -p... /usr/local/bin/mkdir -p
checking for inline... inline
checking whether byte ordering is bigendian... no
checking if memory is strongly-ordered... unsure
checking how to run the C preprocessor... gcc -E
checking for gmp.h... yes
checking if version of GMP is greater than 6.2.1... yes
checking if GMP defines mp_limb_t as unsigned long long int... no
checking for mpfr.h... yes
checking if version of MPFR is greater than 4.1.0... yes
checking for desired ABI... 64
checking for stdarg.h... yes
checking for math.h... yes
checking for float.h... yes
checking for errno.h... yes
checking for fenv.h... yes
checking for alloca.h... yes
checking for malloc.h... no
checking for sys/param.h... yes
checking for windows.h... no
checking for pthread_np.h... no
checking for pthread.h... yes
checking for library containing atan2... none required
checking for library containing __gmpz_init... -lgmp
checking for library containing __gmpn_gcd_11... none required
checking for library containing __gmpn_div_q... none required
checking for library containing __gmpn_mul_basecase... none required
checking for library containing __gmpn_modexact_1_odd... no
checking for library containing __gmpn_addmul_2... no
checking for library containing mpfr_init... -lmpfr
checking for library containing mpfr_round_p... none required
checking for library containing mpfr_mulhigh_n... none required
checking for library containing mpfr_sqrhigh_n... none required
checking whether gcc accepts -pthread... yes
checking if cpu_set_t is supported... no
checking if alloca works... yes
checking for aligned_alloc... yes
checking for _aligned_malloc... no
checking whether gcc accepts -Werror=unknown-warning-option... yes
checking whether gcc accepts -Wall... yes
checking whether gcc accepts -Wno-stringop-overread... no
checking whether gcc accepts -Wno-stringop-overflow... no
checking whether gcc accepts -Werror=implicit-function-declaration... yes
checking whether gcc accepts -O3... yes
checking whether gcc accepts -march=native... yes
checking whether gcc accepts -std=c11... yes
checking whether gcc accepts -pedantic... yes
checking for host architecture... apple-m1
checking for arm_neon.h... yes
checking if system have required Arm instruction set for fft_small... yes
checking if system can use FLINT's fft_small module... yes
configure: creating ./config.status
config.status: creating src/gmpcompat.h
config.status: creating src/fft_tuning.h
config.status: creating src/fmpz/fmpz.c
config.status: creating Makefile
config.status: creating flint.pc
config.status: creating src/flint.h
config.status: creating src/config.h
config.status: creating src/flint-config.h
config.status: executing libtool commands
$ make
<...>
$ make check
  CC  test/main.c
add_ssaaaa...
add_ssaaaa                                        0.01   (PASS)
add_sssaaaaaa...
add_sssaaaaaa                                     0.03   (PASS)
add_ssssaaaaaaaa...
add_ssssaaaaaaaa                                  0.03   (PASS)
byte_swap...
byte_swap                                         0.00   (PASS)
flint_clz...
flint_clz                                         0.00   (PASS)
flint_ctz...
flint_ctz                                         0.00   (PASS)
flint_fprintf...
flint_fprintf                                     0.00   (PASS)
flint_printf...
flint_printf                                          (SKIPPED)
memory_manager...
memory_manager                                    0.00   (PASS)
sdiv_qrnnd...
sdiv_qrnnd                                        0.01   (PASS)
smul_ppmm...
smul_ppmm                                         0.01   (PASS)
sub_dddmmmsss...
sub_dddmmmsss                                     0.00   (FAIL)
a[2] = 22630, a[1] = 132912939, a[0] = 3
b[2] = 387565, b[1] = 27284933481435, b[0] = 36930710888
s[2] = 18446744073709186681, s[1] = 18446716788908983119, s[0] = 18446744036778840731
t[2] = 18446744073709186680, t[1] = 18446716788908983119, t[0] = 18446744036778840731
make: *** [Makefile:751: build/test/main_TEST_RUN] Abort trap: 6
albinahlback commented 3 weeks 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?

jaganmn commented 2 weeks ago

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
albinahlback commented 2 weeks ago

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).

jaganmn commented 2 weeks ago

Still failing on the main branch. I'll try upgrading my toolchain to get a version closer to the runner's ...

albinahlback commented 2 weeks ago

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?

jaganmn commented 2 weeks ago

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
albinahlback commented 1 week ago

Okay, I will check the generated assembly. Do the following:

  1. Prepend #include <gmp.h> into src/test/t-sub_dddmmmsss.c.
  2. Check the variables in the Makefile, and load CC, TESTCFLAGS and CPPFLAGS into your shell environment.
  3. Standing in the top directory, run
    ${CC} ${TESTCFLAGS} ${CPPFLAGS} -S -fverbose-asm src/test/t-sub_dddmmmsss.c -o t-sub_dddmmmsss.s
  4. Either upload t-sub_dddmmmsss.s here, or mail it to me (you can find my email in the README).
albinahlback commented 1 week ago

I strongly suspect Clang generates something wrong here. If not, it should at least show why the wrong result is obtained.

albinahlback commented 1 week ago

By the way, how did you obtain GMP? Did you build from source? If true, did you check the build?

jaganmn commented 1 week ago

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 ...

albinahlback commented 1 week ago

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.

albinahlback commented 1 week ago

I will close this. Feel free to reopen if you believe it still comes from us.