Re: [PATCH 2/8] compat: make gcc bswap an inline function
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Mar 16, 2011, 19:44 UTC
- Message-ID
- <7v8vwe97f9.fsf@alter.siamese.dyndns.org>
- In-Reply-To
- <20110316093108.GB7886@elie>
Jonathan Nieder <jrnieder@gmail.com> writes:
Show 13 quoted lines
> Johannes Sixt wrote:
>> Am 3/16/2011 8:00, schrieb Jonathan Nieder:
>
>>> +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_endprocon 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.