Thread (1 message) 1 message, 1 author, 2016-06-15

Re: [PATCH 2/8] compat: make gcc bswap an inline function

From: Junio C Hamano <hidden>
Date: 2016-06-15 22:50:47

Jonathan Nieder [off-list ref] writes:
Johannes Sixt wrote:
quoted
Am 3/16/2011 8:00, schrieb Jonathan Nieder:
quoted
quoted
+static inline uint32_t git_bswap32(uint32_t x)
+{
+	uint32_t result;
+	if (__builtin_constant_p(x))
Can this predicate ever be true? Isn't it false even if the function is
inlined?
It's true if x is a constant.
... demonstration ...
And this trivial function:

    int f(void) {
            return git_bswap32(0x01000000);
    }

compiles down to:

    .globl f
            .type   f, @function
    f:
    .LFB2:
            .cfi_startproc
            movl    $1, %eax
            ret
            .cfi_endproc

on my amd64, with -Os, -O1, or -O2 (gcc 4.4.5). Of course -O0 gives a true
call to git_bswap32() and leaves the definitions of two helper functions
in the object, but that is to be expected.
Keyboard shortcuts
hback out one level
jnext message in thread
kprevious message in thread
ldrill in
Escclose help / fold thread tree
?toggle this help