* [PATCH] fix arm run-time abi string functions
@ 2017-02-21 1:15 Szabolcs Nagy
2017-06-18 11:58 ` Szabolcs Nagy
2017-06-18 12:14 ` Alexander Monakov
0 siblings, 2 replies; 10+ messages in thread
From: Szabolcs Nagy @ 2017-02-21 1:15 UTC (permalink / raw)
To: musl
in arm rtabi these __aeabi_* functions have special abi (they are
only allowed to clobber r0,r1,r2,r3,ip,lr,cpsr), so they cannot
be simple wrappers around normal string functions (which may
clobber other registers), the safest solution is to write them
in asm, a naive implementation will do because these are not
supposed to be emitted by compilers or used in general.
---
src/string/arm/__aeabi_memclr.c | 9 ---------
src/string/arm/__aeabi_memcpy.c | 9 ---------
src/string/arm/__aeabi_memcpy.s | 42 ++++++++++++++++++++++++++++++++++++++++
src/string/arm/__aeabi_memmove.c | 9 ---------
src/string/arm/__aeabi_memset.c | 9 ---------
src/string/arm/__aeabi_memset.s | 31 +++++++++++++++++++++++++++++
6 files changed, 73 insertions(+), 36 deletions(-)
delete mode 100644 src/string/arm/__aeabi_memclr.c
delete mode 100644 src/string/arm/__aeabi_memcpy.c
create mode 100644 src/string/arm/__aeabi_memcpy.s
delete mode 100644 src/string/arm/__aeabi_memmove.c
delete mode 100644 src/string/arm/__aeabi_memset.c
create mode 100644 src/string/arm/__aeabi_memset.s
diff --git a/src/string/arm/__aeabi_memclr.c b/src/string/arm/__aeabi_memclr.c
deleted file mode 100644
index a25306d7..00000000
--- a/src/string/arm/__aeabi_memclr.c
+++ /dev/null
@@ -1,9 +0,0 @@
-#include <string.h>
-#include "libc.h"
-
-void __aeabi_memclr(void *dest, size_t n)
-{
- memset(dest, 0, n);
-}
-weak_alias(__aeabi_memclr, __aeabi_memclr4);
-weak_alias(__aeabi_memclr, __aeabi_memclr8);
diff --git a/src/string/arm/__aeabi_memcpy.c b/src/string/arm/__aeabi_memcpy.c
deleted file mode 100644
index 4ae5c777..00000000
--- a/src/string/arm/__aeabi_memcpy.c
+++ /dev/null
@@ -1,9 +0,0 @@
-#include <string.h>
-#include "libc.h"
-
-void __aeabi_memcpy(void *restrict dest, const void *restrict src, size_t n)
-{
- memcpy(dest, src, n);
-}
-weak_alias(__aeabi_memcpy, __aeabi_memcpy4);
-weak_alias(__aeabi_memcpy, __aeabi_memcpy8);
diff --git a/src/string/arm/__aeabi_memcpy.s b/src/string/arm/__aeabi_memcpy.s
new file mode 100644
index 00000000..5dd9b027
--- /dev/null
+++ b/src/string/arm/__aeabi_memcpy.s
@@ -0,0 +1,42 @@
+.syntax unified
+
+.global __aeabi_memcpy8
+.global __aeabi_memcpy4
+.global __aeabi_memcpy
+.global __aeabi_memmove8
+.global __aeabi_memmove4
+.global __aeabi_memmove
+
+.type __aeabi_memcpy8,%function
+.type __aeabi_memcpy4,%function
+.type __aeabi_memcpy,%function
+.type __aeabi_memmove8,%function
+.type __aeabi_memmove4,%function
+.type __aeabi_memmove,%function
+
+__aeabi_memmove8:
+__aeabi_memmove4:
+__aeabi_memmove:
+ cmp r0, r1
+ bls 2f
+ cmp r2, #0
+ bxeq lr
+ add r0, r0, r2
+ add r2, r1, r2
+1: ldrb r3, [r2, #-1]!
+ cmp r1, r2
+ strb r3, [r0, #-1]!
+ bne 1b
+ bx lr
+__aeabi_memcpy8:
+__aeabi_memcpy4:
+__aeabi_memcpy:
+2: cmp r2, #0
+ bxeq lr
+ sub r0, r0, #1
+ add r2, r1, r2
+1: ldrb r3, [r1], #1
+ cmp r1, r2
+ strb r3, [r0, #1]!
+ bne 1b
+ bx lr
diff --git a/src/string/arm/__aeabi_memmove.c b/src/string/arm/__aeabi_memmove.c
deleted file mode 100644
index 951e7d39..00000000
--- a/src/string/arm/__aeabi_memmove.c
+++ /dev/null
@@ -1,9 +0,0 @@
-#include <string.h>
-#include "libc.h"
-
-void __aeabi_memmove(void *dest, const void *src, size_t n)
-{
- memmove(dest, src, n);
-}
-weak_alias(__aeabi_memmove, __aeabi_memmove4);
-weak_alias(__aeabi_memmove, __aeabi_memmove8);
diff --git a/src/string/arm/__aeabi_memset.c b/src/string/arm/__aeabi_memset.c
deleted file mode 100644
index 89299757..00000000
--- a/src/string/arm/__aeabi_memset.c
+++ /dev/null
@@ -1,9 +0,0 @@
-#include <string.h>
-#include "libc.h"
-
-void __aeabi_memset(void *dest, size_t n, int c)
-{
- memset(dest, c, n);
-}
-weak_alias(__aeabi_memset, __aeabi_memset4);
-weak_alias(__aeabi_memset, __aeabi_memset8);
diff --git a/src/string/arm/__aeabi_memset.s b/src/string/arm/__aeabi_memset.s
new file mode 100644
index 00000000..f2c85883
--- /dev/null
+++ b/src/string/arm/__aeabi_memset.s
@@ -0,0 +1,31 @@
+.syntax unified
+
+.global __aeabi_memclr8
+.global __aeabi_memclr4
+.global __aeabi_memclr
+.global __aeabi_memset8
+.global __aeabi_memset4
+.global __aeabi_memset
+
+.type __aeabi_memclr8,%function
+.type __aeabi_memclr4,%function
+.type __aeabi_memclr,%function
+.type __aeabi_memset8,%function
+.type __aeabi_memset4,%function
+.type __aeabi_memset,%function
+
+__aeabi_memclr8:
+__aeabi_memclr4:
+__aeabi_memclr:
+ mov r2, #0
+__aeabi_memset8:
+__aeabi_memset4:
+__aeabi_memset:
+ cmp r1, #0
+ bxeq lr
+ and r2, r2, #255
+ add r1, r0, r1
+1: strb r2, [r0], #1
+ cmp r1, r0
+ bne 1b
+ bx lr
--
2.11.0
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] fix arm run-time abi string functions
2017-02-21 1:15 [PATCH] fix arm run-time abi string functions Szabolcs Nagy
@ 2017-06-18 11:58 ` Szabolcs Nagy
2017-06-18 12:14 ` Alexander Monakov
1 sibling, 0 replies; 10+ messages in thread
From: Szabolcs Nagy @ 2017-06-18 11:58 UTC (permalink / raw)
To: musl
* Szabolcs Nagy <nsz@port70.net> [2017-02-21 02:15:08 +0100]:
> in arm rtabi these __aeabi_* functions have special abi (they are
> only allowed to clobber r0,r1,r2,r3,ip,lr,cpsr), so they cannot
> be simple wrappers around normal string functions (which may
> clobber other registers), the safest solution is to write them
> in asm, a naive implementation will do because these are not
> supposed to be emitted by compilers or used in general.
> ---
ping
> src/string/arm/__aeabi_memclr.c | 9 ---------
> src/string/arm/__aeabi_memcpy.c | 9 ---------
> src/string/arm/__aeabi_memcpy.s | 42 ++++++++++++++++++++++++++++++++++++++++
> src/string/arm/__aeabi_memmove.c | 9 ---------
> src/string/arm/__aeabi_memset.c | 9 ---------
> src/string/arm/__aeabi_memset.s | 31 +++++++++++++++++++++++++++++
> 6 files changed, 73 insertions(+), 36 deletions(-)
> delete mode 100644 src/string/arm/__aeabi_memclr.c
> delete mode 100644 src/string/arm/__aeabi_memcpy.c
> create mode 100644 src/string/arm/__aeabi_memcpy.s
> delete mode 100644 src/string/arm/__aeabi_memmove.c
> delete mode 100644 src/string/arm/__aeabi_memset.c
> create mode 100644 src/string/arm/__aeabi_memset.s
>
> diff --git a/src/string/arm/__aeabi_memclr.c b/src/string/arm/__aeabi_memclr.c
> deleted file mode 100644
> index a25306d7..00000000
> --- a/src/string/arm/__aeabi_memclr.c
> +++ /dev/null
> @@ -1,9 +0,0 @@
> -#include <string.h>
> -#include "libc.h"
> -
> -void __aeabi_memclr(void *dest, size_t n)
> -{
> - memset(dest, 0, n);
> -}
> -weak_alias(__aeabi_memclr, __aeabi_memclr4);
> -weak_alias(__aeabi_memclr, __aeabi_memclr8);
> diff --git a/src/string/arm/__aeabi_memcpy.c b/src/string/arm/__aeabi_memcpy.c
> deleted file mode 100644
> index 4ae5c777..00000000
> --- a/src/string/arm/__aeabi_memcpy.c
> +++ /dev/null
> @@ -1,9 +0,0 @@
> -#include <string.h>
> -#include "libc.h"
> -
> -void __aeabi_memcpy(void *restrict dest, const void *restrict src, size_t n)
> -{
> - memcpy(dest, src, n);
> -}
> -weak_alias(__aeabi_memcpy, __aeabi_memcpy4);
> -weak_alias(__aeabi_memcpy, __aeabi_memcpy8);
> diff --git a/src/string/arm/__aeabi_memcpy.s b/src/string/arm/__aeabi_memcpy.s
> new file mode 100644
> index 00000000..5dd9b027
> --- /dev/null
> +++ b/src/string/arm/__aeabi_memcpy.s
> @@ -0,0 +1,42 @@
> +.syntax unified
> +
> +.global __aeabi_memcpy8
> +.global __aeabi_memcpy4
> +.global __aeabi_memcpy
> +.global __aeabi_memmove8
> +.global __aeabi_memmove4
> +.global __aeabi_memmove
> +
> +.type __aeabi_memcpy8,%function
> +.type __aeabi_memcpy4,%function
> +.type __aeabi_memcpy,%function
> +.type __aeabi_memmove8,%function
> +.type __aeabi_memmove4,%function
> +.type __aeabi_memmove,%function
> +
> +__aeabi_memmove8:
> +__aeabi_memmove4:
> +__aeabi_memmove:
> + cmp r0, r1
> + bls 2f
> + cmp r2, #0
> + bxeq lr
> + add r0, r0, r2
> + add r2, r1, r2
> +1: ldrb r3, [r2, #-1]!
> + cmp r1, r2
> + strb r3, [r0, #-1]!
> + bne 1b
> + bx lr
> +__aeabi_memcpy8:
> +__aeabi_memcpy4:
> +__aeabi_memcpy:
> +2: cmp r2, #0
> + bxeq lr
> + sub r0, r0, #1
> + add r2, r1, r2
> +1: ldrb r3, [r1], #1
> + cmp r1, r2
> + strb r3, [r0, #1]!
> + bne 1b
> + bx lr
> diff --git a/src/string/arm/__aeabi_memmove.c b/src/string/arm/__aeabi_memmove.c
> deleted file mode 100644
> index 951e7d39..00000000
> --- a/src/string/arm/__aeabi_memmove.c
> +++ /dev/null
> @@ -1,9 +0,0 @@
> -#include <string.h>
> -#include "libc.h"
> -
> -void __aeabi_memmove(void *dest, const void *src, size_t n)
> -{
> - memmove(dest, src, n);
> -}
> -weak_alias(__aeabi_memmove, __aeabi_memmove4);
> -weak_alias(__aeabi_memmove, __aeabi_memmove8);
> diff --git a/src/string/arm/__aeabi_memset.c b/src/string/arm/__aeabi_memset.c
> deleted file mode 100644
> index 89299757..00000000
> --- a/src/string/arm/__aeabi_memset.c
> +++ /dev/null
> @@ -1,9 +0,0 @@
> -#include <string.h>
> -#include "libc.h"
> -
> -void __aeabi_memset(void *dest, size_t n, int c)
> -{
> - memset(dest, c, n);
> -}
> -weak_alias(__aeabi_memset, __aeabi_memset4);
> -weak_alias(__aeabi_memset, __aeabi_memset8);
> diff --git a/src/string/arm/__aeabi_memset.s b/src/string/arm/__aeabi_memset.s
> new file mode 100644
> index 00000000..f2c85883
> --- /dev/null
> +++ b/src/string/arm/__aeabi_memset.s
> @@ -0,0 +1,31 @@
> +.syntax unified
> +
> +.global __aeabi_memclr8
> +.global __aeabi_memclr4
> +.global __aeabi_memclr
> +.global __aeabi_memset8
> +.global __aeabi_memset4
> +.global __aeabi_memset
> +
> +.type __aeabi_memclr8,%function
> +.type __aeabi_memclr4,%function
> +.type __aeabi_memclr,%function
> +.type __aeabi_memset8,%function
> +.type __aeabi_memset4,%function
> +.type __aeabi_memset,%function
> +
> +__aeabi_memclr8:
> +__aeabi_memclr4:
> +__aeabi_memclr:
> + mov r2, #0
> +__aeabi_memset8:
> +__aeabi_memset4:
> +__aeabi_memset:
> + cmp r1, #0
> + bxeq lr
> + and r2, r2, #255
> + add r1, r0, r1
> +1: strb r2, [r0], #1
> + cmp r1, r0
> + bne 1b
> + bx lr
> --
> 2.11.0
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] fix arm run-time abi string functions
2017-02-21 1:15 [PATCH] fix arm run-time abi string functions Szabolcs Nagy
2017-06-18 11:58 ` Szabolcs Nagy
@ 2017-06-18 12:14 ` Alexander Monakov
2017-06-18 18:50 ` Szabolcs Nagy
1 sibling, 1 reply; 10+ messages in thread
From: Alexander Monakov @ 2017-06-18 12:14 UTC (permalink / raw)
To: musl
Sorry for a bit of extreme nit-picking, but
On Tue, 21 Feb 2017, Szabolcs Nagy wrote:
> +__aeabi_memmove8:
> +__aeabi_memmove4:
> +__aeabi_memmove:
> + cmp r0, r1
> + bls 2f
> + cmp r2, #0
> + bxeq lr
> + add r0, r0, r2
> + add r2, r1, r2
> +1: ldrb r3, [r2, #-1]!
> + cmp r1, r2
> + strb r3, [r0, #-1]!
> + bne 1b
> + bx lr
> +__aeabi_memcpy8:
> +__aeabi_memcpy4:
> +__aeabi_memcpy:
> +2: cmp r2, #0
> + bxeq lr
> + sub r0, r0, #1
> + add r2, r1, r2
> +1: ldrb r3, [r1], #1
> + cmp r1, r2
> + strb r3, [r0, #1]!
> + bne 1b
> + bx lr
here it's possible to hoist and deduplicate 'cmp r2, #0; bxeq lr' by placing it
prior to the direction check.
> +__aeabi_memclr8:
> +__aeabi_memclr4:
> +__aeabi_memclr:
> + mov r2, #0
> +__aeabi_memset8:
> +__aeabi_memset4:
> +__aeabi_memset:
> + cmp r1, #0
> + bxeq lr
> + and r2, r2, #255
here I don't see why the 'and' is useful, I don't think the following strb
needs high bits cleared?
> + add r1, r0, r1
> +1: strb r2, [r0], #1
> + cmp r1, r0
> + bne 1b
> + bx lr
Alexander
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] fix arm run-time abi string functions
2017-06-18 12:14 ` Alexander Monakov
@ 2017-06-18 18:50 ` Szabolcs Nagy
2017-06-18 19:05 ` Alexander Monakov
2017-06-18 19:11 ` Szabolcs Nagy
0 siblings, 2 replies; 10+ messages in thread
From: Szabolcs Nagy @ 2017-06-18 18:50 UTC (permalink / raw)
To: musl
* Alexander Monakov <amonakov@ispras.ru> [2017-06-18 15:14:51 +0300]:
> Sorry for a bit of extreme nit-picking, but
>
> On Tue, 21 Feb 2017, Szabolcs Nagy wrote:
> > +__aeabi_memmove8:
> > +__aeabi_memmove4:
> > +__aeabi_memmove:
> > + cmp r0, r1
> > + bls 2f
> > + cmp r2, #0
> > + bxeq lr
> > + add r0, r0, r2
> > + add r2, r1, r2
> > +1: ldrb r3, [r2, #-1]!
> > + cmp r1, r2
> > + strb r3, [r0, #-1]!
> > + bne 1b
> > + bx lr
> > +__aeabi_memcpy8:
> > +__aeabi_memcpy4:
> > +__aeabi_memcpy:
> > +2: cmp r2, #0
> > + bxeq lr
> > + sub r0, r0, #1
> > + add r2, r1, r2
> > +1: ldrb r3, [r1], #1
> > + cmp r1, r2
> > + strb r3, [r0, #1]!
> > + bne 1b
> > + bx lr
>
> here it's possible to hoist and deduplicate 'cmp r2, #0; bxeq lr' by placing it
> prior to the direction check.
>
i dont think there is a difference
(either way, both functions need to do this cmp once,
the executed insns are the same you just changed the
ordering a bit)
> > +__aeabi_memclr8:
> > +__aeabi_memclr4:
> > +__aeabi_memclr:
> > + mov r2, #0
> > +__aeabi_memset8:
> > +__aeabi_memset4:
> > +__aeabi_memset:
> > + cmp r1, #0
> > + bxeq lr
> > + and r2, r2, #255
>
> here I don't see why the 'and' is useful, I don't think the following strb
> needs high bits cleared?
>
indeed
(i wrote naive c code and compiled with gcc..
for some reason it did the and so i kept it, but
strb seems to ignore top bits according to spec)
shall i resend without and?
> > + add r1, r0, r1
> > +1: strb r2, [r0], #1
> > + cmp r1, r0
> > + bne 1b
> > + bx lr
>
> Alexander
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] fix arm run-time abi string functions
2017-06-18 18:50 ` Szabolcs Nagy
@ 2017-06-18 19:05 ` Alexander Monakov
2017-06-18 19:09 ` Szabolcs Nagy
2017-06-18 19:11 ` Szabolcs Nagy
1 sibling, 1 reply; 10+ messages in thread
From: Alexander Monakov @ 2017-06-18 19:05 UTC (permalink / raw)
To: musl
On Sun, 18 Jun 2017, Szabolcs Nagy wrote:
> > here it's possible to hoist and deduplicate 'cmp r2, #0; bxeq lr' by placing it
> > prior to the direction check.
> >
>
> i dont think there is a difference
> (either way, both functions need to do this cmp once,
> the executed insns are the same you just changed the
> ordering a bit)
I was pointing that out as a size optimization, but depending on alignment
of the following code it might be pointless indeed.
Alexander
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] fix arm run-time abi string functions
2017-06-18 19:05 ` Alexander Monakov
@ 2017-06-18 19:09 ` Szabolcs Nagy
2017-06-18 19:27 ` Alexander Monakov
0 siblings, 1 reply; 10+ messages in thread
From: Szabolcs Nagy @ 2017-06-18 19:09 UTC (permalink / raw)
To: musl
* Alexander Monakov <amonakov@ispras.ru> [2017-06-18 22:05:59 +0300]:
> On Sun, 18 Jun 2017, Szabolcs Nagy wrote:
> > > here it's possible to hoist and deduplicate 'cmp r2, #0; bxeq lr' by placing it
> > > prior to the direction check.
> > >
> >
> > i dont think there is a difference
> > (either way, both functions need to do this cmp once,
> > the executed insns are the same you just changed the
> > ordering a bit)
>
> I was pointing that out as a size optimization, but depending on alignment
> of the following code it might be pointless indeed.
>
i dont think the size changes, only the order of instructions
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] fix arm run-time abi string functions
2017-06-18 18:50 ` Szabolcs Nagy
2017-06-18 19:05 ` Alexander Monakov
@ 2017-06-18 19:11 ` Szabolcs Nagy
2017-06-18 19:40 ` Szabolcs Nagy
1 sibling, 1 reply; 10+ messages in thread
From: Szabolcs Nagy @ 2017-06-18 19:11 UTC (permalink / raw)
To: musl
* Szabolcs Nagy <nsz@port70.net> [2017-06-18 20:50:07 +0200]:
> * Alexander Monakov <amonakov@ispras.ru> [2017-06-18 15:14:51 +0300]:
> > Sorry for a bit of extreme nit-picking, but
> >
> > On Tue, 21 Feb 2017, Szabolcs Nagy wrote:
> > > +__aeabi_memmove8:
> > > +__aeabi_memmove4:
> > > +__aeabi_memmove:
> > > + cmp r0, r1
> > > + bls 2f
> > > + cmp r2, #0
> > > + bxeq lr
> > > + add r0, r0, r2
> > > + add r2, r1, r2
> > > +1: ldrb r3, [r2, #-1]!
> > > + cmp r1, r2
> > > + strb r3, [r0, #-1]!
> > > + bne 1b
> > > + bx lr
> > > +__aeabi_memcpy8:
> > > +__aeabi_memcpy4:
> > > +__aeabi_memcpy:
> > > +2: cmp r2, #0
> > > + bxeq lr
> > > + sub r0, r0, #1
> > > + add r2, r1, r2
> > > +1: ldrb r3, [r1], #1
> > > + cmp r1, r2
> > > + strb r3, [r0, #1]!
> > > + bne 1b
> > > + bx lr
> >
> > here it's possible to hoist and deduplicate 'cmp r2, #0; bxeq lr' by placing it
> > prior to the direction check.
> >
>
> i dont think there is a difference
> (either way, both functions need to do this cmp once,
> the executed insns are the same you just changed the
> ordering a bit)
>
> > > +__aeabi_memclr8:
> > > +__aeabi_memclr4:
> > > +__aeabi_memclr:
> > > + mov r2, #0
> > > +__aeabi_memset8:
> > > +__aeabi_memset4:
> > > +__aeabi_memset:
> > > + cmp r1, #0
> > > + bxeq lr
> > > + and r2, r2, #255
> >
> > here I don't see why the 'and' is useful, I don't think the following strb
> > needs high bits cleared?
> >
>
> indeed
> (i wrote naive c code and compiled with gcc..
> for some reason it did the and so i kept it, but
> strb seems to ignore top bits according to spec)
>
> shall i resend without and?
>
i cannot reproduce the gcc issue with and now, however..
> > > + add r1, r0, r1
> > > +1: strb r2, [r0], #1
it seems strb with postindex+writeback is armv6t,
so does not work in armv4t, i'll send an updated patch.
> > > + cmp r1, r0
> > > + bne 1b
> > > + bx lr
> >
> > Alexander
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] fix arm run-time abi string functions
2017-06-18 19:11 ` Szabolcs Nagy
@ 2017-06-18 19:40 ` Szabolcs Nagy
2017-06-22 22:39 ` Rich Felker
0 siblings, 1 reply; 10+ messages in thread
From: Szabolcs Nagy @ 2017-06-18 19:40 UTC (permalink / raw)
To: musl
[-- Attachment #1: Type: text/plain, Size: 302 bytes --]
* Szabolcs Nagy <nsz@port70.net> [2017-06-18 21:11:04 +0200]:
> > > > +1: strb r2, [r0], #1
>
> it seems strb with postindex+writeback is armv6t,
> so does not work in armv4t, i'll send an updated patch.
>
now i checked with all arch and thumb combinations
and gas accepts the new patch with them.
[-- Attachment #2: 0001-fix-arm-run-time-abi-string-functions.patch --]
[-- Type: text/x-diff, Size: 4822 bytes --]
From 2433c13b758499e8088170380322ef33252cd079 Mon Sep 17 00:00:00 2001
From: Szabolcs Nagy <nsz@port70.net>
Date: Tue, 21 Feb 2017 00:07:34 +0000
Subject: [PATCH] fix arm run-time abi string functions
in arm rtabi these __aeabi_* functions have special abi (they are
only allowed to clobber r0,r1,r2,r3,ip,lr,cpsr), so they cannot
be simple wrappers around normal string functions (which may
clobber other registers), the safest solution is to write them in
asm, a minimalistic implementation works because these are not
supposed to be emitted by compilers or used in general.
---
src/string/arm/__aeabi_memclr.c | 9 --------
src/string/arm/__aeabi_memcpy.c | 9 --------
src/string/arm/__aeabi_memcpy.s | 45 ++++++++++++++++++++++++++++++++++++++++
src/string/arm/__aeabi_memmove.c | 9 --------
src/string/arm/__aeabi_memset.c | 9 --------
src/string/arm/__aeabi_memset.s | 31 +++++++++++++++++++++++++++
6 files changed, 76 insertions(+), 36 deletions(-)
delete mode 100644 src/string/arm/__aeabi_memclr.c
delete mode 100644 src/string/arm/__aeabi_memcpy.c
create mode 100644 src/string/arm/__aeabi_memcpy.s
delete mode 100644 src/string/arm/__aeabi_memmove.c
delete mode 100644 src/string/arm/__aeabi_memset.c
create mode 100644 src/string/arm/__aeabi_memset.s
diff --git a/src/string/arm/__aeabi_memclr.c b/src/string/arm/__aeabi_memclr.c
deleted file mode 100644
index a25306d7..00000000
--- a/src/string/arm/__aeabi_memclr.c
+++ /dev/null
@@ -1,9 +0,0 @@
-#include <string.h>
-#include "libc.h"
-
-void __aeabi_memclr(void *dest, size_t n)
-{
- memset(dest, 0, n);
-}
-weak_alias(__aeabi_memclr, __aeabi_memclr4);
-weak_alias(__aeabi_memclr, __aeabi_memclr8);
diff --git a/src/string/arm/__aeabi_memcpy.c b/src/string/arm/__aeabi_memcpy.c
deleted file mode 100644
index 4ae5c777..00000000
--- a/src/string/arm/__aeabi_memcpy.c
+++ /dev/null
@@ -1,9 +0,0 @@
-#include <string.h>
-#include "libc.h"
-
-void __aeabi_memcpy(void *restrict dest, const void *restrict src, size_t n)
-{
- memcpy(dest, src, n);
-}
-weak_alias(__aeabi_memcpy, __aeabi_memcpy4);
-weak_alias(__aeabi_memcpy, __aeabi_memcpy8);
diff --git a/src/string/arm/__aeabi_memcpy.s b/src/string/arm/__aeabi_memcpy.s
new file mode 100644
index 00000000..3a527e41
--- /dev/null
+++ b/src/string/arm/__aeabi_memcpy.s
@@ -0,0 +1,45 @@
+.syntax unified
+
+.global __aeabi_memcpy8
+.global __aeabi_memcpy4
+.global __aeabi_memcpy
+.global __aeabi_memmove8
+.global __aeabi_memmove4
+.global __aeabi_memmove
+
+.type __aeabi_memcpy8,%function
+.type __aeabi_memcpy4,%function
+.type __aeabi_memcpy,%function
+.type __aeabi_memmove8,%function
+.type __aeabi_memmove4,%function
+.type __aeabi_memmove,%function
+
+__aeabi_memmove8:
+__aeabi_memmove4:
+__aeabi_memmove:
+ cmp r0, r1
+ bls 3f
+ cmp r2, #0
+ beq 2f
+ adds r0, r0, r2
+ adds r2, r1, r2
+1: subs r2, r2, #1
+ ldrb r3, [r2]
+ subs r0, r0, #1
+ strb r3, [r0]
+ cmp r1, r2
+ bne 1b
+2: bx lr
+__aeabi_memcpy8:
+__aeabi_memcpy4:
+__aeabi_memcpy:
+3: cmp r2, #0
+ beq 2f
+ adds r2, r1, r2
+1: ldrb r3, [r1]
+ adds r1, r1, #1
+ strb r3, [r0]
+ adds r0, r0, #1
+ cmp r1, r2
+ bne 1b
+2: bx lr
diff --git a/src/string/arm/__aeabi_memmove.c b/src/string/arm/__aeabi_memmove.c
deleted file mode 100644
index 951e7d39..00000000
--- a/src/string/arm/__aeabi_memmove.c
+++ /dev/null
@@ -1,9 +0,0 @@
-#include <string.h>
-#include "libc.h"
-
-void __aeabi_memmove(void *dest, const void *src, size_t n)
-{
- memmove(dest, src, n);
-}
-weak_alias(__aeabi_memmove, __aeabi_memmove4);
-weak_alias(__aeabi_memmove, __aeabi_memmove8);
diff --git a/src/string/arm/__aeabi_memset.c b/src/string/arm/__aeabi_memset.c
deleted file mode 100644
index 89299757..00000000
--- a/src/string/arm/__aeabi_memset.c
+++ /dev/null
@@ -1,9 +0,0 @@
-#include <string.h>
-#include "libc.h"
-
-void __aeabi_memset(void *dest, size_t n, int c)
-{
- memset(dest, c, n);
-}
-weak_alias(__aeabi_memset, __aeabi_memset4);
-weak_alias(__aeabi_memset, __aeabi_memset8);
diff --git a/src/string/arm/__aeabi_memset.s b/src/string/arm/__aeabi_memset.s
new file mode 100644
index 00000000..f9f60583
--- /dev/null
+++ b/src/string/arm/__aeabi_memset.s
@@ -0,0 +1,31 @@
+.syntax unified
+
+.global __aeabi_memclr8
+.global __aeabi_memclr4
+.global __aeabi_memclr
+.global __aeabi_memset8
+.global __aeabi_memset4
+.global __aeabi_memset
+
+.type __aeabi_memclr8,%function
+.type __aeabi_memclr4,%function
+.type __aeabi_memclr,%function
+.type __aeabi_memset8,%function
+.type __aeabi_memset4,%function
+.type __aeabi_memset,%function
+
+__aeabi_memclr8:
+__aeabi_memclr4:
+__aeabi_memclr:
+ movs r2, #0
+__aeabi_memset8:
+__aeabi_memset4:
+__aeabi_memset:
+ cmp r1, #0
+ beq 2f
+ adds r1, r0, r1
+1: strb r2, [r0]
+ adds r0, r0, #1
+ cmp r1, r0
+ bne 1b
+2: bx lr
--
2.12.2
^ permalink raw reply [flat|nested] 10+ messages in thread
* Re: [PATCH] fix arm run-time abi string functions
2017-06-18 19:40 ` Szabolcs Nagy
@ 2017-06-22 22:39 ` Rich Felker
0 siblings, 0 replies; 10+ messages in thread
From: Rich Felker @ 2017-06-22 22:39 UTC (permalink / raw)
To: musl
On Sun, Jun 18, 2017 at 09:40:52PM +0200, Szabolcs Nagy wrote:
> * Szabolcs Nagy <nsz@port70.net> [2017-06-18 21:11:04 +0200]:
> > > > > +1: strb r2, [r0], #1
> >
> > it seems strb with postindex+writeback is armv6t,
> > so does not work in armv4t, i'll send an updated patch.
> >
>
> now i checked with all arch and thumb combinations
> and gas accepts the new patch with them.
> [....]
OK, committed.
Rich
^ permalink raw reply [flat|nested] 10+ messages in thread
end of thread, other threads:[~2017-06-22 22:39 UTC | newest]
Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-02-21 1:15 [PATCH] fix arm run-time abi string functions Szabolcs Nagy
2017-06-18 11:58 ` Szabolcs Nagy
2017-06-18 12:14 ` Alexander Monakov
2017-06-18 18:50 ` Szabolcs Nagy
2017-06-18 19:05 ` Alexander Monakov
2017-06-18 19:09 ` Szabolcs Nagy
2017-06-18 19:27 ` Alexander Monakov
2017-06-18 19:11 ` Szabolcs Nagy
2017-06-18 19:40 ` Szabolcs Nagy
2017-06-22 22:39 ` Rich Felker
Code repositories for project(s) associated with this public inbox
https://git.vuxu.org/mirror/musl/
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).