diff mbox

[11/11] alpha: Add haszero.h and whichzero.h

Message ID 20161217065729.28561-12-rth@twiddle.net
State New
Headers show

Commit Message

Richard Henderson Dec. 17, 2016, 6:57 a.m. UTC
While alpha has the more important string functions in assembly,
there are still a few for which the generic routines are used.

Use the CMPBGE insn, via the builtin, for testing of zeros.  Use a
simplified expansion of __builtin_ctz when the insn isn't available.

	* sysdeps/alpha/haszero.h: New file.
	* sysdeps/alpha/whichzero.h: New file.
---
 sysdeps/alpha/haszero.h   | 36 +++++++++++++++++++++++++++++++
 sysdeps/alpha/whichzero.h | 55 +++++++++++++++++++++++++++++++++++++++++++++++
 2 files changed, 91 insertions(+)
 create mode 100644 sysdeps/alpha/haszero.h
 create mode 100644 sysdeps/alpha/whichzero.h
diff mbox

Patch

diff --git a/sysdeps/alpha/haszero.h b/sysdeps/alpha/haszero.h
new file mode 100644
index 0000000..e5c2c49
--- /dev/null
+++ b/sysdeps/alpha/haszero.h
@@ -0,0 +1,36 @@ 
+/* haszero.h -- function for zero byte detection.  Alpha version.
+   Copyright (C) 2016 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef HASZERO_H
+#define HASZERO_H	1
+
+static inline unsigned long int
+haszero(unsigned long int x)
+{
+  return __builtin_alpha_cmpbge (0, x);
+}
+
+/* Likewise, but for two words simultaneously.  */
+
+static inline unsigned long int
+haszero2(unsigned long int x1, unsigned long int x2)
+{
+  return __builtin_alpha_cmpbge (0, x1) | __builtin_alpha_cmpbge (0, x2);
+}
+
+#endif /* haszero.h */
diff --git a/sysdeps/alpha/whichzero.h b/sysdeps/alpha/whichzero.h
new file mode 100644
index 0000000..3f8e5c9
--- /dev/null
+++ b/sysdeps/alpha/whichzero.h
@@ -0,0 +1,55 @@ 
+/* whichzero.h -- functions for zero byte searching.  Alpha version.
+   Copyright (C) 2016 Free Software Foundation, Inc.
+   This file is part of the GNU C Library.
+
+   The GNU C Library is free software; you can redistribute it and/or
+   modify it under the terms of the GNU Lesser General Public
+   License as published by the Free Software Foundation; either
+   version 2.1 of the License, or (at your option) any later version.
+
+   The GNU C Library is distributed in the hope that it will be useful,
+   but WITHOUT ANY WARRANTY; without even the implied warranty of
+   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+   Lesser General Public License for more details.
+
+   You should have received a copy of the GNU Lesser General Public
+   License along with the GNU C Library; if not, see
+   <http://www.gnu.org/licenses/>.  */
+
+#ifndef WHICHZERO_H
+#define WHICHZERO_H 1
+
+/* A subroutine for the whichzero and whichzero2 functions.  Given a
+   test word C, return the index of the first byte in memory order
+   that contains 0x80 (all other bits will be zero).  */
+
+static inline unsigned int
+whichzero_ffs(unsigned long int c)
+{
+#ifdef __alpha_cix__
+  return __builtin_ctzl (c);
+#else
+  c = c & -c;
+  return (c & 0xf0 ? 4 : 0) + (c & 0xcc ? 2 : 0) + (c & 0xaa ? 1 : 0);
+#endif
+}
+
+/* Given a long that is known to contain a zero byte, return the
+   index of the first such within the long in host memory order.  */
+
+static inline unsigned int
+whichzero(unsigned long int x)
+{
+  return whichzero_ffs (__builtin_alpha_cmpbge (0, x));
+}
+
+/* Similarly, but perform the test for two longs simultaneously.  */
+
+static inline unsigned int
+whichzero2(unsigned long int x1, unsigned long int x2)
+{
+  return whichzero_ffs (__builtin_alpha_cmpbge (0, x1)
+		        | __builtin_alpha_cmpbge (0, x2));
+}
+
+#endif /* whichzero.h */