• Stars
    star
    217
  • Rank 182,446 (Top 4 %)
  • Language
    C
  • Created about 5 years ago
  • Updated over 4 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

A very fast library for validating UTF-8 using AVX2/SSE4 instructions

faster-utf8-validator

This library is a very fast UTF-8 validator using AVX2/SSE4 instructions. As far as I am aware, it is the fastest validator in the world on the CPUs that support these instructions (...and not AVX-512). Using AVX2, it can validate random UTF-8 text as fast as .26 cycles/byte, and random ASCII text at .09 cycles/byte. For UTF-8, this is roughly 1.5-1.7x faster than the fastvalidate-utf-8 library.

This repository contains the library (one C file), a build script for the make.py build system, and a Lua test script (which requires LuaJIT due to use of the ffi module).

A detailed description of the algorithm can be found in z_validate.c. This algorithm should map fairly nicely to AVX-512, and should in fact be a bit faster than 2x the speed of AVX2 since a few instructions can be saved. But I don't have an AVX-512 machine, so I haven't tried it yet.

Benchmark

Here's some raw numbers, measured on my 2.4GHz Haswell laptop, using a modified version of the benchmark in the fastvalidate-utf-8 repository. There are four configurations of test input: random UTF-8 bytes or random ASCII bytes, and either 64K bytes or 16M bytes. All measurements are the best of 50 runs, with each run using a different random seed, but each validator tested with the same seeds (and thus the same inputs). All measurements are in cycles per byte. The first two rows are the fastvalidate-utf-8 AVX2 functions, and the second two rows are this library, using AVX2 and SSE4 instruction sets.

Validator 64K UTF-8 64K ASCII 16M UTF-8 16M ASCII
validate_utf8_fast_avx 0.410 0.410 0.496 0.429
validate_utf8_fast_avx_asciipath 0.436 0.074 0.457 0.156
z_validate_utf8_avx2 0.264 0.079 0.290 0.160
z_validate_utf8_sse4 0.568 0.163 0.596 0.202

More Repositories

1

x86-sat

Basic SAT model of x86 instructions using Z3, autogenerated from Intel docs
Python
312
star
2

x86-info-term

A terminal viewer for x86 instruction/intrinsic information using Python 3 + curses
Python
127
star
3

zp7

ZP7: Zach's Peppy Parallel-Prefix-Popcountin' PEXT/PDEP Polyfill
C
43
star
4

make.py

make.py, a fast Python-based build tool (fork of https://code.google.com/archive/p/make-py/)
Python
26
star
5

mutagen

Mutagen, a purely functional programming language with Pythonic syntax
Python
15
star
6

Miroslav

A proof-of-concept for a fast regex matcher using lossy NFA matching on SIMD
C++
12
star
7

sprdpl

Simple Python Recursive-Descent Parsing Library
Python
11
star
8

game-about-squares-solver

Solver for Game About Squares (gameaboutsquares.com)
Python
7
star
9

undulance

Python Software Synthesis Framework
Python
6
star
10

CubingB

CubingB is a timer/analyzer for speedsolving Rubik's cubes, with smart cube support
Python
6
star
11

slidey-blocky-thingy

Clone of Unblock Me/Rush Hour type games in react.js, with Python solver/puzzle generator
JavaScript
5
star
12

zmt

A vim-esque editor with a C backend and luajit frontend
C
3
star
13

obfusound

Old obfuscated sound-generating program, utilizing (asexual) genetic algorithms over tiny programs that run on a simple virtual machine.
C
2
star
14

stretchy

A basic Linjat/Ordinary Puzzles clone made with React
JavaScript
2
star
15

lc3b-sim

A simulator for the LC-3b microarchitecture.
C
2
star
16

pythonc

Pythonc, a Python 3->C++ compiler.
Python
2
star
17

tinychess

A very small obfuscated chess engine in C.
C
2
star
18

boro

Boro is a very basic Amazons engine written in C. It uses very dumb monte carlo/UCT for AI.
C
2
star
19

quines

Some old quines I wrote intermittently between 2008 and 2010
C
1
star
20

zct

ZCT, my old chess program
C
1
star
21

switchy

A simple javascript game of questionable entertainment value
Python
1
star
22

speedy

Speedy is a basic bitboard chess move generator framework in C.
C
1
star
23

prethon

Prethon is a Python based preprocessor. Take a text/code/whatever file with embedded Python macros and generate more text/code/whatever.
Python
1
star