Subject: Re: spllower() assembly oddity
To: None <jakllsch@kollasch.net>
From: Andrew Doran <ad@netbsd.org>
List: port-amd64
Date: 12/10/2007 00:24:42
On Sun, Dec 09, 2007 at 12:20:50PM -0600, jakllsch@kollasch.net wrote:

> I've been investigating why recent NetBSD/amd64 running in
> qemu-system-x86_64 hangs the emulator in spllower().
> 
> I'm puzzled by two versions of this function.
> 
> In rev 1.12, one of the outs of this function is:
> 
> 	...
> 1:
> 	rep
> 	ret
> 2:
>
> In rev 1.13 and latter, this is:
> 
> 	...
> 1:	
> 	ret
> 	ret
> 2:
> 	...
> 
> FWIW, the i386 one uses a single 'ret'.
> 
> Could someone explain the differences?

The replacement was mistake on my part. The reason for the 'rep ret' is:

http://www.amd.com/us-en/assets/content_type/DownloadableAssets/dwamd_25112.pdf

6.2 Two-Byte Near-Return RET Instruction

Use of a two-byte near-return can improve performance. The single-byte
near-return (opcode C3h) of the RET instruction should be used carefully.
Specifically, avoid the following two situations:

?   Any kind of branch (either conditional or unconditional) that has the
    single-byte near-return RET instruction as its target. See "Examples."

?   A conditional branch that occurs in the code directly before the
    single-byte near-return RET instruction. See "Examples."

Andrew