[Ffmpeg-devel] [PATCH] wrong use of ff_get_fourcc in mpjg.c
Måns Rullgård
mru
Wed Feb 7 18:33:33 CET 2007
Reimar D?ffinger said:
> Hello,
> On Wed, Feb 07, 2007 at 01:45:25PM -0000, M?ns Rullg?rd wrote:
>> Reimar Doeffinger said:
> [...]
>> > AV_RB32 etc. in general when there are optimized variants maybe not, but a
>> macro
>> > that expands to
>> > ("ABCD")[0] | (("ABCD")[1] << 8) ...
>> > I'd expect to resolve to a constant...
>>
>> Well, it doesn't. Believe me, I've tried it.
>
> Maybe your info is outdated?
> It does for me with gcc 4.1.1 and starting from -O1.
> program:
> int main(int argc, char *argv[]) {
> #define TAG(s) ((s)[0] | ((s)[1] << 8) | ((s)[2] << 16) | ((s)[3] <<
> 24))
> int t = TAG(argv[0]);
> return t == TAG("test");
> }
>
> generated asm (64 bit mode, -O1):
> 400498: 48 8b 0e mov (%rsi),%rcx
> 40049b: 0f be 31 movsbl (%rcx),%esi
> 40049e: 0f be 41 01 movsbl 0x1(%rcx),%eax
> 4004a2: c1 e0 08 shl $0x8,%eax
> 4004a5: 09 c6 or %eax,%esi
> 4004a7: 0f be 51 02 movsbl 0x2(%rcx),%edx
> 4004ab: c1 e2 10 shl $0x10,%edx
> 4004ae: 0f be 41 03 movsbl 0x3(%rcx),%eax
> 4004b2: c1 e0 18 shl $0x18,%eax
> 4004b5: 09 c2 or %eax,%edx
> 4004b7: 09 d6 or %edx,%esi
> 4004b9: 81 fe 74 65 73 74 cmp $0x74736574,%esi
> 4004bf: 0f 94 c0 sete %al
> 4004c2: 0f b6 c0 movzbl %al,%eax
That proves nothing. Here's a proper test with gcc 4.1.1:
$ cat tag.c
#define TAG(s) ((s)[0] | ((s)[1] << 8) | ((s)[2] << 16) | ((s)[3] << 24))
int test = TAG("test");
int foo(int f)
{
switch(f){
case TAG("test"):
return 0;
}
return 1;
}
$ gcc -O2 -c tag.c
tag.c:2: error: initializer element is not constant
tag.c: In function 'foo':
tag.c:7: error: case label does not reduce to an integer constant
The optimizer may well reduce it to a constant, but it's not a constant
expression at the C language level.
--
M?ns Rullg?rd
mru at inprovide.com
More information about the ffmpeg-devel
mailing list