Results 1 to 8 of 8

Thread: GCC inline assembly is a failure on a couple levels

  1. #1
    Join Date
    May 2012
    Posts
    547

    Default GCC inline assembly is a failure on a couple levels

    so first the foreword:

    i learned assembly as a hobby and find it suitable for my way of thinking (its not THAT hard to learn)
    anyway..

    few weeks ago i actually found a use for my knowledge in the form of writing an sse loop for an OSS program, that can not be written in other languages

    firstly ofc my plan was to write it in inline assembly
    my thought process was "i write it in nasm where i can debug and benchmark it, then i just copy/paste it"
    and ofc that plan failed fast

    the only problem with the plan was GCC's idea of what inline assembly is
    to be more precise, GCC's "we dont care about inline assembly"

    GCC inline asm by default is AT&T syntax, what is to be honest ugly
    they did add ".intel_syntax" switch, but you still have to put every instruction in quotes and append a "\n" at the end, what is utterly useless and again ugly
    (also probably incompatible with other compilers)

    to work with the incompatible GCC/GAS intel syntax you also have to append an ".noprefix" that eliminates the need for an AT&T "%" prefix infront of registers, something that should be implied with the ".intel_syntax" switch

    and to add insult to injury, you also have to put a ".att_syntax" at the end of your "intel syntax" inline assembly or the compiler wont compile the C/C++ code that comes after the inline part


    but thats not all;
    GCC/GAS inline assembly has the ugliest parameter passing (C code to asm code) known to exist
    and even using the just on paper intel syntax, the gcc ".intel_syntax", you cant even pass parameters at all (unless your implementing your code as a separate call, what im not)


    all this reasons make writing cross OS inline assembly one of the dumbest things you can think of, and it should/could be simple and really easy to do
    (icc and msvc use the sane/normal syntax and the most simple and easy parameter passing, icc even went out of their way to make it reasonably compatible with gcc's att syntax(dont know about M$))



    to be fair as i should be considering i use gcc and programs compiled with gcc;
    i did send an email at gcc@gcc.gnu.org explaining my problem and asking why is it like that when it should be much simpler
    what i got in return not a minute later was:

    Code:
    Hi. This is the qmail-send program at sourceware.org.
    I'm afraid I wasn't able to deliver your message to the following addresses.
    This is a permanent error; I've given up. Sorry it didn't work out.
    
    <gcc@gcc.gnu.org>:
    Invalid mime type "text/html" detected in message text or
    attachment.  Please send plain text messages only.
    i used standard ascii character set, not even unicode what everything today should support
    and ofc, i didnt attach anything to my email

    was it because i sent the email from my hotmail account i have since i was 14yo ?

    i have respect for anyone who can make an optimized compiler, but this is pure bullshit
    i wrote here as i dont know where else to write
    only other idea where to write about this was the gcc bug-list thingy, but it feels like it would be ignored there

    PS: to all those thinking this is some complicated and unsolvable problem, it is not
    the syntax problem could be solved with a sed script, only the parameter passing is a bit harder but shouldn't be that hard to do (idk C so i wont even look at the milion of GCC source code lines)

  2. #2
    Join Date
    Jul 2008
    Location
    Greece
    Posts
    3,798

    Default

    Quote Originally Posted by gens View Post
    but you still have to put every instruction in quotes and append a "\n" at the end, what is utterly useless and again ugly
    This should work:

    Code:
    void foo()
    {
        asm
        (
            ; write your assembly here, unescaped, unquoted
        );
    }

  3. #3
    Join Date
    Feb 2008
    Location
    Linuxland
    Posts
    5,186

    Default

    Quote Originally Posted by gens View Post
    to be fair as i should be considering i use gcc and programs compiled with gcc;
    i did send an email at gcc@gcc.gnu.org explaining my problem and asking why is it like that when it should be much simpler
    what i got in return not a minute later was:

    i used standard ascii character set, not even unicode what everything today should support
    and ofc, i didnt attach anything to my email

    was it because i sent the email from my hotmail account i have since i was 14yo ?
    Probably. Hotmail is a crap service, I wouldn't be surprised in the least if it always sends HTML without an option to turn it off.

  4. #4
    Join Date
    May 2012
    Posts
    547

    Default

    Quote Originally Posted by RealNC View Post
    This should work:

    Code:
    void foo()
    {
        asm
        (
            ; write your assembly here, unescaped, unquoted
        );
    }
    Code:
    void foo()
    {
        asm
            (
            jmp labelll
            xor eax, eax
            labelll:
            mov eax, eax
                    ; write your assembly here, unescaped, unquoted
            );
    }
    temp.c: In function ‘foo’:
    temp.c:5:9: error: expected string literal before ‘jmp’


    probably the same with ".intel_syntax" and all that, i tried all the combinations i could think of
    (there is no documentation on this, unless its burried somewhere deep)

  5. #5
    Join Date
    Jul 2008
    Location
    Greece
    Posts
    3,798

    Default

    Yep, you're right. It's been ages since I tried inline assembly. I remember that it worked like that when using extended asm, but apparently I remember wrong.

  6. #6
    Join Date
    May 2012
    Posts
    547

    Default

    it is that easy to do it in m$vc and icc, but gcc has to do it its own way
    and since inline assembly is not standardized, nobody cares

    all this is weird for me since you have to know plenty of low level things to write/debug/improve an optimizing compiler
    that makes this kinda ironic really

  7. #7
    Join Date
    Sep 2012
    Posts
    358

    Default

    You can also use sse intrinsics.

  8. #8
    Join Date
    May 2012
    Posts
    547

    Default

    Quote Originally Posted by JS987 View Post
    You can also use sse intrinsics.
    i am using sse intrinsics and have 3 problems with it

    1.i cant make the loop as i want to make it; althou the gain would be a few kB and some .1% so this is not such a big problem
    2.what the loop does is complicated enough without thinking what the compiler will do
    the loop needs minimum 8 sse registers, and if the compiler messes up 1 step or i do 1 step wrong(as intrinsics adds "mov" steps) then comes register spilling (check the phoronix post on gcc's new register allocator)
    3.debugging is hard as its all jumbled up

    so i make one version in assembly then redo it in intrinsics, but i still depend on the compiler doing register allocation right

    also http://gcc.gnu.org/bugzilla/show_bug.cgi?id=19680
    that should change with gcc 4.8, i repeat "should"

    and in the end i like assembly and find it easy to test its speed and correctness in small loops
    why should i do it in intrinsics anyway when theres inline; that is "why is there inline there if its useless and ugly"

    and again, i would file a bug report on it but i feel it would surely be ignored as there is no ISO standard on inline assembly
    Last edited by gens; 11-12-2012 at 10:58 AM.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •