[PATCH 4/4] Use __inhibit_loop_to_libcall in all memset/memcpy implementations

[email protected]
Newsgroups gmane.comp.lib.newlib
Message-ID <[email protected]>
From: Keith Packard <[email protected]>

This macro selects a compiler option that disables recognition of
common memset/memcpy patterns and converting those to direct
memset/memcpy calls.

Signed-off-by: Keith Packard <[email protected]>
---
 newlib/libc/machine/cris/memcpy.c   | 2 ++
 newlib/libc/machine/riscv/memcpy.c  | 2 ++
 newlib/libc/machine/spu/memcpy.c    | 5 ++++-
 newlib/libc/machine/spu/memcpy_ea.c | 2 ++
 newlib/libc/machine/spu/memset_ea.c | 2 ++
 newlib/libc/machine/visium/memcpy.c | 5 +++++
 newlib/libc/machine/visium/memset.c | 6 +++++-
 newlib/libc/machine/xscale/memcpy.c | 2 ++
 newlib/libc/machine/xscale/memset.c | 2 ++
 newlib/libc/string/memcpy.c         | 2 ++
 10 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/newlib/libc/machine/cris/memcpy.c b/newlib/libc/machine/cris/memcpy.c
index c7a1af957..c314edeb6 100644
--- a/newlib/libc/machine/cris/memcpy.c
+++ b/newlib/libc/machine/cris/memcpy.c
@@ -31,6 +31,7 @@
    than what we describe.  An assembly file should be used instead.  */
 
 #include <stddef.h>
+#include "../../string/local.h"
 
 /* Break even between movem and move16 is really at 38.7 * 2, but
    modulo 44, so up to the next multiple of 44, we use ordinary code.  */
@@ -40,6 +41,7 @@
 __asm__ (".syntax no_register_prefix");
 
 void *
+__inhibit_loop_to_libcall
 memcpy(void *__restrict pdst, const void *__restrict psrc, size_t pn)
 {
   /* Now we want the parameters put in special registers.
diff --git a/newlib/libc/machine/riscv/memcpy.c b/newlib/libc/machine/riscv/memcpy.c
index c717f9f4b..a0ab78a0a 100644
--- a/newlib/libc/machine/riscv/memcpy.c
+++ b/newlib/libc/machine/riscv/memcpy.c
@@ -11,10 +11,12 @@
 
 #include <string.h>
 #include <stdint.h>
+#include "../../string/local.h"
 
 #define unlikely(X) __builtin_expect (!!(X), 0)
 
 void *
+__inhibit_loop_to_libcall
 memcpy(void *__restrict aa, const void *__restrict bb, size_t n)
 {
   #define BODY(a, b, t) { \
diff --git a/newlib/libc/machine/spu/memcpy.c b/newlib/libc/machine/spu/memcpy.c
index dbbce8cee..0483cd23d 100644
--- a/newlib/libc/machine/spu/memcpy.c
+++ b/newlib/libc/machine/spu/memcpy.c
@@ -33,6 +33,7 @@
 #include <spu_intrinsics.h>
 #include <stddef.h>
 #include <vec_literal.h>
+#include "../../string/local.h"
 
 /* Copy n bytes from memory area src to memory area dest.
  * The memory areas may not overlap. The memcpy subroutine
@@ -42,7 +43,9 @@
  * either with prior knowledge of the alignment or special
  * casing specific optimal alignments.
  */
-void * memcpy(void * __restrict__ dest, const void * __restrict__ src, size_t n)
+void *
+__inhibit_loop_to_libcall
+memcpy(void * __restrict__ dest, const void * __restrict__ src, size_t n)
 {
   int adjust, delta;
   unsigned int soffset1, doffset1, doffset2;
diff --git a/newlib/libc/machine/spu/memcpy_ea.c b/newlib/libc/machine/spu/memcpy_ea.c
index 6dfea7abb..ae67f86b1 100644
--- a/newlib/libc/machine/spu/memcpy_ea.c
+++ b/newlib/libc/machine/spu/memcpy_ea.c
@@ -34,10 +34,12 @@ POSSIBILITY OF SUCH DAMAGE.
 #include "ea_internal.h"
 #include <ea.h>
 #include <spu_cache.h>
+#include "../../string/local.h"
 
 COMPAT_EA_ALIAS (memcpy_ea);
 
 __ea void *
+__inhibit_loop_to_libcall
 memcpy_ea (__ea void *dest, __ea const void *src, size_ea_t n)
 {
   __ea void *curr_dest = dest;
diff --git a/newlib/libc/machine/spu/memset_ea.c b/newlib/libc/machine/spu/memset_ea.c
index a18baf206..1d6027382 100644
--- a/newlib/libc/machine/spu/memset_ea.c
+++ b/newlib/libc/machine/spu/memset_ea.c
@@ -34,10 +34,12 @@ POSSIBILITY OF SUCH DAMAGE.
 #include <spu_cache.h>
 #include "ea_internal.h"
 #include <ea.h>
+#include "../../string/local.h"
 
 COMPAT_EA_ALIAS (memset_ea);
 
 __ea void *
+__inhibit_loop_to_libcall
 memset_ea (__ea void *dest, int c, size_ea_t n)
 {
   __ea void *curr_dest = dest;
diff --git a/newlib/libc/machine/visium/memcpy.c b/newlib/libc/machine/visium/memcpy.c
index c5110064d..e64403135 100644
--- a/newlib/libc/machine/visium/memcpy.c
+++ b/newlib/libc/machine/visium/memcpy.c
@@ -31,6 +31,7 @@
 
 #include <stddef.h>
 #include "memcpy.h"
+#include "../../string/local.h"
 
 #define INST_BARRIER   __asm__ __volatile__ ("":::"memory");
 
@@ -422,6 +423,7 @@ do {				\
 
 
 static inline void
+__inhibit_loop_to_libcall
 __int_memcpy (void *__restrict s1, const void *__restrict s2, size_t n) 
 {
   int value = n;
@@ -562,6 +564,7 @@ __int_memcpy (void *__restrict s1, const void *__restrict s2, size_t n)
 }
 
 static inline void
+__inhibit_loop_to_libcall
 __shrt_int_memcpy (void *__restrict s1, const void *__restrict s2, size_t n) 
 {
   int value = n;
@@ -703,6 +706,7 @@ __shrt_int_memcpy (void *__restrict s1, const void *__restrict s2, size_t n)
 
 
 static inline void
+__inhibit_loop_to_libcall
 __byte_memcpy (void *__restrict s1, const void *__restrict s2, size_t n) 
 {
   int value = n;
@@ -846,6 +850,7 @@ __byte_memcpy (void *__restrict s1, const void *__restrict s2, size_t n)
 /* Exposed interface.  */
 
 void *
+__inhibit_loop_to_libcall
 memcpy (void *__restrict s1, const void *__restrict s2, size_t n)
 {
   void *result = s1;
diff --git a/newlib/libc/machine/visium/memset.c b/newlib/libc/machine/visium/memset.c
index bad64a96d..5c3906aa6 100644
--- a/newlib/libc/machine/visium/memset.c
+++ b/newlib/libc/machine/visium/memset.c
@@ -31,6 +31,7 @@
 
 #include <stddef.h>
 #include "memset.h"
+#include "../../string/local.h"
 
 #define SET_32_OBJECTS(out)	\
 do {				\
@@ -228,8 +229,8 @@ do {				\
   out += 1;			\
 } while(0)
 
-
 static inline void
+__inhibit_loop_to_libcall
 __int_memset (void *__restrict s1, int val, size_t n)
 {
   int value = n;
@@ -369,6 +370,7 @@ __int_memset (void *__restrict s1, int val, size_t n)
 }
 
 static inline void
+__inhibit_loop_to_libcall
 __short_int_memset (void *__restrict s1, int val, size_t n)
 {
   int value = n;
@@ -508,6 +510,7 @@ __short_int_memset (void *__restrict s1, int val, size_t n)
 }
 
 static inline void
+__inhibit_loop_to_libcall
 __byte_memset (void *__restrict s1, int val, size_t n)
 {
   int value = n;
@@ -650,6 +653,7 @@ __byte_memset (void *__restrict s1, int val, size_t n)
 /* Exposed interface.  */
 
 void *
+__inhibit_loop_to_libcall
 memset (void *s, int c, size_t n)
 {
   void *result = s;
diff --git a/newlib/libc/machine/xscale/memcpy.c b/newlib/libc/machine/xscale/memcpy.c
index 7de967fb9..20758e159 100644
--- a/newlib/libc/machine/xscale/memcpy.c
+++ b/newlib/libc/machine/xscale/memcpy.c
@@ -6,8 +6,10 @@
 
 #include <string.h>
 #include "xscale.h"
+#include "../../string/local.h"
 
 void *
+__inhibit_loop_to_libcall
 memcpy (void *__restrict dst0, const void *__restrict src0, size_t len)
 {
   int dummy;
diff --git a/newlib/libc/machine/xscale/memset.c b/newlib/libc/machine/xscale/memset.c
index 4ff8d01e0..8fab2a7d1 100644
--- a/newlib/libc/machine/xscale/memset.c
+++ b/newlib/libc/machine/xscale/memset.c
@@ -6,8 +6,10 @@
 
 #include <string.h>
 #include "xscale.h"
+#include "../../string/local.h"
 
 void *
+__inhibit_loop_to_libcall
 memset (void *dst, int c, size_t len)
 {
   int dummy;
diff --git a/newlib/libc/string/memcpy.c b/newlib/libc/string/memcpy.c
index a1cff12d9..52f716b92 100644
--- a/newlib/libc/string/memcpy.c
+++ b/newlib/libc/string/memcpy.c
@@ -29,6 +29,7 @@ QUICKREF
 
 #include <_ansi.h>
 #include <string.h>
+#include "local.h"
 
 /* Nonzero if either X or Y is not aligned on a "long" boundary.  */
 #define UNALIGNED(X, Y) \
@@ -44,6 +45,7 @@ QUICKREF
 #define TOO_SMALL(LEN)  ((LEN) < BIGBLOCKSIZE)
 
 void *
+__inhibit_loop_to_libcall
 memcpy (void *__restrict dst0,
 	const void *__restrict src0,
 	size_t len0)
-- 
2.18.0
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.