[PATCH] D106210: [MS] Preserve base register %esi around movs[bwl]

namazso via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Jul 16 21:14:57 PDT 2021


namazso created this revision.
namazso added a project: clang.
namazso requested review of this revision.
Herald added a subscriber: cfe-commits.

fix for behavior reported in https://bugs.llvm.org/show_bug.cgi?id=51100 workaround for root cause https://bugs.llvm.org/show_bug.cgi?id=16830


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D106210

Files:
  clang/lib/Headers/intrin.h


Index: clang/lib/Headers/intrin.h
===================================================================
--- clang/lib/Headers/intrin.h
+++ clang/lib/Headers/intrin.h
@@ -451,24 +451,35 @@
 static __inline__ void __DEFAULT_FN_ATTRS __movsb(unsigned char *__dst,
                                                   unsigned char const *__src,
                                                   size_t __n) {
+#if defined(__x86_64__)
   __asm__ __volatile__("rep movsb" : "+D"(__dst), "+S"(__src), "+c"(__n)
                        : : "memory");
+#else
+  __asm__ __volatile__("xchg %%esi, %1\nrep movsb\nxchg %%esi, %1" : "+D"(__dst), "+r"(__src), "+c"(__n)
+                       : : "memory");
+#endif
 }
 static __inline__ void __DEFAULT_FN_ATTRS __movsd(unsigned long *__dst,
                                                   unsigned long const *__src,
                                                   size_t __n) {
-  __asm__ __volatile__("rep movsl"
-                       : "+D"(__dst), "+S"(__src), "+c"(__n)
-                       :
-                       : "memory");
+#if defined(__x86_64__)
+  __asm__ __volatile__("rep movsl" : "+D"(__dst), "+S"(__src), "+c"(__n)
+                       : : "memory");
+#else
+  __asm__ __volatile__("xchg %%esi, %1\nrep movsl\nxchg %%esi, %1" : "+D"(__dst), "+r"(__src), "+c"(__n)
+                       : : "memory");
+#endif
 }
 static __inline__ void __DEFAULT_FN_ATTRS __movsw(unsigned short *__dst,
                                                   unsigned short const *__src,
                                                   size_t __n) {
-  __asm__ __volatile__("rep movsw"
-                       : "+D"(__dst), "+S"(__src), "+c"(__n)
-                       :
-                       : "memory");
+#if defined(__x86_64__)
+  __asm__ __volatile__("rep movsw" : "+D"(__dst), "+S"(__src), "+c"(__n)
+                       : : "memory");
+#else
+  __asm__ __volatile__("xchg %%esi, %1\nrep movsw\nxchg %%esi, %1" : "+D"(__dst), "+r"(__src), "+c"(__n)
+                       : : "memory");
+#endif
 }
 static __inline__ void __DEFAULT_FN_ATTRS __stosd(unsigned long *__dst,
                                                   unsigned long __x,


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D106210.359526.patch
Type: text/x-patch
Size: 2207 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20210717/df56f18f/attachment.bin>


More information about the cfe-commits mailing list