Skip to content

Commit cde7799

Browse files
authored
Use CRT implementation of memset/memcpy (#67788)
* Use CRT implementation of memset/memcpy * Remove the outdated comment:
1 parent 4a8f230 commit cde7799

File tree

2 files changed

+63
-158
lines changed

2 files changed

+63
-158
lines changed

src/coreclr/vm/amd64/CrtHelpers.asm

-5
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,6 @@
66

77
;
88
; ==--==
9-
; ***********************************************************************
10-
; File: CrtHelpers.asm, see history in asmhelpers.asm
11-
;
12-
; ***********************************************************************
13-
149
include AsmMacros.inc
1510

1611
extern memset:proc

src/coreclr/vm/arm64/crthelpers.asm

+63-153
Original file line numberDiff line numberDiff line change
@@ -1,176 +1,86 @@
11
; Licensed to the .NET Foundation under one or more agreements.
22
; The .NET Foundation licenses this file to you under the MIT license.
33

4-
;; ==++==
5-
;;
6-
7-
;;
8-
;; ==--==
4+
; ==++==
5+
;
96

7+
;
8+
; ==--==
109
#include "ksarm64.h"
10+
#include "asmconstants.h"
11+
#include "asmmacros.h"
1112

12-
TEXTAREA
13+
IMPORT memset
14+
IMPORT memmove
1315

14-
;void JIT_MemSet(void *dst, int val, SIZE_T count)
15-
;{
16-
; uint64_t valEx = (unsigned char)val;
17-
; valEx = valEx | valEx << 8;
18-
; valEx = valEx | valEx << 16;
19-
; valEx = valEx | valEx << 32;
20-
;
21-
; count-=16;
22-
;
23-
; while(count >= 0)
24-
; {
25-
; *(uint64_t*)dst = valEx;
26-
; dst = (uint64_t*)dst + 1;
27-
; *(uint64_t*)dst = valEx;
28-
; dst = (uint64_t*)dst + 1;
29-
; count-=16;
30-
; }
31-
;
32-
; if(count & 8)
33-
; {
34-
; *(uint64_t*)dst = valEx;
35-
; dst = (uint64_t*)dst + 1;
36-
; }
37-
;
38-
; if(count & 4)
39-
; {
40-
; *(uint32_t*)dst = (uint32_t)valEx;
41-
; dst = (uint32_t*)dst + 1;
42-
; }
43-
;
44-
; if(count & 2)
45-
; {
46-
; *(uint16_t*)dst = (uint16_t)valEx;
47-
; dst = (uint16_t*)dst + 1;
48-
; }
49-
;
50-
; if(count & 1)
51-
; {
52-
; *(uint8_t*)dst = (uint8_t)valEx;
53-
; }
54-
;}
16+
; JIT_MemSet/JIT_MemCpy
17+
;
18+
; It is IMPORTANT that the exception handling code is able to find these guys
19+
; on the stack, but on windows platforms we can just defer to the platform
20+
; implementation.
5521
;
5622

57-
; Assembly code corresponding to above C++ method. JIT_MemSet can AV and clr exception personality routine needs to
58-
; determine if the exception has taken place inside JIT_Memset in order to throw corresponding managed exception.
59-
; Determining this is slow if the method were implemented as C++ method (using unwind info). In .asm file by adding JIT_MemSet_End
60-
; marker it can be easily determined if exception happened in JIT_MemSet. Therefore, JIT_MemSet has been written in assembly instead of
61-
; as C++ method.
23+
; void JIT_MemSet(void* dest, int c, size_t count)
24+
;
25+
; Purpose:
26+
; Sets the first "count" bytes of the block of memory pointed byte
27+
; "dest" to the specified value (interpreted as an unsigned char).
28+
;
29+
; Entry:
30+
; RCX: void* dest - Pointer to the block of memory to fill.
31+
; RDX: int c - Value to be set.
32+
; R8: size_t count - Number of bytes to be set to the value.
33+
;
34+
; Exit:
35+
;
36+
; Uses:
37+
;
38+
; Exceptions:
39+
;
6240

41+
TEXTAREA
42+
6343
LEAF_ENTRY JIT_MemSet
64-
ands w1, w1, #0xff
65-
orr w1, w1, w1, lsl #8
66-
orr w1, w1, w1, lsl #0x10
67-
orr x1, x1, x1, lsl #0x20
44+
cbz x2, JIT_MemSet_ret ; check if count is zero, no bytes to set
6845

69-
b JIT_MemSet_bottom
70-
JIT_MemSet_top
71-
stp x1, x1, [x0], #16
72-
JIT_MemSet_bottom
73-
subs x2, x2, #16
74-
bge JIT_MemSet_top
75-
76-
tbz x2, #3, JIT_MemSet_tbz4
77-
str x1, [x0], #8
78-
JIT_MemSet_tbz4
79-
tbz x2, #2, JIT_MemSet_tbz2
80-
str w1, [x0], #4
81-
JIT_MemSet_tbz2
82-
tbz x2, #1, JIT_MemSet_tbz1
83-
strh w1, [x0], #2
84-
JIT_MemSet_tbz1
85-
tbz x2, #0, JIT_MemSet_ret
86-
strb w1, [x0]
87-
JIT_MemSet_ret
88-
ret lr
89-
LEAF_END
90-
91-
LEAF_ENTRY JIT_MemSet_End
92-
nop
93-
LEAF_END
46+
ldrb wzr, [x0] ; check dest for null
9447

48+
b memset ; forward to the CRT implementation
9549

96-
; See comments above for JIT_MemSet
50+
JIT_MemSet_ret
51+
ret lr
52+
53+
LEAF_END_MARKED JIT_MemSet
9754

98-
;void JIT_MemCpy(void *dst, const void *src, SIZE_T count)
99-
;{
100-
; count-=16;
101-
;
102-
; while(count >= 0)
103-
; {
104-
; *(unit64_t*)dst = *(unit64_t*)src;
105-
; dst = (unit64_t*)dst + 1;
106-
; src = (unit64_t*)src + 1;
107-
; *(unit64_t*)dst = *(unit64_t*)src;
108-
; dst = (unit64_t*)dst + 1;
109-
; src = (unit64_t*)src + 1;
110-
; count-=16;
111-
; }
112-
;
113-
; if(count & 8)
114-
; {
115-
; *(unit64_t*)dst = *(unit64_t*)src;
116-
; dst = (unit64_t*)dst + 1;
117-
; src = (unit64_t*)src + 1;
118-
; }
119-
;
120-
; if(count & 4)
121-
; {
122-
; *(unit32_t*)dst = *(unit32_t*)src;
123-
; dst = (unit32_t*)dst + 1;
124-
; src = (unit32_t*)src + 1;
125-
; }
126-
;
127-
; if(count & 2)
128-
; {
129-
; *(unit16_t*)dst = *(unit16_t*)src;
130-
; dst = (unit16_t*)dst + 1;
131-
; src = (unit16_t*)src + 1;
132-
; }
133-
;
134-
; if(count & 1)
135-
; {
136-
; *(unit8_t*)dst = *(unit8_t*)src;
137-
; }
138-
;}
55+
; void JIT_MemCpy(void* dest, const void* src, size_t count)
56+
;
57+
; Purpose:
58+
; Copies the values of "count" bytes from the location pointed to
59+
; by "src" to the memory block pointed by "dest".
60+
;
61+
; Entry:
62+
; RCX: void* dest - Pointer to the destination array where content is to be copied.
63+
; RDX: const void* src - Pointer to the source of the data to be copied.
64+
; R8: size_t count - Number of bytes to copy.
65+
;
66+
; Exit:
67+
;
68+
; Uses:
69+
;
70+
; Exceptions:
13971
;
140-
141-
; Assembly code corresponding to above C++ method.
142-
; See comments above for JIT_MemSet method
14372
LEAF_ENTRY JIT_MemCpy
144-
b JIT_MemCpy_bottom
145-
JIT_MemCpy_top
146-
ldp x8, x9, [x1], #16
147-
stp x8, x9, [x0], #16
148-
JIT_MemCpy_bottom
149-
subs x2, x2, #16
150-
bge JIT_MemCpy_top
73+
cbz x2, JIT_MemCpy_ret ; check if count is zero, no bytes to set
74+
75+
ldrb wzr, [x0] ; check dest for null
76+
ldrb wzr, [x1] ; check src for null
77+
78+
b memmove ; forward to the CRT implementation
15179

152-
tbz x2, #3, JIT_MemCpy_tbz4
153-
ldr x8, [x1], #8
154-
str x8, [x0], #8
155-
JIT_MemCpy_tbz4
156-
tbz x2, #2, JIT_MemCpy_tbz2
157-
ldr w8, [x1], #4
158-
str w8, [x0], #4
159-
JIT_MemCpy_tbz2
160-
tbz x2, #1, JIT_MemCpy_tbz1
161-
ldrsh w8, [x1], #2
162-
strh w8, [x0], #2
163-
JIT_MemCpy_tbz1
164-
tbz x2, #0, JIT_MemCpy_ret
165-
ldrsb w8, [x1]
166-
strb w8, [x0]
16780
JIT_MemCpy_ret
16881
ret lr
169-
LEAF_END
17082

171-
LEAF_ENTRY JIT_MemCpy_End
172-
nop
173-
LEAF_END
83+
LEAF_END_MARKED JIT_MemCpy
17484

17585
; Must be at very end of file
176-
END
86+
END

0 commit comments

Comments
 (0)