1 /* Copyright (C) 1996-2022 Free Software Foundation, Inc.
2 This file is part of the GNU C Library.
4 The GNU C Library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
9 The GNU C Library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
14 You should have received a copy of the GNU Lesser General Public
15 License along with the GNU C Library; if not, see
16 <https://www.gnu.org/licenses/>. */
21 #include <libc-diag.h>
23 /* Find index of weight. */
24 static inline int32_t __attribute__ ((always_inline
))
25 findidx (const int32_t *table
,
26 const int32_t *indirect
,
27 const unsigned char *extra
,
28 const unsigned char **cpp
, size_t len
)
30 int_fast32_t i
= table
[*(*cpp
)++];
31 const unsigned char *cp
;
32 const unsigned char *usrc
;
35 /* This is an index into the weight table. Cool. */
38 /* Oh well, more than one sequence starting with this byte.
39 Search for the correct one. */
47 /* The first thing is the index. */
48 i
= *((const int32_t *) cp
);
49 cp
+= sizeof (int32_t);
51 /* Next is the length of the byte sequence. These are always
52 short byte sequences so there is no reason to call any
53 function (even if they are inlined). */
58 /* It is a single character. If it matches we found our
59 index. Note that at the end of each list there is an
60 entry of length zero which represents the single byte
61 sequence. The first (and here only) byte was tested
65 /* With GCC 5.3 when compiling with -Os the compiler warns
66 that seq2.back_us, which becomes usrc, might be used
67 uninitialized. This can't be true because we pass a length
68 of -1 for len at the same time which means that this loop
70 DIAG_PUSH_NEEDS_COMMENT
;
71 DIAG_IGNORE_Os_NEEDS_COMMENT (5, "-Wmaybe-uninitialized");
72 for (cnt
= 0; cnt
< nhere
&& cnt
< len
; ++cnt
)
73 if (cp
[cnt
] != usrc
[cnt
])
75 DIAG_POP_NEEDS_COMMENT
;
84 /* Up to the next entry. */
86 if (!LOCFILE_ALIGNED_P (1 + nhere
))
87 cp
+= LOCFILE_ALIGN
- (1 + nhere
) % LOCFILE_ALIGN
;
91 /* This is a range of characters. First decide whether the
92 current byte sequence lies in the range. */
96 for (cnt
= 0; cnt
< nhere
&& cnt
< len
; ++cnt
)
97 if (cp
[cnt
] != usrc
[cnt
])
102 if (cnt
== len
|| cp
[cnt
] > usrc
[cnt
])
104 /* Cannot be in this range. */
106 if (!LOCFILE_ALIGNED_P (1 + 2 * nhere
))
108 - (1 + 2 * nhere
) % LOCFILE_ALIGN
);
112 /* Test against the end of the range. */
113 for (cnt
= 0; cnt
< nhere
; ++cnt
)
114 if (cp
[nhere
+ cnt
] != usrc
[cnt
])
117 if (cnt
!= nhere
&& cp
[nhere
+ cnt
] < usrc
[cnt
])
119 /* Cannot be in this range. */
121 if (!LOCFILE_ALIGNED_P (1 + 2 * nhere
))
123 - (1 + 2 * nhere
) % LOCFILE_ALIGN
);
127 /* This range matches the next characters. Now find
128 the offset in the indirect table. */
129 for (cnt
= 0; cp
[cnt
] == usrc
[cnt
]; ++cnt
);
134 /* With GCC 7 when compiling with -Os the compiler
135 warns that seq1.back_us and seq2.back_us, which
136 become usrc, might be used uninitialized. This
137 is impossible for the same reason as described
139 DIAG_PUSH_NEEDS_COMMENT
;
140 DIAG_IGNORE_Os_NEEDS_COMMENT (7, "-Wmaybe-uninitialized");
141 offset
+= usrc
[cnt
] - cp
[cnt
];
142 DIAG_POP_NEEDS_COMMENT
;
144 while (++cnt
< nhere
);
148 return indirect
[-i
+ offset
];
156 #endif /* weight.h */