brintos

brintos / llvm-project-archived public Read only

0
0
Text · 2.1 KiB · a3185b9 Raw
101 lines · plain
1/*2 * memset - fill memory with a constant3 *4 * Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.5 * See https://llvm.org/LICENSE.txt for license information.6 * SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception7 */8 9/*10   Written by Dave Gilbert <david.gilbert@linaro.org>11 12   This memset routine is optimised on a Cortex-A9 and should work on13   all ARMv7 processors.14 15 */16 17	.syntax unified18	.arch armv7-a19 20@ 2011-08-30 david.gilbert@linaro.org21@    Extracted from local git 2f11b43622 23@ this lets us check a flag in a 00/ff byte easily in either endianness24#ifdef __ARMEB__25#define CHARTSTMASK(c) 1<<(31-(c*8))26#else27#define CHARTSTMASK(c) 1<<(c*8)28#endif29	.text30	.thumb31 32@ ---------------------------------------------------------------------------33	.thumb_func34	.align 235	.p2align 4,,1536	.global __memset_arm37	.type __memset_arm,%function38__memset_arm:39	@ r0 = address40	@ r1 = character41	@ r2 = count42	@ returns original address in r043 44	mov	r3, r0		@ Leave r0 alone45	cbz	r2, 10f		@ Exit if 0 length46 47	tst	r0, #748	beq	2f		@ Already aligned49 50	@ Ok, so we're misaligned here511:52	strb	r1, [r3], #153	subs	r2,r2,#154	tst	r3, #755	cbz	r2, 10f		@ Exit if we hit the end56	bne	1b		@ go round again if still misaligned57 582:59	@ OK, so we're aligned60	push	{r4,r5,r6,r7}61	bics	r4, r2, #15	@ if less than 16 bytes then need to finish it off62	beq	5f63 643:65	@ POSIX says that ch is cast to an unsigned char.  A uxtb is one66	@ byte and takes two cycles, where an AND is four bytes but one67	@ cycle.68	and	r1, #0xFF69	orr	r1, r1, r1, lsl#8	@ Same character into all bytes70	orr	r1, r1, r1, lsl#1671	mov	r5,r172	mov	r6,r173	mov	r7,r174 754:76	subs	r4,r4,#1677	stmia	r3!,{r1,r5,r6,r7}78	bne	4b79	and	r2,r2,#1580 81	@ At this point we're still aligned and we have upto align-1 bytes left to right82	@ we can avoid some of the byte-at-a time now by testing for some big chunks83	tst	r2,#884	itt	ne85	subne	r2,r2,#886	stmiane	r3!,{r1,r5}87 885:89	pop	{r4,r5,r6,r7}90	cbz	r2, 10f91 92	@ Got to do any last < alignment bytes936:94	subs	r2,r2,#195	strb	r1,[r3],#196	bne	6b97 9810:99	bx	lr		@ goodbye100	.size	__memset_arm, . - __memset_arm101