diff mbox

Improve bzero performance

Message ID 001c01d02e7a$15e03f50$41a0bdf0$@com
State New
Headers show

Commit Message

Wilco Jan. 12, 2015, 3:11 p.m. UTC
Rather than using a C implementation of memset, directly call memset, which typically has a much
faster optimized implementation.

ChangeLog:

2015-01-12  Wilco Dijkstra  wdijkstr@arm.com

    * string/bzero.c (__bzero): Call memset for performance.

---
 string/bzero.c | 58 +++-------------------------------------------------------
 1 file changed, 3 insertions(+), 55 deletions(-)

Comments

Roland McGrath Jan. 13, 2015, 6:39 p.m. UTC | #1
This is fine.  I think it's safe enough during the freeze, but there is no
burning (melting?) reason to rush it if folks are feeling conservative.
Roland McGrath Jan. 13, 2015, 6:40 p.m. UTC | #2
> +#include <stddef.h>
>  #include <string.h>

Actually, there is no reason for this new #include.  Drop it.
Wilco Feb. 27, 2015, 3:03 p.m. UTC | #3
> Roland McGrath wrote:
> > +#include <stddef.h>
> >  #include <string.h>
> 
> Actually, there is no reason for this new #include.  Drop it.

OK, committed without the include.

Wilco
diff mbox

Patch

diff --git a/string/bzero.c b/string/bzero.c
index 9c220b9..f1a0584 100644
--- a/string/bzero.c
+++ b/string/bzero.c
@@ -16,67 +16,15 @@ 
    License along with the GNU C Library; if not, see
    <http://www.gnu.org/licenses/>.  */
 
+#include <stddef.h>
 #include <string.h>
-#include <memcopy.h>
 
 #undef __bzero
 
 /* Set N bytes of S to 0.  */
 void
-__bzero (s, len)
-     void *s;
-     size_t len;
+__bzero (void *s, size_t len)
 {
-  long int dstp = (long int) s;
-  const op_t zero = 0;
-
-  if (len >= 8)
-    {
-      size_t xlen;
-
-      /* There are at least some bytes to zero.  No need to test
-	 for LEN == 0 in this alignment loop.  */
-      while (dstp % OPSIZ != 0)
-	{
-	  ((byte *) dstp)[0] = 0;
-	  dstp += 1;
-	  len -= 1;
-	}
-
-      /* Write 8 op_t per iteration until less than 8 op_t remain.  */
-      xlen = len / (OPSIZ * 8);
-      while (xlen != 0)
-	{
-	  ((op_t *) dstp)[0] = zero;
-	  ((op_t *) dstp)[1] = zero;
-	  ((op_t *) dstp)[2] = zero;
-	  ((op_t *) dstp)[3] = zero;
-	  ((op_t *) dstp)[4] = zero;
-	  ((op_t *) dstp)[5] = zero;
-	  ((op_t *) dstp)[6] = zero;
-	  ((op_t *) dstp)[7] = zero;
-	  dstp += 8 * OPSIZ;
-	  xlen -= 1;
-	}
-      len %= OPSIZ * 8;
-
-      /* Write 1 op_t per iteration until less than op_t remain.  */
-      xlen = len / OPSIZ;
-      while (xlen != 0)
-	{
-	  ((op_t *) dstp)[0] = zero;
-	  dstp += OPSIZ;
-	  xlen -= 1;
-	}
-      len %= OPSIZ;
-    }
-
-  /* Write the last few bytes.  */
-  while (len != 0)
-    {
-      ((byte *) dstp)[0] = 0;
-      dstp += 1;
-      len -= 1;
-    }
+  memset (s, '\0', len);
 }
 weak_alias (__bzero, bzero)