Understanding the source code of memcpy()

后端 未结 6 1950
野的像风
野的像风 2020-12-08 08:32
00018 void *memcpy(void *dst, const void *src, size_t len)
00019 {
00020         size_t i;
00021 
00022         /*
00023          * memcpy does not support overlappi         


        
6条回答
  •  不思量自难忘°
    2020-12-08 08:55

    As if you see assembly code of memcpy it show that in 32 bit system each register is 32 bit it can store 4 byte at a time, if you will copy only one byte in 32 bit register, CPU need extra Instruction cycle.

    If len/count is aliged in the multiple of 4 , we can copy 4 byte in one cycle

        MOV FROM, R2
        MOV TO,   R3
        MOV R2,   R4
        ADD LEN,  R4
    CP: MOV (R2+), (R3+) ; "(Rx+)" means "*Rx++" in C
        CMP R2, R4
        BNE CP
    

提交回复
热议问题