1 | ; $Id: memset.asm 106061 2024-09-16 14:03:52Z vboxsync $
|
---|
2 | ;; @file
|
---|
3 | ; IPRT - No-CRT memset - AMD64 & X86.
|
---|
4 | ;
|
---|
5 |
|
---|
6 | ;
|
---|
7 | ; Copyright (C) 2006-2024 Oracle and/or its affiliates.
|
---|
8 | ;
|
---|
9 | ; This file is part of VirtualBox base platform packages, as
|
---|
10 | ; available from https://www.virtualbox.org.
|
---|
11 | ;
|
---|
12 | ; This program is free software; you can redistribute it and/or
|
---|
13 | ; modify it under the terms of the GNU General Public License
|
---|
14 | ; as published by the Free Software Foundation, in version 3 of the
|
---|
15 | ; License.
|
---|
16 | ;
|
---|
17 | ; This program is distributed in the hope that it will be useful, but
|
---|
18 | ; WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
19 | ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
---|
20 | ; General Public License for more details.
|
---|
21 | ;
|
---|
22 | ; You should have received a copy of the GNU General Public License
|
---|
23 | ; along with this program; if not, see <https://www.gnu.org/licenses>.
|
---|
24 | ;
|
---|
25 | ; The contents of this file may alternatively be used under the terms
|
---|
26 | ; of the Common Development and Distribution License Version 1.0
|
---|
27 | ; (CDDL), a copy of it is provided in the "COPYING.CDDL" file included
|
---|
28 | ; in the VirtualBox distribution, in which case the provisions of the
|
---|
29 | ; CDDL are applicable instead of those of the GPL.
|
---|
30 | ;
|
---|
31 | ; You may elect to license modified versions of this file under the
|
---|
32 | ; terms and conditions of either the GPL or the CDDL or both.
|
---|
33 | ;
|
---|
34 | ; SPDX-License-Identifier: GPL-3.0-only OR CDDL-1.0
|
---|
35 | ;
|
---|
36 |
|
---|
37 | %include "iprt/asmdefs.mac"
|
---|
38 |
|
---|
39 | BEGINCODE
|
---|
40 |
|
---|
41 | ;;
|
---|
42 | ; @param pvDst gcc: rdi msc: ecx x86:[esp+4] wcall: eax
|
---|
43 | ; @param ch gcc: esi msc: edx x86:[esp+8] wcall: edx
|
---|
44 | ; @param cb gcc: rdx msc: r8 x86:[esp+0ch] wcall: ebx
|
---|
45 | RT_NOCRT_BEGINPROC memset
|
---|
46 | cld
|
---|
47 | %ifdef RT_ARCH_AMD64
|
---|
48 | %ifdef ASM_CALL64_MSC
|
---|
49 | mov r9, rdi ; save rdi in r9
|
---|
50 | mov rdi, rcx
|
---|
51 | mov r10, rcx ; the return value.
|
---|
52 | movzx eax, dl
|
---|
53 | cmp r8, 32
|
---|
54 | jb .dobytes
|
---|
55 |
|
---|
56 | ; eax = (al << 24) | (al << 16) | (al << 8) | al;
|
---|
57 | ; rdx = (eax << 32) | eax
|
---|
58 | movzx edx, dl
|
---|
59 | mov rax, qword 0101010101010101h
|
---|
60 | imul rax, rdx
|
---|
61 |
|
---|
62 | ; todo: alignment.
|
---|
63 | mov rcx, r8
|
---|
64 | shr rcx, 3
|
---|
65 | rep stosq
|
---|
66 |
|
---|
67 | and r8, 7
|
---|
68 | .dobytes:
|
---|
69 | mov rcx, r8
|
---|
70 | rep stosb
|
---|
71 |
|
---|
72 | mov rdi, r9 ; restore rdi
|
---|
73 | mov rax, r10
|
---|
74 |
|
---|
75 | %else ; GCC
|
---|
76 | mov r10, rdi ; the return value.
|
---|
77 | movzx eax, sil
|
---|
78 | cmp rdx, 32
|
---|
79 | jb .dobytes
|
---|
80 |
|
---|
81 | ; eax = (al << 24) | (al << 16) | (al << 8) | al;
|
---|
82 | ; rdx = (eax << 32) | eax
|
---|
83 | movzx esi, sil
|
---|
84 | mov rax, qword 0101010101010101h
|
---|
85 | imul rax, rsi
|
---|
86 |
|
---|
87 | ; todo: alignment.
|
---|
88 | mov rcx, rdx
|
---|
89 | shr rcx, 3
|
---|
90 | rep stosq
|
---|
91 |
|
---|
92 | and rdx, 7
|
---|
93 | .dobytes:
|
---|
94 | mov rcx, rdx
|
---|
95 | rep stosb
|
---|
96 |
|
---|
97 | mov rax, r10
|
---|
98 | %endif ; GCC
|
---|
99 |
|
---|
100 | %else ; X86
|
---|
101 | push edi
|
---|
102 |
|
---|
103 | %ifdef ASM_CALL32_WATCOM
|
---|
104 | push eax
|
---|
105 | mov edi, eax
|
---|
106 | mov ecx, ebx
|
---|
107 | movzx eax, dl
|
---|
108 | %else
|
---|
109 | mov ecx, [esp + 0ch + 4]
|
---|
110 | movzx eax, byte [esp + 08h + 4]
|
---|
111 | mov edi, [esp + 04h + 4]
|
---|
112 | %endif
|
---|
113 | cmp ecx, 12
|
---|
114 | jb .dobytes
|
---|
115 |
|
---|
116 | ; eax = (al << 24) | (al << 16) | (al << 8) | al;
|
---|
117 | mov ah, al
|
---|
118 | mov edx, eax
|
---|
119 | shl edx, 16
|
---|
120 | or eax, edx
|
---|
121 |
|
---|
122 | mov edx, ecx
|
---|
123 | shr ecx, 2
|
---|
124 | rep stosd
|
---|
125 |
|
---|
126 | and edx, 3
|
---|
127 | mov ecx, edx
|
---|
128 | .dobytes:
|
---|
129 | rep stosb
|
---|
130 |
|
---|
131 | %ifdef ASM_CALL32_WATCOM
|
---|
132 | pop eax
|
---|
133 | pop edi
|
---|
134 | %else
|
---|
135 | pop edi
|
---|
136 | mov eax, [esp + 4]
|
---|
137 | %endif
|
---|
138 | %endif ; X86
|
---|
139 | ret
|
---|
140 | ENDPROC RT_NOCRT(memset)
|
---|
141 |
|
---|