Add MAP_SHARED_VALIDATE from Linux 4.15.
[glibc.git] / sysdeps / tile / string-endian.h
blob3a2d4953792e07d97762448db899636168abbd64
1 /* Copyright (C) 2011-2018 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 #include <endian.h>
20 #include <stdint.h>
22 /* Provide a set of macros to help keep endianness #ifdefs out of
23 the string functions.
25 MASK: Provide a mask based on the pointer alignment that
26 sets up non-zero bytes before the beginning of the string.
27 The MASK expression works because shift counts are taken mod 64.
29 NULMASK: Clear bytes beyond a given point in the string.
31 CFZ: Find the first zero bit in the 8 string bytes in a long.
33 REVCZ: Find the last zero bit in the 8 string bytes in a long.
35 STRSHIFT: Shift N bits towards the start of the string. */
37 #if __BYTE_ORDER == __LITTLE_ENDIAN
38 #define MASK(x) (__insn_shl(1ULL, (x << 3)) - 1)
39 #define NULMASK(x) ((2ULL << x) - 1)
40 #define CFZ(x) __insn_ctz(x)
41 #define REVCZ(x) __insn_clz(x)
42 #define STRSHIFT(x,n) ((x) >> n)
43 #else
44 #define MASK(x) (__insn_shl(-2LL, ((-x << 3) - 1)))
45 #define NULMASK(x) (-2LL << (63 - x))
46 #define CFZ(x) __insn_clz(x)
47 #define REVCZ(x) __insn_ctz(x)
48 #define STRSHIFT(x,n) ((x) << n)
49 #endif
51 /* Create eight copies of the byte in a uint64_t. Byte Shuffle uses
52 the bytes of srcB as the index into the dest vector to select a
53 byte. With all indices of zero, the first byte is copied into all
54 the other bytes. */
55 static inline uint64_t copy_byte(uint8_t byte)
57 return __insn_shufflebytes(byte, 0, 0);
60 /* Implement the byte vector instructions using extended assembly.
61 The __insn_OP() builtins are buggy in the upstream compiler;
62 see gcc bugzilla 78117. */
64 #define VECOP(OP) \
65 static inline uint64_t OP (uint64_t a, uint64_t b) \
66 { \
67 uint64_t result; \
68 asm volatile (#OP " %0, %1, %2" : "=r"(result) : "r"(a), "r"(b)); \
69 return result; \
70 } \
72 static inline uint64_t OP ## i (uint64_t a, uint64_t b) \
73 { \
74 uint64_t result; \
75 asm volatile (#OP "i %0, %1, %2" : "=r"(result) : "r"(a), "I"(b)); \
76 return result; \
79 VECOP(v1cmpeq)
80 VECOP(v1cmpltu)
81 VECOP(v1cmpne)
82 VECOP(v1add)
83 VECOP(v1shru)
84 VECOP(v1shl)