Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^3: [C Question] Determine if gcc provides erfl() function

by Anonymous Monk
on Jun 02, 2015 at 14:14 UTC ( [id://1128779]=note: print w/replies, xml ) Need Help??


in reply to Re^2: [C Question] Determine if gcc provides erfl() function
in thread [C Question] Determine if gcc provides erfl() function

These functions are gcc builtins. They are optimised away. On linux, too. (Compile with -save-temps to see what is produced, or check the disassembly with objdump -d.)

To do a proper test, use separate compilation units.

/* test_isnanl.c */ #include <math.h> int test_isnanl(long double x) { return isnanl(x); }
And link: cc main.o test_isnanl.o -lm && ./a.out || FAIL

However, the above is not entirely future-proof either—it's defeated with link-time optimisation (-flto).
So perhaps it would be better to
#include <stdio.h> #include <stdlib.h> #include <math.h> int main(int argc, char *argv[]) { long double x = strtold(argv[1], NULL); printf("%d", isnanl(x)); printf("%Lf", erfl(x)); return 0; }

Finally, if you limit your scope to the usual gcc/clang, then there is the -fno-builtin option that will make your original test work as is. This might be the best option of all.

Replies are listed 'Best First'.
Re^4: [C Question] Determine if gcc provides erfl() function
by syphilis (Archbishop) on Jun 03, 2015 at 11:09 UTC
    Compile with -save-temps to see what is produced, or check the disassembly with objdump -d

    Christ !! ... this is starting to look very difficult to understand.
    What sort of fuck-brained system allows the use of erfl() in a C file, but not in an XS file ?

    I'm also starting to worry that even if I get it working right for Bingos' smoker, I'll get it wrong elsewhere ... to the extent that the Makefile.PL will abort the build, even though the build would have succeeded had it been allowed to continue. This would be unforgivable, IMO. (My intention is simply to abort the build if erfl is not available.)

    I *think* there's an option to ban certain smokers (and/or testers) from testing modules, or something like that ... so I might investigate that path instead.
    I've really got better things to do than spend my time trying to figure out how Bingos' NetBSD systems work (for some questionable meaning of "work").

    Thanks for the responses, guys - they're all appreciated and any hostility detected in this post is not directed towards any of them.

    Cheers,
    Rob

      ... so I might investigate that path instead.
      Why? From what I see, the smoker is working as intended. The functions are not available on that platform and trying to use them ends in failure.

      Standard C gives the specification for many functions; this allows the compiler to make optimizations. Such as replacing a memcpy() with immediate moves. Or replacing a printf() by puts(), etc. Or eliminating a function call that has no effect...

      What you need to test is the presence of a function *in the system library*. Thus, for the purpose of said test, you can (a) make a sufficiently complicated test, avoiding constants; (b) disable the compilers awareness of those functions by disabling c99 mode, or by using -fno-builtin.

      Gcc defines its internal builtins with the expectation that fallback is available. But if the libm is deficient... Using gnu tools on a non-gnu platform, you may run into problems like that.

        (a) make a sufficiently complicated test, avoiding constants

        Ok - I'll start with that, keeping the other options in mind.
        I'll reply to this post, giving details of the solution I used when I find that solution.

        Thanks for your input.

        Cheers,
        Rob

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1128779]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (4)
As of 2024-04-23 11:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found