Quantcast
Channel: Active questions tagged gcc - Stack Overflow
Viewing all articles
Browse latest Browse all 22176

Early-clobbers and named registers

$
0
0

I'm trying to understand the usage of "early-clobber outputs" but I stumbled upon a snipped which confuses me. Consider the following multiply-modulo function:

static inline uint64_t mulmod64(uint64_t a, uint64_t b, uint64_t n)
{
    uint64_t d;
    uint64_t unused;
    asm ("mulq %3\n\t""divq %4"
         :"=a"(unused), "=&d"(d)
         :"a"(a), "rm"(b), "rm"(n)
         :"cc");
    return d;
}

Why has RDX the early-clobber flag (&)? Is it because mulq implicitly modified RDX? Would the example work without the flag? (I tried and it seems it does. But would it be correct as well?) On the other had, isn't it enough that the function outputs RDX to tell the compiler RDX was modified?

Also, why there is that unused variable? I assume it's there to denote that RAX was modified, correct? Can I remove it? (I tried and it seems to work.) I would have expected the correct way of marking the modified RAX is by including "rax" to "clobbers", along with "cc". But that does not work.


Viewing all articles
Browse latest Browse all 22176

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>