On Thu, Sep 19, 2013 at 01:23:19PM -0400, Brad Smith wrote:
> On 19/09/13 7:47 AM, mxb wrote:
> >
> >This file is already in base.
> >/usr/src/sys/lib/libkern/arch/amd64/memset.S
> 
> That is in the kernel not libc.

Indeed. I recall seeing a macro called "COPY_TO_KERNEL" or something. I
probably need to use that.

With regards to the differences. The only difference between the in-kernel
version and FreeBSD's from libc (that is not in a comment) is as follows:

---8<---
@@ -8,6 +11,7 @@
 
 ENTRY(memset)
        movq    %rsi,%rax
+       andq    $0xff,%rax
        movq    %rdx,%rcx
        movq    %rdi,%r11
---8<---

The FreeBSD implementation has the extra instruction.

It looks like they copy the second argument (int c) from rsi and stash it it
rax. Since c is going to be used as a char (and thus uses only a byte) the
original author clears bits 8 through 63 with an andq.

It looks like this is not strictly necessary as the lower byte of rax (aka,
AL) is then copied across the other bytes of rax anyway. This allows them to
copy the bytes 8 at a time by movq.

Can someone check this? Is the andq unnecessary in this case?

-- 
Best Regards
Edd Barrett

http://www.theunixzoo.co.uk

Reply via email to