* [U-Boot] [PATCH V4 1/3] lib_generic memcpy: copy one word at a time if possible
[not found] ` <cover.1255168028.git.rubini@unipv.it>
@ 2009-10-10 9:51 ` Alessandro Rubini
2009-10-18 21:10 ` Wolfgang Denk
2009-10-10 9:51 ` [U-Boot] [PATCH V4 2/3] lib_generic memset: fill " Alessandro Rubini
2009-10-10 9:51 ` [U-Boot] [PATCH V4 3/3] lcd: remove '#if 0' 32-bit scroll, now memcpy does it Alessandro Rubini
2 siblings, 1 reply; 8+ messages in thread
From: Alessandro Rubini @ 2009-10-10 9:51 UTC (permalink / raw)
To: u-boot
From: Alessandro Rubini <rubini@unipv.it>
If source and destination are aligned, this copies ulong values
until possible, trailing part is copied by byte. Thanks for the details
to Wolfgang Denk, Mike Frysinger, Peter Tyser, Chris Moore.
Signed-off-by: Alessandro Rubini <rubini@unipv.it>
Acked-by: Andrea Gallo <andrea.gallo@stericsson.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>
---
lib_generic/string.c | 19 +++++++++++++++----
1 files changed, 15 insertions(+), 4 deletions(-)
diff --git a/lib_generic/string.c b/lib_generic/string.c
index 181eda6..61a45dc 100644
--- a/lib_generic/string.c
+++ b/lib_generic/string.c
@@ -446,12 +446,23 @@ char * bcopy(const char * src, char * dest, int count)
* You should not use this function to access IO space, use memcpy_toio()
* or memcpy_fromio() instead.
*/
-void * memcpy(void * dest,const void *src,size_t count)
+void * memcpy(void *dest, const void *src, size_t count)
{
- char *tmp = (char *) dest, *s = (char *) src;
-
+ unsigned long *dl = (unsigned long *)dest, *sl = (unsigned long *)src;
+ char *d8, *s8;
+
+ /* while all data is aligned (common case), copy a word at a time */
+ if ( (((ulong)dest | (ulong)src) & (sizeof(*dl) - 1)) == 0) {
+ while (count >= sizeof(*dl)) {
+ *dl++ = *sl++;
+ count -= sizeof(*dl);
+ }
+ }
+ /* copy the reset one byte at a time */
+ d8 = (char *)dl;
+ s8 = (char *)sl;
while (count--)
- *tmp++ = *s++;
+ *d8++ = *s8++;
return dest;
}
--
1.6.0.2
^ permalink raw reply related [flat|nested] 8+ messages in thread* [U-Boot] [PATCH V4 1/3] lib_generic memcpy: copy one word at a time if possible
2009-10-10 9:51 ` [U-Boot] [PATCH V4 1/3] lib_generic memcpy: copy one word at a time if possible Alessandro Rubini
@ 2009-10-18 21:10 ` Wolfgang Denk
0 siblings, 0 replies; 8+ messages in thread
From: Wolfgang Denk @ 2009-10-18 21:10 UTC (permalink / raw)
To: u-boot
Dear Alessandro Rubini,
In message <cceb84d6368125b2d1003ebced494b45ca2cf999.1255168028.git.rubini@ unipv.it> you wrote:
> From: Alessandro Rubini <rubini@unipv.it>
>
> If source and destination are aligned, this copies ulong values
> until possible, trailing part is copied by byte. Thanks for the details
> to Wolfgang Denk, Mike Frysinger, Peter Tyser, Chris Moore.
>
> Signed-off-by: Alessandro Rubini <rubini@unipv.it>
> Acked-by: Andrea Gallo <andrea.gallo@stericsson.com>
> Acked-by: Mike Frysinger <vapier@gentoo.org>
> ---
> lib_generic/string.c | 19 +++++++++++++++----
> 1 files changed, 15 insertions(+), 4 deletions(-)
Applied, thanks.
Best regards,
Wolfgang Denk
--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Madness has no purpose. Or reason. But it may have a goal.
-- Spock, "The Alternative Factor", stardate 3088.7
^ permalink raw reply [flat|nested] 8+ messages in thread
* [U-Boot] [PATCH V4 2/3] lib_generic memset: fill one word at a time if possible
[not found] ` <cover.1255168028.git.rubini@unipv.it>
2009-10-10 9:51 ` [U-Boot] [PATCH V4 1/3] lib_generic memcpy: copy one word at a time if possible Alessandro Rubini
@ 2009-10-10 9:51 ` Alessandro Rubini
[not found] ` <ab1169840f2a99906a81d8512922f5911dc9c0f1.1255168028.git.rubini@unipv.it>
` (2 more replies)
2009-10-10 9:51 ` [U-Boot] [PATCH V4 3/3] lcd: remove '#if 0' 32-bit scroll, now memcpy does it Alessandro Rubini
2 siblings, 3 replies; 8+ messages in thread
From: Alessandro Rubini @ 2009-10-10 9:51 UTC (permalink / raw)
To: u-boot
From: Alessandro Rubini <rubini@unipv.it>
If the destination is aligned, fill ulong values until possible.
Then fill remaining part by byte.
Signed-off-by: Alessandro Rubini <rubini@unipv.it>
Acked-by: Andrea Gallo <andrea.gallo@stericsson.com>
Acked-by: Mike Frysinger <vapier@gentoo.org>
---
lib_generic/string.c | 22 +++++++++++++++++++---
1 files changed, 19 insertions(+), 3 deletions(-)
diff --git a/lib_generic/string.c b/lib_generic/string.c
index 61a45dc..b375b81 100644
--- a/lib_generic/string.c
+++ b/lib_generic/string.c
@@ -403,10 +403,26 @@ char *strswab(const char *s)
*/
void * memset(void * s,int c,size_t count)
{
- char *xs = (char *) s;
-
+ unsigned long *sl = (unsigned long *) s;
+ unsigned long cl = 0;
+ char *s8;
+ int i;
+
+ /* do it one word at a time (32 bits or 64 bits) while possible */
+ if ( ((ulong)s & (sizeof(*sl) - 1)) == 0) {
+ for (i = 0; i < sizeof(*sl); i++) {
+ cl <<= 8;
+ cl |= c & 0xff;
+ }
+ while (count >= sizeof(*sl)) {
+ *sl++ = cl;
+ count -= sizeof(*sl);
+ }
+ }
+ /* fill 8 bits at a time */
+ s8 = (char *)sl;
while (count--)
- *xs++ = c;
+ *s8++ = c;
return s;
}
--
1.6.0.2
^ permalink raw reply related [flat|nested] 8+ messages in thread[parent not found: <ab1169840f2a99906a81d8512922f5911dc9c0f1.1255168028.git.rubini@unipv.it>]
* [U-Boot] [PATCH V4 2/3] lib_generic memset: fill one word at a time if possible
[not found] ` <ab1169840f2a99906a81d8512922f5911dc9c0f1.1255168028.git.rubini@unipv.it>
@ 2009-10-10 10:43 ` Joakim Tjernlund
0 siblings, 0 replies; 8+ messages in thread
From: Joakim Tjernlund @ 2009-10-10 10:43 UTC (permalink / raw)
To: u-boot
u-boot-bounces at lists.denx.de wrote on 10/10/2009 11:51:16:
> From:
>
> Alessandro Rubini <rubini-list@gnudd.com>
>
> To:
>
> u-boot at lists.denx.de
>
> Cc:
>
> STEricsson_nomadik_linux at list.st.com, andrea.gallo at stericsson.com
>
> Date:
>
> 10/10/2009 11:51
>
> Subject:
>
> [U-Boot] [PATCH V4 2/3] lib_generic memset: fill one word at a time if possible
>
> Sent by:
>
> u-boot-bounces at lists.denx.de
>
> From: Alessandro Rubini <rubini@unipv.it>
>
> If the destination is aligned, fill ulong values until possible.
> Then fill remaining part by byte.
>
> Signed-off-by: Alessandro Rubini <rubini@unipv.it>
> Acked-by: Andrea Gallo <andrea.gallo@stericsson.com>
> Acked-by: Mike Frysinger <vapier@gentoo.org>
> ---
> lib_generic/string.c | 22 +++++++++++++++++++---
> 1 files changed, 19 insertions(+), 3 deletions(-)
>
> diff --git a/lib_generic/string.c b/lib_generic/string.c
> index 61a45dc..b375b81 100644
> --- a/lib_generic/string.c
> +++ b/lib_generic/string.c
> @@ -403,10 +403,26 @@ char *strswab(const char *s)
> */
> void * memset(void * s,int c,size_t count)
> {
> - char *xs = (char *) s;
> -
> + unsigned long *sl = (unsigned long *) s;
> + unsigned long cl = 0;
> + char *s8;
> + int i;
> +
> + /* do it one word at a time (32 bits or 64 bits) while possible */
> + if ( ((ulong)s & (sizeof(*sl) - 1)) == 0) {
> + for (i = 0; i < sizeof(*sl); i++) {
> + cl <<= 8;
> + cl |= c & 0xff;
> + }
> + while (count >= sizeof(*sl)) {
> + *sl++ = cl;
> + count -= sizeof(*sl);
> + }
The above while can be slow if not the complier manages to turn into:
for(wc = count / sizeof(*sl); wc; --wc) {
*sl++ = cl;
}
count = count & (sizeof(*sl)-1);
even better would be:
for(--sl, wc = count / sizeof(*sl); wc; --wc) {
*++sl = cl;
}
++sl;
count = count & (sizeof(*sl)-1);
for those arch's that can do pre inc and load/store in one
instruction.
Just figured I should mention it.
^ permalink raw reply [flat|nested] 8+ messages in thread
[parent not found: <OF174ADC43.E238E9B3-ONC125764B.0039E83E-C125764B.003AEEB3@tran smode.se>]
* [U-Boot] [PATCH V4 2/3] lib_generic memset: fill one word at a time if possible
2009-10-10 9:51 ` [U-Boot] [PATCH V4 2/3] lib_generic memset: fill " Alessandro Rubini
[not found] ` <ab1169840f2a99906a81d8512922f5911dc9c0f1.1255168028.git.rubini@unipv.it>
[not found] ` <OF174ADC43.E238E9B3-ONC125764B.0039E83E-C125764B.003AEEB3@tran smode.se>
@ 2009-10-18 21:11 ` Wolfgang Denk
2 siblings, 0 replies; 8+ messages in thread
From: Wolfgang Denk @ 2009-10-18 21:11 UTC (permalink / raw)
To: u-boot
Dear Alessandro Rubini,
In message <ab1169840f2a99906a81d8512922f5911dc9c0f1.1255168028.git.rubini@ unipv.it> you wrote:
> From: Alessandro Rubini <rubini@unipv.it>
>
> If the destination is aligned, fill ulong values until possible.
> Then fill remaining part by byte.
>
> Signed-off-by: Alessandro Rubini <rubini@unipv.it>
> Acked-by: Andrea Gallo <andrea.gallo@stericsson.com>
> Acked-by: Mike Frysinger <vapier@gentoo.org>
> ---
> lib_generic/string.c | 22 +++++++++++++++++++---
> 1 files changed, 19 insertions(+), 3 deletions(-)
Applied, thanks.
Best regards,
Wolfgang Denk
--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
"A witty saying proves nothing." - Voltaire
^ permalink raw reply [flat|nested] 8+ messages in thread
* [U-Boot] [PATCH V4 3/3] lcd: remove '#if 0' 32-bit scroll, now memcpy does it
[not found] ` <cover.1255168028.git.rubini@unipv.it>
2009-10-10 9:51 ` [U-Boot] [PATCH V4 1/3] lib_generic memcpy: copy one word at a time if possible Alessandro Rubini
2009-10-10 9:51 ` [U-Boot] [PATCH V4 2/3] lib_generic memset: fill " Alessandro Rubini
@ 2009-10-10 9:51 ` Alessandro Rubini
2009-10-18 21:11 ` Wolfgang Denk
2 siblings, 1 reply; 8+ messages in thread
From: Alessandro Rubini @ 2009-10-10 9:51 UTC (permalink / raw)
To: u-boot
From: Alessandro Rubini <rubini@unipv.it>
Signed-off-by: Alessandro Rubini <rubini@unipv.it>
Acked-by: Andrea Gallo <andrea.gallo@stericsson.com>
---
common/lcd.c | 21 ---------------------
1 files changed, 0 insertions(+), 21 deletions(-)
diff --git a/common/lcd.c b/common/lcd.c
index dc8fea6..4e31618 100644
--- a/common/lcd.c
+++ b/common/lcd.c
@@ -99,32 +99,11 @@ static int lcd_getfgcolor (void);
static void console_scrollup (void)
{
-#if 1
/* Copy up rows ignoring the first one */
memcpy (CONSOLE_ROW_FIRST, CONSOLE_ROW_SECOND, CONSOLE_SCROLL_SIZE);
/* Clear the last one */
memset (CONSOLE_ROW_LAST, COLOR_MASK(lcd_color_bg), CONSOLE_ROW_SIZE);
-#else
- /*
- * Poor attempt to optimize speed by moving "long"s.
- * But the code is ugly, and not a bit faster :-(
- */
- ulong *t = (ulong *)CONSOLE_ROW_FIRST;
- ulong *s = (ulong *)CONSOLE_ROW_SECOND;
- ulong l = CONSOLE_SCROLL_SIZE / sizeof(ulong);
- uchar c = lcd_color_bg & 0xFF;
- ulong val= (c<<24) | (c<<16) | (c<<8) | c;
-
- while (l--)
- *t++ = *s++;
-
- t = (ulong *)CONSOLE_ROW_LAST;
- l = CONSOLE_ROW_SIZE / sizeof(ulong);
-
- while (l-- > 0)
- *t++ = val;
-#endif
}
/*----------------------------------------------------------------------*/
--
1.6.0.2
^ permalink raw reply related [flat|nested] 8+ messages in thread* [U-Boot] [PATCH V4 3/3] lcd: remove '#if 0' 32-bit scroll, now memcpy does it
2009-10-10 9:51 ` [U-Boot] [PATCH V4 3/3] lcd: remove '#if 0' 32-bit scroll, now memcpy does it Alessandro Rubini
@ 2009-10-18 21:11 ` Wolfgang Denk
0 siblings, 0 replies; 8+ messages in thread
From: Wolfgang Denk @ 2009-10-18 21:11 UTC (permalink / raw)
To: u-boot
Dear Alessandro Rubini,
In message <a492794e122bec9e622a27c0b5cf895602ef1ffd.1255168028.git.rubini@ unipv.it> you wrote:
> From: Alessandro Rubini <rubini@unipv.it>
>
> Signed-off-by: Alessandro Rubini <rubini@unipv.it>
> Acked-by: Andrea Gallo <andrea.gallo@stericsson.com>
> ---
> common/lcd.c | 21 ---------------------
> 1 files changed, 0 insertions(+), 21 deletions(-)
Applied, thanks.
Best regards,
Wolfgang Denk
--
DENX Software Engineering GmbH, MD: Wolfgang Denk & Detlev Zundel
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
If in any problem you find yourself doing an immense amount of work,
the answer can be obtained by simple inspection.
^ permalink raw reply [flat|nested] 8+ messages in thread