⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 memset.c

📁 Newlib 嵌入式 C库 标准实现代码
💻 C
字号:
#if defined __thumb__#include "../../string/memset.c"#else#include <string.h>#include "xscale.h"void *memset (void *dst, int c, size_t len){  int dummy;  asm volatile ("tst	%0, #0x3"#ifndef __OPTIMIZE_SIZE__"\n\	beq	1f\n\	b	2f\n\0:\n\	strb	%1, [%0], #1\n\	tst	%0, #0x3\n\	beq	1f\n\2:\n\	movs	r3, %2\n\	sub	%2, %2, #1\n\	bne	0b\n\# At this point we know that %2 == len == -1 (since the SUB has already taken\n\# place).  If we fall through to the 1: label (as the code used to do), the\n\# CMP will detect this negative value and branch to the 2: label.  This will\n\# test %2 again, but this time against 0.  The test will fail and the loop\n\# at 2: will go on for (almost) ever.  Hence the explicit branch to the end\n\# of the hand written assembly code.\n\	b       4f\n\1:\n\	cmp	%2, #0x3\n\	bls	2f\n\	and	%1, %1, #0xff\n\	orr	lr, %1, %1, asl #8\n\	cmp	%2, #0xf\n\	orr	lr, lr, lr, asl #16\n\	bls	1f\n\	mov	r3, lr\n\	mov	r4, lr\n\	mov	r5, lr\n\0:\n\	sub	%2, %2, #16\n\	stmia	%0!, { r3, r4, r5, lr }\n\	cmp	%2, #0xf\n\	bhi	0b\n\1:\n\	cmp	%2, #0x7\n\	bls	1f\n\	mov	r3, lr\n\0:\n\	sub	%2, %2, #8\n\	stmia	%0!, { r3, lr }\n\	cmp	%2, #0x7\n\	bhi	0b\n\1:\n\	cmp	%2, #0x3\n\	bls	2f\n\0:\n\	sub	%2, %2, #4\n\	str	lr, [%0], #4\n\	cmp	%2, #0x3\n\	bhi	0b\n\"#endif /* !__OPTIMIZE_SIZE__ */"\n\2:\n\	movs	r3, %2\n\	sub	%2, %2, #1\n\	beq	4f\n\0:\n\	movs	r3, %2\n\	sub	%2, %2, #1\n\	strb	%1, [%0], #1\n\	bne	0b\n\4:"       : "=&r" (dummy), "=&r" (c), "=&r" (len)       : "0" (dst), "1" (c), "2" (len)       : "memory", "r3", "r4", "r5", "lr");  return dst;} #endif

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -