Clean powers of ten, how

hi @all,

I’d like to get ( need ) correct! integer powers of 10 with fp80 precision, e.g. ‘powl( 10, i )’, ‘pow10l( i )’, ‘10^i’ or ‘10**i’ with ‘i’ being an integer between -4951 and 4932. AFAIS nearly all compilers are ‘weak’ and fail for some to plenty values to produce IEEE 754 compliant ‘nearest’.

By chance I stumbled over exactly 1 exception, Intel icpx or dpcpp calculate good values when I use ‘exp10l( i )’ in the code. They call clang++ with a huge bunch of options from which ‘-cc1’ and ‘-x c++’ look relevant to me. ‘-cc1’ seems somewhat ‘special’ / sophisticated, that’s why I ask for help.

  • Can I achieve the ‘good’ computation for 'exp10l( i ) that is done with ‘-cc1’ in other modes? how?
  • Can I compile a library with ‘-cc1’ that provides functions declared with ‘external C’ that I can use from ‘pure C’ programs? how?
  • Can someone explain the difference that clang++ makes with or without ‘cc1’, and show how / where I can find the respective code that is used for ‘exp10l’?

long story:

for a project compiled with gcc i need good powers of ten for rounding. Since powl( 10, i ) and pow10l( i ) produce some errors ( rounding error in the last bit, different results from ‘1Ei’), I searched around and by chance found Intel icpx which gives better results. It uses clang++ with - among many others - the options ‘-cc1’ and ‘-x c++’.

Despite diligent searching, I have not yet been able to achieve the quality of these results in other compilers, nor have I been able to create a library with clang++ that I can call from other programs (‘external C’). (Library in principle is possible, but not together with ‘cc1’).

I have now read in llvm/llvm-project/llvm/lib/Analysis/TargetLibraryInfo.cpp:

case Triple::Linux:
    // exp10, exp10f, exp10l is available on Linux (GLIBC) but are extremely
    // buggy prior to glibc version 2.18. Until this version is widely deployed
    // or we have a reasonable detection strategy, we cannot use exp10 reliably
    // on Linux.

but don’t know how far this is still valid (in some files I could find with ‘nm’ that clang with ‘-cc1’ simply calls ‘exp10l’ - good results, while other compilers use ‘exp10l@GLIC_2.2.5’ - bad results).

Since I just want to use this without writing a thesis about compiler options or insufficient implementations or the secrets of ‘cc1’ three questions:

  • Can I achieve the ‘good’ computation for 'exp10l( i ) that is done with ‘cc1’ in other modes? how?
  • Can I compile a library with ‘cc1’ that provides functions declared with ‘external C’ that I can use from ‘pure C’ programs? how?
  • Can someone explain the difference that clang++ makes with or without ‘cc1’, and show how / where I can find the code that is used for ‘exp10l’ vs. ‘exp10l@GLIBC_2.2.5’?

Best Regards, TIA for any help,

b.

You probably should start there: Frequently Asked Questions (FAQ) — Clang 13 documentation ; this touches on what cc1 is.

You can also try to take a usual clang invocation (without -cc1) and add -v to see that this invocation of the clang driver will fork/exec into a cc1 invocation.

Also, any option to be passed to cc1 that isn’t available/exposed by the driver can just be passed through with -Xclang <option>, for example on my machine:

$ clang -Xclang -foobar /tmp/main.c -v
Debian clang version 11.1.0-4+build1

“/usr/lib/llvm-11/bin/clang” -cc1 -triple x86_64-pc-linux-gnu -emit-obj -mrelax-all -disable-free -disable-llvm-verifier -discard-value-names -main-file-name main.c -mrelocation-model static -mframe-pointer=all -fmath-errno -fno-rounding-math -mconstructor-aliases -munwind-tables -target-cpu x86-64 -fno-split-dwarf-inlining -debugger-tuning=gdb -v -resource-dir /usr/lib/llvm-11/lib/clang/11.1.0 -internal-isystem /usr/local/include -internal-isystem /usr/lib/llvm-11/lib/clang/11.1.0/include -internal-externc-isystem /usr/include/x86_64-linux-gnu -internal-externc-isystem /include -internal-externc-isystem /usr/include -fdebug-compilation-dir /usr/local/google/home/aminim/projects/export-llvm-project -ferror-limit 19 -fgnuc-version=4.2.1 -fcolor-diagnostics -foobar -faddrsig -o /tmp/main-3c1cce.o -x c /tmp/main.c