diff options
author | David Schleef <ds@schleef.org> | 2005-05-02 09:06:04 +0000 |
---|---|---|
committer | David Schleef <ds@schleef.org> | 2005-05-02 09:06:04 +0000 |
commit | 68c2c4e577f39f9a230cd065a34be13a0cd0b72e (patch) | |
tree | 166fdc103fda5906762d97dcb76a0021139c8308 /liboil/utf8 | |
parent | 83c2d5d15012e22f310067cf58d0b53abf527682 (diff) | |
download | liboil-68c2c4e577f39f9a230cd065a34be13a0cd0b72e.tar.gz |
* liboil/utf8/Makefile.am:
* liboil/utf8/utf8_fast.c: Some implementations.
Diffstat (limited to 'liboil/utf8')
-rw-r--r-- | liboil/utf8/Makefile.am | 2 | ||||
-rw-r--r-- | liboil/utf8/utf8_fast.c | 187 |
2 files changed, 188 insertions, 1 deletions
diff --git a/liboil/utf8/Makefile.am b/liboil/utf8/Makefile.am index 163f592..2c24921 100644 --- a/liboil/utf8/Makefile.am +++ b/liboil/utf8/Makefile.am @@ -9,7 +9,7 @@ noinst_LTLIBRARIES = libutf8.la $(opt_libs) noinst_HEADERS = utf8.h -c_sources = utf8.c +c_sources = utf8.c utf8_fast.c if HAVE_CPU_I386 #i386_sources = utf8_i386.c diff --git a/liboil/utf8/utf8_fast.c b/liboil/utf8/utf8_fast.c new file mode 100644 index 0000000..7f70837 --- /dev/null +++ b/liboil/utf8/utf8_fast.c @@ -0,0 +1,187 @@ +/* + * LIBOIL - Library of Optimized Inner Loops + * Copyright (c) 2004 David A. Schleef <ds@schleef.org> + * All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * + * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR + * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED + * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, + * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES + * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR + * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, + * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING + * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifdef HAVE_CONFIG_H +#include "config.h" +#endif + +#include <liboil/liboil.h> +#include "liboil/utf8/utf8.h" + + +void +utf8_validate_fast (int32_t *d_1, uint8_t *s, int n) +{ + int i; + int extra_bytes; + int mask; + + i=0; + while (i<n) { + if ((*(uint32_t *)(s+i) & 0x80808080) == 0) { + i+=4; + continue; + } + if (s[i] < 128) { + i++; + continue; + } + if ((s[i] & 0xe0) == 0xc0) { + extra_bytes = 1; + mask = 0x7f; + } else if ((s[i] & 0xf0) == 0xe0) { + extra_bytes = 2; + mask = 0x1f; + } else if ((s[i] & 0xf8) == 0xf0) { + extra_bytes = 3; + mask = 0x0f; + } else { + goto error; + } + if (i + extra_bytes >= n) goto error; + while(extra_bytes--) { + if ((s[i] & 0xc0) != 0x80) goto error; + i++; + } + i++; + } + +error: + d_1[0] = i; +} +OIL_DEFINE_IMPL (utf8_validate_fast, utf8_validate); + +void +utf8_validate_fast2 (int32_t *d_1, uint8_t *s, int n) +{ + int i; + uint8_t x; + + i=0; + while (i<n) { + x = s[i]; + if (s[i] < 128) { + i++; + continue; + } + x <<= 1; + if (s[i] < 128) { + i++; + if ((s[i] & 0xc0) != 0x80) goto error; + i++; + continue; + } + x <<= 1; + if (s[i] < 128) { + i++; + if ((s[i] & 0xc0) != 0x80) goto error; + i++; + if ((s[i] & 0xc0) != 0x80) goto error; + i++; + continue; + } + x <<= 1; + if (s[i] < 128) { + i++; + if ((s[i] & 0xc0) != 0x80) goto error; + i++; + if ((s[i] & 0xc0) != 0x80) goto error; + i++; + if ((s[i] & 0xc0) != 0x80) goto error; + i++; + continue; + } + goto error; + } + +error: + d_1[0] = i; +} +OIL_DEFINE_IMPL (utf8_validate_fast2, utf8_validate); + +#if 0 +void +utf8_validate_asm1 (int32_t *d_1, uint8_t *s, int n) +{ + uint8_t *tmp = s; + + asm ( + "1:\n" + " movb (%%eax), %%bl\n" + " testb %%bl, %%bl\n" + //" jns 3f\n" + " js 2f\n" + "3:\n" + " addl $1, %%eax\n" + " subl $1, %%ecx\n" + " jne 1b\n" + "2:\n" + : "+a" (tmp), "+c" (n) + : + : "ebx" ); + + d_1[0] = tmp - s; +} +OIL_DEFINE_IMPL (utf8_validate_asm1, utf8_validate); + +void +utf8_validate_asm2 (int32_t *d_1, uint8_t *s, int n) +{ + uint8_t *tmp = s; + + asm ( + "1:\n" + " testl $0x80808080, (%%eax)\n" + " jne 2f\n" + " testl $0x80808080, 4(%%eax)\n" + " jne 2f\n" + " testl $0x80808080, 8(%%eax)\n" + " jne 2f\n" + " testl $0x80808080, 12(%%eax)\n" + " jne 2f\n" + " addl $16, %%eax\n" + " subl $16, %%ecx\n" + " jge 1b\n" + " jl 4f\n" + "2:\n" + " movb (%%eax), %%bl\n" + " testb %%bl, %%bl\n" + " js 4f\n" + "3:\n" + " addl $1, %%eax\n" + " subl $1, %%ecx\n" + " jne 1b\n" + "4:\n" + : "+a" (tmp), "+c" (n) + : + : "ebx" ); + + d_1[0] = tmp - s; +} +OIL_DEFINE_IMPL (utf8_validate_asm2, utf8_validate); +#endif + |