1 /* Copyright (C) 1996-2018 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
3 Written by Ulrich Drepper, <drepper@cygnus.com>.
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/>. */
22 #include <libc-diag.h>
24 /* Find index of weight. */
25 static inline int32_t __attribute__ ((always_inline
))
26 findidx (const int32_t *table
,
27 const int32_t *indirect
,
28 const unsigned char *extra
,
29 const unsigned char **cpp
, size_t len
)
31 int_fast32_t i
= table
[*(*cpp
)++];
32 const unsigned char *cp
;
33 const unsigned char *usrc
;
36 /* This is an index into the weight table. Cool. */
39 /* Oh well, more than one sequence starting with this byte.
40 Search for the correct one. */
48 /* The first thing is the index. */
49 i
= *((const int32_t *) cp
);
50 cp
+= sizeof (int32_t);
52 /* Next is the length of the byte sequence. These are always
53 short byte sequences so there is no reason to call any
54 function (even if they are inlined). */
59 /* It is a single character. If it matches we found our
60 index. Note that at the end of each list there is an
61 entry of length zero which represents the single byte
62 sequence. The first (and here only) byte was tested
66 /* With GCC 5.3 when compiling with -Os the compiler warns
67 that seq2.back_us, which becomes usrc, might be used
68 uninitialized. This can't be true because we pass a length
69 of -1 for len at the same time which means that this loop
71 DIAG_PUSH_NEEDS_COMMENT
;
72 DIAG_IGNORE_Os_NEEDS_COMMENT (5, "-Wmaybe-uninitialized");
73 for (cnt
= 0; cnt
< nhere
&& cnt
< len
; ++cnt
)
74 if (cp
[cnt
] != usrc
[cnt
])
76 DIAG_POP_NEEDS_COMMENT
;
85 /* Up to the next entry. */
87 if (!LOCFILE_ALIGNED_P (1 + nhere
))
88 cp
+= LOCFILE_ALIGN
- (1 + nhere
) % LOCFILE_ALIGN
;
92 /* This is a range of characters. First decide whether the
93 current byte sequence lies in the range. */
97 for (cnt
= 0; cnt
< nhere
&& cnt
< len
; ++cnt
)
98 if (cp
[cnt
] != usrc
[cnt
])
103 if (cnt
== len
|| cp
[cnt
] > usrc
[cnt
])
105 /* Cannot be in this range. */
107 if (!LOCFILE_ALIGNED_P (1 + 2 * nhere
))
109 - (1 + 2 * nhere
) % LOCFILE_ALIGN
);
113 /* Test against the end of the range. */
114 for (cnt
= 0; cnt
< nhere
; ++cnt
)
115 if (cp
[nhere
+ cnt
] != usrc
[cnt
])
118 if (cnt
!= nhere
&& cp
[nhere
+ cnt
] < usrc
[cnt
])
120 /* Cannot be in this range. */
122 if (!LOCFILE_ALIGNED_P (1 + 2 * nhere
))
124 - (1 + 2 * nhere
) % LOCFILE_ALIGN
);
128 /* This range matches the next characters. Now find
129 the offset in the indirect table. */
130 for (cnt
= 0; cp
[cnt
] == usrc
[cnt
]; ++cnt
);
135 /* With GCC 7 when compiling with -Os the compiler
136 warns that seq1.back_us and seq2.back_us, which
137 become usrc, might be used uninitialized. This
138 is impossible for the same reason as described
140 DIAG_PUSH_NEEDS_COMMENT
;
141 DIAG_IGNORE_Os_NEEDS_COMMENT (7, "-Wmaybe-uninitialized");
142 offset
+= usrc
[cnt
] - cp
[cnt
];
143 DIAG_POP_NEEDS_COMMENT
;
145 while (++cnt
< nhere
);
149 return indirect
[-i
+ offset
];
157 #endif /* weight.h */