Subject: Re: Intermediate void* casts
To: None <tech-misc@netbsd.org>
From: Geoff Wing <mason@primenet.com.au>
List: tech-misc
Date: 08/11/2003 09:20:49
Martin Husemann <martin@duskware.de> typed:
: On Sun, Aug 10, 2003 at 05:15:43PM -0700, Bill Studenmund wrote:
:> I'm not so sure about that. Can/will the compiler notice that you're only
:> using half of a 64-bit value? Otherwise, by making this change, you're
: If gcc does miss the obvious, the 32bit code might be slightly slower
: than the old code. I can't test that right now, anyone with i386 gcc 3.3.1
: around? If the value is spread accross two 32 bit registers, and the code
Works OK. On i386:
compiled -O2 with compiled -O2 with
gcc 2.95.3 (NetBSD nb4) gcc 3.3.1 (from NetBSD src yesterday)
00000000 <bswap64>: 00000000 <bswap64>:
0: 55 push %ebp 0: 55 push %ebp
1: 89 e5 mov %esp,%ebp 1: 89 e5 mov %esp,%ebp
3: 53 push %ebx | 3: 8b 45 08 mov 0x8(%ebp),%e
4: 8b 45 08 mov 0x8(%ebp),%e | 6: 53 push %ebx
7: 8b 55 0c mov 0xc(%ebp),%e 7: 8b 55 0c mov 0xc(%ebp),%e
a: 89 c1 mov %eax,%ecx a: 89 c1 mov %eax,%ecx
c: 66 c1 c9 08 ror $0x8,%cx c: 66 c1 c9 08 ror $0x8,%cx
10: c1 c9 10 ror $0x10,%ecx 10: c1 c9 10 ror $0x10,%ecx
13: 66 c1 c9 08 ror $0x8,%cx 13: 66 c1 c9 08 ror $0x8,%cx
17: 89 d0 mov %edx,%eax | 17: 89 d3 mov %edx,%ebx
19: 31 d2 xor %edx,%edx | 19: 66 c1 cb 08 ror $0x8,%bx
1b: 66 c1 c8 08 ror $0x8,%ax | 1d: c1 cb 10 ror $0x10,%ebx
1f: c1 c8 10 ror $0x10,%eax | 20: 66 c1 cb 08 ror $0x8,%bx
22: 66 c1 c8 08 ror $0x8,%ax | 24: 31 c0 xor %eax,%eax
26: 31 db xor %ebx,%ebx | 26: 89 ca mov %ecx,%edx
28: 89 cb mov %ecx,%ebx | 28: 89 d9 mov %ebx,%ecx
2a: 31 c9 xor %ecx,%ecx | 2a: 31 db xor %ebx,%ebx
2c: 31 d2 xor %edx,%edx | 2c: 09 da or %ebx,%edx
2e: 09 c1 or %eax,%ecx | 2e: 09 c8 or %ecx,%eax
30: 09 d3 or %edx,%ebx | 30: 8b 1c 24 mov (%esp,1),%eb
32: 89 c8 mov %ecx,%eax | 33: c9 leave
34: 89 da mov %ebx,%edx | 34: c3 ret
36: 5b pop %ebx <
37: c9 leave <
38: c3 ret <
Following is how gcc 3.4 20030806 (experimental) with -O2 makes it:
00000000 <bswap64>:
0: 55 push %ebp
1: 89 e5 mov %esp,%ebp
3: 8b 45 08 mov 0x8(%ebp),%eax
6: 53 push %ebx
7: 8b 55 0c mov 0xc(%ebp),%edx
a: 89 c1 mov %eax,%ecx
c: 66 c1 c9 08 ror $0x8,%cx
10: c1 c9 10 ror $0x10,%ecx
13: 66 c1 c9 08 ror $0x8,%cx
17: 89 d3 mov %edx,%ebx
19: 66 c1 cb 08 ror $0x8,%bx
1d: c1 cb 10 ror $0x10,%ebx
20: 66 c1 cb 08 ror $0x8,%bx
24: 31 c0 xor %eax,%eax
26: 89 ca mov %ecx,%edx
28: 89 d9 mov %ebx,%ecx
2a: 31 db xor %ebx,%ebx
2c: 09 da or %ebx,%edx
2e: 09 c8 or %ecx,%eax
30: 5b pop %ebx
31: c9 leave
32: c3 ret
Regards,
--
Geoff Wing : <gcw@pobox.com>
Rxvt Stuff : <gcw@rxvt.org>
Zsh Stuff : <gcw@zsh.org>