]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
tilegx: small performance fix for string routines
authorChris Metcalf <cmetcalf@tilera.com>
Fri, 11 May 2012 22:03:58 +0000 (18:03 -0400)
committerChris Metcalf <cmetcalf@tilera.com>
Mon, 14 May 2012 19:46:12 +0000 (15:46 -0400)
We were multiplying a byte by 0x0101010101010101ULL to create a
constant for SIMD ops, but the compiler isn't good at optimizing
this case (the fact that one operand is a byte is lost by the time
it would be possible to do the optimization).  So instead we add
a helper routine that explicitly uses SIMD ops to create the constant.

ChangeLog.tile
sysdeps/tile/tilegx/memchr.c
sysdeps/tile/tilegx/memset.c
sysdeps/tile/tilegx/rawmemchr.c
sysdeps/tile/tilegx/strchr.c
sysdeps/tile/tilegx/strchrnul.c
sysdeps/tile/tilegx/string-endian.h
sysdeps/tile/tilegx/strrchr.c

index 83136aa6c34dee8f4b3d7ac0396fec9600820fd8..3c192e908ac21b8c0ea35f56b73e204e881463af 100644 (file)
@@ -1,3 +1,14 @@
+2012-05-12  Chris Metcalf  <cmetcalf@tilera.com>
+
+       * sysdeps/tile/tilegx/memchr.c: Use new copy_byte() function
+       to efficiently generate a large constant for masking.
+       * sysdeps/tile/tilegx/memset.c: Likewise.
+       * sysdeps/tile/tilegx/rawmemchr.c: Likewise.
+       * sysdeps/tile/tilegx/strchr.c: Likewise.
+       * sysdeps/tile/tilegx/strchrnul.c: Likewise.
+       * sysdeps/tile/tilegx/strrchr.c: Likewise.
+       * sysdeps/tile/tilegx/string-endian.h (copy_byte): New function.
+
 2012-05-12  Chris Metcalf  <cmetcalf@tilera.com>
 
        * sysdeps/tile/tilegx/memcpy.c: Allow memcpy(p, p, n)
index aea25ff303b8122f72251cf12a9f1faebc4bfaa0..32f24ec43ecc5d9997e8282df4333a2c062c99e4 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2011 Free Software Foundation, Inc.
+/* Copyright (C) 2011-2012 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
 
@@ -41,7 +41,7 @@ __memchr (const void *s, int c, size_t n)
   p = (const uint64_t *) (s_int & -8);
 
   /* Create eight copies of the byte for which we are looking. */
-  goal = 0x0101010101010101ULL * (uint8_t) c;
+  goal = copy_byte(c);
 
   /* Read the first word, but munge it so that bytes before the array
      will not match goal.  */
index 8083abf5cbc57b428c0e4869e641c9d3fd81e72d..dad3eadc5acb3f496295e0545d817ba5aeebac34 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2011 Free Software Foundation, Inc.
+/* Copyright (C) 2011-2012 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
 
@@ -19,6 +19,7 @@
 #include <arch/chip.h>
 #include <string.h>
 #include <stdint.h>
+#include "string-endian.h"
 
 void *
 __memset (void *s, int c, size_t n)
@@ -71,7 +72,7 @@ __memset (void *s, int c, size_t n)
   n64 = n >> 3;
 
   /* Tile input byte out to 64 bits. */
-  v64 = 0x0101010101010101ULL * (uint8_t) c;
+  v64 = copy_byte(c);
 
   /* This must be at least 8 or the following loop doesn't work. */
 #define CACHE_LINE_SIZE_IN_DOUBLEWORDS (CHIP_L2_LINE_SIZE() / 8)
index ed9162d1c1245849060706b48d63122f19273996..70b5928ebc88aaf4a26e157e5d8e286c632dec2a 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2011 Free Software Foundation, Inc.
+/* Copyright (C) 2011-2012 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
 
@@ -28,7 +28,7 @@ __rawmemchr (const void *s, int c)
   const uint64_t *p = (const uint64_t *) (s_int & -8);
 
   /* Create eight copies of the byte for which we are looking. */
-  const uint64_t goal = 0x0101010101010101ULL * (uint8_t) c;
+  const uint64_t goal = copy_byte(c);
 
   /* Read the first word, but munge it so that bytes before the array
      will not match goal.  */
index 8ef4fdc04d44f1923aa564748e0acc7cbe75b9a9..c6a741b37d7c892ecf638e60d819d73f4bb6aa59 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2011 Free Software Foundation, Inc.
+/* Copyright (C) 2011-2012 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
 
@@ -32,7 +32,7 @@ strchr (const char *s, int c)
   const uint64_t *p = (const uint64_t *) (s_int & -8);
 
   /* Create eight copies of the byte for which we are looking. */
-  const uint64_t goal = 0x0101010101010101ULL * (uint8_t) c;
+  const uint64_t goal = copy_byte(c);
 
   /* Read the first aligned word, but force bytes before the string to
      match neither zero nor goal (we make sure the high bit of each byte
index 11814431b51c0301d484a86120d403d6b62b5616..4251598dca8901cc19ff301c51529ac3d16446cd 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2011 Free Software Foundation, Inc.
+/* Copyright (C) 2011-2012 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
 
@@ -30,7 +30,7 @@ __strchrnul (const char *s, int c)
   const uint64_t *p = (const uint64_t *) (s_int & -8);
 
   /* Create eight copies of the byte for which we are looking. */
-  const uint64_t goal = 0x0101010101010101ULL * (uint8_t) c;
+  const uint64_t goal = copy_byte(c);
 
   /* Read the first aligned word, but force bytes before the string to
      match neither zero nor goal (we make sure the high bit of each byte
index 280efd37762d0428966df1a86aa1e9dfd51c6bfd..c2e40ecd4fe5def8338ad90bb2e163eb4d2f8856 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2011 Free Software Foundation, Inc.
+/* Copyright (C) 2011-2012 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
 
 #define CFZ(x) __insn_clz(x)
 #define REVCZ(x) __insn_ctz(x)
 #endif
+
+/* Create eight copies of the byte in a uint64_t. */
+static inline uint64_t copy_byte(uint8_t byte)
+{
+  uint64_t word = byte;
+  word = __insn_bfins(word, word, 8, 15);
+  word = __insn_bfins(word, word, 16, 31);
+  word = __insn_bfins(word, word, 32, 63);
+  return word;
+}
index 223c59dd4cc7851f7407053130f2fd03a5e9a9ea..b6e43a6832648eecac329292ac30a9f0db55ef97 100644 (file)
@@ -1,4 +1,4 @@
-/* Copyright (C) 2011 Free Software Foundation, Inc.
+/* Copyright (C) 2011-2012 Free Software Foundation, Inc.
    This file is part of the GNU C Library.
    Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
 
@@ -28,7 +28,7 @@ strrchr (const char *s, int c)
   const uint64_t *p = (const uint64_t *) (s_int & -8);
 
   /* Create eight copies of the byte for which we are looking. */
-  const uint64_t goal = 0x0101010101010101ULL * (uint8_t) c;
+  const uint64_t goal = copy_byte(c);
 
   /* Read the first aligned word, but force bytes before the string to
      match neither zero nor goal (we make sure the high bit of each byte