I looked at disassembly with

> +__attribute__((optimize("no-builtin-sin")))
> +__attribute__((optimize("no-builtin-cos")))
> +__attribute__((optimize("no-builtin-sincos")))
>  void sincos(double x, double *sx, double *cx)

on gcc version 4.9.1 and irritatingly the __attribute__ does not inhibit
the transformation to a sincos call.  Nor does #pragma GCC optimize.
Only a commandline flag does the job.

The same goes for gcc 4.6, 4.7 and 4.8 all as packaged by Debian.

So my proposed patch doesn't seem likely to work out.  Even if the gcc
folks viewed this as a bug and fixed it tomorrow, we'd still have years
of debian/ubuntu releases to support that behave like this.

Methodology:  with the following contents in sc.c

/* ****************************************************** */
extern double sin(double);
extern double cos(double);

#ifdef USE_PRAGMA_FREESTANDING
#pragma GCC optimize "freestanding"
#endif

#ifdef USE_PRAGMA_NO_BUILTIN
#pragma GCC optimize "no-builtin-sin"
#pragma GCC optimize "no-builtin-cos"
#pragma GCC optimize "no-builtin-sincos"
#endif

#ifdef USE_ATTRIBUTE_FREESTANDING
__attribute__((optimize("freestanding")))
#endif

#ifdef USE_ATTRIBUTE_NO_BUILTIN
__attribute__((optimize("no-builtin-sin")))
__attribute__((optimize("no-builtin-cos")))
__attribute__((optimize("no-builtin-sincos")))
#endif

void fn(double x, double *sx, double *cx) {
    *sx = sin(x);
    *cx = cos(x);
}
/* ****************************************************** */

build using various compilers and flags:

    set -o pipefail
    for cc in gcc-4.6 gcc-4.7 gcc-4.8 gcc-4.9 clang-3.4 clang-3.5; do
        for opt in -ffreestanding -fno-builtin-sin -DUSE_PRAGMA_FREESTANDING \
                -DUSE_PRAGMA_NO_BUILTIN -DUSE_ATTRIBUTE_FREESTANDING \
                -DUSE_ATTRIBUTE_NO_BUILTIN; do
            echo -n $cc - $opt ""
            if $cc -O -Wall -m64 $opt -S -o- sc.c | grep -q sincos; then
                echo "BAD"
            else
                echo "GOOD"
            fi
        done
        echo
    done

this inspects the assembly for having the string 'sincos' in it, presumably a
'call sincos'.  I got the following output:

4.6 - -ffreestanding GOOD
4.6 - -fno-builtin-sin GOOD
4.6 - -DUSE_PRAGMA_FREESTANDING BAD
4.6 - -DUSE_PRAGMA_NO_BUILTIN BAD
4.6 - -DUSE_ATTRIBUTE_FREESTANDING BAD
4.6 - -DUSE_ATTRIBUTE_NO_BUILTIN BAD

4.7 - -ffreestanding GOOD
4.7 - -fno-builtin-sin GOOD
4.7 - -DUSE_PRAGMA_FREESTANDING BAD
4.7 - -DUSE_PRAGMA_NO_BUILTIN BAD
4.7 - -DUSE_ATTRIBUTE_FREESTANDING BAD
4.7 - -DUSE_ATTRIBUTE_NO_BUILTIN BAD

4.8 - -ffreestanding GOOD
4.8 - -fno-builtin-sin GOOD
4.8 - -DUSE_PRAGMA_FREESTANDING BAD
4.8 - -DUSE_PRAGMA_NO_BUILTIN BAD
4.8 - -DUSE_ATTRIBUTE_FREESTANDING BAD
4.8 - -DUSE_ATTRIBUTE_NO_BUILTIN BAD

4.9 - -ffreestanding GOOD
4.9 - -fno-builtin-sin GOOD
4.9 - -DUSE_PRAGMA_FREESTANDING BAD
4.9 - -DUSE_PRAGMA_NO_BUILTIN BAD
4.9 - -DUSE_ATTRIBUTE_FREESTANDING BAD
4.9 - -DUSE_ATTRIBUTE_NO_BUILTIN BAD

Additionally, the #pragma and __attribute__ directives suggested trigger
warnings under clang 3.3, 3.4 and 3.5 (-Wunknown-pragmas and
-Wunknown-attributes / -Wattributes).  However, no version of clang that
I tested performed the transformation to sincos either.

Here's another alternative that seems to work everywhere:
    #ifdef USE_ASM_TRICKERY
    extern double sin_(double) __asm__("sin");
    #define sin sin_
    #endif    
I can't say I'm thrilled about this one either.

I'd love to hear what anybody else thinks is the best choice in this
mess.  In particular, can anybody identify a problem with Michael's
original suggestion to add 
    -fno-builtin-sincos -fno-builtin-sin -fno-builtin-cos
(or alternately to add -ffreestanding) to the realtime build flags?

(for i386 and for uspace, the flag is not needed afaik; that's the core
of why I'm reluctant to apply it unconditionally, I think)

Jeff

------------------------------------------------------------------------------
Meet PCI DSS 3.0 Compliance Requirements with EventLog Analyzer
Achieve PCI DSS 3.0 Compliant Status with Out-of-the-box PCI DSS Reports
Are you Audit-Ready for PCI DSS 3.0 Compliance? Download White paper
Comply to PCI DSS 3.0 Requirement 10 and 11.5 with EventLog Analyzer
http://p.sf.net/sfu/Zoho
_______________________________________________
Emc-developers mailing list
Emc-developers@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/emc-developers

Reply via email to