arm裸跑与带linux差别,MDK中,ARM裸跑中memcmp的疑问。

c标准库源代码之 memcmp

int

memcmp (s1, s2, len)

const __ptr_t s1;

const __ptr_t s2;

size_t len;

{

op_t a0;

op_t b0;

long int srcp1 = (long int) s1;

long int srcp2 = (long int) s2;

op_t res;

if (len >= OP_T_THRES)

{

/* There are at least some bytes to compare.  No need to test

for LEN == 0 in this alignment loop.  */

while (srcp2 % OPSIZ != 0)

{

a0 = ((byte *) srcp1)[0];

b0 = ((byte *) srcp2)[0];

srcp1 += 1;

srcp2 += 1;

res = a0 - b0;

if (res != 0)

return res;

len -= 1;

}

/* SRCP2 is now aligned for memory operations on `op_t'.

SRCP1 alignment determines if we can do a simple,

aligned compare or need to shuffle bits.  */

if (srcp1 % OPSIZ == 0)

res = memcmp_common_alignment (srcp1, srcp2, len / OPSIZ);

else

res = memcmp_not_common_alignment (srcp1, srcp2, len / OPSIZ);

if (res != 0)

return res;

/* Number of bytes remaining in the interval [0..OPSIZ-1].  */

srcp1 += len & -OPSIZ;

srcp2 += len & -OPSIZ;

len %= OPSIZ;

}

/* There are just a few bytes to compare.  Use byte memory operations.  */

while (len != 0)

{

a0 = ((byte *) srcp1)[0];

b0 = ((byte *) srcp2)[0];

srcp1 += 1;

srcp2 += 1;

res = a0 - b0;

if (res != 0)

return res;

len -= 1;

}

return 0;

}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值