[ovs-dev] [RFC PATCH] userspace: Define and use struct eth_addr.

Ben Pfaff blp at nicira.com
Fri Aug 28 22:20:41 UTC 2015


On Fri, Aug 28, 2015 at 03:02:54PM -0700, Jarno Rajahalme wrote:
> 
> > On Aug 28, 2015, at 10:54 AM, Ben Pfaff <blp at nicira.com> wrote:
> > However, GCC is almost criminally bad at optimizing it:
> > 
> >    blp at sigabrt:~/nicira/ovs/_build(0)$ cat tmp.c
> >    struct x {
> >        union {
> >            unsigned char b[6];
> >            unsigned short w[3];
> >        };
> >    };
> >    void g(struct x);
> >    void f(void)
> >    {
> >        struct x y = { { { 1, 2, 3, 4, 5, 6 } } };
> >        g(y);
> >    }
> > 
> >    blp at sigabrt:~/nicira/ovs/_build(0)$ gcc -O2 -g -m64 -c tmp.c
> >    blp at sigabrt:~/nicira/ovs/_build(0)$ objdump -dr tmp.o
> > 
> >    tmp.o:     file format elf64-x86-64
> > 
> > 
> >    Disassembly of section .text:
> > 
> >    0000000000000000 <f>:
> >       0:	48 83 ec 18          	sub    $0x18,%rsp
> >       4:	c6 04 24 01          	movb   $0x1,(%rsp)
> >       8:	c6 44 24 01 02       	movb   $0x2,0x1(%rsp)
> >       d:	c6 44 24 02 03       	movb   $0x3,0x2(%rsp)
> >      12:	c6 44 24 03 04       	movb   $0x4,0x3(%rsp)
> >      17:	c6 44 24 04 05       	movb   $0x5,0x4(%rsp)
> >      1c:	c6 44 24 05 06       	movb   $0x6,0x5(%rsp)
> >      21:	48 8b 3c 24          	mov    (%rsp),%rdi
> >      25:	e8 00 00 00 00       	callq  2a <f+0x2a>
> >                            26: R_X86_64_PC32	g-0x4
> >      2a:	48 83 c4 18          	add    $0x18,%rsp
> >      2e:	c3                   	retq   
>
> One would hope that GCC would do a better job when inlining, though?

I hope so!

> > Acked-by: Ben Pfaff <blp at nicira.com <mailto:blp at nicira.com>>
> 
> Thanks for the review. Unfortunately I forgot to add your Acked-by to
> the commit message, and I realized that just after pushing to github -
> now I don’t have anyone to shift blame to if builds start failing…

;-)



More information about the dev mailing list