Implement JIT_MemSet and JIT_MemCpy for clang
authorGeoff Norton <grompf@gmail.com>
Wed, 11 Feb 2015 05:56:48 +0000 (21:56 -0800)
committerGeoff Norton <grompf@gmail.com>
Wed, 11 Feb 2015 18:49:10 +0000 (10:49 -0800)
The windows build has a hand written version of these functions, but
modern systems should have an equivalent performant version of this.
We do need to wrap them to get the trap for a null reference exception,
but after that we can tail call directly.

src/vm/CMakeLists.txt
src/vm/amd64/crthelpers.S [new file with mode: 0644]

index f777e41443be3974d284b2efbec88afe819df9ea..b89daacc5581dec5a0cf5a73c02719ac568da989 100644 (file)
@@ -326,6 +326,7 @@ set(VM_SOURCES_WKS_AMD64_ASM
 
 else()
 set(VM_SOURCES_WKS_AMD64_ASM
+    ${AMD64_SOURCES_DIR}/crthelpers.S
     ${AMD64_SOURCES_DIR}/jithelpers_fastwritebarriers.S
     ${AMD64_SOURCES_DIR}/jithelpers_slow.S
     ${AMD64_SOURCES_DIR}/jithelpers_fast.S
diff --git a/src/vm/amd64/crthelpers.S b/src/vm/amd64/crthelpers.S
new file mode 100644 (file)
index 0000000..0b36e00
--- /dev/null
@@ -0,0 +1,43 @@
+//
+// Copyright (c) Microsoft. All rights reserved.
+// Copyright (c) Geoff Norton. All rights reserved.
+// Licensed under the MIT license. See LICENSE file in the project root for full license information. 
+//
+
+.intel_syntax noprefix
+#include "unixasmmacros.inc"
+#include "asmconstants.h"
+
+// JIT_MemSet/JIT_MemCpy
+//
+// It is IMPORANT that the exception handling code is able to find these guys
+// on the stack, but on non-windows platforms we can just defer to the platform
+// implementation.
+// 
+
+LEAF_ENTRY JIT_MemSet, _TEXT
+        test rdx, rdx
+        jz   Exit_MemSet
+
+        cmp  byte ptr [rdi], 0
+
+        jmp  C_FUNC(memset)
+
+Exit_MemSet:
+        ret
+
+LEAF_END JIT_MemSet, _TEXT
+
+LEAF_ENTRY JIT_MemCpy, _TEXT
+        test rdx, rdx
+        jz   Exit_MemCpy
+
+        cmp  byte ptr [rdi], 0
+        cmp  byte ptr [rsi], 0
+
+        jmp  C_FUNC(memcpy)
+
+Exit_MemCpy:
+        ret
+
+LEAF_END JIT_MemCpy, _TEXT