Add Changelog ...
[glibc.git] / sysdeps / tile / tilegx / string-endian.h
blobc2e40ecd4fe5def8338ad90bb2e163eb4d2f8856
1 /* Copyright (C) 2011-2012 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Contributed by Chris Metcalf <cmetcalf@tilera.com>, 2011.
5 The GNU C Library is free software; you can redistribute it and/or
6 modify it under the terms of the GNU Lesser General Public
7 License as published by the Free Software Foundation; either
8 version 2.1 of the License, or (at your option) any later version.
10 The GNU C Library is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 Lesser General Public License for more details.
15 You should have received a copy of the GNU Lesser General Public
16 License along with the GNU C Library. If not, see
17 <http://www.gnu.org/licenses/>. */
19 /* Provide a mask based on the pointer alignment that
20 sets up non-zero bytes before the beginning of the string.
21 The MASK expression works because shift counts are taken mod 64.
22 Also, specify how to count "first" and "last" bits
23 when the bits have been read as a word. */
25 #ifndef __BIG_ENDIAN__
26 #define MASK(x) (__insn_shl(1ULL, (x << 3)) - 1)
27 #define NULMASK(x) ((2ULL << x) - 1)
28 #define CFZ(x) __insn_ctz(x)
29 #define REVCZ(x) __insn_clz(x)
30 #else
31 #define MASK(x) (__insn_shl(-2LL, ((-x << 3) - 1)))
32 #define NULMASK(x) (-2LL << (63 - x))
33 #define CFZ(x) __insn_clz(x)
34 #define REVCZ(x) __insn_ctz(x)
35 #endif
37 /* Create eight copies of the byte in a uint64_t. */
38 static inline uint64_t copy_byte(uint8_t byte)
40 uint64_t word = byte;
41 word = __insn_bfins(word, word, 8, 15);
42 word = __insn_bfins(word, word, 16, 31);
43 word = __insn_bfins(word, word, 32, 63);
44 return word;