1/*
2 * ====================================================
3 * Copyright (C) 1998, 2002, 2008 by Red Hat Inc. All rights reserved.
4 *
5 * Permission to use, copy, modify, and distribute this
6 * software is freely granted, provided that this notice
7 * is preserved.
8 * ====================================================
9 */
10
11#include <picolibc.h>
12
13	#include "i386mach.h"
14
15	.global SYM (memset)
16       SOTYPE_FUNCTION(memset)
17
18SYM (memset):
19
20#ifdef __iamcu__
21	pushl edi
22	movl eax,edi
23	movzbl dl,eax
24	mov edi,edx
25	rep stosb
26	mov edx,eax
27	popl edi
28#else
29	pushl ebp
30	movl esp,ebp
31	pushl edi
32	movl 8(ebp),edi
33	movzbl 12(ebp),eax
34	movl 16(ebp),ecx
35	cld
36
37#ifndef __OPTIMIZE_SIZE__
38/* Less than 16 bytes won't benefit from the 'rep stosl' loop.  */
39	cmpl $16,ecx
40	jbe .L19
41	testl $7,edi
42	je .L10
43
44/* It turns out that 8-byte aligned 'rep stosl' outperforms
45   4-byte aligned on some x86 platforms.  */
46	movb al,(edi)
47	incl edi
48	decl ecx
49	testl $7,edi
50	je .L10
51
52	movb al,(edi)
53	incl edi
54	decl ecx
55	testl $7,edi
56	je .L10
57
58	movb al,(edi)
59	incl edi
60	decl ecx
61	testl $7,edi
62	je .L10
63
64	movb al,(edi)
65	incl edi
66	decl ecx
67	testl $7,edi
68	je .L10
69
70	movb al,(edi)
71	incl edi
72	decl ecx
73	testl $7,edi
74	je .L10
75
76	movb al,(edi)
77	incl edi
78	decl ecx
79	testl $7,edi
80	je .L10
81
82	movb al,(edi)
83	incl edi
84	decl ecx
85
86/* At this point, ecx>8 and edi%8==0.  */
87.L10:
88	movb al,ah
89	movl eax,edx
90	sall $16,edx
91	orl edx,eax
92
93	movl ecx,edx
94	shrl $2,ecx
95	andl $3,edx
96	rep
97	stosl
98	movl edx,ecx
99#endif /* not __OPTIMIZE_SIZE__ */
100
101.L19:
102	rep
103	stosb
104
105	movl 8(ebp),eax
106
107	leal -4(ebp),esp
108	popl edi
109	leave
110#endif
111	ret
112
113#if defined(__linux__) && defined(__ELF__)
114.section .note.GNU-stack,"",%progbits
115#endif
116