[llvm-dev] Problem about 128bit floating-point operations in x86 machines

Kyoungju Sim via llvm-dev llvm-dev at lists.llvm.org
Mon Dec 12 05:46:17 PST 2016


Hello,

I'm making a compiler utilizing LLVM.
Because I want the compiler to support 128bit floating-point operations, I
added the code for 128bit floating-point operations and tested these
operations in i686, x86_64, SPARCv8 and SPARCv9 machines.
Generated codes by LLVM operated normally when using x86_64, SPARCv8 and
SPARCv9 machines, but generated codes in a x86 machine produce wrong
result.

Because Clang supports __float128 type, I also tried to test using Clang
3.9 version.
However, I could not get the correct result of 128bit floating-point
operations using Clang.

For example, C source code that included operations of 128bit
floating-point is as follows:

#include <stdio.h>
#include <quadmath.h>

int main() {
    __float128 a = 3.14;
    char buf[128];

    quadmath_snprintf(buf, sizeof(buf), "%QE", -a);
    printf("%s\n", buf);
    quadmath_snprintf(buf, sizeof(buf), "%QE", a * 5.0);
    printf("%s\n", buf);
    quadmath_snprintf(buf, sizeof(buf), "%QE", a + 5.0);
    printf("%s\n", buf);

    return 0;
}


After compilation, the correct result of the compiled program must be

-3.140000E+00
1.570000E+01
8.140000E+00.


However, I could not get the right result from the program that compiled by
Clang 3.9.
(the result of the program that compiled by gcc 4.8.4 was correct)

I think that IR codes generated LLVM for 128bit floating-point operations
are not wrong, but assembly generated from LLVM IR codes produced wrong
result.
(: Because the compiled program produced the wrong result only in x86
machine)

How can I get the right result of 128bit floating-point operations using
LLVM?


[ Environments ]
- CPU: Intel(R) core(TM) i7-6700
- OS: Ubuntu 14.04 (32bit)
- LLVM target triple: i686-pc-linux-gnu
- LLVM version: LLVM 3.8 / LLVM 3.9
- Clang version: 3.9
(※ use gcc 4.8.4 for building LLVM & Clang)


Thank you. :)

Sincerely,
Stella
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-dev/attachments/20161212/f64dd362/attachment.html>


More information about the llvm-dev mailing list