Linux内核中的memcpy实现 [英] memcpy implementation in linux kernel

查看:605
本文介绍了Linux内核中的memcpy实现的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在实模式下看到了Linux内核中的memcpy实现:

I see memcpy implementation in linux kernel in real mode:

GLOBAL(memcpy)
    pushw   %si
    pushw   %di
    movw    %ax, %di
    movw    %dx, %si
    pushw   %cx
    shrw    $2, %cx
    rep; movsl
    popw    %cx
    andw    $3, %cx
    rep; movsb
    popw    %di
    popw    %si
    retl
ENDPROC(memcpy)

我理解rep; movsl之前的第一部分,但是为什么是rep; movsl之后的第二部分,它已经从si-> di复制了32个字节.为什么是第二部分,我仅看到一个理由来再次应对si中的地址未按4个字节对齐的结构.

I understand first part before rep; movsl, but why is the second part after rep; movsl, it already copied from si -> di by 32 bytes. Why is the second part, i see only one reason to make coping again that structure which address is in si not aligned by 4 bytes.

谢谢.

推荐答案

下面是与注释相关的代码行,以解释它们的作用:

Here are the relevant lines of code with comments to explain what they do:

shrw    $2, %cx   ; length /= sizeof(DWORD)
rep; movsl        ; Copy the first length/sizeof(DWORD) DWORDs
popw    %cx       ; Restore the original length
andw    $3, %cx   ; length &= 3, i.e. length %= sizeof(DWORD)
rep; movsb        ; Copy the remaining length % sizeof(DWORD) bytes (if any)

这篇关于Linux内核中的memcpy实现的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆