Update contrib.
2 * LIBOIL - Library of Optimized Inner Loops
3 * Copyright (c) 2004 David A. Schleef <ds@schleef.org>
6 * Redistribution and use in source and binary forms, with or without
7 * modification, are permitted provided that the following conditions
9 * 1. Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * 2. Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in the
13 * documentation and/or other materials provided with the distribution.
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
19 * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
23 * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
24 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 * POSSIBILITY OF SUCH DAMAGE.
27 //Portions Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies). All rights reserved.
33 #include <liboil/liboil.h>
34 #include "liboil/utf8/utf8.h"
37 #ifdef HAVE_UNALIGNED_ACCESS
39 utf8_validate_fast (int32_t *d_1, uint8_t *s, int n)
47 if (i < n-3 && (*(uint32_t *)(s+i) & 0x80808080) == 0) {
55 if ((s[i] & 0xe0) == 0xc0) {
58 } else if ((s[i] & 0xf0) == 0xe0) {
61 } else if ((s[i] & 0xf8) == 0xf0) {
67 if (i + extra_bytes >= n) goto error;
68 while(extra_bytes--) {
70 if ((s[i] & 0xc0) != 0x80) goto error;
78 OIL_DEFINE_IMPL (utf8_validate_fast, utf8_validate);
82 utf8_validate_fast2 (int32_t *d_1, uint8_t *s, int n)
100 if (i + 1 >= n) goto error;
102 if ((s[i] & 0xc0) != 0x80) goto error;
108 if (i + 2 >= n) goto error;
110 if ((s[i] & 0xc0) != 0x80) goto error;
112 if ((s[i] & 0xc0) != 0x80) goto error;
118 if (i + 3 >= n) goto error;
120 if ((s[i] & 0xc0) != 0x80) goto error;
122 if ((s[i] & 0xc0) != 0x80) goto error;
124 if ((s[i] & 0xc0) != 0x80) goto error;
134 OIL_DEFINE_IMPL (utf8_validate_fast2, utf8_validate);
136 #ifdef HAVE_UNALIGNED_ACCESS
138 utf8_validate_fast3 (int32_t *d_1, uint8_t *s, int n)
145 if (i < n-3 && (*(uint32_t *)(s+i) & 0x80808080) == 0) {
158 if (i + 1 >= n) goto error;
160 if ((s[i] & 0xc0) != 0x80) goto error;
165 if (i + 2 >= n) goto error;
167 if ((s[i] & 0xc0) != 0x80) goto error;
169 if ((s[i] & 0xc0) != 0x80) goto error;
174 if (i + 3 >= n) goto error;
176 if ((s[i] & 0xc0) != 0x80) goto error;
178 if ((s[i] & 0xc0) != 0x80) goto error;
180 if ((s[i] & 0xc0) != 0x80) goto error;
190 OIL_DEFINE_IMPL (utf8_validate_fast3, utf8_validate);
193 static uint8_t utf8_table[256] = {
194 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
195 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
196 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
197 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
198 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
199 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
200 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
201 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
202 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
203 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
204 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
205 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8, 8,
206 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
207 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1,
208 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,
209 3, 3, 3, 3, 3, 3, 3, 3, 8, 8, 8, 8, 8, 8, 8, 8
213 utf8_validate_lookup (int32_t *d_1, uint8_t *s, int n)
220 x = utf8_table[s[i]];
222 if (x == 8 || i + x >= n) goto error;
225 if ((s[i] & 0xc0) != 0x80) goto error;
235 OIL_DEFINE_IMPL (utf8_validate_lookup, utf8_validate);
239 utf8_validate_asm1 (int32_t *d_1, uint8_t *s, int n)
245 " movb (%%eax), %%bl\n"
246 " testb %%bl, %%bl\n"
254 : "+a" (tmp), "+c" (n)
260 OIL_DEFINE_IMPL (utf8_validate_asm1, utf8_validate);
263 utf8_validate_asm2 (int32_t *d_1, uint8_t *s, int n)
269 " testl $0x80808080, (%%eax)\n"
271 " testl $0x80808080, 4(%%eax)\n"
273 " testl $0x80808080, 8(%%eax)\n"
275 " testl $0x80808080, 12(%%eax)\n"
282 " movb (%%eax), %%bl\n"
283 " testb %%bl, %%bl\n"
290 : "+a" (tmp), "+c" (n)
296 OIL_DEFINE_IMPL (utf8_validate_asm2, utf8_validate);
301 #ifdef HAVE_UNALIGNED_ACCESS
304 OilFunctionImpl* __oil_function_impl_utf8_validate_fast() {
305 return &_oil_function_impl_utf8_validate_fast;
312 OilFunctionImpl* __oil_function_impl_utf8_validate_fast2() {
313 return &_oil_function_impl_utf8_validate_fast2;
317 #ifdef HAVE_UNALIGNED_ACCESS
320 OilFunctionImpl* __oil_function_impl_utf8_validate_fast3() {
321 return &_oil_function_impl_utf8_validate_fast3;
328 OilFunctionImpl* __oil_function_impl_utf8_validate_lookup() {
329 return &_oil_function_impl_utf8_validate_lookup;
335 OilFunctionImpl* __oil_function_impl_utf8_validate_asm1() {
336 return &_oil_function_impl_utf8_validate_asm1;
342 OilFunctionImpl* __oil_function_impl_utf8_validate_asm2() {
343 return &_oil_function_impl_utf8_validate_asm2;