aboutsummaryrefslogtreecommitdiff
path: root/libffwd
diff options
context:
space:
mode:
authorOnur Gündüz <ogunduz@gmail.com>2026-09-29 12:54:13 +0200
committerOnur Gündüz <ogunduz@gmail.com>2026-09-29 12:54:13 +0200
commit91871be6ece9317c5d49353f6474583e7e28168d (patch)
tree8cabf2546322a9e1b724bf8413f32de54378824f /libffwd
parent35ab9c12ba4d396e6cba99d6ea947e26becedad4 (diff)
downloadlangdet-91871be6ece9317c5d49353f6474583e7e28168d.tar.gz
langdet-91871be6ece9317c5d49353f6474583e7e28168d.zip
Add native CPU language detection CLI
Diffstat (limited to 'libffwd')
-rw-r--r--libffwd/LICENSE20
-rw-r--r--libffwd/act.c90
-rw-r--r--libffwd/alloc.c91
-rw-r--r--libffwd/alloc.h31
-rw-r--r--libffwd/attn.c458
-rw-r--r--libffwd/avx.c271
-rw-r--r--libffwd/bpe.c1898
-rw-r--r--libffwd/bpe.h74
-rw-r--r--libffwd/config.c341
-rw-r--r--libffwd/config.h8
-rw-r--r--libffwd/dtype.h55
-rw-r--r--libffwd/ffwd.h281
-rw-r--r--libffwd/forward.c721
-rw-r--r--libffwd/gemm.c429
-rw-r--r--libffwd/generic.c44
-rw-r--r--libffwd/impl.h280
-rw-r--r--libffwd/internal.h129
-rw-r--r--libffwd/kernels.h181
-rw-r--r--libffwd/model.c511
-rw-r--r--libffwd/model_blas.c201
-rw-r--r--libffwd/model_internal.h85
-rw-r--r--libffwd/model_types.h122
-rw-r--r--libffwd/neon.c118
-rw-r--r--libffwd/norm.c138
-rw-r--r--libffwd/rope.c137
-rw-r--r--libffwd/safetensors.c518
-rw-r--r--libffwd/safetensors.h71
-rw-r--r--libffwd/sentencepiece.c947
-rw-r--r--libffwd/sentencepiece.h88
-rw-r--r--libffwd/threadpool.c218
-rw-r--r--libffwd/threadpool.h30
-rw-r--r--libffwd/tokenize.c349
-rw-r--r--libffwd/unicode.h4992
-rw-r--r--libffwd/vec.c47
-rw-r--r--libffwd/wordpiece.c679
-rw-r--r--libffwd/wordpiece.h72
36 files changed, 14725 insertions, 0 deletions
diff --git a/libffwd/LICENSE b/libffwd/LICENSE
new file mode 100644
index 0000000..a00caa7
--- /dev/null
+++ b/libffwd/LICENSE
@@ -0,0 +1,20 @@
+MIT License
+
+Copyright (c) 2026 The ffwd authors
+
+Permission is hereby granted, free of charge, to any person obtaining a copy of
+this software and associated documentation files (the "Software"), to deal in
+the Software without restriction, including without limitation the rights to
+use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
+the Software, and to permit persons to whom the Software is furnished to do so,
+subject to the following conditions:
+
+The above copyright notice and this permission notice shall be included in all
+copies or substantial portions of the Software.
+
+THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
+FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
+COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
+IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
+CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
diff --git a/libffwd/act.c b/libffwd/act.c
new file mode 100644
index 0000000..2495311
--- /dev/null
+++ b/libffwd/act.c
@@ -0,0 +1,90 @@
+/* Activation kernels: softmax, SiLU-gated multiply, and the erf and tanh GeLU variants. */
+
+#include <math.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "impl.h"
+#include "kernels.h"
+
+#if (defined(__AVX512F__) || defined(__AVX2__)) && \
+ (defined(__x86_64__) || defined(__i386__) || defined(_M_X64) || defined(_M_IX86))
+# include <immintrin.h>
+#endif
+#if defined(__ARM_NEON) || defined(__ARM_NEON__)
+# include <arm_neon.h>
+#endif
+
+#ifdef USE_BLAS
+# ifdef __APPLE__
+# include <Accelerate/Accelerate.h>
+# else
+# include <cblas.h>
+# endif
+#endif
+
+#ifndef M_PI
+# define M_PI 3.14159265358979323846
+#endif
+
+void silu_mul_inplace(float *gate, const float *up, int n) {
+#if defined(__APPLE__) && defined(USE_BLAS)
+ enum { CHUNK = 4096 };
+ float exp_neg[CHUNK];
+
+ for (int base = 0; base < n; base += CHUNK) {
+ int len = n - base;
+ if (len > CHUNK)
+ len = CHUNK;
+
+ for (int i = 0; i < len; i++)
+ exp_neg[i] = -gate[base + i];
+ vvexpf(exp_neg, exp_neg, &len);
+
+ for (int i = 0; i < len; i++) {
+ float g = gate[base + i];
+ gate[base + i] = (g / (1.0f + exp_neg[i])) * up[base + i];
+ }
+ }
+#else
+ for (int i = 0; i < n; i++) {
+ float g = gate[i];
+ gate[i] = (g / (1.0f + expf(-g))) * up[i];
+ }
+#endif
+}
+
+void gelu_inplace(float *x, int n) {
+ /* Exact erf GeLU; 0.70710678... = 1/sqrt(2). */
+ for (int i = 0; i < n; i++)
+ x[i] = 0.5f * x[i] * (1.0f + erff(x[i] * 0.70710678118654752f));
+}
+
+void gelu_tanh_inplace(float *x, int n) {
+ /* Tanh-approximation GeLU; 0.79788456... = sqrt(2/pi). */
+ for (int i = 0; i < n; i++) {
+ float v = x[i];
+ float inner = 0.79788456080286536f * (v + 0.044715f * v * v * v);
+ x[i] = 0.5f * v * (1.0f + tanhf(inner));
+ }
+}
+
+void softmax(float *x, int rows, int cols) {
+ for (int r = 0; r < rows; r++) {
+ float *row = x + r * cols;
+ float max_val = row[0];
+ for (int c = 1; c < cols; c++) {
+ if (row[c] > max_val)
+ max_val = row[c];
+ }
+ float sum = 0.0f;
+ for (int c = 0; c < cols; c++) {
+ row[c] = expf(row[c] - max_val);
+ sum += row[c];
+ }
+ float inv_sum = 1.0f / sum;
+ for (int c = 0; c < cols; c++) {
+ row[c] *= inv_sum;
+ }
+ }
+}
diff --git a/libffwd/alloc.c b/libffwd/alloc.c
new file mode 100644
index 0000000..828258e
--- /dev/null
+++ b/libffwd/alloc.c
@@ -0,0 +1,91 @@
+#include "alloc.h"
+
+#include <stdlib.h>
+#include <stdint.h>
+#include <limits.h>
+
+/* Sequence-capacity growth policy for the forward-pass workspaces:
+ * For new growth:
+ * - never allocate less than the minimum required size.
+ * - round up to the granularity so small length changes do not trigger a realloc on every call.
+ * - keep existing capacity if it is already larger. */
+#define FFWD_MIN_WORKSPACE_SEQ_CAP 16
+#define FFWD_WORKSPACE_SEQ_GRANULARITY 16
+
+int mul_size(size_t a, size_t b, size_t *out) {
+ if (a != 0 && b > SIZE_MAX / a)
+ return -1;
+ *out = a * b;
+ return 0;
+}
+
+int add_size(size_t a, size_t b, size_t *out) {
+ if (b > SIZE_MAX - a)
+ return -1;
+ *out = a + b;
+ return 0;
+}
+
+int grow_cap(int current, int needed, int *out) {
+ if (current < 0 || needed <= 0)
+ return -1;
+
+ int cap = needed;
+ if (cap < FFWD_MIN_WORKSPACE_SEQ_CAP)
+ cap = FFWD_MIN_WORKSPACE_SEQ_CAP;
+
+ int rem = cap % FFWD_WORKSPACE_SEQ_GRANULARITY;
+ if (rem != 0) {
+ int pad = FFWD_WORKSPACE_SEQ_GRANULARITY - rem;
+ if (cap > INT_MAX - pad)
+ return -1;
+ cap += pad;
+ }
+
+ if (cap < current)
+ cap = current;
+
+ *out = cap;
+ return 0;
+}
+
+int realloc_floats(float **ptr, size_t count) {
+ size_t bytes;
+ if (mul_size(count, sizeof(float), &bytes) != 0)
+ return -1;
+
+ void *p = realloc(*ptr, bytes);
+ if (!p && bytes != 0)
+ return -1;
+ *ptr = (float *)p;
+ return 0;
+}
+
+float *malloc_floats(size_t count) {
+ size_t bytes;
+ if (mul_size(count, sizeof(float), &bytes) != 0)
+ return NULL;
+ return (float *)malloc(bytes);
+}
+
+int realloc_floats_2d(float **ptr, int rows, int cols) {
+ if (rows < 0 || cols < 0)
+ return -1;
+
+ size_t count;
+ if (mul_size((size_t)rows, (size_t)cols, &count) != 0)
+ return -1;
+ return realloc_floats(ptr, count);
+}
+
+int realloc_ints(int **ptr, size_t count) {
+ size_t bytes;
+ if (mul_size(count, sizeof(int), &bytes) != 0)
+ return -1;
+
+ void *p = realloc(*ptr, bytes);
+ if (!p && bytes != 0)
+ return -1;
+ *ptr = (int *)p;
+ return 0;
+}
diff --git a/libffwd/alloc.h b/libffwd/alloc.h
new file mode 100644
index 0000000..a12ee7a
--- /dev/null
+++ b/libffwd/alloc.h
@@ -0,0 +1,31 @@
+#ifndef FFWD_ALLOC_H
+#define FFWD_ALLOC_H
+
+#include <stddef.h>
+
+/* Checked size arithmetic and typed allocation helpers.
+ * Return -1 or NULL on overflow/allocation failure.
+ * realloc_* leave the original pointer unchanged on failure. */
+
+/* out = a * b, or -1 if the product overflows size_t. */
+int mul_size(size_t a, size_t b, size_t *out);
+
+/* out = a + b, or -1 if the sum overflows size_t. */
+int add_size(size_t a, size_t b, size_t *out);
+
+/* Grow sequence capacity without shrinking. */
+int grow_cap(int current, int needed, int *out);
+
+/* realloc *ptr to hold count floats; *ptr unchanged on failure. */
+int realloc_floats(float **ptr, size_t count);
+
+/* malloc count floats, NULL on overflow/failure. */
+float *malloc_floats(size_t count);
+
+/* realloc *ptr to hold rows*cols floats; -1 on negative dims/overflow/failure. */
+int realloc_floats_2d(float **ptr, int rows, int cols);
+
+/* realloc *ptr to hold count ints; *ptr unchanged on failure. */
+int realloc_ints(int **ptr, size_t count);
+
+#endif /* FFWD_ALLOC_H */
diff --git a/libffwd/attn.c b/libffwd/attn.c
new file mode 100644
index 0000000..57c665a
--- /dev/null
+++ b/libffwd/attn.c
@@ -0,0 +1,458 @@
+#include "kernels.h"
+#include "impl.h"
+#include "threadpool.h"
+
+#include <math.h>
+#include <stdlib.h>
+#include <string.h>
+
+#ifdef USE_BLAS
+# ifdef __APPLE__
+# include <Accelerate/Accelerate.h>
+# else
+# include <cblas.h>
+# endif
+#endif
+
+#ifndef M_PI
+# define M_PI 3.14159265358979323846
+#endif
+
+/* Packed block-diagonal attention: causal (Qwen) and bidirectional (BERT/GTE)
+ * GQA, each with an online-softmax and a BLAS-GEMM path. */
+
+/* Attention operations */
+
+float dot_f32(const float *a, const float *b, int n) { return dot_f32_impl(a, b, n); }
+
+static inline float dot_f32_fast(const float *a, const float *b, int n) {
+ return dot_f32_impl(a, b, n);
+}
+
+/* dst = dst * scale */
+static inline void vec_scale_inplace(float *dst, float scale, int n) {
+ vec_scale_inplace_impl(dst, scale, n);
+}
+
+/* dst += alpha * src */
+static inline void vec_axpy_inplace(float *dst, const float *src, float alpha, int n) {
+ vec_axpy_inplace_impl(dst, src, alpha, n);
+}
+
+/* dst = dst * correction + src */
+static inline void vec_scale_add(float *dst, const float *src, float correction, int n) {
+ vec_scale_add_impl(dst, src, correction, n);
+}
+
+#define PACKED_ATTN_QUERY_TILE 32
+#define PACKED_ATTN_BLAS_MIN_SEQ 128
+
+static void bidirectional_gqa_attention_packed_online_rows(float *out,
+ const float *Q,
+ const float *K,
+ const float *V,
+ int start,
+ int end,
+ int n_heads,
+ int n_kv_heads,
+ int head_dim,
+ float scale,
+ int h,
+ int query_start,
+ int query_end) {
+ int heads_per_kv = n_heads / n_kv_heads;
+ int q_hidden = n_heads * head_dim;
+ int kv_hidden = n_kv_heads * head_dim;
+ int kv_h = h / heads_per_kv;
+
+ for (int i = query_start; i < query_end; i++) {
+ const float *q_row = Q + (size_t)i * q_hidden + h * head_dim;
+ float *o_row = out + (size_t)i * q_hidden + h * head_dim;
+
+ float max_score = -1e30f;
+ float sum_exp = 0.0f;
+ for (int d = 0; d < head_dim; d++)
+ o_row[d] = 0.0f;
+
+ for (int j = start; j < end; j++) {
+ const float *k_row = K + (size_t)j * kv_hidden + kv_h * head_dim;
+ const float *v_row = V + (size_t)j * kv_hidden + kv_h * head_dim;
+
+ float score = dot_f32_fast(q_row, k_row, head_dim) * scale;
+
+ if (score > max_score) {
+ float correction = expf(max_score - score);
+ sum_exp = sum_exp * correction + 1.0f;
+ vec_scale_add(o_row, v_row, correction, head_dim);
+ max_score = score;
+ } else {
+ float wt = expf(score - max_score);
+ sum_exp += wt;
+ vec_axpy_inplace(o_row, v_row, wt, head_dim);
+ }
+ }
+
+ if (sum_exp > 0.0f) {
+ float inv_sum = 1.0f / sum_exp;
+ vec_scale_inplace(o_row, inv_sum, head_dim);
+ }
+ }
+}
+
+#ifdef USE_BLAS
+static void bidirectional_gqa_attention_packed_blas_rows(float *out,
+ const float *Q,
+ const float *K,
+ const float *V,
+ int start,
+ int end,
+ int n_heads,
+ int n_kv_heads,
+ int head_dim,
+ float scale,
+ int h,
+ int query_start,
+ int query_end,
+ float *scores) {
+ int heads_per_kv = n_heads / n_kv_heads;
+ int q_hidden = n_heads * head_dim;
+ int kv_hidden = n_kv_heads * head_dim;
+ int kv_h = h / heads_per_kv;
+ int rows = query_end - query_start;
+ int keys = end - start;
+
+ const float *q = Q + (size_t)query_start * q_hidden + h * head_dim;
+ const float *k = K + (size_t)start * kv_hidden + kv_h * head_dim;
+ const float *v = V + (size_t)start * kv_hidden + kv_h * head_dim;
+ float *o = out + (size_t)query_start * q_hidden + h * head_dim;
+
+ cblas_sgemm(CblasRowMajor, CblasNoTrans, CblasTrans, rows, keys, head_dim, scale, q, q_hidden, k,
+ kv_hidden, 0.0f, scores, keys);
+ softmax(scores, rows, keys);
+ cblas_sgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, rows, head_dim, keys, 1.0f, scores, keys,
+ v, kv_hidden, 0.0f, o, q_hidden);
+}
+#endif
+
+typedef struct {
+ float *out;
+ const float *Q;
+ const float *K;
+ const float *V;
+ const int *offsets;
+ int batch;
+ int n_heads, n_kv_heads;
+ int head_dim;
+ float scale;
+ float *scores;
+ int max_seq;
+} packed_gqa_attn_task_t;
+
+static void packed_gqa_attn_worker(int tid, int n_threads, void *arg) {
+ packed_gqa_attn_task_t *t = (packed_gqa_attn_task_t *)arg;
+ int task_id = 0;
+#ifdef USE_BLAS
+ float *scores = t->scores ? t->scores + (size_t)tid * PACKED_ATTN_QUERY_TILE * t->max_seq : NULL;
+#endif
+
+ for (int h = 0; h < t->n_heads; h++) {
+ for (int b = 0; b < t->batch; b++) {
+ int start = t->offsets[b];
+ int end = t->offsets[b + 1];
+ for (int q0 = start; q0 < end; q0 += PACKED_ATTN_QUERY_TILE) {
+ int q1 = q0 + PACKED_ATTN_QUERY_TILE;
+ if (q1 > end)
+ q1 = end;
+ if (task_id++ % n_threads != tid)
+ continue;
+#ifdef USE_BLAS
+ if (scores && end - start >= PACKED_ATTN_BLAS_MIN_SEQ) {
+ bidirectional_gqa_attention_packed_blas_rows(
+ t->out, t->Q, t->K, t->V, start, end, t->n_heads, t->n_kv_heads, t->head_dim,
+ t->scale, h, q0, q1, scores);
+ continue;
+ }
+#endif
+ bidirectional_gqa_attention_packed_online_rows(t->out, t->Q, t->K, t->V, start, end,
+ t->n_heads, t->n_kv_heads, t->head_dim,
+ t->scale, h, q0, q1);
+ }
+ }
+ }
+}
+
+size_t bidirectional_gqa_attention_packed_scratch_bytes(const int *offsets, int batch) {
+#ifdef USE_BLAS
+ if (!offsets || batch <= 0)
+ return 0;
+
+ int max_seq = 0;
+ for (int b = 0; b < batch; b++) {
+ int len = offsets[b + 1] - offsets[b];
+ if (len > max_seq)
+ max_seq = len;
+ }
+ if (max_seq < PACKED_ATTN_BLAS_MIN_SEQ)
+ return 0;
+ if ((size_t)max_seq >
+ SIZE_MAX / (sizeof(float) * PACKED_ATTN_QUERY_TILE * (size_t)tp_num_threads()))
+ return 0;
+ return (size_t)tp_num_threads() * PACKED_ATTN_QUERY_TILE * (size_t)max_seq * sizeof(float);
+#else
+ (void)offsets;
+ (void)batch;
+ return 0;
+#endif
+}
+
+void bidirectional_gqa_attention_packed_with_scratch(float *out,
+ const float *Q,
+ const float *K,
+ const float *V,
+ const int *offsets,
+ int batch,
+ int n_heads,
+ int n_kv_heads,
+ int head_dim,
+ float scale,
+ float *scratch,
+ size_t scratch_bytes) {
+ long long qk_work = 0;
+ int max_seq = 0;
+ for (int b = 0; b < batch; b++) {
+ int len = offsets[b + 1] - offsets[b];
+ qk_work += (long long)len * len * n_heads;
+ if (len > max_seq)
+ max_seq = len;
+ }
+
+ float *scores = NULL;
+#ifdef USE_BLAS
+ size_t required = bidirectional_gqa_attention_packed_scratch_bytes(offsets, batch);
+ if (required != 0 && scratch && scratch_bytes >= required)
+ scores = scratch;
+#else
+ (void)scratch;
+ (void)scratch_bytes;
+#endif
+ packed_gqa_attn_task_t task = {.out = out,
+ .Q = Q,
+ .K = K,
+ .V = V,
+ .offsets = offsets,
+ .batch = batch,
+ .n_heads = n_heads,
+ .n_kv_heads = n_kv_heads,
+ .head_dim = head_dim,
+ .scale = scale,
+ .scores = scores,
+ .max_seq = max_seq};
+ if (tp_num_threads() > 1 && n_heads >= 2 && qk_work >= 4096) {
+ parallel_for(packed_gqa_attn_worker, &task);
+ } else {
+ packed_gqa_attn_worker(0, 1, &task);
+ }
+}
+
+void bidirectional_gqa_attention_packed(float *out,
+ const float *Q,
+ const float *K,
+ const float *V,
+ const int *offsets,
+ int batch,
+ int n_heads,
+ int n_kv_heads,
+ int head_dim,
+ float scale) {
+ size_t scratch_bytes = bidirectional_gqa_attention_packed_scratch_bytes(offsets, batch);
+ float *scores = scratch_bytes ? malloc(scratch_bytes) : NULL;
+ bidirectional_gqa_attention_packed_with_scratch(out, Q, K, V, offsets, batch, n_heads, n_kv_heads,
+ head_dim, scale, scores, scratch_bytes);
+ free(scores);
+}
+
+static void causal_gqa_attention_packed_online_rows(float *out,
+ const float *Q,
+ const float *K,
+ const float *V,
+ int start,
+ int n_heads,
+ int n_kv_heads,
+ int head_dim,
+ float scale,
+ int h,
+ int query_start,
+ int query_end) {
+ int heads_per_kv = n_heads / n_kv_heads;
+ int q_hidden = n_heads * head_dim;
+ int kv_hidden = n_kv_heads * head_dim;
+ int kv_h = h / heads_per_kv;
+
+ for (int i = query_start; i < query_end; i++) {
+ const float *q_row = Q + (size_t)i * q_hidden + h * head_dim;
+ float *o_row = out + (size_t)i * q_hidden + h * head_dim;
+
+ float max_score = -1e30f;
+ float sum_exp = 0.0f;
+ for (int d = 0; d < head_dim; d++)
+ o_row[d] = 0.0f;
+
+ for (int j = start; j <= i; j++) {
+ const float *k_row = K + (size_t)j * kv_hidden + kv_h * head_dim;
+ const float *v_row = V + (size_t)j * kv_hidden + kv_h * head_dim;
+ float score = dot_f32_fast(q_row, k_row, head_dim) * scale;
+
+ if (score > max_score) {
+ float correction = expf(max_score - score);
+ sum_exp = sum_exp * correction + 1.0f;
+ vec_scale_add(o_row, v_row, correction, head_dim);
+ max_score = score;
+ } else {
+ float wt = expf(score - max_score);
+ sum_exp += wt;
+ vec_axpy_inplace(o_row, v_row, wt, head_dim);
+ }
+ }
+
+ if (sum_exp > 0.0f)
+ vec_scale_inplace(o_row, 1.0f / sum_exp, head_dim);
+ }
+}
+
+#ifdef USE_BLAS
+static void causal_gqa_attention_packed_blas_rows(float *out,
+ const float *Q,
+ const float *K,
+ const float *V,
+ int start,
+ int n_heads,
+ int n_kv_heads,
+ int head_dim,
+ float scale,
+ int h,
+ int query_start,
+ int query_end,
+ float *scores) {
+ int heads_per_kv = n_heads / n_kv_heads;
+ int q_hidden = n_heads * head_dim;
+ int kv_hidden = n_kv_heads * head_dim;
+ int kv_h = h / heads_per_kv;
+ int rows = query_end - query_start;
+ int keys = query_end - start;
+
+ const float *q = Q + (size_t)query_start * q_hidden + h * head_dim;
+ const float *k = K + (size_t)start * kv_hidden + kv_h * head_dim;
+ const float *v = V + (size_t)start * kv_hidden + kv_h * head_dim;
+ float *o = out + (size_t)query_start * q_hidden + h * head_dim;
+
+ cblas_sgemm(CblasRowMajor, CblasNoTrans, CblasTrans, rows, keys, head_dim, scale, q, q_hidden, k,
+ kv_hidden, 0.0f, scores, keys);
+ for (int r = 0; r < rows; r++) {
+ int allowed = query_start + r - start + 1;
+ float *row = scores + (size_t)r * keys;
+ for (int j = allowed; j < keys; j++)
+ row[j] = -INFINITY;
+ }
+ softmax(scores, rows, keys);
+ cblas_sgemm(CblasRowMajor, CblasNoTrans, CblasNoTrans, rows, head_dim, keys, 1.0f, scores, keys,
+ v, kv_hidden, 0.0f, o, q_hidden);
+}
+#endif
+
+static void packed_causal_gqa_attn_worker(int tid, int n_threads, void *arg) {
+ packed_gqa_attn_task_t *t = (packed_gqa_attn_task_t *)arg;
+ int task_id = 0;
+#ifdef USE_BLAS
+ float *scores = t->scores ? t->scores + (size_t)tid * PACKED_ATTN_QUERY_TILE * t->max_seq : NULL;
+#endif
+
+ for (int h = 0; h < t->n_heads; h++) {
+ for (int b = 0; b < t->batch; b++) {
+ int start = t->offsets[b];
+ int end = t->offsets[b + 1];
+ for (int q0 = start; q0 < end; q0 += PACKED_ATTN_QUERY_TILE) {
+ int q1 = q0 + PACKED_ATTN_QUERY_TILE;
+ if (q1 > end)
+ q1 = end;
+ if (task_id++ % n_threads != tid)
+ continue;
+#ifdef USE_BLAS
+ if (scores && end - start >= PACKED_ATTN_BLAS_MIN_SEQ) {
+ causal_gqa_attention_packed_blas_rows(t->out, t->Q, t->K, t->V, start, t->n_heads,
+ t->n_kv_heads, t->head_dim, t->scale, h, q0,
+ q1, scores);
+ continue;
+ }
+#endif
+ causal_gqa_attention_packed_online_rows(t->out, t->Q, t->K, t->V, start, t->n_heads,
+ t->n_kv_heads, t->head_dim, t->scale, h, q0,
+ q1);
+ }
+ }
+ }
+}
+
+void causal_gqa_attention_packed_with_scratch(float *out,
+ const float *Q,
+ const float *K,
+ const float *V,
+ const int *offsets,
+ int batch,
+ int n_heads,
+ int n_kv_heads,
+ int head_dim,
+ float scale,
+ float *scratch,
+ size_t scratch_bytes) {
+ long long qk_work = 0;
+ int max_seq = 0;
+ for (int b = 0; b < batch; b++) {
+ int len = offsets[b + 1] - offsets[b];
+ qk_work += (long long)len * (len + 1) / 2 * n_heads;
+ if (len > max_seq)
+ max_seq = len;
+ }
+
+ float *scores = NULL;
+#ifdef USE_BLAS
+ size_t required = bidirectional_gqa_attention_packed_scratch_bytes(offsets, batch);
+ if (required != 0 && scratch && scratch_bytes >= required)
+ scores = scratch;
+#else
+ (void)scratch;
+ (void)scratch_bytes;
+#endif
+ packed_gqa_attn_task_t task = {.out = out,
+ .Q = Q,
+ .K = K,
+ .V = V,
+ .offsets = offsets,
+ .batch = batch,
+ .n_heads = n_heads,
+ .n_kv_heads = n_kv_heads,
+ .head_dim = head_dim,
+ .scale = scale,
+ .scores = scores,
+ .max_seq = max_seq};
+ if (tp_num_threads() > 1 && n_heads >= 2 && qk_work >= 4096)
+ parallel_for(packed_causal_gqa_attn_worker, &task);
+ else
+ packed_causal_gqa_attn_worker(0, 1, &task);
+}
+
+void causal_gqa_attention_packed(float *out,
+ const float *Q,
+ const float *K,
+ const float *V,
+ const int *offsets,
+ int batch,
+ int n_heads,
+ int n_kv_heads,
+ int head_dim,
+ float scale) {
+ size_t scratch_bytes = bidirectional_gqa_attention_packed_scratch_bytes(offsets, batch);
+ float *scores = scratch_bytes ? malloc(scratch_bytes) : NULL;
+ causal_gqa_attention_packed_with_scratch(out, Q, K, V, offsets, batch, n_heads, n_kv_heads,
+ head_dim, scale, scores, scratch_bytes);
+ free(scores);
+}
diff --git a/libffwd/avx.c b/libffwd/avx.c
new file mode 100644
index 0000000..7cbbd5a
--- /dev/null
+++ b/libffwd/avx.c
@@ -0,0 +1,271 @@
+/* x86 SIMD hot kernels: AVX2+FMA, plus AVX-512 when available.
+ *
+ * BF16 -> F32 conversion:
+ * load 16 uint16 values, zero-extend to 32-bit, then shift left 16.
+ *
+ * Uses AVX-512F+BW for 16-wide BF16 matvec, dominant when seq_len == 1.
+ * Uses AVX2+FMA / AVX-512F for F32 attention helpers, which operate on
+ * cache-resident data.
+ *
+ * BF16 matvec processes 4 output rows at once to reduce instruction overhead
+ * and improve out-of-order execution on memory-bound workloads.
+ */
+
+#include "impl.h"
+
+#if defined(__AVX2__) && defined(__FMA__)
+
+# include <immintrin.h>
+# include <string.h>
+
+/* BF16 matvec: uses AVX-512F+BW when available, AVX2 fallback otherwise */
+
+# if defined(__AVX512F__) && defined(__AVX512BW__)
+
+void bf16_matvec_fused_avx(
+ float *y, const float *x, const uint16_t *W_bf16, const float *bias, int in_dim, int out_dim) {
+ int o = 0;
+
+ /* Process 4 output rows at a time */
+ for (; o + 3 < out_dim; o += 4) {
+ const uint16_t *w0 = W_bf16 + (size_t)o * in_dim;
+ const uint16_t *w1 = w0 + in_dim;
+ const uint16_t *w2 = w1 + in_dim;
+ const uint16_t *w3 = w2 + in_dim;
+
+ __m512 a0 = _mm512_setzero_ps(), a1 = _mm512_setzero_ps();
+ __m512 a2 = _mm512_setzero_ps(), a3 = _mm512_setzero_ps();
+ __m512 a4 = _mm512_setzero_ps(), a5 = _mm512_setzero_ps();
+ __m512 a6 = _mm512_setzero_ps(), a7 = _mm512_setzero_ps();
+ int k = 0;
+
+ for (; k + 32 <= in_dim; k += 32) {
+ __m512 xv0 = _mm512_loadu_ps(x + k);
+ __m512 xv1 = _mm512_loadu_ps(x + k + 16);
+
+ /* Row 0 */
+ __m256i r0a = _mm256_loadu_si256((const __m256i *)(w0 + k));
+ __m256i r0b = _mm256_loadu_si256((const __m256i *)(w0 + k + 16));
+ a0 = _mm512_fmadd_ps(
+ _mm512_castsi512_ps(_mm512_slli_epi32(_mm512_cvtepu16_epi32(r0a), 16)), xv0, a0);
+ a1 = _mm512_fmadd_ps(
+ _mm512_castsi512_ps(_mm512_slli_epi32(_mm512_cvtepu16_epi32(r0b), 16)), xv1, a1);
+
+ /* Row 1 */
+ __m256i r1a = _mm256_loadu_si256((const __m256i *)(w1 + k));
+ __m256i r1b = _mm256_loadu_si256((const __m256i *)(w1 + k + 16));
+ a2 = _mm512_fmadd_ps(
+ _mm512_castsi512_ps(_mm512_slli_epi32(_mm512_cvtepu16_epi32(r1a), 16)), xv0, a2);
+ a3 = _mm512_fmadd_ps(
+ _mm512_castsi512_ps(_mm512_slli_epi32(_mm512_cvtepu16_epi32(r1b), 16)), xv1, a3);
+
+ /* Row 2 */
+ __m256i r2a = _mm256_loadu_si256((const __m256i *)(w2 + k));
+ __m256i r2b = _mm256_loadu_si256((const __m256i *)(w2 + k + 16));
+ a4 = _mm512_fmadd_ps(
+ _mm512_castsi512_ps(_mm512_slli_epi32(_mm512_cvtepu16_epi32(r2a), 16)), xv0, a4);
+ a5 = _mm512_fmadd_ps(
+ _mm512_castsi512_ps(_mm512_slli_epi32(_mm512_cvtepu16_epi32(r2b), 16)), xv1, a5);
+
+ /* Row 3 */
+ __m256i r3a = _mm256_loadu_si256((const __m256i *)(w3 + k));
+ __m256i r3b = _mm256_loadu_si256((const __m256i *)(w3 + k + 16));
+ a6 = _mm512_fmadd_ps(
+ _mm512_castsi512_ps(_mm512_slli_epi32(_mm512_cvtepu16_epi32(r3a), 16)), xv0, a6);
+ a7 = _mm512_fmadd_ps(
+ _mm512_castsi512_ps(_mm512_slli_epi32(_mm512_cvtepu16_epi32(r3b), 16)), xv1, a7);
+ }
+
+ for (; k + 16 <= in_dim; k += 16) {
+ __m512 xv = _mm512_loadu_ps(x + k);
+ __m256i r0 = _mm256_loadu_si256((const __m256i *)(w0 + k));
+ __m256i r1 = _mm256_loadu_si256((const __m256i *)(w1 + k));
+ __m256i r2 = _mm256_loadu_si256((const __m256i *)(w2 + k));
+ __m256i r3 = _mm256_loadu_si256((const __m256i *)(w3 + k));
+ a0 = _mm512_fmadd_ps(
+ _mm512_castsi512_ps(_mm512_slli_epi32(_mm512_cvtepu16_epi32(r0), 16)), xv, a0);
+ a2 = _mm512_fmadd_ps(
+ _mm512_castsi512_ps(_mm512_slli_epi32(_mm512_cvtepu16_epi32(r1), 16)), xv, a2);
+ a4 = _mm512_fmadd_ps(
+ _mm512_castsi512_ps(_mm512_slli_epi32(_mm512_cvtepu16_epi32(r2), 16)), xv, a4);
+ a6 = _mm512_fmadd_ps(
+ _mm512_castsi512_ps(_mm512_slli_epi32(_mm512_cvtepu16_epi32(r3), 16)), xv, a6);
+ }
+
+ float s0 = _mm512_reduce_add_ps(_mm512_add_ps(a0, a1)) + (bias ? bias[o] : 0.0f);
+ float s1 = _mm512_reduce_add_ps(_mm512_add_ps(a2, a3)) + (bias ? bias[o + 1] : 0.0f);
+ float s2 = _mm512_reduce_add_ps(_mm512_add_ps(a4, a5)) + (bias ? bias[o + 2] : 0.0f);
+ float s3 = _mm512_reduce_add_ps(_mm512_add_ps(a6, a7)) + (bias ? bias[o + 3] : 0.0f);
+
+ for (; k < in_dim; k++) {
+ float xk = x[k];
+ uint32_t b0 = ((uint32_t)w0[k]) << 16, b1 = ((uint32_t)w1[k]) << 16;
+ uint32_t b2 = ((uint32_t)w2[k]) << 16, b3 = ((uint32_t)w3[k]) << 16;
+ float v0, v1, v2, v3;
+ memcpy(&v0, &b0, 4);
+ memcpy(&v1, &b1, 4);
+ memcpy(&v2, &b2, 4);
+ memcpy(&v3, &b3, 4);
+ s0 += v0 * xk;
+ s1 += v1 * xk;
+ s2 += v2 * xk;
+ s3 += v3 * xk;
+ }
+ y[o] = s0;
+ y[o + 1] = s1;
+ y[o + 2] = s2;
+ y[o + 3] = s3;
+ }
+
+ /* Handle 2-row remainder */
+ for (; o + 1 < out_dim; o += 2) {
+ const uint16_t *w0 = W_bf16 + (size_t)o * in_dim;
+ const uint16_t *w1 = w0 + in_dim;
+ __m512 a0 = _mm512_setzero_ps(), a1 = _mm512_setzero_ps();
+ __m512 a2 = _mm512_setzero_ps(), a3 = _mm512_setzero_ps();
+ int k = 0;
+
+ for (; k + 32 <= in_dim; k += 32) {
+ __m512 xv0 = _mm512_loadu_ps(x + k);
+ __m512 xv1 = _mm512_loadu_ps(x + k + 16);
+ __m256i r0a = _mm256_loadu_si256((const __m256i *)(w0 + k));
+ __m256i r0b = _mm256_loadu_si256((const __m256i *)(w0 + k + 16));
+ __m256i r1a = _mm256_loadu_si256((const __m256i *)(w1 + k));
+ __m256i r1b = _mm256_loadu_si256((const __m256i *)(w1 + k + 16));
+ a0 = _mm512_fmadd_ps(
+ _mm512_castsi512_ps(_mm512_slli_epi32(_mm512_cvtepu16_epi32(r0a), 16)), xv0, a0);
+ a1 = _mm512_fmadd_ps(
+ _mm512_castsi512_ps(_mm512_slli_epi32(_mm512_cvtepu16_epi32(r0b), 16)), xv1, a1);
+ a2 = _mm512_fmadd_ps(
+ _mm512_castsi512_ps(_mm512_slli_epi32(_mm512_cvtepu16_epi32(r1a), 16)), xv0, a2);
+ a3 = _mm512_fmadd_ps(
+ _mm512_castsi512_ps(_mm512_slli_epi32(_mm512_cvtepu16_epi32(r1b), 16)), xv1, a3);
+ }
+ for (; k + 16 <= in_dim; k += 16) {
+ __m512 xv = _mm512_loadu_ps(x + k);
+ __m256i r0 = _mm256_loadu_si256((const __m256i *)(w0 + k));
+ __m256i r1 = _mm256_loadu_si256((const __m256i *)(w1 + k));
+ a0 = _mm512_fmadd_ps(
+ _mm512_castsi512_ps(_mm512_slli_epi32(_mm512_cvtepu16_epi32(r0), 16)), xv, a0);
+ a2 = _mm512_fmadd_ps(
+ _mm512_castsi512_ps(_mm512_slli_epi32(_mm512_cvtepu16_epi32(r1), 16)), xv, a2);
+ }
+
+ float s0 = _mm512_reduce_add_ps(_mm512_add_ps(a0, a1)) + (bias ? bias[o] : 0.0f);
+ float s1 = _mm512_reduce_add_ps(_mm512_add_ps(a2, a3)) + (bias ? bias[o + 1] : 0.0f);
+
+ for (; k < in_dim; k++) {
+ uint32_t b0 = ((uint32_t)w0[k]) << 16, b1 = ((uint32_t)w1[k]) << 16;
+ float v0, v1;
+ memcpy(&v0, &b0, 4);
+ memcpy(&v1, &b1, 4);
+ s0 += v0 * x[k];
+ s1 += v1 * x[k];
+ }
+ y[o] = s0;
+ y[o + 1] = s1;
+ }
+
+ /* Single remaining row */
+ for (; o < out_dim; o++) {
+ const uint16_t *w = W_bf16 + (size_t)o * in_dim;
+ __m512 acc = _mm512_setzero_ps();
+ int k = 0;
+ for (; k + 16 <= in_dim; k += 16) {
+ __m256i raw = _mm256_loadu_si256((const __m256i *)(w + k));
+ acc = _mm512_fmadd_ps(
+ _mm512_castsi512_ps(_mm512_slli_epi32(_mm512_cvtepu16_epi32(raw), 16)),
+ _mm512_loadu_ps(x + k), acc);
+ }
+ float sum = _mm512_reduce_add_ps(acc) + (bias ? bias[o] : 0.0f);
+ for (; k < in_dim; k++) {
+ uint32_t bits = ((uint32_t)w[k]) << 16;
+ float wv;
+ memcpy(&wv, &bits, 4);
+ sum += wv * x[k];
+ }
+ y[o] = sum;
+ }
+}
+
+# else /* AVX2 only (or AVX-512F without BW) */
+
+/* Helper: bf16 to f32 for 8 elements */
+static inline __m256 bf16x8_to_f32(__m128i raw) {
+ return _mm256_castsi256_ps(_mm256_slli_epi32(_mm256_cvtepu16_epi32(raw), 16));
+}
+
+static inline void bf16x16_to_f32(const uint16_t *src, __m256 *lo, __m256 *hi) {
+ __m256i raw = _mm256_loadu_si256((const __m256i *)src);
+ *lo = bf16x8_to_f32(_mm256_castsi256_si128(raw));
+ *hi = bf16x8_to_f32(_mm256_extracti128_si256(raw, 1));
+}
+
+void bf16_matvec_fused_avx(
+ float *y, const float *x, const uint16_t *W_bf16, const float *bias, int in_dim, int out_dim) {
+ int o = 0;
+
+ for (; o + 1 < out_dim; o += 2) {
+ const uint16_t *w0 = W_bf16 + (size_t)o * in_dim;
+ const uint16_t *w1 = w0 + in_dim;
+ __m256 a0 = _mm256_setzero_ps(), a1 = _mm256_setzero_ps();
+ __m256 a2 = _mm256_setzero_ps(), a3 = _mm256_setzero_ps();
+ int k = 0;
+ for (; k + 16 <= in_dim; k += 16) {
+ __m256 xlo = _mm256_loadu_ps(x + k);
+ __m256 xhi = _mm256_loadu_ps(x + k + 8);
+ __m256 wlo, whi;
+ bf16x16_to_f32(w0 + k, &wlo, &whi);
+ a0 = _mm256_fmadd_ps(wlo, xlo, a0);
+ a1 = _mm256_fmadd_ps(whi, xhi, a1);
+ bf16x16_to_f32(w1 + k, &wlo, &whi);
+ a2 = _mm256_fmadd_ps(wlo, xlo, a2);
+ a3 = _mm256_fmadd_ps(whi, xhi, a3);
+ }
+ a0 = _mm256_add_ps(a0, a1);
+ a2 = _mm256_add_ps(a2, a3);
+ __m128 r0 = _mm_add_ps(_mm256_castps256_ps128(a0), _mm256_extractf128_ps(a0, 1));
+ __m128 r1 = _mm_add_ps(_mm256_castps256_ps128(a2), _mm256_extractf128_ps(a2, 1));
+ r0 = _mm_hadd_ps(r0, r1);
+ r0 = _mm_hadd_ps(r0, r0);
+ float s0 = _mm_cvtss_f32(r0) + (bias ? bias[o] : 0.0f);
+ float s1 = _mm_cvtss_f32(_mm_shuffle_ps(r0, r0, 1)) + (bias ? bias[o + 1] : 0.0f);
+ for (; k < in_dim; k++) {
+ uint32_t b0 = ((uint32_t)w0[k]) << 16, b1 = ((uint32_t)w1[k]) << 16;
+ float v0, v1;
+ memcpy(&v0, &b0, 4);
+ memcpy(&v1, &b1, 4);
+ s0 += v0 * x[k];
+ s1 += v1 * x[k];
+ }
+ y[o] = s0;
+ y[o + 1] = s1;
+ }
+ for (; o < out_dim; o++) {
+ const uint16_t *w = W_bf16 + (size_t)o * in_dim;
+ __m256 a0 = _mm256_setzero_ps(), a1 = _mm256_setzero_ps();
+ int k = 0;
+ for (; k + 16 <= in_dim; k += 16) {
+ __m256 wlo, whi;
+ bf16x16_to_f32(w + k, &wlo, &whi);
+ a0 = _mm256_fmadd_ps(wlo, _mm256_loadu_ps(x + k), a0);
+ a1 = _mm256_fmadd_ps(whi, _mm256_loadu_ps(x + k + 8), a1);
+ }
+ a0 = _mm256_add_ps(a0, a1);
+ __m128 r = _mm_add_ps(_mm256_castps256_ps128(a0), _mm256_extractf128_ps(a0, 1));
+ r = _mm_hadd_ps(r, r);
+ r = _mm_hadd_ps(r, r);
+ float sum = _mm_cvtss_f32(r) + (bias ? bias[o] : 0.0f);
+ for (; k < in_dim; k++) {
+ uint32_t bits = ((uint32_t)w[k]) << 16;
+ float wv;
+ memcpy(&wv, &bits, 4);
+ sum += wv * x[k];
+ }
+ y[o] = sum;
+ }
+}
+
+# endif /* AVX-512F+BW vs AVX2 for bf16 */
+
+#endif /* __AVX2__ && __FMA__ */
diff --git a/libffwd/bpe.c b/libffwd/bpe.c
new file mode 100644
index 0000000..5a4d184
--- /dev/null
+++ b/libffwd/bpe.c
@@ -0,0 +1,1898 @@
+#include "bpe.h"
+
+#include <yyjson.h>
+
+#include <limits.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+/* GPT-2 bytes-to-unicode mapping */
+
+static int gpt2_byte_to_unicode[256];
+static int gpt2_unicode_to_byte[512]; /* codepoints up to ~384 */
+static int gpt2_mapping_initialized = 0;
+
+static void init_gpt2_mapping(void) {
+ if (gpt2_mapping_initialized)
+ return;
+
+ memset(gpt2_unicode_to_byte, -1, sizeof(gpt2_unicode_to_byte));
+
+ int n = 0;
+ for (int b = 0; b < 256; b++) {
+ int is_normal = 0;
+ if (b >= 33 && b <= 126)
+ is_normal = 1; /* '!'..'~' */
+ if (b >= 161 && b <= 172)
+ is_normal = 1; /* '¡'..'¬' */
+ if (b >= 174 && b <= 255)
+ is_normal = 1; /* '®'..'ÿ' */
+
+ if (is_normal)
+ gpt2_byte_to_unicode[b] = b;
+ else
+ gpt2_byte_to_unicode[b] = 256 + n++;
+ }
+
+ for (int b = 0; b < 256; b++) {
+ int cp = gpt2_byte_to_unicode[b];
+ if (cp < 512)
+ gpt2_unicode_to_byte[cp] = b;
+ }
+
+ gpt2_mapping_initialized = 1;
+}
+
+/* Convert one Unicode codepoint to UTF-8 bytes. Returns bytes written. */
+static int utf8_encode_cp(int cp, char out[4]) {
+ if (cp < 0x80) {
+ out[0] = (char)cp;
+ return 1;
+ }
+ if (cp < 0x800) {
+ out[0] = (char)(0xC0 | (cp >> 6));
+ out[1] = (char)(0x80 | (cp & 0x3F));
+ return 2;
+ }
+ out[0] = (char)(0xE0 | (cp >> 12));
+ out[1] = (char)(0x80 | ((cp >> 6) & 0x3F));
+ out[2] = (char)(0x80 | (cp & 0x3F));
+ return 3;
+}
+
+/*
+ * Decode a GPT-2 encoded token string (vocab key) to raw bytes/UTF-8 text.
+ * Returns allocated string (caller must free).
+ */
+static char *decode_gpt2_token(const char *token_str) {
+ init_gpt2_mapping();
+
+ size_t len = strlen(token_str);
+ unsigned char *bytes = (unsigned char *)malloc(len + 1);
+ if (!bytes)
+ return NULL;
+
+ int byte_count = 0;
+ const unsigned char *p = (const unsigned char *)token_str;
+ const unsigned char *end = p + len;
+
+ while (p < end) {
+ int cp = 0;
+ int nbytes = 1;
+
+ if ((*p & 0x80) == 0) {
+ cp = *p;
+ nbytes = 1;
+ } else if ((*p & 0xE0) == 0xC0) {
+ cp = (*p & 0x1F) << 6;
+ if (p + 1 < end)
+ cp |= (p[1] & 0x3F);
+ nbytes = 2;
+ } else if ((*p & 0xF0) == 0xE0) {
+ cp = (*p & 0x0F) << 12;
+ if (p + 1 < end)
+ cp |= (p[1] & 0x3F) << 6;
+ if (p + 2 < end)
+ cp |= (p[2] & 0x3F);
+ nbytes = 3;
+ } else if ((*p & 0xF8) == 0xF0) {
+ cp = (*p & 0x07) << 18;
+ if (p + 1 < end)
+ cp |= (p[1] & 0x3F) << 12;
+ if (p + 2 < end)
+ cp |= (p[2] & 0x3F) << 6;
+ if (p + 3 < end)
+ cp |= (p[3] & 0x3F);
+ nbytes = 4;
+ } else {
+ cp = *p;
+ nbytes = 1;
+ }
+ p += nbytes;
+
+ if (cp < 512 && gpt2_unicode_to_byte[cp] >= 0) {
+ bytes[byte_count++] = (unsigned char)gpt2_unicode_to_byte[cp];
+ } else {
+ bytes[byte_count++] = '?';
+ }
+ }
+ bytes[byte_count] = '\0';
+ return (char *)bytes;
+}
+
+/* String->int hash map (open addressing) */
+
+typedef struct {
+ char *key; /* NULL means empty slot */
+ int value;
+} str_int_entry_t;
+
+static uint64_t fnv1a_hash(const char *s) {
+ uint64_t h = 1469598103934665603ULL;
+ while (*s) {
+ h ^= (unsigned char)*s++;
+ h *= 1099511628211ULL;
+ }
+ return h;
+}
+
+static uint64_t fnv1a_hash_pair(const char *a, const char *b) {
+ uint64_t h = 1469598103934665603ULL;
+ while (*a) {
+ h ^= (unsigned char)*a++;
+ h *= 1099511628211ULL;
+ }
+ h ^= (unsigned char)' ';
+ h *= 1099511628211ULL;
+ while (*b) {
+ h ^= (unsigned char)*b++;
+ h *= 1099511628211ULL;
+ }
+ return h;
+}
+
+static int pair_key_eq(const char *key, const char *a, const char *b) {
+ while (*a) {
+ if (*key++ != *a++)
+ return 0;
+ }
+ if (*key++ != ' ')
+ return 0;
+ while (*b) {
+ if (*key++ != *b++)
+ return 0;
+ }
+ return *key == '\0';
+}
+
+static int next_pow2(int x) {
+ int p = 1;
+ while (p < x)
+ p <<= 1;
+ return p;
+}
+
+static int map_insert(str_int_entry_t *map, int cap, char *key, int value) {
+ if (!map || cap <= 0 || !key)
+ return -1;
+ int mask = cap - 1;
+ int pos = (int)(fnv1a_hash(key) & (uint64_t)mask);
+ for (int i = 0; i < cap; i++) {
+ int idx = (pos + i) & mask;
+ if (!map[idx].key) {
+ map[idx].key = key;
+ map[idx].value = value;
+ return 0;
+ }
+ if (strcmp(map[idx].key, key) == 0) {
+ map[idx].value = value;
+ return 0;
+ }
+ }
+ return -1;
+}
+
+static int map_insert_owned(str_int_entry_t *map, int cap, char **keyp, int value) {
+ if (!keyp)
+ return -1;
+ char *key = *keyp;
+ if (!map || cap <= 0 || !key)
+ return -1;
+ int mask = cap - 1;
+ int pos = (int)(fnv1a_hash(key) & (uint64_t)mask);
+ for (int i = 0; i < cap; i++) {
+ int idx = (pos + i) & mask;
+ if (!map[idx].key) {
+ map[idx].key = key;
+ map[idx].value = value;
+ *keyp = NULL;
+ return 0;
+ }
+ if (strcmp(map[idx].key, key) == 0) {
+ map[idx].value = value;
+ return 0;
+ }
+ }
+ return -1;
+}
+
+static int map_get(const str_int_entry_t *map, int cap, const char *key) {
+ if (!map || cap <= 0 || !key)
+ return -1;
+ int mask = cap - 1;
+ int pos = (int)(fnv1a_hash(key) & (uint64_t)mask);
+ for (int i = 0; i < cap; i++) {
+ int idx = (pos + i) & mask;
+ if (!map[idx].key)
+ return -1;
+ if (strcmp(map[idx].key, key) == 0)
+ return map[idx].value;
+ }
+ return -1;
+}
+
+static int map_get_pair(const str_int_entry_t *map, int cap, const char *a, const char *b) {
+ if (!map || cap <= 0 || !a || !b)
+ return -1;
+ int mask = cap - 1;
+ int pos = (int)(fnv1a_hash_pair(a, b) & (uint64_t)mask);
+ for (int i = 0; i < cap; i++) {
+ int idx = (pos + i) & mask;
+ if (!map[idx].key)
+ return -1;
+ if (pair_key_eq(map[idx].key, a, b))
+ return map[idx].value;
+ }
+ return -1;
+}
+
+/* BPE helpers */
+
+static int utf8_char_len(unsigned char c) {
+ if ((c & 0x80) == 0)
+ return 1;
+ if ((c & 0xE0) == 0xC0)
+ return 2;
+ if ((c & 0xF0) == 0xE0)
+ return 3;
+ if ((c & 0xF8) == 0xF0)
+ return 4;
+ return 1;
+}
+
+static int split_utf8_symbols(const char *s, char ***out_syms, int *out_n) {
+ *out_syms = NULL;
+ *out_n = 0;
+ if (!s || !*s)
+ return 0;
+
+ int n = 0;
+ for (const unsigned char *p = (const unsigned char *)s; *p;) {
+ int l = utf8_char_len(*p);
+ p += l;
+ n++;
+ }
+ if (n <= 0)
+ return 0;
+
+ char **syms = (char **)calloc((size_t)n, sizeof(char *));
+ if (!syms)
+ return -1;
+
+ int i = 0;
+ for (const unsigned char *p = (const unsigned char *)s; *p;) {
+ int l = utf8_char_len(*p);
+ syms[i] = (char *)malloc((size_t)l + 1);
+ if (!syms[i]) {
+ for (int j = 0; j < i; j++)
+ free(syms[j]);
+ free(syms);
+ return -1;
+ }
+ memcpy(syms[i], p, (size_t)l);
+ syms[i][l] = '\0';
+ p += l;
+ i++;
+ }
+
+ *out_syms = syms;
+ *out_n = n;
+ return 0;
+}
+
+static char *str_concat2(const char *a, const char *b) {
+ size_t la = strlen(a), lb = strlen(b);
+ char *r = (char *)malloc(la + lb + 1);
+ if (!r)
+ return NULL;
+ memcpy(r, a, la);
+ memcpy(r + la, b, lb);
+ r[la + lb] = '\0';
+ return r;
+}
+
+/* Integer-pair BPE merges: (left_id, right_id) -> (rank, merged_id) */
+
+typedef struct {
+ uint64_t key; /* (left_id << 32) | right_id; UINT64_MAX = empty */
+ int rank;
+ int merged_id;
+} pair_merge_entry_t;
+
+static uint64_t pair_hash(uint64_t k) {
+ /* splitmix64 finalizer */
+ k ^= k >> 30;
+ k *= 0xbf58476d1ce4e5b9ULL;
+ k ^= k >> 27;
+ k *= 0x94d049bb133111ebULL;
+ k ^= k >> 31;
+ return k;
+}
+
+static void pair_map_insert(pair_merge_entry_t *map, int cap, uint64_t key, int rank, int merged_id) {
+ int mask = cap - 1;
+ int idx = (int)(pair_hash(key) & (uint64_t)mask);
+ for (int probe = 0; probe < cap; probe++, idx = (idx + 1) & mask) {
+ if (map[idx].key == UINT64_MAX) {
+ map[idx].key = key;
+ map[idx].rank = rank;
+ map[idx].merged_id = merged_id;
+ return;
+ }
+ if (map[idx].key == key)
+ return; /* first (lowest) rank wins */
+ }
+}
+
+/* Returns the rank and sets *merged_id, or INT_MAX when the pair never
+ * merges. */
+static int pair_merge_lookup(const tok_bpe_t *tok, int left, int right, int *merged_id) {
+ const pair_merge_entry_t *map = (const pair_merge_entry_t *)tok->int_merges;
+ uint64_t key = ((uint64_t)(uint32_t)left << 32) | (uint32_t)right;
+ int mask = tok->int_merges_cap - 1;
+ int idx = (int)(pair_hash(key) & (uint64_t)mask);
+ for (int probe = 0; probe < tok->int_merges_cap; probe++, idx = (idx + 1) & mask) {
+ if (map[idx].key == UINT64_MAX)
+ return INT_MAX;
+ if (map[idx].key == key) {
+ *merged_id = map[idx].merged_id;
+ return map[idx].rank;
+ }
+ }
+ return INT_MAX;
+}
+
+static int merge_rank(const tok_bpe_t *tok, const char *a, const char *b) {
+ if (!tok->merge_map || tok->merge_map_cap <= 0)
+ return INT_MAX;
+
+ int rank = map_get_pair((const str_int_entry_t *)tok->merge_map, tok->merge_map_cap, a, b);
+ return rank >= 0 ? rank : INT_MAX;
+}
+
+static int append_id(int **arr, int *n, int *cap, int id) {
+ if (*n >= *cap) {
+ int new_cap = (*cap == 0) ? 16 : (*cap * 2);
+ int *tmp = (int *)realloc(*arr, (size_t)new_cap * sizeof(int));
+ if (!tmp)
+ return -1;
+ *arr = tmp;
+ *cap = new_cap;
+ }
+ (*arr)[(*n)++] = id;
+ return 0;
+}
+
+/* Convert UTF-8 bytes to GPT-2 byte-level unicode string. */
+static char *text_to_bpe_unicode(const char *text) {
+ init_gpt2_mapping();
+ size_t len = strlen(text);
+ /* Every input byte becomes one codepoint up to 3 UTF-8 bytes. */
+ char *out = (char *)malloc(len * 3 + 1);
+ if (!out)
+ return NULL;
+
+ size_t w = 0;
+ for (size_t i = 0; i < len; i++) {
+ int cp = gpt2_byte_to_unicode[(unsigned char)text[i]];
+ char tmp[4];
+ int n = utf8_encode_cp(cp, tmp);
+ for (int j = 0; j < n; j++)
+ out[w++] = tmp[j];
+ }
+ out[w] = '\0';
+ return out;
+}
+
+static int encode_bpe_word(const tok_bpe_t *tok, const char *mapped, int **out_ids, int *out_n);
+
+static int
+utf8_decode_cp_len(const unsigned char *p, const unsigned char *end, int *cp_out, int *len_out) {
+ if (p >= end || *p == '\0')
+ return 0;
+
+ unsigned char c = *p;
+ if ((c & 0x80) == 0) {
+ *cp_out = c;
+ *len_out = 1;
+ return 1;
+ }
+ if ((c & 0xE0) == 0xC0 && p + 1 < end && (p[1] & 0xC0) == 0x80) {
+ *cp_out = ((c & 0x1F) << 6) | (p[1] & 0x3F);
+ *len_out = 2;
+ return 1;
+ }
+ if ((c & 0xF0) == 0xE0 && p + 2 < end && (p[1] & 0xC0) == 0x80 && (p[2] & 0xC0) == 0x80) {
+ *cp_out = ((c & 0x0F) << 12) | ((p[1] & 0x3F) << 6) | (p[2] & 0x3F);
+ *len_out = 3;
+ return 1;
+ }
+ if ((c & 0xF8) == 0xF0 && p + 3 < end && (p[1] & 0xC0) == 0x80 && (p[2] & 0xC0) == 0x80 &&
+ (p[3] & 0xC0) == 0x80) {
+ *cp_out = ((c & 0x07) << 18) | ((p[1] & 0x3F) << 12) | ((p[2] & 0x3F) << 6) | (p[3] & 0x3F);
+ *len_out = 4;
+ return 1;
+ }
+
+ *cp_out = c;
+ *len_out = 1;
+ return 1;
+}
+
+/* The pretokenizer classifies every codepoint, several times each, and the
+ * input is overwhelmingly ASCII; one table lookup replaces the range chains
+ * for cp < 0x80. Non-ASCII codepoints fall through to the full checks.
+ * ASCII has no symbolish codepoints, so that class needs no bit. */
+#define CPC_SPACE 1
+#define CPC_NUMBER 2
+#define CPC_LETTER 4
+
+static const unsigned char ascii_cp_class[128] = {
+ ['\t'] = CPC_SPACE, ['\n'] = CPC_SPACE, ['\v'] = CPC_SPACE,
+ ['\f'] = CPC_SPACE, ['\r'] = CPC_SPACE, [' '] = CPC_SPACE,
+ ['0' ... '9'] = CPC_NUMBER, ['A' ... 'Z'] = CPC_LETTER, ['a' ... 'z'] = CPC_LETTER,
+};
+
+static int is_number_cp(int cp) {
+ if ((unsigned)cp < 0x80)
+ return ascii_cp_class[cp] & CPC_NUMBER;
+ if (cp >= 0x0660 && cp <= 0x0669)
+ return 1;
+ if (cp >= 0x06F0 && cp <= 0x06F9)
+ return 1;
+ if (cp >= 0x0966 && cp <= 0x096F)
+ return 1;
+ if (cp >= 0xFF10 && cp <= 0xFF19)
+ return 1;
+ return 0;
+}
+
+static int is_space_cp(int cp) {
+ if ((unsigned)cp < 0x80)
+ return ascii_cp_class[cp] & CPC_SPACE;
+ return cp == 0x85 || cp == 0xA0 || cp == 0x1680 || (cp >= 0x2000 && cp <= 0x200A) ||
+ cp == 0x2028 || cp == 0x2029 || cp == 0x202F || cp == 0x205F || cp == 0x3000;
+}
+
+static int is_symbolish_cp(int cp) {
+ if (cp < 0x80)
+ return 0;
+ if (cp >= 0x0300 && cp <= 0x036F)
+ return 1;
+ if (cp >= 0x00A1 && cp <= 0x00BF && cp != 0x00AA && cp != 0x00B5 && cp != 0x00BA)
+ return 1;
+ if (cp == 0x00D7 || cp == 0x00F7)
+ return 1;
+ if (cp >= 0x064B && cp <= 0x065F)
+ return 1;
+ if ((cp >= 0x0900 && cp <= 0x0903) || (cp >= 0x093A && cp <= 0x094F) ||
+ (cp >= 0x0951 && cp <= 0x0957) || (cp >= 0x0962 && cp <= 0x0963))
+ return 1;
+ if (cp >= 0x2000 && cp <= 0x206F)
+ return 1;
+ if (cp >= 0x2190 && cp <= 0x27BF)
+ return 1;
+ if (cp >= 0x2E00 && cp <= 0x2E7F)
+ return 1;
+ if (cp >= 0x3000 && cp <= 0x303F)
+ return 1;
+ if (cp >= 0x1F000 && cp <= 0x1FAFF)
+ return 1;
+ return 0;
+}
+
+static int compose_latin_mark(int base, int mark) {
+ switch (mark) {
+ case 0x0300:
+ switch (base) {
+ case 'A':
+ return 0x00C0;
+ case 'E':
+ return 0x00C8;
+ case 'I':
+ return 0x00CC;
+ case 'O':
+ return 0x00D2;
+ case 'U':
+ return 0x00D9;
+ case 'a':
+ return 0x00E0;
+ case 'e':
+ return 0x00E8;
+ case 'i':
+ return 0x00EC;
+ case 'o':
+ return 0x00F2;
+ case 'u':
+ return 0x00F9;
+ }
+ break;
+ case 0x0301:
+ switch (base) {
+ case 'A':
+ return 0x00C1;
+ case 'C':
+ return 0x0106;
+ case 'E':
+ return 0x00C9;
+ case 'I':
+ return 0x00CD;
+ case 'L':
+ return 0x0139;
+ case 'N':
+ return 0x0143;
+ case 'O':
+ return 0x00D3;
+ case 'R':
+ return 0x0154;
+ case 'S':
+ return 0x015A;
+ case 'U':
+ return 0x00DA;
+ case 'Y':
+ return 0x00DD;
+ case 'Z':
+ return 0x0179;
+ case 'a':
+ return 0x00E1;
+ case 'c':
+ return 0x0107;
+ case 'e':
+ return 0x00E9;
+ case 'i':
+ return 0x00ED;
+ case 'l':
+ return 0x013A;
+ case 'n':
+ return 0x0144;
+ case 'o':
+ return 0x00F3;
+ case 'r':
+ return 0x0155;
+ case 's':
+ return 0x015B;
+ case 'u':
+ return 0x00FA;
+ case 'y':
+ return 0x00FD;
+ case 'z':
+ return 0x017A;
+ }
+ break;
+ case 0x0302:
+ switch (base) {
+ case 'A':
+ return 0x00C2;
+ case 'E':
+ return 0x00CA;
+ case 'I':
+ return 0x00CE;
+ case 'O':
+ return 0x00D4;
+ case 'U':
+ return 0x00DB;
+ case 'a':
+ return 0x00E2;
+ case 'e':
+ return 0x00EA;
+ case 'i':
+ return 0x00EE;
+ case 'o':
+ return 0x00F4;
+ case 'u':
+ return 0x00FB;
+ }
+ break;
+ case 0x0303:
+ switch (base) {
+ case 'A':
+ return 0x00C3;
+ case 'N':
+ return 0x00D1;
+ case 'O':
+ return 0x00D5;
+ case 'a':
+ return 0x00E3;
+ case 'n':
+ return 0x00F1;
+ case 'o':
+ return 0x00F5;
+ }
+ break;
+ case 0x0308:
+ switch (base) {
+ case 'A':
+ return 0x00C4;
+ case 'E':
+ return 0x00CB;
+ case 'I':
+ return 0x00CF;
+ case 'O':
+ return 0x00D6;
+ case 'U':
+ return 0x00DC;
+ case 'Y':
+ return 0x0178;
+ case 'a':
+ return 0x00E4;
+ case 'e':
+ return 0x00EB;
+ case 'i':
+ return 0x00EF;
+ case 'o':
+ return 0x00F6;
+ case 'u':
+ return 0x00FC;
+ case 'y':
+ return 0x00FF;
+ }
+ break;
+ case 0x030A:
+ switch (base) {
+ case 'A':
+ return 0x00C5;
+ case 'a':
+ return 0x00E5;
+ }
+ break;
+ case 0x0327:
+ switch (base) {
+ case 'C':
+ return 0x00C7;
+ case 'c':
+ return 0x00E7;
+ }
+ break;
+ }
+ return 0;
+}
+
+static char *normalize_nfc_latin(const char *text) {
+ const unsigned char *p = (const unsigned char *)text;
+ const unsigned char *end = p + strlen(text);
+ char *out = (char *)malloc((size_t)(end - p) * 2 + 1);
+ if (!out)
+ return NULL;
+
+ size_t w = 0;
+ while (p < end) {
+ const unsigned char *cur = p;
+ int cp = 0, len = 0;
+ if (!utf8_decode_cp_len(p, end, &cp, &len))
+ break;
+ p += len;
+
+ if (p < end) {
+ int mark = 0, mark_len = 0;
+ utf8_decode_cp_len(p, end, &mark, &mark_len);
+ int composed = compose_latin_mark(cp, mark);
+ if (composed) {
+ char tmp[4];
+ int n = utf8_encode_cp(composed, tmp);
+ for (int i = 0; i < n; i++)
+ out[w++] = tmp[i];
+ p += mark_len;
+ continue;
+ }
+ }
+
+ memcpy(out + w, cur, (size_t)len);
+ w += (size_t)len;
+ }
+
+ out[w] = '\0';
+ return out;
+}
+
+static int is_letter_cp(int cp) {
+ if ((unsigned)cp < 0x80)
+ return ascii_cp_class[cp] & CPC_LETTER;
+ if (is_space_cp(cp) || is_number_cp(cp) || is_symbolish_cp(cp))
+ return 0;
+ return 1;
+}
+
+static int is_word_cp(int cp) { return is_letter_cp(cp) || is_number_cp(cp); }
+
+static int is_newline_cp(int cp) { return cp == '\n' || cp == '\r'; }
+
+static int ascii_lower(int c) { return (c >= 'A' && c <= 'Z') ? c + ('a' - 'A') : c; }
+
+static int match_contraction(const unsigned char *p, const unsigned char *end) {
+ if (p >= end || *p != '\'')
+ return 0;
+ int remain = (int)(end - p);
+ if (remain >= 2) {
+ int c1 = ascii_lower(p[1]);
+ if (c1 == 's' || c1 == 't' || c1 == 'm' || c1 == 'd')
+ return 2;
+ }
+ if (remain >= 3) {
+ int c1 = ascii_lower(p[1]);
+ int c2 = ascii_lower(p[2]);
+ if ((c1 == 'r' && c2 == 'e') || (c1 == 'v' && c2 == 'e') || (c1 == 'l' && c2 == 'l'))
+ return 3;
+ }
+ return 0;
+}
+
+static int append_encoded_piece(
+ const tok_bpe_t *tok, const char *piece, size_t piece_len, int **ids, int *n_ids, int *cap) {
+ if (piece_len == 0)
+ return 0;
+
+ char *tmp = (char *)malloc(piece_len + 1);
+ if (!tmp)
+ return -1;
+ memcpy(tmp, piece, piece_len);
+ tmp[piece_len] = '\0';
+
+ char *mapped = text_to_bpe_unicode(tmp);
+ free(tmp);
+ if (!mapped)
+ return -1;
+
+ int *piece_ids = NULL;
+ int n_piece = 0;
+ if (encode_bpe_word(tok, mapped, &piece_ids, &n_piece) != 0) {
+ free(mapped);
+ free(piece_ids);
+ return -1;
+ }
+ free(mapped);
+
+ for (int i = 0; i < n_piece; i++) {
+ if (append_id(ids, n_ids, cap, piece_ids[i]) != 0) {
+ free(piece_ids);
+ return -1;
+ }
+ }
+ free(piece_ids);
+ return 0;
+}
+
+static int encode_pretokenized(const tok_bpe_t *tok, const char *text, int **out_ids, int *out_n) {
+ const unsigned char *start = (const unsigned char *)text;
+ const unsigned char *p = start;
+ const unsigned char *end = start + strlen(text);
+ int *ids = NULL;
+ int n_ids = 0, cap = 0;
+
+ while (p < end) {
+ const unsigned char *piece = p;
+ int cp = 0, len = 0;
+ if (!utf8_decode_cp_len(p, end, &cp, &len))
+ break;
+
+ int clen = match_contraction(p, end);
+ if (clen > 0) {
+ p += clen;
+ } else {
+ const unsigned char *next = p + len;
+ int next_cp = 0, next_len = 0;
+ int has_next = utf8_decode_cp_len(next, end, &next_cp, &next_len);
+
+ if (!is_newline_cp(cp) && !is_word_cp(cp) && has_next && is_letter_cp(next_cp)) {
+ p = next + next_len;
+ while (p < end) {
+ int c = 0, l = 0;
+ utf8_decode_cp_len(p, end, &c, &l);
+ if (!is_letter_cp(c))
+ break;
+ p += l;
+ }
+ } else if (is_letter_cp(cp)) {
+ p += len;
+ while (p < end) {
+ int c = 0, l = 0;
+ utf8_decode_cp_len(p, end, &c, &l);
+ if (!is_letter_cp(c))
+ break;
+ p += l;
+ }
+ } else if (is_number_cp(cp)) {
+ p += len;
+ } else if (is_space_cp(cp)) {
+ const unsigned char *q = p;
+ int saw_newline = 0;
+ while (q < end) {
+ int c = 0, l = 0;
+ utf8_decode_cp_len(q, end, &c, &l);
+ if (!is_space_cp(c))
+ break;
+ if (is_newline_cp(c))
+ saw_newline = 1;
+ q += l;
+ if (saw_newline) {
+ while (q < end) {
+ int c2 = 0, l2 = 0;
+ utf8_decode_cp_len(q, end, &c2, &l2);
+ if (!is_newline_cp(c2))
+ break;
+ q += l2;
+ }
+ break;
+ }
+ }
+
+ if (saw_newline) {
+ p = q;
+ } else if (cp == ' ' && has_next && !is_space_cp(next_cp) && !is_word_cp(next_cp)) {
+ p = next + next_len;
+ while (p < end) {
+ int c = 0, l = 0;
+ utf8_decode_cp_len(p, end, &c, &l);
+ if (is_space_cp(c) || is_word_cp(c))
+ break;
+ p += l;
+ }
+ while (p < end) {
+ int c = 0, l = 0;
+ utf8_decode_cp_len(p, end, &c, &l);
+ if (!is_newline_cp(c))
+ break;
+ p += l;
+ }
+ } else {
+ const unsigned char *last = p;
+ const unsigned char *q2 = p;
+ int count = 0;
+ while (q2 < end) {
+ int c = 0, l = 0;
+ utf8_decode_cp_len(q2, end, &c, &l);
+ if (!is_space_cp(c))
+ break;
+ last = q2;
+ q2 += l;
+ count++;
+ }
+ if (q2 < end && count > 1)
+ p = last;
+ else
+ p = q2;
+ }
+ } else {
+ p += len;
+ while (p < end) {
+ int c = 0, l = 0;
+ utf8_decode_cp_len(p, end, &c, &l);
+ if (is_space_cp(c) || is_word_cp(c))
+ break;
+ p += l;
+ }
+ while (p < end) {
+ int c = 0, l = 0;
+ utf8_decode_cp_len(p, end, &c, &l);
+ if (!is_newline_cp(c))
+ break;
+ p += l;
+ }
+ }
+ }
+
+ if (append_encoded_piece(tok, (const char *)piece, (size_t)(p - piece), &ids, &n_ids, &cap) !=
+ 0) {
+ free(ids);
+ return -1;
+ }
+ }
+
+ *out_ids = ids;
+ *out_n = n_ids;
+ return 0;
+}
+
+/* Encode one mapped BPE unicode string to token IDs. */
+static int encode_bpe_word(const tok_bpe_t *tok, const char *mapped, int **out_ids, int *out_n) {
+ *out_ids = NULL;
+ *out_n = 0;
+ if (!mapped || !*mapped)
+ return 0;
+
+ char **syms = NULL;
+ int n_syms = 0;
+ if (split_utf8_symbols(mapped, &syms, &n_syms) != 0)
+ return -1;
+ if (n_syms <= 0) {
+ free(syms);
+ return 0;
+ }
+
+ while (n_syms > 1) {
+ int best_rank = INT_MAX;
+ int best_i = -1;
+ for (int i = 0; i < n_syms - 1; i++) {
+ int r = merge_rank(tok, syms[i], syms[i + 1]);
+ if (r < best_rank) {
+ best_rank = r;
+ best_i = i;
+ }
+ }
+ if (best_i < 0 || best_rank == INT_MAX)
+ break;
+
+ char *merged = str_concat2(syms[best_i], syms[best_i + 1]);
+ if (!merged) {
+ for (int i = 0; i < n_syms; i++)
+ free(syms[i]);
+ free(syms);
+ return -1;
+ }
+ free(syms[best_i]);
+ free(syms[best_i + 1]);
+ syms[best_i] = merged;
+ for (int j = best_i + 1; j < n_syms - 1; j++)
+ syms[j] = syms[j + 1];
+ n_syms--;
+ }
+
+ int *ids = NULL;
+ int n_ids = 0, cap = 0;
+ for (int i = 0; i < n_syms; i++) {
+ int id = map_get((const str_int_entry_t *)tok->vocab_map, tok->vocab_map_cap, syms[i]);
+ if (id < 0) {
+ /* Should not happen with valid vocab + merges + byte-level mapping. */
+ for (int k = 0; k < n_syms; k++)
+ free(syms[k]);
+ free(syms);
+ free(ids);
+ return -1;
+ }
+ if (append_id(&ids, &n_ids, &cap, id) != 0) {
+ for (int k = 0; k < n_syms; k++)
+ free(syms[k]);
+ free(syms);
+ free(ids);
+ return -1;
+ }
+ }
+
+ for (int i = 0; i < n_syms; i++)
+ free(syms[i]);
+ free(syms);
+
+ *out_ids = ids;
+ *out_n = n_ids;
+ return 0;
+}
+
+typedef struct {
+ size_t off;
+} bpe_sym_ref_t;
+
+struct tok_bpe_workspace {
+ char *normalized;
+ size_t normalized_cap;
+ char *mapped;
+ size_t mapped_cap;
+ char *arena;
+ size_t arena_cap;
+ size_t arena_len;
+ bpe_sym_ref_t *syms;
+ int syms_cap;
+ int *ids;
+ int ids_cap;
+ /* Integer-pair BPE merge scratch: token id, doubly-linked live order,
+ * and the cached (rank, merged id) of the pair starting at each live
+ * position. */
+ int *bpe_ids;
+ int *bpe_prv;
+ int *bpe_nxt;
+ int *bpe_rnk;
+ int *bpe_mrg;
+ int bpe_cap;
+};
+
+static int reserve_bpe(tok_bpe_workspace_t *ws, int need) {
+ if (ws->bpe_cap >= need)
+ return 0;
+ int new_cap = ws->bpe_cap ? ws->bpe_cap : 64;
+ while (new_cap < need) {
+ if (new_cap > INT_MAX / 2)
+ return -1;
+ new_cap *= 2;
+ }
+ int *p;
+#define R(field) \
+ p = (int *)realloc(ws->field, (size_t)new_cap * sizeof(int)); \
+ if (!p) \
+ return -1; \
+ ws->field = p;
+ R(bpe_ids)
+ R(bpe_prv)
+ R(bpe_nxt)
+ R(bpe_rnk)
+ R(bpe_mrg)
+#undef R
+ ws->bpe_cap = new_cap;
+ return 0;
+}
+
+static int reserve_bytes(char **buf, size_t *cap, size_t need) {
+ if (*cap >= need)
+ return 0;
+ size_t new_cap = *cap ? *cap : 256;
+ while (new_cap < need) {
+ if (new_cap > SIZE_MAX / 2)
+ return -1;
+ new_cap *= 2;
+ }
+ char *p = (char *)realloc(*buf, new_cap);
+ if (!p)
+ return -1;
+ *buf = p;
+ *cap = new_cap;
+ return 0;
+}
+
+static int reserve_ints(int **buf, int *cap, int need) {
+ if (*cap >= need)
+ return 0;
+ int new_cap = *cap ? *cap : 64;
+ while (new_cap < need) {
+ if (new_cap > INT_MAX / 2)
+ return -1;
+ new_cap *= 2;
+ }
+ int *p = (int *)realloc(*buf, (size_t)new_cap * sizeof(int));
+ if (!p)
+ return -1;
+ *buf = p;
+ *cap = new_cap;
+ return 0;
+}
+
+static int reserve_syms(tok_bpe_workspace_t *ws, int need) {
+ if (ws->syms_cap >= need)
+ return 0;
+ int new_cap = ws->syms_cap ? ws->syms_cap : 64;
+ while (new_cap < need) {
+ if (new_cap > INT_MAX / 2)
+ return -1;
+ new_cap *= 2;
+ }
+ bpe_sym_ref_t *p = (bpe_sym_ref_t *)realloc(ws->syms, (size_t)new_cap * sizeof(*ws->syms));
+ if (!p)
+ return -1;
+ ws->syms = p;
+ ws->syms_cap = new_cap;
+ return 0;
+}
+
+static int arena_append(tok_bpe_workspace_t *ws, const char *s, size_t len, size_t *off) {
+ if (ws->arena_len > SIZE_MAX - len - 1)
+ return -1;
+ size_t need = ws->arena_len + len + 1;
+ if (reserve_bytes(&ws->arena, &ws->arena_cap, need) != 0)
+ return -1;
+ *off = ws->arena_len;
+ memcpy(ws->arena + ws->arena_len, s, len);
+ ws->arena_len += len;
+ ws->arena[ws->arena_len++] = '\0';
+ return 0;
+}
+
+static const char *arena_str(const tok_bpe_workspace_t *ws, bpe_sym_ref_t sym) {
+ return ws->arena + sym.off;
+}
+
+static int normalize_nfc_latin_into(tok_bpe_workspace_t *ws, const char *text, const char **out) {
+ const unsigned char *p = (const unsigned char *)text;
+ const unsigned char *end = p + strlen(text);
+ size_t in_len = (size_t)(end - p);
+ if (in_len > (SIZE_MAX - 1) / 2)
+ return -1;
+ if (reserve_bytes(&ws->normalized, &ws->normalized_cap, in_len * 2 + 1) != 0)
+ return -1;
+
+ size_t w = 0;
+ while (p < end) {
+ const unsigned char *cur = p;
+ int cp = 0, len = 0;
+ if (!utf8_decode_cp_len(p, end, &cp, &len))
+ break;
+ p += len;
+
+ if (p < end) {
+ int mark = 0, mark_len = 0;
+ utf8_decode_cp_len(p, end, &mark, &mark_len);
+ int composed = compose_latin_mark(cp, mark);
+ if (composed) {
+ char tmp[4];
+ int n = utf8_encode_cp(composed, tmp);
+ memcpy(ws->normalized + w, tmp, (size_t)n);
+ w += (size_t)n;
+ p += mark_len;
+ continue;
+ }
+ }
+
+ memcpy(ws->normalized + w, cur, (size_t)len);
+ w += (size_t)len;
+ }
+
+ ws->normalized[w] = '\0';
+ *out = ws->normalized;
+ return 0;
+}
+
+static int
+text_to_bpe_unicode_into(tok_bpe_workspace_t *ws, const char *text, size_t len, const char **out) {
+ init_gpt2_mapping();
+ if (len > (SIZE_MAX - 1) / 3)
+ return -1;
+ if (reserve_bytes(&ws->mapped, &ws->mapped_cap, len * 3 + 1) != 0)
+ return -1;
+
+ size_t w = 0;
+ for (size_t i = 0; i < len; i++) {
+ int cp = gpt2_byte_to_unicode[(unsigned char)text[i]];
+ char tmp[4];
+ int n = utf8_encode_cp(cp, tmp);
+ memcpy(ws->mapped + w, tmp, (size_t)n);
+ w += (size_t)n;
+ }
+ ws->mapped[w] = '\0';
+ *out = ws->mapped;
+ return 0;
+}
+
+static int output_append_id(int *out_ids, int out_cap, int *n_ids, int *overflow, int id) {
+ if (*n_ids < out_cap && out_ids)
+ out_ids[*n_ids] = id;
+ else
+ *overflow = 1;
+ (*n_ids)++;
+ return 0;
+}
+
+static int encode_bpe_word_into_slow(const tok_bpe_t *tok,
+ tok_bpe_workspace_t *ws,
+ const char *mapped,
+ int *out_ids,
+ int out_cap,
+ int *n_ids,
+ int *overflow) {
+ if (!mapped || !*mapped)
+ return 0;
+
+ int n_syms = 0;
+ for (const unsigned char *p = (const unsigned char *)mapped; *p;) {
+ int l = utf8_char_len(*p);
+ p += l;
+ n_syms++;
+ }
+ if (n_syms <= 0)
+ return 0;
+ if (reserve_syms(ws, n_syms) != 0)
+ return -1;
+
+ ws->arena_len = 0;
+ int i = 0;
+ for (const unsigned char *p = (const unsigned char *)mapped; *p;) {
+ int l = utf8_char_len(*p);
+ size_t off = 0;
+ if (arena_append(ws, (const char *)p, (size_t)l, &off) != 0)
+ return -1;
+ ws->syms[i++].off = off;
+ p += l;
+ }
+
+ while (n_syms > 1) {
+ int best_rank = INT_MAX;
+ int best_i = -1;
+ for (int j = 0; j < n_syms - 1; j++) {
+ int r = merge_rank(tok, arena_str(ws, ws->syms[j]), arena_str(ws, ws->syms[j + 1]));
+ if (r < best_rank) {
+ best_rank = r;
+ best_i = j;
+ }
+ }
+ if (best_i < 0 || best_rank == INT_MAX)
+ break;
+
+ const char *a = arena_str(ws, ws->syms[best_i]);
+ const char *b = arena_str(ws, ws->syms[best_i + 1]);
+ size_t la = strlen(a), lb = strlen(b);
+ if (la > SIZE_MAX - lb)
+ return -1;
+ if (reserve_bytes(&ws->arena, &ws->arena_cap, ws->arena_len + la + lb + 1) != 0)
+ return -1;
+
+ a = arena_str(ws, ws->syms[best_i]);
+ b = arena_str(ws, ws->syms[best_i + 1]);
+ size_t off = ws->arena_len;
+ memcpy(ws->arena + ws->arena_len, a, la);
+ ws->arena_len += la;
+ memcpy(ws->arena + ws->arena_len, b, lb);
+ ws->arena_len += lb;
+ ws->arena[ws->arena_len++] = '\0';
+ ws->syms[best_i].off = off;
+ for (int j = best_i + 1; j < n_syms - 1; j++)
+ ws->syms[j] = ws->syms[j + 1];
+ n_syms--;
+ }
+
+ for (int j = 0; j < n_syms; j++) {
+ int id = map_get((const str_int_entry_t *)tok->vocab_map, tok->vocab_map_cap,
+ arena_str(ws, ws->syms[j]));
+ if (id < 0)
+ return -1;
+ output_append_id(out_ids, out_cap, n_ids, overflow, id);
+ }
+ return 0;
+}
+
+/* Integer-pair BPE merge.
+ * Uses token ids in a doubly-linked array with cached pair ranks.
+ * Each merge updates only the two adjacent pairs.
+ *
+ * Falls back to the string-based loop when int tables are unavailable.
+ *
+ * Output is identical: initial ids are byte-level single-char token ids, and
+ * each merge result is the vocab id of the concatenated pair. */
+static int encode_bpe_word_into(const tok_bpe_t *tok,
+ tok_bpe_workspace_t *ws,
+ const char *mapped,
+ int *out_ids,
+ int out_cap,
+ int *n_ids,
+ int *overflow) {
+ if (!mapped || !*mapped)
+ return 0;
+ if (!tok->int_merges || !tok->cp_to_id)
+ return encode_bpe_word_into_slow(tok, ws, mapped, out_ids, out_cap, n_ids, overflow);
+
+ int n = 0;
+ for (const unsigned char *p = (const unsigned char *)mapped; *p;) {
+ p += utf8_char_len(*p);
+ n++;
+ }
+ if (n <= 0)
+ return 0;
+ if (reserve_bpe(ws, n) != 0)
+ return -1;
+
+ int *ids = ws->bpe_ids, *prv = ws->bpe_prv, *nxt = ws->bpe_nxt;
+ int *rnk = ws->bpe_rnk, *mrg = ws->bpe_mrg;
+
+ int i = 0;
+ for (const unsigned char *p = (const unsigned char *)mapped; *p;) {
+ int len = utf8_char_len(*p);
+ int cp;
+ if (len == 1)
+ cp = *p;
+ else if (len == 2)
+ cp = ((*p & 0x1F) << 6) | (p[1] & 0x3F);
+ else
+ cp = 512; /* byte-level alphabet never exceeds two bytes */
+ int id = cp < 512 ? tok->cp_to_id[cp] : -1;
+ if (id < 0)
+ return encode_bpe_word_into_slow(tok, ws, mapped, out_ids, out_cap, n_ids, overflow);
+ ids[i] = id;
+ prv[i] = i - 1;
+ nxt[i] = i + 1 < n ? i + 1 : -1;
+ i++;
+ p += len;
+ }
+
+ for (int j = 0; j < n - 1; j++)
+ rnk[j] = pair_merge_lookup(tok, ids[j], ids[j + 1], &mrg[j]);
+ if (n > 0)
+ rnk[n - 1] = INT_MAX;
+
+ for (;;) {
+ int best = -1, best_rank = INT_MAX;
+ for (int j = 0; j != -1 && nxt[j] != -1; j = nxt[j]) {
+ if (rnk[j] < best_rank) {
+ best_rank = rnk[j];
+ best = j;
+ }
+ }
+ if (best < 0)
+ break;
+
+ ids[best] = mrg[best];
+ int dead = nxt[best];
+ nxt[best] = nxt[dead];
+ if (nxt[dead] != -1)
+ prv[nxt[dead]] = best;
+
+ if (prv[best] != -1)
+ rnk[prv[best]] = pair_merge_lookup(tok, ids[prv[best]], ids[best], &mrg[prv[best]]);
+ rnk[best] =
+ nxt[best] != -1 ? pair_merge_lookup(tok, ids[best], ids[nxt[best]], &mrg[best]) : INT_MAX;
+ }
+
+ for (int j = 0; j != -1; j = nxt[j])
+ output_append_id(out_ids, out_cap, n_ids, overflow, ids[j]);
+ return 0;
+}
+
+static int append_encoded_piece_into(const tok_bpe_t *tok,
+ tok_bpe_workspace_t *ws,
+ const char *piece,
+ size_t piece_len,
+ int *out_ids,
+ int out_cap,
+ int *n_ids,
+ int *overflow) {
+ if (piece_len == 0)
+ return 0;
+
+ const char *mapped = NULL;
+ if (text_to_bpe_unicode_into(ws, piece, piece_len, &mapped) != 0)
+ return -1;
+ return encode_bpe_word_into(tok, ws, mapped, out_ids, out_cap, n_ids, overflow);
+}
+
+static int encode_pretokenized_into(const tok_bpe_t *tok,
+ tok_bpe_workspace_t *ws,
+ const char *text,
+ int *out_ids,
+ int out_cap,
+ int *out_n) {
+ const unsigned char *start = (const unsigned char *)text;
+ const unsigned char *p = start;
+ const unsigned char *end = start + strlen(text);
+ int n_ids = 0;
+ int overflow = 0;
+
+ while (p < end) {
+ const unsigned char *piece = p;
+ int cp = 0, len = 0;
+ if (!utf8_decode_cp_len(p, end, &cp, &len))
+ break;
+
+ int clen = match_contraction(p, end);
+ if (clen > 0) {
+ p += clen;
+ } else {
+ const unsigned char *next = p + len;
+ int next_cp = 0, next_len = 0;
+ int has_next = utf8_decode_cp_len(next, end, &next_cp, &next_len);
+
+ if (!is_newline_cp(cp) && !is_word_cp(cp) && has_next && is_letter_cp(next_cp)) {
+ p = next + next_len;
+ while (p < end) {
+ int c = 0, l = 0;
+ utf8_decode_cp_len(p, end, &c, &l);
+ if (!is_letter_cp(c))
+ break;
+ p += l;
+ }
+ } else if (is_letter_cp(cp)) {
+ p += len;
+ while (p < end) {
+ int c = 0, l = 0;
+ utf8_decode_cp_len(p, end, &c, &l);
+ if (!is_letter_cp(c))
+ break;
+ p += l;
+ }
+ } else if (is_number_cp(cp)) {
+ p += len;
+ } else if (is_space_cp(cp)) {
+ const unsigned char *q = p;
+ int saw_newline = 0;
+ while (q < end) {
+ int c = 0, l = 0;
+ utf8_decode_cp_len(q, end, &c, &l);
+ if (!is_space_cp(c))
+ break;
+ if (is_newline_cp(c))
+ saw_newline = 1;
+ q += l;
+ if (saw_newline) {
+ while (q < end) {
+ int c2 = 0, l2 = 0;
+ utf8_decode_cp_len(q, end, &c2, &l2);
+ if (!is_newline_cp(c2))
+ break;
+ q += l2;
+ }
+ break;
+ }
+ }
+
+ if (saw_newline) {
+ p = q;
+ } else if (cp == ' ' && has_next && !is_space_cp(next_cp) && !is_word_cp(next_cp)) {
+ p = next + next_len;
+ while (p < end) {
+ int c = 0, l = 0;
+ utf8_decode_cp_len(p, end, &c, &l);
+ if (is_space_cp(c) || is_word_cp(c))
+ break;
+ p += l;
+ }
+ while (p < end) {
+ int c = 0, l = 0;
+ utf8_decode_cp_len(p, end, &c, &l);
+ if (!is_newline_cp(c))
+ break;
+ p += l;
+ }
+ } else {
+ const unsigned char *last = p;
+ const unsigned char *q2 = p;
+ int count = 0;
+ while (q2 < end) {
+ int c = 0, l = 0;
+ utf8_decode_cp_len(q2, end, &c, &l);
+ if (!is_space_cp(c))
+ break;
+ last = q2;
+ q2 += l;
+ count++;
+ }
+ if (q2 < end && count > 1)
+ p = last;
+ else
+ p = q2;
+ }
+ } else {
+ p += len;
+ while (p < end) {
+ int c = 0, l = 0;
+ utf8_decode_cp_len(p, end, &c, &l);
+ if (is_space_cp(c) || is_word_cp(c))
+ break;
+ p += l;
+ }
+ while (p < end) {
+ int c = 0, l = 0;
+ utf8_decode_cp_len(p, end, &c, &l);
+ if (!is_newline_cp(c))
+ break;
+ p += l;
+ }
+ }
+ }
+
+ if (append_encoded_piece_into(tok, ws, (const char *)piece, (size_t)(p - piece), out_ids,
+ out_cap, &n_ids, &overflow) != 0)
+ return -1;
+ }
+
+ *out_n = n_ids;
+ return overflow ? -2 : 0;
+}
+
+static int derive_merges_path(const char *vocab_path, char *out_path, size_t out_cap) {
+ const char *slash = strrchr(vocab_path, '/');
+ if (!slash) {
+ if (snprintf(out_path, out_cap, "merges.txt") >= (int)out_cap)
+ return -1;
+ return 0;
+ }
+ size_t dir_len = (size_t)(slash - vocab_path);
+ if (dir_len + 12 >= out_cap)
+ return -1;
+ memcpy(out_path, vocab_path, dir_len);
+ out_path[dir_len] = '\0';
+ snprintf(out_path + dir_len, out_cap - dir_len, "/merges.txt");
+ return 0;
+}
+
+static void trim_newline(char *line) {
+ size_t n = strlen(line);
+ while (n > 0 && (line[n - 1] == '\n' || line[n - 1] == '\r'))
+ line[--n] = '\0';
+}
+
+static int parse_merge_pair(char *line, char **a, char **b) {
+ *a = NULL;
+ *b = NULL;
+ trim_newline(line);
+ if (line[0] == '\0')
+ return -1;
+ if (line[0] == '#')
+ return -1;
+
+ char *sp = strchr(line, ' ');
+ if (!sp)
+ return -1;
+ *sp = '\0';
+ char *p2 = sp + 1;
+ while (*p2 == ' ')
+ p2++;
+ if (*line == '\0' || *p2 == '\0')
+ return -1;
+ *a = line;
+ *b = p2;
+ return 0;
+}
+
+static int load_merges_map(tok_bpe_t *tok, const char *merges_path) {
+ FILE *f = fopen(merges_path, "rb");
+ if (!f)
+ return -1;
+
+ int n_pairs = 0;
+ char line[8192];
+ while (fgets(line, sizeof(line), f)) {
+ char *a = NULL, *b = NULL;
+ if (parse_merge_pair(line, &a, &b) == 0)
+ n_pairs++;
+ }
+ if (n_pairs <= 0) {
+ fclose(f);
+ return -1;
+ }
+
+ tok->merge_map_cap = next_pow2(n_pairs * 2);
+ tok->merge_map = calloc((size_t)tok->merge_map_cap, sizeof(str_int_entry_t));
+ if (!tok->merge_map) {
+ fclose(f);
+ tok->merge_map_cap = 0;
+ return -1;
+ }
+
+ if (fseek(f, 0, SEEK_SET) != 0) {
+ fclose(f);
+ return -1;
+ }
+ tok->int_merges_cap = next_pow2(n_pairs * 2);
+ pair_merge_entry_t *pm =
+ (pair_merge_entry_t *)calloc((size_t)tok->int_merges_cap, sizeof(pair_merge_entry_t));
+ if (pm) {
+ for (int i = 0; i < tok->int_merges_cap; i++) {
+ pm[i].key = UINT64_MAX;
+ pm[i].rank = INT_MAX;
+ pm[i].merged_id = -1;
+ }
+ }
+ tok->int_merges = pm;
+
+ int rank = 0;
+ while (fgets(line, sizeof(line), f)) {
+ char *a = NULL, *b = NULL;
+ if (parse_merge_pair(line, &a, &b) != 0)
+ continue;
+
+ size_t la = strlen(a), lb = strlen(b);
+ char *key = (char *)malloc(la + 1 + lb + 1);
+ if (!key)
+ continue;
+ memcpy(key, a, la);
+ key[la] = ' ';
+ memcpy(key + la + 1, b, lb);
+ key[la + 1 + lb] = '\0';
+
+ if (tok->int_merges) {
+ /* Resolve (a, b) and the merged token a+b to vocab ids; if any
+ * merge is unresolvable, drop the whole int table and keep the
+ * string-based loop as the only path. */
+ const str_int_entry_t *vm = (const str_int_entry_t *)tok->vocab_map;
+ int left = map_get(vm, tok->vocab_map_cap, a);
+ int right = map_get(vm, tok->vocab_map_cap, b);
+ char ab[8192];
+ int merged = -1;
+ if (la + lb < sizeof(ab)) {
+ memcpy(ab, a, la);
+ memcpy(ab + la, b, lb);
+ ab[la + lb] = '\0';
+ merged = map_get(vm, tok->vocab_map_cap, ab);
+ }
+ if (left < 0 || right < 0 || merged < 0) {
+ free(tok->int_merges);
+ tok->int_merges = NULL;
+ tok->int_merges_cap = 0;
+ } else {
+ pair_map_insert((pair_merge_entry_t *)tok->int_merges, tok->int_merges_cap,
+ ((uint64_t)(uint32_t)left << 32) | (uint32_t)right, rank, merged);
+ }
+ }
+ (void)map_insert_owned((str_int_entry_t *)tok->merge_map, tok->merge_map_cap, &key, rank);
+ free(key);
+ rank++;
+ }
+ fclose(f);
+
+ /* Byte-level unicode codepoint -> single-char token id table. */
+ if (tok->int_merges) {
+ init_gpt2_mapping();
+ tok->cp_to_id = (int *)malloc(512 * sizeof(int));
+ if (tok->cp_to_id) {
+ for (int i = 0; i < 512; i++)
+ tok->cp_to_id[i] = -1;
+ for (int byte = 0; byte < 256 && tok->cp_to_id; byte++) {
+ int cp = gpt2_byte_to_unicode[byte];
+ char buf[4];
+ int n;
+ if (cp < 0x80) {
+ buf[0] = (char)cp;
+ n = 1;
+ } else {
+ buf[0] = (char)(0xC0 | (cp >> 6));
+ buf[1] = (char)(0x80 | (cp & 0x3F));
+ n = 2;
+ }
+ buf[n] = '\0';
+ int id = map_get((const str_int_entry_t *)tok->vocab_map, tok->vocab_map_cap, buf);
+ if (id < 0) {
+ free(tok->cp_to_id);
+ tok->cp_to_id = NULL;
+ } else {
+ tok->cp_to_id[cp] = id;
+ }
+ }
+ }
+ }
+ return 0;
+}
+
+/* Public API */
+
+tok_bpe_t *tok_bpe_load(const char *vocab_json_path) {
+ FILE *f = fopen(vocab_json_path, "rb");
+ if (!f) {
+ fprintf(stderr, "tok_bpe_load: cannot open %s\n", vocab_json_path);
+ return NULL;
+ }
+
+ if (fseek(f, 0, SEEK_END) != 0) {
+ fclose(f);
+ return NULL;
+ }
+ long file_size = ftell(f);
+ if (file_size < 0 || fseek(f, 0, SEEK_SET) != 0) {
+ fclose(f);
+ return NULL;
+ }
+
+ char *json = (char *)malloc((size_t)file_size + 1);
+ if (!json || fread(json, 1, (size_t)file_size, f) != (size_t)file_size) {
+ fclose(f);
+ free(json);
+ return NULL;
+ }
+ fclose(f);
+ json[file_size] = '\0';
+
+ yyjson_doc *doc = yyjson_read(json, (size_t)file_size, 0);
+ yyjson_val *root = yyjson_doc_get_root(doc);
+ if (!yyjson_is_obj(root)) {
+ yyjson_doc_free(doc);
+ free(json);
+ return NULL;
+ }
+
+ /* vocab.json is a flat { token: id } object.
+ * Walk it once to find the max id and size the tables, then again to fill them.
+ * yyjson unescapes each key, including \uXXXX, to the same byte-level GPT-2 form
+ * the old scanner produced.
+ * decode_gpt2_token then maps that to the raw token text. */
+ int max_id = 0;
+ size_t idx, n;
+ yyjson_val *key, *val;
+ yyjson_obj_foreach(root, idx, n, key, val) {
+ int64_t id = yyjson_get_int(val);
+ if (id > max_id)
+ max_id = (int)id;
+ }
+
+ int vocab_size = max_id + 1;
+ tok_bpe_t *tok = (tok_bpe_t *)calloc(1, sizeof(tok_bpe_t));
+ if (!tok) {
+ yyjson_doc_free(doc);
+ free(json);
+ return NULL;
+ }
+ tok->vocab_size = vocab_size;
+ tok->id_to_text = (char **)calloc((size_t)vocab_size, sizeof(char *));
+ tok->id_to_bpe = (char **)calloc((size_t)vocab_size, sizeof(char *));
+ if (!tok->id_to_text || !tok->id_to_bpe) {
+ tok_bpe_free(tok);
+ yyjson_doc_free(doc);
+ free(json);
+ return NULL;
+ }
+
+ yyjson_obj_foreach(root, idx, n, key, val) {
+ const char *kstr = yyjson_get_str(key);
+ int64_t id = yyjson_get_int(val);
+ if (kstr && id >= 0 && id < vocab_size) {
+ free(tok->id_to_bpe[id]);
+ free(tok->id_to_text[id]);
+ tok->id_to_bpe[id] = strdup(kstr);
+ tok->id_to_text[id] = decode_gpt2_token(kstr);
+ }
+ }
+ yyjson_doc_free(doc);
+ free(json);
+
+ int n_vocab_entries = 0;
+ for (int i = 0; i < vocab_size; i++)
+ if (tok->id_to_bpe[i])
+ n_vocab_entries++;
+ tok->vocab_map_cap = next_pow2(n_vocab_entries * 2 + 1);
+ tok->vocab_map = calloc((size_t)tok->vocab_map_cap, sizeof(str_int_entry_t));
+ if (!tok->vocab_map) {
+ tok_bpe_free(tok);
+ return NULL;
+ }
+ for (int i = 0; i < vocab_size; i++) {
+ if (tok->id_to_bpe[i]) {
+ map_insert((str_int_entry_t *)tok->vocab_map, tok->vocab_map_cap, tok->id_to_bpe[i], i);
+ }
+ }
+
+ char merges_path[1024];
+ if (derive_merges_path(vocab_json_path, merges_path, sizeof(merges_path)) == 0) {
+ if (load_merges_map(tok, merges_path) != 0) {
+ fprintf(stderr,
+ "Tokenizer: merges not loaded from %s (encoding falls back to byte-level)\n",
+ merges_path);
+ }
+ }
+
+ return tok;
+}
+
+const char *tok_bpe_decode(const tok_bpe_t *tok, int token_id) {
+ if (!tok || token_id < 0 || token_id >= tok->vocab_size)
+ return "";
+ return tok->id_to_text[token_id] ? tok->id_to_text[token_id] : "";
+}
+
+int tok_bpe_token_id(const tok_bpe_t *tok, const char *token) {
+ if (!tok || !token || !tok->vocab_map)
+ return -1;
+ return map_get((const str_int_entry_t *)tok->vocab_map, tok->vocab_map_cap, token);
+}
+
+int *tok_bpe_encode(const tok_bpe_t *tok, const char *text, int *out_n_tokens) {
+ if (out_n_tokens)
+ *out_n_tokens = 0;
+ if (!tok || !text || text[0] == '\0')
+ return NULL;
+
+ char *normalized = normalize_nfc_latin(text);
+ if (!normalized)
+ return NULL;
+
+ int *ids = NULL;
+ int n_ids = 0;
+ if (encode_pretokenized(tok, normalized, &ids, &n_ids) != 0) {
+ free(normalized);
+ free(ids);
+ return NULL;
+ }
+ free(normalized);
+
+ if (out_n_tokens)
+ *out_n_tokens = n_ids;
+ return ids;
+}
+
+tok_bpe_workspace_t *tok_bpe_workspace_new(void) {
+ return (tok_bpe_workspace_t *)calloc(1, sizeof(tok_bpe_workspace_t));
+}
+
+void tok_bpe_workspace_free(tok_bpe_workspace_t *ws) {
+ if (!ws)
+ return;
+ free(ws->normalized);
+ free(ws->mapped);
+ free(ws->arena);
+ free(ws->syms);
+ free(ws->ids);
+ free(ws->bpe_ids);
+ free(ws->bpe_prv);
+ free(ws->bpe_nxt);
+ free(ws->bpe_rnk);
+ free(ws->bpe_mrg);
+ free(ws);
+}
+
+int tok_bpe_encode_into(const tok_bpe_t *tok,
+ tok_bpe_workspace_t *ws,
+ const char *text,
+ int *out_ids,
+ int out_cap,
+ int *out_n_tokens) {
+ if (out_n_tokens)
+ *out_n_tokens = 0;
+ if (!tok || !ws || !text || out_cap < 0)
+ return -1;
+ if (text[0] == '\0')
+ return 0;
+
+ const char *normalized = NULL;
+ if (normalize_nfc_latin_into(ws, text, &normalized) != 0)
+ return -1;
+
+ int n_ids = 0;
+ int rc = encode_pretokenized_into(tok, ws, normalized, out_ids, out_cap, &n_ids);
+ if (out_n_tokens)
+ *out_n_tokens = n_ids;
+ return rc;
+}
+
+int *tok_bpe_encode_with_workspace(const tok_bpe_t *tok,
+ tok_bpe_workspace_t *ws,
+ const char *text,
+ int *out_n_tokens) {
+ if (out_n_tokens)
+ *out_n_tokens = 0;
+ if (!tok || !ws || !text || text[0] == '\0')
+ return NULL;
+
+ size_t len = strlen(text);
+ size_t cap_sz = len > (SIZE_MAX - 8) / 2 ? SIZE_MAX : len * 2 + 8;
+ if (cap_sz > (size_t)INT_MAX)
+ return NULL;
+ int cap = (int)cap_sz;
+
+ if (reserve_ints(&ws->ids, &ws->ids_cap, cap) != 0)
+ return NULL;
+
+ int n_ids = 0;
+ int rc = tok_bpe_encode_into(tok, ws, text, ws->ids, ws->ids_cap, &n_ids);
+ if (rc == -2) {
+ if (reserve_ints(&ws->ids, &ws->ids_cap, n_ids) != 0)
+ return NULL;
+ rc = tok_bpe_encode_into(tok, ws, text, ws->ids, ws->ids_cap, &n_ids);
+ }
+ if (rc != 0 || n_ids <= 0)
+ return NULL;
+
+ int *ids = (int *)malloc((size_t)n_ids * sizeof(int));
+ if (!ids)
+ return NULL;
+ memcpy(ids, ws->ids, (size_t)n_ids * sizeof(int));
+ if (out_n_tokens)
+ *out_n_tokens = n_ids;
+ return ids;
+}
+
+void tok_bpe_free(tok_bpe_t *tok) {
+ if (!tok)
+ return;
+
+ if (tok->id_to_text) {
+ for (int i = 0; i < tok->vocab_size; i++)
+ free(tok->id_to_text[i]);
+ free(tok->id_to_text);
+ }
+ if (tok->id_to_bpe) {
+ for (int i = 0; i < tok->vocab_size; i++)
+ free(tok->id_to_bpe[i]);
+ free(tok->id_to_bpe);
+ }
+
+ if (tok->merge_map) {
+ str_int_entry_t *m = (str_int_entry_t *)tok->merge_map;
+ for (int i = 0; i < tok->merge_map_cap; i++)
+ free(m[i].key);
+ free(tok->merge_map);
+ }
+ free(tok->vocab_map);
+ free(tok->int_merges);
+ free(tok->cp_to_id);
+ free(tok);
+}
diff --git a/libffwd/bpe.h b/libffwd/bpe.h
new file mode 100644
index 0000000..5199fd0
--- /dev/null
+++ b/libffwd/bpe.h
@@ -0,0 +1,74 @@
+/*
+ * Qwen2/Qwen3 BPE tokenizer (GPT-2 byte-level).
+ *
+ * Supports:
+ * - decode token ID -> UTF-8 text
+ * - encode UTF-8 text -> token IDs (vocab.json + merges.txt)
+ */
+
+#ifndef TOK_BPE_H
+#define TOK_BPE_H
+
+typedef struct {
+ char **id_to_text; /* [vocab_size] decoded text strings */
+ char **id_to_bpe; /* [vocab_size] raw BPE token strings from vocab.json */
+ int vocab_size;
+
+ /* Internal hash maps (opaque to callers) */
+ void *vocab_map;
+ int vocab_map_cap;
+ void *merge_map;
+ int merge_map_cap;
+ /* Integer-pair BPE merge table: (left_id, right_id) -> (rank, merged_id).
+ * NULL when the vocab could not resolve every merge; encoding then falls
+ * back to the string-based merge loop. */
+ void *int_merges;
+ int int_merges_cap;
+ /* Byte-level unicode codepoint -> single-character token id (512 slots),
+ * or NULL when any byte token is missing from the vocab. */
+ int *cp_to_id;
+} tok_bpe_t;
+
+typedef struct tok_bpe_workspace tok_bpe_workspace_t;
+
+/* Load tokenizer from vocab.json in model directory */
+tok_bpe_t *tok_bpe_load(const char *vocab_json_path);
+
+/* Decode a single token ID to text. Returns pointer to internal string. */
+const char *tok_bpe_decode(const tok_bpe_t *tok, int token_id);
+
+/* Look up the id of a raw vocab.json token string (e.g. "<|endoftext|>").
+ * Returns -1 when the token is not in the vocab. */
+int tok_bpe_token_id(const tok_bpe_t *tok, const char *token);
+
+/* Encode UTF-8 text into token IDs using BPE.
+ * Returns malloc'd array of token IDs and sets *out_n_tokens.
+ * Returns NULL on error (and sets *out_n_tokens to 0). */
+int *tok_bpe_encode(const tok_bpe_t *tok, const char *text, int *out_n_tokens);
+
+/* Reusable scratch for allocation-light repeated encoding. */
+tok_bpe_workspace_t *tok_bpe_workspace_new(void);
+void tok_bpe_workspace_free(tok_bpe_workspace_t *ws);
+
+/* Encode into caller-provided out_ids[0..out_cap-1].
+ * Returns 0 on success, -1 on error, -2 if out_cap is too small.
+ * In all cases *out_n_tokens is set to the number of tokens needed/emitted
+ * when out_n_tokens is non-NULL. */
+int tok_bpe_encode_into(const tok_bpe_t *tok,
+ tok_bpe_workspace_t *ws,
+ const char *text,
+ int *out_ids,
+ int out_cap,
+ int *out_n_tokens);
+
+/* Same tokenization as tok_bpe_encode(), but reuses ws internally and
+ * performs only the final returned int[] allocation. */
+int *tok_bpe_encode_with_workspace(const tok_bpe_t *tok,
+ tok_bpe_workspace_t *ws,
+ const char *text,
+ int *out_n_tokens);
+
+/* Free tokenizer */
+void tok_bpe_free(tok_bpe_t *tok);
+
+#endif /* TOK_BPE_H */
diff --git a/libffwd/config.c b/libffwd/config.c
new file mode 100644
index 0000000..d9efb4d
--- /dev/null
+++ b/libffwd/config.c
@@ -0,0 +1,341 @@
+#include "config.h"
+
+#include <yyjson.h>
+
+#include <errno.h>
+#include <limits.h>
+#include <math.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+/* Verbosity flag for optional stderr diagnostics across the codebase.
+ * Defined in config.c because every backend links it. */
+int ffwd_verbose = 0;
+
+typedef enum {
+ JSON_BOOL_MISSING = 0,
+ JSON_BOOL_FALSE = 1,
+ JSON_BOOL_TRUE = 2,
+ JSON_BOOL_INVALID = -1,
+} json_bool_t;
+
+/* Read fields from a parsed JSON object.
+ * yyjson getters tolerate NULL, so missing keys or wrong types cleanly return
+ * the fallback.
+ *
+ * This replaces substring scanning, which could match a key anywhere in the
+ * document, including inside nested sub-configs. A real parser avoids that
+ * failure mode. */
+static int json_get_int(yyjson_val *obj, const char *key, int fallback) {
+ yyjson_val *v = yyjson_obj_get(obj, key);
+ if (yyjson_is_int(v))
+ return (int)yyjson_get_int(v);
+ if (yyjson_is_real(v))
+ return (int)yyjson_get_real(v);
+ return fallback;
+}
+
+static double json_get_double(yyjson_val *obj, const char *key, double fallback) {
+ yyjson_val *v = yyjson_obj_get(obj, key);
+ return yyjson_is_num(v) ? yyjson_get_num(v) : fallback;
+}
+
+static int json_string_equals(yyjson_val *obj, const char *key, const char *expected) {
+ const char *s = yyjson_get_str(yyjson_obj_get(obj, key));
+ return s && strcmp(s, expected) == 0;
+}
+
+static json_bool_t json_get_bool(yyjson_val *obj, const char *key) {
+ yyjson_val *v = yyjson_obj_get(obj, key);
+ if (!v)
+ return JSON_BOOL_MISSING;
+ if (yyjson_is_bool(v))
+ return yyjson_get_bool(v) ? JSON_BOOL_TRUE : JSON_BOOL_FALSE;
+ return JSON_BOOL_INVALID;
+}
+
+/* Return 1 with a NUL-terminated buffer, 0 when an optional file is absent,
+ * and -1 for an existing file that could not be read. */
+static int read_optional_file(const char *model_dir, const char *relative, char **out) {
+ char path[1024];
+ int n = snprintf(path, sizeof(path), "%s/%s", model_dir, relative);
+ if (n < 0 || (size_t)n >= sizeof(path)) {
+ fprintf(stderr, "ffwd_config: model path too long\n");
+ return -1;
+ }
+
+ FILE *f = fopen(path, "rb");
+ if (!f && errno == ENOENT)
+ return 0;
+ if (!f) {
+ fprintf(stderr, "ffwd_config: cannot open %s\n", path);
+ return -1;
+ }
+ if (fseek(f, 0, SEEK_END) != 0) {
+ fclose(f);
+ return -1;
+ }
+ long sz = ftell(f);
+ if (sz < 0 || (size_t)sz == SIZE_MAX || fseek(f, 0, SEEK_SET) != 0) {
+ fclose(f);
+ return -1;
+ }
+ char *buf = (char *)malloc((size_t)sz + 1);
+ if (!buf || fread(buf, 1, (size_t)sz, f) != (size_t)sz) {
+ fclose(f);
+ free(buf);
+ return -1;
+ }
+ fclose(f);
+ buf[sz] = '\0';
+ *out = buf;
+ return 1;
+}
+
+static int parse_sentence_transformers_metadata(ffwd_config_t *cfg, const char *model_dir) {
+ char *buf = NULL;
+ int rc = read_optional_file(model_dir, "1_Pooling/config.json", &buf);
+ if (rc < 0)
+ return -1;
+ if (rc > 0) {
+ yyjson_doc *doc = yyjson_read(buf, strlen(buf), 0);
+ yyjson_val *root = yyjson_doc_get_root(doc);
+ json_bool_t mean = json_get_bool(root, "pooling_mode_mean_tokens");
+ json_bool_t last = json_get_bool(root, "pooling_mode_lasttoken");
+ json_bool_t cls = json_get_bool(root, "pooling_mode_cls_token");
+ json_bool_t max = json_get_bool(root, "pooling_mode_max_tokens");
+ json_bool_t sqrt_len = json_get_bool(root, "pooling_mode_mean_sqrt_len_tokens");
+ json_bool_t weighted = json_get_bool(root, "pooling_mode_weightedmean_tokens");
+ if (mean < 0 || last < 0 || cls < 0 || max < 0 || sqrt_len < 0 || weighted < 0) {
+ fprintf(stderr, "ffwd_config: invalid pooling metadata\n");
+ yyjson_doc_free(doc);
+ free(buf);
+ return -1;
+ }
+ int supported = (mean == JSON_BOOL_TRUE) + (last == JSON_BOOL_TRUE) + (cls == JSON_BOOL_TRUE);
+ int unsupported =
+ max == JSON_BOOL_TRUE || sqrt_len == JSON_BOOL_TRUE || weighted == JSON_BOOL_TRUE;
+ if (supported != 1 || unsupported) {
+ fprintf(stderr, "ffwd_config: unsupported Sentence Transformers pooling mode\n");
+ yyjson_doc_free(doc);
+ free(buf);
+ return -1;
+ }
+ cfg->pooling_mode = cls == JSON_BOOL_TRUE ? FFWD_POOL_CLS
+ : last == JSON_BOOL_TRUE ? FFWD_POOL_LAST_TOKEN
+ : FFWD_POOL_MEAN;
+ yyjson_doc_free(doc);
+ free(buf);
+ buf = NULL;
+ }
+
+ rc = read_optional_file(model_dir, "modules.json", &buf);
+ if (rc < 0)
+ return -1;
+ if (rc > 0) {
+ /* modules.json is an array of module objects; the embeddings are
+ * normalized iff one module's "type" is the Normalize class. Walking the
+ * array is exact, unlike a substring match that any field could trip. */
+ yyjson_doc *doc = yyjson_read(buf, strlen(buf), 0);
+ yyjson_val *root = yyjson_doc_get_root(doc);
+ int normalize = 0;
+ size_t idx, n;
+ yyjson_val *mod;
+ yyjson_arr_foreach(root, idx, n, mod) {
+ if (json_string_equals(mod, "type", "sentence_transformers.models.Normalize")) {
+ normalize = 1;
+ break;
+ }
+ }
+ cfg->normalize_embeddings = normalize;
+ yyjson_doc_free(doc);
+ free(buf);
+ buf = NULL;
+ }
+
+ rc = read_optional_file(model_dir, "tokenizer_config.json", &buf);
+ if (rc < 0)
+ return -1;
+ if (rc > 0) {
+ yyjson_doc *doc = yyjson_read(buf, strlen(buf), 0);
+ yyjson_val *root = yyjson_doc_get_root(doc);
+ json_bool_t add_eos = json_get_bool(root, "add_eos_token");
+ if (add_eos < 0) {
+ fprintf(stderr, "ffwd_config: invalid add_eos_token metadata\n");
+ yyjson_doc_free(doc);
+ free(buf);
+ return -1;
+ }
+ if (add_eos != JSON_BOOL_MISSING)
+ cfg->append_terminal_token = add_eos == JSON_BOOL_TRUE;
+ yyjson_doc_free(doc);
+ free(buf);
+ }
+ return 0;
+}
+
+int ffwd_config_parse(ffwd_config_t *cfg, const char *model_dir) {
+ char path[1024];
+ int n = snprintf(path, sizeof(path), "%s/config.json", model_dir);
+ if (n < 0 || (size_t)n >= sizeof(path)) {
+ fprintf(stderr, "ffwd_config: model path too long\n");
+ return -1;
+ }
+
+ FILE *f = fopen(path, "rb");
+ if (!f) {
+ fprintf(stderr, "ffwd_config: cannot open %s\n", path);
+ return -1;
+ }
+
+ if (fseek(f, 0, SEEK_END) != 0) {
+ fclose(f);
+ return -1;
+ }
+ long sz = ftell(f);
+ if (sz < 0 || (size_t)sz == SIZE_MAX || fseek(f, 0, SEEK_SET) != 0) {
+ fclose(f);
+ return -1;
+ }
+ char *buf = (char *)malloc((size_t)sz + 1);
+ if (!buf || fread(buf, 1, (size_t)sz, f) != (size_t)sz) {
+ fclose(f);
+ free(buf);
+ return -1;
+ }
+ fclose(f);
+ buf[sz] = '\0';
+
+ yyjson_doc *doc = yyjson_read(buf, (size_t)sz, 0);
+ yyjson_val *root = yyjson_doc_get_root(doc);
+ if (!yyjson_is_obj(root)) {
+ fprintf(stderr, "ffwd_config: invalid JSON in %s\n", path);
+ yyjson_doc_free(doc);
+ free(buf);
+ return -1;
+ }
+
+ cfg->hidden_size = json_get_int(root, "hidden_size", 0);
+ cfg->n_layers = json_get_int(root, "num_hidden_layers", 0);
+ cfg->n_heads = json_get_int(root, "num_attention_heads", 0);
+ cfg->n_kv_heads = json_get_int(root, "num_key_value_heads", 0);
+ cfg->head_dim = json_get_int(root, "head_dim", FFWD_HEAD_DIM);
+ cfg->intermediate_size = json_get_int(root, "intermediate_size", 0);
+ cfg->vocab_size = json_get_int(root, "vocab_size", FFWD_VOCAB_SIZE);
+ cfg->rms_norm_eps = (float)json_get_double(root, "rms_norm_eps", 1e-6);
+ cfg->layer_norm_eps = (float)json_get_double(root, "layer_norm_eps", 1e-12);
+ cfg->rope_theta = (float)json_get_double(root, "rope_theta", 1000000.0);
+ cfg->max_position_embeddings = json_get_int(root, "max_position_embeddings", 0);
+ cfg->position_id_offset = 0;
+ cfg->type_vocab_size = json_get_int(root, "type_vocab_size", 2);
+ cfg->family = FFWD_FAMILY_QWEN3;
+ cfg->qk_norm = 1;
+ cfg->qkv_bias = 0;
+ cfg->attention_mode = FFWD_ATTENTION_BIDIRECTIONAL;
+ cfg->pooling_mode = FFWD_POOL_MEAN;
+ cfg->normalize_embeddings = 0;
+ cfg->append_terminal_token = 0;
+
+ if (json_string_equals(root, "model_type", "qwen3")) {
+ cfg->attention_mode = FFWD_ATTENTION_CAUSAL;
+ cfg->pooling_mode = FFWD_POOL_LAST_TOKEN;
+ cfg->normalize_embeddings = 1;
+ cfg->append_terminal_token = 1;
+ } else if (json_string_equals(root, "model_type", "qwen2")) {
+ cfg->qk_norm = 0;
+ cfg->qkv_bias = 1;
+ cfg->attention_mode = FFWD_ATTENTION_CAUSAL;
+ } else if (json_string_equals(root, "model_type", "bert") ||
+ json_string_equals(root, "model_type", "roberta") ||
+ json_string_equals(root, "model_type", "xlm-roberta")) {
+ cfg->family = FFWD_FAMILY_BERT;
+ cfg->qk_norm = 0;
+ cfg->qkv_bias = 1; /* q/k/v/o and both dense layers carry bias */
+ cfg->attention_mode = FFWD_ATTENTION_BIDIRECTIONAL;
+ cfg->n_kv_heads = cfg->n_heads; /* full multi-head attention, no GQA */
+ cfg->head_dim = cfg->n_heads > 0 ? cfg->hidden_size / cfg->n_heads : 0;
+ if (json_string_equals(root, "model_type", "roberta") ||
+ json_string_equals(root, "model_type", "xlm-roberta")) {
+ int pad_id = json_get_int(root, "pad_token_id", 1);
+ if (pad_id < 0 || pad_id == INT_MAX) {
+ fprintf(stderr, "ffwd_config: invalid RoBERTa pad_token_id\n");
+ yyjson_doc_free(doc);
+ free(buf);
+ return -1;
+ }
+ cfg->position_id_offset = pad_id + 1;
+ }
+ /* hidden_act selects the feed-forward GeLU curve. gelu_new and
+ * gelu_pytorch_tanh are the same tanh approximation; everything else
+ * (gelu, absent) is the exact erf GeLU the released encoders use. */
+ if (json_string_equals(root, "hidden_act", "gelu_new") ||
+ json_string_equals(root, "hidden_act", "gelu_pytorch_tanh")) {
+ cfg->ffn_act = FFWD_ACT_GELU_TANH;
+ }
+ if (cfg->max_position_embeddings <= 0 ||
+ cfg->position_id_offset >= cfg->max_position_embeddings || cfg->type_vocab_size <= 0 ||
+ !isfinite(cfg->layer_norm_eps) || cfg->layer_norm_eps <= 0.0f) {
+ fprintf(stderr, "ffwd_config: invalid BERT layer_norm_eps/max_position_embeddings\n");
+ yyjson_doc_free(doc);
+ free(buf);
+ return -1;
+ }
+ }
+
+ json_bool_t is_causal = json_get_bool(root, "is_causal");
+ if (is_causal < 0) {
+ fprintf(stderr, "ffwd_config: invalid is_causal in %s\n", path);
+ yyjson_doc_free(doc);
+ free(buf);
+ return -1;
+ }
+ if (is_causal != JSON_BOOL_MISSING) {
+ cfg->attention_mode =
+ is_causal == JSON_BOOL_TRUE ? FFWD_ATTENTION_CAUSAL : FFWD_ATTENTION_BIDIRECTIONAL;
+ }
+
+ cfg->q_dim = 0;
+ cfg->kv_dim = 0;
+ if (cfg->n_heads > 0 && cfg->head_dim > 0 && cfg->n_heads <= INT_MAX / cfg->head_dim)
+ cfg->q_dim = cfg->n_heads * cfg->head_dim;
+ if (cfg->n_kv_heads > 0 && cfg->head_dim > 0 && cfg->n_kv_heads <= INT_MAX / cfg->head_dim)
+ cfg->kv_dim = cfg->n_kv_heads * cfg->head_dim;
+
+ yyjson_doc_free(doc);
+ free(buf);
+
+ if (parse_sentence_transformers_metadata(cfg, model_dir) != 0)
+ return -1;
+
+ if (cfg->hidden_size <= 0 || cfg->n_layers <= 0 || cfg->n_heads <= 0 || cfg->n_kv_heads <= 0 ||
+ cfg->head_dim <= 0 || cfg->intermediate_size <= 0 || cfg->vocab_size <= 0 ||
+ cfg->q_dim <= 0 || cfg->kv_dim <= 0 || (cfg->head_dim & 1) ||
+ cfg->n_heads % cfg->n_kv_heads != 0 || !isfinite(cfg->rms_norm_eps) ||
+ cfg->rms_norm_eps <= 0.0f || !isfinite(cfg->rope_theta) || cfg->rope_theta <= 0.0f) {
+ fprintf(stderr,
+ "ffwd_config: invalid config in %s "
+ "(hidden=%d, layers=%d, heads=%d/%d, head_dim=%d, inter=%d)\n",
+ path, cfg->hidden_size, cfg->n_layers, cfg->n_heads, cfg->n_kv_heads, cfg->head_dim,
+ cfg->intermediate_size);
+ return -1;
+ }
+ if (cfg->n_layers > FFWD_MAX_LAYERS) {
+ fprintf(stderr, "ffwd_config: too many layers (%d > %d)\n", cfg->n_layers, FFWD_MAX_LAYERS);
+ return -1;
+ }
+
+ if (ffwd_verbose >= 1)
+ fprintf(stderr,
+ "config: hidden=%d, layers=%d, heads=%d/%d, "
+ "inter=%d, head_dim=%d, attention=%s, pooling=%s, qk_norm=%s, qkv_bias=%s\n",
+ cfg->hidden_size, cfg->n_layers, cfg->n_heads, cfg->n_kv_heads,
+ cfg->intermediate_size, cfg->head_dim,
+ cfg->attention_mode == FFWD_ATTENTION_CAUSAL ? "causal" : "bidirectional",
+ cfg->pooling_mode == FFWD_POOL_LAST_TOKEN ? "last-token"
+ : cfg->pooling_mode == FFWD_POOL_CLS ? "cls"
+ : "mean",
+ cfg->qk_norm ? "yes" : "no", cfg->qkv_bias ? "yes" : "no");
+
+ return 0;
+}
diff --git a/libffwd/config.h b/libffwd/config.h
new file mode 100644
index 0000000..b3e2f67
--- /dev/null
+++ b/libffwd/config.h
@@ -0,0 +1,8 @@
+#ifndef FFWD_CONFIG_H
+#define FFWD_CONFIG_H
+
+#include "ffwd.h"
+
+int ffwd_config_parse(ffwd_config_t *cfg, const char *model_dir);
+
+#endif /* FFWD_CONFIG_H */
diff --git a/libffwd/dtype.h b/libffwd/dtype.h
new file mode 100644
index 0000000..7a7a2ad
--- /dev/null
+++ b/libffwd/dtype.h
@@ -0,0 +1,55 @@
+#ifndef FFWD_DTYPE_H
+#define FFWD_DTYPE_H
+
+#include <stdint.h>
+#include <string.h>
+
+/* BF16 is the upper 16 bits of an IEEE-754 binary32, so widening one value is a
+ * left shift reinterpreted as a float. Shared by every host-side caller (the
+ * CPU loader, the safetensors reader); the CUDA backend keeps its own
+ * __nv_bfloat16 device kernels, and kernels.c keeps the SIMD buffer variant
+ * bf16_to_f32_buf for hot, contiguous conversions. */
+static inline float ffwd_bf16_to_f32(uint16_t bf16) {
+ uint32_t bits = (uint32_t)bf16 << 16;
+ float f;
+ memcpy(&f, &bits, sizeof(f));
+ return f;
+}
+
+/* IEEE-754 binary16 -> binary32. Unlike BF16, F16 has a 5-bit exponent and a
+ * 10-bit mantissa, so widening is a field re-pack, not a shift: rebias the
+ * exponent (15 -> 127), shift the mantissa up by 13, and special-case zeros,
+ * subnormals, and inf/NaN. Used by the loaders to accept F16 safetensors
+ * snapshots (e.g. the public multilingual-e5 weights); there is no fused F16
+ * kernel, so weights are widened to F32 once at load. */
+static inline float ffwd_f16_to_f32(uint16_t f16) {
+ uint32_t sign = (uint32_t)(f16 & 0x8000u) << 16;
+ uint32_t exp = (f16 >> 10) & 0x1fu;
+ uint32_t mant = f16 & 0x3ffu;
+ uint32_t bits;
+ if (exp == 0) {
+ if (mant == 0) {
+ bits = sign; /* signed zero */
+ } else {
+ /* Subnormal half: renormalize into a normal float. Shift the
+ * mantissa left until its leading 1 reaches the hidden-bit
+ * position, decrementing the exponent for each shift. */
+ exp = 127 - 15 + 1;
+ while ((mant & 0x400u) == 0) {
+ mant <<= 1;
+ exp--;
+ }
+ mant &= 0x3ffu;
+ bits = sign | (exp << 23) | (mant << 13);
+ }
+ } else if (exp == 0x1fu) {
+ bits = sign | 0x7f800000u | (mant << 13); /* inf or NaN */
+ } else {
+ bits = sign | ((exp + (127 - 15)) << 23) | (mant << 13);
+ }
+ float f;
+ memcpy(&f, &bits, sizeof(f));
+ return f;
+}
+
+#endif /* FFWD_DTYPE_H */
diff --git a/libffwd/ffwd.h b/libffwd/ffwd.h
new file mode 100644
index 0000000..c4708fa
--- /dev/null
+++ b/libffwd/ffwd.h
@@ -0,0 +1,281 @@
+#ifndef FFWD_H
+#define FFWD_H
+
+/* The libraries are built with -fvisibility=hidden, so only declarations carrying
+ * FFWD_API are exported from the shared library; everything else stays internal. */
+#ifndef FFWD_API
+# if defined(__GNUC__)
+# define FFWD_API __attribute__((visibility("default")))
+# else
+# define FFWD_API
+# endif
+#endif
+
+#include <stddef.h>
+#include <stdint.h>
+
+/* Shared constants and defaults */
+
+#define FFWD_VOCAB_SIZE 151936
+#define FFWD_HEAD_DIM 128
+#define FFWD_MAX_LAYERS 64 /* upper bound for stack arrays */
+#define FFWD_CONTEXT_SEPARATOR_TOKEN_ID 151643 /* <|endoftext|> */
+
+/* Late-interaction (ColBERT) fallback special-token ids and query pad length.
+ * Used when the model tokenizer does not define these tokens itself. */
+#define FFWD_LATE_QUERY_TOKENS 32
+#define FFWD_LATE_MASK_TOKEN_ID 151642
+#define FFWD_LATE_QUERY_PREFIX_ID 151669
+#define FFWD_LATE_DOCUMENT_PREFIX_ID 151670
+
+/* Model Configuration (populated from config.json at load time) */
+
+typedef enum {
+ FFWD_ATTENTION_BIDIRECTIONAL = 0,
+ FFWD_ATTENTION_CAUSAL = 1,
+} ffwd_attention_mode_t;
+
+typedef enum {
+ FFWD_POOL_MEAN = 0,
+ FFWD_POOL_LAST_TOKEN = 1,
+ FFWD_POOL_CLS = 2, /* first token; the encoder-family [CLS] sentence vector */
+} ffwd_pooling_mode_t;
+
+typedef enum {
+ FFWD_FAMILY_QWEN3 = 0, /* RMSNorm + RoPE + SwiGLU decoder block (Qwen2/3, pplx-embed) */
+ FFWD_FAMILY_BERT = 1, /* LayerNorm + learned positions + GeLU encoder block */
+} ffwd_family_t;
+
+/* BERT feed-forward activation. The released MiniLM/BGE encoders use exact erf
+ * GeLU; some encoders publish the tanh approximation (hidden_act gelu_new or
+ * gelu_pytorch_tanh), which is a different curve and must be matched exactly. */
+typedef enum {
+ FFWD_ACT_GELU_ERF = 0, /* 0.5 x (1 + erf(x / sqrt(2))) */
+ FFWD_ACT_GELU_TANH = 1, /* 0.5 x (1 + tanh(sqrt(2/pi) (x + 0.044715 x^3))) */
+} ffwd_act_t;
+
+typedef struct {
+ ffwd_family_t family;
+ ffwd_act_t ffn_act; /* BERT feed-forward GeLU variant; ERF for Qwen/SwiGLU */
+ int hidden_size;
+ int n_layers;
+ int n_heads;
+ int n_kv_heads;
+ int head_dim;
+ int q_dim; /* n_heads * head_dim */
+ int kv_dim; /* n_kv_heads * head_dim */
+ int intermediate_size;
+ int vocab_size;
+ int max_position_embeddings; /* BERT learned position table size */
+ int position_id_offset; /* RoBERTa/XLM-R positions start at pad_id + 1 */
+ int type_vocab_size; /* BERT token-type embedding rows; XLM-R uses 1 */
+ float rms_norm_eps;
+ float layer_norm_eps; /* BERT LayerNorm epsilon */
+ float rope_theta;
+ int qk_norm;
+ int qkv_bias;
+ ffwd_attention_mode_t attention_mode;
+ ffwd_pooling_mode_t pooling_mode;
+ int normalize_embeddings;
+ /* Qwen3-Embedding pools the last token: the tokenizer's <|endoftext|> suffix
+ * added by its post-processor, not the model's chat eos_token_id (<|im_end|>).
+ *
+ * Text frontends append it and resolve its id from the tokenizer, just like the
+ * contextual separator. FFWD_CONTEXT_SEPARATOR_TOKEN_ID is the released-model
+ * fallback.
+ *
+ * Model forward consumes token ids exactly and never appends. */
+ int append_terminal_token;
+} ffwd_config_t;
+
+typedef struct {
+ const int *ids;
+ int n_tokens;
+} ffwd_input_t;
+
+typedef struct {
+ int start;
+ int n_tokens;
+} ffwd_span_t;
+
+typedef struct {
+ ffwd_input_t input;
+ const ffwd_span_t *spans;
+ int n_spans;
+} ffwd_context_input_t;
+
+/*
+ * Backend-selected inference handle.
+ *
+ * This is the library's main public interface and the full supported surface of
+ * the shared library. Exactly one backend is linked at build time: CPU, Apple Metal,
+ * or NVIDIA CUDA. That backend implements these functions, so callers never branch
+ * on backend.
+ *
+ * The CLI, server, and language bindings use only these functions plus the math
+ * helpers below.
+ *
+ * Model loading has two phases so a GPU context can be created on the thread
+ * that owns it.
+ *
+ * ffwd_open runs on the caller's thread. It loads a CPU model immediately; in a
+ * GPU build, it only records what to load.
+ *
+ * ffwd_activate runs on the inference thread and creates the GPU context. It is
+ * a no-op for CPU.
+ *
+ * Teardown mirrors activation: ffwd_worker_free releases the GPU context from
+ * the inference thread, and ffwd_free releases the rest.
+ */
+
+/* Opaque inference handle; layout is private to the linked backend. */
+typedef struct embed ffwd_t;
+
+/* Backend tuning, parsed from the command line. A backend reads the fields it
+ * supports and ignores the rest, so the front-ends parse them with no backend
+ * branch. */
+typedef struct {
+ int n_threads; /* CPU worker threads; <= 0 auto-detects */
+ int gpu_quant_bits; /* GPU load-time weight quantization (0 or 8) */
+ int gpu_quant_group_size; /* GPU quantization group size (> 0) */
+ const char *gpu_gemm_mode; /* GPU GEMM compute mode, or NULL */
+ const char *gpu_weight_dtype; /* GPU weight storage dtype, or NULL */
+ double memory_utilization; /* GPU memory budget fraction; 0 = default */
+} ffwd_options_t;
+
+/* One late-interaction rerank: a query and N candidate documents, each given as
+ * token ids plus the kept-token indices. The vector dimension is the loaded
+ * late model's token_dim. */
+typedef struct {
+ const int *query_ids;
+ int query_n_tokens;
+ int query_n_keep;
+ const int *const *doc_ids;
+ const int *doc_n_tokens;
+ const int *const *doc_keep;
+ const int *doc_n_keep;
+ int n_docs;
+} ffwd_rerank_input_t;
+
+/* Apply process-wide settings before any load (CPU thread count, GPU GEMM and
+ * weight settings, GPU option checks) and print the startup banner. Returns -1 and
+ * writes a reason into err on a rejected option value. */
+FFWD_API int ffwd_init(const ffwd_options_t *opts, char *err, size_t errlen);
+
+/* First load phase, on the caller's thread: load a CPU model now, or record what
+ * a GPU build will load in ffwd_activate. is_late selects a late-interaction
+ * model. NULL on failure with a reason in err. */
+FFWD_API ffwd_t *
+ffwd_open(const char *model_dir, int is_late, const ffwd_options_t *opts, char *err, size_t errlen);
+/* Second load phase, on the inference thread: create the GPU context. CPU
+ * no-op. Returns -1 with a reason in err on failure. */
+FFWD_API int ffwd_activate(ffwd_t *e, char *err, size_t errlen);
+/* Release the inference-thread-owned GPU context; CPU no-op. Idempotent. */
+FFWD_API void ffwd_worker_free(ffwd_t *e);
+/* Release CPU state and the handle; call after ffwd_worker_free. */
+FFWD_API void ffwd_free(ffwd_t *e);
+
+/* Available once the model is loaded (after open for CPU, after activate for
+ * GPU); config is NULL until then. */
+FFWD_API const ffwd_config_t *ffwd_config(const ffwd_t *e);
+/* Late projection dimension, or 0 for a standard model. */
+FFWD_API int ffwd_token_dim(const ffwd_t *e);
+/* Whether the backend pads batches to a common length rather than packing them. */
+FFWD_API int ffwd_uses_dense_batches(const ffwd_t *e);
+
+/* Encode a packed batch into out[batch, hidden_size]. Returns 0 on success. */
+FFWD_API int ffwd_encode_batch(ffwd_t *e, const ffwd_input_t *inputs, int batch, float *out);
+/* Encode a contextual document batch, pooling each selected span in order. */
+FFWD_API int
+ffwd_encode_spans_batch(ffwd_t *e, const ffwd_context_input_t *inputs, int batch, float *out);
+/* Score one query against its candidate documents into scores[n_docs]. */
+FFWD_API int ffwd_rerank(ffwd_t *e, const ffwd_rerank_input_t *in, float *scores);
+/* Scratch memory the model currently holds, for diagnostics; 0 on GPU. */
+FFWD_API size_t ffwd_scratch_nbytes(const ffwd_t *e);
+
+/* Accelerator label for --build-info and the startup banner: "Apple Metal",
+ * "NVIDIA CUDA", or "" on a CPU build. A function, not a macro, so a shared
+ * object does not bake in one backend's label and stays correct across a
+ * rebuild. */
+FFWD_API const char *ffwd_capability(void);
+
+/* First-arrival micro-batch wait the backend prefers, in microseconds. */
+FFWD_API int ffwd_default_batch_wait_us(void);
+/* Reject a model set that would not fit host memory (GPU backends); 0 otherwise. On
+ * rejection returns -1 with a reason in err. paths are the model directories. */
+FFWD_API int ffwd_preflight(
+ const char *const *paths, int n_paths, const ffwd_options_t *opts, char *err, size_t errlen);
+
+/*
+ * L2-normalize vec[dim] in place.
+ *
+ * Returns 0 on success. Returns -1 for invalid arguments or a zero-length
+ * vector, which cannot be normalized.
+ */
+FFWD_API int ffwd_l2_normalize(float *vec, int dim);
+
+/*
+ * Cosine similarity between two vectors.
+ * Returns 0 for invalid arguments or if either vector has zero length.
+ */
+FFWD_API float ffwd_cosine_similarity(const float *a, const float *b, int dim);
+
+/*
+ * Tokenization: text -> token ids the model expects.
+ *
+ * Tokenization is backend-independent because text -> ids is the same on CPU
+ * and GPU, so it has its own handle, separate from ffwd_t.
+ *
+ * ffwd_tok_open selects the tokenizer from files in model_dir: WordPiece
+ * vocab.txt, SentencePiece .model, or byte-level vocab.json. It also resolves
+ * the model's special-token ids.
+ *
+ * ffwd_tokenize applies the model's token layout: BERT and XLM-R wrap ids with
+ * [CLS]..[SEP] (<s>..</s>), while Qwen appends its terminal token.
+ */
+
+/* Opaque tokenizer handle; owns the tokenizer and its resolved special tokens. */
+typedef struct ffwd_tok ffwd_tok_t;
+
+/* Late-interaction tokens:
+ * token ids plus the document positions to score.
+ * For queries, keep is NULL because every position is kept, and
+ * n_keep == n_tokens. */
+typedef struct {
+ int *ids;
+ int n_tokens;
+ int *keep;
+ int n_keep;
+} ffwd_late_tokens_t;
+
+/* Load the tokenizer for the model in model_dir and resolve its special-token
+ * ids. is_late additionally resolves the late-interaction [Q]/[D]/[MASK] ids.
+ * NULL on failure with a reason in err. */
+FFWD_API ffwd_tok_t *ffwd_tok_open(const char *model_dir, int is_late, char *err, size_t errlen);
+FFWD_API void ffwd_tok_free(ffwd_tok_t *t);
+
+/* Tokenize text for this model: applies the model's special-token layout and
+ * optionally prepends a query instruction. Returns a malloc'd id array (caller
+ * frees) and sets *n_out. NULL on error. */
+FFWD_API int *ffwd_tokenize(ffwd_tok_t *t, const char *text, const char *query_instruct, int *n_out);
+
+/* Late-interaction tokenization: [Q]/[D] prefix, [MASK]-pad queries to a fixed
+ * length, and mark the document positions to score. Returns 0 on success. */
+FFWD_API int
+ffwd_tokenize_late(ffwd_tok_t *t, const char *text, int is_query, ffwd_late_tokens_t *out);
+FFWD_API void ffwd_late_tokens_free(ffwd_late_tokens_t *out);
+
+/* The contextual chunk-separator id (the tokenizer's <|endoftext|>), for
+ * frontends that split a document into chunks. */
+FFWD_API int ffwd_tok_context_separator_id(const ffwd_tok_t *t);
+
+/* Whether ffwd_tokenize appends the model's terminal token (<|endoftext|>) for
+ * last-token pooling. Off until set; the caller sets it from the loaded model's
+ * config (ffwd_config(...)->append_terminal_token), since it is model-specific
+ * and only known after the backend is open. */
+FFWD_API void ffwd_tok_set_append_terminal(ffwd_tok_t *t, int on);
+
+/* Verbose level: 0=quiet, 1=info, 2=debug */
+FFWD_API extern int ffwd_verbose;
+
+#endif /* FFWD_H */
diff --git a/libffwd/forward.c b/libffwd/forward.c
new file mode 100644
index 0000000..d5d2442
--- /dev/null
+++ b/libffwd/forward.c
@@ -0,0 +1,721 @@
+#include "ffwd.h"
+#include "model_internal.h"
+#include "dtype.h"
+#include "kernels.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <math.h>
+#include <limits.h>
+
+/* For packed sequences below these lengths, fused BF16 row kernels beat
+ * widening the weight to F32 and using BLAS. For longer packed sequences, widen once. */
+#define FFWD_BF16_QKV_FUSE_MAX_SEQ 16
+#define FFWD_BF16_PAIR_FUSE_MAX_SEQ 4
+
+/* Linear projections (weight-dtype dispatch) and workspace scratch growth */
+
+static void bf16_row_to_f32(float *dst, const uint16_t *src, int n) {
+ for (int i = 0; i < n; i++)
+ dst[i] = ffwd_bf16_to_f32(src[i]);
+}
+
+static void copy_weight_row(float *dst, const ffwd_weight_ref_t *w, size_t row, int row_width) {
+ if (w->dtype == DTYPE_F32) {
+ const float *src = (const float *)w->data + row * (size_t)row_width;
+ memcpy(dst, src, (size_t)row_width * sizeof(float));
+ } else {
+ const uint16_t *src = (const uint16_t *)w->data + row * (size_t)row_width;
+ bf16_row_to_f32(dst, src, row_width);
+ }
+}
+
+static int ensure_bf16_widen(ffwd_workspace_t *ws, size_t count) {
+ if (ws->bf16_widen_count >= count)
+ return 0;
+ float *p = (float *)realloc(ws->bf16_widen, count * sizeof(float));
+ if (!p)
+ return -1;
+ ws->bf16_widen = p;
+ ws->bf16_widen_count = count;
+ return 0;
+}
+
+void linear_nobias_weight(ffwd_workspace_t *ws,
+ float *y,
+ const float *x,
+ const ffwd_weight_ref_t *w,
+ int seq_len,
+ int in_dim,
+ int out_dim) {
+ if (w->dtype == DTYPE_F32) {
+ linear_nobias(y, x, (const float *)w->data, seq_len, in_dim, out_dim);
+ return;
+ }
+ if (seq_len > 16) {
+ /* Widen the weight matrix once into workspace scratch and use the
+ * BLAS-backed F32 path; below that the fused BF16 row kernels win. */
+ size_t count = (size_t)out_dim * (size_t)in_dim;
+ if (ensure_bf16_widen(ws, count) == 0) {
+ bf16_to_f32_buf(ws->bf16_widen, (const uint16_t *)w->data, count);
+ linear_nobias(y, x, ws->bf16_widen, seq_len, in_dim, out_dim);
+ return;
+ }
+ }
+ linear_nobias_bf16(y, x, (const uint16_t *)w->data, seq_len, in_dim, out_dim);
+}
+
+static void linear_qkv_weight(ffwd_workspace_t *ws,
+ float *q,
+ float *k,
+ float *v,
+ const float *x,
+ const ffwd_weight_ref_t *wq,
+ const ffwd_weight_ref_t *wk,
+ const ffwd_weight_ref_t *wv,
+ int seq_len,
+ int in_dim,
+ int q_dim,
+ int kv_dim) {
+ if (wq->dtype == DTYPE_BF16 && wk->dtype == DTYPE_BF16 && wv->dtype == DTYPE_BF16 &&
+ seq_len <= FFWD_BF16_QKV_FUSE_MAX_SEQ) {
+ linear_nobias_bf16_qkv(q, k, v, x, (const uint16_t *)wq->data, (const uint16_t *)wk->data,
+ (const uint16_t *)wv->data, seq_len, in_dim, q_dim, kv_dim);
+ return;
+ }
+
+ linear_nobias_weight(ws, q, x, wq, seq_len, in_dim, q_dim);
+ linear_nobias_weight(ws, k, x, wk, seq_len, in_dim, kv_dim);
+ linear_nobias_weight(ws, v, x, wv, seq_len, in_dim, kv_dim);
+}
+
+static void add_bias_rows(float *x, const float *bias, int rows, int dim) {
+ if (!bias)
+ return;
+ for (int row = 0; row < rows; row++) {
+ float *dst = x + (size_t)row * dim;
+ for (int d = 0; d < dim; d++)
+ dst[d] += bias[d];
+ }
+}
+
+static void linear_pair_weight(ffwd_workspace_t *ws,
+ float *a,
+ float *b,
+ const float *x,
+ const ffwd_weight_ref_t *wa,
+ const ffwd_weight_ref_t *wb,
+ int seq_len,
+ int in_dim,
+ int a_dim,
+ int b_dim) {
+ if (wa->dtype == DTYPE_BF16 && wb->dtype == DTYPE_BF16 &&
+ seq_len <= FFWD_BF16_PAIR_FUSE_MAX_SEQ) {
+ linear_nobias_bf16_pair(a, b, x, (const uint16_t *)wa->data, (const uint16_t *)wb->data,
+ seq_len, in_dim, a_dim, b_dim);
+ return;
+ }
+
+ linear_nobias_weight(ws, a, x, wa, seq_len, in_dim, a_dim);
+ linear_nobias_weight(ws, b, x, wb, seq_len, in_dim, b_dim);
+}
+
+/* Packed forward pass.
+ *
+ * Workspace-growth helpers called here live in model_blas.c beside the
+ * workspace lifecycle and ffwd_workspace_nbytes:
+ * ensure_buffers, ensure_rope_cache, ensure_attention_scores, ensure_offsets.
+ *
+ * ffwd_workspace_nbytes mirrors their size accounting.
+ */
+
+static ffwd_attention_fn attention_for_config(const ffwd_config_t *cfg) {
+ return cfg->attention_mode == FFWD_ATTENTION_CAUSAL
+ ? causal_gqa_attention_packed_with_scratch
+ : bidirectional_gqa_attention_packed_with_scratch;
+}
+
+int build_offsets(const ffwd_input_t *inputs,
+ int batch,
+ int require_ids,
+ int *offsets,
+ int *total_out,
+ int *max_out) {
+ if (!inputs || batch <= 0 || !offsets || !total_out || !max_out)
+ return -1;
+
+ int total = 0;
+ int max_seq = 0;
+ for (int b = 0; b < batch; b++) {
+ if ((require_ids && !inputs[b].ids) || inputs[b].n_tokens <= 0)
+ return -1;
+ if (total > INT32_MAX - inputs[b].n_tokens)
+ return -1;
+ offsets[b] = total;
+ total += inputs[b].n_tokens;
+ if (inputs[b].n_tokens > max_seq)
+ max_seq = inputs[b].n_tokens;
+ }
+ offsets[batch] = total;
+ *total_out = total;
+ *max_out = max_seq;
+ return 0;
+}
+
+static int forward_packed_slice_inplace(const ffwd_model_t *model,
+ ffwd_workspace_t *ws,
+ const ffwd_input_t *inputs,
+ int batch,
+ const int *offsets,
+ int total_seq,
+ int max_seq,
+ const float *input_states,
+ int layer_start,
+ int layer_end,
+ int apply_final_norm) {
+ if (!model || !ws || ws->model != model || !inputs || batch <= 0 || !offsets || total_seq <= 0 ||
+ max_seq <= 0)
+ return -1;
+
+ const ffwd_config_t *cfg = &model->config;
+ const ffwd_weights_t *w = &model->weights;
+ if (layer_start < 0 || layer_start > layer_end || layer_end > cfg->n_layers ||
+ layer_start < model->layer_start || layer_end > model->layer_end ||
+ (layer_start == 0 && input_states) || (layer_start != 0 && !input_states) ||
+ (layer_start == 0 && !w->embed_tokens.data) ||
+ (apply_final_norm && (layer_end != cfg->n_layers || !w->norm)))
+ return -1;
+
+ int hidden = cfg->hidden_size;
+ int n_heads = cfg->n_heads;
+ int n_kv_heads = cfg->n_kv_heads;
+ int head_dim = cfg->head_dim;
+ int q_dim = cfg->q_dim;
+ int kv_dim = cfg->kv_dim;
+ int inter = cfg->intermediate_size;
+ float eps = cfg->rms_norm_eps;
+
+ if (ensure_buffers(ws, cfg, total_seq) != 0)
+ return -1;
+ if (ensure_rope_cache(ws, cfg, max_seq) != 0)
+ return -1;
+ ensure_attention_scores(ws, offsets, batch);
+
+ const float *rope_cos = ws->rope_cos;
+ const float *rope_sin = ws->rope_sin;
+
+ float *x = ws->x;
+ float *x_norm = ws->x_norm;
+ float *q_buf = ws->q;
+ float *k_buf = ws->k;
+ float *v_buf = ws->v;
+ float *attn_out = ws->attn_out;
+ float *proj_out = ws->proj_out;
+ float *ffn_gate = ws->ffn_gate;
+ float *ffn_up = ws->ffn_up;
+
+ /* A first stage performs embedding lookup. Later stages resume from a
+ * packed hidden-state tensor received from the preceding stage. */
+ if (layer_start == 0) {
+ for (int b = 0; b < batch; b++) {
+ int start = offsets[b];
+ for (int i = 0; i < inputs[b].n_tokens; i++) {
+ int id = inputs[b].ids[i];
+ if (id < 0 || id >= cfg->vocab_size) {
+ fprintf(stderr, "ffwd: invalid token id %d at input %d position %d\n", id, b, i);
+ return -1;
+ }
+ copy_weight_row(x + (size_t)(start + i) * hidden, &w->embed_tokens, (size_t)id,
+ hidden);
+ }
+ }
+ } else {
+ memcpy(x, input_states, (size_t)total_seq * hidden * sizeof(float));
+ }
+
+ float scale = 1.0f / sqrtf((float)head_dim);
+
+ /* 2. Transformer layers. Linear/MLP ops run over all packed tokens;
+ * attention is explicitly block-diagonal by sequence offsets. */
+ for (int layer = layer_start; layer < layer_end; layer++) {
+ const ffwd_layer_t *l = &w->layers[layer];
+
+ rms_norm(x_norm, x, l->input_norm, total_seq, hidden, eps);
+
+ linear_qkv_weight(ws, q_buf, k_buf, v_buf, x_norm, &l->wq, &l->wk, &l->wv, total_seq, hidden,
+ q_dim, kv_dim);
+
+ add_bias_rows(q_buf, l->q_bias, total_seq, q_dim);
+ add_bias_rows(k_buf, l->k_bias, total_seq, kv_dim);
+ add_bias_rows(v_buf, l->v_bias, total_seq, kv_dim);
+ if (cfg->qk_norm) {
+ rms_norm_per_head(q_buf, l->q_norm, total_seq, n_heads, head_dim, eps);
+ rms_norm_per_head(k_buf, l->k_norm, total_seq, n_kv_heads, head_dim, eps);
+ }
+
+ for (int b = 0; b < batch; b++) {
+ int start = offsets[b];
+ int len = offsets[b + 1] - start;
+ apply_rope_neox(q_buf + (size_t)start * q_dim, rope_cos, rope_sin, len, n_heads,
+ head_dim);
+ apply_rope_neox(k_buf + (size_t)start * kv_dim, rope_cos, rope_sin, len, n_kv_heads,
+ head_dim);
+ }
+
+ ffwd_attention_fn attention = attention_for_config(cfg);
+ attention(attn_out, q_buf, k_buf, v_buf, offsets, batch, n_heads, n_kv_heads, head_dim, scale,
+ ws->attn_scores, ws->attn_scores_bytes);
+
+ linear_nobias_weight(ws, proj_out, attn_out, &l->wo, total_seq, q_dim, hidden);
+ add_inplace(x, proj_out, total_seq * hidden);
+
+ rms_norm(x_norm, x, l->post_attn_norm, total_seq, hidden, eps);
+
+ linear_pair_weight(ws, ffn_gate, ffn_up, x_norm, &l->gate_proj, &l->up_proj, total_seq,
+ hidden, inter, inter);
+ silu_mul_inplace(ffn_gate, ffn_up, total_seq * inter);
+ linear_nobias_weight(ws, proj_out, ffn_gate, &l->down_proj, total_seq, inter, hidden);
+ add_inplace(x, proj_out, total_seq * hidden);
+ }
+
+ if (apply_final_norm)
+ rms_norm(x, x, w->norm, total_seq, hidden, eps);
+ return 0;
+}
+
+int forward_packed_inplace(const ffwd_model_t *model,
+ ffwd_workspace_t *ws,
+ const ffwd_input_t *inputs,
+ int batch,
+ const int *offsets,
+ int total_seq,
+ int max_seq,
+ int apply_final_norm) {
+ return forward_packed_slice_inplace(model, ws, inputs, batch, offsets, total_seq, max_seq, NULL,
+ 0, model->config.n_layers, apply_final_norm);
+}
+
+/* BERT-family forward pass.
+ *
+ * Uses token, learned-position, and token-type embeddings, then embedding
+ * LayerNorm.
+ *
+ * Encoder layers are post-norm, with bias on every projection, GeLU
+ * feed-forward, no RoPE, and no per-head norm.
+ *
+ * Bidirectional attention is block-diagonal over the packed batch. Each
+ * sequence's positions restart at cfg->position_id_offset: 0 for BERT, or
+ * pad_id + 1 for RoBERTa/XLM-R.
+ *
+ * Leaves final hidden states in ws->x. Pooling reads them as-is because the last
+ * layer's LayerNorm is already the model's final normalization.
+ */
+static int forward_packed_bert(const ffwd_model_t *model,
+ ffwd_workspace_t *ws,
+ const ffwd_input_t *inputs,
+ int batch,
+ const int *offsets,
+ int total_seq,
+ int max_seq) {
+ if (!model || !ws || ws->model != model || !inputs || batch <= 0 || !offsets || total_seq <= 0 ||
+ max_seq <= 0)
+ return -1;
+
+ const ffwd_config_t *cfg = &model->config;
+ const ffwd_weights_t *w = &model->weights;
+ int hidden = cfg->hidden_size;
+ int n_heads = cfg->n_heads;
+ int head_dim = cfg->head_dim;
+ int inter = cfg->intermediate_size;
+ float eps = cfg->layer_norm_eps;
+
+ if (!w->embed_tokens.data || !w->position_embeddings || !w->token_type_embeddings ||
+ !w->ffwd_ln_w || !w->ffwd_ln_b)
+ return -1;
+ if (max_seq > cfg->max_position_embeddings - cfg->position_id_offset) {
+ fprintf(stderr,
+ "ffwd: sequence length %d plus position offset %d exceeds max_position_embeddings "
+ "%d\n",
+ max_seq, cfg->position_id_offset, cfg->max_position_embeddings);
+ return -1;
+ }
+ if (ensure_buffers(ws, cfg, total_seq) != 0)
+ return -1;
+ ensure_attention_scores(ws, offsets, batch);
+
+ float *x = ws->x;
+ float *q_buf = ws->q, *k_buf = ws->k, *v_buf = ws->v;
+ float *attn_out = ws->attn_out, *proj_out = ws->proj_out, *ffn_up = ws->ffn_up;
+
+ /* Embeddings: token + learned absolute position + token-type[0], then the
+ * embedding LayerNorm over every packed token. */
+ for (int b = 0; b < batch; b++) {
+ int start = offsets[b];
+ for (int i = 0; i < inputs[b].n_tokens; i++) {
+ int id = inputs[b].ids[i];
+ if (id < 0 || id >= cfg->vocab_size) {
+ fprintf(stderr, "ffwd: invalid token id %d at input %d position %d\n", id, b, i);
+ return -1;
+ }
+ float *row = x + (size_t)(start + i) * hidden;
+ copy_weight_row(row, &w->embed_tokens, (size_t)id, hidden);
+ int pos = cfg->position_id_offset + i;
+ add_inplace(row, w->position_embeddings + (size_t)pos * hidden, hidden);
+ add_inplace(row, w->token_type_embeddings, hidden);
+ }
+ }
+ layer_norm(x, x, w->ffwd_ln_w, w->ffwd_ln_b, total_seq, hidden, eps);
+
+ float scale = 1.0f / sqrtf((float)head_dim);
+
+ for (int layer = 0; layer < cfg->n_layers; layer++) {
+ const ffwd_layer_t *l = &w->layers[layer];
+
+ /* Self-attention (post-norm): projections read x directly. */
+ linear_qkv_weight(ws, q_buf, k_buf, v_buf, x, &l->wq, &l->wk, &l->wv, total_seq, hidden,
+ hidden, hidden);
+ add_bias_rows(q_buf, l->q_bias, total_seq, hidden);
+ add_bias_rows(k_buf, l->k_bias, total_seq, hidden);
+ add_bias_rows(v_buf, l->v_bias, total_seq, hidden);
+
+ ffwd_attention_fn attention = attention_for_config(cfg);
+ attention(attn_out, q_buf, k_buf, v_buf, offsets, batch, n_heads, n_heads, head_dim, scale,
+ ws->attn_scores, ws->attn_scores_bytes);
+
+ linear_nobias_weight(ws, proj_out, attn_out, &l->wo, total_seq, hidden, hidden);
+ add_bias_rows(proj_out, l->o_bias, total_seq, hidden);
+ add_inplace(x, proj_out, total_seq * hidden);
+ layer_norm(x, x, l->input_norm, l->attn_ln_bias, total_seq, hidden, eps);
+
+ /* Feed-forward (post-norm): dense -> GeLU -> dense. */
+ linear_nobias_weight(ws, ffn_up, x, &l->up_proj, total_seq, hidden, inter);
+ add_bias_rows(ffn_up, l->ffn_inter_bias, total_seq, inter);
+ if (cfg->ffn_act == FFWD_ACT_GELU_TANH)
+ gelu_tanh_inplace(ffn_up, total_seq * inter);
+ else
+ gelu_inplace(ffn_up, total_seq * inter);
+ linear_nobias_weight(ws, proj_out, ffn_up, &l->down_proj, total_seq, inter, hidden);
+ add_bias_rows(proj_out, l->ffn_out_bias, total_seq, hidden);
+ add_inplace(x, proj_out, total_seq * hidden);
+ layer_norm(x, x, l->post_attn_norm, l->ffn_ln_bias, total_seq, hidden, eps);
+ }
+ return 0;
+}
+
+static int pool_embeddings(const ffwd_model_t *model,
+ const ffwd_workspace_t *ws,
+ const int *offsets,
+ int batch,
+ float *out_embeddings) {
+ const ffwd_config_t *cfg = &model->config;
+ int hidden = cfg->hidden_size;
+ float eps = cfg->rms_norm_eps;
+ /* Qwen pools pre-final-norm states, then applies final RMSNorm here.
+ * BERT pools already-normalized states, so a NULL norm means no final norm. */
+ const float *norm_weight = model->weights.norm;
+ const float *x = ws->x;
+ if (hidden <= 0 || !x)
+ return -1;
+
+ for (int b = 0; b < batch; b++) {
+ int start = offsets[b];
+ int end = offsets[b + 1];
+ int len = end - start;
+ float *emb = out_embeddings + (size_t)b * hidden;
+
+ if (cfg->pooling_mode == FFWD_POOL_LAST_TOKEN || cfg->pooling_mode == FFWD_POOL_CLS) {
+ /* Single-token pooling: CLS uses the first token; last-token uses the final token. */
+ int idx = cfg->pooling_mode == FFWD_POOL_CLS ? start : end - 1;
+ const float *row = x + (size_t)idx * hidden;
+ if (norm_weight) {
+ float sum_sq = 0.0f;
+ for (int d = 0; d < hidden; d++)
+ sum_sq += row[d] * row[d];
+ float rms_inv = 1.0f / sqrtf(sum_sq / (float)hidden + eps);
+ for (int d = 0; d < hidden; d++)
+ emb[d] = row[d] * rms_inv * norm_weight[d];
+ } else {
+ memcpy(emb, row, (size_t)hidden * sizeof(float));
+ }
+ } else {
+ memset(emb, 0, (size_t)hidden * sizeof(float));
+ for (int i = start; i < end; i++) {
+ const float *row = x + (size_t)i * hidden;
+ if (norm_weight) {
+ float sum_sq = 0.0f;
+ for (int d = 0; d < hidden; d++)
+ sum_sq += row[d] * row[d];
+ float rms_inv = 1.0f / sqrtf(sum_sq / (float)hidden + eps);
+ for (int d = 0; d < hidden; d++)
+ emb[d] += row[d] * rms_inv * norm_weight[d];
+ } else {
+ for (int d = 0; d < hidden; d++)
+ emb[d] += row[d];
+ }
+ }
+ float inv_len = 1.0f / (float)len;
+ for (int d = 0; d < hidden; d++)
+ emb[d] *= inv_len;
+ }
+
+ if (cfg->normalize_embeddings && ffwd_l2_normalize(emb, hidden) != 0)
+ return -1;
+ }
+ return 0;
+}
+
+/* Forward/embed APIs */
+
+int ffwd_model_forward_into(const ffwd_model_t *model,
+ ffwd_workspace_t *ws,
+ const int *token_ids,
+ int n_tokens,
+ float *out_states) {
+ if (!model || !ws || !token_ids || n_tokens <= 0 || !out_states)
+ return -1;
+
+ size_t count, bytes;
+ if (mul_size((size_t)n_tokens, (size_t)model->config.hidden_size, &count) != 0 ||
+ mul_size(count, sizeof(float), &bytes) != 0)
+ return -1;
+
+ ffwd_input_t input = {token_ids, n_tokens};
+ int offsets[2] = {0, n_tokens};
+ if (forward_packed_inplace(model, ws, &input, 1, offsets, n_tokens, n_tokens, 1) != 0)
+ return -1;
+
+ memcpy(out_states, ws->x, bytes);
+ return 0;
+}
+
+int ffwd_pool_spans(const ffwd_config_t *cfg,
+ const float *states,
+ int n_tokens,
+ const ffwd_span_t *spans,
+ int n_spans,
+ float *out_embeddings) {
+ if (!cfg || !states || n_tokens <= 0 || !spans || n_spans <= 0 || !out_embeddings)
+ return -1;
+
+ int hidden = cfg->hidden_size;
+ if (hidden <= 0)
+ return -1;
+
+ for (int s = 0; s < n_spans; s++) {
+ int start = spans[s].start;
+ int len = spans[s].n_tokens;
+ if (start < 0 || len <= 0 || start > n_tokens || len > n_tokens - start)
+ return -1;
+
+ float *emb = out_embeddings + (size_t)s * hidden;
+ memset(emb, 0, (size_t)hidden * sizeof(float));
+
+ for (int t = 0; t < len; t++) {
+ const float *row = states + (size_t)(start + t) * hidden;
+ for (int d = 0; d < hidden; d++)
+ emb[d] += row[d];
+ }
+
+ float inv_len = 1.0f / (float)len;
+ for (int d = 0; d < hidden; d++) {
+ emb[d] *= inv_len;
+ }
+ }
+ return 0;
+}
+
+int ffwd_model_encode_spans_batch(const ffwd_model_t *model,
+ ffwd_workspace_t *ws,
+ const ffwd_context_input_t *inputs,
+ int batch,
+ float *out_embeddings) {
+ if (!model || !ws || !inputs || batch <= 0 || !out_embeddings)
+ return -1;
+
+ if (ensure_offsets(ws, batch) != 0)
+ return -1;
+ if ((size_t)batch > SIZE_MAX / sizeof(ffwd_input_t))
+ return -1;
+ ffwd_input_t *packed_inputs = malloc((size_t)batch * sizeof(*packed_inputs));
+ if (!packed_inputs)
+ return -1;
+ int *offsets = ws->offsets;
+ int total_seq = 0;
+ int max_seq = 0;
+ int total_spans = 0;
+ for (int b = 0; b < batch; b++) {
+ const ffwd_context_input_t *input = &inputs[b];
+ int n_tokens = input->input.n_tokens;
+ if (!input->input.ids || n_tokens <= 0 || !input->spans || input->n_spans <= 0 ||
+ total_seq > INT_MAX - n_tokens || total_spans > INT_MAX - input->n_spans) {
+ free(packed_inputs);
+ return -1;
+ }
+ packed_inputs[b] = input->input;
+ offsets[b] = total_seq;
+ total_seq += n_tokens;
+ total_spans += input->n_spans;
+ if (n_tokens > max_seq)
+ max_seq = n_tokens;
+ for (int s = 0; s < input->n_spans; s++) {
+ int start = input->spans[s].start;
+ int len = input->spans[s].n_tokens;
+ if (start < 0 || len <= 0 || start > n_tokens || len > n_tokens - start) {
+ free(packed_inputs);
+ return -1;
+ }
+ }
+ }
+ offsets[batch] = total_seq;
+
+ if (forward_packed_inplace(model, ws, packed_inputs, batch, offsets, total_seq, max_seq, 1) !=
+ 0) {
+ free(packed_inputs);
+ return -1;
+ }
+ free(packed_inputs);
+
+ int span_offset = 0;
+ int hidden = model->config.hidden_size;
+ for (int b = 0; b < batch; b++) {
+ const ffwd_context_input_t *input = &inputs[b];
+ if (ffwd_pool_spans(&model->config, ws->x + (size_t)offsets[b] * hidden,
+ input->input.n_tokens, input->spans, input->n_spans,
+ out_embeddings + (size_t)span_offset * hidden) != 0)
+ return -1;
+ span_offset += input->n_spans;
+ }
+ return 0;
+}
+
+int ffwd_model_encode_spans(const ffwd_model_t *model,
+ ffwd_workspace_t *ws,
+ const int *token_ids,
+ int n_tokens,
+ const ffwd_span_t *spans,
+ int n_spans,
+ float *out_embeddings) {
+ ffwd_context_input_t input = {
+ .input = {token_ids, n_tokens},
+ .spans = spans,
+ .n_spans = n_spans,
+ };
+ return ffwd_model_encode_spans_batch(model, ws, &input, 1, out_embeddings);
+}
+
+float *ffwd_model_forward(const ffwd_model_t *model,
+ ffwd_workspace_t *ws,
+ const int *token_ids,
+ int n_tokens) {
+ if (!model || !ws || !token_ids || n_tokens <= 0)
+ return NULL;
+
+ size_t n;
+ if (mul_size((size_t)n_tokens, (size_t)model->config.hidden_size, &n) != 0)
+ return NULL;
+ float *out = malloc_floats(n);
+ if (!out)
+ return NULL;
+
+ if (ffwd_model_forward_into(model, ws, token_ids, n_tokens, out) != 0) {
+ free(out);
+ return NULL;
+ }
+ return out;
+}
+
+int ffwd_model_encode_batch(const ffwd_model_t *model,
+ ffwd_workspace_t *ws,
+ const ffwd_input_t *inputs,
+ int batch,
+ float *out_embeddings) {
+ if (!model || !ws || !inputs || batch <= 0 || !out_embeddings)
+ return -1;
+
+ if (ensure_offsets(ws, batch) != 0)
+ return -1;
+ int *offsets = ws->offsets;
+
+ int total_seq = 0;
+ int max_seq = 0;
+ if (build_offsets(inputs, batch, 1, offsets, &total_seq, &max_seq) != 0)
+ return -1;
+
+ int rc = model->config.family == FFWD_FAMILY_BERT
+ ? forward_packed_bert(model, ws, inputs, batch, offsets, total_seq, max_seq)
+ : forward_packed_inplace(model, ws, inputs, batch, offsets, total_seq, max_seq, 0);
+ if (rc == 0)
+ rc = pool_embeddings(model, ws, offsets, batch, out_embeddings);
+
+ return rc;
+}
+
+int ffwd_pool_batch(const ffwd_config_t *cfg,
+ const float *states,
+ const int *seq_lengths,
+ int batch,
+ float *out_embeddings) {
+ if (!cfg || !states || !seq_lengths || batch <= 0 || !out_embeddings || cfg->hidden_size <= 0)
+ return -1;
+
+ int offset = 0;
+ for (int b = 0; b < batch; b++) {
+ int len = seq_lengths[b];
+ if (len <= 0 || offset > INT_MAX - len)
+ return -1;
+
+ float *emb = out_embeddings + (size_t)b * cfg->hidden_size;
+ if (cfg->pooling_mode == FFWD_POOL_LAST_TOKEN || cfg->pooling_mode == FFWD_POOL_CLS) {
+ /* CLS takes the first token, last-token the final one; these states
+ * already carry the model's final RMSNorm. */
+ int idx = cfg->pooling_mode == FFWD_POOL_CLS ? offset : offset + len - 1;
+ const float *row = states + (size_t)idx * cfg->hidden_size;
+ memcpy(emb, row, (size_t)cfg->hidden_size * sizeof(float));
+ } else {
+ memset(emb, 0, (size_t)cfg->hidden_size * sizeof(float));
+ for (int t = 0; t < len; t++) {
+ const float *row = states + (size_t)(offset + t) * cfg->hidden_size;
+ for (int d = 0; d < cfg->hidden_size; d++)
+ emb[d] += row[d];
+ }
+ float inv_len = 1.0f / (float)len;
+ for (int d = 0; d < cfg->hidden_size; d++)
+ emb[d] *= inv_len;
+ }
+ if (cfg->normalize_embeddings && ffwd_l2_normalize(emb, cfg->hidden_size) != 0)
+ return -1;
+ offset += len;
+ }
+ return 0;
+}
+
+int ffwd_model_encode_into(const ffwd_model_t *model,
+ ffwd_workspace_t *ws,
+ const int *token_ids,
+ int n_tokens,
+ float *out_embedding) {
+ ffwd_input_t input = {token_ids, n_tokens};
+ return ffwd_model_encode_batch(model, ws, &input, 1, out_embedding);
+}
+
+float *ffwd_model_encode(const ffwd_model_t *model,
+ ffwd_workspace_t *ws,
+ const int *token_ids,
+ int n_tokens) {
+ if (!model || !ws || !token_ids || n_tokens <= 0)
+ return NULL;
+
+ int hidden = model->config.hidden_size;
+ if (hidden <= 0)
+ return NULL;
+ float *emb = malloc_floats((size_t)hidden);
+ if (!emb)
+ return NULL;
+
+ if (ffwd_model_encode_into(model, ws, token_ids, n_tokens, emb) != 0) {
+ free(emb);
+ return NULL;
+ }
+ return emb;
+}
diff --git a/libffwd/gemm.c b/libffwd/gemm.c
new file mode 100644
index 0000000..ab664f1
--- /dev/null
+++ b/libffwd/gemm.c
@@ -0,0 +1,429 @@
+/*
+ * General matrix multiplication.
+ */
+
+#include "kernels.h"
+#include "impl.h"
+#include "threadpool.h"
+
+#include <math.h>
+#include <stdlib.h>
+#include <string.h>
+
+#if (defined(__AVX512F__) || defined(__AVX2__)) && \
+ (defined(__x86_64__) || defined(__i386__) || defined(_M_X64) || defined(_M_IX86))
+# include <immintrin.h>
+#endif
+#if defined(__ARM_NEON) || defined(__ARM_NEON__)
+# include <arm_neon.h>
+#endif
+
+#ifdef USE_BLAS
+# ifdef __APPLE__
+# include <Accelerate/Accelerate.h>
+# else
+# include <cblas.h>
+# endif
+#endif
+
+#ifndef M_PI
+# define M_PI 3.14159265358979323846
+#endif
+
+/* Matrix and vector ops:
+ * GEMM, dtype-dispatch linear kernels, BF16-fused matvec/QKV/pair workers,
+ * and element-wise residual add. */
+
+/* Basic element-wise operations */
+
+void add_inplace(float *a, const float *b, int n) {
+ for (int i = 0; i < n; i++)
+ a[i] += b[i];
+}
+
+/* Matrix operations */
+
+void matmul_t(float *C, const float *A, const float *B, int M, int K, int N) {
+#ifdef USE_BLAS
+ cblas_sgemm(CblasRowMajor, CblasNoTrans, CblasTrans, M, N, K, 1.0f, A, K, B, K, 0.0f, C, N);
+#else
+ for (int m = 0; m < M; m++) {
+ for (int n = 0; n < N; n++) {
+ float sum = 0.0f;
+ for (int k = 0; k < K; k++) {
+ sum += A[m * K + k] * B[n * K + k];
+ }
+ C[m * N + n] = sum;
+ }
+ }
+#endif
+}
+
+void linear(
+ float *y, const float *x, const float *W, const float *b, int seq_len, int in_dim, int out_dim) {
+#ifdef USE_BLAS
+ if (seq_len == 1) {
+ cblas_sgemv(CblasRowMajor, CblasNoTrans, out_dim, in_dim, 1.0f, W, in_dim, x, 1, 0.0f, y, 1);
+ } else {
+ cblas_sgemm(CblasRowMajor, CblasNoTrans, CblasTrans, seq_len, out_dim, in_dim, 1.0f, x,
+ in_dim, W, in_dim, 0.0f, y, out_dim);
+ }
+ if (b != NULL) {
+ for (int s = 0; s < seq_len; s++) {
+ for (int o = 0; o < out_dim; o++) {
+ y[s * out_dim + o] += b[o];
+ }
+ }
+ }
+#else
+ for (int s = 0; s < seq_len; s++) {
+ const float *x_row = x + s * in_dim;
+ float *y_row = y + s * out_dim;
+ for (int o = 0; o < out_dim; o++) {
+ const float *w_row = W + o * in_dim;
+ float sum = (b != NULL) ? b[o] : 0.0f;
+ for (int i = 0; i < in_dim; i++) {
+ sum += x_row[i] * w_row[i];
+ }
+ y_row[o] = sum;
+ }
+ }
+#endif
+}
+
+void linear_nobias(float *y, const float *x, const float *W, int seq_len, int in_dim, int out_dim) {
+ linear(y, x, W, NULL, seq_len, in_dim, out_dim);
+}
+
+/* Convert bf16 buffer to f32 buffer */
+void bf16_to_f32_buf(float *dst, const uint16_t *src, size_t n) {
+#if defined(__ARM_NEON) || defined(__ARM_NEON__)
+ size_t i = 0;
+ uint32_t *d = (uint32_t *)(void *)dst;
+ for (; i + 8 <= n; i += 8) {
+ uint16x8_t v = vld1q_u16(src + i);
+ uint32x4_t lo = vshlq_n_u32(vmovl_u16(vget_low_u16(v)), 16);
+ uint32x4_t hi = vshlq_n_u32(vmovl_u16(vget_high_u16(v)), 16);
+ vst1q_u32(d + i, lo);
+ vst1q_u32(d + i + 4, hi);
+ }
+ for (; i < n; i++)
+ d[i] = ((uint32_t)src[i]) << 16;
+#else
+ uint32_t *d = (uint32_t *)(void *)dst;
+ for (size_t i = 0; i < n; i++)
+ d[i] = ((uint32_t)src[i]) << 16;
+#endif
+}
+
+/*
+ * Fused BF16 matvec: y[out_dim] = W_bf16[out_dim, in_dim] @ x[in_dim] + bias
+ * Processes 2 output rows at a time to amortize x vector loads.
+ */
+static void bf16_matvec_fused(
+ float *y, const float *x, const uint16_t *W_bf16, const float *bias, int in_dim, int out_dim) {
+ bf16_matvec_fused_impl(y, x, W_bf16, bias, in_dim, out_dim);
+}
+
+/* Threaded matvec: split output rows across threads */
+typedef struct {
+ float *y;
+ const float *x;
+ const uint16_t *W_bf16;
+ const float *bias;
+ int in_dim;
+ int out_dim;
+} matvec_task_t;
+
+static void matvec_worker(int tid, int n_threads, void *arg) {
+ matvec_task_t *t = (matvec_task_t *)arg;
+ int chunk = (t->out_dim + n_threads - 1) / n_threads;
+ int start = tid * chunk;
+ int end = start + chunk;
+ if (end > t->out_dim)
+ end = t->out_dim;
+ if (start >= end)
+ return;
+
+ bf16_matvec_fused(t->y + start, t->x, t->W_bf16 + (size_t)start * t->in_dim,
+ t->bias ? t->bias + start : NULL, t->in_dim, end - start);
+}
+
+static void bf16_matvec_threaded(
+ float *y, const float *x, const uint16_t *W_bf16, const float *bias, int in_dim, int out_dim) {
+ if (tp_num_threads() <= 1) {
+ bf16_matvec_fused(y, x, W_bf16, bias, in_dim, out_dim);
+ return;
+ }
+ matvec_task_t task = {y, x, W_bf16, bias, in_dim, out_dim};
+ parallel_for(matvec_worker, &task);
+}
+
+typedef struct {
+ float *y;
+ const float *x;
+ const uint16_t *W_bf16;
+ const float *bias;
+ int seq_len;
+ int in_dim;
+ int out_dim;
+} bf16_linear_rows_task_t;
+
+static void bf16_linear_rows_worker(int tid, int n_threads, void *arg) {
+ bf16_linear_rows_task_t *t = (bf16_linear_rows_task_t *)arg;
+ int chunk = (t->seq_len + n_threads - 1) / n_threads;
+ int start = tid * chunk;
+ int end = start + chunk;
+ if (end > t->seq_len)
+ end = t->seq_len;
+ if (start >= end)
+ return;
+
+ for (int s = start; s < end; s++) {
+ bf16_matvec_fused(t->y + (size_t)s * t->out_dim, t->x + (size_t)s * t->in_dim, t->W_bf16,
+ t->bias, t->in_dim, t->out_dim);
+ }
+}
+
+static void bf16_linear_rows(float *y,
+ const float *x,
+ const uint16_t *W_bf16,
+ const float *bias,
+ int seq_len,
+ int in_dim,
+ int out_dim) {
+ bf16_linear_rows_task_t task = {
+ .y = y,
+ .x = x,
+ .W_bf16 = W_bf16,
+ .bias = bias,
+ .seq_len = seq_len,
+ .in_dim = in_dim,
+ .out_dim = out_dim,
+ };
+
+ if (tp_num_threads() > 1 && seq_len >= 2)
+ parallel_for(bf16_linear_rows_worker, &task);
+ else
+ bf16_linear_rows_worker(0, 1, &task);
+}
+
+typedef struct {
+ float *a;
+ float *b;
+ const float *x;
+ const uint16_t *Wa_bf16;
+ const uint16_t *Wb_bf16;
+ int seq_len;
+ int in_dim;
+ int a_dim;
+ int b_dim;
+ int total_dim;
+} pair_matvec_task_t;
+
+static void pair_matvec_range(const pair_matvec_task_t *t, int row, int start, int end) {
+ const float *x_row = t->x + (size_t)row * t->in_dim;
+ int a_end = t->a_dim;
+ int b_end = a_end + t->b_dim;
+
+ if (start < a_end) {
+ int s = start;
+ int e = end < a_end ? end : a_end;
+ if (s < e) {
+ bf16_matvec_fused(t->a + (size_t)row * t->a_dim + s, x_row,
+ t->Wa_bf16 + (size_t)s * t->in_dim, NULL, t->in_dim, e - s);
+ }
+ }
+
+ if (end > a_end && start < b_end) {
+ int s = start > a_end ? start - a_end : 0;
+ int e_abs = end < b_end ? end : b_end;
+ int e = e_abs - a_end;
+ if (s < e) {
+ bf16_matvec_fused(t->b + (size_t)row * t->b_dim + s, x_row,
+ t->Wb_bf16 + (size_t)s * t->in_dim, NULL, t->in_dim, e - s);
+ }
+ }
+}
+
+static void pair_matvec_worker(int tid, int n_threads, void *arg) {
+ pair_matvec_task_t *t = (pair_matvec_task_t *)arg;
+ int total_work = t->seq_len * t->total_dim;
+ int chunk = (total_work + n_threads - 1) / n_threads;
+ int start = tid * chunk;
+ int end = start + chunk;
+ if (end > total_work)
+ end = total_work;
+ if (start >= end)
+ return;
+
+ while (start < end) {
+ int row = start / t->total_dim;
+ int pos = start - row * t->total_dim;
+ int row_end = (row + 1) * t->total_dim;
+ int stop = end < row_end ? end : row_end;
+ pair_matvec_range(t, row, pos, stop - row * t->total_dim);
+ start = stop;
+ }
+}
+
+void linear_nobias_bf16_pair(float *a,
+ float *b,
+ const float *x,
+ const uint16_t *Wa_bf16,
+ const uint16_t *Wb_bf16,
+ int seq_len,
+ int in_dim,
+ int a_dim,
+ int b_dim) {
+ if (seq_len <= 0)
+ return;
+
+ if (tp_num_threads() <= 1) {
+ for (int s = 0; s < seq_len; s++) {
+ const float *x_row = x + (size_t)s * in_dim;
+ bf16_matvec_fused(a + (size_t)s * a_dim, x_row, Wa_bf16, NULL, in_dim, a_dim);
+ bf16_matvec_fused(b + (size_t)s * b_dim, x_row, Wb_bf16, NULL, in_dim, b_dim);
+ }
+ return;
+ }
+
+ pair_matvec_task_t task = {
+ .a = a,
+ .b = b,
+ .x = x,
+ .Wa_bf16 = Wa_bf16,
+ .Wb_bf16 = Wb_bf16,
+ .seq_len = seq_len,
+ .in_dim = in_dim,
+ .a_dim = a_dim,
+ .b_dim = b_dim,
+ .total_dim = a_dim + b_dim,
+ };
+ parallel_for(pair_matvec_worker, &task);
+}
+
+typedef struct {
+ float *q;
+ float *k;
+ float *v;
+ const float *x;
+ const uint16_t *Wq_bf16;
+ const uint16_t *Wk_bf16;
+ const uint16_t *Wv_bf16;
+ int in_dim;
+ int q_dim;
+ int kv_dim;
+ int seq_len;
+ int total_dim;
+} qkv_matvec_task_t;
+
+static void qkv_matvec_range(const qkv_matvec_task_t *t, int row, int start, int end) {
+ const float *x_row = t->x + (size_t)row * t->in_dim;
+ int q_end = t->q_dim;
+ int k_end = q_end + t->kv_dim;
+ int v_end = k_end + t->kv_dim;
+
+ if (start < q_end) {
+ int s = start;
+ int e = end < q_end ? end : q_end;
+ if (s < e) {
+ bf16_matvec_fused(t->q + (size_t)row * t->q_dim + s, x_row,
+ t->Wq_bf16 + (size_t)s * t->in_dim, NULL, t->in_dim, e - s);
+ }
+ }
+
+ if (end > q_end && start < k_end) {
+ int s = start > q_end ? start - q_end : 0;
+ int e_abs = end < k_end ? end : k_end;
+ int e = e_abs - q_end;
+ if (s < e) {
+ bf16_matvec_fused(t->k + (size_t)row * t->kv_dim + s, x_row,
+ t->Wk_bf16 + (size_t)s * t->in_dim, NULL, t->in_dim, e - s);
+ }
+ }
+
+ if (end > k_end && start < v_end) {
+ int s = start > k_end ? start - k_end : 0;
+ int e_abs = end < v_end ? end : v_end;
+ int e = e_abs - k_end;
+ if (s < e) {
+ bf16_matvec_fused(t->v + (size_t)row * t->kv_dim + s, x_row,
+ t->Wv_bf16 + (size_t)s * t->in_dim, NULL, t->in_dim, e - s);
+ }
+ }
+}
+
+static void qkv_matvec_worker(int tid, int n_threads, void *arg) {
+ qkv_matvec_task_t *t = (qkv_matvec_task_t *)arg;
+ int total_work = t->seq_len * t->total_dim;
+ int chunk = (total_work + n_threads - 1) / n_threads;
+ int start = tid * chunk;
+ int end = start + chunk;
+ if (end > total_work)
+ end = total_work;
+ if (start >= end)
+ return;
+
+ while (start < end) {
+ int row = start / t->total_dim;
+ int pos = start - row * t->total_dim;
+ int row_end = (row + 1) * t->total_dim;
+ int stop = end < row_end ? end : row_end;
+ qkv_matvec_range(t, row, pos, stop - row * t->total_dim);
+ start = stop;
+ }
+}
+
+void linear_nobias_bf16_qkv(float *q,
+ float *k,
+ float *v,
+ const float *x,
+ const uint16_t *Wq_bf16,
+ const uint16_t *Wk_bf16,
+ const uint16_t *Wv_bf16,
+ int seq_len,
+ int in_dim,
+ int q_dim,
+ int kv_dim) {
+ if (seq_len <= 0)
+ return;
+
+ if (tp_num_threads() <= 1) {
+ for (int s = 0; s < seq_len; s++) {
+ const float *x_row = x + (size_t)s * in_dim;
+ bf16_matvec_fused(q + (size_t)s * q_dim, x_row, Wq_bf16, NULL, in_dim, q_dim);
+ bf16_matvec_fused(k + (size_t)s * kv_dim, x_row, Wk_bf16, NULL, in_dim, kv_dim);
+ bf16_matvec_fused(v + (size_t)s * kv_dim, x_row, Wv_bf16, NULL, in_dim, kv_dim);
+ }
+ return;
+ }
+
+ qkv_matvec_task_t task = {
+ .q = q,
+ .k = k,
+ .v = v,
+ .x = x,
+ .Wq_bf16 = Wq_bf16,
+ .Wk_bf16 = Wk_bf16,
+ .Wv_bf16 = Wv_bf16,
+ .in_dim = in_dim,
+ .q_dim = q_dim,
+ .kv_dim = kv_dim,
+ .seq_len = seq_len,
+ .total_dim = q_dim + 2 * kv_dim,
+ };
+ parallel_for(qkv_matvec_worker, &task);
+}
+
+void linear_nobias_bf16(
+ float *y, const float *x, const uint16_t *W_bf16, int seq_len, int in_dim, int out_dim) {
+ if (seq_len == 1) {
+ bf16_matvec_threaded(y, x, W_bf16, NULL, in_dim, out_dim);
+ return;
+ }
+ /* Callers send longer sequences through an F32-widened weight matrix in
+ * caller-owned scratch.
+ * This per-row path remains correct for any length. */
+ bf16_linear_rows(y, x, W_bf16, NULL, seq_len, in_dim, out_dim);
+}
diff --git a/libffwd/generic.c b/libffwd/generic.c
new file mode 100644
index 0000000..5425247
--- /dev/null
+++ b/libffwd/generic.c
@@ -0,0 +1,44 @@
+/*
+ * Architecture-generic hot kernels / non-SIMD fallback.
+ */
+
+#include "impl.h"
+
+#include <string.h>
+
+void bf16_matvec_fused_generic(
+ float *y, const float *x, const uint16_t *W_bf16, const float *bias, int in_dim, int out_dim) {
+ for (int o = 0; o < out_dim; o++) {
+ const uint16_t *w_row = W_bf16 + (size_t)o * in_dim;
+ float sum = bias ? bias[o] : 0.0f;
+ for (int k = 0; k < in_dim; k++) {
+ uint32_t f32_bits = ((uint32_t)w_row[k]) << 16;
+ float w_val;
+ memcpy(&w_val, &f32_bits, sizeof(float));
+ sum += w_val * x[k];
+ }
+ y[o] = sum;
+ }
+}
+
+float dot_f32_generic(const float *a, const float *b, int n) {
+ float sum = 0.0f;
+ for (int i = 0; i < n; i++)
+ sum += a[i] * b[i];
+ return sum;
+}
+
+void vec_scale_inplace_generic(float *dst, float scale, int n) {
+ for (int i = 0; i < n; i++)
+ dst[i] *= scale;
+}
+
+void vec_axpy_inplace_generic(float *dst, const float *src, float alpha, int n) {
+ for (int i = 0; i < n; i++)
+ dst[i] += alpha * src[i];
+}
+
+void vec_scale_add_generic(float *dst, const float *src, float correction, int n) {
+ for (int i = 0; i < n; i++)
+ dst[i] = dst[i] * correction + src[i];
+}
diff --git a/libffwd/impl.h b/libffwd/impl.h
new file mode 100644
index 0000000..2149cf2
--- /dev/null
+++ b/libffwd/impl.h
@@ -0,0 +1,280 @@
+/*
+ * Internal architecture dispatch for hot kernels.
+ *
+ * Small vector primitives (dot product, scale, axpy, scale-add, scaled
+ * multiply) are static inline here so they fold into the caller's loop.
+ * For example, an RMSNorm or attention row has no call overhead, and the
+ * compiler can keep the row in registers across reduction and write-back.
+ *
+ * Generic scalar versions stay out of line in generic.c. They are the reference
+ * for kernel tests and the fallback when no SIMD path is available.
+ *
+ * bf16_matvec_fused is a large full matrix-vector product, called once per
+ * output tile rather than inside a tight loop, so it stays out of line.
+ */
+
+#ifndef KERNELS_IMPL_H
+#define KERNELS_IMPL_H
+
+#include <stdint.h>
+
+/* Scalar references (generic.c): the kernel tests compare the SIMD results
+ * against these, and the no-SIMD build dispatches to them directly. */
+void bf16_matvec_fused_generic(
+ float *y, const float *x, const uint16_t *W_bf16, const float *bias, int in_dim, int out_dim);
+float dot_f32_generic(const float *a, const float *b, int n);
+void vec_scale_inplace_generic(float *dst, float scale, int n);
+void vec_axpy_inplace_generic(float *dst, const float *src, float alpha, int n);
+void vec_scale_add_generic(float *dst, const float *src, float correction, int n);
+
+#ifdef __ARM_NEON
+
+# include <arm_neon.h>
+
+void bf16_matvec_fused_neon(
+ float *y, const float *x, const uint16_t *W_bf16, const float *bias, int in_dim, int out_dim);
+# define bf16_matvec_fused_impl bf16_matvec_fused_neon
+
+static inline float dot_f32_impl(const float *a, const float *b, int n) {
+ int i = 0;
+ float32x4_t acc0 = vdupq_n_f32(0.0f);
+ float32x4_t acc1 = vdupq_n_f32(0.0f);
+ for (; i + 8 <= n; i += 8) {
+ float32x4_t a0 = vld1q_f32(a + i);
+ float32x4_t b0 = vld1q_f32(b + i);
+ float32x4_t a1 = vld1q_f32(a + i + 4);
+ float32x4_t b1 = vld1q_f32(b + i + 4);
+ acc0 = vfmaq_f32(acc0, a0, b0);
+ acc1 = vfmaq_f32(acc1, a1, b1);
+ }
+ float sum = vaddvq_f32(vaddq_f32(acc0, acc1));
+ for (; i < n; i++)
+ sum += a[i] * b[i];
+ return sum;
+}
+
+static inline void vec_scale_inplace_impl(float *dst, float scale, int n) {
+ int i = 0;
+ float32x4_t s = vdupq_n_f32(scale);
+ for (; i + 8 <= n; i += 8) {
+ float32x4_t d0 = vld1q_f32(dst + i);
+ float32x4_t d1 = vld1q_f32(dst + i + 4);
+ vst1q_f32(dst + i, vfmaq_f32(vdupq_n_f32(0.0f), d0, s));
+ vst1q_f32(dst + i + 4, vfmaq_f32(vdupq_n_f32(0.0f), d1, s));
+ }
+ for (; i < n; i++)
+ dst[i] *= scale;
+}
+
+static inline void vec_axpy_inplace_impl(float *dst, const float *src, float alpha, int n) {
+ int i = 0;
+ float32x4_t a = vdupq_n_f32(alpha);
+ for (; i + 8 <= n; i += 8) {
+ float32x4_t d0 = vld1q_f32(dst + i);
+ float32x4_t s0 = vld1q_f32(src + i);
+ float32x4_t d1 = vld1q_f32(dst + i + 4);
+ float32x4_t s1 = vld1q_f32(src + i + 4);
+ vst1q_f32(dst + i, vfmaq_f32(d0, s0, a));
+ vst1q_f32(dst + i + 4, vfmaq_f32(d1, s1, a));
+ }
+ for (; i < n; i++)
+ dst[i] += alpha * src[i];
+}
+
+static inline void vec_scale_add_impl(float *dst, const float *src, float correction, int n) {
+ int i = 0;
+ float32x4_t c = vdupq_n_f32(correction);
+ for (; i + 8 <= n; i += 8) {
+ float32x4_t d0 = vld1q_f32(dst + i);
+ float32x4_t s0 = vld1q_f32(src + i);
+ float32x4_t d1 = vld1q_f32(dst + i + 4);
+ float32x4_t s1 = vld1q_f32(src + i + 4);
+ vst1q_f32(dst + i, vfmaq_f32(s0, d0, c));
+ vst1q_f32(dst + i + 4, vfmaq_f32(s1, d1, c));
+ }
+ for (; i < n; i++)
+ dst[i] = dst[i] * correction + src[i];
+}
+
+#elif defined(__AVX2__) && defined(__FMA__)
+
+# include <immintrin.h>
+
+void bf16_matvec_fused_avx(
+ float *y, const float *x, const uint16_t *W_bf16, const float *bias, int in_dim, int out_dim);
+# define bf16_matvec_fused_impl bf16_matvec_fused_avx
+
+static inline float dot_f32_impl(const float *a, const float *b, int n) {
+# if defined(__AVX512F__)
+ int i = 0;
+ __m512 acc0 = _mm512_setzero_ps();
+ __m512 acc1 = _mm512_setzero_ps();
+ __m512 acc2 = _mm512_setzero_ps();
+ __m512 acc3 = _mm512_setzero_ps();
+ for (; i + 64 <= n; i += 64) {
+ acc0 = _mm512_fmadd_ps(_mm512_loadu_ps(a + i), _mm512_loadu_ps(b + i), acc0);
+ acc1 = _mm512_fmadd_ps(_mm512_loadu_ps(a + i + 16), _mm512_loadu_ps(b + i + 16), acc1);
+ acc2 = _mm512_fmadd_ps(_mm512_loadu_ps(a + i + 32), _mm512_loadu_ps(b + i + 32), acc2);
+ acc3 = _mm512_fmadd_ps(_mm512_loadu_ps(a + i + 48), _mm512_loadu_ps(b + i + 48), acc3);
+ }
+ __m512 acc = _mm512_add_ps(_mm512_add_ps(acc0, acc1), _mm512_add_ps(acc2, acc3));
+ for (; i + 16 <= n; i += 16) {
+ acc = _mm512_fmadd_ps(_mm512_loadu_ps(a + i), _mm512_loadu_ps(b + i), acc);
+ }
+ float sum = _mm512_reduce_add_ps(acc);
+ for (; i < n; i++)
+ sum += a[i] * b[i];
+ return sum;
+# else
+ int i = 0;
+ __m256 acc0 = _mm256_setzero_ps();
+ __m256 acc1 = _mm256_setzero_ps();
+ __m256 acc2 = _mm256_setzero_ps();
+ __m256 acc3 = _mm256_setzero_ps();
+ for (; i + 32 <= n; i += 32) {
+ acc0 = _mm256_fmadd_ps(_mm256_loadu_ps(a + i), _mm256_loadu_ps(b + i), acc0);
+ acc1 = _mm256_fmadd_ps(_mm256_loadu_ps(a + i + 8), _mm256_loadu_ps(b + i + 8), acc1);
+ acc2 = _mm256_fmadd_ps(_mm256_loadu_ps(a + i + 16), _mm256_loadu_ps(b + i + 16), acc2);
+ acc3 = _mm256_fmadd_ps(_mm256_loadu_ps(a + i + 24), _mm256_loadu_ps(b + i + 24), acc3);
+ }
+ acc0 = _mm256_add_ps(_mm256_add_ps(acc0, acc1), _mm256_add_ps(acc2, acc3));
+ for (; i + 8 <= n; i += 8) {
+ acc0 = _mm256_fmadd_ps(_mm256_loadu_ps(a + i), _mm256_loadu_ps(b + i), acc0);
+ }
+ __m128 r = _mm_add_ps(_mm256_castps256_ps128(acc0), _mm256_extractf128_ps(acc0, 1));
+ r = _mm_hadd_ps(r, r);
+ r = _mm_hadd_ps(r, r);
+ float sum = _mm_cvtss_f32(r);
+ for (; i < n; i++)
+ sum += a[i] * b[i];
+ return sum;
+# endif
+}
+
+static inline void vec_scale_inplace_impl(float *dst, float scale, int n) {
+# if defined(__AVX512F__)
+ int i = 0;
+ __m512 s = _mm512_set1_ps(scale);
+ for (; i + 64 <= n; i += 64) {
+ _mm512_storeu_ps(dst + i, _mm512_mul_ps(_mm512_loadu_ps(dst + i), s));
+ _mm512_storeu_ps(dst + i + 16, _mm512_mul_ps(_mm512_loadu_ps(dst + i + 16), s));
+ _mm512_storeu_ps(dst + i + 32, _mm512_mul_ps(_mm512_loadu_ps(dst + i + 32), s));
+ _mm512_storeu_ps(dst + i + 48, _mm512_mul_ps(_mm512_loadu_ps(dst + i + 48), s));
+ }
+ for (; i + 16 <= n; i += 16) {
+ _mm512_storeu_ps(dst + i, _mm512_mul_ps(_mm512_loadu_ps(dst + i), s));
+ }
+ for (; i < n; i++)
+ dst[i] *= scale;
+# else
+ int i = 0;
+ __m256 s = _mm256_set1_ps(scale);
+ for (; i + 32 <= n; i += 32) {
+ _mm256_storeu_ps(dst + i, _mm256_mul_ps(_mm256_loadu_ps(dst + i), s));
+ _mm256_storeu_ps(dst + i + 8, _mm256_mul_ps(_mm256_loadu_ps(dst + i + 8), s));
+ _mm256_storeu_ps(dst + i + 16, _mm256_mul_ps(_mm256_loadu_ps(dst + i + 16), s));
+ _mm256_storeu_ps(dst + i + 24, _mm256_mul_ps(_mm256_loadu_ps(dst + i + 24), s));
+ }
+ for (; i + 8 <= n; i += 8) {
+ _mm256_storeu_ps(dst + i, _mm256_mul_ps(_mm256_loadu_ps(dst + i), s));
+ }
+ for (; i < n; i++)
+ dst[i] *= scale;
+# endif
+}
+
+static inline void vec_axpy_inplace_impl(float *dst, const float *src, float alpha, int n) {
+# if defined(__AVX512F__)
+ int i = 0;
+ __m512 a = _mm512_set1_ps(alpha);
+ for (; i + 64 <= n; i += 64) {
+ _mm512_storeu_ps(dst + i,
+ _mm512_fmadd_ps(_mm512_loadu_ps(src + i), a, _mm512_loadu_ps(dst + i)));
+ _mm512_storeu_ps(dst + i + 16, _mm512_fmadd_ps(_mm512_loadu_ps(src + i + 16), a,
+ _mm512_loadu_ps(dst + i + 16)));
+ _mm512_storeu_ps(dst + i + 32, _mm512_fmadd_ps(_mm512_loadu_ps(src + i + 32), a,
+ _mm512_loadu_ps(dst + i + 32)));
+ _mm512_storeu_ps(dst + i + 48, _mm512_fmadd_ps(_mm512_loadu_ps(src + i + 48), a,
+ _mm512_loadu_ps(dst + i + 48)));
+ }
+ for (; i + 16 <= n; i += 16) {
+ _mm512_storeu_ps(dst + i,
+ _mm512_fmadd_ps(_mm512_loadu_ps(src + i), a, _mm512_loadu_ps(dst + i)));
+ }
+ for (; i < n; i++)
+ dst[i] += alpha * src[i];
+# else
+ int i = 0;
+ __m256 a = _mm256_set1_ps(alpha);
+ for (; i + 32 <= n; i += 32) {
+ _mm256_storeu_ps(dst + i,
+ _mm256_fmadd_ps(_mm256_loadu_ps(src + i), a, _mm256_loadu_ps(dst + i)));
+ _mm256_storeu_ps(dst + i + 8, _mm256_fmadd_ps(_mm256_loadu_ps(src + i + 8), a,
+ _mm256_loadu_ps(dst + i + 8)));
+ _mm256_storeu_ps(dst + i + 16, _mm256_fmadd_ps(_mm256_loadu_ps(src + i + 16), a,
+ _mm256_loadu_ps(dst + i + 16)));
+ _mm256_storeu_ps(dst + i + 24, _mm256_fmadd_ps(_mm256_loadu_ps(src + i + 24), a,
+ _mm256_loadu_ps(dst + i + 24)));
+ }
+ for (; i + 8 <= n; i += 8) {
+ _mm256_storeu_ps(dst + i,
+ _mm256_fmadd_ps(_mm256_loadu_ps(src + i), a, _mm256_loadu_ps(dst + i)));
+ }
+ for (; i < n; i++)
+ dst[i] += alpha * src[i];
+# endif
+}
+
+static inline void vec_scale_add_impl(float *dst, const float *src, float correction, int n) {
+# if defined(__AVX512F__)
+ int i = 0;
+ __m512 c = _mm512_set1_ps(correction);
+ for (; i + 64 <= n; i += 64) {
+ _mm512_storeu_ps(dst + i,
+ _mm512_fmadd_ps(_mm512_loadu_ps(dst + i), c, _mm512_loadu_ps(src + i)));
+ _mm512_storeu_ps(dst + i + 16, _mm512_fmadd_ps(_mm512_loadu_ps(dst + i + 16), c,
+ _mm512_loadu_ps(src + i + 16)));
+ _mm512_storeu_ps(dst + i + 32, _mm512_fmadd_ps(_mm512_loadu_ps(dst + i + 32), c,
+ _mm512_loadu_ps(src + i + 32)));
+ _mm512_storeu_ps(dst + i + 48, _mm512_fmadd_ps(_mm512_loadu_ps(dst + i + 48), c,
+ _mm512_loadu_ps(src + i + 48)));
+ }
+ for (; i + 16 <= n; i += 16) {
+ _mm512_storeu_ps(dst + i,
+ _mm512_fmadd_ps(_mm512_loadu_ps(dst + i), c, _mm512_loadu_ps(src + i)));
+ }
+ for (; i < n; i++)
+ dst[i] = dst[i] * correction + src[i];
+# else
+ int i = 0;
+ __m256 c = _mm256_set1_ps(correction);
+ for (; i + 32 <= n; i += 32) {
+ _mm256_storeu_ps(dst + i,
+ _mm256_fmadd_ps(_mm256_loadu_ps(dst + i), c, _mm256_loadu_ps(src + i)));
+ _mm256_storeu_ps(dst + i + 8, _mm256_fmadd_ps(_mm256_loadu_ps(dst + i + 8), c,
+ _mm256_loadu_ps(src + i + 8)));
+ _mm256_storeu_ps(dst + i + 16, _mm256_fmadd_ps(_mm256_loadu_ps(dst + i + 16), c,
+ _mm256_loadu_ps(src + i + 16)));
+ _mm256_storeu_ps(dst + i + 24, _mm256_fmadd_ps(_mm256_loadu_ps(dst + i + 24), c,
+ _mm256_loadu_ps(src + i + 24)));
+ }
+ for (; i + 8 <= n; i += 8) {
+ _mm256_storeu_ps(dst + i,
+ _mm256_fmadd_ps(_mm256_loadu_ps(dst + i), c, _mm256_loadu_ps(src + i)));
+ }
+ for (; i < n; i++)
+ dst[i] = dst[i] * correction + src[i];
+# endif
+}
+
+#else /* no SIMD path: dispatch to the scalar references */
+
+# define bf16_matvec_fused_impl bf16_matvec_fused_generic
+# define dot_f32_impl dot_f32_generic
+# define vec_scale_inplace_impl vec_scale_inplace_generic
+# define vec_axpy_inplace_impl vec_axpy_inplace_generic
+# define vec_scale_add_impl vec_scale_add_generic
+
+#endif
+
+#endif /* KERNELS_IMPL_H */
diff --git a/libffwd/internal.h b/libffwd/internal.h
new file mode 100644
index 0000000..6030c36
--- /dev/null
+++ b/libffwd/internal.h
@@ -0,0 +1,129 @@
+#ifndef FFWD_INTERNAL_H
+#define FFWD_INTERNAL_H
+
+#include "ffwd.h"
+
+#include <stddef.h>
+#include <stdio.h>
+
+typedef struct ffwd_model ffwd_model_t;
+typedef struct ffwd_workspace ffwd_workspace_t;
+typedef struct ffwd_late_model ffwd_late_model_t;
+typedef struct ffwd_late_workspace ffwd_late_workspace_t;
+
+/* Help text used by the frontends. */
+/* TODO: tools should not depend on the internal API */
+void ffwd_cli_help(FILE *f);
+void ffwd_server_help(FILE *f);
+
+/*
+ * Lower-level CPU model API. These functions are used by backend glue, tests,
+ * benchmarks, and parity harnesses; they are not exported from libffwd.
+ */
+ffwd_model_t *ffwd_model_load(const char *model_dir);
+void ffwd_model_free(ffwd_model_t *model);
+
+ffwd_workspace_t *ffwd_workspace_new(const ffwd_model_t *model);
+void ffwd_workspace_free(ffwd_workspace_t *ws);
+
+const ffwd_config_t *ffwd_model_config(const ffwd_model_t *model);
+size_t ffwd_workspace_nbytes(const ffwd_workspace_t *ws);
+
+float *ffwd_model_encode(const ffwd_model_t *model,
+ ffwd_workspace_t *ws,
+ const int *token_ids,
+ int n_tokens);
+
+int ffwd_model_encode_into(const ffwd_model_t *model,
+ ffwd_workspace_t *ws,
+ const int *token_ids,
+ int n_tokens,
+ float *out_embedding);
+
+int ffwd_model_encode_batch(const ffwd_model_t *model,
+ ffwd_workspace_t *ws,
+ const ffwd_input_t *inputs,
+ int batch,
+ float *out_embeddings);
+
+int ffwd_pool_batch(const ffwd_config_t *cfg,
+ const float *states,
+ const int *seq_lengths,
+ int batch,
+ float *out_embeddings);
+
+float *ffwd_model_forward(const ffwd_model_t *model,
+ ffwd_workspace_t *ws,
+ const int *token_ids,
+ int n_tokens);
+
+int ffwd_model_forward_into(const ffwd_model_t *model,
+ ffwd_workspace_t *ws,
+ const int *token_ids,
+ int n_tokens,
+ float *out_states);
+
+int ffwd_pool_spans(const ffwd_config_t *cfg,
+ const float *states,
+ int n_tokens,
+ const ffwd_span_t *spans,
+ int n_spans,
+ float *out_embeddings);
+
+int ffwd_model_encode_spans(const ffwd_model_t *model,
+ ffwd_workspace_t *ws,
+ const int *token_ids,
+ int n_tokens,
+ const ffwd_span_t *spans,
+ int n_spans,
+ float *out_embeddings);
+
+int ffwd_model_encode_spans_batch(const ffwd_model_t *model,
+ ffwd_workspace_t *ws,
+ const ffwd_context_input_t *inputs,
+ int batch,
+ float *out_embeddings);
+
+/*
+ * Late-interaction CPU model API. The public engine path exposes reranking via
+ * ffwd_rerank(); these entry points are for tests/backends only.
+ */
+ffwd_late_model_t *ffwd_late_model_load(const char *model_dir);
+void ffwd_late_model_free(ffwd_late_model_t *model);
+
+ffwd_late_workspace_t *ffwd_late_workspace_new(const ffwd_late_model_t *model);
+void ffwd_late_workspace_free(ffwd_late_workspace_t *ws);
+
+const ffwd_config_t *ffwd_late_model_config(const ffwd_late_model_t *model);
+int ffwd_late_model_token_dim(const ffwd_late_model_t *model);
+
+int ffwd_late_model_encode_tokens(const ffwd_late_model_t *model,
+ ffwd_late_workspace_t *ws,
+ const int *token_ids,
+ int n_tokens,
+ int normalize,
+ float *out_vectors);
+
+int ffwd_late_model_encode_docs(const ffwd_late_model_t *model,
+ ffwd_late_workspace_t *ws,
+ const int *const *doc_ids,
+ const int *n_tokens,
+ const int *const *keep,
+ const int *n_keep,
+ int n_docs,
+ int normalize,
+ float *out_vectors,
+ int *out_offsets);
+
+float ffwd_late_maxsim(
+ const float *query_vectors, int query_tokens, const float *doc_vectors, int doc_tokens, int dim);
+
+int ffwd_late_maxsim_batch(const float *query_vectors,
+ int query_tokens,
+ const float *doc_vectors,
+ const int *doc_offsets,
+ int docs,
+ int dim,
+ float *scores);
+
+#endif /* FFWD_INTERNAL_H */
diff --git a/libffwd/kernels.h b/libffwd/kernels.h
new file mode 100644
index 0000000..11312db
--- /dev/null
+++ b/libffwd/kernels.h
@@ -0,0 +1,181 @@
+/*
+ * Transformer inference kernels (CPU, float32).
+ *
+ * Low-level math operations. All operate on float32 tensors in row-major order.
+ */
+
+#ifndef KERNELS_H
+#define KERNELS_H
+
+#include <stddef.h>
+#include <stdint.h>
+
+/* Basic operations */
+
+void add_inplace(float *a, const float *b, int n);
+
+/* Matrix operations */
+
+/* C = A @ B^T: A[M,K], B[N,K], C[M,N] */
+void matmul_t(float *C, const float *A, const float *B, int M, int K, int N);
+
+/* y = x @ W^T + b: x[seq,in], W[out,in], b[out], y[seq,out] */
+void linear(
+ float *y, const float *x, const float *W, const float *b, int seq_len, int in_dim, int out_dim);
+
+void linear_nobias(float *y, const float *x, const float *W, int seq_len, int in_dim, int out_dim);
+
+/* bf16 weight variants */
+
+void bf16_to_f32_buf(float *dst, const uint16_t *src, size_t n);
+void linear_nobias_bf16(
+ float *y, const float *x, const uint16_t *W_bf16, int seq_len, int in_dim, int out_dim);
+
+/* Small-sequence BF16 path: compute two projections with one threaded dispatch. */
+void linear_nobias_bf16_pair(float *a,
+ float *b,
+ const float *x,
+ const uint16_t *Wa_bf16,
+ const uint16_t *Wb_bf16,
+ int seq_len,
+ int in_dim,
+ int a_dim,
+ int b_dim);
+
+/* Small-sequence BF16 path: compute Q/K/V matvecs with one threaded dispatch. */
+void linear_nobias_bf16_qkv(float *q,
+ float *k,
+ float *v,
+ const float *x,
+ const uint16_t *Wq_bf16,
+ const uint16_t *Wk_bf16,
+ const uint16_t *Wv_bf16,
+ int seq_len,
+ int in_dim,
+ int q_dim,
+ int kv_dim);
+
+/* Dot product using the best available local SIMD implementation. */
+float dot_f32(const float *a, const float *b, int n);
+
+/* Normalization */
+
+/* RMS Normalization: out = x / rms(x) * weight */
+void rms_norm(float *out, const float *x, const float *weight, int seq_len, int hidden, float eps);
+
+/* Per-head RMS Normalization for Q/K norms in decoder
+ * x: [seq, n_heads, head_dim], weight: [head_dim]
+ * Normalizes each head independently */
+void rms_norm_per_head(
+ float *x, const float *weight, int seq_len, int n_heads, int head_dim, float eps);
+
+/* Layer normalization for BERT-family models:
+ * out = gamma * (x - mean) / sqrt(var + eps) + beta.
+ * Mean and biased/population variance are computed over the hidden axis per row.
+ * Unlike RMSNorm, this subtracts the mean and adds a bias. */
+void layer_norm(float *out,
+ const float *x,
+ const float *gamma,
+ const float *beta,
+ int seq_len,
+ int hidden,
+ float eps);
+
+/* Activation functions */
+
+void softmax(float *x, int rows, int cols);
+/* gate = SiLU(gate) * up */
+void silu_mul_inplace(float *gate, const float *up, int n);
+
+/* Exact (erf) GeLU in place: x = 0.5 * x * (1 + erf(x / sqrt(2))).
+ * This is the "gelu" activation HF BERT/BGE/MiniLM use, not the tanh approximation. */
+void gelu_inplace(float *x, int n);
+
+/* Tanh-approximation GeLU in place (HF gelu_new / gelu_pytorch_tanh):
+ * x = 0.5 * x * (1 + tanh(sqrt(2/pi) * (x + 0.044715 * x^3))). */
+void gelu_tanh_inplace(float *x, int n);
+
+/* Attention operations */
+
+/*
+ * Bidirectional GQA attention over a packed/ragged batch.
+ *
+ * Q: [total_seq, n_heads * head_dim]
+ * K,V: [total_seq, n_kv_heads * head_dim]
+ * offsets: [batch + 1], token spans for each sequence.
+ *
+ * Attention is block-diagonal: tokens only attend within their own
+ * offsets[b]..offsets[b+1] span.
+ */
+void bidirectional_gqa_attention_packed(float *out,
+ const float *Q,
+ const float *K,
+ const float *V,
+ const int *offsets,
+ int batch,
+ int n_heads,
+ int n_kv_heads,
+ int head_dim,
+ float scale);
+
+/* Optional reusable scratch for the BLAS-tiled packed attention path. */
+size_t bidirectional_gqa_attention_packed_scratch_bytes(const int *offsets, int batch);
+void bidirectional_gqa_attention_packed_with_scratch(float *out,
+ const float *Q,
+ const float *K,
+ const float *V,
+ const int *offsets,
+ int batch,
+ int n_heads,
+ int n_kv_heads,
+ int head_dim,
+ float scale,
+ float *scratch,
+ size_t scratch_bytes);
+
+/*
+ * Causal GQA attention over a packed/ragged batch. Query position i attends
+ * only to positions at or before i within its sequence.
+ */
+void causal_gqa_attention_packed(float *out,
+ const float *Q,
+ const float *K,
+ const float *V,
+ const int *offsets,
+ int batch,
+ int n_heads,
+ int n_kv_heads,
+ int head_dim,
+ float scale);
+void causal_gqa_attention_packed_with_scratch(float *out,
+ const float *Q,
+ const float *K,
+ const float *V,
+ const int *offsets,
+ int batch,
+ int n_heads,
+ int n_kv_heads,
+ int head_dim,
+ float scale,
+ float *scratch,
+ size_t scratch_bytes);
+
+/* Position embeddings */
+
+/*
+ * NeoX-style RoPE: compute cos/sin for positions.
+ * cos_out, sin_out: [seq, head_dim]
+ * cos[d] and cos[half+d] are the same (duplicated for full head_dim).
+ */
+void compute_rope_neox(
+ float *cos_out, float *sin_out, const int *positions, int seq, int head_dim, float theta);
+
+/*
+ * Apply NeoX-style RoPE to Q or K.
+ * x: [seq, n_heads * head_dim] (in-place)
+ * cos_vals, sin_vals: [seq, head_dim]
+ */
+void apply_rope_neox(
+ float *x, const float *cos_vals, const float *sin_vals, int seq, int n_heads, int head_dim);
+
+#endif /* KERNELS_H */
diff --git a/libffwd/model.c b/libffwd/model.c
new file mode 100644
index 0000000..7346e32
--- /dev/null
+++ b/libffwd/model.c
@@ -0,0 +1,511 @@
+#include "ffwd.h"
+#include "model_internal.h"
+#include "config.h"
+#include "dtype.h"
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <stdint.h>
+#include <string.h>
+
+/* Model-directory probes */
+
+static int model_dir_has_file(const char *model_dir, const char *rel) {
+ char path[1024];
+ int n = snprintf(path, sizeof(path), "%s/%s", model_dir, rel);
+ if (n < 0 || (size_t)n >= sizeof(path))
+ return 0;
+ FILE *f = fopen(path, "rb");
+ if (!f)
+ return 0;
+ fclose(f);
+ return 1;
+}
+
+int model_dir_has_late_projection(const char *model_dir) {
+ return model_dir_has_file(model_dir, "1_Dense/config.json") &&
+ model_dir_has_file(model_dir, "1_Dense/model.safetensors");
+}
+
+/* Weight tensor loading and validation (direct mmap pointers into safetensors) */
+
+static size_t dtype_size(safetensor_dtype_t dtype) {
+ switch (dtype) {
+ case DTYPE_F32:
+ return sizeof(float);
+ case DTYPE_BF16:
+ case DTYPE_F16:
+ return sizeof(uint16_t);
+ default:
+ return 0;
+ }
+}
+
+static const char *dtype_name(safetensor_dtype_t dtype) {
+ switch (dtype) {
+ case DTYPE_F32:
+ return "F32";
+ case DTYPE_F16:
+ return "F16";
+ case DTYPE_BF16:
+ return "BF16";
+ case DTYPE_I32:
+ return "I32";
+ case DTYPE_I64:
+ return "I64";
+ case DTYPE_BOOL:
+ return "BOOL";
+ default:
+ return "UNKNOWN";
+ }
+}
+
+int tensor_has_supported_shape(const safetensors_file_t *sf,
+ const safetensor_t *t,
+ const char *name,
+ const int64_t *shape,
+ int ndim,
+ int bf16_ok) {
+ /* bf16_ok admits either 16-bit float format (BF16 or F16); both are widened
+ * to F32 by the caller (BF16 lazily per matmul, F16 once at load). */
+ int sixteen_ok = bf16_ok && (t->dtype == DTYPE_BF16 || t->dtype == DTYPE_F16);
+ if (t->dtype != DTYPE_F32 && !sixteen_ok) {
+ fprintf(stderr, "ffwd: unsupported dtype for %s: got %s, expected %s\n", name,
+ dtype_name(t->dtype), bf16_ok ? "F32, BF16, or F16" : "F32");
+ return 0;
+ }
+ if (t->ndim != ndim) {
+ fprintf(stderr, "ffwd: bad rank for %s: got %d, expected %d\n", name, t->ndim, ndim);
+ return 0;
+ }
+
+ size_t numel = 1;
+ for (int i = 0; i < ndim; i++) {
+ if (t->shape[i] != shape[i]) {
+ fprintf(stderr,
+ "ffwd: bad shape for %s at dim %d: "
+ "got %lld, expected %lld\n",
+ name, i, (long long)t->shape[i], (long long)shape[i]);
+ return 0;
+ }
+ if (shape[i] < 0 || (uint64_t)shape[i] > SIZE_MAX / numel) {
+ fprintf(stderr, "ffwd: shape too large for %s\n", name);
+ return 0;
+ }
+ numel *= (size_t)shape[i];
+ }
+
+ size_t elem_size = dtype_size(t->dtype);
+ if (elem_size == 0) {
+ fprintf(stderr, "ffwd: unsupported dtype for %s: got %s\n", name, dtype_name(t->dtype));
+ return 0;
+ }
+
+ size_t bytes;
+ if (mul_size(numel, elem_size, &bytes) != 0) {
+ fprintf(stderr, "ffwd: tensor data too large for %s\n", name);
+ return 0;
+ }
+ if (t->data_size != bytes) {
+ fprintf(stderr, "ffwd: bad data size for %s: got %zu, expected %zu\n", name, t->data_size,
+ bytes);
+ return 0;
+ }
+
+ size_t data_start = 8 + sf->header_size;
+ if (data_start > sf->file_size || t->data_offset > sf->file_size - data_start ||
+ t->data_size > sf->file_size - data_start - t->data_offset) {
+ fprintf(stderr, "ffwd: tensor data out of bounds for %s\n", name);
+ return 0;
+ }
+ return 1;
+}
+
+/* Widen a safetensors tensor to f32. Caller frees. */
+static float *safetensors_get_f32(const safetensors_file_t *sf, const safetensor_t *t) {
+ int64_t n = safetensor_numel(t);
+ if (n <= 0)
+ return NULL;
+ float *out = malloc((size_t)n * sizeof(float));
+ if (!out)
+ return NULL;
+ const void *data = safetensors_data(sf, t);
+ switch (t->dtype) {
+ case DTYPE_F32:
+ memcpy(out, data, (size_t)n * sizeof(float));
+ break;
+ case DTYPE_BF16: {
+ const uint16_t *s = (const uint16_t *)data;
+ for (int64_t i = 0; i < n; i++)
+ out[i] = ffwd_bf16_to_f32(s[i]);
+ break;
+ }
+ case DTYPE_F16: {
+ const uint16_t *s = (const uint16_t *)data;
+ for (int64_t i = 0; i < n; i++)
+ out[i] = ffwd_f16_to_f32(s[i]);
+ break;
+ }
+ default:
+ free(out);
+ return NULL;
+ }
+ return out;
+}
+
+ffwd_weight_ref_t weight_ref_from_tensor(const safetensors_file_t *sf, const safetensor_t *t) {
+ ffwd_weight_ref_t ref = {DTYPE_UNKNOWN, NULL, 0};
+ /* F32/BF16 are consumed directly by the forward pass, so the ref borrows the
+ * mmap (zero copy; BF16 is widened lazily per matmul). F16 has neither a
+ * fused kernel nor a zero-copy F32 view, so widen it once here into an owned
+ * buffer the model frees on unload. DTYPE_F16 never reaches the forward. */
+ if (t->dtype == DTYPE_F16) {
+ float *buf = safetensors_get_f32(sf, t);
+ if (!buf)
+ return ref;
+ ref.dtype = DTYPE_F32;
+ ref.data = buf;
+ ref.owned = 1;
+ } else {
+ ref.dtype = t->dtype;
+ ref.data = safetensors_data(sf, t);
+ }
+ return ref;
+}
+
+static ffwd_weight_ref_t
+load_weight_direct(multi_safetensors_t *ms, const char *name, const int64_t *shape, int ndim) {
+ ffwd_weight_ref_t ref = {DTYPE_UNKNOWN, NULL, 0};
+ safetensors_file_t *sf = NULL;
+ const safetensor_t *t = multi_safetensors_find(ms, name, &sf);
+ if (!t) {
+ fprintf(stderr, "ffwd: tensor not found: %s\n", name);
+ return ref;
+ }
+ if (!tensor_has_supported_shape(sf, t, name, shape, ndim, 1))
+ return ref;
+
+ return weight_ref_from_tensor(sf, t);
+}
+
+static float *
+load_norm_f32(multi_safetensors_t *ms, const char *name, const int64_t *shape, int ndim) {
+ safetensors_file_t *sf = NULL;
+ const safetensor_t *t = multi_safetensors_find(ms, name, &sf);
+ if (!t) {
+ fprintf(stderr, "ffwd: tensor not found: %s\n", name);
+ return NULL;
+ }
+ if (!tensor_has_supported_shape(sf, t, name, shape, ndim, 1))
+ return NULL;
+ return safetensors_get_f32(sf, t);
+}
+
+/* Model / workspace load and free */
+
+/* BERT-family weight loader.
+ * Tensor names differ completely from Qwen
+ * (encoder.layer.N.*, embeddings.*), so this family has its own entry point.
+ *
+ * Reused ffwd_layer_t slots keep their BERT meanings:
+ * wo is the attention output dense;
+ * input_norm/post_attn_norm are the two block LayerNorm weights;
+ * up_proj/down_proj are the two FFN matrices.
+ *
+ * See internal.h.
+ */
+static int
+load_bert_weights(ffwd_model_t *model, multi_safetensors_t *ms, int layer_start, int layer_end) {
+ const ffwd_config_t *cfg = &model->config;
+ ffwd_weights_t *w = &model->weights;
+ char name[256];
+
+ /* sentence-transformers checkpoints store encoder tensors unprefixed; raw
+ * HF BERT and RoBERTa/XLM-R checkpoints use "bert." or "roberta.". */
+ const char *p;
+ if (multi_safetensors_find(ms, "embeddings.word_embeddings.weight", NULL))
+ p = "";
+ else if (multi_safetensors_find(ms, "bert.embeddings.word_embeddings.weight", NULL))
+ p = "bert.";
+ else if (multi_safetensors_find(ms, "roberta.embeddings.word_embeddings.weight", NULL))
+ p = "roberta.";
+ else {
+ fprintf(stderr, "ffwd_model_load: BERT-family word embeddings not found\n");
+ return -1;
+ }
+
+ int hidden = cfg->hidden_size, inter = cfg->intermediate_size;
+
+ if (layer_start == 0) {
+ const int64_t emb_shape[2] = {cfg->vocab_size, hidden};
+ snprintf(name, sizeof(name), "%sembeddings.word_embeddings.weight", p);
+ w->embed_tokens = load_weight_direct(ms, name, emb_shape, 2);
+ const int64_t pos_shape[2] = {cfg->max_position_embeddings, hidden};
+ snprintf(name, sizeof(name), "%sembeddings.position_embeddings.weight", p);
+ w->position_embeddings = load_norm_f32(ms, name, pos_shape, 2);
+ const int64_t type_shape[2] = {cfg->type_vocab_size, hidden};
+ snprintf(name, sizeof(name), "%sembeddings.token_type_embeddings.weight", p);
+ w->token_type_embeddings = load_norm_f32(ms, name, type_shape, 2);
+ const int64_t ln_shape[1] = {hidden};
+ snprintf(name, sizeof(name), "%sembeddings.LayerNorm.weight", p);
+ w->ffwd_ln_w = load_norm_f32(ms, name, ln_shape, 1);
+ snprintf(name, sizeof(name), "%sembeddings.LayerNorm.bias", p);
+ w->ffwd_ln_b = load_norm_f32(ms, name, ln_shape, 1);
+ if (!w->embed_tokens.data || !w->position_embeddings || !w->token_type_embeddings ||
+ !w->ffwd_ln_w || !w->ffwd_ln_b)
+ return -1;
+ }
+
+ w->layers = (ffwd_layer_t *)calloc(cfg->n_layers, sizeof(ffwd_layer_t));
+ if (!w->layers)
+ return -1;
+
+ for (int i = layer_start; i < layer_end; i++) {
+ ffwd_layer_t *l = &w->layers[i];
+
+#define BERT_W(field, suffix, d0, d1) \
+ do { \
+ const int64_t e[2] = {(d0), (d1)}; \
+ snprintf(name, sizeof(name), "%sencoder.layer.%d." suffix, p, i); \
+ l->field = load_weight_direct(ms, name, e, 2); \
+ if (!l->field.data) \
+ return -1; \
+ } while (0)
+#define BERT_V(field, suffix, d0) \
+ do { \
+ const int64_t e[1] = {(d0)}; \
+ snprintf(name, sizeof(name), "%sencoder.layer.%d." suffix, p, i); \
+ l->field = load_norm_f32(ms, name, e, 1); \
+ if (!l->field) \
+ return -1; \
+ } while (0)
+
+ BERT_W(wq, "attention.self.query.weight", hidden, hidden);
+ BERT_V(q_bias, "attention.self.query.bias", hidden);
+ BERT_W(wk, "attention.self.key.weight", hidden, hidden);
+ BERT_V(k_bias, "attention.self.key.bias", hidden);
+ BERT_W(wv, "attention.self.value.weight", hidden, hidden);
+ BERT_V(v_bias, "attention.self.value.bias", hidden);
+ BERT_W(wo, "attention.output.dense.weight", hidden, hidden);
+ BERT_V(o_bias, "attention.output.dense.bias", hidden);
+ BERT_V(input_norm, "attention.output.LayerNorm.weight", hidden);
+ BERT_V(attn_ln_bias, "attention.output.LayerNorm.bias", hidden);
+ BERT_W(up_proj, "intermediate.dense.weight", inter, hidden);
+ BERT_V(ffn_inter_bias, "intermediate.dense.bias", inter);
+ BERT_W(down_proj, "output.dense.weight", hidden, inter);
+ BERT_V(ffn_out_bias, "output.dense.bias", hidden);
+ BERT_V(post_attn_norm, "output.LayerNorm.weight", hidden);
+ BERT_V(ffn_ln_bias, "output.LayerNorm.bias", hidden);
+
+#undef BERT_W
+#undef BERT_V
+ }
+ /* BERT has no final norm: w->norm stays NULL, and pooling skips it. */
+ return 0;
+}
+
+ffwd_model_t *
+model_load_range_ex(const char *model_dir, int layer_start, int layer_end, int allow_late) {
+ if (!allow_late && model_dir_has_late_projection(model_dir)) {
+ fprintf(stderr, "ffwd_model_load: late-interaction models require "
+ "token-level MaxSim support and are not valid pooled "
+ "embedding models yet\n");
+ return NULL;
+ }
+
+ ffwd_model_t *model = (ffwd_model_t *)calloc(1, sizeof(ffwd_model_t));
+ if (!model)
+ return NULL;
+
+ /* Parse config.json */
+ if (ffwd_config_parse(&model->config, model_dir) != 0) {
+ free(model);
+ return NULL;
+ }
+
+ const ffwd_config_t *cfg = &model->config;
+ if (layer_end == -1)
+ layer_end = cfg->n_layers;
+ if (layer_start < 0 || layer_start >= layer_end || layer_end > cfg->n_layers) {
+ fprintf(stderr,
+ "ffwd_model_load: invalid layer range [%d, %d) "
+ "for %d-layer model\n",
+ layer_start, layer_end, cfg->n_layers);
+ free(model);
+ return NULL;
+ }
+ model->layer_start = layer_start;
+ model->layer_end = layer_end;
+
+ /* Open safetensors (handles single file or multi-shard) */
+ multi_safetensors_t *ms = multi_safetensors_open(model_dir);
+ if (!ms) {
+ fprintf(stderr, "ffwd_model_load: failed to open safetensors in %s\n", model_dir);
+ free(model);
+ return NULL;
+ }
+ model->safetensors = ms;
+
+ if (cfg->family == FFWD_FAMILY_BERT) {
+ if (load_bert_weights(model, ms, layer_start, layer_end) != 0)
+ goto fail;
+ if (ffwd_verbose >= 1)
+ fprintf(stderr, "ffwd_model_load: BERT layers [%d, %d) loaded (%d-dim)\n", layer_start,
+ layer_end, cfg->hidden_size);
+ return model;
+ }
+
+ const char *weight_prefix = multi_safetensors_weight_prefix(ms, "embed_tokens.weight");
+ if (!weight_prefix) {
+ fprintf(stderr, "ffwd_model_load: neither embed_tokens.weight nor "
+ "model.embed_tokens.weight was found\n");
+ goto fail;
+ }
+
+ if (ffwd_verbose >= 1)
+ fprintf(stderr, "ffwd_model_load: loading weights from %s\n", model_dir);
+
+ char name[256];
+
+ /* Only the first stage needs token embeddings. */
+ ffwd_weights_t *w = &model->weights;
+ if (layer_start == 0) {
+ const int64_t embed_shape[2] = {cfg->vocab_size, cfg->hidden_size};
+ snprintf(name, sizeof(name), "%sembed_tokens.weight", weight_prefix);
+ w->embed_tokens = load_weight_direct(ms, name, embed_shape, 2);
+ if (!w->embed_tokens.data)
+ goto fail;
+ }
+
+ /* Allocate layer array */
+ w->layers = (ffwd_layer_t *)calloc(cfg->n_layers, sizeof(ffwd_layer_t));
+ if (!w->layers)
+ goto fail;
+
+ /* Per-layer weights */
+ for (int i = layer_start; i < layer_end; i++) {
+ ffwd_layer_t *l = &w->layers[i];
+
+#define LOAD_NORM(field, fmt, d0) \
+ do { \
+ const int64_t expect[1] = {(d0)}; \
+ snprintf(name, sizeof(name), fmt, weight_prefix, i); \
+ l->field = load_norm_f32(ms, name, expect, 1); \
+ if (!l->field) \
+ goto fail; \
+ } while (0)
+
+#define LOAD2(field, fmt, d0, d1) \
+ do { \
+ const int64_t expect[2] = {(d0), (d1)}; \
+ snprintf(name, sizeof(name), fmt, weight_prefix, i); \
+ l->field = load_weight_direct(ms, name, expect, 2); \
+ if (!l->field.data) \
+ goto fail; \
+ } while (0)
+
+ LOAD2(wq, "%slayers.%d.self_attn.q_proj.weight", cfg->q_dim, cfg->hidden_size);
+ LOAD2(wk, "%slayers.%d.self_attn.k_proj.weight", cfg->kv_dim, cfg->hidden_size);
+ LOAD2(wv, "%slayers.%d.self_attn.v_proj.weight", cfg->kv_dim, cfg->hidden_size);
+ LOAD2(wo, "%slayers.%d.self_attn.o_proj.weight", cfg->hidden_size, cfg->q_dim);
+ if (cfg->qkv_bias) {
+ LOAD_NORM(q_bias, "%slayers.%d.self_attn.q_proj.bias", cfg->q_dim);
+ LOAD_NORM(k_bias, "%slayers.%d.self_attn.k_proj.bias", cfg->kv_dim);
+ LOAD_NORM(v_bias, "%slayers.%d.self_attn.v_proj.bias", cfg->kv_dim);
+ }
+ if (cfg->qk_norm) {
+ LOAD_NORM(q_norm, "%slayers.%d.self_attn.q_norm.weight", cfg->head_dim);
+ LOAD_NORM(k_norm, "%slayers.%d.self_attn.k_norm.weight", cfg->head_dim);
+ }
+ LOAD_NORM(input_norm, "%slayers.%d.input_layernorm.weight", cfg->hidden_size);
+ LOAD_NORM(post_attn_norm, "%slayers.%d.post_attention_layernorm.weight", cfg->hidden_size);
+ LOAD2(gate_proj, "%slayers.%d.mlp.gate_proj.weight", cfg->intermediate_size,
+ cfg->hidden_size);
+ LOAD2(up_proj, "%slayers.%d.mlp.up_proj.weight", cfg->intermediate_size, cfg->hidden_size);
+ LOAD2(down_proj, "%slayers.%d.mlp.down_proj.weight", cfg->hidden_size,
+ cfg->intermediate_size);
+
+#undef LOAD2
+#undef LOAD_NORM
+
+ if (ffwd_verbose >= 2)
+ fprintf(stderr, " layer %d loaded\n", i);
+ }
+
+ /* Only the final stage applies the output RMSNorm. */
+ if (layer_end == cfg->n_layers) {
+ const int64_t norm_shape[1] = {cfg->hidden_size};
+ snprintf(name, sizeof(name), "%snorm.weight", weight_prefix);
+ w->norm = load_norm_f32(ms, name, norm_shape, 1);
+ if (!w->norm)
+ goto fail;
+ }
+
+ if (ffwd_verbose >= 1)
+ fprintf(stderr,
+ "ffwd_model_load: layers [%d, %d) loaded "
+ "(%d-dim embeddings)\n",
+ layer_start, layer_end, cfg->hidden_size);
+
+ return model;
+
+fail:
+ ffwd_model_free(model);
+ return NULL;
+}
+
+ffwd_model_t *ffwd_model_load(const char *model_dir) {
+ return model_load_range_ex(model_dir, 0, -1, 0);
+}
+
+/* Release a weight ref's backing store. Only F16-widened refs own their buffer;
+ * borrowed F32/BF16 views into the mmap are a no-op (see weight_ref_from_tensor). */
+static void free_weight_ref(ffwd_weight_ref_t *w) {
+ if (w->owned)
+ free((void *)w->data);
+ w->data = NULL;
+ w->owned = 0;
+}
+
+void ffwd_model_free(ffwd_model_t *model) {
+ if (!model)
+ return;
+ if (model->weights.layers) {
+ for (int i = 0; i < model->config.n_layers; i++) {
+ ffwd_layer_t *l = &model->weights.layers[i];
+ free_weight_ref(&l->wq);
+ free_weight_ref(&l->wk);
+ free_weight_ref(&l->wv);
+ free_weight_ref(&l->wo);
+ free_weight_ref(&l->gate_proj);
+ free_weight_ref(&l->up_proj);
+ free_weight_ref(&l->down_proj);
+ free((void *)l->q_bias);
+ free((void *)l->k_bias);
+ free((void *)l->v_bias);
+ free((void *)l->q_norm);
+ free((void *)l->k_norm);
+ free((void *)l->input_norm);
+ free((void *)l->post_attn_norm);
+ free((void *)l->o_bias);
+ free((void *)l->attn_ln_bias);
+ free((void *)l->ffn_inter_bias);
+ free((void *)l->ffn_out_bias);
+ free((void *)l->ffn_ln_bias);
+ }
+ }
+ free_weight_ref(&model->weights.embed_tokens);
+ free((void *)model->weights.norm);
+ free((void *)model->weights.position_embeddings);
+ free((void *)model->weights.token_type_embeddings);
+ free((void *)model->weights.ffwd_ln_w);
+ free((void *)model->weights.ffwd_ln_b);
+ if (model->safetensors)
+ multi_safetensors_close((multi_safetensors_t *)model->safetensors);
+ free(model->weights.layers);
+ free(model);
+}
+
+const ffwd_config_t *ffwd_model_config(const ffwd_model_t *model) {
+ return model ? &model->config : NULL;
+}
diff --git a/libffwd/model_blas.c b/libffwd/model_blas.c
new file mode 100644
index 0000000..aae2a44
--- /dev/null
+++ b/libffwd/model_blas.c
@@ -0,0 +1,201 @@
+#include "ffwd.h"
+#include "model_internal.h"
+#include "kernels.h"
+
+#include <limits.h>
+#include <math.h>
+#include <stdint.h>
+#include <stdlib.h>
+
+/* CPU workspace ownership and scratch growth. GPU builds use their own
+ * backend contexts and do not link this translation unit. */
+
+ffwd_workspace_t *ffwd_workspace_new(const ffwd_model_t *model) {
+ if (!model)
+ return NULL;
+ ffwd_workspace_t *ws = (ffwd_workspace_t *)calloc(1, sizeof(ffwd_workspace_t));
+ if (!ws)
+ return NULL;
+ ws->model = model;
+ return ws;
+}
+
+void ffwd_workspace_free(ffwd_workspace_t *ws) {
+ if (!ws)
+ return;
+ free(ws->x);
+ free(ws->x_norm);
+ free(ws->q);
+ free(ws->k);
+ free(ws->v);
+ free(ws->attn_out);
+ free(ws->proj_out);
+ free(ws->ffn_gate);
+ free(ws->ffn_up);
+ free(ws->attn_scores);
+ free(ws->offsets);
+ free(ws->rope_cos);
+ free(ws->rope_sin);
+ free(ws->bf16_widen);
+ free(ws);
+}
+
+int ensure_buffers(ffwd_workspace_t *ws, const ffwd_config_t *c, int seq) {
+ if (seq <= ws->buf_seq_cap)
+ return 0;
+
+ int cap;
+ if (grow_cap(ws->buf_seq_cap, seq, &cap) != 0)
+ return -1;
+
+#define R(ptr, n) \
+ do { \
+ if (realloc_floats_2d(&(ptr), cap, (n)) != 0) \
+ return -1; \
+ } while (0)
+
+ R(ws->x, c->hidden_size);
+ R(ws->x_norm, c->hidden_size);
+ R(ws->q, c->q_dim);
+ R(ws->k, c->kv_dim);
+ R(ws->v, c->kv_dim);
+ R(ws->attn_out, c->q_dim);
+ R(ws->proj_out, c->hidden_size);
+ R(ws->ffn_gate, c->intermediate_size);
+ R(ws->ffn_up, c->intermediate_size);
+
+#undef R
+
+ ws->buf_seq_cap = cap;
+ return 0;
+}
+
+void ensure_attention_scores(ffwd_workspace_t *ws, const int *offsets, int batch) {
+ size_t bytes = bidirectional_gqa_attention_packed_scratch_bytes(offsets, batch);
+ if (bytes <= ws->attn_scores_bytes)
+ return;
+
+ void *p = realloc(ws->attn_scores, bytes);
+ if (!p)
+ return;
+ ws->attn_scores = (float *)p;
+ ws->attn_scores_bytes = bytes;
+}
+
+int ensure_rope_cache(ffwd_workspace_t *ws, const ffwd_config_t *cfg, int n_pos) {
+ if (n_pos <= ws->rope_cache_cap)
+ return 0;
+
+ int cap = ws->rope_cache_cap > 0 ? ws->rope_cache_cap : 512;
+ while (cap < n_pos) {
+ if (cap > INT_MAX / 2)
+ return -1;
+ cap *= 2;
+ }
+
+ int head_dim = cfg->head_dim;
+ int half = head_dim / 2;
+ float theta = cfg->rope_theta;
+
+ size_t count;
+ if (mul_size((size_t)cap, (size_t)head_dim, &count) != 0)
+ return -1;
+ if (realloc_floats(&ws->rope_cos, count) != 0)
+ return -1;
+ if (realloc_floats(&ws->rope_sin, count) != 0)
+ return -1;
+
+ for (int pos = ws->rope_cache_cap; pos < cap; pos++) {
+ float fp = (float)pos;
+ float *c = ws->rope_cos + (size_t)pos * head_dim;
+ float *s = ws->rope_sin + (size_t)pos * head_dim;
+ for (int d = 0; d < half; d++) {
+ float inv = 1.0f / powf(theta, (float)(2 * d) / (float)head_dim);
+ float angle = fp * inv;
+ float cv = cosf(angle), sv = sinf(angle);
+ c[d] = cv;
+ c[half + d] = cv;
+ s[d] = sv;
+ s[half + d] = sv;
+ }
+ }
+
+ ws->rope_cache_cap = cap;
+ return 0;
+}
+
+int ensure_offsets(ffwd_workspace_t *ws, int batch) {
+ if (!ws || batch <= 0 || batch == INT_MAX)
+ return -1;
+
+ int needed = batch + 1;
+ if (needed <= ws->offsets_cap)
+ return 0;
+
+ if (realloc_ints(&ws->offsets, (size_t)needed) != 0)
+ return -1;
+ ws->offsets_cap = needed;
+ return 0;
+}
+
+size_t ffwd_workspace_nbytes(const ffwd_workspace_t *ws) {
+ if (!ws)
+ return 0;
+
+ size_t total = sizeof(*ws);
+ const ffwd_model_t *model = ws->model;
+ if (!model)
+ return total;
+
+ const ffwd_config_t *c = &model->config;
+ size_t row_floats = 0;
+ const int dims[] = {
+ c->hidden_size, /* x */
+ c->hidden_size, /* x_norm */
+ c->q_dim, /* q */
+ c->kv_dim, /* k */
+ c->kv_dim, /* v */
+ c->q_dim, /* attn_out */
+ c->hidden_size, /* proj_out */
+ c->intermediate_size, /* ffn_gate */
+ c->intermediate_size, /* ffn_up */
+ };
+
+ for (size_t i = 0; i < sizeof(dims) / sizeof(dims[0]); i++) {
+ if (dims[i] < 0 || add_size(row_floats, (size_t)dims[i], &row_floats) != 0)
+ return SIZE_MAX;
+ }
+
+ size_t buf_floats = 0;
+ if (ws->buf_seq_cap > 0 && mul_size((size_t)ws->buf_seq_cap, row_floats, &buf_floats) != 0)
+ return SIZE_MAX;
+
+ size_t rope_floats = 0;
+ if (ws->rope_cache_cap > 0) {
+ size_t rope_rows = 0;
+ if (mul_size((size_t)ws->rope_cache_cap, (size_t)c->head_dim, &rope_rows) != 0 ||
+ mul_size(rope_rows, 2, &rope_floats) != 0)
+ return SIZE_MAX;
+ }
+
+ size_t all_floats = 0, bytes = 0;
+ if (add_size(buf_floats, rope_floats, &all_floats) != 0 ||
+ mul_size(all_floats, sizeof(float), &bytes) != 0 || add_size(total, bytes, &total) != 0)
+ return SIZE_MAX;
+
+ size_t offset_bytes = 0;
+ if (ws->offsets_cap > 0 && mul_size((size_t)ws->offsets_cap, sizeof(int), &offset_bytes) != 0)
+ return SIZE_MAX;
+ if (add_size(total, offset_bytes, &total) != 0)
+ return SIZE_MAX;
+ if (add_size(total, ws->attn_scores_bytes, &total) != 0)
+ return SIZE_MAX;
+
+ size_t widen_bytes = 0;
+ if (ws->bf16_widen_count > 0 && mul_size(ws->bf16_widen_count, sizeof(float), &widen_bytes) != 0)
+ return SIZE_MAX;
+ if (add_size(total, widen_bytes, &total) != 0)
+ return SIZE_MAX;
+
+ return total;
+}
diff --git a/libffwd/model_internal.h b/libffwd/model_internal.h
new file mode 100644
index 0000000..b828e67
--- /dev/null
+++ b/libffwd/model_internal.h
@@ -0,0 +1,85 @@
+/* Cross-file declarations private to CPU model code.
+ *
+ * model_types.h holds the shared struct definitions; this header holds the
+ * shared functions.
+ *
+ * These are not part of the public API (ffwd.h) and do not use FFWD_API
+ * visibility. They are shared between translation units that used to be one
+ * file: model loading, the forward pass, and late interaction.
+ *
+ * Frontends and GPU backends do not include this header.
+ */
+
+#ifndef FFWD_MODEL_INTERNAL_H
+#define FFWD_MODEL_INTERNAL_H
+
+#include "model_types.h"
+#include "alloc.h"
+
+/* Validate that a safetensor has the expected dtype, rank, and shape, and that
+ * its bytes are within the mapped file. bf16_ok also allows either 16-bit float
+ * format, BF16 or F16, in addition to F32. */
+int tensor_has_supported_shape(const safetensors_file_t *sf,
+ const safetensor_t *t,
+ const char *name,
+ const int64_t *shape,
+ int ndim,
+ int bf16_ok);
+
+/* Build a weight ref from a located tensor.
+ * F32/BF16 borrow the mmap; F16 is widened to an owned F32 buffer because there
+ * is no fused F16 kernel.
+ *
+ * Shared by the model loader and late-interaction projection loader.
+ * The owner frees ref.data when ref.owned is set.
+ *
+ * Returns ref.data == NULL on allocation failure. */
+ffwd_weight_ref_t weight_ref_from_tensor(const safetensors_file_t *sf, const safetensor_t *t);
+
+/* True if model_dir carries a 1_Dense projection (a late-interaction model). */
+int model_dir_has_late_projection(const char *model_dir);
+
+/* Load (a layer range of) a model. allow_late lets the late loader accept a
+ * 1_Dense snapshot that the pooled loader rejects. layer_end == -1 means all. */
+ffwd_model_t *
+model_load_range_ex(const char *model_dir, int layer_start, int layer_end, int allow_late);
+
+/* Workspace scratch grows lazily per forward call.
+ * Defined in model.c beside the workspace lifecycle. ffwd_workspace_nbytes mirrors this sizing.
+ * Called from the forward pass in forward.c. */
+int ensure_buffers(ffwd_workspace_t *ws, const ffwd_config_t *c, int seq);
+void ensure_attention_scores(ffwd_workspace_t *ws, const int *offsets, int batch);
+int ensure_rope_cache(ffwd_workspace_t *ws, const ffwd_config_t *cfg, int n_pos);
+int ensure_offsets(ffwd_workspace_t *ws, int batch);
+
+/* y[seq,out] = x[seq,in] @ w^T, no bias; dispatches F32/BF16 paths. Shared by
+ * the forward pass and the late projection. */
+void linear_nobias_weight(ffwd_workspace_t *ws,
+ float *y,
+ const float *x,
+ const ffwd_weight_ref_t *w,
+ int seq_len,
+ int in_dim,
+ int out_dim);
+
+/* Compute packed sequence offsets [batch+1] plus total and max sequence length
+ * over a batch of inputs. require_ids rejects inputs with a NULL id pointer. */
+int build_offsets(const ffwd_input_t *inputs,
+ int batch,
+ int require_ids,
+ int *offsets,
+ int *total_out,
+ int *max_out);
+
+/* Run the full transformer forward over a packed batch in ws, leaving hidden
+ * states in ws->x. Used by pooled encoding and by late-interaction encoding. */
+int forward_packed_inplace(const ffwd_model_t *model,
+ ffwd_workspace_t *ws,
+ const ffwd_input_t *inputs,
+ int batch,
+ const int *offsets,
+ int total_seq,
+ int max_seq,
+ int apply_final_norm);
+
+#endif /* FFWD_MODEL_INTERNAL_H */
diff --git a/libffwd/model_types.h b/libffwd/model_types.h
new file mode 100644
index 0000000..4f01ca2
--- /dev/null
+++ b/libffwd/model_types.h
@@ -0,0 +1,122 @@
+/* In-memory layout of a loaded model: model/workspace structs, per-layer weight
+ * references, and accessors for GPU backends.
+ *
+ * Shared by CPU model code and the CUDA backend. Not part of the public ABI
+ * (ffwd.h).
+ *
+ * model_internal.h declares the CPU model's private functions.
+ */
+
+#ifndef FFWD_MODEL_TYPES_H
+#define FFWD_MODEL_TYPES_H
+
+#include "internal.h"
+#include "safetensors.h"
+
+typedef struct {
+ safetensor_dtype_t dtype;
+ const void *data;
+ /* 0: data is a borrowed view into the safetensors mmap (F32/BF16, the common
+ * case). 1: data is a heap buffer owned by the model and freed on unload.
+ * Set when an F16 tensor is widened to F32 at load (no fused F16 kernel). */
+ int owned;
+} ffwd_weight_ref_t;
+
+typedef struct {
+ ffwd_weight_ref_t wq; /* [q_dim, hidden] */
+ ffwd_weight_ref_t wk; /* [kv_dim, hidden] */
+ ffwd_weight_ref_t wv; /* [kv_dim, hidden] */
+ ffwd_weight_ref_t wo; /* [hidden, q_dim] */
+ const float *q_bias; /* [q_dim], optional */
+ const float *k_bias; /* [kv_dim], optional */
+ const float *v_bias; /* [kv_dim], optional */
+ const float *q_norm; /* [head_dim] */
+ const float *k_norm; /* [head_dim] */
+ const float *input_norm; /* [hidden] */
+ const float *post_attn_norm; /* [hidden] */
+ ffwd_weight_ref_t gate_proj; /* [intermediate, hidden] */
+ ffwd_weight_ref_t up_proj; /* [intermediate, hidden] */
+ ffwd_weight_ref_t down_proj; /* [hidden, intermediate] */
+ /* BERT family (all NULL for Qwen3). The attention projections reuse
+ * wq/wk/wv/wo and q/k/v_bias; the two FFN matrices reuse up_proj
+ * (intermediate.dense) and down_proj (output.dense); the two block
+ * LayerNorm weights reuse input_norm (post-attention) and post_attn_norm
+ * (post-FFN). These fields add the biases those reused slots lack. */
+ const float *o_bias; /* attention output dense bias [hidden] */
+ const float *attn_ln_bias; /* post-attention LayerNorm bias [hidden] */
+ const float *ffn_inter_bias; /* intermediate.dense bias [intermediate] */
+ const float *ffn_out_bias; /* output.dense bias [hidden] */
+ const float *ffn_ln_bias; /* post-FFN LayerNorm bias [hidden] */
+} ffwd_layer_t;
+
+typedef struct {
+ ffwd_weight_ref_t embed_tokens; /* [vocab_size, hidden] */
+ ffwd_layer_t *layers; /* [n_layers] heap-allocated */
+ const float *norm; /* [hidden]; NULL for BERT (no final norm) */
+ /* BERT family (NULL for Qwen3): learned absolute position embeddings,
+ * token-type (segment) embeddings, and the embedding LayerNorm. */
+ const float *position_embeddings; /* [max_position_embeddings, hidden] */
+ const float *token_type_embeddings; /* [type_vocab_size, hidden] */
+ const float *ffwd_ln_w; /* embedding LayerNorm weight [hidden] */
+ const float *ffwd_ln_b; /* embedding LayerNorm bias [hidden] */
+} ffwd_weights_t;
+
+typedef void (*ffwd_attention_fn)(float *out,
+ const float *Q,
+ const float *K,
+ const float *V,
+ const int *offsets,
+ int batch,
+ int n_heads,
+ int n_kv_heads,
+ int head_dim,
+ float scale,
+ float *scratch,
+ size_t scratch_bytes);
+
+struct ffwd_model {
+ ffwd_config_t config;
+ ffwd_weights_t weights;
+ void *safetensors; /* multi_safetensors_t*, keeps mmap alive */
+ int layer_start; /* loaded transformer range, inclusive */
+ int layer_end; /* loaded transformer range, exclusive */
+};
+
+struct ffwd_workspace {
+ const ffwd_model_t *model; /* immutable model this workspace belongs to */
+ int buf_seq_cap;
+ float *x; /* [seq, hidden] */
+ float *x_norm; /* [seq, hidden] */
+ float *q; /* [seq, q_dim] */
+ float *k; /* [seq, kv_dim] */
+ float *v; /* [seq, kv_dim] */
+ float *attn_out; /* [seq, q_dim] */
+ float *proj_out; /* [seq, hidden] */
+ float *ffn_gate; /* [seq, intermediate] */
+ float *ffn_up; /* [seq, intermediate] */
+ float *attn_scores; /* reusable BLAS attention score tiles */
+ size_t attn_scores_bytes;
+
+ int *offsets; /* [batch + 1] packed sequence offsets */
+ int offsets_cap;
+
+ /* RoPE cosine/sine cache [n_pos, head_dim], grown lazily. */
+ float *rope_cos;
+ float *rope_sin;
+ int rope_cache_cap;
+
+ /* F32 view of one BF16 weight matrix for SGEMM dispatch, grown to the
+ * largest projection. Workspace-owned so concurrent workspaces on one
+ * model never share conversion scratch. */
+ float *bf16_widen;
+ size_t bf16_widen_count;
+};
+
+/* Internal accessors for the late-interaction model. GPU backends build a device
+ * context from an already-loaded CPU late model because the model dir is a late
+ * snapshot that the pooled loader rejects; these expose the base model and the
+ * projection weight without making struct ffwd_late_model public. */
+ffwd_model_t *ffwd_late_model_base(const ffwd_late_model_t *model);
+const ffwd_weight_ref_t *ffwd_late_model_projection(const ffwd_late_model_t *model);
+
+#endif /* FFWD_MODEL_TYPES_H */
diff --git a/libffwd/neon.c b/libffwd/neon.c
new file mode 100644
index 0000000..50cf649
--- /dev/null
+++ b/libffwd/neon.c
@@ -0,0 +1,118 @@
+/*
+ * ARM NEON hot kernels.
+ */
+
+#include "impl.h"
+
+#ifdef __ARM_NEON
+
+# include <arm_neon.h>
+# include <string.h>
+
+void bf16_matvec_fused_neon(
+ float *y, const float *x, const uint16_t *W_bf16, const float *bias, int in_dim, int out_dim) {
+ int o = 0;
+
+ /* Process 2 output rows at a time, 32 elements/iter, 8 accumulators */
+ for (; o + 1 < out_dim; o += 2) {
+ const uint16_t *w0 = W_bf16 + (size_t)o * in_dim;
+ const uint16_t *w1 = W_bf16 + (size_t)(o + 1) * in_dim;
+ float s0 = bias ? bias[o] : 0.0f;
+ float s1 = bias ? bias[o + 1] : 0.0f;
+
+ float32x4_t a0 = vdupq_n_f32(0.0f), a1 = vdupq_n_f32(0.0f);
+ float32x4_t a2 = vdupq_n_f32(0.0f), a3 = vdupq_n_f32(0.0f);
+ float32x4_t b0 = vdupq_n_f32(0.0f), b1 = vdupq_n_f32(0.0f);
+ float32x4_t b2 = vdupq_n_f32(0.0f), b3 = vdupq_n_f32(0.0f);
+ int k = 0;
+
+ for (; k + 32 <= in_dim; k += 32) {
+ float32x4_t x0 = vld1q_f32(x + k);
+ float32x4_t x1 = vld1q_f32(x + k + 4);
+ float32x4_t x2 = vld1q_f32(x + k + 8);
+ float32x4_t x3 = vld1q_f32(x + k + 12);
+ float32x4_t x4 = vld1q_f32(x + k + 16);
+ float32x4_t x5 = vld1q_f32(x + k + 20);
+ float32x4_t x6 = vld1q_f32(x + k + 24);
+ float32x4_t x7 = vld1q_f32(x + k + 28);
+
+ uint16x8_t r0a = vld1q_u16(w0 + k);
+ uint16x8_t r0b = vld1q_u16(w0 + k + 8);
+ uint16x8_t r0c = vld1q_u16(w0 + k + 16);
+ uint16x8_t r0d = vld1q_u16(w0 + k + 24);
+ a0 = vfmaq_f32(a0, vreinterpretq_f32_u32(vshll_n_u16(vget_low_u16(r0a), 16)), x0);
+ a1 = vfmaq_f32(a1, vreinterpretq_f32_u32(vshll_n_u16(vget_high_u16(r0a), 16)), x1);
+ a2 = vfmaq_f32(a2, vreinterpretq_f32_u32(vshll_n_u16(vget_low_u16(r0b), 16)), x2);
+ a3 = vfmaq_f32(a3, vreinterpretq_f32_u32(vshll_n_u16(vget_high_u16(r0b), 16)), x3);
+ a0 = vfmaq_f32(a0, vreinterpretq_f32_u32(vshll_n_u16(vget_low_u16(r0c), 16)), x4);
+ a1 = vfmaq_f32(a1, vreinterpretq_f32_u32(vshll_n_u16(vget_high_u16(r0c), 16)), x5);
+ a2 = vfmaq_f32(a2, vreinterpretq_f32_u32(vshll_n_u16(vget_low_u16(r0d), 16)), x6);
+ a3 = vfmaq_f32(a3, vreinterpretq_f32_u32(vshll_n_u16(vget_high_u16(r0d), 16)), x7);
+
+ uint16x8_t r1a = vld1q_u16(w1 + k);
+ uint16x8_t r1b = vld1q_u16(w1 + k + 8);
+ uint16x8_t r1c = vld1q_u16(w1 + k + 16);
+ uint16x8_t r1d = vld1q_u16(w1 + k + 24);
+ b0 = vfmaq_f32(b0, vreinterpretq_f32_u32(vshll_n_u16(vget_low_u16(r1a), 16)), x0);
+ b1 = vfmaq_f32(b1, vreinterpretq_f32_u32(vshll_n_u16(vget_high_u16(r1a), 16)), x1);
+ b2 = vfmaq_f32(b2, vreinterpretq_f32_u32(vshll_n_u16(vget_low_u16(r1b), 16)), x2);
+ b3 = vfmaq_f32(b3, vreinterpretq_f32_u32(vshll_n_u16(vget_high_u16(r1b), 16)), x3);
+ b0 = vfmaq_f32(b0, vreinterpretq_f32_u32(vshll_n_u16(vget_low_u16(r1c), 16)), x4);
+ b1 = vfmaq_f32(b1, vreinterpretq_f32_u32(vshll_n_u16(vget_high_u16(r1c), 16)), x5);
+ b2 = vfmaq_f32(b2, vreinterpretq_f32_u32(vshll_n_u16(vget_low_u16(r1d), 16)), x6);
+ b3 = vfmaq_f32(b3, vreinterpretq_f32_u32(vshll_n_u16(vget_high_u16(r1d), 16)), x7);
+ }
+ for (; k + 8 <= in_dim; k += 8) {
+ float32x4_t x0 = vld1q_f32(x + k);
+ float32x4_t x1 = vld1q_f32(x + k + 4);
+ uint16x8_t r0 = vld1q_u16(w0 + k);
+ uint16x8_t r1 = vld1q_u16(w1 + k);
+ a0 = vfmaq_f32(a0, vreinterpretq_f32_u32(vshll_n_u16(vget_low_u16(r0), 16)), x0);
+ a1 = vfmaq_f32(a1, vreinterpretq_f32_u32(vshll_n_u16(vget_high_u16(r0), 16)), x1);
+ b0 = vfmaq_f32(b0, vreinterpretq_f32_u32(vshll_n_u16(vget_low_u16(r1), 16)), x0);
+ b1 = vfmaq_f32(b1, vreinterpretq_f32_u32(vshll_n_u16(vget_high_u16(r1), 16)), x1);
+ }
+ s0 += vaddvq_f32(vaddq_f32(vaddq_f32(a0, a2), vaddq_f32(a1, a3)));
+ s1 += vaddvq_f32(vaddq_f32(vaddq_f32(b0, b2), vaddq_f32(b1, b3)));
+
+ for (; k < in_dim; k++) {
+ uint32_t bits0 = ((uint32_t)w0[k]) << 16;
+ uint32_t bits1 = ((uint32_t)w1[k]) << 16;
+ float wv0, wv1;
+ memcpy(&wv0, &bits0, sizeof(float));
+ memcpy(&wv1, &bits1, sizeof(float));
+ s0 += wv0 * x[k];
+ s1 += wv1 * x[k];
+ }
+ y[o] = s0;
+ y[o + 1] = s1;
+ }
+
+ /* Handle remaining odd row */
+ for (; o < out_dim; o++) {
+ const uint16_t *w_row = W_bf16 + (size_t)o * in_dim;
+ float sum = bias ? bias[o] : 0.0f;
+ int k = 0;
+
+ float32x4_t acc0 = vdupq_n_f32(0.0f);
+ float32x4_t acc1 = vdupq_n_f32(0.0f);
+ for (; k + 8 <= in_dim; k += 8) {
+ uint16x8_t bf = vld1q_u16(w_row + k);
+ acc0 = vfmaq_f32(acc0, vreinterpretq_f32_u32(vshll_n_u16(vget_low_u16(bf), 16)),
+ vld1q_f32(x + k));
+ acc1 = vfmaq_f32(acc1, vreinterpretq_f32_u32(vshll_n_u16(vget_high_u16(bf), 16)),
+ vld1q_f32(x + k + 4));
+ }
+ sum += vaddvq_f32(vaddq_f32(acc0, acc1));
+
+ for (; k < in_dim; k++) {
+ uint32_t f32_bits = ((uint32_t)w_row[k]) << 16;
+ float w_val;
+ memcpy(&w_val, &f32_bits, sizeof(float));
+ sum += w_val * x[k];
+ }
+ y[o] = sum;
+ }
+}
+
+#endif /* __ARM_NEON */
diff --git a/libffwd/norm.c b/libffwd/norm.c
new file mode 100644
index 0000000..57c93db
--- /dev/null
+++ b/libffwd/norm.c
@@ -0,0 +1,138 @@
+/*
+ * Normalization kernels: RMSNorm (Qwen) and LayerNorm (BERT), plus the
+ * per-head RMSNorm used for QK-norm.
+ */
+
+#include "kernels.h"
+#include "threadpool.h"
+
+#include <math.h>
+#include <stdlib.h>
+#include <string.h>
+
+#ifdef USE_BLAS
+# ifdef __APPLE__
+# include <Accelerate/Accelerate.h>
+# else
+# include <cblas.h>
+# endif
+#endif
+
+#ifndef M_PI
+# define M_PI 3.14159265358979323846
+#endif
+
+/* Normalization */
+
+/* Rows split across the pool only when the tensor is big enough to pay
+ * for the dispatch. */
+#define RMS_NORM_PARALLEL_ELEMS 262144
+
+/* The sum of squares and the scaled write-back are plain loops: the compiler
+ * auto-vectorizes both in place, which is faster than reducing through a
+ * two-input dot kernel that reloads the row and is reduction-latency bound. */
+static void rms_norm_range(
+ float *out, const float *x, const float *weight, int start, int end, int hidden, float eps) {
+ for (int s = start; s < end; s++) {
+ const float *x_row = x + (size_t)s * hidden;
+ float *out_row = out + (size_t)s * hidden;
+
+ float sum_sq = 0.0f;
+ for (int i = 0; i < hidden; i++)
+ sum_sq += x_row[i] * x_row[i];
+ float rms_inv = 1.0f / sqrtf(sum_sq / hidden + eps);
+ for (int i = 0; i < hidden; i++)
+ out_row[i] = x_row[i] * rms_inv * weight[i];
+ }
+}
+
+typedef struct {
+ float *out;
+ const float *x;
+ const float *weight;
+ int seq_len;
+ int hidden;
+ float eps;
+} rms_norm_task_t;
+
+static void rms_norm_worker(int tid, int n_threads, void *arg) {
+ rms_norm_task_t *t = (rms_norm_task_t *)arg;
+ int chunk = (t->seq_len + n_threads - 1) / n_threads;
+ int start = tid * chunk;
+ int end = start + chunk;
+ if (end > t->seq_len)
+ end = t->seq_len;
+ if (start >= end)
+ return;
+ rms_norm_range(t->out, t->x, t->weight, start, end, t->hidden, t->eps);
+}
+
+void rms_norm(float *out, const float *x, const float *weight, int seq_len, int hidden, float eps) {
+ if (seq_len <= 0 || hidden <= 0)
+ return;
+
+ long long elems = (long long)seq_len * hidden;
+ if (tp_num_threads() > 1 && elems >= RMS_NORM_PARALLEL_ELEMS) {
+ rms_norm_task_t task = {
+ .out = out,
+ .x = x,
+ .weight = weight,
+ .seq_len = seq_len,
+ .hidden = hidden,
+ .eps = eps,
+ };
+ parallel_for(rms_norm_worker, &task);
+ } else {
+ rms_norm_range(out, x, weight, 0, seq_len, hidden, eps);
+ }
+}
+
+void rms_norm_per_head(
+ float *x, const float *weight, int seq_len, int n_heads, int head_dim, float eps) {
+ /* x is [seq, n_heads * head_dim] - normalize each [head_dim] segment */
+ int hidden = n_heads * head_dim;
+ for (int s = 0; s < seq_len; s++) {
+ for (int h = 0; h < n_heads; h++) {
+ float *vec = x + s * hidden + h * head_dim;
+
+ float sum_sq = 0.0f;
+ for (int d = 0; d < head_dim; d++)
+ sum_sq += vec[d] * vec[d];
+ float rms_inv = 1.0f / sqrtf(sum_sq / head_dim + eps);
+ for (int d = 0; d < head_dim; d++)
+ vec[d] = vec[d] * rms_inv * weight[d];
+ }
+ }
+}
+
+/* Mean-subtracting LayerNorm with bias. Safe in place (out may alias x): each
+ * row's mean and variance are reduced before the row is rewritten. Scalar for
+ * now; LayerNorm is not GEMM-bound, so SIMD/threading is a later perf step. */
+void layer_norm(float *out,
+ const float *x,
+ const float *gamma,
+ const float *beta,
+ int seq_len,
+ int hidden,
+ float eps) {
+ if (seq_len <= 0 || hidden <= 0)
+ return;
+ float inv_h = 1.0f / (float)hidden;
+ for (int s = 0; s < seq_len; s++) {
+ const float *row = x + (size_t)s * hidden;
+ float *dst = out + (size_t)s * hidden;
+ float mean = 0.0f;
+ for (int d = 0; d < hidden; d++)
+ mean += row[d];
+ mean *= inv_h;
+ float var = 0.0f;
+ for (int d = 0; d < hidden; d++) {
+ float diff = row[d] - mean;
+ var += diff * diff;
+ }
+ var *= inv_h;
+ float inv_std = 1.0f / sqrtf(var + eps);
+ for (int d = 0; d < hidden; d++)
+ dst[d] = gamma[d] * (row[d] - mean) * inv_std + beta[d];
+ }
+}
diff --git a/libffwd/rope.c b/libffwd/rope.c
new file mode 100644
index 0000000..29cbb17
--- /dev/null
+++ b/libffwd/rope.c
@@ -0,0 +1,137 @@
+/*
+ * Rotary position embeddings: cache-free NeoX-style RoPE compute and apply.
+ */
+
+#include "kernels.h"
+#include "impl.h"
+
+#include <math.h>
+#include <stdlib.h>
+#include <string.h>
+
+#if (defined(__AVX512F__) || defined(__AVX2__)) && \
+ (defined(__x86_64__) || defined(__i386__) || defined(_M_X64) || defined(_M_IX86))
+# include <immintrin.h>
+#endif
+#if defined(__ARM_NEON) || defined(__ARM_NEON__)
+# include <arm_neon.h>
+#endif
+
+#ifdef USE_BLAS
+# ifdef __APPLE__
+# include <Accelerate/Accelerate.h>
+# else
+# include <cblas.h>
+# endif
+#endif
+
+#ifndef M_PI
+# define M_PI 3.14159265358979323846
+#endif
+
+/* Position embeddings */
+
+void compute_rope_neox(
+ float *cos_out, float *sin_out, const int *positions, int seq, int head_dim, float theta) {
+ int half = head_dim / 2;
+
+ for (int s = 0; s < seq; s++) {
+ float pos = (float)positions[s];
+ for (int d = 0; d < half; d++) {
+ float freq = 1.0f / powf(theta, (float)(2 * d) / (float)head_dim);
+ float angle = pos * freq;
+ float c = cosf(angle);
+ float sn = sinf(angle);
+ /* Duplicate for full head_dim */
+ cos_out[s * head_dim + d] = c;
+ cos_out[s * head_dim + half + d] = c;
+ sin_out[s * head_dim + d] = sn;
+ sin_out[s * head_dim + half + d] = sn;
+ }
+ }
+}
+
+void apply_rope_neox(
+ float *x, const float *cos_vals, const float *sin_vals, int seq, int n_heads, int head_dim) {
+ /*
+ * NeoX split-half style:
+ * x1 = x[..., :half], x2 = x[..., half:]
+ * rotated = cat(-x2, x1)
+ * result = x * cos + rotated * sin
+ */
+ int half = head_dim / 2;
+ int hidden = n_heads * head_dim;
+
+ for (int s = 0; s < seq; s++) {
+ const float *c = cos_vals + s * head_dim;
+ const float *sn = sin_vals + s * head_dim;
+
+ for (int h = 0; h < n_heads; h++) {
+ float *vec = x + s * hidden + h * head_dim;
+
+#if defined(__AVX512F__) && defined(__FMA__)
+ int d = 0;
+ for (; d + 16 <= half; d += 16) {
+ __m512 x1 = _mm512_loadu_ps(vec + d);
+ __m512 x2 = _mm512_loadu_ps(vec + half + d);
+ /* RoPE cache duplicates cos/sin across halves. */
+ __m512 cc = _mm512_loadu_ps(c + d);
+ __m512 ss = _mm512_loadu_ps(sn + d);
+ __m512 new1 = _mm512_fmsub_ps(x1, cc, _mm512_mul_ps(x2, ss));
+ __m512 new2 = _mm512_fmadd_ps(x2, cc, _mm512_mul_ps(x1, ss));
+ _mm512_storeu_ps(vec + d, new1);
+ _mm512_storeu_ps(vec + half + d, new2);
+ }
+ for (; d < half; d++) {
+ float x1 = vec[d];
+ float x2 = vec[half + d];
+ vec[d] = x1 * c[d] + (-x2) * sn[d];
+ vec[half + d] = x2 * c[half + d] + x1 * sn[half + d];
+ }
+#elif defined(__AVX2__) && defined(__FMA__)
+ int d = 0;
+ for (; d + 8 <= half; d += 8) {
+ __m256 x1 = _mm256_loadu_ps(vec + d);
+ __m256 x2 = _mm256_loadu_ps(vec + half + d);
+ __m256 cc = _mm256_loadu_ps(c + d);
+ __m256 ss = _mm256_loadu_ps(sn + d);
+ __m256 new1 = _mm256_fmsub_ps(x1, cc, _mm256_mul_ps(x2, ss));
+ __m256 new2 = _mm256_fmadd_ps(x2, cc, _mm256_mul_ps(x1, ss));
+ _mm256_storeu_ps(vec + d, new1);
+ _mm256_storeu_ps(vec + half + d, new2);
+ }
+ for (; d < half; d++) {
+ float x1 = vec[d];
+ float x2 = vec[half + d];
+ vec[d] = x1 * c[d] + (-x2) * sn[d];
+ vec[half + d] = x2 * c[half + d] + x1 * sn[half + d];
+ }
+#elif defined(__ARM_NEON) || defined(__ARM_NEON__)
+ int d = 0;
+ for (; d + 4 <= half; d += 4) {
+ float32x4_t x1 = vld1q_f32(vec + d);
+ float32x4_t x2 = vld1q_f32(vec + half + d);
+ float32x4_t cc = vld1q_f32(c + d);
+ float32x4_t ss = vld1q_f32(sn + d);
+ float32x4_t new1 = vmlsq_f32(vmulq_f32(x1, cc), x2, ss);
+ float32x4_t new2 = vfmaq_f32(vmulq_f32(x2, cc), x1, ss);
+ vst1q_f32(vec + d, new1);
+ vst1q_f32(vec + half + d, new2);
+ }
+ for (; d < half; d++) {
+ float x1 = vec[d];
+ float x2 = vec[half + d];
+ vec[d] = x1 * c[d] + (-x2) * sn[d];
+ vec[half + d] = x2 * c[half + d] + x1 * sn[half + d];
+ }
+#else
+ for (int d = 0; d < half; d++) {
+ float x1 = vec[d]; /* first half */
+ float x2 = vec[half + d]; /* second half */
+ vec[d] = x1 * c[d] + (-x2) * sn[d];
+ vec[half + d] = x2 * c[half + d] + x1 * sn[half + d];
+ }
+#endif
+ }
+ }
+}
diff --git a/libffwd/safetensors.c b/libffwd/safetensors.c
new file mode 100644
index 0000000..f2c9b26
--- /dev/null
+++ b/libffwd/safetensors.c
@@ -0,0 +1,518 @@
+#include "safetensors.h"
+
+#include <dirent.h>
+#include <fcntl.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <sys/mman.h>
+#include <sys/stat.h>
+#include <unistd.h>
+
+/* Minimal JSON parser for safetensors header */
+/* TODO: consider replacing with yyjson */
+
+static void skip_whitespace(const char **p) {
+ while (**p == ' ' || **p == '\n' || **p == '\r' || **p == '\t')
+ (*p)++;
+}
+
+static int parse_string(const char **p, char *out, size_t max_len) {
+ skip_whitespace(p);
+ if (**p != '"')
+ return -1;
+ (*p)++;
+ size_t i = 0;
+ while (**p && **p != '"' && i < max_len - 1) {
+ if (**p == '\\') {
+ (*p)++;
+ if (**p == 'n')
+ out[i++] = '\n';
+ else if (**p == 't')
+ out[i++] = '\t';
+ else if (**p == '"')
+ out[i++] = '"';
+ else if (**p == '\\')
+ out[i++] = '\\';
+ else
+ out[i++] = **p;
+ } else {
+ out[i++] = **p;
+ }
+ (*p)++;
+ }
+ out[i] = '\0';
+ if (**p != '"')
+ return -1;
+ (*p)++;
+ return 0;
+}
+
+static int parse_int(const char **p, int64_t *out) {
+ skip_whitespace(p);
+ int64_t val = 0;
+ int neg = 0;
+ if (**p == '-') {
+ neg = 1;
+ (*p)++;
+ }
+ if (**p < '0' || **p > '9')
+ return -1;
+ while (**p >= '0' && **p <= '9') {
+ val = val * 10 + (**p - '0');
+ (*p)++;
+ }
+ *out = neg ? -val : val;
+ return 0;
+}
+
+static safetensor_dtype_t parse_dtype(const char *s) {
+ if (strcmp(s, "F32") == 0)
+ return DTYPE_F32;
+ if (strcmp(s, "F16") == 0)
+ return DTYPE_F16;
+ if (strcmp(s, "BF16") == 0)
+ return DTYPE_BF16;
+ if (strcmp(s, "I32") == 0)
+ return DTYPE_I32;
+ if (strcmp(s, "I64") == 0)
+ return DTYPE_I64;
+ if (strcmp(s, "BOOL") == 0)
+ return DTYPE_BOOL;
+ return DTYPE_UNKNOWN;
+}
+
+static int parse_tensor_entry(const char **p, safetensor_t *t) {
+ skip_whitespace(p);
+ if (**p != '{')
+ return -1;
+ (*p)++;
+
+ t->dtype = DTYPE_UNKNOWN;
+ t->ndim = 0;
+ t->data_offset = 0;
+ t->data_size = 0;
+
+ while (**p && **p != '}') {
+ skip_whitespace(p);
+ if (**p == ',') {
+ (*p)++;
+ continue;
+ }
+
+ char key[64];
+ if (parse_string(p, key, sizeof(key)) != 0)
+ return -1;
+ skip_whitespace(p);
+ if (**p != ':')
+ return -1;
+ (*p)++;
+ skip_whitespace(p);
+
+ if (strcmp(key, "dtype") == 0) {
+ char dtype_str[32];
+ if (parse_string(p, dtype_str, sizeof(dtype_str)) != 0)
+ return -1;
+ t->dtype = parse_dtype(dtype_str);
+ } else if (strcmp(key, "shape") == 0) {
+ if (**p != '[')
+ return -1;
+ (*p)++;
+ t->ndim = 0;
+ while (**p && **p != ']') {
+ skip_whitespace(p);
+ if (**p == ',') {
+ (*p)++;
+ continue;
+ }
+ if (t->ndim >= 8)
+ return -1;
+ if (parse_int(p, &t->shape[t->ndim]) != 0)
+ return -1;
+ t->ndim++;
+ }
+ if (**p != ']')
+ return -1;
+ (*p)++;
+ } else if (strcmp(key, "data_offsets") == 0) {
+ if (**p != '[')
+ return -1;
+ (*p)++;
+ skip_whitespace(p);
+ int64_t start_i;
+ if (parse_int(p, &start_i) != 0)
+ return -1;
+ skip_whitespace(p);
+ if (**p != ',')
+ return -1;
+ (*p)++;
+ skip_whitespace(p);
+ int64_t end_i;
+ if (parse_int(p, &end_i) != 0)
+ return -1;
+ if (start_i < 0 || end_i < start_i)
+ return -1;
+ t->data_offset = (size_t)start_i;
+ t->data_size = (size_t)(end_i - start_i);
+ skip_whitespace(p);
+ if (**p != ']')
+ return -1;
+ (*p)++;
+ } else {
+ /* Skip unknown value */
+ if (**p == '"') {
+ (*p)++;
+ while (**p && **p != '"') {
+ if (**p == '\\')
+ (*p)++;
+ if (**p)
+ (*p)++;
+ }
+ if (**p == '"')
+ (*p)++;
+ } else if (**p == '[') {
+ int depth = 1;
+ (*p)++;
+ while (**p && depth > 0) {
+ if (**p == '[')
+ depth++;
+ else if (**p == ']')
+ depth--;
+ (*p)++;
+ }
+ } else if (**p == '{') {
+ int depth = 1;
+ (*p)++;
+ while (**p && depth > 0) {
+ if (**p == '{')
+ depth++;
+ else if (**p == '}')
+ depth--;
+ (*p)++;
+ }
+ } else {
+ while (**p && **p != ',' && **p != '}')
+ (*p)++;
+ }
+ }
+ }
+ if (**p != '}')
+ return -1;
+ (*p)++;
+ return 0;
+}
+
+static int parse_header(safetensors_file_t *sf) {
+ const char *p = sf->header_json;
+ skip_whitespace(&p);
+ if (*p != '{')
+ return -1;
+ p++;
+
+ sf->num_tensors = 0;
+
+ while (*p && *p != '}') {
+ skip_whitespace(&p);
+ if (*p == ',') {
+ p++;
+ continue;
+ }
+ if (*p == '}')
+ break;
+
+ char name[256];
+ if (parse_string(&p, name, sizeof(name)) != 0)
+ return -1;
+ skip_whitespace(&p);
+ if (*p != ':')
+ return -1;
+ p++;
+
+ if (strcmp(name, "__metadata__") == 0) {
+ skip_whitespace(&p);
+ if (*p == '{') {
+ int depth = 1;
+ p++;
+ while (*p && depth > 0) {
+ if (*p == '{')
+ depth++;
+ else if (*p == '}')
+ depth--;
+ p++;
+ }
+ }
+ continue;
+ }
+
+ if (sf->num_tensors >= SAFETENSORS_MAX_TENSORS) {
+ fprintf(stderr, "safetensors: too many tensors in %s (max %d)\n",
+ sf->path ? sf->path : "<unknown>", SAFETENSORS_MAX_TENSORS);
+ return -1;
+ }
+
+ safetensor_t *t = &sf->tensors[sf->num_tensors];
+ snprintf(t->name, sizeof(t->name), "%s", name);
+ if (parse_tensor_entry(&p, t) != 0)
+ return -1;
+ sf->num_tensors++;
+ }
+ if (*p != '}')
+ return -1;
+ return 0;
+}
+
+/* Single file operations */
+
+safetensors_file_t *safetensors_open(const char *path) {
+ int fd = open(path, O_RDONLY);
+ if (fd < 0)
+ return NULL;
+
+ struct stat st;
+ if (fstat(fd, &st) < 0) {
+ close(fd);
+ return NULL;
+ }
+
+ size_t file_size = (size_t)st.st_size;
+ if (file_size < 8) {
+ close(fd);
+ return NULL;
+ }
+
+ void *data = mmap(NULL, file_size, PROT_READ, MAP_PRIVATE, fd, 0);
+ close(fd);
+ if (data == MAP_FAILED)
+ return NULL;
+
+ uint64_t header_size = 0;
+ memcpy(&header_size, data, 8);
+ if (header_size > file_size - 8) {
+ munmap(data, file_size);
+ return NULL;
+ }
+
+ safetensors_file_t *sf = calloc(1, sizeof(safetensors_file_t));
+ if (!sf) {
+ munmap(data, file_size);
+ return NULL;
+ }
+
+ sf->path = strdup(path);
+ sf->data = data;
+ sf->file_size = file_size;
+ sf->header_size = (size_t)header_size;
+
+ sf->header_json = malloc(header_size + 1);
+ if (!sf->header_json) {
+ safetensors_close(sf);
+ return NULL;
+ }
+ memcpy(sf->header_json, (char *)data + 8, header_size);
+ sf->header_json[header_size] = '\0';
+
+ if (parse_header(sf) != 0) {
+ safetensors_close(sf);
+ return NULL;
+ }
+
+ return sf;
+}
+
+void safetensors_close(safetensors_file_t *sf) {
+ if (!sf)
+ return;
+ if (sf->data)
+ munmap(sf->data, sf->file_size);
+ free(sf->path);
+ free(sf->header_json);
+ free(sf);
+}
+
+const void *safetensors_data(const safetensors_file_t *sf, const safetensor_t *t) {
+ return (const char *)sf->data + 8 + sf->header_size + t->data_offset;
+}
+
+int64_t safetensor_numel(const safetensor_t *t) {
+ int64_t n = 1;
+ for (int i = 0; i < t->ndim; i++)
+ n *= t->shape[i];
+ return n;
+}
+
+/* Multi-shard operations */
+
+static int cmp_shard_names(const void *a, const void *b) {
+ const char *sa = (const char *)a;
+ const char *sb = (const char *)b;
+ return strcmp(sa, sb);
+}
+
+static int parse_shard_name(const char *name, int *idx, int *total) {
+ int i = 0, n = 0, consumed = 0;
+ if (sscanf(name, "model-%d-of-%d.safetensors%n", &i, &n, &consumed) != 2)
+ return -1;
+ if (name[consumed] != '\0' || i <= 0 || n <= 0 || i > n)
+ return -1;
+ *idx = i;
+ *total = n;
+ return 0;
+}
+
+multi_safetensors_t *multi_safetensors_open(const char *model_dir) {
+ multi_safetensors_t *ms = calloc(1, sizeof(multi_safetensors_t));
+ if (!ms)
+ return NULL;
+
+ char path[4096];
+
+ /* Try single file first */
+ snprintf(path, sizeof(path), "%s/model.safetensors", model_dir);
+ safetensors_file_t *sf = safetensors_open(path);
+ if (sf) {
+ ms->shards[0] = sf;
+ ms->num_shards = 1;
+ return ms;
+ }
+
+ /* Scan directory for shard files */
+ DIR *dir = opendir(model_dir);
+ if (!dir) {
+ free(ms);
+ return NULL;
+ }
+
+ struct dirent *entry;
+ char shard_names[SAFETENSORS_MAX_SHARDS][256];
+ int seen[SAFETENSORS_MAX_SHARDS] = {0};
+ int n_shards = 0;
+ int expected_total = 0;
+
+ while ((entry = readdir(dir)) != NULL) {
+ if (strncmp(entry->d_name, "model-", 6) == 0 &&
+ strstr(entry->d_name, ".safetensors") != NULL) {
+ int shard_idx = 0, shard_total = 0;
+ if (parse_shard_name(entry->d_name, &shard_idx, &shard_total) != 0) {
+ fprintf(stderr, "multi_safetensors_open: bad shard name: %s\n", entry->d_name);
+ closedir(dir);
+ free(ms);
+ return NULL;
+ }
+ if (shard_total > SAFETENSORS_MAX_SHARDS) {
+ fprintf(stderr, "multi_safetensors_open: too many shards (%d > %d)\n", shard_total,
+ SAFETENSORS_MAX_SHARDS);
+ closedir(dir);
+ free(ms);
+ return NULL;
+ }
+ if (expected_total == 0) {
+ expected_total = shard_total;
+ } else if (expected_total != shard_total) {
+ fprintf(stderr, "multi_safetensors_open: inconsistent shard total in %s\n",
+ entry->d_name);
+ closedir(dir);
+ free(ms);
+ return NULL;
+ }
+ if (seen[shard_idx - 1]) {
+ fprintf(stderr, "multi_safetensors_open: duplicate shard index %d\n", shard_idx);
+ closedir(dir);
+ free(ms);
+ return NULL;
+ }
+ seen[shard_idx - 1] = 1;
+
+ snprintf(shard_names[n_shards], sizeof(shard_names[n_shards]), "%s", entry->d_name);
+ n_shards++;
+ }
+ }
+ closedir(dir);
+
+ if (n_shards == 0) {
+ fprintf(stderr, "multi_safetensors_open: no safetensors files in %s\n", model_dir);
+ free(ms);
+ return NULL;
+ }
+ if (expected_total != n_shards) {
+ fprintf(stderr, "multi_safetensors_open: expected %d shard(s), found %d in %s\n",
+ expected_total, n_shards, model_dir);
+ free(ms);
+ return NULL;
+ }
+ for (int i = 0; i < expected_total; i++) {
+ if (!seen[i]) {
+ fprintf(stderr, "multi_safetensors_open: missing shard %d of %d in %s\n", i + 1,
+ expected_total, model_dir);
+ free(ms);
+ return NULL;
+ }
+ }
+
+ /* Sort shard names to ensure consistent ordering */
+ qsort(shard_names, n_shards, sizeof(shard_names[0]), cmp_shard_names);
+
+ /* Open each shard */
+ for (int i = 0; i < n_shards; i++) {
+ snprintf(path, sizeof(path), "%s/%s", model_dir, shard_names[i]);
+ ms->shards[i] = safetensors_open(path);
+ if (!ms->shards[i]) {
+ fprintf(stderr, "multi_safetensors_open: failed to open %s\n", path);
+ multi_safetensors_close(ms);
+ return NULL;
+ }
+ }
+ ms->num_shards = n_shards;
+ return ms;
+}
+
+void multi_safetensors_close(multi_safetensors_t *ms) {
+ if (!ms)
+ return;
+ for (int i = 0; i < ms->num_shards; i++) {
+ safetensors_close(ms->shards[i]);
+ }
+ free(ms);
+}
+
+int multi_safetensors_data_nbytes(const multi_safetensors_t *ms, size_t *out_nbytes) {
+ if (!ms || !out_nbytes)
+ return -1;
+ size_t total = 0;
+ for (int s = 0; s < ms->num_shards; s++) {
+ const safetensors_file_t *sf = ms->shards[s];
+ for (int i = 0; i < sf->num_tensors; i++) {
+ size_t n = sf->tensors[i].data_size;
+ if (n > SIZE_MAX - total)
+ return -1;
+ total += n;
+ }
+ }
+ *out_nbytes = total;
+ return 0;
+}
+
+const safetensor_t *
+multi_safetensors_find(const multi_safetensors_t *ms, const char *name, safetensors_file_t **out_sf) {
+ for (int s = 0; s < ms->num_shards; s++) {
+ safetensors_file_t *sf = ms->shards[s];
+ for (int i = 0; i < sf->num_tensors; i++) {
+ if (strcmp(sf->tensors[i].name, name) == 0) {
+ if (out_sf)
+ *out_sf = sf;
+ return &sf->tensors[i];
+ }
+ }
+ }
+ return NULL;
+}
+
+const char *multi_safetensors_weight_prefix(const multi_safetensors_t *ms, const char *tensor_name) {
+ if (multi_safetensors_find(ms, tensor_name, NULL))
+ return "";
+
+ char prefixed[sizeof(((safetensor_t *)0)->name)];
+ int n = snprintf(prefixed, sizeof(prefixed), "model.%s", tensor_name);
+ if (n < 0 || (size_t)n >= sizeof(prefixed))
+ return NULL;
+ return multi_safetensors_find(ms, prefixed, NULL) ? "model." : NULL;
+}
diff --git a/libffwd/safetensors.h b/libffwd/safetensors.h
new file mode 100644
index 0000000..f2ea9fd
--- /dev/null
+++ b/libffwd/safetensors.h
@@ -0,0 +1,71 @@
+/*
+ * Safetensors file format reader with multi-shard support.
+ */
+
+#ifndef SAFETENSORS_H
+#define SAFETENSORS_H
+
+#include <stddef.h>
+#include <stdint.h>
+
+#define SAFETENSORS_MAX_TENSORS 1024
+#define SAFETENSORS_MAX_SHARDS 8
+
+typedef enum {
+ DTYPE_F32 = 0,
+ DTYPE_F16 = 1,
+ DTYPE_BF16 = 2,
+ DTYPE_I32 = 3,
+ DTYPE_I64 = 4,
+ DTYPE_BOOL = 5,
+ DTYPE_UNKNOWN = -1
+} safetensor_dtype_t;
+
+typedef struct {
+ char name[256];
+ safetensor_dtype_t dtype;
+ int ndim;
+ int64_t shape[8];
+ size_t data_offset;
+ size_t data_size;
+} safetensor_t;
+
+typedef struct {
+ char *path;
+ void *data;
+ size_t file_size;
+ size_t header_size;
+ char *header_json;
+ int num_tensors;
+ safetensor_t tensors[SAFETENSORS_MAX_TENSORS];
+} safetensors_file_t;
+
+/* Multi-shard wrapper: opens all shard files and provides unified tensor lookup */
+typedef struct {
+ safetensors_file_t *shards[SAFETENSORS_MAX_SHARDS];
+ int num_shards;
+} multi_safetensors_t;
+
+/* Open a single safetensors file (memory-mapped) */
+safetensors_file_t *safetensors_open(const char *path);
+void safetensors_close(safetensors_file_t *sf);
+
+/* Open model from directory (auto-detects single file or multi-shard) */
+multi_safetensors_t *multi_safetensors_open(const char *model_dir);
+void multi_safetensors_close(multi_safetensors_t *ms);
+int multi_safetensors_data_nbytes(const multi_safetensors_t *ms, size_t *out_nbytes);
+
+/* Find a tensor by name across all shards */
+const safetensor_t *
+multi_safetensors_find(const multi_safetensors_t *ms, const char *name, safetensors_file_t **out_sf);
+
+/* Resolve an optional Hugging Face "model." namespace for a backbone tensor.
+ * Returns "", "model.", or NULL when neither form exists. */
+const char *multi_safetensors_weight_prefix(const multi_safetensors_t *ms, const char *tensor_name);
+
+/* Get raw pointer to tensor data (within mmap'd region) */
+const void *safetensors_data(const safetensors_file_t *sf, const safetensor_t *t);
+
+int64_t safetensor_numel(const safetensor_t *t);
+
+#endif /* SAFETENSORS_H */
diff --git a/libffwd/sentencepiece.c b/libffwd/sentencepiece.c
new file mode 100644
index 0000000..e5e8393
--- /dev/null
+++ b/libffwd/sentencepiece.c
@@ -0,0 +1,947 @@
+/*
+ * SentencePiece Unigram tokenizer.
+ *
+ * The implementation reads the small subset of ModelProto needed at runtime:
+ * pieces, scores, piece types, trainer model_type, and normalizer options. The
+ * normalizer supports SentencePiece's precompiled charsmap format used by
+ * nmt_nfkc, then the encoder runs the standard Unigram Viterbi dynamic program
+ * over UTF-8 byte offsets.
+ */
+
+#include "sentencepiece.h"
+
+#include <errno.h>
+#include <float.h>
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+enum {
+ SP_MODEL_UNIGRAM = 1,
+ SP_PIECE_NORMAL = 1,
+ SP_PIECE_UNKNOWN = 2,
+ SP_PIECE_CONTROL = 3,
+ SP_PIECE_USER_DEFINED = 4,
+ SP_PIECE_UNUSED = 5,
+ SP_PIECE_BYTE = 6,
+};
+
+typedef struct {
+ const char *key;
+ uint16_t len;
+ int val;
+} sp_entry_t;
+
+typedef struct {
+ int id;
+ int prev;
+ double score;
+} sp_best_t;
+
+struct tok_spm_workspace {
+ char *norm;
+ size_t norm_len;
+ size_t norm_cap;
+ sp_best_t *best;
+ int best_cap;
+ int *ids;
+ int ids_cap;
+};
+
+static uint64_t fnv1a_bytes(const char *s, size_t n) {
+ uint64_t h = 1469598103934665603ULL;
+ for (size_t i = 0; i < n; i++) {
+ h ^= (unsigned char)s[i];
+ h *= 1099511628211ULL;
+ }
+ return h;
+}
+
+static int next_pow2(int x) {
+ int p = 1;
+ while (p < x && p <= (1 << 29))
+ p <<= 1;
+ return p;
+}
+
+static int map_put(sp_entry_t *map, int cap, const char *key, int len, int val) {
+ if (len <= 0 || len > UINT16_MAX)
+ return -1;
+ uint64_t mask = (uint64_t)cap - 1;
+ int pos = (int)(fnv1a_bytes(key, (size_t)len) & mask);
+ while (map[pos].key) {
+ if (map[pos].len == (uint16_t)len && memcmp(map[pos].key, key, (size_t)len) == 0) {
+ map[pos].val = val;
+ return 0;
+ }
+ pos = (int)((pos + 1) & (int)mask);
+ }
+ map[pos].key = key;
+ map[pos].len = (uint16_t)len;
+ map[pos].val = val;
+ return 0;
+}
+
+static int map_get(const sp_entry_t *map, int cap, const char *key, int len) {
+ if (!map || len <= 0)
+ return -1;
+ uint64_t mask = (uint64_t)cap - 1;
+ int pos = (int)(fnv1a_bytes(key, (size_t)len) & mask);
+ while (map[pos].key) {
+ if (map[pos].len == (uint16_t)len && memcmp(map[pos].key, key, (size_t)len) == 0)
+ return map[pos].val;
+ pos = (int)((pos + 1) & (int)mask);
+ }
+ return -1;
+}
+
+static int is_tokenizable_type(int type) {
+ return type == SP_PIECE_NORMAL || type == SP_PIECE_USER_DEFINED || type == SP_PIECE_UNUSED ||
+ type == SP_PIECE_BYTE;
+}
+
+static int reserve_chars(char **buf, size_t *cap, size_t need) {
+ if (need <= *cap)
+ return 0;
+ size_t nc = *cap ? *cap : 128;
+ while (nc < need) {
+ if (nc > SIZE_MAX / 2)
+ return -1;
+ nc *= 2;
+ }
+ char *p = (char *)realloc(*buf, nc);
+ if (!p)
+ return -1;
+ *buf = p;
+ *cap = nc;
+ return 0;
+}
+
+static int append_bytes(char **buf, size_t *len, size_t *cap, const char *s, size_t n) {
+ if (n > SIZE_MAX - *len - 1 || reserve_chars(buf, cap, *len + n + 1) != 0)
+ return -1;
+ memcpy(*buf + *len, s, n);
+ *len += n;
+ (*buf)[*len] = '\0';
+ return 0;
+}
+
+static int reserve_best(tok_spm_workspace_t *ws, int need) {
+ if (need <= ws->best_cap)
+ return 0;
+ int nc = ws->best_cap ? ws->best_cap : 128;
+ while (nc < need) {
+ if (nc > INT_MAX / 2)
+ return -1;
+ nc *= 2;
+ }
+ sp_best_t *p = (sp_best_t *)realloc(ws->best, (size_t)nc * sizeof(*p));
+ if (!p)
+ return -1;
+ ws->best = p;
+ ws->best_cap = nc;
+ return 0;
+}
+
+static int reserve_ids(tok_spm_workspace_t *ws, int need) {
+ if (need <= ws->ids_cap)
+ return 0;
+ int nc = ws->ids_cap ? ws->ids_cap : 64;
+ while (nc < need) {
+ if (nc > INT_MAX / 2)
+ return -1;
+ nc *= 2;
+ }
+ int *p = (int *)realloc(ws->ids, (size_t)nc * sizeof(*p));
+ if (!p)
+ return -1;
+ ws->ids = p;
+ ws->ids_cap = nc;
+ return 0;
+}
+
+static int utf8_len(unsigned char c) {
+ if (c < 0x80)
+ return 1;
+ if ((c & 0xE0) == 0xC0)
+ return 2;
+ if ((c & 0xF0) == 0xE0)
+ return 3;
+ if ((c & 0xF8) == 0xF0)
+ return 4;
+ return 1;
+}
+
+static int valid_utf8_one(const char *s, size_t n, size_t off, size_t *len_out) {
+ if (off >= n)
+ return 0;
+ const unsigned char *p = (const unsigned char *)s + off;
+ int len = utf8_len(p[0]);
+ if (off + (size_t)len > n) {
+ *len_out = 1;
+ return 0;
+ }
+ if (len > 1) {
+ for (int i = 1; i < len; i++) {
+ if ((p[i] & 0xC0) != 0x80) {
+ *len_out = 1;
+ return 0;
+ }
+ }
+ }
+ *len_out = (size_t)len;
+ return 1;
+}
+
+static uint32_t read_le32(const unsigned char *p) {
+ return (uint32_t)p[0] | ((uint32_t)p[1] << 8) | ((uint32_t)p[2] << 16) | ((uint32_t)p[3] << 24);
+}
+
+static int pb_read_varint(const unsigned char **p, const unsigned char *end, uint64_t *out) {
+ uint64_t v = 0;
+ int shift = 0;
+ while (*p < end && shift <= 63) {
+ unsigned char c = *(*p)++;
+ v |= (uint64_t)(c & 0x7f) << shift;
+ if (!(c & 0x80)) {
+ *out = v;
+ return 0;
+ }
+ shift += 7;
+ }
+ return -1;
+}
+
+static int pb_read_key(const unsigned char **p, const unsigned char *end, int *field, int *wire) {
+ uint64_t key = 0;
+ if (pb_read_varint(p, end, &key) != 0)
+ return -1;
+ *field = (int)(key >> 3);
+ *wire = (int)(key & 7);
+ return *field > 0 ? 0 : -1;
+}
+
+static int pb_read_len(const unsigned char **p,
+ const unsigned char *end,
+ const unsigned char **data,
+ size_t *len) {
+ uint64_t n = 0;
+ if (pb_read_varint(p, end, &n) != 0 || n > (uint64_t)(end - *p))
+ return -1;
+ *data = *p;
+ *len = (size_t)n;
+ *p += n;
+ return 0;
+}
+
+static int pb_skip(const unsigned char **p, const unsigned char *end, int wire) {
+ uint64_t v = 0;
+ const unsigned char *data = NULL;
+ size_t len = 0;
+ switch (wire) {
+ case 0:
+ return pb_read_varint(p, end, &v);
+ case 1:
+ if ((size_t)(end - *p) < 8)
+ return -1;
+ *p += 8;
+ return 0;
+ case 2:
+ return pb_read_len(p, end, &data, &len);
+ case 5:
+ if ((size_t)(end - *p) < 4)
+ return -1;
+ *p += 4;
+ return 0;
+ default:
+ return -1;
+ }
+}
+
+static char *memdup0(const unsigned char *data, size_t len) {
+ char *s = (char *)malloc(len + 1);
+ if (!s)
+ return NULL;
+ memcpy(s, data, len);
+ s[len] = '\0';
+ return s;
+}
+
+static int parse_piece(tok_spm_t *tok, int idx, const unsigned char *data, size_t len) {
+ const unsigned char *p = data, *end = data + len;
+ char *piece = NULL;
+ float score = 0.0f;
+ int type = SP_PIECE_NORMAL;
+ while (p < end) {
+ int field = 0, wire = 0;
+ if (pb_read_key(&p, end, &field, &wire) != 0)
+ goto fail;
+ if (field == 1 && wire == 2) {
+ const unsigned char *s = NULL;
+ size_t n = 0;
+ if (pb_read_len(&p, end, &s, &n) != 0 || n > UINT16_MAX)
+ goto fail;
+ free(piece);
+ piece = memdup0(s, n);
+ if (!piece)
+ goto fail;
+ tok->piece_lens[idx] = (uint16_t)n;
+ } else if (field == 2 && wire == 5) {
+ if ((size_t)(end - p) < 4)
+ goto fail;
+ uint32_t bits = read_le32(p);
+ memcpy(&score, &bits, sizeof(score));
+ p += 4;
+ } else if (field == 3 && wire == 0) {
+ uint64_t v = 0;
+ if (pb_read_varint(&p, end, &v) != 0 || v > UINT8_MAX)
+ goto fail;
+ type = (int)v;
+ } else if (pb_skip(&p, end, wire) != 0) {
+ goto fail;
+ }
+ }
+ if (!piece)
+ goto fail;
+ tok->id_to_piece[idx] = piece;
+ tok->scores[idx] = score;
+ tok->types[idx] = (uint8_t)type;
+ if (is_tokenizable_type(type) && tok->piece_lens[idx] > tok->max_piece_len)
+ tok->max_piece_len = tok->piece_lens[idx];
+ return 0;
+fail:
+ free(piece);
+ return -1;
+}
+
+static int parse_trainer(tok_spm_t *tok, const unsigned char *data, size_t len) {
+ const unsigned char *p = data, *end = data + len;
+ int model_type = SP_MODEL_UNIGRAM;
+ while (p < end) {
+ int field = 0, wire = 0;
+ if (pb_read_key(&p, end, &field, &wire) != 0)
+ return -1;
+ if (field == 3 && wire == 0) {
+ uint64_t v = 0;
+ if (pb_read_varint(&p, end, &v) != 0 || v > INT_MAX)
+ return -1;
+ model_type = (int)v;
+ } else if (pb_skip(&p, end, wire) != 0) {
+ return -1;
+ }
+ }
+ if (model_type != SP_MODEL_UNIGRAM) {
+ fprintf(stderr, "sentencepiece: unsupported model_type %d (only Unigram is implemented)\n",
+ model_type);
+ return -1;
+ }
+ (void)tok;
+ return 0;
+}
+
+static int parse_normalizer(tok_spm_t *tok, const unsigned char *data, size_t len) {
+ const unsigned char *p = data, *end = data + len;
+ while (p < end) {
+ int field = 0, wire = 0;
+ if (pb_read_key(&p, end, &field, &wire) != 0)
+ return -1;
+ if ((field == 3 || field == 4 || field == 5) && wire == 0) {
+ uint64_t v = 0;
+ if (pb_read_varint(&p, end, &v) != 0)
+ return -1;
+ if (field == 3)
+ tok->add_dummy_prefix = v != 0;
+ else if (field == 4)
+ tok->remove_extra_whitespaces = v != 0;
+ else
+ tok->escape_whitespaces = v != 0;
+ } else if (field == 2 && wire == 2) {
+ const unsigned char *blob = NULL;
+ size_t n = 0;
+ if (pb_read_len(&p, end, &blob, &n) != 0)
+ return -1;
+ if (n >= 4) {
+ uint32_t xcda_bytes = read_le32(blob);
+ if ((size_t)xcda_bytes + 4 <= n && (xcda_bytes % 4) == 0) {
+ tok->xcda_count = xcda_bytes / 4;
+ tok->xcda = (uint32_t *)malloc(tok->xcda_count * sizeof(*tok->xcda));
+ if (!tok->xcda)
+ return -1;
+ for (size_t i = 0; i < tok->xcda_count; i++)
+ tok->xcda[i] = read_le32(blob + 4 + i * 4);
+ tok->prefix_replacements_len = n - 4 - xcda_bytes;
+ tok->prefix_replacements = (char *)malloc(tok->prefix_replacements_len + 1);
+ if (!tok->prefix_replacements)
+ return -1;
+ memcpy(tok->prefix_replacements, blob + 4 + xcda_bytes,
+ tok->prefix_replacements_len);
+ tok->prefix_replacements[tok->prefix_replacements_len] = '\0';
+ }
+ }
+ } else if (pb_skip(&p, end, wire) != 0) {
+ return -1;
+ }
+ }
+ return 0;
+}
+
+static int count_pieces(const unsigned char *data, size_t len) {
+ const unsigned char *p = data, *end = data + len;
+ int n = 0;
+ while (p < end) {
+ int field = 0, wire = 0;
+ if (pb_read_key(&p, end, &field, &wire) != 0)
+ return -1;
+ if (field == 1 && wire == 2) {
+ const unsigned char *msg = NULL;
+ size_t msg_len = 0;
+ if (pb_read_len(&p, end, &msg, &msg_len) != 0)
+ return -1;
+ n++;
+ } else if (pb_skip(&p, end, wire) != 0) {
+ return -1;
+ }
+ }
+ return n;
+}
+
+static int parse_model(tok_spm_t *tok, const unsigned char *data, size_t len) {
+ int n_pieces = count_pieces(data, len);
+ if (n_pieces <= 0)
+ return -1;
+ tok->piece_count = n_pieces;
+ tok->id_to_piece = (char **)calloc((size_t)n_pieces, sizeof(*tok->id_to_piece));
+ tok->piece_lens = (uint16_t *)calloc((size_t)n_pieces, sizeof(*tok->piece_lens));
+ tok->scores = (float *)calloc((size_t)n_pieces, sizeof(*tok->scores));
+ tok->types = (uint8_t *)calloc((size_t)n_pieces, sizeof(*tok->types));
+ if (!tok->id_to_piece || !tok->piece_lens || !tok->scores || !tok->types)
+ return -1;
+
+ const unsigned char *p = data, *end = data + len;
+ int piece_idx = 0;
+ int saw_trainer = 0;
+ while (p < end) {
+ int field = 0, wire = 0;
+ if (pb_read_key(&p, end, &field, &wire) != 0)
+ return -1;
+ if (wire == 2 && field == 1) {
+ const unsigned char *msg = NULL;
+ size_t msg_len = 0;
+ if (pb_read_len(&p, end, &msg, &msg_len) != 0 || piece_idx >= n_pieces ||
+ parse_piece(tok, piece_idx++, msg, msg_len) != 0)
+ return -1;
+ } else if (wire == 2 && field == 2) {
+ const unsigned char *msg = NULL;
+ size_t msg_len = 0;
+ if (pb_read_len(&p, end, &msg, &msg_len) != 0 || parse_trainer(tok, msg, msg_len) != 0)
+ return -1;
+ saw_trainer = 1;
+ } else if (wire == 2 && field == 3) {
+ const unsigned char *msg = NULL;
+ size_t msg_len = 0;
+ if (pb_read_len(&p, end, &msg, &msg_len) != 0 || parse_normalizer(tok, msg, msg_len) != 0)
+ return -1;
+ } else if (pb_skip(&p, end, wire) != 0) {
+ return -1;
+ }
+ }
+ if (piece_idx != n_pieces || !saw_trainer)
+ return -1;
+ return 0;
+}
+
+static int raw_piece_id(const tok_spm_t *tok, const char *piece) {
+ if (!tok || !piece)
+ return -1;
+ return map_get((const sp_entry_t *)tok->piece_map, tok->piece_map_cap, piece, (int)strlen(piece));
+}
+
+static int raw_to_model_id(const tok_spm_t *tok, int raw_id) {
+ if (!tok || raw_id < 0 || raw_id >= tok->piece_count)
+ return -1;
+ if (tok->id_map == TOK_SPM_XLM_ROBERTA) {
+ if (raw_id == 1)
+ return 0; /* <s> */
+ if (raw_id == 2)
+ return 2; /* </s> */
+ if (raw_id == 0)
+ return 3; /* <unk> */
+ return raw_id + 1;
+ }
+ return raw_id;
+}
+
+static int model_to_raw_id(const tok_spm_t *tok, int id) {
+ if (!tok || id < 0)
+ return -1;
+ if (tok->id_map == TOK_SPM_XLM_ROBERTA) {
+ if (id == 0)
+ return 1;
+ if (id == 2)
+ return 2;
+ if (id == 3)
+ return 0;
+ if (id >= 4 && id <= tok->piece_count)
+ return id - 1;
+ return -1;
+ }
+ return id < tok->piece_count ? id : -1;
+}
+
+static int file_contains_xlm_roberta(const char *model_dir, const char *name) {
+ char path[1024];
+ int n = snprintf(path, sizeof(path), "%s/%s", model_dir, name);
+ if (n < 0 || (size_t)n >= sizeof(path))
+ return 0;
+ FILE *f = fopen(path, "rb");
+ if (!f)
+ return 0;
+ if (fseek(f, 0, SEEK_END) != 0) {
+ fclose(f);
+ return 0;
+ }
+ long sz = ftell(f);
+ if (sz < 0 || (size_t)sz == SIZE_MAX || fseek(f, 0, SEEK_SET) != 0) {
+ fclose(f);
+ return 0;
+ }
+ char *buf = (char *)malloc((size_t)sz + 1);
+ if (!buf) {
+ fclose(f);
+ return 0;
+ }
+ size_t got = fread(buf, 1, (size_t)sz, f);
+ fclose(f);
+ buf[got] = '\0';
+ int yes = strstr(buf, "XLMRobertaTokenizer") != NULL ||
+ strstr(buf, "XLMRobertaTokenizerFast") != NULL ||
+ strstr(buf, "XLMRobertaModel") != NULL || strstr(buf, "xlm-roberta") != NULL;
+ free(buf);
+ return yes;
+}
+
+static int detect_xlm_roberta(const char *model_dir) {
+ return file_contains_xlm_roberta(model_dir, "tokenizer_config.json") ||
+ file_contains_xlm_roberta(model_dir, "config.json");
+}
+
+static int find_model_file(const char *model_dir, char path[1024]) {
+ static const char *names[] = {
+ "sentencepiece.bpe.model",
+ "tokenizer.model",
+ "spiece.model",
+ };
+ for (int i = 0; i < (int)(sizeof(names) / sizeof(names[0])); i++) {
+ int n = snprintf(path, 1024, "%s/%s", model_dir, names[i]);
+ if (n < 0 || n >= 1024)
+ return -1;
+ FILE *f = fopen(path, "rb");
+ if (f) {
+ fclose(f);
+ return 0;
+ }
+ if (errno != ENOENT)
+ return -1;
+ }
+ return -1;
+}
+
+static int load_file(const char *path, unsigned char **out, size_t *out_len) {
+ FILE *f = fopen(path, "rb");
+ if (!f)
+ return -1;
+ if (fseek(f, 0, SEEK_END) != 0) {
+ fclose(f);
+ return -1;
+ }
+ long sz = ftell(f);
+ if (sz < 0 || (size_t)sz == SIZE_MAX || fseek(f, 0, SEEK_SET) != 0) {
+ fclose(f);
+ return -1;
+ }
+ unsigned char *buf = (unsigned char *)malloc((size_t)sz);
+ if (!buf) {
+ fclose(f);
+ return -1;
+ }
+ if (fread(buf, 1, (size_t)sz, f) != (size_t)sz) {
+ fclose(f);
+ free(buf);
+ return -1;
+ }
+ fclose(f);
+ *out = buf;
+ *out_len = (size_t)sz;
+ return 0;
+}
+
+static uint32_t xcda_base(const tok_spm_t *tok, size_t idx) {
+ uint32_t v = tok->xcda[idx];
+ return (v >> 10) << ((v & (1u << 9)) >> 6);
+}
+
+static uint32_t xcda_lcheck(const tok_spm_t *tok, size_t idx) {
+ return tok->xcda[idx] & ((1u << 31) | 0xffu);
+}
+
+static int xcda_leaf(const tok_spm_t *tok, size_t idx) { return (tok->xcda[idx] >> 8) & 1u; }
+
+static uint32_t xcda_value(const tok_spm_t *tok, size_t idx) {
+ return tok->xcda[idx] & ((1u << 31) - 1u);
+}
+
+typedef struct {
+ const char *data;
+ size_t len;
+ size_t consumed;
+} norm_prefix_t;
+
+static norm_prefix_t
+normalize_prefix(const tok_spm_t *tok, const char *input, size_t input_len, size_t off) {
+ static const char repl[] = "\xef\xbf\xbd";
+ if (off >= input_len)
+ return (norm_prefix_t){input + off, 0, 0};
+
+ size_t best_len = 0;
+ size_t best_repl = 0;
+ if (tok->xcda && tok->xcda_count > 0) {
+ uint32_t node = xcda_base(tok, 0);
+ for (size_t p = off; p < input_len; p++) {
+ unsigned char c = (unsigned char)input[p];
+ if (c == 0)
+ break;
+ node ^= c;
+ if (node >= tok->xcda_count || xcda_lcheck(tok, node) != c)
+ break;
+ int leaf = xcda_leaf(tok, node);
+ node ^= xcda_base(tok, node);
+ if (leaf) {
+ best_len = p - off + 1;
+ best_repl = xcda_value(tok, node);
+ }
+ }
+ }
+ if (best_len > 0 && best_repl < tok->prefix_replacements_len) {
+ const char *r = tok->prefix_replacements + best_repl;
+ size_t max = tok->prefix_replacements_len - best_repl;
+ size_t n = strnlen(r, max);
+ return (norm_prefix_t){r, n, best_len};
+ }
+
+ size_t clen = 1;
+ if (valid_utf8_one(input, input_len, off, &clen))
+ return (norm_prefix_t){input + off, clen, clen};
+ return (norm_prefix_t){repl, 3, 1};
+}
+
+static int normalize_into(const tok_spm_t *tok, tok_spm_workspace_t *ws, const char *text) {
+ ws->norm_len = 0;
+ if (!text)
+ return -1;
+ size_t input_len = strlen(text);
+ const char space[] = "\xe2\x96\x81"; /* U+2581 */
+ const char *space_s = tok->escape_whitespaces ? space : " ";
+ size_t space_n = tok->escape_whitespaces ? 3 : 1;
+ int processing_non_ws = 0;
+ int space_prepended = 0;
+
+ for (size_t off = 0; off < input_len;) {
+ norm_prefix_t r = normalize_prefix(tok, text, input_len, off);
+ for (size_t i = 0; i < r.len; i++) {
+ char c = r.data[i];
+ if (c != ' ') {
+ if (!processing_non_ws) {
+ processing_non_ws = 1;
+ if ((tok->add_dummy_prefix && !space_prepended) ||
+ tok->remove_extra_whitespaces) {
+ if (append_bytes(&ws->norm, &ws->norm_len, &ws->norm_cap, space_s, space_n) !=
+ 0)
+ return -1;
+ space_prepended = 1;
+ }
+ }
+ if (append_bytes(&ws->norm, &ws->norm_len, &ws->norm_cap, &c, 1) != 0)
+ return -1;
+ } else {
+ processing_non_ws = 0;
+ if (!tok->remove_extra_whitespaces) {
+ if (append_bytes(&ws->norm, &ws->norm_len, &ws->norm_cap, space_s, space_n) != 0)
+ return -1;
+ }
+ }
+ }
+ off += r.consumed ? r.consumed : 1;
+ }
+ if (ws->norm)
+ ws->norm[ws->norm_len] = '\0';
+ return 0;
+}
+
+static double compute_unknown_score(const tok_spm_t *tok) {
+ float min_score = FLT_MAX;
+ for (int i = 0; i < tok->piece_count; i++) {
+ if (tok->types[i] == SP_PIECE_NORMAL && tok->scores[i] < min_score)
+ min_score = tok->scores[i];
+ }
+ if (min_score == FLT_MAX)
+ min_score = -10.0f;
+ return (double)min_score - 10.0;
+}
+
+static int segment(tok_spm_t const *tok, tok_spm_workspace_t *ws) {
+ size_t n = ws->norm_len;
+ if (n == 0)
+ return 0;
+ if (n > (size_t)INT_MAX - 1 || reserve_best(ws, (int)n + 1) != 0 ||
+ reserve_ids(ws, (int)n + 1) != 0)
+ return -1;
+ for (size_t i = 0; i <= n; i++)
+ ws->best[i] = (sp_best_t){tok->unk_id, -1, -DBL_MAX};
+ ws->best[0] = (sp_best_t){tok->unk_id, 0, 0.0};
+ double unk_score = tok->unknown_score;
+
+ for (size_t off = 0; off < n;) {
+ size_t cp_len = 1;
+ valid_utf8_one(ws->norm, n, off, &cp_len);
+ sp_best_t cur = ws->best[off];
+ if (cur.score <= -DBL_MAX / 2.0) {
+ off += cp_len;
+ continue;
+ }
+
+ int single_cp_found = 0;
+ for (size_t end = off + cp_len; end <= n && end - off <= (size_t)tok->max_piece_len;) {
+ int raw = map_get((const sp_entry_t *)tok->piece_map, tok->piece_map_cap, ws->norm + off,
+ (int)(end - off));
+ if (raw >= 0 && is_tokenizable_type(tok->types[raw])) {
+ if (end - off == cp_len)
+ single_cp_found = 1;
+ double sc =
+ cur.score + (tok->types[raw] == SP_PIECE_USER_DEFINED ? 0.0 : tok->scores[raw]);
+ if (sc > ws->best[end].score)
+ ws->best[end] = (sp_best_t){raw_to_model_id(tok, raw), (int)off, sc};
+ }
+ if (end == n)
+ break;
+ size_t next_len = 1;
+ valid_utf8_one(ws->norm, n, end, &next_len);
+ end += next_len;
+ }
+ if (!single_cp_found) {
+ size_t end = off + cp_len;
+ double sc = cur.score + unk_score;
+ if (sc > ws->best[end].score)
+ ws->best[end] = (sp_best_t){tok->unk_id, (int)off, sc};
+ }
+ off += cp_len;
+ }
+
+ int out_n = 0;
+ int prev_unk = 0;
+ for (size_t off = n; off > 0;) {
+ sp_best_t b = ws->best[off];
+ if (b.prev < 0 || b.prev >= (int)off)
+ return -1;
+ int is_unk = b.id == tok->unk_id;
+ if (!(prev_unk && is_unk)) {
+ if (out_n >= ws->ids_cap)
+ return -1;
+ ws->ids[out_n++] = b.id;
+ }
+ prev_unk = is_unk;
+ off = (size_t)b.prev;
+ }
+ for (int i = 0; i < out_n / 2; i++) {
+ int t = ws->ids[i];
+ ws->ids[i] = ws->ids[out_n - 1 - i];
+ ws->ids[out_n - 1 - i] = t;
+ }
+ return out_n;
+}
+
+tok_spm_t *tok_spm_load(const char *model_dir) {
+ if (!model_dir)
+ return NULL;
+ char path[1024];
+ if (find_model_file(model_dir, path) != 0) {
+ fprintf(stderr, "sentencepiece: model file not found under %s\n", model_dir);
+ return NULL;
+ }
+ unsigned char *data = NULL;
+ size_t len = 0;
+ if (load_file(path, &data, &len) != 0) {
+ fprintf(stderr, "sentencepiece: cannot read %s\n", path);
+ return NULL;
+ }
+
+ tok_spm_t *tok = (tok_spm_t *)calloc(1, sizeof(tok_spm_t));
+ if (!tok) {
+ free(data);
+ return NULL;
+ }
+ tok->add_dummy_prefix = 1;
+ tok->remove_extra_whitespaces = 1;
+ tok->escape_whitespaces = 1;
+ tok->id_map = detect_xlm_roberta(model_dir) ? TOK_SPM_XLM_ROBERTA : TOK_SPM_IDENTITY;
+ if (parse_model(tok, data, len) != 0) {
+ fprintf(stderr, "sentencepiece: malformed or unsupported model: %s\n", path);
+ free(data);
+ tok_spm_free(tok);
+ return NULL;
+ }
+ free(data);
+
+ int cap = next_pow2(tok->piece_count * 2 + 1);
+ tok->piece_map = calloc((size_t)cap, sizeof(sp_entry_t));
+ if (!tok->piece_map) {
+ tok_spm_free(tok);
+ return NULL;
+ }
+ tok->piece_map_cap = cap;
+ for (int i = 0; i < tok->piece_count; i++) {
+ if (!tok->id_to_piece[i] || map_put((sp_entry_t *)tok->piece_map, cap, tok->id_to_piece[i],
+ tok->piece_lens[i], i) != 0) {
+ tok_spm_free(tok);
+ return NULL;
+ }
+ }
+
+ tok->unk_id = raw_to_model_id(tok, raw_piece_id(tok, "<unk>"));
+ tok->bos_id = raw_to_model_id(tok, raw_piece_id(tok, "<s>"));
+ tok->eos_id = raw_to_model_id(tok, raw_piece_id(tok, "</s>"));
+ tok->pad_id =
+ tok->id_map == TOK_SPM_XLM_ROBERTA ? 1 : raw_to_model_id(tok, raw_piece_id(tok, "<pad>"));
+ tok->mask_id = tok->id_map == TOK_SPM_XLM_ROBERTA
+ ? tok->piece_count + 1
+ : raw_to_model_id(tok, raw_piece_id(tok, "<mask>"));
+ tok->vocab_size = tok->id_map == TOK_SPM_XLM_ROBERTA ? tok->piece_count + 2 : tok->piece_count;
+ tok->unknown_score = compute_unknown_score(tok);
+ if (tok->unk_id < 0 || tok->max_piece_len <= 0) {
+ fprintf(stderr, "sentencepiece: missing <unk> or normal pieces in %s\n", path);
+ tok_spm_free(tok);
+ return NULL;
+ }
+ return tok;
+}
+
+const char *tok_spm_decode(const tok_spm_t *tok, int id) {
+ if (!tok || id < 0)
+ return NULL;
+ if (tok->id_map == TOK_SPM_XLM_ROBERTA) {
+ if (id == 1)
+ return "<pad>";
+ if (id == tok->piece_count + 1)
+ return "<mask>";
+ }
+ int raw = model_to_raw_id(tok, id);
+ return raw >= 0 ? tok->id_to_piece[raw] : NULL;
+}
+
+int tok_spm_token_id(const tok_spm_t *tok, const char *token) {
+ if (!tok || !token)
+ return -1;
+ if (tok->id_map == TOK_SPM_XLM_ROBERTA) {
+ if (!strcmp(token, "<s>"))
+ return 0;
+ if (!strcmp(token, "<pad>"))
+ return 1;
+ if (!strcmp(token, "</s>"))
+ return 2;
+ if (!strcmp(token, "<unk>"))
+ return 3;
+ if (!strcmp(token, "<mask>"))
+ return tok->piece_count + 1;
+ }
+ return raw_to_model_id(tok, raw_piece_id(tok, token));
+}
+
+int tok_spm_encode_into(const tok_spm_t *tok,
+ tok_spm_workspace_t *ws,
+ const char *text,
+ int *out_ids,
+ int out_cap,
+ int *out_n_tokens) {
+ if (out_n_tokens)
+ *out_n_tokens = 0;
+ if (!tok || !ws || !text)
+ return -1;
+ if (normalize_into(tok, ws, text) != 0)
+ return -1;
+ int n = segment(tok, ws);
+ if (n < 0)
+ return -1;
+ if (out_n_tokens)
+ *out_n_tokens = n;
+ if (n == 0)
+ return 0;
+ if (!out_ids || out_cap < n)
+ return -2;
+ memcpy(out_ids, ws->ids, (size_t)n * sizeof(*out_ids));
+ return 0;
+}
+
+int *tok_spm_encode_with_workspace(const tok_spm_t *tok,
+ tok_spm_workspace_t *ws,
+ const char *text,
+ int *out_n_tokens) {
+ if (out_n_tokens)
+ *out_n_tokens = 0;
+ if (!tok || !ws || !text)
+ return NULL;
+ int n = 0;
+ int rc = tok_spm_encode_into(tok, ws, text, NULL, 0, &n);
+ if (rc < 0 && rc != -2)
+ return NULL;
+ if (out_n_tokens)
+ *out_n_tokens = n;
+ if (n == 0)
+ return NULL;
+ int *ids = (int *)malloc((size_t)n * sizeof(*ids));
+ if (!ids)
+ return NULL;
+ memcpy(ids, ws->ids, (size_t)n * sizeof(*ids));
+ return ids;
+}
+
+int *tok_spm_encode(const tok_spm_t *tok, const char *text, int *out_n_tokens) {
+ tok_spm_workspace_t *ws = tok_spm_workspace_new();
+ if (!ws) {
+ if (out_n_tokens)
+ *out_n_tokens = 0;
+ return NULL;
+ }
+ int *ids = tok_spm_encode_with_workspace(tok, ws, text, out_n_tokens);
+ tok_spm_workspace_free(ws);
+ return ids;
+}
+
+tok_spm_workspace_t *tok_spm_workspace_new(void) {
+ return (tok_spm_workspace_t *)calloc(1, sizeof(tok_spm_workspace_t));
+}
+
+void tok_spm_workspace_free(tok_spm_workspace_t *ws) {
+ if (!ws)
+ return;
+ free(ws->norm);
+ free(ws->best);
+ free(ws->ids);
+ free(ws);
+}
+
+void tok_spm_free(tok_spm_t *tok) {
+ if (!tok)
+ return;
+ if (tok->id_to_piece) {
+ for (int i = 0; i < tok->piece_count; i++)
+ free(tok->id_to_piece[i]);
+ }
+ free(tok->id_to_piece);
+ free(tok->piece_lens);
+ free(tok->scores);
+ free(tok->types);
+ free(tok->piece_map);
+ free(tok->xcda);
+ free(tok->prefix_replacements);
+ free(tok);
+}
diff --git a/libffwd/sentencepiece.h b/libffwd/sentencepiece.h
new file mode 100644
index 0000000..b79f47c
--- /dev/null
+++ b/libffwd/sentencepiece.h
@@ -0,0 +1,88 @@
+/*
+ * SentencePiece tokenizer for XLM-R style models.
+ *
+ * Loads a SentencePiece ModelProto (sentencepiece.bpe.model, tokenizer.model,
+ * or spiece.model) and implements the Unigram Viterbi encoder used by XLM-R
+ * and multilingual E5. It encodes text only; frontends add the model's special
+ * token layout, e.g. <s> ... </s> for XLM-R.
+ */
+
+#ifndef TOK_SPM_H
+#define TOK_SPM_H
+
+#include <stddef.h>
+#include <stdint.h>
+
+typedef enum {
+ TOK_SPM_IDENTITY = 0,
+ TOK_SPM_XLM_ROBERTA = 1,
+} tok_spm_id_map_t;
+
+typedef struct {
+ char **id_to_piece; /* [piece_count] raw SentencePiece ids */
+ uint16_t *piece_lens; /* byte length for id_to_piece entries */
+ float *scores; /* SentencePiece score per raw id */
+ uint8_t *types; /* SentencePiece piece type per raw id */
+ int piece_count; /* raw SentencePiece vocabulary size */
+ int vocab_size; /* model embedding vocab size after id mapping */
+ int unk_id; /* model-space unknown-token id */
+ int bos_id; /* model-space beginning-token id, or -1 */
+ int eos_id; /* model-space end-token id, or -1 */
+ int pad_id; /* model-space pad-token id, or -1 */
+ int mask_id; /* model-space mask-token id, or -1 */
+ int max_piece_len; /* max normal/user/unused piece byte length */
+ double unknown_score; /* score assigned to an unmatched UTF-8 codepoint */
+ int add_dummy_prefix;
+ int remove_extra_whitespaces;
+ int escape_whitespaces;
+ tok_spm_id_map_t id_map;
+
+ void *piece_map; /* piece bytes -> raw SentencePiece id */
+ int piece_map_cap;
+
+ uint32_t *xcda;
+ size_t xcda_count;
+ char *prefix_replacements;
+ size_t prefix_replacements_len;
+} tok_spm_t;
+
+typedef struct tok_spm_workspace tok_spm_workspace_t;
+
+/* Load the first supported SentencePiece model found in model_dir. Returns NULL
+ * on missing model file, unsupported model type, malformed protobuf, or OOM. */
+tok_spm_t *tok_spm_load(const char *model_dir);
+
+/* Decode one model-space id to an internal token string, or NULL when invalid. */
+const char *tok_spm_decode(const tok_spm_t *tok, int id);
+
+/* Resolve a named token (e.g. "<s>", "</s>", "<pad>", "<mask>") to a
+ * model-space id, or -1 when absent. */
+int tok_spm_token_id(const tok_spm_t *tok, const char *token);
+
+/* Encode UTF-8 text into malloc'd model-space token ids. Empty text returns
+ * NULL with *out_n_tokens = 0. NULL with a negative/unspecified count is an
+ * error. */
+int *tok_spm_encode(const tok_spm_t *tok, const char *text, int *out_n_tokens);
+
+tok_spm_workspace_t *tok_spm_workspace_new(void);
+void tok_spm_workspace_free(tok_spm_workspace_t *ws);
+
+/* Encode into caller-provided out_ids. Returns 0 on success, -1 on error, -2 if
+ * out_cap is too small. *out_n_tokens receives the emitted/needed token count. */
+int tok_spm_encode_into(const tok_spm_t *tok,
+ tok_spm_workspace_t *ws,
+ const char *text,
+ int *out_ids,
+ int out_cap,
+ int *out_n_tokens);
+
+/* Same tokenization as tok_spm_encode(), reusing ws internally
+ * and performing only the final returned int[] allocation. */
+int *tok_spm_encode_with_workspace(const tok_spm_t *tok,
+ tok_spm_workspace_t *ws,
+ const char *text,
+ int *out_n_tokens);
+
+void tok_spm_free(tok_spm_t *tok);
+
+#endif /* TOK_SPM_H */
diff --git a/libffwd/threadpool.c b/libffwd/threadpool.c
new file mode 100644
index 0000000..6cb4252
--- /dev/null
+++ b/libffwd/threadpool.c
@@ -0,0 +1,218 @@
+/*
+ * CPU thread pool.
+ */
+
+#if defined(__linux__) && !defined(_GNU_SOURCE)
+# define _GNU_SOURCE
+#endif
+
+#include "threadpool.h"
+
+#include <pthread.h>
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#ifdef __APPLE__
+# include <sys/sysctl.h>
+#else
+# ifdef __linux__
+# include <sched.h>
+# endif
+# include <unistd.h>
+#endif
+
+#if defined(USE_OPENBLAS)
+void openblas_set_num_threads(int num_threads);
+#endif
+
+#define TP_MAX_THREADS 16
+
+static struct {
+ pthread_t threads[TP_MAX_THREADS - 1];
+ int tids[TP_MAX_THREADS - 1];
+ int n_threads;
+ int shutdown;
+
+ parallel_fn_t fn;
+ void *arg;
+ uint64_t generation;
+
+ pthread_mutex_t mutex;
+ pthread_cond_t cond_work;
+ pthread_cond_t cond_done;
+ int n_done;
+} tp = {
+ .n_threads = 1,
+ .shutdown = 0,
+ .generation = 0,
+ .mutex = PTHREAD_MUTEX_INITIALIZER,
+ .cond_work = PTHREAD_COND_INITIALIZER,
+ .cond_done = PTHREAD_COND_INITIALIZER,
+};
+
+static void *worker_loop(void *arg) {
+ int tid = *(int *)arg;
+ uint64_t my_gen = 0;
+
+ for (;;) {
+ pthread_mutex_lock(&tp.mutex);
+ while (tp.generation == my_gen && !tp.shutdown)
+ pthread_cond_wait(&tp.cond_work, &tp.mutex);
+ if (tp.shutdown) {
+ pthread_mutex_unlock(&tp.mutex);
+ return NULL;
+ }
+ my_gen = tp.generation;
+ parallel_fn_t fn = tp.fn;
+ void *a = tp.arg;
+ int nt = tp.n_threads;
+ pthread_mutex_unlock(&tp.mutex);
+
+ fn(tid, nt, a);
+
+ pthread_mutex_lock(&tp.mutex);
+ if (++tp.n_done >= tp.n_threads - 1)
+ pthread_cond_signal(&tp.cond_done);
+ pthread_mutex_unlock(&tp.mutex);
+ }
+}
+
+void tp_set_threads(int n) {
+ if (n < 1)
+ n = 1;
+ if (n > TP_MAX_THREADS)
+ n = TP_MAX_THREADS;
+
+#if defined(USE_OPENBLAS)
+ /* OpenBLAS owns the heavy F32 GEMM parallelism on Linux. Keep the
+ * auxiliary pool serial to avoid nested thread contention. */
+ int blas_threads = n;
+ openblas_set_num_threads(blas_threads);
+ n = 1;
+#endif
+
+ /* Shutdown existing workers */
+ if (tp.n_threads > 1) {
+ pthread_mutex_lock(&tp.mutex);
+ tp.shutdown = 1;
+ pthread_cond_broadcast(&tp.cond_work);
+ pthread_mutex_unlock(&tp.mutex);
+ for (int i = 0; i < tp.n_threads - 1; i++)
+ pthread_join(tp.threads[i], NULL);
+ tp.shutdown = 0;
+ tp.generation = 0;
+ }
+
+ tp.n_threads = n;
+ if (n <= 1)
+ return;
+
+ for (int i = 0; i < n - 1; i++) {
+ tp.tids[i] = i + 1;
+ pthread_create(&tp.threads[i], NULL, worker_loop, &tp.tids[i]);
+ }
+}
+
+#ifndef __APPLE__
+/* CPU quota available to this process, in whole cores, or 0 if uncapped.
+ * Containers such as Docker --cpus, Kubernetes, and RunPod may expose every host
+ * CPU through sysconf()/cpuset, while CFS quota limits the CPU time the process
+ * can actually use.
+ *
+ * Sizing the BLAS/thread pool to the host CPU count oversubscribes that quota:
+ * threads use the period budget early, then get throttled for the rest of the
+ * period, causing large bursty stalls. Example: a 16-thread default against a
+ * 5.1-core quota ran the 0.6B model about 2x slower than a 5-thread pool.
+ *
+ * Floor instead of ceil, so a fully busy pool stays under quota and avoids
+ * throttling.
+ */
+static int cgroup_cpu_quota(void) {
+ /* cgroup v2: "/sys/fs/cgroup/cpu.max" is "<quota> <period>", or
+ * "max <period>" when unlimited. */
+ FILE *f = fopen("/sys/fs/cgroup/cpu.max", "r");
+ if (f) {
+ char quota[32];
+ long period = 0;
+ int got = fscanf(f, "%31s %ld", quota, &period);
+ fclose(f);
+ if (got == 2 && period > 0 && strcmp(quota, "max") != 0) {
+ long q = atol(quota);
+ if (q > 0)
+ return q / period < 1 ? 1 : (int)(q / period);
+ }
+ }
+ /* cgroup v1: separate files; quota -1 means unlimited. */
+ long q = -1, period = 0;
+ f = fopen("/sys/fs/cgroup/cpu/cpu.cfs_quota_us", "r");
+ if (f) {
+ if (fscanf(f, "%ld", &q) != 1)
+ q = -1;
+ fclose(f);
+ }
+ f = fopen("/sys/fs/cgroup/cpu/cpu.cfs_period_us", "r");
+ if (f) {
+ if (fscanf(f, "%ld", &period) != 1)
+ period = 0;
+ fclose(f);
+ }
+ if (q > 0 && period > 0)
+ return q / period < 1 ? 1 : (int)(q / period);
+ return 0;
+}
+#endif
+
+int tp_get_num_cpus(void) {
+#ifdef __APPLE__
+ int n = 0;
+ size_t len = sizeof(n);
+ sysctlbyname("hw.ncpu", &n, &len, NULL, 0);
+ return n > 0 ? n : 1;
+#else
+ int online = (int)sysconf(_SC_NPROCESSORS_ONLN);
+ if (online < 1)
+ online = 1;
+# ifdef __linux__
+ cpu_set_t set;
+ if (sched_getaffinity(0, sizeof(set), &set) == 0) {
+ int affinity = CPU_COUNT(&set);
+ if (affinity >= 1 && affinity < online)
+ online = affinity;
+ }
+# endif
+ /* Honor a cgroup CPU quota when it is tighter than the visible core count,
+ * so the default thread pool does not oversubscribe a CPU-limited
+ * container and get throttled. */
+ int quota = cgroup_cpu_quota();
+ if (quota >= 1 && quota < online)
+ return quota;
+ return online;
+#endif
+}
+
+int tp_num_threads(void) { return tp.n_threads; }
+
+/* Dispatch work to all threads; main thread is tid=0 */
+void parallel_for(parallel_fn_t fn, void *arg) {
+ if (tp.n_threads <= 1) {
+ fn(0, 1, arg);
+ return;
+ }
+
+ pthread_mutex_lock(&tp.mutex);
+ tp.fn = fn;
+ tp.arg = arg;
+ tp.n_done = 0;
+ tp.generation++;
+ pthread_cond_broadcast(&tp.cond_work);
+ pthread_mutex_unlock(&tp.mutex);
+
+ fn(0, tp.n_threads, arg);
+
+ pthread_mutex_lock(&tp.mutex);
+ while (tp.n_done < tp.n_threads - 1)
+ pthread_cond_wait(&tp.cond_done, &tp.mutex);
+ pthread_mutex_unlock(&tp.mutex);
+}
diff --git a/libffwd/threadpool.h b/libffwd/threadpool.h
new file mode 100644
index 0000000..f9739a1
--- /dev/null
+++ b/libffwd/threadpool.h
@@ -0,0 +1,30 @@
+#ifndef TP_THREADPOOL_H
+#define TP_THREADPOOL_H
+
+/* Persistent worker pool for CPU kernels.
+ * Uses a fixed thread set that sleeps until parallel_for() gives it a callback.
+ * Also provides the cgroup-quota-aware CPU-count helper used to size the pool.
+ *
+ * Kept separate from the kernels so they depend only on parallel_for and
+ * tp_num_threads, not pool internals.
+ *
+ * kernels.h includes this, so kernel callers need no extra include. */
+
+/* Worker callback: (thread index, total threads, user arg). */
+typedef void (*parallel_fn_t)(int tid, int n_threads, void *arg);
+
+/* Set the persistent pool size (default 1). Creates/rebuilds the pool; call
+ * before inference. */
+void tp_set_threads(int n);
+
+/* Available CPU cores, capped to a cgroup CPU quota when one is tighter. */
+int tp_get_num_cpus(void);
+
+/* Current pool size (1 == serial). Kernels gate parallelism on this. */
+int tp_num_threads(void);
+
+/* Run fn across the pool; the calling thread participates as tid 0. Blocks
+ * until every worker has finished. */
+void parallel_for(parallel_fn_t fn, void *arg);
+
+#endif /* TP_THREADPOOL_H */
diff --git a/libffwd/tokenize.c b/libffwd/tokenize.c
new file mode 100644
index 0000000..2af151a
--- /dev/null
+++ b/libffwd/tokenize.c
@@ -0,0 +1,349 @@
+/*
+ * Model-aware tokenization: text -> token ids the model expects.
+ *
+ * Backend-independent, so this uses its own handle, ffwd_tok_t, instead of the
+ * per-backend ffwd_t.
+ *
+ * ffwd_tok_open selects the tokenizer from the files present and resolves the
+ * model's special-token ids.
+ *
+ * ffwd_tokenize applies the model's token layout: BERT/XLM-R [CLS]..[SEP], or
+ * Qwen appended terminal token.
+ */
+
+#include "ffwd.h"
+
+#include "bpe.h"
+#include "sentencepiece.h"
+#include "wordpiece.h"
+
+#include <limits.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+
+typedef enum { TOK_KIND_BPE, TOK_KIND_WP, TOK_KIND_SPM } tok_kind_t;
+
+struct ffwd_tok {
+ tok_kind_t kind;
+ /* exactly one trio is populated, by kind */
+ tok_bpe_t *bpe;
+ tok_bpe_workspace_t *bpe_ws;
+ tok_wp_t *wp;
+ tok_wp_workspace_t *wp_ws;
+ tok_spm_t *spm;
+ tok_spm_workspace_t *spm_ws;
+
+ int cls_id; /* [CLS] / <s> — wp/spm wrap with these */
+ int sep_id; /* [SEP] / </s> */
+ int context_separator_id;
+ int terminal_id; /* appended on the bpe path when append_terminal */
+ int append_terminal; /* Qwen3-Embedding pools the last token; see note */
+
+ int is_late;
+ int late_mask_id;
+ int late_query_prefix_id;
+ int late_document_prefix_id;
+ int late_skip_ids[64];
+ int n_late_skip_ids;
+};
+
+static void set_err(char *err, size_t errlen, const char *msg) {
+ if (err && errlen)
+ snprintf(err, errlen, "%s", msg);
+}
+
+ffwd_tok_t *ffwd_tok_open(const char *model_dir, int is_late, char *err, size_t errlen) {
+ if (!model_dir) {
+ set_err(err, errlen, "model_dir is NULL");
+ return NULL;
+ }
+ ffwd_tok_t *t = calloc(1, sizeof(*t));
+ if (!t) {
+ set_err(err, errlen, "out of memory");
+ return NULL;
+ }
+ t->cls_id = -1;
+ t->sep_id = -1;
+ t->terminal_id = -1;
+ t->is_late = is_late;
+
+ char path[1024];
+
+ /* WordPiece (BERT family): vocab.txt. */
+ snprintf(path, sizeof(path), "%s/vocab.txt", model_dir);
+ if (access(path, R_OK) == 0) {
+ t->kind = TOK_KIND_WP;
+ t->wp = tok_wp_load(model_dir);
+ if (!t->wp) {
+ set_err(err, errlen, "failed to load WordPiece tokenizer");
+ goto fail;
+ }
+ t->wp_ws = tok_wp_workspace_new();
+ if (!t->wp_ws) {
+ set_err(err, errlen, "out of memory");
+ goto fail;
+ }
+ t->cls_id = tok_wp_token_id(t->wp, "[CLS]");
+ t->sep_id = tok_wp_token_id(t->wp, "[SEP]");
+ if (t->cls_id < 0 || t->sep_id < 0) {
+ set_err(err, errlen, "WordPiece vocab missing [CLS]/[SEP]");
+ goto fail;
+ }
+ return t;
+ }
+
+ /* SentencePiece (XLM-R family): sentencepiece.bpe.model / tokenizer.model /
+ * spiece.model. */
+ snprintf(path, sizeof(path), "%s/sentencepiece.bpe.model", model_dir);
+ if (access(path, R_OK) != 0) {
+ snprintf(path, sizeof(path), "%s/tokenizer.model", model_dir);
+ if (access(path, R_OK) != 0)
+ snprintf(path, sizeof(path), "%s/spiece.model", model_dir);
+ }
+ if (access(path, R_OK) == 0) {
+ t->kind = TOK_KIND_SPM;
+ t->spm = tok_spm_load(model_dir);
+ if (!t->spm) {
+ set_err(err, errlen, "failed to load SentencePiece tokenizer");
+ goto fail;
+ }
+ t->spm_ws = tok_spm_workspace_new();
+ if (!t->spm_ws) {
+ set_err(err, errlen, "out of memory");
+ goto fail;
+ }
+ t->cls_id = tok_spm_token_id(t->spm, "<s>");
+ t->sep_id = tok_spm_token_id(t->spm, "</s>");
+ if (t->cls_id < 0 || t->sep_id < 0) {
+ set_err(err, errlen, "SentencePiece vocab missing <s>/</s>");
+ goto fail;
+ }
+ return t;
+ }
+
+ /* Byte-level BPE (Qwen family): vocab.json. */
+ snprintf(path, sizeof(path), "%s/vocab.json", model_dir);
+ t->kind = TOK_KIND_BPE;
+ t->bpe = tok_bpe_load(path);
+ if (!t->bpe) {
+ set_err(err, errlen, "failed to load tokenizer");
+ goto fail;
+ }
+ t->bpe_ws = tok_bpe_workspace_new();
+ if (!t->bpe_ws) {
+ set_err(err, errlen, "out of memory");
+ goto fail;
+ }
+ /* The contextual chunk separator is the tokenizer's <|endoftext|>; released
+ * models keep it out of vocab.json, so the family constant is the fallback.
+ * Qwen3-Embedding pools the last token (the same <|endoftext|>), so the bpe
+ * path appends it. A config that disables append_terminal_token would need
+ * to override this; the released models all enable it. */
+ int sep = tok_bpe_token_id(t->bpe, "<|endoftext|>");
+ t->context_separator_id = sep >= 0 ? sep : FFWD_CONTEXT_SEPARATOR_TOKEN_ID;
+ t->terminal_id = t->context_separator_id;
+ /* Off until the caller sets it from config->append_terminal_token; it is
+ * model-specific (pplx-embed does not append, for example). */
+ t->append_terminal = 0;
+
+ if (is_late) {
+ int id = tok_bpe_token_id(t->bpe, "[MASK]");
+ t->late_mask_id = id >= 0 ? id : FFWD_LATE_MASK_TOKEN_ID;
+ id = tok_bpe_token_id(t->bpe, "[Q]");
+ t->late_query_prefix_id = id >= 0 ? id : FFWD_LATE_QUERY_PREFIX_ID;
+ id = tok_bpe_token_id(t->bpe, "[D]");
+ t->late_document_prefix_id = id >= 0 ? id : FFWD_LATE_DOCUMENT_PREFIX_ID;
+
+ const char *punct = "!\"#$%&'()*+,-./:;<=>?@[\\]^_`{|}~";
+ for (const char *p = punct;
+ *p && t->n_late_skip_ids < (int)(sizeof(t->late_skip_ids) / sizeof(t->late_skip_ids[0]));
+ p++) {
+ char text[2] = {*p, '\0'};
+ int n_ids = 0;
+ int *ids = tok_bpe_encode(t->bpe, text, &n_ids);
+ if (ids && n_ids == 1)
+ t->late_skip_ids[t->n_late_skip_ids++] = ids[0];
+ free(ids);
+ }
+ }
+ return t;
+
+fail:
+ ffwd_tok_free(t);
+ return NULL;
+}
+
+void ffwd_tok_free(ffwd_tok_t *t) {
+ if (!t)
+ return;
+ if (t->bpe_ws)
+ tok_bpe_workspace_free(t->bpe_ws);
+ if (t->bpe)
+ tok_bpe_free(t->bpe);
+ if (t->wp_ws)
+ tok_wp_workspace_free(t->wp_ws);
+ if (t->wp)
+ tok_wp_free(t->wp);
+ if (t->spm_ws)
+ tok_spm_workspace_free(t->spm_ws);
+ if (t->spm)
+ tok_spm_free(t->spm);
+ free(t);
+}
+
+int ffwd_tok_context_separator_id(const ffwd_tok_t *t) { return t ? t->context_separator_id : -1; }
+
+void ffwd_tok_set_append_terminal(ffwd_tok_t *t, int on) {
+ if (t)
+ t->append_terminal = on ? 1 : 0;
+}
+
+/* Encode text and apply the model's special-token layout. Returns malloc'd ids
+ * and sets *n_out; NULL on error. */
+static int *tokenize_core(ffwd_tok_t *t, const char *text, int *n_out) {
+ *n_out = 0;
+
+ if (t->kind == TOK_KIND_WP || t->kind == TOK_KIND_SPM) {
+ int n = 0;
+ int *core = (t->kind == TOK_KIND_WP)
+ ? tok_wp_encode_with_workspace(t->wp, t->wp_ws, text, &n)
+ : tok_spm_encode_with_workspace(t->spm, t->spm_ws, text, &n);
+ /* Wrap [CLS] core [SEP]. A whitespace-only input cleans to zero core
+ * tokens (core == NULL, n == 0); the bare [CLS][SEP] pair is what
+ * Hugging Face produces for it too. Grow in place so only the one
+ * allocation is touched. */
+ if (n < 0 || n > INT_MAX - 2) {
+ free(core);
+ return NULL;
+ }
+ int *ids = realloc(core, (size_t)(n + 2) * sizeof(*ids));
+ if (!ids) {
+ free(core);
+ return NULL;
+ }
+ memmove(ids + 1, ids, (size_t)n * sizeof(*ids));
+ ids[0] = t->cls_id;
+ ids[n + 1] = t->sep_id;
+ *n_out = n + 2;
+ return ids;
+ }
+
+ /* BPE. */
+ int n = 0;
+ int *ids = tok_bpe_encode_with_workspace(t->bpe, t->bpe_ws, text, &n);
+ if (!ids || n <= 0) {
+ free(ids);
+ return NULL;
+ }
+ if (t->append_terminal) {
+ if (n == INT_MAX) {
+ free(ids);
+ return NULL;
+ }
+ int *grown = realloc(ids, (size_t)(n + 1) * sizeof(*ids));
+ if (!grown) {
+ free(ids);
+ return NULL;
+ }
+ ids = grown;
+ ids[n++] = t->terminal_id;
+ }
+ *n_out = n;
+ return ids;
+}
+
+int *ffwd_tokenize(ffwd_tok_t *t, const char *text, const char *query_instruct, int *n_out) {
+ if (n_out)
+ *n_out = 0;
+ if (!t || !text)
+ return NULL;
+
+ int n = 0;
+ int *ids;
+ if (!query_instruct) {
+ ids = tokenize_core(t, text, &n);
+ } else {
+ /* Tokenize the instruction and the input in one pass. */
+ size_t plen = strlen(query_instruct);
+ size_t tlen = strlen(text);
+ char *buf = malloc(plen + tlen + 1);
+ if (!buf)
+ return NULL;
+ memcpy(buf, query_instruct, plen);
+ memcpy(buf + plen, text, tlen + 1);
+ ids = tokenize_core(t, buf, &n);
+ free(buf);
+ }
+ if (!ids)
+ return NULL;
+ if (n_out)
+ *n_out = n;
+ return ids;
+}
+
+static int late_id_is_skipped(const ffwd_tok_t *t, int id) {
+ for (int i = 0; i < t->n_late_skip_ids; i++) {
+ if (t->late_skip_ids[i] == id)
+ return 1;
+ }
+ return 0;
+}
+
+int ffwd_tokenize_late(ffwd_tok_t *t, const char *text, int is_query, ffwd_late_tokens_t *out) {
+ memset(out, 0, sizeof(*out));
+ if (!t || !text)
+ return -1;
+
+ int raw_n = 0;
+ int *raw = tokenize_core(t, text, &raw_n);
+ if (!raw)
+ return -1;
+
+ int target = raw_n + 1;
+ if (is_query && target < FFWD_LATE_QUERY_TOKENS)
+ target = FFWD_LATE_QUERY_TOKENS;
+
+ out->ids = malloc((size_t)target * sizeof(*out->ids));
+ if (!out->ids) {
+ free(raw);
+ return -1;
+ }
+ out->ids[0] = raw[0];
+ out->ids[1] = is_query ? t->late_query_prefix_id : t->late_document_prefix_id;
+ if (raw_n > 1)
+ memcpy(out->ids + 2, raw + 1, (size_t)(raw_n - 1) * sizeof(*out->ids));
+ out->n_tokens = raw_n + 1;
+ free(raw);
+
+ if (is_query) {
+ while (out->n_tokens < FFWD_LATE_QUERY_TOKENS)
+ out->ids[out->n_tokens++] = t->late_mask_id;
+ out->n_keep = out->n_tokens;
+ } else {
+ out->keep = malloc((size_t)out->n_tokens * sizeof(*out->keep));
+ if (!out->keep) {
+ ffwd_late_tokens_free(out);
+ return -1;
+ }
+ for (int i = 0; i < out->n_tokens; i++) {
+ if (!late_id_is_skipped(t, out->ids[i]))
+ out->keep[out->n_keep++] = i;
+ }
+ }
+
+ if (out->n_keep <= 0) {
+ ffwd_late_tokens_free(out);
+ return -1;
+ }
+ return 0;
+}
+
+void ffwd_late_tokens_free(ffwd_late_tokens_t *out) {
+ if (!out)
+ return;
+ free(out->ids);
+ free(out->keep);
+ memset(out, 0, sizeof(*out));
+}
diff --git a/libffwd/unicode.h b/libffwd/unicode.h
new file mode 100644
index 0000000..bce8967
--- /dev/null
+++ b/libffwd/unicode.h
@@ -0,0 +1,4992 @@
+/* Generated by tools/gen_wordpiece_unicode.py from Python unicodedata
+ * (Unicode 13.0.0). Do not edit by hand.
+ *
+ * Tables for the BasicTokenizer, matching transformers' BertTokenizer.
+ *
+ * WP_PUNCT_RANGES / WP_CONTROL_RANGES: _is_punctuation and _is_control as sorted
+ * [lo, hi] ranges. Punctuation is the ASCII set (33-47/58-64/91-96/123-126) plus
+ * every category P* codepoint. Control is categories Cc, Cf, Co minus
+ * tab/newline/carriage-return (those route to whitespace). Unassigned (Cn) is
+ * intentionally not control: it never occurs in real text and would bind the
+ * table to one Unicode version.
+ *
+ * WP_FOLD: the do_lower_case fold (Python str.lower then NFD then drop Mn marks),
+ * sorted by codepoint. n is the output length (0 drops a combining mark; up to
+ * 3). Hangul syllables (U+AC00..U+D7A3) decompose by formula on the C side and
+ * are excluded here. */
+#ifndef WORDPIECE_UNICODE_H
+#define WORDPIECE_UNICODE_H
+
+#include <stdint.h>
+
+typedef struct {
+ uint32_t lo;
+ uint32_t hi;
+} wp_range_t;
+
+typedef struct {
+ uint32_t cp;
+ uint32_t out[3];
+ uint8_t n;
+} wp_fold_t;
+
+static const wp_range_t WP_PUNCT_RANGES[] = {
+ {0x21, 0x2F}, {0x3A, 0x40}, {0x5B, 0x60}, {0x7B, 0x7E},
+ {0xA1, 0xA1}, {0xA7, 0xA7}, {0xAB, 0xAB}, {0xB6, 0xB7},
+ {0xBB, 0xBB}, {0xBF, 0xBF}, {0x37E, 0x37E}, {0x387, 0x387},
+ {0x55A, 0x55F}, {0x589, 0x58A}, {0x5BE, 0x5BE}, {0x5C0, 0x5C0},
+ {0x5C3, 0x5C3}, {0x5C6, 0x5C6}, {0x5F3, 0x5F4}, {0x609, 0x60A},
+ {0x60C, 0x60D}, {0x61B, 0x61B}, {0x61E, 0x61F}, {0x66A, 0x66D},
+ {0x6D4, 0x6D4}, {0x700, 0x70D}, {0x7F7, 0x7F9}, {0x830, 0x83E},
+ {0x85E, 0x85E}, {0x964, 0x965}, {0x970, 0x970}, {0x9FD, 0x9FD},
+ {0xA76, 0xA76}, {0xAF0, 0xAF0}, {0xC77, 0xC77}, {0xC84, 0xC84},
+ {0xDF4, 0xDF4}, {0xE4F, 0xE4F}, {0xE5A, 0xE5B}, {0xF04, 0xF12},
+ {0xF14, 0xF14}, {0xF3A, 0xF3D}, {0xF85, 0xF85}, {0xFD0, 0xFD4},
+ {0xFD9, 0xFDA}, {0x104A, 0x104F}, {0x10FB, 0x10FB}, {0x1360, 0x1368},
+ {0x1400, 0x1400}, {0x166E, 0x166E}, {0x169B, 0x169C}, {0x16EB, 0x16ED},
+ {0x1735, 0x1736}, {0x17D4, 0x17D6}, {0x17D8, 0x17DA}, {0x1800, 0x180A},
+ {0x1944, 0x1945}, {0x1A1E, 0x1A1F}, {0x1AA0, 0x1AA6}, {0x1AA8, 0x1AAD},
+ {0x1B5A, 0x1B60}, {0x1BFC, 0x1BFF}, {0x1C3B, 0x1C3F}, {0x1C7E, 0x1C7F},
+ {0x1CC0, 0x1CC7}, {0x1CD3, 0x1CD3}, {0x2010, 0x2027}, {0x2030, 0x2043},
+ {0x2045, 0x2051}, {0x2053, 0x205E}, {0x207D, 0x207E}, {0x208D, 0x208E},
+ {0x2308, 0x230B}, {0x2329, 0x232A}, {0x2768, 0x2775}, {0x27C5, 0x27C6},
+ {0x27E6, 0x27EF}, {0x2983, 0x2998}, {0x29D8, 0x29DB}, {0x29FC, 0x29FD},
+ {0x2CF9, 0x2CFC}, {0x2CFE, 0x2CFF}, {0x2D70, 0x2D70}, {0x2E00, 0x2E2E},
+ {0x2E30, 0x2E4F}, {0x2E52, 0x2E52}, {0x3001, 0x3003}, {0x3008, 0x3011},
+ {0x3014, 0x301F}, {0x3030, 0x3030}, {0x303D, 0x303D}, {0x30A0, 0x30A0},
+ {0x30FB, 0x30FB}, {0xA4FE, 0xA4FF}, {0xA60D, 0xA60F}, {0xA673, 0xA673},
+ {0xA67E, 0xA67E}, {0xA6F2, 0xA6F7}, {0xA874, 0xA877}, {0xA8CE, 0xA8CF},
+ {0xA8F8, 0xA8FA}, {0xA8FC, 0xA8FC}, {0xA92E, 0xA92F}, {0xA95F, 0xA95F},
+ {0xA9C1, 0xA9CD}, {0xA9DE, 0xA9DF}, {0xAA5C, 0xAA5F}, {0xAADE, 0xAADF},
+ {0xAAF0, 0xAAF1}, {0xABEB, 0xABEB}, {0xFD3E, 0xFD3F}, {0xFE10, 0xFE19},
+ {0xFE30, 0xFE52}, {0xFE54, 0xFE61}, {0xFE63, 0xFE63}, {0xFE68, 0xFE68},
+ {0xFE6A, 0xFE6B}, {0xFF01, 0xFF03}, {0xFF05, 0xFF0A}, {0xFF0C, 0xFF0F},
+ {0xFF1A, 0xFF1B}, {0xFF1F, 0xFF20}, {0xFF3B, 0xFF3D}, {0xFF3F, 0xFF3F},
+ {0xFF5B, 0xFF5B}, {0xFF5D, 0xFF5D}, {0xFF5F, 0xFF65}, {0x10100, 0x10102},
+ {0x1039F, 0x1039F}, {0x103D0, 0x103D0}, {0x1056F, 0x1056F}, {0x10857, 0x10857},
+ {0x1091F, 0x1091F}, {0x1093F, 0x1093F}, {0x10A50, 0x10A58}, {0x10A7F, 0x10A7F},
+ {0x10AF0, 0x10AF6}, {0x10B39, 0x10B3F}, {0x10B99, 0x10B9C}, {0x10EAD, 0x10EAD},
+ {0x10F55, 0x10F59}, {0x11047, 0x1104D}, {0x110BB, 0x110BC}, {0x110BE, 0x110C1},
+ {0x11140, 0x11143}, {0x11174, 0x11175}, {0x111C5, 0x111C8}, {0x111CD, 0x111CD},
+ {0x111DB, 0x111DB}, {0x111DD, 0x111DF}, {0x11238, 0x1123D}, {0x112A9, 0x112A9},
+ {0x1144B, 0x1144F}, {0x1145A, 0x1145B}, {0x1145D, 0x1145D}, {0x114C6, 0x114C6},
+ {0x115C1, 0x115D7}, {0x11641, 0x11643}, {0x11660, 0x1166C}, {0x1173C, 0x1173E},
+ {0x1183B, 0x1183B}, {0x11944, 0x11946}, {0x119E2, 0x119E2}, {0x11A3F, 0x11A46},
+ {0x11A9A, 0x11A9C}, {0x11A9E, 0x11AA2}, {0x11C41, 0x11C45}, {0x11C70, 0x11C71},
+ {0x11EF7, 0x11EF8}, {0x11FFF, 0x11FFF}, {0x12470, 0x12474}, {0x16A6E, 0x16A6F},
+ {0x16AF5, 0x16AF5}, {0x16B37, 0x16B3B}, {0x16B44, 0x16B44}, {0x16E97, 0x16E9A},
+ {0x16FE2, 0x16FE2}, {0x1BC9F, 0x1BC9F}, {0x1DA87, 0x1DA8B}, {0x1E95E, 0x1E95F},
+};
+enum { WP_PUNCT_RANGES_N = (int)(sizeof(WP_PUNCT_RANGES) / sizeof(WP_PUNCT_RANGES[0])) };
+
+static const wp_range_t WP_CONTROL_RANGES[] = {
+ {0x0, 0x8}, {0xB, 0xC}, {0xE, 0x1F}, {0x7F, 0x9F},
+ {0xAD, 0xAD}, {0x600, 0x605}, {0x61C, 0x61C}, {0x6DD, 0x6DD},
+ {0x70F, 0x70F}, {0x8E2, 0x8E2}, {0x180E, 0x180E}, {0x200B, 0x200F},
+ {0x202A, 0x202E}, {0x2060, 0x2064}, {0x2066, 0x206F}, {0xE000, 0xF8FF},
+ {0xFEFF, 0xFEFF}, {0xFFF9, 0xFFFB}, {0x110BD, 0x110BD}, {0x110CD, 0x110CD},
+ {0x13430, 0x13438}, {0x1BCA0, 0x1BCA3}, {0x1D173, 0x1D17A}, {0xE0001, 0xE0001},
+ {0xE0020, 0xE007F}, {0xF0000, 0xFFFFD}, {0x100000, 0x10FFFD},
+};
+enum { WP_CONTROL_RANGES_N = (int)(sizeof(WP_CONTROL_RANGES) / sizeof(WP_CONTROL_RANGES[0])) };
+
+static const wp_fold_t WP_FOLD[] = {
+ {0x41, {0x61, 0x0, 0x0}, 1},
+ {0x42, {0x62, 0x0, 0x0}, 1},
+ {0x43, {0x63, 0x0, 0x0}, 1},
+ {0x44, {0x64, 0x0, 0x0}, 1},
+ {0x45, {0x65, 0x0, 0x0}, 1},
+ {0x46, {0x66, 0x0, 0x0}, 1},
+ {0x47, {0x67, 0x0, 0x0}, 1},
+ {0x48, {0x68, 0x0, 0x0}, 1},
+ {0x49, {0x69, 0x0, 0x0}, 1},
+ {0x4A, {0x6A, 0x0, 0x0}, 1},
+ {0x4B, {0x6B, 0x0, 0x0}, 1},
+ {0x4C, {0x6C, 0x0, 0x0}, 1},
+ {0x4D, {0x6D, 0x0, 0x0}, 1},
+ {0x4E, {0x6E, 0x0, 0x0}, 1},
+ {0x4F, {0x6F, 0x0, 0x0}, 1},
+ {0x50, {0x70, 0x0, 0x0}, 1},
+ {0x51, {0x71, 0x0, 0x0}, 1},
+ {0x52, {0x72, 0x0, 0x0}, 1},
+ {0x53, {0x73, 0x0, 0x0}, 1},
+ {0x54, {0x74, 0x0, 0x0}, 1},
+ {0x55, {0x75, 0x0, 0x0}, 1},
+ {0x56, {0x76, 0x0, 0x0}, 1},
+ {0x57, {0x77, 0x0, 0x0}, 1},
+ {0x58, {0x78, 0x0, 0x0}, 1},
+ {0x59, {0x79, 0x0, 0x0}, 1},
+ {0x5A, {0x7A, 0x0, 0x0}, 1},
+ {0xC0, {0x61, 0x0, 0x0}, 1},
+ {0xC1, {0x61, 0x0, 0x0}, 1},
+ {0xC2, {0x61, 0x0, 0x0}, 1},
+ {0xC3, {0x61, 0x0, 0x0}, 1},
+ {0xC4, {0x61, 0x0, 0x0}, 1},
+ {0xC5, {0x61, 0x0, 0x0}, 1},
+ {0xC6, {0xE6, 0x0, 0x0}, 1},
+ {0xC7, {0x63, 0x0, 0x0}, 1},
+ {0xC8, {0x65, 0x0, 0x0}, 1},
+ {0xC9, {0x65, 0x0, 0x0}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{0xF2, {0x6F, 0x0, 0x0}, 1},
+ {0xF3, {0x6F, 0x0, 0x0}, 1},
+ {0xF4, {0x6F, 0x0, 0x0}, 1},
+ {0xF5, {0x6F, 0x0, 0x0}, 1},
+ {0xF6, {0x6F, 0x0, 0x0}, 1},
+ {0xF9, {0x75, 0x0, 0x0}, 1},
+ {0xFA, {0x75, 0x0, 0x0}, 1},
+ {0xFB, {0x75, 0x0, 0x0}, 1},
+ {0xFC, {0x75, 0x0, 0x0}, 1},
+ {0xFD, {0x79, 0x0, 0x0}, 1},
+ {0xFF, {0x79, 0x0, 0x0}, 1},
+ {0x100, {0x61, 0x0, 0x0}, 1},
+ {0x101, {0x61, 0x0, 0x0}, 1},
+ {0x102, {0x61, 0x0, 0x0}, 1},
+ {0x103, {0x61, 0x0, 0x0}, 1},
+ {0x104, {0x61, 0x0, 0x0}, 1},
+ {0x105, {0x61, 0x0, 0x0}, 1},
+ {0x106, {0x63, 0x0, 0x0}, 1},
+ {0x107, {0x63, 0x0, 0x0}, 1},
+ {0x108, {0x63, 0x0, 0x0}, 1},
+ {0x109, {0x63, 0x0, 0x0}, 1},
+ {0x10A, {0x63, 0x0, 0x0}, 1},
+ {0x10B, {0x63, 0x0, 0x0}, 1},
+ {0x10C, {0x63, 0x0, 0x0}, 1},
+ {0x10D, {0x63, 0x0, 0x0}, 1},
+ {0x10E, {0x64, 0x0, 0x0}, 1},
+ {0x10F, {0x64, 0x0, 0x0}, 1},
+ {0x110, {0x111, 0x0, 0x0}, 1},
+ {0x112, {0x65, 0x0, 0x0}, 1},
+ {0x113, {0x65, 0x0, 0x0}, 1},
+ {0x114, {0x65, 0x0, 0x0}, 1},
+ {0x115, {0x65, 0x0, 0x0}, 1},
+ {0x116, {0x65, 0x0, 0x0}, 1},
+ {0x117, {0x65, 0x0, 0x0}, 1},
+ {0x118, {0x65, 0x0, 0x0}, 1},
+ {0x119, {0x65, 0x0, 0x0}, 1},
+ {0x11A, {0x65, 0x0, 0x0}, 1},
+ {0x11B, {0x65, 0x0, 0x0}, 1},
+ {0x11C, {0x67, 0x0, 0x0}, 1},
+ {0x11D, {0x67, 0x0, 0x0}, 1},
+ {0x11E, {0x67, 0x0, 0x0}, 1},
+ {0x11F, {0x67, 0x0, 0x0}, 1},
+ {0x120, {0x67, 0x0, 0x0}, 1},
+ {0x121, {0x67, 0x0, 0x0}, 1},
+ {0x122, {0x67, 0x0, 0x0}, 1},
+ {0x123, {0x67, 0x0, 0x0}, 1},
+ {0x124, {0x68, 0x0, 0x0}, 1},
+ {0x125, {0x68, 0x0, 0x0}, 1},
+ {0x126, {0x127, 0x0, 0x0}, 1},
+ {0x128, {0x69, 0x0, 0x0}, 1},
+ {0x129, {0x69, 0x0, 0x0}, 1},
+ {0x12A, {0x69, 0x0, 0x0}, 1},
+ {0x12B, {0x69, 0x0, 0x0}, 1},
+ {0x12C, {0x69, 0x0, 0x0}, 1},
+ {0x12D, {0x69, 0x0, 0x0}, 1},
+ {0x12E, {0x69, 0x0, 0x0}, 1},
+ {0x12F, {0x69, 0x0, 0x0}, 1},
+ {0x130, {0x69, 0x0, 0x0}, 1},
+ {0x132, {0x133, 0x0, 0x0}, 1},
+ {0x134, {0x6A, 0x0, 0x0}, 1},
+ {0x135, {0x6A, 0x0, 0x0}, 1},
+ {0x136, {0x6B, 0x0, 0x0}, 1},
+ {0x137, {0x6B, 0x0, 0x0}, 1},
+ {0x139, {0x6C, 0x0, 0x0}, 1},
+ {0x13A, {0x6C, 0x0, 0x0}, 1},
+ {0x13B, {0x6C, 0x0, 0x0}, 1},
+ {0x13C, {0x6C, 0x0, 0x0}, 1},
+ {0x13D, {0x6C, 0x0, 0x0}, 1},
+ {0x13E, {0x6C, 0x0, 0x0}, 1},
+ {0x13F, {0x140, 0x0, 0x0}, 1},
+ {0x141, {0x142, 0x0, 0x0}, 1},
+ {0x143, {0x6E, 0x0, 0x0}, 1},
+ {0x144, {0x6E, 0x0, 0x0}, 1},
+ {0x145, {0x6E, 0x0, 0x0}, 1},
+ {0x146, {0x6E, 0x0, 0x0}, 1},
+ {0x147, {0x6E, 0x0, 0x0}, 1},
+ {0x148, {0x6E, 0x0, 0x0}, 1},
+ {0x14A, {0x14B, 0x0, 0x0}, 1},
+ {0x14C, {0x6F, 0x0, 0x0}, 1},
+ {0x14D, {0x6F, 0x0, 0x0}, 1},
+ {0x14E, {0x6F, 0x0, 0x0}, 1},
+ {0x14F, {0x6F, 0x0, 0x0}, 1},
+ {0x150, {0x6F, 0x0, 0x0}, 1},
+ {0x151, {0x6F, 0x0, 0x0}, 1},
+ {0x152, {0x153, 0x0, 0x0}, 1},
+ {0x154, {0x72, 0x0, 0x0}, 1},
+ {0x155, {0x72, 0x0, 0x0}, 1},
+ {0x156, {0x72, 0x0, 0x0}, 1},
+ {0x157, {0x72, 0x0, 0x0}, 1},
+ {0x158, {0x72, 0x0, 0x0}, 1},
+ {0x159, {0x72, 0x0, 0x0}, 1},
+ {0x15A, {0x73, 0x0, 0x0}, 1},
+ {0x15B, {0x73, 0x0, 0x0}, 1},
+ {0x15C, {0x73, 0x0, 0x0}, 1},
+ {0x15D, {0x73, 0x0, 0x0}, 1},
+ {0x15E, {0x73, 0x0, 0x0}, 1},
+ {0x15F, {0x73, 0x0, 0x0}, 1},
+ {0x160, {0x73, 0x0, 0x0}, 1},
+ {0x161, {0x73, 0x0, 0x0}, 1},
+ {0x162, {0x74, 0x0, 0x0}, 1},
+ {0x163, {0x74, 0x0, 0x0}, 1},
+ {0x164, {0x74, 0x0, 0x0}, 1},
+ {0x165, {0x74, 0x0, 0x0}, 1},
+ {0x166, {0x167, 0x0, 0x0}, 1},
+ {0x168, {0x75, 0x0, 0x0}, 1},
+ {0x169, {0x75, 0x0, 0x0}, 1},
+ {0x16A, {0x75, 0x0, 0x0}, 1},
+ {0x16B, {0x75, 0x0, 0x0}, 1},
+ {0x16C, {0x75, 0x0, 0x0}, 1},
+ {0x16D, {0x75, 0x0, 0x0}, 1},
+ {0x16E, {0x75, 0x0, 0x0}, 1},
+ {0x16F, {0x75, 0x0, 0x0}, 1},
+ {0x170, {0x75, 0x0, 0x0}, 1},
+ {0x171, {0x75, 0x0, 0x0}, 1},
+ {0x172, {0x75, 0x0, 0x0}, 1},
+ {0x173, {0x75, 0x0, 0x0}, 1},
+ {0x174, {0x77, 0x0, 0x0}, 1},
+ {0x175, {0x77, 0x0, 0x0}, 1},
+ {0x176, {0x79, 0x0, 0x0}, 1},
+ {0x177, {0x79, 0x0, 0x0}, 1},
+ {0x178, {0x79, 0x0, 0x0}, 1},
+ {0x179, {0x7A, 0x0, 0x0}, 1},
+ {0x17A, {0x7A, 0x0, 0x0}, 1},
+ {0x17B, {0x7A, 0x0, 0x0}, 1},
+ {0x17C, {0x7A, 0x0, 0x0}, 1},
+ {0x17D, {0x7A, 0x0, 0x0}, 1},
+ {0x17E, {0x7A, 0x0, 0x0}, 1},
+ {0x181, {0x253, 0x0, 0x0}, 1},
+ {0x182, {0x183, 0x0, 0x0}, 1},
+ {0x184, {0x185, 0x0, 0x0}, 1},
+ {0x186, {0x254, 0x0, 0x0}, 1},
+ {0x187, {0x188, 0x0, 0x0}, 1},
+ {0x189, {0x256, 0x0, 0x0}, 1},
+ {0x18A, {0x257, 0x0, 0x0}, 1},
+ {0x18B, {0x18C, 0x0, 0x0}, 1},
+ {0x18E, {0x1DD, 0x0, 0x0}, 1},
+ {0x18F, {0x259, 0x0, 0x0}, 1},
+ {0x190, {0x25B, 0x0, 0x0}, 1},
+ {0x191, {0x192, 0x0, 0x0}, 1},
+ {0x193, {0x260, 0x0, 0x0}, 1},
+ {0x194, {0x263, 0x0, 0x0}, 1},
+ {0x196, {0x269, 0x0, 0x0}, 1},
+ {0x197, {0x268, 0x0, 0x0}, 1},
+ {0x198, {0x199, 0x0, 0x0}, 1},
+ {0x19C, {0x26F, 0x0, 0x0}, 1},
+ {0x19D, {0x272, 0x0, 0x0}, 1},
+ {0x19F, {0x275, 0x0, 0x0}, 1},
+ {0x1A0, {0x6F, 0x0, 0x0},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, 0x0}, 1},
+ {0x1FE, {0xF8, 0x0, 0x0}, 1},
+ {0x1FF, {0xF8, 0x0, 0x0}, 1},
+ {0x200, {0x61, 0x0, 0x0}, 1},
+ {0x201, {0x61, 0x0, 0x0}, 1},
+ {0x202, {0x61, 0x0, 0x0}, 1},
+ {0x203, {0x61, 0x0, 0x0}, 1},
+ {0x204, {0x65, 0x0, 0x0}, 1},
+ {0x205, {0x65, 0x0, 0x0}, 1},
+ {0x206, {0x65, 0x0, 0x0}, 1},
+ {0x207, {0x65, 0x0, 0x0}, 1},
+ {0x208, {0x69, 0x0, 0x0}, 1},
+ {0x209, {0x69, 0x0, 0x0}, 1},
+ {0x20A, {0x69, 0x0, 0x0}, 1},
+ {0x20B, {0x69, 0x0, 0x0}, 1},
+ {0x20C, {0x6F, 0x0, 0x0}, 1},
+ {0x20D, {0x6F, 0x0, 0x0}, 1},
+ {0x20E, {0x6F, 0x0, 0x0}, 1},
+ {0x20F, {0x6F, 0x0, 0x0}, 1},
+ {0x210, {0x72, 0x0, 0x0}, 1},
+ {0x211, {0x72, 0x0, 0x0}, 1},
+ {0x212, {0x72, 0x0, 0x0}, 1},
+ {0x213, {0x72, 0x0, 0x0}, 1},
+ {0x214, {0x75, 0x0, 0x0}, 1},
+ {0x215, {0x75, 0x0, 0x0}, 1},
+ {0x216, {0x75, 0x0, 0x0}, 1},
+ {0x217, {0x75, 0x0, 0x0}, 1},
+ {0x218, {0x73, 0x0, 0x0}, 1},
+ {0x219, {0x73, 0x0, 0x0}, 1},
+ {0x21A, {0x74, 0x0, 0x0}, 1},
+ {0x21B, {0x74, 0x0, 0x0}, 1},
+ {0x21C, {0x21D, 0x0, 0x0}, 1},
+ {0x21E, {0x68, 0x0, 0x0}, 1},
+ {0x21F, {0x68, 0x0, 0x0}, 1},
+ {0x220, {0x19E, 0x0, 0x0}, 1},
+ {0x222, {0x223, 0x0, 0x0}, 1},
+ {0x224, {0x225, 0x0, 0x0}, 1},
+ {0x226, {0x61, 0x0, 0x0}, 1},
+ {0x227, {0x61, 0x0, 0x0}, 1},
+ {0x228, {0x65, 0x0, 0x0}, 1},
+ {0x229, {0x65, 0x0, 0x0}, 1},
+ {0x22A, {0x6F, 0x0, 0x0}, 1},
+ {0x22B, {0x6F, 0x0, 0x0}, 1},
+ {0x22C, {0x6F, 0x0, 0x0}, 1},
+ {0x22D, {0x6F, 0x0, 0x0}, 1},
+ {0x22E, {0x6F, 0x0, 0x0}, 1},
+ {0x22F, {0x6F, 0x0, 0x0}, 1},
+ {0x230, {0x6F, 0x0, 0x0}, 1},
+ {0x231, {0x6F, 0x0, 0x0}, 1},
+ {0x232, {0x79, 0x0, 0x0}, 1},
+ {0x233, {0x79, 0x0, 0x0}, 1},
+ {0x23A, {0x2C65, 0x0, 0x0}, 1},
+ {0x23B, {0x23C, 0x0, 0x0}, 1},
+ {0x23D, {0x19A, 0x0, 0x0}, 1},
+ {0x23E, {0x2C66, 0x0, 0x0}, 1},
+ {0x241, {0x242, 0x0, 0x0}, 1},
+ {0x243, {0x180, 0x0, 0x0}, 1},
+ {0x244, {0x289, 0x0, 0x0}, 1},
+ {0x245, {0x28C, 0x0, 0x0}, 1},
+ {0x246, {0x247, 0x0, 0x0}, 1},
+ {0x248, {0x249, 0x0, 0x0}, 1},
+ {0x24A, {0x24B, 0x0, 0x0}, 1},
+ {0x24C, {0x24D, 0x0, 0x0}, 1},
+ {0x24E, {0x24F, 0x0, 0x0}, 1},
+ {0x300, {0x0, 0x0, 0x0}, 0},
+ {0x301, {0x0, 0x0, 0x0}, 0},
+ {0x302, {0x0, 0x0, 0x0}, 0},
+ {0x303, {0x0, 0x0, 0x0}, 0},
+ {0x304, {0x0, 0x0, 0x0}, 0},
+ {0x305, {0x0, 0x0, 0x0}, 0},
+ {0x306, {0x0, 0x0, 0x0}, 0},
+ {0x307, {0x0, 0x0, 0x0}, 0},
+ {0x308, {0x0, 0x0, 0x0}, 0},
+ {0x309, {0x0, 0x0, 0x0}, 0},
+ {0x30A, {0x0, 0x0, 0x0}, 0},
+ {0x30B, {0x0, 0x0, 0x0}, 0},
+ {0x30C, {0x0, 0x0, 0x0}, 0},
+ {0x30D, {0x0, 0x0, 0x0}, 0},
+ {0x30E, {0x0, 0x0, 0x0}, 0},
+ {0x30F, {0x0, 0x0, 0x0}, 0},
+ {0x310, {0x0, 0x0, 0x0}, 0},
+ {0x311, {0x0, 0x0, 0x0}, 0},
+ {0x312, {0x0, 0x0, 0x0}, 0},
+ {0x313, {0x0, 0x0, 0x0}, 0},
+ {0x314, {0x0, 0x0, 0x0}, 0},
+ {0x315, {0x0, 0x0, 0x0}, 0},
+ {0x316, {0x0, 0x0, 0x0}, 0},
+ {0x317, {0x0, 0x0, 0x0}, 0},
+ {0x318, {0x0, 0x0, 0x0}, 0},
+ {0x319, {0x0, 0x0, 0x0}, 0},
+ {0x31A, {0x0, 0x0, 0x0}, 0},
+ {0x31B, {0x0, 0x0, 0x0}, 0},
+ {0x31C, {0x0, 0x0, 0x0}, 0},
+ {0x31D, {0x0, 0x0, 0x0}, 0},
+ {0x31E, {0x0, 0x0, 0x0}, 0},
+ {0x31F, {0x0, 0x0, 0x0}, 0},
+ {0x320, {0x0, 0x0, 0x0}, 0},
+ {0x321, {0x0, 0x0, 0x0}, 0},
+ {0x322, {0x0, 0x0, 0x0}, 0},
+ {0x323, {0x0, 0x0, 0x0}, 0},
+ {0x324, {0x0, 0x0, 0x0}, 0},
+ {0x325, {0x0, 0x0, 0x0}, 0},
+ {0x326, {0x0, 0x0, 0x0}, 0},
+ {0x327, {0x0, 0x0, 0x0}, 0},
+ {0x328, {0x0, 0x0, 0x0}, 0},
+ {0x329, {0x0, 0x0, 0x0}, 0},
+ {0x32A, {0x0, 0x0, 0x0}, 0},
+ {0x32B, {0x0, 0x0, 0x0}, 0},
+ {0x32C, {0x0, 0x0, 0x0}, 0},
+ {0x32D, {0x0, 0x0, 0x0}, 0},
+ {0x32E, {0x0, 0x0, 0x0}, 0},
+ {0x32F, {0x0, 0x0, 0x0}, 0},
+ {0x330, {0x0, 0x0, 0x0}, 0},
+ {0x331, {0x0, 0x0, 0x0}, 0},
+ {0x332, {0x0, 0x0, 0x0}, 0},
+ {0x333, {0x0, 0x0, 0x0}, 0},
+ {0x334, {0x0, 0x0, 0x0}, 0},
+ {0x335, {0x0, 0x0, 0x0}, 0},
+ {0x336, {0x0, 0x0, 0x0}, 0},
+ {0x337, {0x0, 0x0, 0x0}, 0},
+ {0x338, {0x0, 0x0, 0x0}, 0},
+ {0x339, {0x0, 0x0, 0x0}, 0},
+ {0x33A, {0x0, 0x0, 0x0}, 0},
+ {0x33B, {0x0, 0x0, 0x0}, 0},
+ {0x33C, {0x0, 0x0, 0x0}, 0},
+ {0x33D, {0x0, 0x0, 0x0}, 0},
+ {0x33E, {0x0, 0x0, 0x0}, 0},
+ {0x33F, {0x0, 0x0, 0x0}, 0},
+ {0x340, {0x0, 0x0, 0x0}, 0},
+ {0x341, {0x0, 0x0, 0x0}, 0},
+ {0x342, {0x0, 0x0, 0x0}, 0},
+ {0x343, {0x0, 0x0, 0x0}, 0},
+ {0x344, {0x0, 0x0, 0x0}, 0},
+ {0x345, {0x0, 0x0, 0x0}, 0},
+ {0x346, {0x0, 0x0, 0x0}, 0},
+ {0x347, {0x0, 0x0, 0x0}, 0},
+ {0x348, {0x0, 0x0, 0x0}, 0},
+ {0x349, {0x0, 0x0, 0x0}, 0},
+ {0x34A, {0x0, 0x0, 0x0}, 0},
+ {0x34B, {0x0, 0x0, 0x0}, 0},
+ {0x34C, {0x0, 0x0, 0x0}, 0},
+ {0x34D, {0x0, 0x0, 0x0}, 0},
+ {0x34E, {0x0, 0x0, 0x0}, 0},
+ {0x34F, {0x0, 0x0, 0x0}, 0},
+ {0x350, {0x0, 0x0, 0x0}, 0},
+ {0x351, {0x0, 0x0, 0x0}, 0},
+ {0x352, {0x0, 0x0, 0x0}, 0},
+ {0x353, {0x0, 0x0, 0x0}, 0},
+ {0x354, {0x0, 0x0, 0x0}, 0},
+ {0x355, {0x0, 0x0, 0x0}, 0},
+ {0x356, {0x0, 0x0, 0x0}, 0},
+ {0x357, {0x0, 0x0, 0x0}, 0},
+ {0x358, {0x0, 0x0, 0x0}, 0},
+ {0x359, {0x0, 0x0, 0x0}, 0},
+ {0x35A, {0x0, 0x0, 0x0}, 0},
+ {0x35B, {0x0, 0x0, 0x0}, 0},
+ {0x35C, {0x0, 0x0, 0x0}, 0},
+ {0x35D, {0x0, 0x0, 0x0}, 0},
+ {0x35E, {0x0, 0x0, 0x0}, 0},
+ {0x35F, {0x0, 0x0, 0x0}, 0},
+ {0x360, {0x0, 0x0, 0x0}, 0},
+ {0x361, {0x0, 0x0, 0x0}, 0},
+ {0x362, {0x0, 0x0, 0x0}, 0},
+ {0x363, {0x0, 0x0, 0x0}, 0},
+ {0x364, {0x0, 0x0, 0x0}, 0},
+ {0x365, {0x0, 0x0, 0x0}, 0},
+ {0x366, {0x0, 0x0, 0x0}, 0},
+ {0x367, {0x0, 0x0, 0x0}, 0},
+ {0x368, {0x0, 0x0, 0x0}, 0},
+ {0x369, {0x0, 0x0, 0x0}, 0},
+ {0x36A, {0x0, 0x0, 0x0}, 0},
+ {0x36B, {0x0, 0x0, 0x0}, 0},
+ {0x36C, {0x0, 0x0, 0x0}, 0},
+ {0x36D, {0x0, 0x0, 0x0}, 0},
+ {0x36E, {0x0, 0x0, 0x0}, 0},
+ {0x36F, {0x0, 0x0, 0x0}, 0},
+ {0x370, {0x371, 0x0, 0x0}, 1},
+ {0x372, {0x373, 0x0, 0x0}, 1},
+ {0x374, {0x2B9, 0x0, 0x0}, 1},
+ {0x376, {0x377, 0x0, 0x0}, 1},
+ {0x37E, {0x3B, 0x0, 0x0}, 1},
+ {0x37F, {0x3F3, 0x0, 0x0}, 1},
+ {0x385, {0xA8, 0x0, 0x0}, 1},
+ {0x386, {0x3B1, 0x0, 0x0}, 1},
+ {0x387, {0xB7, 0x0, 0x0}, 1},
+ {0x388, {0x3B5, 0x0, 0x0}, 1},
+ {0x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 1},
+ {0x404, {0x454, 0x0, 0x0}, 1},
+ {0x405, {0x455, 0x0, 0x0}, 1},
+ {0x406, {0x456, 0x0, 0x0}, 1},
+ {0x407, {0x456, 0x0, 0x0}, 1},
+ {0x408, {0x458, 0x0, 0x0}, 1},
+ {0x409, {0x459, 0x0, 0x0}, 1},
+ {0x40A, {0x45A, 0x0, 0x0}, 1},
+ {0x40B, {0x45B, 0x0, 0x0}, 1},
+ {0x40C, {0x43A, 0x0, 0x0}, 1},
+ {0x40D, {0x438, 0x0, 0x0}, 1},
+ {0x40E, {0x443, 0x0, 0x0}, 1},
+ {0x40F, {0x45F, 0x0, 0x0}, 1},
+ {0x410, {0x430, 0x0, 0x0}, 1},
+ {0x411, {0x431, 0x0, 0x0}, 1},
+ {0x412, {0x432, 0x0, 0x0}, 1},
+ {0x413, {0x433, 0x0, 0x0}, 1},
+ {0x414, {0x434, 0x0, 0x0}, 1},
+ {0x415, {0x435, 0x0, 0x0}, 1},
+ {0x416, {0x436, 0x0, 0x0}, 1},
+ {0x417, {0x437, 0x0, 0x0}, 1},
+ {0x418, {0x438, 0x0, 0x0}, 1},
+ {0x419, {0x438, 0x0, 0x0}, 1},
+ {0x41A, {0x43A, 0x0, 0x0}, 1},
+ {0x41B, {0x43B, 0x0, 0x0}, 1},
+ {0x41C, {0x43C, 0x0, 0x0}, 1},
+ {0x41D, {0x43D, 0x0, 0x0}, 1},
+ {0x41E, {0x43E, 0x0, 0x0}, 1},
+ {0x41F, {0x43F, 0x0, 0x0}, 1},
+ {0x420, {0x440, 0x0, 0x0}, 1},
+ {0x421, {0x441, 0x0, 0x0}, 1},
+ {0x422, {0x442, 0x0, 0x0}, 1},
+ {0x423, {0x443, 0x0, 0x0}, 1},
+ {0x424, {0x444, 0x0, 0x0}, 1},
+ {0x425, {0x445, 0x0, 0x0}, 1},
+ {0x426, {0x446, 0x0, 0x0}, 1},
+ {0x427, {0x447, 0x0, 0x0}, 1},
+ {0x428, {0x448, 0x0, 0x0}, 1},
+ {0x429, {0x449, 0x0, 0x0}, 1},
+ {0x42A, {0x44A, 0x0, 0x0}, 1},
+ {0x42B, {0x44B, 0x0, 0x0}, 1},
+ {0x42C, {0x44C, 0x0, 0x0}, 1},
+ {0x42D, {0x44D, 0x0, 0x0}, 1},
+ {0x42E, {0x44E, 0x0, 0x0}, 1},
+ {0x42F, {0x44F, 0x0, 0x0}, 1},
+ {0x439, {0x438, 0x0, 0x0}, 1},
+ {0x450, {0x435, 0x0, 0x0}, 1},
+ {0x451, {0x435, 0x0, 0x0}, 1},
+ {0x453, {0x433, 0x0, 0x0}, 1},
+ {0x457, {0x456, 0x0, 0x0}, 1},
+ {0x45C, {0x43A, 0x0, 0x0}, 1},
+ {0x45D, {0x438, 0x0, 0x0}, 1},
+ {0x45E, {0x443, 0x0, 0x0}, 1},
+ {0x460, {0x461, 0x0, 0x0}, 1},
+ {0x462, {0x463, 0x0, 0x0}, 1},
+ {0x464, {0x465, 0x0, 0x0}, 1},
+ {0x466, {0x467, 0x0, 0x0}, 1},
+ {0x468, {0x469, 0x0, 0x0}, 1},
+ {0x46A, {0x46B, 0x0, 0x0}, 1},
+ {0x46C, {0x46D, 0x0, 0x0}, 1},
+ {0x46E, {0x46F, 0x0, 0x0}, 1},
+ {0x470, {0x471, 0x0, 0x0}, 1},
+ {0x472, {0x473, 0x0, 0x0}, 1},
+ {0x474, {0x475, 0x0, 0x0}, 1},
+ {0x476, {0x475, 0x0, 0x0}, 1},
+ {0x477, {0x475, 0x0, 0x0}, 1},
+ {0x478, {0x479, 0x0, 0x0}, 1},
+ {0x47A, {0x47B, 0x0, 0x0}, 1},
+ {0x47C, {0x47D, 0x0, 0x0}, 1},
+ {0x47E, {0x47F, 0x0, 0x0}, 1},
+ {0x480, {0x481, 0x0, 0x0}, 1},
+ {0x483, {0x0, 0x0, 0x0}, 0},
+ {0x484, {0x0, 0x0, 0x0}, 0},
+ {0x485, {0x0, 0x0, 0x0}, 0},
+ {0x486, {0x0, 0x0, 0x0}, 0},
+ {0x487, {0x0, 0x0, 0x0}, 0},
+ {0x48A, {0x48B, 0x0, 0x0}, 1},
+ {0x48C, {0x48D, 0x0, 0x0}, 1},
+ {0x48E, {0x48F, 0x0, 0x0}, 1},
+ {0x490, {0x491, 0x0, 0x0}, 1},
+ {0x492, {0x493, 0x0, 0x0}, 1},
+ {0x494, {0x495, 0x0, 0x0}, 1},
+ {0x496, {0x497, 0x0, 0x0}, 1},
+ {0x498, {0x499, 0x0, 0x0}, 1},
+ {0x49A, {0x49B, 0x0, 0x0}, 1},
+ {0x49C, {0x49D, 0x0, 0x0}, 1},
+ {0x49E, {0x49F, 0x0, 0x0}, 1},
+ {0x4A0, {0x4A1, 0x0, 0x0}, 1},
+ {0x4A2, {0x4A3, 0x0, 0x0}, 1},
+ {0x4A4, {0x4A5, 0x0, 0x0}, 1},
+ {0x4A6, {0x4A7, 0x0, 0x0}, 1},
+ {0x4A8, {0x4A9, 0x0, 0x0}, 1},
+ {0x4AA, {0x4AB, 0x0, 0x0}, 1},
+ {0x4AC, {0x4AD, 0x0, 0x0}, 1},
+ {0x4AE, {0x4AF, 0x0, 0x0}, 1},
+ {0x4B0, {0x4B1, 0x0, 0x0}, 1},
+ {0x4B2, {0x4B3, 0x0, 0x0}, 1},
+ {0x4B4, {0x4B5, 0x0, 0x0}, 1},
+ {0x4B6, {0x4B7, 0x0, 0x0}, 1},
+ {0x4B8, {0x4B9, 0x0, 0x0}, 1},
+ {0x4BA, {0x4BB, 0x0, 0x0}, 1},
+ {0x4BC, {0x4BD, 0x0, 0x0}, 1},
+ {0x4BE, {0x4BF, 0x0, 0x0}, 1},
+ {0x4C0, {0x4CF, 0x0, 0x0}, 1},
+ {0x4C1, {0x436, 0x0, 0x0}, 1},
+ {0x4C2, {0x436, 0x0, 0x0}, 1},
+ {0x4C3, {0x4C4, 0x0, 0x0}, 1},
+ {0x4C5, {0x4C6, 0x0, 0x0}, 1},
+ {0x4C7, {0x4C8, 0x0, 0x0}, 1},
+ {0x4C9, {0x4CA, 0x0, 0x0}, 1},
+ {0x4CB, {0x4CC, 0x0, 0x0}, 1},
+ {0x4CD, {0x4CE, 0x0, 0x0}, 1},
+ {0x4D0, {0x430, 0x0, 0x0}, 1},
+ {0x4D1, {0x430, 0x0, 0x0}, 1},
+ {0x4D2, {0x430, 0x0, 0x0}, 1},
+ {0x4D3, {0x430, 0x0, 0x0}, 1},
+ {0x4D4, {0x4D5, 0x0, 0x0}, 1},
+ {0x4D6, {0x435, 0x0, 0x0}, 1},
+ {0x4D7, {0x435, 0x0, 0x0}, 1},
+ {0x4D8, {0x4D9, 0x0, 0x0}, 1},
+ {0x4DA, {0x4D9, 0x0, 0x0}, 1},
+ {0x4DB, {0x4D9, 0x0, 0x0}, 1},
+ {0x4DC, {0x436, 0x0, 0x0}, 1},
+ {0x4DD, {0x436, 0x0, 0x0}, 1},
+ {0x4DE, {0x437, 0x0, 0x0}, 1},
+ {0x4DF, {0x437, 0x0, 0x0}, 1},
+ {0x4E0, {0x4E1, 0x0, 0x0}, 1},
+ {0x4E2, {0x438, 0x0, 0x0}, 1},
+ {0x4E3, {0x438, 0x0, 0x0}, 1},
+ {0x4E4, {0x438, 0x0, 0x0}, 1},
+ {0x4E5, {0x438, 0x0, 0x0}, 1},
+ {0x4E6, {0x43E, 0x0, 0x0}, 1},
+ {0x4E7, {0x43E, 0x0, 0x0}, 1},
+ {0x4E8, {0x4E9, 0x0, 0x0}, 1},
+ {0x4EA, {0x4E9, 0x0, 0x0}, 1},
+ {0x4EB, {0x4E9, 0x0, 0x0}, 1},
+ {0x4EC, {0x44D, 0x0, 0x0}, 1},
+ {0x4ED, {0x44D, 0x0, 0x0}, 1},
+ {0x4EE, {0x443, 0x0, 0x0}, 1},
+ {0x4EF, {0x443, 0x0, 0x0}, 1},
+ {0x4F0, {0x443, 0x0, 0x0}, 1},
+ {0x4F1, {0x443, 0x0, 0x0}, 1},
+ {0x4F2, {0x443, 0x0, 0x0}, 1},
+ {0x4F3, {0x443, 0x0, 0x0}, 1},
+ {0x4F4, {0x447, 0x0, 0x0}, 1},
+ {0x4F5, {0x447, 0x0, 0x0}, 1},
+ {0x4F6, {0x4F7, 0x0, 0x0}, 1},
+ {0x4F8, {0x44B, 0x0, 0x0}, 1},
+ {0x4F9, {0x44B, 0x0, 0x0}, 1},
+ {0x4FA, {0x4FB, 0x0, 0x0}, 1},
+ {0x4FC, {0x4FD, 0x0, 0x0}, 1},
+ {0x4FE, {0x4FF, 0x0, 0x0}, 1},
+ {0x500, {0x501, 0x0, 0x0}, 1},
+ {0x502, {0x503, 0x0, 0x0}, 1},
+ {0x504, {0x505, 0x0, 0x0}, 1},
+ {0x506, {0x507, 0x0, 0x0}, 1},
+ {0x508, {0x509, 0x0, 0x0}, 1},
+ {0x50A, {0x50B, 0x0, 0x0}, 1},
+ {0x50C, {0x50D, 0x0, 0x0}, 1},
+ {0x50E, {0x50F, 0x0, 0x0}, 1},
+ {0x510, {0x511, 0x0, 0x0}, 1},
+ {0x512, {0x513, 0x0, 0x0}, 1},
+ {0x514, {0x515, 0x0, 0x0}, 1},
+ {0x516, {0x517, 0x0, 0x0}, 1},
+ {0x518, {0x519, 0x0, 0x0}, 1},
+ {0x51A, {0x51B, 0x0, 0x0}, 1},
+ {0x51C, {0x51D, 0x0, 0x0}, 1},
+ {0x51E, {0x51F, 0x0, 0x0}, 1},
+ {0x520, {0x521, 0x0, 0x0}, 1},
+ {0x522, {0x523, 0x0, 0x0}, 1},
+ {0x524, {0x525, 0x0, 0x0}, 1},
+ {0x526, {0x527, 0x0, 0x0}, 1},
+ {0x528, {0x529, 0x0, 0x0}, 1},
+ {0x52A, {0x52B, 0x0, 0x0}, 1},
+ {0x52C, {0x52D, 0x0, 0x0}, 1},
+ {0x52E, {0x52F, 0x0, 0x0}, 1},
+ {0x531, {0x561, 0x0, 0x0}, 1},
+ {0x532, {0x562, 0x0, 0x0}, 1},
+ {0x533, {0x563, 0x0, 0x0}, 1},
+ {0x534, {0x564, 0x0, 0x0}, 1},
+ {0x535, {0x565, 0x0, 0x0}, 1},
+ {0x536, {0x566, 0x0, 0x0}, 1},
+ {0x537, {0x567, 0x0, 0x0}, 1},
+ {0x538, {0x568, 0x0, 0x0}, 1},
+ {0x539, {0x569, 0x0, 0x0}, 1},
+ {0x53A, {0x56A, 0x0, 0x0}, 1},
+ {0x53B, {0x56B, 0x0, 0x0}, 1},
+ {0x53C, {0x56C, 0x0, 0x0}, 1},
+ {0x53D, {0x56D, 0x0, 0x0}, 1},
+ {0x53E, {0x56E, 0x0, 0x0}, 1},
+ {0x53F, {0x56F, 0x0, 0x0}, 1},
+ {0x540, {0x570, 0x0, 0x0}, 1},
+ {0x541, {0x571, 0x0, 0x0}, 1},
+ {0x542, {0x572, 0x0, 0x0}, 1},
+ {0x543, {0x573, 0x0, 0x0}, 1},
+ {0x544, {0x574, 0x0, 0x0}, 1},
+ {0x545, {0x575, 0x0, 0x0}, 1},
+ {0x546, {0x576, 0x0, 0x0}, 1},
+ {0x547, {0x577, 0x0, 0x0}, 1},
+ {0x548, {0x578, 0x0, 0x0}, 1},
+ {0x549, {0x579, 0x0, 0x0}, 1},
+ {0x54A, {0x57A, 0x0, 0x0}, 1},
+ {0x54B, {0x57B, 0x0, 0x0}, 1},
+ {0x54C, {0x57C, 0x0, 0x0}, 1},
+ {0x54D, {0x57D, 0x0, 0x0}, 1},
+ {0x54E, {0x57E, 0x0, 0x0}, 1},
+ {0x54F, {0x57F, 0x0, 0x0}, 1},
+ {0x550, {0x580, 0x0, 0x0}, 1},
+ {0x551, {0x581, 0x0, 0x0}, 1},
+ {0x552, {0x582, 0x0, 0x0}, 1},
+ {0x553, {0x583, 0x0, 0x0}, 1},
+ {0x554, {0x584, 0x0, 0x0}, 1},
+ {0x555, {0x585, 0x0, 0x0}, 1},
+ {0x556, {0x586, 0x0, 0x0}, 1},
+ {0x591, {0x0, 0x0, 0x0}, 0},
+ {0x592, {0x0, 0x0, 0x0}, 0},
+ {0x593, {0x0, 0x0, 0x0}, 0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 0},
+ {0x5B8, {0x0, 0x0, 0x0}, 0},
+ {0x5B9, {0x0, 0x0, 0x0}, 0},
+ {0x5BA, {0x0, 0x0, 0x0}, 0},
+ {0x5BB, {0x0, 0x0, 0x0}, 0},
+ {0x5BC, {0x0, 0x0, 0x0}, 0},
+ {0x5BD, {0x0, 0x0, 0x0}, 0},
+ {0x5BF, {0x0, 0x0, 0x0}, 0},
+ {0x5C1, {0x0, 0x0, 0x0}, 0},
+ {0x5C2, {0x0, 0x0, 0x0}, 0},
+ {0x5C4, {0x0, 0x0, 0x0}, 0},
+ {0x5C5, {0x0, 0x0, 0x0}, 0},
+ {0x5C7, {0x0, 0x0, 0x0}, 0},
+ {0x610, {0x0, 0x0, 0x0}, 0},
+ {0x611, {0x0, 0x0, 0x0}, 0},
+ {0x612, {0x0, 0x0, 0x0}, 0},
+ {0x613, {0x0, 0x0, 0x0}, 0},
+ {0x614, {0x0, 0x0, 0x0}, 0},
+ {0x615, {0x0, 0x0, 0x0}, 0},
+ {0x616, {0x0, 0x0, 0x0}, 0},
+ {0x617, {0x0, 0x0, 0x0}, 0},
+ {0x618, {0x0, 0x0, 0x0}, 0},
+ {0x619, {0x0, 0x0, 0x0}, 0},
+ {0x61A, {0x0, 0x0, 0x0}, 0},
+ {0x622, {0x627, 0x0, 0x0}, 1},
+ {0x623, {0x627, 0x0, 0x0}, 1},
+ {0x624, {0x648, 0x0, 0x0}, 1},
+ {0x625, {0x627, 0x0, 0x0}, 1},
+ {0x626, {0x64A, 0x0, 0x0}, 1},
+ {0x64B, {0x0, 0x0, 0x0}, 0},
+ {0x64C, {0x0, 0x0, 0x0}, 0},
+ {0x64D, {0x0, 0x0, 0x0}, 0},
+ {0x64E, {0x0, 0x0, 0x0}, 0},
+ {0x64F, {0x0, 0x0, 0x0}, 0},
+ {0x650, {0x0, 0x0, 0x0}, 0},
+ {0x651, {0x0, 0x0, 0x0}, 0},
+ {0x652, {0x0, 0x0, 0x0}, 0},
+ {0x653, {0x0, 0x0,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0x0, 0x0}, 0},
+ {0x730, {0x0, 0x0, 0x0}, 0},
+ {0x731, {0x0, 0x0, 0x0}, 0},
+ {0x732, {0x0, 0x0, 0x0}, 0},
+ {0x733, {0x0, 0x0, 0x0}, 0},
+ {0x734, {0x0, 0x0, 0x0}, 0},
+ {0x735, {0x0, 0x0, 0x0}, 0},
+ {0x736, {0x0, 0x0, 0x0}, 0},
+ {0x737, {0x0, 0x0, 0x0}, 0},
+ {0x738, {0x0, 0x0, 0x0}, 0},
+ {0x739, {0x0, 0x0, 0x0}, 0},
+ {0x73A, {0x0, 0x0, 0x0}, 0},
+ {0x73B, {0x0, 0x0, 0x0}, 0},
+ {0x73C, {0x0, 0x0, 0x0}, 0},
+ {0x73D, {0x0, 0x0, 0x0}, 0},
+ {0x73E, {0x0, 0x0, 0x0}, 0},
+ {0x73F, {0x0, 0x0, 0x0}, 0},
+ {0x740, {0x0, 0x0, 0x0}, 0},
+ {0x741, {0x0, 0x0, 0x0}, 0},
+ {0x742, {0x0, 0x0, 0x0}, 0},
+ {0x743, {0x0, 0x0, 0x0}, 0},
+ {0x744, {0x0, 0x0, 0x0}, 0},
+ {0x745, {0x0, 0x0, 0x0}, 0},
+ {0x746, {0x0, 0x0, 0x0}, 0},
+ {0x747, {0x0, 0x0, 0x0}, 0},
+ {0x748, {0x0, 0x0, 0x0}, 0},
+ {0x749, {0x0, 0x0, 0x0}, 0},
+ {0x74A, {0x0, 0x0, 0x0}, 0},
+ {0x7A6, {0x0, 0x0, 0x0}, 0},
+ {0x7A7, {0x0, 0x0, 0x0}, 0},
+ {0x7A8, {0x0, 0x0, 0x0}, 0},
+ {0x7A9, {0x0, 0x0, 0x0}, 0},
+ {0x7AA, {0x0, 0x0, 0x0}, 0},
+ {0x7AB, {0x0, 0x0, 0x0}, 0},
+ {0x7AC, {0x0, 0x0, 0x0}, 0},
+ {0x7AD, {0x0, 0x0, 0x0}, 0},
+ {0x7AE, {0x0, 0x0, 0x0}, 0},
+ {0x7AF, {0x0, 0x0, 0x0}, 0},
+ {0x7B0, {0x0, 0x0, 0x0}, 0},
+ {0x7EB, {0x0, 0x0, 0x0}, 0},
+ {0x7EC, {0x0, 0x0, 0x0}, 0},
+ {0x7ED, {0x0, 0x0, 0x0}, 0},
+ {0x7EE, {0x0, 0x0, 0x0}, 0},
+ {0x7EF, {0x0, 0x0, 0x0}, 0},
+ {0x7F0, {0x0, 0x0, 0x0}, 0},
+ {0x7F1, {0x0, 0x0, 0x0}, 0},
+ {0x7F2, {0x0, 0x0, 0x0}, 0},
+ {0x7F3, {0x0, 0x0, 0x0}, 0},
+ {0x7FD, {0x0, 0x0, 0x0}, 0},
+ {0x816, {0x0, 0x0, 0x0}, 0},
+ {0x817, {0x0, 0x0, 0x0}, 0},
+ {0x818, {0x0, 0x0, 0x0}, 0},
+ {0x819, {0x0, 0x0, 0x0}, 0},
+ {0x81B, {0x0, 0x0, 0x0}, 0},
+ {0x81C, {0x0, 0x0, 0x0}, 0},
+ {0x81D, {0x0, 0x0, 0x0}, 0},
+ {0x81E, {0x0, 0x0, 0x0}, 0},
+ {0x81F, {0x0, 0x0, 0x0}, 0},
+ {0x820, {0x0, 0x0, 0x0}, 0},
+ {0x821, {0x0, 0x0, 0x0}, 0},
+ {0x822, {0x0, 0x0, 0x0}, 0},
+ {0x823, {0x0, 0x0, 0x0}, 0},
+ {0x825, {0x0, 0x0, 0x0}, 0},
+ {0x826, {0x0, 0x0, 0x0}, 0},
+ {0x827, {0x0, 0x0, 0x0}, 0},
+ {0x829, {0x0, 0x0, 0x0}, 0},
+ {0x82A, {0x0, 0x0, 0x0}, 0},
+ {0x82B, {0x0, 0x0, 0x0}, 0},
+ {0x82C, {0x0, 0x0, 0x0}, 0},
+ {0x82D, {0x0, 0x0, 0x0}, 0},
+ {0x859, {0x0, 0x0, 0x0}, 0},
+ {0x85A, {0x0, 0x0, 0x0}, 0},
+ {0x85B, {0x0, 0x0, 0x0}, 0},
+ {0x8D3, {0x0, 0x0, 0x0}, 0},
+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0x0, 0x0, 0x0}, 0},
+ {0x8F9, {0x0, 0x0, 0x0}, 0},
+ {0x8FA, {0x0, 0x0, 0x0}, 0},
+ {0x8FB, {0x0, 0x0, 0x0}, 0},
+ {0x8FC, {0x0, 0x0, 0x0}, 0},
+ {0x8FD, {0x0, 0x0, 0x0}, 0},
+ {0x8FE, {0x0, 0x0, 0x0}, 0},
+ {0x8FF, {0x0, 0x0, 0x0}, 0},
+ {0x900, {0x0, 0x0, 0x0}, 0},
+ {0x901, {0x0, 0x0, 0x0}, 0},
+ {0x902, {0x0, 0x0, 0x0}, 0},
+ {0x929, {0x928, 0x0, 0x0}, 1},
+ {0x931, {0x930, 0x0, 0x0}, 1},
+ {0x934, {0x933, 0x0, 0x0}, 1},
+ {0x93A, {0x0, 0x0, 0x0}, 0},
+ {0x93C, {0x0, 0x0, 0x0}, 0},
+ {0x941, {0x0, 0x0, 0x0}, 0},
+ {0x942, {0x0, 0x0, 0x0}, 0},
+ {0x943, {0x0, 0x0, 0x0}, 0},
+ {0x944, {0x0, 0x0, 0x0}, 0},
+ {0x945, {0x0, 0x0, 0x0}, 0},
+ {0x946, {0x0, 0x0, 0x0}, 0},
+ {0x947, {0x0, 0x0, 0x0}, 0},
+ {0x948, {0x0, 0x0, 0x0}, 0},
+ {0x94D, {0x0, 0x0, 0x0}, 0},
+ {0x951, {0x0, 0x0, 0x0}, 0},
+ {0x952, {0x0, 0x0, 0x0}, 0},
+ {0x953, {0x0, 0x0, 0x0}, 0},
+ {0x954, {0x0, 0x0, 0x0}, 0},
+ {0x955, {0x0, 0x0, 0x0}, 0},
+ {0x956, {0x0, 0x0, 0x0}, 0},
+ {0x957, {0x0, 0x0, 0x0}, 0},
+ {0x958, {0x915, 0x0, 0x0}, 1},
+ {0x959, {0x916, 0x0, 0x0}, 1},
+ {0x95A, {0x917, 0x0, 0x0}, 1},
+ {0x95B, {0x91C, 0x0, 0x0}, 1},
+ {0x95C, {0x921, 0x0, 0x0}, 1},
+ {0x95D, {0x922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1026, {0x1025, 0x0, 0x0}, 1},
+ {0x102D, {0x0, 0x0, 0x0}, 0},
+ {0x102E, {0x0, 0x0, 0x0}, 0},
+ {0x102F, {0x0, 0x0, 0x0}, 0},
+ {0x1030, {0x0, 0x0, 0x0}, 0},
+ {0x1032, {0x0, 0x0, 0x0}, 0},
+ {0x1033, {0x0, 0x0, 0x0}, 0},
+ {0x1034, {0x0, 0x0, 0x0}, 0},
+ {0x1035, {0x0, 0x0, 0x0}, 0},
+ {0x1036, {0x0, 0x0, 0x0}, 0},
+ {0x1037, {0x0, 0x0, 0x0}, 0},
+ {0x1039, {0x0, 0x0, 0x0}, 0},
+ {0x103A, {0x0, 0x0, 0x0}, 0},
+ {0x103D, {0x0, 0x0, 0x0}, 0},
+ {0x103E, {0x0, 0x0, 0x0}, 0},
+ {0x1058, {0x0, 0x0, 0x0}, 0},
+ {0x1059, {0x0, 0x0, 0x0}, 0},
+ {0x105E, {0x0, 0x0, 0x0}, 0},
+ {0x105F, {0x0, 0x0, 0x0}, 0},
+ {0x1060, {0x0, 0x0, 0x0}, 0},
+ {0x1071, {0x0, 0x0, 0x0}, 0},
+ {0x1072, {0x0, 0x0, 0x0}, 0},
+ {0x1073, {0x0, 0x0, 0x0}, 0},
+ {0x1074, {0x0, 0x0, 0x0}, 0},
+ {0x1082, {0x0, 0x0, 0x0}, 0},
+ {0x1085, {0x0, 0x0, 0x0}, 0},
+ {0x1086, {0x0, 0x0, 0x0}, 0},
+ {0x108D, {0x0, 0x0, 0x0}, 0},
+ {0x109D, {0x0, 0x0, 0x0}, 0},
+ {0x10A0, {0x2D00, 0x0, 0x0}, 1},
+ {0x10A1, {0x2D01, 0x0, 0x0}, 1},
+ {0x10A2, {0x2D02, 0x0, 0x0}, 1},
+ {0x10A3, {0x2D03, 0x0, 0x0}, 1},
+ {0x10A4, {0x2D04, 0x0, 0x0}, 1},
+ {0x10A5, {0x2D05, 0x0, 0x0}, 1},
+ {0x10A6, {0x2D06, 0x0, 0x0}, 1},
+ {0x10A7, {0x2D07, 0x0, 0x0}, 1},
+ {0x10A8, {0x2D08, 0x0, 0x0}, 1},
+ {0x10A9, {0x2D09, 0x0, 0x0}, 1},
+ {0x10AA, {0x2D0A, 0x0, 0x0}, 1},
+ {0x10AB, {0x2D0B, 0x0, 0x0}, 1},
+ {0x10AC, {0x2D0C, 0x0, 0x0}, 1},
+ {0x10AD, {0x2D0D, 0x0, 0x0}, 1},
+ {0x10AE, {0x2D0E, 0x0, 0x0}, 1},
+ {0x10AF, {0x2D0F, 0x0, 0x0}, 1},
+ {0x10B0, {0x2D10, 0x0, 0x0}, 1},
+ {0x10B1, {0x2D11, 0x0, 0x0}, 1},
+ {0x10B2, {0x2D12, 0x0, 0x0}, 1},
+ {0x10B3, {0x2D13, 0x0, 0x0}, 1},
+ {0x10B4, {0x2D14, 0x0, 0x0}, 1},
+ {0x10B5, {0x2D15, 0x0, 0x0}, 1},
+ {0x10B6, {0x2D16, 0x0, 0x0}, 1},
+ {0x10B7, {0x2D17, 0x0, 0x0}, 1},
+ {0x10B8, {0x2D18, 0x0, 0x0}, 1},
+ {0x10B9, {0x2D19, 0x0, 0x0}, 1},
+ {0x10BA, {0x2D1A, 0x0, 0x0}, 1},
+ {0x10BB, {0x2D1B, 0x0, 0x0}, 1},
+ {0x10BC, {0x2D1C, 0x0, 0x0}, 1},
+ {0x10BD, {0x2D1D, 0x0, 0x0}, 1},
+ {0x10BE, {0x2D1E, 0x0, 0x0}, 1},
+ {0x10BF, {0x2D1F, 0x0, 0x0}, 1},
+ {0x10C0, {0x2D20, 0x0, 0x0}, 1},
+ {0x10C1, {0x2D21, 0x0, 0x0}, 1},
+ {0x10C2, {0x2D22, 0x0, 0x0}, 1},
+ {0x10C3, {0x2D23, 0x0, 0x0}, 1},
+ {0x10C4, {0x2D24, 0x0, 0x0}, 1},
+ {0x10C5, {0x2D25, 0x0, 0x0}, 1},
+ {0x10C7, {0x2D27, 0x0, 0x0}, 1},
+ {0x10CD, {0x2D2D, 0x0, 0x0}, 1},
+ {0x135D, {0x0, 0x0, 0x0}, 0},
+ {0x135E, {0x0, 0x0, 0x0}, 0},
+ {0x135F, {0x0, 0x0, 0x0}, 0},
+ {0x13A0, {0xAB70, 0x0, 0x0}, 1},
+ {0x13A1, {0xAB71, 0x0, 0x0}, 1},
+ {0x13A2, {0xAB72, 0x0, 0x0}, 1},
+ {0x13A3, {0xAB73, 0x0, 0x0}, 1},
+ {0x13A4, {0xAB74, 0x0, 0x0}, 1},
+ {0x13A5, {0xAB75, 0x0, 0x0}, 1},
+ {0x13A6, {0xAB76, 0x0, 0x0}, 1},
+ {0x13A7, {0xAB77, 0x0, 0x0}, 1},
+ {0x13A8, {0xAB78, 0x0, 0x0}, 1},
+ {0x13A9, {0xAB79, 0x0, 0x0}, 1},
+ {0x13AA, {0xAB7A, 0x0, 0x0}, 1},
+ {0x13AB, {0xAB7B, 0x0, 0x0}, 1},
+ {0x13AC, {0xAB7C, 0x0, 0x0}, 1},
+ {0x13AD, {0xAB7D, 0x0, 0x0}, 1},
+ {0x13AE, {0xAB7E, 0x0, 0x0}, 1},
+ {0x13AF, {0xAB7F, 0x0, 0x0}, 1},
+ {0x13B0, {0xAB80, 0x0, 0x0}, 1},
+ {0x13B1, {0xAB81, 0x0, 0x0}, 1},
+ {0x13B2, {0xAB82, 0x0, 0x0}, 1},
+ {0x13B3, {0xAB83, 0x0, 0x0}, 1},
+ {0x13B4, {0xAB84, 0x0, 0x0}, 1},
+ {0x13B5, {0xAB85, 0x0, 0x0}, 1},
+ {0x13B6, {0xAB86, 0x0, 0x0}, 1},
+ {0x13B7, {0xAB87, 0x0, 0x0}, 1},
+ {0x13B8, {0xAB88, 0x0, 0x0}, 1},
+ {0x13B9, {0xAB89, 0x0, 0x0}, 1},
+ {0x13BA, {0xAB8A, 0x0, 0x0}, 1},
+ {0x13BB, {0xAB8B, 0x0, 0x0}, 1},
+ {0x13BC, {0xAB8C, 0x0, 0x0}, 1},
+ {0x13BD, {0xAB8D, 0x0, 0x0}, 1},
+ {0x13BE, {0xAB8E, 0x0, 0x0}, 1},
+ {0x13BF, {0xAB8F, 0x0, 0x0}, 1},
+ {0x13C0, {0xAB90, 0x0, 0x0}, 1},
+ {0x13C1, {0xAB91, 0x0, 0x0}, 1},
+ {0x13C2, {0xAB92, 0x0, 0x0}, 1},
+ {0x13C3, {0xAB93, 0x0, 0x0}, 1},
+ {0x13C4, {0xAB94, 0x0, 0x0}, 1},
+ {0x13C5, {0xAB95, 0x0, 0x0}, 1},
+ {0x13C6, {0xAB96, 0x0, 0x0}, 1},
+ {0x13C7, {0xAB97, 0x0, 0x0}, 1},
+ {0x13C8, {0xAB98, 0x0, 0x0}, 1},
+ {0x13C9, {0xAB99, 0x0, 0x0}, 1},
+ {0x13CA, {0xAB9A, 0x0, 0x0}, 1},
+ {0x13CB, {0xAB9B, 0x0, 0x0}, 1},
+ {0x13CC, {0xAB9C, 0x0, 0x0}, 1},
+ {0x13CD, {0xAB9D, 0x0, 0x0}, 1},
+ {0x13CE, {0xAB9E, 0x0, 0x0}, 1},
+ {0x13CF, {0xAB9F, 0x0, 0x0}, 1},
+ {0x13D0, {0xABA0, 0x0, 0x0}, 1},
+ {0x13D1, {0xABA1, 0x0, 0x0}, 1},
+ {0x13D2, {0xABA2, 0x0, 0x0}, 1},
+ {0x13D3, {0xABA3, 0x0, 0x0}, 1},
+ {0x13D4, {0xABA4, 0x0, 0x0}, 1},
+ {0x13D5, {0xABA5, 0x0, 0x0}, 1},
+ {0x13D6, {0xABA6, 0x0, 0x0}, 1},
+ {0x13D7, {0xABA7, 0x0, 0x0}, 1},
+ {0x13D8, {0xABA8, 0x0, 0x0}, 1},
+ {0x13D9, {0xABA9, 0x0, 0x0}, 1},
+ {0x13DA, {0xABAA, 0x0, 0x0}, 1},
+ {0x13DB, {0xABAB, 0x0, 0x0}, 1},
+ {0x13DC, {0xABAC, 0x0, 0x0}, 1},
+ {0x13DD, {0xABAD, 0x0, 0x0}, 1},
+ {0x13DE, {0xABAE, 0x0, 0x0}, 1},
+ {0x13DF, {0xABAF, 0x0, 0x0}, 1},
+ {0x13E0, {0xABB0, 0x0, 0x0}, 1},
+ {0x13E1, {0xABB1, 0x0, 0x0}, 1},
+ {0x13E2, {0xABB2, 0x0, 0x0}, 1},
+ {0x13E3, {0xABB3, 0x0, 0x0}, 1},
+ {0x13E4, {0xABB4, 0x0, 0x0}, 1},
+ {0x13E5, {0xABB5, 0x0, 0x0}, 1},
+ {0x13E6, {0xABB6, 0x0, 0x0}, 1},
+ {0x13E7, {0xABB7, 0x0, 0x0}, 1},
+ {0x13E8, {0xABB8, 0x0, 0x0}, 1},
+ {0x13E9, {0xABB9, 0x0, 0x0}, 1},
+ {0x13EA, {0xABBA, 0x0, 0x0}, 1},
+ {0x13EB, {0xABBB, 0x0, 0x0}, 1},
+ {0x13EC, {0xABBC, 0x0, 0x0}, 1},
+ {0x13ED, {0xABBD, 0x0, 0x0}, 1},
+ {0x13EE, {0xABBE, 0x0, 0x0}, 1},
+ {0x13EF, {0xABBF, 0x0, 0x0}, 1},
+ {0x13F0, {0x13F8, 0x0, 0x0}, 1},
+ {0x13F1, {0x13F9, 0x0, 0x0}, 1},
+ {0x13F2, {0x13FA, 0x0, 0x0}, 1},
+ {0x13F3, {0x13FB, 0x0, 0x0}, 1},
+ {0x13F4, {0x13FC, 0x0, 0x0}, 1},
+ {0x13F5, {0x13FD, 0x0, 0x0}, 1},
+ {0x1712, {0x0, 0x0, 0x0}, 0},
+ {0x1713, {0x0, 0x0, 0x0}, 0},
+ {0x1714, {0x0, 0x0, 0x0}, 0},
+ {0x1732, {0x0, 0x0, 0x0}, 0},
+ {0x1733, {0x0, 0x0, 0x0}, 0},
+ {0x1734, {0x0, 0x0, 0x0}, 0},
+ {0x1752, {0x0, 0x0, 0x0}, 0},
+ {0x1753, {0x0, 0x0, 0x0}, 0},
+ {0x1772, {0x0, 0x0, 0x0}, 0},
+ {0x1773, {0x0, 0x0, 0x0}, 0},
+ {0x17B4, {0x0, 0x0, 0x0}, 0},
+ {0x17B5, {0x0, 0x0, 0x0}, 0},
+ {0x17B7, {0x0, 0x0, 0x0}, 0},
+ {0x17B8, {0x0, 0x0, 0x0}, 0},
+ {0x17B9, {0x0, 0x0, 0x0}, 0},
+ {0x17BA, {0x0, 0x0, 0x0}, 0},
+ {0x17BB, {0x0, 0x0, 0x0}, 0},
+ {0x17BC, {0x0, 0x0, 0x0}, 0},
+ {0x17BD, {0x0, 0x0, 0x0}, 0},
+ {0x17C6, {0x0, 0x0, 0x0}, 0},
+ {0x17C9, {0x0, 0x0, 0x0}, 0},
+ {0x17CA, {0x0, 0x0, 0x0}, 0},
+ {0x17CB, {0x0, 0x0, 0x0}, 0},
+ {0x17CC, {0x0, 0x0, 0x0}, 0},
+ {0x17CD, {0x0, 0x0, 0x0}, 0},
+ {0x17CE, {0x0, 0x0, 0x0}, 0},
+ {0x17CF, {0x0, 0x0, 0x0}, 0},
+ {0x17D0, {0x0, 0x0, 0x0}, 0},
+ {0x17D1, {0x0, 0x0, 0x0}, 0},
+ {0x17D2, {0x0, 0x0, 0x0}, 0},
+ {0x17D3, {0x0, 0x0, 0x0}, 0},
+ {0x17DD, {0x0, 0x0, 0x0}, 0},
+ {0x180B, {0x0, 0x0, 0x0}, 0},
+ {0x180C, {0x0, 0x0, 0x0}, 0},
+ {0x180D, {0x0, 0x0, 0x0}, 0},
+ {0x1885, {0x0, 0x0, 0x0}, 0},
+ {0x1886, {0x0, 0x0, 0x0}, 0},
+ {0x18A9, {0x0, 0x0, 0x0}, 0},
+ {0x1920, {0x0, 0x0, 0x0}, 0},
+ {0x1921, {0x0, 0x0, 0x0}, 0},
+ {0x1922, {0x0, 0x0, 0x0}, 0},
+ {0x1927, {0x0, 0x0, 0x0}, 0},
+ {0x1928, {0x0, 0x0, 0x0}, 0},
+ {0x1932, {0x0, 0x0, 0x0}, 0},
+ {0x1939, {0x0, 0x0, 0x0}, 0},
+ {0x193A, {0x0, 0x0, 0x0}, 0},
+ {0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0, 0x0}, 0},
+ {0x1C30, {0x0, 0x0, 0x0}, 0},
+ {0x1C31, {0x0, 0x0, 0x0}, 0},
+ {0x1C32, {0x0, 0x0, 0x0}, 0},
+ {0x1C33, {0x0, 0x0, 0x0}, 0},
+ {0x1C36, {0x0, 0x0, 0x0}, 0},
+ {0x1C37, {0x0, 0x0, 0x0}, 0},
+ {0x1C90, {0x10D0, 0x0, 0x0}, 1},
+ {0x1C91, {0x10D1, 0x0, 0x0}, 1},
+ {0x1C92, {0x10D2, 0x0, 0x0}, 1},
+ {0x1C93, {0x10D3, 0x0, 0x0}, 1},
+ {0x1C94, {0x10D4, 0x0, 0x0}, 1},
+ {0x1C95, {0x10D5, 0x0, 0x0}, 1},
+ {0x1C96, {0x10D6, 0x0, 0x0}, 1},
+ {0x1C97, {0x10D7, 0x0, 0x0}, 1},
+ {0x1C98, {0x10D8, 0x0, 0x0}, 1},
+ {0x1C99, {0x10D9, 0x0, 0x0}, 1},
+ {0x1C9A, {0x10DA, 0x0, 0x0}, 1},
+ {0x1C9B, {0x10DB, 0x0, 0x0}, 1},
+ {0x1C9C, {0x10DC, 0x0, 0x0}, 1},
+ {0x1C9D, {0x10DD, 0x0, 0x0}, 1},
+ {0x1C9E, {0x10DE, 0x0, 0x0}, 1},
+ {0x1C9F, {0x10DF, 0x0, 0x0}, 1},
+ {0x1CA0, {0x10E0, 0x0, 0x0}, 1},
+ {0x1CA1, {0x10E1, 0x0, 0x0}, 1},
+ {0x1CA2, {0x10E2, 0x0, 0x0}, 1},
+ {0x1CA3, {0x10E3, 0x0, 0x0}, 1},
+ {0x1CA4, {0x10E4, 0x0, 0x0}, 1},
+ {0x1CA5, {0x10E5, 0x0, 0x0}, 1},
+ {0x1CA6, {0x10E6, 0x0, 0x0}, 1},
+ {0x1CA7, {0x10E7, 0x0, 0x0}, 1},
+ {0x1CA8, {0x10E8, 0x0, 0x0}, 1},
+ {0x1CA9, {0x10E9, 0x0, 0x0}, 1},
+ {0x1CAA, {0x10EA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 0x0}, 0},
+ {0x1DF7, {0x0, 0x0, 0x0}, 0},
+ {0x1DF8, {0x0, 0x0, 0x0}, 0},
+ {0x1DF9, {0x0, 0x0, 0x0}, 0},
+ {0x1DFB, {0x0, 0x0, 0x0}, 0},
+ {0x1DFC, {0x0, 0x0, 0x0}, 0},
+ {0x1DFD, {0x0, 0x0, 0x0}, 0},
+ {0x1DFE, {0x0, 0x0, 0x0}, 0},
+ {0x1DFF, {0x0, 0x0, 0x0}, 0},
+ {0x1E00, {0x61, 0x0, 0x0}, 1},
+ {0x1E01, {0x61, 0x0, 0x0}, 1},
+ {0x1E02, {0x62, 0x0, 0x0}, 1},
+ {0x1E03, {0x62, 0x0, 0x0}, 1},
+ {0x1E04, {0x62, 0x0, 0x0}, 1},
+ {0x1E05, {0x62, 0x0, 0x0}, 1},
+ {0x1E06, {0x62, 0x0, 0x0}, 1},
+ {0x1E07, {0x62, 0x0, 0x0}, 1},
+ {0x1E08, {0x63, 0x0, 0x0}, 1},
+ {0x1E09, {0x63, 0x0, 0x0}, 1},
+ {0x1E0A, {0x64, 0x0, 0x0}, 1},
+ {0x1E0B, {0x64, 0x0, 0x0}, 1},
+ {0x1E0C, {0x64, 0x0, 0x0}, 1},
+ {0x1E0D, {0x64, 0x0, 0x0}, 1},
+ {0x1E0E, {0x64, 0x0, 0x0}, 1},
+ {0x1E0F, {0x64, 0x0, 0x0}, 1},
+ {0x1E10, {0x64, 0x0, 0x0}, 1},
+ {0x1E11, {0x64, 0x0, 0x0}, 1},
+ {0x1E12, {0x64, 0x0, 0x0}, 1},
+ {0x1E13, {0x64, 0x0, 0x0}, 1},
+ {0x1E14, {0x65, 0x0, 0x0}, 1},
+ {0x1E15, {0x65, 0x0, 0x0}, 1},
+ {0x1E16, {0x65, 0x0, 0x0}, 1},
+ {0x1E17, {0x65, 0x0, 0x0}, 1},
+ {0x1E18, {0x65, 0x0, 0x0}, 1},
+ {0x1E19, {0x65, 0x0, 0x0}, 1},
+ {0x1E1A, {0x65, 0x0, 0x0}, 1},
+ {0x1E1B, {0x65, 0x0, 0x0}, 1},
+ {0x1E1C, {0x65, 0x0, 0x0}, 1},
+ {0x1E1D, {0x65, 0x0, 0x0}, 1},
+ {0x1E1E, {0x66, 0x0, 0x0}, 1},
+ {0x1E1F, {0x66, 0x0, 0x0}, 1},
+ {0x1E20, {0x67, 0x0, 0x0}, 1},
+ {0x1E21, {0x67, 0x0, 0x0}, 1},
+ {0x1E22, {0x68, 0x0, 0x0}, 1},
+ {0x1E23, {0x68, 0x0, 0x0}, 1},
+ {0x1E24, {0x68, 0x0, 0x0}, 1},
+ {0x1E25, {0x68, 0x0, 0x0}, 1},
+ {0x1E26, {0x68, 0x0, 0x0}, 1},
+ {0x1E27, {0x68, 0x0, 0x0}, 1},
+ {0x1E28, {0x68, 0x0, 0x0}, 1},
+ {0x1E29, {0x68, 0x0, 0x0}, 1},
+ {0x1E2A, {0x68, 0x0, 0x0}, 1},
+ {0x1E2B, {0x68, 0x0, 0x0}, 1},
+ {0x1E2C, {0x69, 0x0, 0x0}, 1},
+ {0x1E2D, {0x69, 0x0, 0x0}, 1},
+ {0x1E2E, {0x69, 0x0, 0x0}, 1},
+ {0x1E2F, {0x69, 0x0, 0x0}, 1},
+ {0x1E30, {0x6B, 0x0, 0x0}, 1},
+ {0x1E31, {0x6B, 0x0, 0x0}, 1},
+ {0x1E32, {0x6B, 0x0, 0x0}, 1},
+ {0x1E33, {0x6B, 0x0, 0x0}, 1},
+ {0x1E34, {0x6B, 0x0, 0x0}, 1},
+ {0x1E35, {0x6B, 0x0, 0x0}, 1},
+ {0x1E36, {0x6C, 0x0, 0x0}, 1},
+ {0x1E37, {0x6C, 0x0, 0x0}, 1},
+ {0x1E38, {0x6C, 0x0, 0x0}, 1},
+ {0x1E39, {0x6C, 0x0, 0x0}, 1},
+ {0x1E3A, {0x6C, 0x0, 0x0}, 1},
+ {0x1E3B, {0x6C, 0x0, 0x0}, 1},
+ {0x1E3C, {0x6C, 0x0, 0x0}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 1},
+ {0x1E5F, {0x72, 0x0, 0x0}, 1},
+ {0x1E60, {0x73, 0x0, 0x0}, 1},
+ {0x1E61, {0x73, 0x0, 0x0}, 1},
+ {0x1E62, {0x73, 0x0, 0x0}, 1},
+ {0x1E63, {0x73, 0x0, 0x0}, 1},
+ {0x1E64, {0x73, 0x0, 0x0}, 1},
+ {0x1E65, {0x73, 0x0, 0x0}, 1},
+ {0x1E66, {0x73, 0x0, 0x0}, 1},
+ {0x1E67, {0x73, 0x0, 0x0}, 1},
+ {0x1E68, {0x73, 0x0, 0x0}, 1},
+ {0x1E69, {0x73, 0x0, 0x0}, 1},
+ {0x1E6A, {0x74, 0x0, 0x0}, 1},
+ {0x1E6B, {0x74, 0x0, 0x0}, 1},
+ {0x1E6C, {0x74, 0x0, 0x0}, 1},
+ {0x1E6D, {0x74, 0x0, 0x0}, 1},
+ {0x1E6E, {0x74, 0x0, 0x0}, 1},
+ {0x1E6F, {0x74, 0x0, 0x0}, 1},
+ {0x1E70, {0x74, 0x0, 0x0}, 1},
+ {0x1E71, {0x74, 0x0, 0x0}, 1},
+ {0x1E72, {0x75, 0x0, 0x0}, 1},
+ {0x1E73, {0x75, 0x0, 0x0}, 1},
+ {0x1E74, {0x75, 0x0, 0x0}, 1},
+ {0x1E75, {0x75, 0x0, 0x0}, 1},
+ {0x1E76, {0x75, 0x0, 0x0}, 1},
+ {0x1E77, {0x75, 0x0, 0x0}, 1},
+ {0x1E78, {0x75, 0x0, 0x0}, 1},
+ {0x1E79, {0x75, 0x0, 0x0}, 1},
+ {0x1E7A, {0x75, 0x0, 0x0}, 1},
+ {0x1E7B, {0x75, 0x0, 0x0}, 1},
+ {0x1E7C, {0x76, 0x0, 0x0}, 1},
+ {0x1E7D, {0x76, 0x0, 0x0}, 1},
+ {0x1E7E, {0x76, 0x0, 0x0}, 1},
+ {0x1E7F, {0x76, 0x0, 0x0}, 1},
+ {0x1E80, {0x77, 0x0, 0x0}, 1},
+ {0x1E81, {0x77, 0x0, 0x0}, 1},
+ {0x1E82, {0x77, 0x0, 0x0}, 1},
+ {0x1E83, {0x77, 0x0, 0x0}, 1},
+ {0x1E84, {0x77, 0x0, 0x0}, 1},
+ {0x1E85, {0x77, 0x0, 0x0}, 1},
+ {0x1E86, {0x77, 0x0, 0x0}, 1},
+ {0x1E87, {0x77, 0x0, 0x0}, 1},
+ {0x1E88, {0x77, 0x0, 0x0}, 1},
+ {0x1E89, {0x77, 0x0, 0x0}, 1},
+ {0x1E8A, {0x78, 0x0, 0x0}, 1},
+ {0x1E8B, {0x78, 0x0, 0x0}, 1},
+ {0x1E8C, {0x78, 0x0, 0x0}, 1},
+ {0x1E8D, {0x78, 0x0, 0x0}, 1},
+ {0x1E8E, {0x79, 0x0, 0x0}, 1},
+ {0x1E8F, {0x79, 0x0, 0x0}, 1},
+ {0x1E90, {0x7A, 0x0, 0x0}, 1},
+ {0x1E91, {0x7A, 0x0, 0x0}, 1},
+ {0x1E92, {0x7A, 0x0, 0x0}, 1},
+ {0x1E93, {0x7A, 0x0, 0x0}, 1},
+ {0x1E94, {0x7A, 0x0, 0x0}, 1},
+ {0x1E95, {0x7A, 0x0, 0x0}, 1},
+ {0x1E96, {0x68, 0x0, 0x0}, 1},
+ {0x1E97, {0x74, 0x0, 0x0}, 1},
+ {0x1E98, {0x77, 0x0, 0x0}, 1},
+ {0x1E99, {0x79, 0x0, 0x0}, 1},
+ {0x1E9B, {0x17F, 0x0, 0x0}, 1},
+ {0x1E9E, {0xDF, 0x0, 0x0}, 1},
+ {0x1EA0, {0x61, 0x0, 0x0}, 1},
+ {0x1EA1, {0x61, 0x0, 0x0}, 1},
+ {0x1EA2, {0x61, 0x0, 0x0}, 1},
+ {0x1EA3, {0x61, 0x0, 0x0}, 1},
+ {0x1EA4, {0x61, 0x0, 0x0}, 1},
+ {0x1EA5, {0x61, 0x0, 0x0}, 1},
+ {0x1EA6, {0x61, 0x0, 0x0}, 1},
+ {0x1EA7, {0x61, 0x0, 0x0}, 1},
+ {0x1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0},
+ {0x20E1, {0x0, 0x0, 0x0}, 0},
+ {0x20E5, {0x0, 0x0, 0x0}, 0},
+ {0x20E6, {0x0, 0x0, 0x0}, 0},
+ {0x20E7, {0x0, 0x0, 0x0}, 0},
+ {0x20E8, {0x0, 0x0, 0x0}, 0},
+ {0x20E9, {0x0, 0x0, 0x0}, 0},
+ {0x20EA, {0x0, 0x0, 0x0}, 0},
+ {0x20EB, {0x0, 0x0, 0x0}, 0},
+ {0x20EC, {0x0, 0x0, 0x0}, 0},
+ {0x20ED, {0x0, 0x0, 0x0}, 0},
+ {0x20EE, {0x0, 0x0, 0x0}, 0},
+ {0x20EF, {0x0, 0x0, 0x0}, 0},
+ {0x20F0, {0x0, 0x0, 0x0}, 0},
+ {0x2126, {0x3C9, 0x0, 0x0}, 1},
+ {0x212A, {0x6B, 0x0, 0x0}, 1},
+ {0x212B, {0x61, 0x0, 0x0}, 1},
+ {0x2132, {0x214E, 0x0, 0x0}, 1},
+ {0x2160, {0x2170, 0x0, 0x0}, 1},
+ {0x2161, {0x2171, 0x0, 0x0}, 1},
+ {0x2162, {0x2172, 0x0, 0x0}, 1},
+ {0x2163, {0x2173, 0x0, 0x0}, 1},
+ {0x2164, {0x2174, 0x0, 0x0}, 1},
+ {0x2165, {0x2175, 0x0, 0x0}, 1},
+ {0x2166, {0x2176, 0x0, 0x0}, 1},
+ {0x2167, {0x2177, 0x0, 0x0}, 1},
+ {0x2168, {0x2178, 0x0, 0x0}, 1},
+ {0x2169, {0x2179, 0x0, 0x0}, 1},
+ {0x216A, {0x217A, 0x0, 0x0}, 1},
+ {0x216B, {0x217B, 0x0, 0x0}, 1},
+ {0x216C, {0x217C, 0x0, 0x0}, 1},
+ {0x216D, {0x217D, 0x0, 0x0}, 1},
+ {0x216E, {0x217E, 0x0, 0x0}, 1},
+ {0x216F, {0x217F, 0x0, 0x0}, 1},
+ {0x2183, {0x2184, 0x0, 0x0}, 1},
+ {0x219A, {0x2190, 0x0, 0x0}, 1},
+ {0x219B, {0x2192, 0x0, 0x0}, 1},
+ {0x21AE, {0x2194, 0x0, 0x0}, 1},
+ {0x21CD, {0x21D0, 0x0, 0x0}, 1},
+ {0x21CE, {0x21D4, 0x0, 0x0}, 1},
+ {0x21CF, {0x21D2, 0x0, 0x0}, 1},
+ {0x2204, {0x2203, 0x0, 0x0}, 1},
+ {0x2209, {0x2208, 0x0, 0x0}, 1},
+ {0x220C, {0x220B, 0x0, 0x0}, 1},
+ {0x2224, {0x2223, 0x0, 0x0}, 1},
+ {0x2226, {0x2225, 0x0, 0x0}, 1},
+ {0x2241, {0x223C, 0x0, 0x0}, 1},
+ {0x2244, {0x2243, 0x0, 0x0}, 1},
+ {0x2247, {0x2245, 0x0, 0x0}, 1},
+ {0x2249, {0x2248, 0x0, 0x0}, 1},
+ {0x2260, {0x3D, 0x0, 0x0}, 1},
+ {0x2262, {0x2261, 0x0, 0x0}, 1},
+ {0x226D, {0x224D, 0x0, 0x0}, 1},
+ {0x226E, {0x3C, 0x0, 0x0}, 1},
+ {0x226F, {0x3E, 0x0, 0x0}, 1},
+ {0x2270, {0x2264, 0x0, 0x0}, 1},
+ {0x2271, {0x2265, 0x0, 0x0}, 1},
+ {0x2274, {0x2272, 0x0, 0x0}, 1},
+ {0x2275, {0x2273, 0x0, 0x0}, 1},
+ {0x2278, {0x2276, 0x0, 0x0}, 1},
+ {0x2279, {0x2277, 0x0, 0x0}, 1},
+ {0x2280, {0x227A, 0x0, 0x0}, 1},
+ {0x2281, {0x227B, 0x0, 0x0}, 1},
+ {0x2284, {0x2282, 0x0, 0x0}, 1},
+ {0x2285, {0x2283, 0x0, 0x0}, 1},
+ {0x2288, {0x2286, 0x0, 0x0}, 1},
+ {0x2289, {0x2287, 0x0, 0x0}, 1},
+ {0x22AC, {0x22A2, 0x0, 0x0}, 1},
+ {0x22AD, {0x22A8, 0x0, 0x0}, 1},
+ {0x22AE, {0x22A9, 0x0, 0x0}, 1},
+ {0x22AF, {0x22AB, 0x0, 0x0}, 1},
+ {0x22E0, {0x227C, 0x0, 0x0}, 1},
+ {0x22E1, {0x227D, 0x0, 0x0}, 1},
+ {0x22E2, {0x2291, 0x0, 0x0}, 1},
+ {0x22E3, {0x2292, 0x0, 0x0}, 1},
+ {0x22EA, {0x22B2, 0x0, 0x0}, 1},
+ {0x22EB, {0x22B3, 0x0, 0x0}, 1},
+ {0x22EC, {0x22B4, 0x0, 0x0}, 1},
+ {0x22ED, {0x22B5, 0x0, 0x0}, 1},
+ {0x2329, {0x3008, 0x0, 0x0}, 1},
+ {0x232A, {0x3009, 0x0, 0x0}, 1},
+ {0x24B6, {0x24D0, 0x0, 0x0}, 1},
+ {0x24B7, {0x24D1, 0x0, 0x0}, 1},
+ {0x24B8, {0x24D2, 0x0, 0x0}, 1},
+ {0x24B9, {0x24D3, 0x0, 0x0}, 1},
+ {0x24BA, {0x24D4, 0x0, 0x0}, 1},
+ {0x24BB, {0x24D5, 0x0, 0x0}, 1},
+ {0x24BC, {0x24D6, 0x0, 0x0}, 1},
+ {0x24BD, {0x24D7, 0x0, 0x0}, 1},
+ {0x24BE, {0x24D8, 0x0, 0x0}, 1},
+ {0x24BF, {0x24D9, 0x0, 0x0}, 1},
+ {0x24C0, {0x24DA, 0x0, 0x0}, 1},
+ {0x24C1, {0x24DB, 0x0, 0x0}, 1},
+ {0x24C2, {0x24DC, 0x0, 0x0}, 1},
+ {0x24C3, {0x24DD, 0x0, 0x0}, 1},
+ {0x24C4, {0x24DE, 0x0, 0x0}, 1},
+ {0x24C5, {0x24DF, 0x0, 0x0}, 1},
+ {0x24C6, {0x24E0, 0x0, 0x0}, 1},
+ {0x24C7, {0x24E1, 0x0, 0x0}, 1},
+ {0x24C8, {0x24E2, 0x0, 0x0}, 1},
+ {0x24C9, {0x24E3, 0x0, 0x0}, 1},
+ {0x24CA, {0x24E4, 0x0, 0x0}, 1},
+ {0x24CB, {0x24E5, 0x0, 0x0}, 1},
+ {0x24CC, {0x24E6, 0x0, 0x0}, 1},
+ {0x24CD, {0x24E7, 0x0, 0x0}, 1},
+ {0x24CE, {0x24E8, 0x0, 0x0}, 1},
+ {0x24CF, {0x24E9, 0x0, 0x0}, 1},
+ {0x2ADC, {0x2ADD, 0x0, 0x0}, 1},
+ {0x2C00, {0x2C30, 0x0, 0x0}, 1},
+ {0x2C01, {0x2C31, 0x0, 0x0}, 1},
+ {0x2C02, {0x2C32, 0x0, 0x0}, 1},
+ {0x2C03, {0x2C33, 0x0, 0x0}, 1},
+ {0x2C04, {0x2C34, 0x0, 0x0}, 1},
+ {0x2C05, {0x2C35, 0x0, 0x0}, 1},
+ {0x2C06, {0x2C36, 0x0, 0x0}, 1},
+ {0x2C07, {0x2C37, 0x0, 0x0}, 1},
+ {0x2C08, {0x2C38, 0x0, 0x0}, 1},
+ {0x2C09, {0x2C39, 0x0, 0x0}, 1},
+ {0x2C0A, {0x2C3A, 0x0, 0x0}, 1},
+ {0x2C0B, {0x2C3B, 0x0, 0x0}, 1},
+ {0x2C0C, {0x2C3C, 0x0, 0x0}, 1},
+ {0x2C0D, {0x2C3D, 0x0, 0x0}, 1},
+ {0x2C0E, {0x2C3E, 0x0, 0x0}, 1},
+ {0x2C0F, {0x2C3F, 0x0, 0x0}, 1},
+ {0x2C10, {0x2C40, 0x0, 0x0}, 1},
+ {0x2C11, {0x2C41, 0x0, 0x0}, 1},
+ {0x2C12, {0x2C42, 0x0, 0x0}, 1},
+ {0x2C13, {0x2C43, 0x0, 0x0}, 1},
+ {0x2C14, {0x2C44, 0x0, 0x0}, 1},
+ {0x2C15, {0x2C45, 0x0, 0x0}, 1},
+ {0x2C16, {0x2C46, 0x0, 0x0}, 1},
+ {0x2C17, {0x2C47, 0x0, 0x0}, 1},
+ {0x2C18, {0x2C48, 0x0, 0x0}, 1},
+ {0x2C19, {0x2C49, 0x0, 0x0}, 1},
+ {0x2C1A, {0x2C4A, 0x0, 0x0}, 1},
+ {0x2C1B, {0x2C4B, 0x0, 0x0}, 1},
+ {0x2C1C, {0x2C4C, 0x0, 0x0}, 1},
+ {0x2C1D, {0x2C4D, 0x0, 0x0}, 1},
+ {0x2C1E, {0x2C4E, 0x0, 0x0}, 1},
+ {0x2C1F, {0x2C4F, 0x0, 0x0}, 1},
+ {0x2C20, {0x2C50, 0x0, 0x0}, 1},
+ {0x2C21, {0x2C51, 0x0, 0x0}, 1},
+ {0x2C22, {0x2C52, 0x0, 0x0}, 1},
+ {0x2C23, {0x2C53, 0x0, 0x0}, 1},
+ {0x2C24, {0x2C54, 0x0, 0x0}, 1},
+ {0x2C25, {0x2C55, 0x0, 0x0}, 1},
+ {0x2C26, {0x2C56, 0x0, 0x0}, 1},
+ {0x2C27, {0x2C57, 0x0, 0x0}, 1},
+ {0x2C28, {0x2C58, 0x0, 0x0}, 1},
+ {0x2C29, {0x2C59, 0x0, 0x0}, 1},
+ {0x2C2A, {0x2C5A, 0x0, 0x0}, 1},
+ {0x2C2B, {0x2C5B, 0x0, 0x0}, 1},
+ {0x2C2C, {0x2C5C, 0x0, 0x0}, 1},
+ {0x2C2D, {0x2C5D, 0x0, 0x0}, 1},
+ {0x2C2E, {0x2C5E, 0x0, 0x0}, 1},
+ {0x2C60, {0x2C61, 0x0, 0x0}, 1},
+ {0x2C62, {0x26B, 0x0, 0x0}, 1},
+ {0x2C63, {0x1D7D, 0x0, 0x0}, 1},
+ {0x2C64, {0x27D, 0x0, 0x0}, 1},
+ {0x2C67, {0x2C68, 0x0, 0x0}, 1},
+ {0x2C69, {0x2C6A, 0x0, 0x0}, 1},
+ {0x2C6B, {0x2C6C, 0x0, 0x0}, 1},
+ {0x2C6D, {0x251, 0x0, 0x0}, 1},
+ {0x2C6E, {0x271, 0x0, 0x0}, 1},
+ {0x2C6F, {0x250, 0x0, 0x0}, 1},
+ {0x2C70, {0x252, 0x0, 0x0}, 1},
+ {0x2C72, {0x2C73, 0x0, 0x0}, 1},
+ {0x2C75, {0x2C76, 0x0, 0x0}, 1},
+ {0x2C7E, {0x23F, 0x0, 0x0}, 1},
+ {0x2C7F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x0, 0x0}, 1},
+ {0x3056, {0x3055, 0x0, 0x0}, 1},
+ {0x3058, {0x3057, 0x0, 0x0}, 1},
+ {0x305A, {0x3059, 0x0, 0x0}, 1},
+ {0x305C, {0x305B, 0x0, 0x0}, 1},
+ {0x305E, {0x305D, 0x0, 0x0}, 1},
+ {0x3060, {0x305F, 0x0, 0x0}, 1},
+ {0x3062, {0x3061, 0x0, 0x0}, 1},
+ {0x3065, {0x3064, 0x0, 0x0}, 1},
+ {0x3067, {0x3066, 0x0, 0x0}, 1},
+ {0x3069, {0x3068, 0x0, 0x0}, 1},
+ {0x3070, {0x306F, 0x0, 0x0}, 1},
+ {0x3071, {0x306F, 0x0, 0x0}, 1},
+ {0x3073, {0x3072, 0x0, 0x0}, 1},
+ {0x3074, {0x3072, 0x0, 0x0}, 1},
+ {0x3076, {0x3075, 0x0, 0x0}, 1},
+ {0x3077, {0x3075, 0x0, 0x0}, 1},
+ {0x3079, {0x3078, 0x0, 0x0}, 1},
+ {0x307A, {0x3078, 0x0, 0x0}, 1},
+ {0x307C, {0x307B, 0x0, 0x0}, 1},
+ {0x307D, {0x307B, 0x0, 0x0}, 1},
+ {0x3094, {0x3046, 0x0, 0x0}, 1},
+ {0x3099, {0x0, 0x0, 0x0}, 0},
+ {0x309A, {0x0, 0x0, 0x0}, 0},
+ {0x309E, {0x309D, 0x0, 0x0}, 1},
+ {0x30AC, {0x30AB, 0x0, 0x0}, 1},
+ {0x30AE, {0x30AD, 0x0, 0x0}, 1},
+ {0x30B0, {0x30AF, 0x0, 0x0}, 1},
+ {0x30B2, {0x30B1, 0x0, 0x0}, 1},
+ {0x30B4, {0x30B3, 0x0, 0x0}, 1},
+ {0x30B6, {0x30B5, 0x0, 0x0}, 1},
+ {0x30B8, {0x30B7, 0x0, 0x0}, 1},
+ {0x30BA, {0x30B9, 0x0, 0x0}, 1},
+ {0x30BC, {0x30BB, 0x0, 0x0}, 1},
+ {0x30BE, {0x30BD, 0x0, 0x0}, 1},
+ {0x30C0, {0x30BF, 0x0, 0x0}, 1},
+ {0x30C2, {0x30C1, 0x0, 0x0}, 1},
+ {0x30C5, {0x30C4, 0x0, 0x0}, 1},
+ {0x30C7, {0x30C6, 0x0, 0x0}, 1},
+ {0x30C9, {0x30C8, 0x0, 0x0}, 1},
+ {0x30D0, {0x30CF, 0x0, 0x0}, 1},
+ {0x30D1, {0x30CF, 0x0, 0x0}, 1},
+ {0x30D3, {0x30D2, 0x0, 0x0}, 1},
+ {0x30D4, {0x30D2, 0x0, 0x0}, 1},
+ {0x30D6, {0x30D5, 0x0, 0x0}, 1},
+ {0x30D7, {0x30D5, 0x0, 0x0}, 1},
+ {0x30D9, {0x30D8, 0x0, 0x0}, 1},
+ {0x30DA, {0x30D8, 0x0, 0x0}, 1},
+ {0x30DC, {0x30DB, 0x0, 0x0}, 1},
+ {0x30DD, {0x30DB, 0x0, 0x0}, 1},
+ {0x30F4, {0x30A6, 0x0, 0x0}, 1},
+ {0x30F7, {0x30EF, 0x0, 0x0}, 1},
+ {0x30F8, {0x30F0, 0x0, 0x0}, 1},
+ {0x30F9, {0x30F1, 0x0, 0x0}, 1},
+ {0x30FA, {0x30F2, 0x0, 0x0}, 1},
+ {0x30FE, {0x30FD, 0x0, 0x0}, 1},
+ {0xA640, {0xA641, 0x0, 0x0}, 1},
+ {0xA642, {0xA643, 0x0, 0x0}, 1},
+ {0xA644, {0xA645, 0x0, 0x0}, 1},
+ {0xA646, {0xA647, 0x0, 0x0}, 1},
+ {0xA648, {0xA649, 0x0, 0x0}, 1},
+ {0xA64A, {0xA64B, 0x0, 0x0}, 1},
+ {0xA64C, {0xA64D, 0x0, 0x0}, 1},
+ {0xA64E, {0xA64F, 0x0, 0x0}, 1},
+ {0xA650, {0xA651, 0x0, 0x0}, 1},
+ {0xA652, {0xA653, 0x0, 0x0}, 1},
+ {0xA654, {0xA655, 0x0, 0x0}, 1},
+ {0xA656, {0xA657, 0x0, 0x0}, 1},
+ {0xA658, {0xA659, 0x0, 0x0}, 1},
+ {0xA65A, {0xA65B, 0x0, 0x0}, 1},
+ {0xA65C, {0xA65D, 0x0, 0x0}, 1},
+ {0xA65E, {0xA65F, 0x0, 0x0}, 1},
+ {0xA660, {0xA661, 0x0, 0x0}, 1},
+ {0xA662, {0xA663, 0x0, 0x0}, 1},
+ {0xA664, {0xA665, 0x0, 0x0}, 1},
+ {0xA666, {0xA667, 0x0, 0x0}, 1},
+ {0xA668, {0xA669, 0x0, 0x0}, 1},
+ {0xA66A, {0xA66B, 0x0, 0x0}, 1},
+ {0xA66C, {0xA66D, 0x0, 0x0}, 1},
+ {0xA66F, {0x0, 0x0, 0x0}, 0},
+ {0xA674, {0x0, 0x0, 0x0}, 0},
+ {0xA675, {0x0, 0x0, 0x0}, 0},
+ {0xA676, {0x0, 0x0, 0x0}, 0},
+ {0xA677, {0x0, 0x0, 0x0}, 0},
+ {0xA678, {0x0, 0x0, 0x0}, 0},
+ {0xA679, {0x0, 0x0, 0x0}, 0},
+ {0xA67A, {0x0, 0x0, 0x0}, 0},
+ {0xA67B, {0x0, 0x0, 0x0}, 0},
+ {0xA67C, {0x0, 0x0, 0x0}, 0},
+ {0xA67D, {0x0, 0x0, 0x0}, 0},
+ {0xA680, {0xA681, 0x0, 0x0}, 1},
+ {0xA682, {0xA683, 0x0, 0x0}, 1},
+ {0xA684, {0xA685, 0x0, 0x0}, 1},
+ {0xA686, {0xA687, 0x0, 0x0}, 1},
+ {0xA688, {0xA689, 0x0, 0x0}, 1},
+ {0xA68A, {0xA68B, 0x0, 0x0}, 1},
+ {0xA68C, {0xA68D, 0x0, 0x0}, 1},
+ {0xA68E, {0xA68F, 0x0, 0x0}, 1},
+ {0xA690, {0xA691, 0x0, 0x0}, 1},
+ {0xA692, {0xA693, 0x0, 0x0}, 1},
+ {0xA694, {0xA695, 0x0, 0x0}, 1},
+ {0xA696, {0xA697, 0x0, 0x0}, 1},
+ {0xA698, {0xA699, 0x0, 0x0}, 1},
+ {0xA69A, {0xA69B, 0x0, 0x0}, 1},
+ {0xA69E, {0x0, 0x0, 0x0}, 0},
+ {0xA69F, {0x0, 0x0, 0x0}, 0},
+ {0xA6F0, {0x0, 0x0, 0x0}, 0},
+ {0xA6F1, {0x0, 0x0, 0x0}, 0},
+ {0xA722, {0xA723, 0x0, 0x0}, 1},
+ {0xA724, {0xA725, 0x0, 0x0}, 1},
+ {0xA726, {0xA727, 0x0, 0x0}, 1},
+ {0xA728, {0xA729, 0x0, 0x0}, 1},
+ {0xA72A, {0xA72B, 0x0, 0x0}, 1},
+ {0xA72C, {0xA72D, 0x0, 0x0}, 1},
+ {0xA72E, {0xA72F, 0x0, 0x0}, 1},
+ {0xA732, {0xA733, 0x0, 0x0}, 1},
+ {0xA734, {0xA735, 0x0, 0x0}, 1},
+ {0xA736, {0xA737, 0x0, 0x0}, 1},
+ {0xA738, {0xA739, 0x0, 0x0}, 1},
+ {0xA73A, {0xA73B, 0x0, 0x0}, 1},
+ {0xA73C, {0xA73D, 0x0, 0x0}, 1},
+ {0xA73E, {0xA73F, 0x0, 0x0}, 1},
+ {0xA740, {0xA741, 0x0, 0x0}, 1},
+ {0xA742, {0xA743, 0x0, 0x0}, 1},
+ {0xA744, {0xA745, 0x0, 0x0}, 1},
+ {0xA746, {0xA747, 0x0, 0x0}, 1},
+ {0xA748, {0xA749, 0x0, 0x0}, 1},
+ {0xA74A, {0xA74B, 0x0, 0x0}, 1},
+ {0xA74C, {0xA74D, 0x0, 0x0}, 1},
+ {0xA74E, {0xA74F, 0x0, 0x0}, 1},
+ {0xA750, {0xA751, 0x0, 0x0}, 1},
+ {0xA752, {0xA753, 0x0, 0x0}, 1},
+ {0xA754, {0xA755, 0x0, 0x0}, 1},
+ {0xA756, {0xA757, 0x0, 0x0}, 1},
+ {0xA758, {0xA759, 0x0, 0x0}, 1},
+ {0xA75A, {0xA75B, 0x0, 0x0}, 1},
+ {0xA75C, {0xA75D, 0x0, 0x0}, 1},
+ {0xA75E, {0xA75F, 0x0, 0x0}, 1},
+ {0xA760, {0xA761, 0x0, 0x0}, 1},
+ {0xA762, {0xA763, 0x0, 0x0}, 1},
+ {0xA764, {0xA765, 0x0, 0x0}, 1},
+ {0xA766, {0xA767, 0x0, 0x0}, 1},
+ {0xA768, {0xA769, 0x0, 0x0}, 1},
+ {0xA76A, {0xA76B, 0x0, 0x0}, 1},
+ {0xA76C, {0xA76D, 0x0, 0x0}, 1},
+ {0xA76E, {0xA76F, 0x0, 0x0}, 1},
+ {0xA779, {0xA77A, 0x0, 0x0}, 1},
+ {0xA77B, {0xA77C, 0x0, 0x0}, 1},
+ {0xA77D, {0x1D79, 0x0, 0x0}, 1},
+ {0xA77E, {0xA77F, 0x0, 0x0}, 1},
+ {0xA780, {0xA781, 0x0, 0x0}, 1},
+ {0xA782, {0xA783, 0x0, 0x0}, 1},
+ {0xA784, {0xA785, 0x0, 0x0}, 1},
+ {0xA786, {0xA787, 0x0, 0x0}, 1},
+ {0xA78B, {0xA78C, 0x0, 0x0}, 1},
+ {0xA78D, {0x265, 0x0, 0x0}, 1},
+ {0xA790, {0xA791, 0x0, 0x0}, 1},
+ {0xA792, {0xA793, 0x0, 0x0}, 1},
+ {0xA796, {0xA797, 0x0, 0x0}, 1},
+ {0xA798, {0xA799, 0x0, 0x0}, 1},
+ {0xA79A, {0xA79B, 0x0, 0x0}, 1},
+ {0xA79C, {0xA79D, 0x0, 0x0}, 1},
+ {0xA79E, {0xA79F, 0x0, 0x0}, 1},
+ {0xA7A0, {0xA7A1, 0x0, 0x0}, 1},
+ {0xA7A2, {0xA7A3, 0x0, 0x0}, 1},
+ {0xA7A4, {0xA7A5, 0x0, 0x0}, 1},
+ {0xA7A6, {0xA7A7, 0x0, 0x0}, 1},
+ {0xA7A8, {0xA7A9, 0x0, 0x0}, 1},
+ {0xA7AA, {0x266, 0x0, 0x0}, 1},
+ {0xA7AB, {0x25C, 0x0, 0x0}, 1},
+ {0xA7AC, {0x261, 0x0, 0x0}, 1},
+ {0xA7AD, {0x26C, 0x0, 0x0}, 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{0xA8E7, {0x0, 0x0, 0x0}, 0},
+ {0xA8E8, {0x0, 0x0, 0x0}, 0},
+ {0xA8E9, {0x0, 0x0, 0x0}, 0},
+ {0xA8EA, {0x0, 0x0, 0x0}, 0},
+ {0xA8EB, {0x0, 0x0, 0x0}, 0},
+ {0xA8EC, {0x0, 0x0, 0x0}, 0},
+ {0xA8ED, {0x0, 0x0, 0x0}, 0},
+ {0xA8EE, {0x0, 0x0, 0x0}, 0},
+ {0xA8EF, {0x0, 0x0, 0x0}, 0},
+ {0xA8F0, {0x0, 0x0, 0x0}, 0},
+ {0xA8F1, {0x0, 0x0, 0x0}, 0},
+ {0xA8FF, {0x0, 0x0, 0x0}, 0},
+ {0xA926, {0x0, 0x0, 0x0}, 0},
+ {0xA927, {0x0, 0x0, 0x0}, 0},
+ {0xA928, {0x0, 0x0, 0x0}, 0},
+ {0xA929, {0x0, 0x0, 0x0}, 0},
+ {0xA92A, {0x0, 0x0, 0x0}, 0},
+ {0xA92B, {0x0, 0x0, 0x0}, 0},
+ {0xA92C, {0x0, 0x0, 0x0}, 0},
+ {0xA92D, {0x0, 0x0, 0x0}, 0},
+ {0xA947, {0x0, 0x0, 0x0}, 0},
+ {0xA948, {0x0, 0x0, 0x0}, 0},
+ {0xA949, {0x0, 0x0, 0x0}, 0},
+ {0xA94A, {0x0, 0x0, 0x0}, 0},
+ {0xA94B, {0x0, 0x0, 0x0}, 0},
+ {0xA94C, {0x0, 0x0, 0x0}, 0},
+ {0xA94D, {0x0, 0x0, 0x0}, 0},
+ {0xA94E, {0x0, 0x0, 0x0}, 0},
+ {0xA94F, {0x0, 0x0, 0x0}, 0},
+ {0xA950, {0x0, 0x0, 0x0}, 0},
+ {0xA951, {0x0, 0x0, 0x0}, 0},
+ {0xA980, {0x0, 0x0, 0x0}, 0},
+ {0xA981, {0x0, 0x0, 0x0}, 0},
+ {0xA982, {0x0, 0x0, 0x0}, 0},
+ {0xA9B3, {0x0, 0x0, 0x0}, 0},
+ {0xA9B6,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0},
+ {0xF900, {0x8C48, 0x0, 0x0}, 1},
+ {0xF901, {0x66F4, 0x0, 0x0}, 1},
+ {0xF902, {0x8ECA, 0x0, 0x0}, 1},
+ {0xF903, {0x8CC8, 0x0, 0x0}, 1},
+ {0xF904, {0x6ED1, 0x0, 0x0}, 1},
+ {0xF905, {0x4E32, 0x0, 0x0}, 1},
+ {0xF906, {0x53E5, 0x0, 0x0}, 1},
+ {0xF907, {0x9F9C, 0x0, 0x0}, 1},
+ {0xF908, {0x9F9C, 0x0, 0x0}, 1},
+ {0xF909, {0x5951, 0x0, 0x0}, 1},
+ {0xF90A, {0x91D1, 0x0, 0x0}, 1},
+ {0xF90B, {0x5587, 0x0, 0x0}, 1},
+ {0xF90C, {0x5948, 0x0, 0x0}, 1},
+ {0xF90D, {0x61F6, 0x0, 0x0}, 1},
+ {0xF90E, {0x7669, 0x0, 0x0}, 1},
+ {0xF90F, {0x7F85, 0x0, 0x0}, 1},
+ {0xF910, {0x863F, 0x0, 0x0}, 1},
+ {0xF911, {0x87BA, 0x0, 0x0}, 1},
+ {0xF912, {0x88F8, 0x0, 0x0}, 1},
+ {0xF913, {0x908F, 0x0, 0x0}, 1},
+ {0xF914, {0x6A02, 0x0, 0x0}, 1},
+ {0xF915, {0x6D1B, 0x0, 0x0}, 1},
+ {0xF916, {0x70D9, 0x0, 0x0}, 1},
+ {0xF917, {0x73DE, 0x0, 0x0}, 1},
+ {0xF918, {0x843D, 0x0, 0x0}, 1},
+ {0xF919, {0x916A, 0x0, 0x0}, 1},
+ {0xF91A, {0x99F1, 0x0, 0x0}, 1},
+ {0xF91B, {0x4E82, 0x0, 0x0}, 1},
+ {0xF91C, {0x5375, 0x0, 0x0}, 1},
+ {0xF91D, {0x6B04, 0x0, 0x0}, 1},
+ {0xF91E, {0x721B, 0x0, 0x0}, 1},
+ {0xF91F, {0x862D, 0x0, 0x0}, 1},
+ {0xF920, {0x9E1E, 0x0, 0x0}, 1},
+ {0xF921, {0x5D50, 0x0, 0x0}, 1},
+ {0xF922, {0x6FEB, 0x0, 0x0}, 1},
+ {0xF923, {0x85CD, 0x0, 0x0}, 1},
+ {0xF924, {0x8964, 0x0, 0x0}, 1},
+ {0xF925, {0x62C9, 0x0, 0x0}, 1},
+ {0xF926, {0x81D8, 0x0, 0x0}, 1},
+ {0xF927, {0x881F, 0x0, 0x0}, 1},
+ {0xF928, {0x5ECA, 0x0, 0x0}, 1},
+ {0xF929, {0x6717, 0x0, 0x0}, 1},
+ {0xF92A, {0x6D6A, 0x0, 0x0}, 1},
+ {0xF92B, {0x72FC, 0x0, 0x0}, 1},
+ {0xF92C, {0x90CE, 0x0, 0x0}, 1},
+ {0xF92D, {0x4F86, 0x0, 0x0}, 1},
+ {0xF92E, {0x51B7, 0x0, 0x0}, 1},
+ {0xF92F, {0x52DE, 0x0, 0x0}, 1},
+ {0xF930, {0x64C4, 0x0, 0x0}, 1},
+ {0xF931, {0x6AD3, 0x0, 0x0}, 1},
+ {0xF932, {0x7210, 0x0, 0x0}, 1},
+ {0xF933, {0x76E7, 0x0, 0x0}, 1},
+ {0xF934, {0x8001, 0x0, 0x0}, 1},
+ {0xF935, {0x8606, 0x0, 0x0}, 1},
+ {0xF936, {0x865C, 0x0, 0x0}, 1},
+ {0xF937, {0x8DEF, 0x0, 0x0}, 1},
+ {0xF938, {0x9732, 0x0, 0x0}, 1},
+ {0xF939, {0x9B6F, 0x0, 0x0}, 1},
+ {0xF93A, {0x9DFA, 0x0, 0x0}, 1},
+ {0xF93B, {0x788C, 0x0, 0x0}, 1},
+ {0xF93C, {0x797F, 0x0, 0x0}, 1},
+ {0xF93D, {0x7DA0, 0x0, 0x0}, 1},
+ {0xF93E, {0x83C9, 0x0, 0x0}, 1},
+ {0xF93F, {0x9304, 0x0, 0x0}, 1},
+ {0xF940, {0x9E7F, 0x0, 0x0}, 1},
+ {0xF941, {0x8AD6, 0x0, 0x0}, 1},
+ {0xF942, {0x58DF, 0x0, 0x0}, 1},
+ {0xF943, {0x5F04, 0x0, 0x0}, 1},
+ {0xF944, {0x7C60, 0x0, 0x0}, 1},
+ {0xF945, {0x807E, 0x0, 0x0}, 1},
+ {0xF946, {0x7262, 0x0, 0x0}, 1},
+ {0xF947, {0x78CA, 0x0, 0x0}, 1},
+ {0xF948, {0x8CC2, 0x0, 0x0}, 1},
+ {0xF949, {0x96F7, 0x0, 0x0}, 1},
+ {0xF94A, {0x58D8, 0x0, 0x0}, 1},
+ {0xF94B, {0x5C62, 0x0, 0x0}, 1},
+ {0xF94C, {0x6A13, 0x0, 0x0}, 1},
+ {0xF94D, {0x6DDA, 0x0, 0x0}, 1},
+ {0xF94E, {0x6F0F, 0x0, 0x0}, 1},
+ {0xF94F, {0x7D2F, 0x0, 0x0}, 1},
+ {0xF950, {0x7E37, 0x0, 0x0}, 1},
+ {0xF951, {0x964B, 0x0, 0x0}, 1},
+ {0xF952, {0x52D2, 0x0, 0x0}, 1},
+ {0xF953, {0x808B, 0x0, 0x0}, 1},
+ {0xF954, {0x51DC, 0x0, 0x0}, 1},
+ {0xF955, {0x51CC, 0x0, 0x0}, 1},
+ {0xF956, {0x7A1C, 0x0, 0x0}, 1},
+ {0xF957, {0x7DBE, 0x0, 0x0}, 1},
+ {0xF958, {0x83F1, 0x0, 0x0}, 1},
+ {0xF959, {0x9675, 0x0, 0x0}, 1},
+ {0xF95A, {0x8B80, 0x0, 0x0}, 1},
+ {0xF95B, {0x62CF, 0x0, 0x0}, 1},
+ {0xF95C, {0x6A02, 0x0, 0x0}, 1},
+ {0xF95D, {0x8AFE, 0x0, 0x0}, 1},
+ {0xF95E, {0x4E39, 0x0, 0x0}, 1},
+ {0xF95F, {0x5BE7, 0x0, 0x0}, 1},
+ {0xF960, {0x6012, 0x0, 0x0}, 1},
+ {0xF961, {0x7387, 0x0, 0x0}, 1},
+ {0xF962, {0x7570, 0x0, 0x0}, 1},
+ {0xF963, {0x5317, 0x0, 0x0}, 1},
+ {0xF964, {0x78FB, 0x0, 0x0}, 1},
+ {0xF965, {0x4FBF, 0x0, 0x0}, 1},
+ {0xF966, {0x5FA9, 0x0, 0x0}, 1},
+ {0xF967, {0x4E0D, 0x0, 0x0}, 1},
+ {0xF968, {0x6CCC, 0x0, 0x0}, 1},
+ {0xF969, {0x6578, 0x0, 0x0}, 1},
+ {0xF96A, {0x7D22, 0x0, 0x0}, 1},
+ {0xF96B, {0x53C3, 0x0, 0x0}, 1},
+ {0xF96C, {0x585E, 0x0, 0x0}, 1},
+ {0xF96D, {0x7701, 0x0, 0x0}, 1},
+ {0xF96E, {0x8449, 0x0, 0x0}, 1},
+ {0xF96F, {0x8AAA, 0x0, 0x0}, 1},
+ {0xF970, {0x6BBA, 0x0, 0x0}, 1},
+ {0xF971, {0x8FB0, 0x0, 0x0}, 1},
+ {0xF972, {0x6C88, 0x0, 0x0}, 1},
+ {0xF973, {0x62FE, 0x0, 0x0}, 1},
+ {0xF974, {0x82E5, 0x0, 0x0}, 1},
+ {0xF975, {0x63A0, 0x0, 0x0}, 1},
+ {0xF976, {0x7565, 0x0, 0x0}, 1},
+ {0xF977, {0x4EAE, 0x0, 0x0}, 1},
+ {0xF978, {0x5169, 0x0, 0x0}, 1},
+ {0xF979, {0x51C9, 0x0, 0x0}, 1},
+ {0xF97A, {0x6881, 0x0, 0x0}, 1},
+ {0xF97B, {0x7CE7, 0x0, 0x0}, 1},
+ {0xF97C, {0x826F, 0x0, 0x0}, 1},
+ {0xF97D, {0x8AD2, 0x0, 0x0}, 1},
+ {0xF97E, {0x91CF, 0x0, 0x0}, 1},
+ {0xF97F, {0x52F5, 0x0, 0x0}, 1},
+ {0xF980, {0x5442, 0x0, 0x0}, 1},
+ {0xF981, {0x5973, 0x0, 0x0}, 1},
+ {0xF982, {0x5EEC, 0x0, 0x0}, 1},
+ {0xF983, {0x65C5, 0x0, 0x0}, 1},
+ {0xF984, {0x6FFE, 0x0, 0x0}, 1},
+ {0xF985, {0x792A, 0x0, 0x0}, 1},
+ {0xF986, {0x95AD, 0x0, 0x0}, 1},
+ {0xF987, {0x9A6A, 0x0, 0x0}, 1},
+ {0xF988, {0x9E97, 0x0, 0x0}, 1},
+ {0xF989, {0x9ECE, 0x0, 0x0}, 1},
+ {0xF98A, {0x529B, 0x0, 0x0}, 1},
+ {0xF98B, {0x66C6, 0x0, 0x0}, 1},
+ {0xF98C, {0x6B77, 0x0, 0x0}, 1},
+ {0xF98D, {0x8F62, 0x0, 0x0}, 1},
+ {0xF98E, {0x5E74, 0x0, 0x0}, 1},
+ {0xF98F, {0x6190, 0x0, 0x0}, 1},
+ {0xF990, {0x6200, 0x0, 0x0}, 1},
+ {0xF991, {0x649A, 0x0, 0x0}, 1},
+ {0xF992, {0x6F23, 0x0, 0x0}, 1},
+ {0xF993, {0x7149, 0x0, 0x0}, 1},
+ {0xF994, {0x7489, 0x0, 0x0}, 1},
+ {0xF995, {0x79CA, 0x0, 0x0}, 1},
+ {0xF996, {0x7DF4, 0x0, 0x0}, 1},
+ {0xF997, {0x806F, 0x0, 0x0}, 1},
+ {0xF998, {0x8F26, 0x0, 0x0}, 1},
+ {0xF999, {0x84EE, 0x0, 0x0}, 1},
+ {0xF99A, {0x9023, 0x0, 0x0}, 1},
+ {0xF99B, {0x934A, 0x0, 0x0}, 1},
+ {0xF99C, {0x5217, 0x0, 0x0}, 1},
+ {0xF99D, {0x52A3, 0x0, 0x0}, 1},
+ {0xF99E, {0x54BD, 0x0, 0x0}, 1},
+ {0xF99F, {0x70C8, 0x0, 0x0}, 1},
+ {0xF9A0, {0x88C2, 0x0, 0x0}, 1},
+ {0xF9A1, {0x8AAA, 0x0, 0x0}, 1},
+ {0xF9A2, {0x5EC9, 0x0, 0x0}, 1},
+ {0xF9A3, {0x5FF5, 0x0, 0x0}, 1},
+ {0xF9A4, {0x637B, 0x0, 0x0}, 1},
+ {0xF9A5, {0x6BAE, 0x0, 0x0}, 1},
+ {0xF9A6, {0x7C3E, 0x0, 0x0}, 1},
+ {0xF9A7, {0x7375, 0x0, 0x0}, 1},
+ {0xF9A8,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B, 0x0, 0x0}, 1},
+ {0xF9C9, {0x67F3, 0x0, 0x0}, 1},
+ {0xF9CA, {0x6D41, 0x0, 0x0}, 1},
+ {0xF9CB, {0x6E9C, 0x0, 0x0}, 1},
+ {0xF9CC, {0x7409, 0x0, 0x0}, 1},
+ {0xF9CD, {0x7559, 0x0, 0x0}, 1},
+ {0xF9CE, {0x786B, 0x0, 0x0}, 1},
+ {0xF9CF, {0x7D10, 0x0, 0x0}, 1},
+ {0xF9D0, {0x985E, 0x0, 0x0}, 1},
+ {0xF9D1, {0x516D, 0x0, 0x0}, 1},
+ {0xF9D2, {0x622E, 0x0, 0x0}, 1},
+ {0xF9D3, {0x9678, 0x0, 0x0}, 1},
+ {0xF9D4, {0x502B, 0x0, 0x0}, 1},
+ {0xF9D5, {0x5D19, 0x0, 0x0}, 1},
+ {0xF9D6, {0x6DEA, 0x0, 0x0}, 1},
+ {0xF9D7, {0x8F2A, 0x0, 0x0}, 1},
+ {0xF9D8, {0x5F8B, 0x0, 0x0}, 1},
+ {0xF9D9, {0x6144, 0x0, 0x0}, 1},
+ {0xF9DA, {0x6817, 0x0, 0x0}, 1},
+ {0xF9DB, {0x7387, 0x0, 0x0}, 1},
+ {0xF9DC, {0x9686, 0x0, 0x0}, 1},
+ {0xF9DD, {0x5229, 0x0, 0x0}, 1},
+ {0xF9DE, {0x540F, 0x0, 0x0}, 1},
+ {0xF9DF, {0x5C65, 0x0, 0x0}, 1},
+ {0xF9E0, {0x6613, 0x0, 0x0}, 1},
+ {0xF9E1, {0x674E, 0x0, 0x0}, 1},
+ {0xF9E2, {0x68A8, 0x0, 0x0}, 1},
+ {0xF9E3, {0x6CE5, 0x0, 0x0}, 1},
+ {0xF9E4, {0x7406, 0x0, 0x0}, 1},
+ {0xF9E5, {0x75E2, 0x0, 0x0}, 1},
+ {0xF9E6, {0x7F79, 0x0, 0x0}, 1},
+ {0xF9E7, {0x88CF, 0x0, 0x0}, 1},
+ {0xF9E8, {0x88E1, 0x0, 0x0}, 1},
+ {0xF9E9, {0x91CC, 0x0, 0x0}, 1},
+ {0xF9EA, {0x96E2, 0x0, 0x0}, 1},
+ {0xF9EB, {0x533F, 0x0, 0x0}, 1},
+ {0xF9EC, {0x6EBA, 0x0, 0x0}, 1},
+ {0xF9ED, {0x541D, 0x0, 0x0}, 1},
+ {0xF9EE, {0x71D0, 0x0, 0x0}, 1},
+ {0xF9EF, {0x7498, 0x0, 0x0}, 1},
+ {0xF9F0, {0x85FA, 0x0, 0x0}, 1},
+ {0xF9F1, {0x96A3, 0x0, 0x0}, 1},
+ {0xF9F2, {0x9C57, 0x0, 0x0}, 1},
+ {0xF9F3, {0x9E9F, 0x0, 0x0}, 1},
+ {0xF9F4, {0x6797, 0x0, 0x0}, 1},
+ {0xF9F5, {0x6DCB, 0x0, 0x0}, 1},
+ {0xF9F6, {0x81E8, 0x0, 0x0}, 1},
+ {0xF9F7, {0x7ACB, 0x0, 0x0}, 1},
+ {0xF9F8, {0x7B20, 0x0, 0x0}, 1},
+ {0xF9F9, {0x7C92, 0x0, 0x0}, 1},
+ {0xF9FA, {0x72C0, 0x0, 0x0}, 1},
+ {0xF9FB, {0x7099, 0x0, 0x0}, 1},
+ {0xF9FC, {0x8B58, 0x0, 0x0}, 1},
+ {0xF9FD, {0x4EC0, 0x0, 0x0}, 1},
+ {0xF9FE, {0x8336, 0x0, 0x0}, 1},
+ {0xF9FF, {0x523A, 0x0, 0x0}, 1},
+ {0xFA00, {0x5207, 0x0, 0x0}, 1},
+ {0xFA01, {0x5EA6, 0x0, 0x0}, 1},
+ {0xFA02, {0x62D3, 0x0, 0x0}, 1},
+ {0xFA03, {0x7CD6, 0x0, 0x0}, 1},
+ {0xFA04, {0x5B85, 0x0, 0x0}, 1},
+ {0xFA05, {0x6D1E, 0x0, 0x0}, 1},
+ {0xFA06, {0x66B4, 0x0, 0x0}, 1},
+ {0xFA07, {0x8F3B, 0x0, 0x0}, 1},
+ {0xFA08, {0x884C, 0x0, 0x0}, 1},
+ {0xFA09, {0x964D, 0x0, 0x0}, 1},
+ {0xFA0A, {0x898B, 0x0, 0x0}, 1},
+ {0xFA0B, {0x5ED3, 0x0, 0x0}, 1},
+ {0xFA0C, {0x5140, 0x0, 0x0}, 1},
+ {0xFA0D, {0x55C0, 0x0, 0x0}, 1},
+ {0xFA10, {0x585A, 0x0, 0x0}, 1},
+ {0xFA12, {0x6674, 0x0, 0x0}, 1},
+ {0xFA15, {0x51DE, 0x0, 0x0}, 1},
+ {0xFA16, {0x732A, 0x0, 0x0}, 1},
+ {0xFA17, {0x76CA, 0x0, 0x0}, 1},
+ {0xFA18, {0x793C, 0x0, 0x0}, 1},
+ {0xFA19, {0x795E, 0x0, 0x0}, 1},
+ {0xFA1A, {0x7965, 0x0, 0x0}, 1},
+ {0xFA1B, {0x798F, 0x0, 0x0}, 1},
+ {0xFA1C, {0x9756, 0x0, 0x0}, 1},
+ {0xFA1D, {0x7CBE, 0x0, 0x0}, 1},
+ {0xFA1E, {0x7FBD, 0x0, 0x0}, 1},
+ {0xFA20, {0x8612, 0x0, 0x0}, 1},
+ {0xFA22, {0x8AF8, 0x0, 0x0}, 1},
+ {0xFA25, {0x9038, 0x0, 0x0}, 1},
+ {0xFA26, {0x90FD, 0x0, 0x0}, 1},
+ {0xFA2A, {0x98EF, 0x0, 0x0}, 1},
+ {0xFA2B, {0x98FC, 0x0, 0x0}, 1},
+ {0xFA2C, {0x9928, 0x0, 0x0}, 1},
+ {0xFA2D, {0x9DB4, 0x0, 0x0}, 1},
+ {0xFA2E, {0x90DE, 0x0, 0x0}, 1},
+ {0xFA2F, {0x96B7, 0x0, 0x0}, 1},
+ {0xFA30, {0x4FAE, 0x0, 0x0}, 1},
+ {0xFA31, {0x50E7, 0x0, 0x0}, 1},
+ {0xFA32, {0x514D, 0x0, 0x0}, 1},
+ {0xFA33, {0x52C9, 0x0, 0x0}, 1},
+ {0xFA34, {0x52E4, 0x0, 0x0}, 1},
+ {0xFA35, {0x5351, 0x0, 0x0}, 1},
+ {0xFA36, {0x559D, 0x0, 0x0}, 1},
+ {0xFA37, {0x5606, 0x0, 0x0}, 1},
+ {0xFA38, {0x5668, 0x0, 0x0}, 1},
+ {0xFA39, {0x5840, 0x0, 0x0}, 1},
+ {0xFA3A, {0x58A8, 0x0, 0x0}, 1},
+ {0xFA3B, {0x5C64, 0x0, 0x0}, 1},
+ {0xFA3C, {0x5C6E, 0x0, 0x0}, 1},
+ {0xFA3D, {0x6094, 0x0, 0x0}, 1},
+ {0xFA3E, {0x6168, 0x0, 0x0}, 1},
+ {0xFA3F, {0x618E, 0x0, 0x0}, 1},
+ {0xFA40, {0x61F2, 0x0, 0x0}, 1},
+ {0xFA41, {0x654F, 0x0, 0x0}, 1},
+ {0xFA42, {0x65E2, 0x0, 0x0}, 1},
+ {0xFA43, {0x6691, 0x0, 0x0}, 1},
+ {0xFA44, {0x6885, 0x0, 0x0}, 1},
+ {0xFA45, {0x6D77, 0x0, 0x0}, 1},
+ {0xFA46, {0x6E1A, 0x0, 0x0}, 1},
+ {0xFA47, {0x6F22, 0x0, 0x0}, 1},
+ {0xFA48, {0x716E, 0x0, 0x0}, 1},
+ {0xFA49, {0x722B, 0x0, 0x0}, 1},
+ {0xFA4A, {0x7422, 0x0, 0x0}, 1},
+ {0xFA4B, {0x7891, 0x0, 0x0}, 1},
+ {0xFA4C, {0x793E, 0x0, 0x0}, 1},
+ {0xFA4D, {0x7949, 0x0, 0x0}, 1},
+ {0xFA4E, {0x7948, 0x0, 0x0}, 1},
+ {0xFA4F, {0x7950, 0x0, 0x0}, 1},
+ {0xFA50, {0x7956, 0x0, 0x0}, 1},
+ {0xFA51, {0x795D, 0x0, 0x0}, 1},
+ {0xFA52, {0x798D, 0x0, 0x0}, 1},
+ {0xFA53, {0x798E, 0x0, 0x0}, 1},
+ {0xFA54, {0x7A40, 0x0, 0x0}, 1},
+ {0xFA55, {0x7A81, 0x0, 0x0}, 1},
+ {0xFA56, {0x7BC0, 0x0, 0x0}, 1},
+ {0xFA57, {0x7DF4, 0x0, 0x0}, 1},
+ {0xFA58, {0x7E09, 0x0, 0x0}, 1},
+ {0xFA59, {0x7E41, 0x0, 0x0}, 1},
+ {0xFA5A, {0x7F72, 0x0, 0x0}, 1},
+ {0xFA5B, {0x8005, 0x0, 0x0}, 1},
+ {0xFA5C, {0x81ED, 0x0, 0x0}, 1},
+ {0xFA5D, {0x8279, 0x0, 0x0}, 1},
+ {0xFA5E, {0x8279, 0x0, 0x0}, 1},
+ {0xFA5F, {0x8457, 0x0, 0x0}, 1},
+ {0xFA60, {0x8910, 0x0, 0x0}, 1},
+ {0xFA61, {0x8996, 0x0, 0x0}, 1},
+ {0xFA62, {0x8B01, 0x0, 0x0}, 1},
+ {0xFA63, {0x8B39, 0x0, 0x0}, 1},
+ {0xFA64, {0x8CD3, 0x0, 0x0}, 1},
+ {0xFA65, {0x8D08, 0x0, 0x0}, 1},
+ {0xFA66, {0x8FB6, 0x0, 0x0}, 1},
+ {0xFA67, {0x9038, 0x0, 0x0}, 1},
+ {0xFA68, {0x96E3, 0x0, 0x0}, 1},
+ {0xFA69, {0x97FF, 0x0, 0x0}, 1},
+ {0xFA6A, {0x983B, 0x0, 0x0}, 1},
+ {0xFA6B, {0x6075, 0x0, 0x0}, 1},
+ {0xFA6C, {0x242EE, 0x0, 0x0}, 1},
+ {0xFA6D, {0x8218, 0x0, 0x0}, 1},
+ {0xFA70, {0x4E26, 0x0, 0x0}, 1},
+ {0xFA71, {0x51B5, 0x0, 0x0}, 1},
+ {0xFA72, {0x5168, 0x0, 0x0}, 1},
+ {0xFA73, {0x4F80, 0x0, 0x0}, 1},
+ {0xFA74, {0x5145, 0x0, 0x0}, 1},
+ {0xFA75, {0x5180, 0x0, 0x0}, 1},
+ {0xFA76, {0x52C7, 0x0, 0x0}, 1},
+ {0xFA77, {0x52FA, 0x0, 0x0}, 1},
+ {0xFA78, {0x559D, 0x0, 0x0}, 1},
+ {0xFA79, {0x5555, 0x0, 0x0}, 1},
+ {0xFA7A, {0x5599, 0x0, 0x0}, 1},
+ {0xFA7B, {0x55E2, 0x0, 0x0}, 1},
+ {0xFA7C, {0x585A, 0x0, 0x0}, 1},
+ {0xFA7D, {0x58B3, 0x0, 0x0}, 1},
+ {0xFA7E, {0x5944, 0x0, 0x0}, 1},
+ {0xFA7F, {0x5954, 0x0, 0x0}, 1},
+ {0xFA80, {0x5A62, 0x0, 0x0}, 1},
+ {0xFA81, {0x5B28, 0x0, 0x0}, 1},
+ {0xFA82, {0x5ED2, 0x0, 0x0}, 1},
+ {0xFA83, {0x5ED9, 0x0, 0x0}, 1},
+ {0xFA84, {0x5F69, 0x0, 0x0}, 1},
+ {0xFA85, {0x5FAD, 0x0, 0x0}, 1},
+ {0xFA86, {0x60D8, 0x0, 0x0}, 1},
+ {0xFA87, {0x614E, 0x0, 0x0}, 1},
+ {0xFA88, {0x6108, 0x0, 0x0}, 1},
+ {0xFA89, {0x618E, 0x0, 0x0}, 1},
+ {0xFA8A, {0x6160, 0x0, 0x0}, 1},
+ {0xFA8B, {0x61F2, 0x0, 0x0}, 1},
+ {0xFA8C, {0x6234, 0x0, 0x0}, 1},
+ {0xFA8D, {0x63C4, 0x0, 0x0}, 1},
+ {0xFA8E, {0x641C, 0x0, 0x0}, 1},
+ {0xFA8F, {0x6452, 0x0, 0x0}, 1},
+ {0xFA90, {0x6556, 0x0, 0x0}, 1},
+ {0xFA91, {0x6674, 0x0, 0x0}, 1},
+ {0xFA92, {0x6717, 0x0, 0x0}, 1},
+ {0xFA93, {0x671B, 0x0, 0x0}, 1},
+ {0xFA94, {0x6756, 0x0, 0x0}, 1},
+ {0xFA95, {0x6B79, 0x0, 0x0}, 1},
+ {0xFA96, {0x6BBA, 0x0, 0x0}, 1},
+ {0xFA97, {0x6D41, 0x0, 0x0}, 1},
+ {0xFA98, {0x6EDB, 0x0, 0x0}, 1},
+ {0xFA99, {0x6ECB, 0x0, 0x0}, 1},
+ {0xFA9A, {0x6F22, 0x0, 0x0}, 1},
+ {0xFA9B, {0x701E, 0x0, 0x0}, 1},
+ {0xFA9C, {0x716E, 0x0, 0x0}, 1},
+ {0xFA9D, {0x77A7, 0x0, 0x0}, 1},
+ {0xFA9E, {0x7235, 0x0, 0x0}, 1},
+ {0xFA9F, {0x72AF, 0x0, 0x0}, 1},
+ {0xFAA0, {0x732A, 0x0, 0x0}, 1},
+ {0xFAA1, {0x7471, 0x0, 0x0}, 1},
+ {0xFAA2, {0x7506, 0x0, 0x0}, 1},
+ {0xFAA3, {0x753B, 0x0, 0x0}, 1},
+ {0xFAA4, {0x761D, 0x0, 0x0}, 1},
+ {0xFAA5, {0x761F, 0x0, 0x0}, 1},
+ {0xFAA6, {0x76CA, 0x0, 0x0}, 1},
+ {0xFAA7, {0x76DB, 0x0, 0x0}, 1},
+ {0xFAA8, {0x76F4, 0x0, 0x0}, 1},
+ {0xFAA9, {0x774A, 0x0, 0x0}, 1},
+ {0xFAAA, {0x7740, 0x0, 0x0}, 1},
+ {0xFAAB, {0x78CC, 0x0, 0x0}, 1},
+ {0xFAAC, {0x7AB1, 0x0, 0x0}, 1},
+ {0xFAAD, {0x7BC0, 0x0, 0x0}, 1},
+ {0xFAAE, {0x7C7B, 0x0, 0x0}, 1},
+ {0xFAAF, {0x7D5B, 0x0, 0x0}, 1},
+ {0xFAB0, {0x7DF4, 0x0, 0x0}, 1},
+ {0xFAB1, {0x7F3E, 0x0, 0x0}, 1},
+ {0xFAB2, {0x8005, 0x0, 0x0}, 1},
+ {0xFAB3, {0x8352, 0x0, 0x0}, 1},
+ {0xFAB4, {0x83EF, 0x0, 0x0}, 1},
+ {0xFAB5, {0x8779, 0x0, 0x0}, 1},
+ {0xFAB6, {0x8941, 0x0, 0x0}, 1},
+ {0xFAB7, {0x8986, 0x0, 0x0}, 1},
+ {0xFAB8, {0x8996, 0x0, 0x0}, 1},
+ {0xFAB9, {0x8ABF, 0x0, 0x0}, 1},
+ {0xFABA, {0x8AF8, 0x0, 0x0}, 1},
+ {0xFABB, {0x8ACB, 0x0, 0x0}, 1},
+ {0xFABC, {0x8B01, 0x0, 0x0}, 1},
+ {0xFABD, {0x8AFE, 0x0, 0x0}, 1},
+ {0xFABE, {0x8AED, 0x0, 0x0}, 1},
+ {0xFABF, {0x8B39, 0x0, 0x0}, 1},
+ {0xFAC0, {0x8B8A, 0x0, 0x0}, 1},
+ {0xFAC1, {0x8D08, 0x0, 0x0}, 1},
+ {0xFAC2, {0x8F38, 0x0, 0x0}, 1},
+ {0xFAC3, {0x9072, 0x0, 0x0}, 1},
+ {0xFAC4, {0x9199, 0x0, 0x0}, 1},
+ {0xFAC5, {0x9276, 0x0, 0x0}, 1},
+ {0xFAC6, {0x967C, 0x0, 0x0}, 1},
+ {0xFAC7, {0x96E3, 0x0, 0x0}, 1},
+ {0xFAC8, {0x9756, 0x0, 0x0}, 1},
+ {0xFAC9, {0x97DB, 0x0, 0x0}, 1},
+ {0xFACA, {0x97FF, 0x0, 0x0}, 1},
+ {0xFACB, {0x980B, 0x0, 0x0}, 1},
+ {0xFACC, {0x983B, 0x0, 0x0}, 1},
+ {0xFACD, {0x9B12, 0x0, 0x0}, 1},
+ {0xFACE, {0x9F9C, 0x0, 0x0}, 1},
+ {0xFACF, {0x2284A, 0x0, 0x0}, 1},
+ {0xFAD0, {0x22844, 0x0, 0x0}, 1},
+ {0xFAD1, {0x233D5, 0x0, 0x0}, 1},
+ {0xFAD2, {0x3B9D, 0x0, 0x0}, 1},
+ {0xFAD3, {0x4018, 0x0, 0x0}, 1},
+ {0xFAD4, {0x4039, 0x0, 0x0}, 1},
+ {0xFAD5, {0x25249, 0x0, 0x0}, 1},
+ {0xFAD6, {0x25CD0, 0x0, 0x0}, 1},
+ {0xFAD7, {0x27ED3, 0x0, 0x0}, 1},
+ {0xFAD8, {0x9F43, 0x0, 0x0}, 1},
+ {0xFAD9, {0x9F8E, 0x0, 0x0}, 1},
+ {0xFB1D, {0x5D9, 0x0, 0x0}, 1},
+ {0xFB1E, {0x0, 0x0, 0x0}, 0},
+ {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0xFF43, 0x0, 0x0}, 1},
+ {0xFF24, {0xFF44, 0x0, 0x0}, 1},
+ {0xFF25, {0xFF45, 0x0, 0x0}, 1},
+ {0xFF26, {0xFF46, 0x0, 0x0}, 1},
+ {0xFF27, {0xFF47, 0x0, 0x0}, 1},
+ {0xFF28, {0xFF48, 0x0, 0x0}, 1},
+ {0xFF29, {0xFF49, 0x0, 0x0}, 1},
+ {0xFF2A, {0xFF4A, 0x0, 0x0}, 1},
+ {0xFF2B, {0xFF4B, 0x0, 0x0}, 1},
+ {0xFF2C, {0xFF4C, 0x0, 0x0}, 1},
+ {0xFF2D, {0xFF4D, 0x0, 0x0}, 1},
+ {0xFF2E, {0xFF4E, 0x0, 0x0}, 1},
+ {0xFF2F, {0xFF4F, 0x0, 0x0}, 1},
+ {0xFF30, {0xFF50, 0x0, 0x0}, 1},
+ {0xFF31, {0xFF51, 0x0, 0x0}, 1},
+ {0xFF32, {0xFF52, 0x0, 0x0}, 1},
+ {0xFF33, {0xFF53, 0x0, 0x0}, 1},
+ {0xFF34, {0xFF54, 0x0, 0x0}, 1},
+ {0xFF35, {0xFF55, 0x0, 0x0}, 1},
+ {0xFF36, {0xFF56, 0x0, 0x0}, 1},
+ {0xFF37, {0xFF57, 0x0, 0x0}, 1},
+ {0xFF38, {0xFF58, 0x0, 0x0}, 1},
+ {0xFF39, {0xFF59, 0x0, 0x0}, 1},
+ {0xFF3A, {0xFF5A, 0x0, 0x0}, 1},
+ {0x101FD, {0x0, 0x0, 0x0}, 0},
+ {0x102E0, {0x0, 0x0, 0x0}, 0},
+ {0x10376, {0x0, 0x0, 0x0}, 0},
+ {0x10377, {0x0, 0x0, 0x0}, 0},
+ {0x10378, {0x0, 0x0, 0x0}, 0},
+ {0x10379, {0x0, 0x0, 0x0}, 0},
+ {0x1037A, {0x0, 0x0, 0x0}, 0},
+ {0x10400, {0x10428, 0x0, 0x0}, 1},
+ {0x10401, {0x10429, 0x0, 0x0}, 1},
+ {0x10402, {0x1042A, 0x0, 0x0}, 1},
+ {0x10403, {0x1042B, 0x0, 0x0}, 1},
+ {0x10404, {0x1042C, 0x0, 0x0}, 1},
+ {0x10405, {0x1042D, 0x0, 0x0}, 1},
+ {0x10406, {0x1042E, 0x0, 0x0}, 1},
+ {0x10407, {0x1042F, 0x0, 0x0}, 1},
+ {0x10408, {0x10430, 0x0, 0x0}, 1},
+ {0x10409, {0x10431, 0x0, 0x0}, 1},
+ {0x1040A, {0x10432, 0x0, 0x0}, 1},
+ {0x1040B, {0x10433, 0x0, 0x0}, 1},
+ {0x1040C, {0x10434, 0x0, 0x0}, 1},
+ {0x1040D, {0x10435, 0x0, 0x0}, 1},
+ {0x1040E, {0x10436, 0x0, 0x0}, 1},
+ {0x1040F, {0x10437, 0x0, 0x0}, 1},
+ {0x10410, {0x10438, 0x0, 0x0}, 1},
+ {0x10411, {0x10439, 0x0, 0x0}, 1},
+ {0x10412, {0x1043A, 0x0, 0x0}, 1},
+ {0x10413, {0x1043B, 0x0, 0x0}, 1},
+ {0x10414, {0x1043C, 0x0, 0x0}, 1},
+ {0x10415, {0x1043D, 0x0, 0x0}, 1},
+ {0x10416, {0x1043E, 0x0, 0x0}, 1},
+ {0x10417, {0x1043F, 0x0, 0x0}, 1},
+ {0x10418, {0x10440, 0x0, 0x0}, 1},
+ {0x10419, {0x10441, 0x0, 0x0}, 1},
+ {0x1041A, {0x10442, 0x0, 0x0}, 1},
+ {0x1041B, {0x10443, 0x0, 0x0}, 1},
+ {0x1041C, {0x10444, 0x0, 0x0}, 1},
+ {0x1041D, {0x10445, 0x0, 0x0}, 1},
+ {0x1041E, {0x10446, 0x0, 0x0}, 1},
+ {0x1041F, {0x10447, 0x0, 0x0}, 1},
+ {0x10420, {0x10448, 0x0, 0x0}, 1},
+ {0x10421, {0x10449, 0x0, 0x0}, 1},
+ {0x10422, {0x1044A, 0x0, 0x0}, 1},
+ {0x10423, {0x1044B, 0x0, 0x0}, 1},
+ {0x10424, {0x1044C, 0x0, 0x0}, 1},
+ {0x10425, {0x1044D, 0x0, 0x0}, 1},
+ {0x10426, {0x1044E, 0x0, 0x0}, 1},
+ {0x10427, {0x1044F, 0x0, 0x0}, 1},
+ {0x104B0, {0x104D8, 0x0, 0x0}, 1},
+ {0x104B1, {0x104D9, 0x0, 0x0}, 1},
+ {0x104B2, {0x104DA, 0x0, 0x0}, 1},
+ {0x104B3, {0x104DB, 0x0, 0x0}, 1},
+ {0x104B4, {0x104DC, 0x0, 0x0}, 1},
+ {0x104B5, {0x104DD, 0x0, 0x0}, 1},
+ {0x104B6, {0x104DE, 0x0, 0x0}, 1},
+ {0x104B7, {0x104DF, 0x0, 0x0}, 1},
+ {0x104B8, {0x104E0, 0x0, 0x0}, 1},
+ {0x104B9, {0x104E1, 0x0, 0x0}, 1},
+ {0x104BA, {0x104E2, 0x0, 0x0}, 1},
+ {0x104BB, {0x104E3, 0x0, 0x0}, 1},
+ {0x104BC, {0x104E4, 0x0, 0x0}, 1},
+ {0x104BD, {0x104E5, 0x0, 0x0}, 1},
+ {0x104BE, {0x104E6, 0x0, 0x0}, 1},
+ {0x104BF, {0x104E7, 0x0, 0x0}, 1},
+ {0x104C0, {0x104E8, 0x0, 0x0}, 1},
+ {0x104C1, {0x104E9, 0x0, 0x0}, 1},
+ {0x104C2, {0x104EA, 0x0, 0x0}, 1},
+ {0x104C3, {0x104EB, 0x0, 0x0}, 1},
+ {0x104C4, {0x104EC, 0x0, 0x0}, 1},
+ {0x104C5, {0x104ED, 0x0, 0x0}, 1},
+ {0x104C6, {0x104EE, 0x0, 0x0}, 1},
+ {0x104C7, {0x104EF, 0x0, 0x0}, 1},
+ {0x104C8, {0x104F0, 0x0, 0x0}, 1},
+ {0x104C9, {0x104F1, 0x0, 0x0}, 1},
+ {0x104CA, {0x104F2, 0x0, 0x0}, 1},
+ {0x104CB, {0x104F3, 0x0, 0x0}, 1},
+ {0x104CC, {0x104F4, 0x0, 0x0}, 1},
+ {0x104CD, {0x104F5, 0x0, 0x0}, 1},
+ {0x104CE, {0x104F6, 0x0, 0x0}, 1},
+ {0x104CF, {0x104F7, 0x0, 0x0}, 1},
+ {0x104D0, {0x104F8, 0x0, 0x0}, 1},
+ {0x104D1, {0x104F9, 0x0, 0x0}, 1},
+ {0x104D2, {0x104FA, 0x0, 0x0}, 1},
+ {0x104D3, {0x104FB, 0x0, 0x0}, 1},
+ {0x10A01, {0x0, 0x0, 0x0}, 0},
+ {0x10A02, {0x0, 0x0, 0x0}, 0},
+ {0x10A03, {0x0, 0x0, 0x0}, 0},
+ {0x10A05, {0x0, 0x0, 0x0}, 0},
+ {0x10A06, {0x0, 0x0, 0x0}, 0},
+ {0x10A0C, {0x0, 0x0, 0x0}, 0},
+ {0x10A0D, {0x0, 0x0, 0x0}, 0},
+ {0x10A0E, {0x0, 0x0, 0x0}, 0},
+ {0x10A0F, {0x0, 0x0, 0x0}, 0},
+ {0x10A38, {0x0, 0x0, 0x0}, 0},
+ {0x10A39, {0x0, 0x0, 0x0}, 0},
+ {0x10A3A, {0x0, 0x0, 0x0}, 0},
+ {0x10A3F, {0x0, 0x0, 0x0}, 0},
+ {0x10AE5, {0x0, 0x0, 0x0}, 0},
+ {0x10AE6, {0x0, 0x0, 0x0}, 0},
+ {0x10C80, {0x10CC0, 0x0, 0x0}, 1},
+ {0x10C81, {0x10CC1, 0x0, 0x0}, 1},
+ {0x10C82, {0x10CC2, 0x0, 0x0}, 1},
+ {0x10C83, {0x10CC3, 0x0, 0x0}, 1},
+ {0x10C84, {0x10CC4, 0x0, 0x0}, 1},
+ {0x10C85, {0x10CC5, 0x0, 0x0}, 1},
+ {0x10C86, {0x10CC6, 0x0, 0x0}, 1},
+ {0x10C87, {0x10CC7, 0x0, 0x0}, 1},
+ {0x10C88, {0x10CC8, 0x0, 0x0}, 1},
+ {0x10C89, {0x10CC9, 0x0, 0x0}, 1},
+ {0x10C8A, {0x10CCA, 0x0, 0x0}, 1},
+ {0x10C8B, {0x10CCB, 0x0, 0x0}, 1},
+ {0x10C8C, {0x10CCC, 0x0, 0x0}, 1},
+ {0x10C8D, {0x10CCD, 0x0, 0x0}, 1},
+ {0x10C8E, {0x10CCE, 0x0, 0x0}, 1},
+ {0x10C8F, {0x10CCF, 0x0, 0x0}, 1},
+ {0x10C90, {0x10CD0, 0x0, 0x0}, 1},
+ {0x10C91, {0x10CD1, 0x0, 0x0}, 1},
+ {0x10C92, {0x10CD2, 0x0, 0x0}, 1},
+ {0x10C93, {0x10CD3, 0x0, 0x0}, 1},
+ {0x10C94, {0x10CD4, 0x0, 0x0}, 1},
+ {0x10C95, {0x10CD5, 0x0, 0x0}, 1},
+ {0x10C96, {0x10CD6, 0x0, 0x0}, 1},
+ {0x10C97, {0x10CD7, 0x0, 0x0}, 1},
+ {0x10C98, {0x10CD8, 0x0, 0x0}, 1},
+ {0x10C99, {0x10CD9, 0x0, 0x0}, 1},
+ {0x10C9A, {0x10CDA, 0x0, 0x0}, 1},
+ {0x10C9B, {0x10CDB, 0x0, 0x0}, 1},
+ {0x10C9C, {0x10CDC, 0x0, 0x0}, 1},
+ {0x10C9D, {0x10CDD, 0x0, 0x0}, 1},
+ {0x10C9E, {0x10CDE, 0x0, 0x0}, 1},
+ {0x10C9F, {0x10CDF, 0x0, 0x0}, 1},
+ {0x10CA0, {0x10CE0, 0x0, 0x0}, 1},
+ {0x10CA1, {0x10CE1, 0x0, 0x0}, 1},
+ {0x10CA2, {0x10CE2, 0x0, 0x0}, 1},
+ {0x10CA3, {0x10CE3, 0x0, 0x0}, 1},
+ {0x10CA4, {0x10CE4, 0x0, 0x0}, 1},
+ {0x10CA5, {0x10CE5, 0x0, 0x0}, 1},
+ {0x10CA6, {0x10CE6, 0x0, 0x0}, 1},
+ {0x10CA7, {0x10CE7, 0x0, 0x0}, 1},
+ {0x10CA8, {0x10CE8, 0x0, 0x0}, 1},
+ {0x10CA9, {0x10CE9, 0x0, 0x0}, 1},
+ {0x10CAA, {0x10CEA, 0x0, 0x0}, 1},
+ {0x10CAB, {0x10CEB, 0x0, 0x0}, 1},
+ {0x10CAC, {0x10CEC, 0x0, 0x0}, 1},
+ {0x10CAD, {0x10CED, 0x0, 0x0}, 1},
+ {0x10CAE, {0x10CEE, 0x0, 0x0}, 1},
+ {0x10CAF, {0x10CEF, 0x0, 0x0}, 1},
+ {0x10CB0, {0x10CF0, 0x0, 0x0}, 1},
+ {0x10CB1, {0x10CF1, 0x0, 0x0}, 1},
+ {0x10CB2, {0x10CF2, 0x0, 0x0}, 1},
+ {0x10D24, {0x0, 0x0, 0x0}, 0},
+ {0x10D25, {0x0, 0x0, 0x0}, 0},
+ {0x10D26, {0x0, 0x0, 0x0}, 0},
+ {0x10D27, {0x0, 0x0, 0x0}, 0},
+ {0x10EAB, {0x0, 0x0, 0x0}, 0},
+ {0x10EAC, {0x0, 0x0, 0x0}, 0},
+ {0x10F46, {0x0, 0x0, 0x0}, 0},
+ {0x10F47, {0x0, 0x0, 0x0}, 0},
+ {0x10F48, {0x0, 0x0, 0x0}, 0},
+ {0x10F49, {0x0, 0x0, 0x0}, 0},
+ {0x10F4A, {0x0, 0x0, 0x0}, 0},
+ {0x10F4B, {0x0, 0x0, 0x0}, 0},
+ {0x10F4C, {0x0, 0x0, 0x0}, 0},
+ {0x10F4D, {0x0, 0x0, 0x0}, 0},
+ {0x10F4E, {0x0, 0x0, 0x0}, 0},
+ {0x10F4F, {0x0, 0x0, 0x0}, 0},
+ {0x10F50, {0x0, 0x0, 0x0}, 0},
+ {0x11001, {0x0, 0x0, 0x0}, 0},
+ {0x11038, {0x0, 0x0, 0x0}, 0},
+ {0x11039, {0x0, 0x0, 0x0}, 0},
+ {0x1103A, {0x0, 0x0, 0x0}, 0},
+ {0x1103B, {0x0, 0x0, 0x0}, 0},
+ {0x1103C, {0x0, 0x0, 0x0}, 0},
+ {0x1103D, {0x0, 0x0, 0x0}, 0},
+ {0x1103E, {0x0, 0x0, 0x0}, 0},
+ {0x1103F, {0x0, 0x0, 0x0}, 0},
+ {0x11040, {0x0, 0x0, 0x0}, 0},
+ {0x11041, {0x0, 0x0, 0x0}, 0},
+ {0x11042, {0x0, 0x0, 0x0}, 0},
+ {0x11043, {0x0, 0x0, 0x0}, 0},
+ {0x11044, {0x0, 0x0, 0x0}, 0},
+ {0x11045, {0x0, 0x0, 0x0}, 0},
+ {0x11046, {0x0, 0x0, 0x0}, 0},
+ {0x1107F, {0x0, 0x0, 0x0}, 0},
+ {0x11080, {0x0, 0x0, 0x0}, 0},
+ {0x11081, {0x0, 0x0, 0x0}, 0},
+ {0x1109A, {0x11099, 0x0, 0x0}, 1},
+ {0x1109C, {0x1109B, 0x0, 0x0}, 1},
+ {0x110AB, {0x110A5, 0x0, 0x0}, 1},
+ {0x110B3, {0x0, 0x0, 0x0}, 0},
+ {0x110B4, {0x0, 0x0, 0x0}, 0},
+ {0x110B5, {0x0, 0x0, 0x0}, 0},
+ {0x110B6, {0x0, 0x0, 0x0}, 0},
+ {0x110B9, {0x0, 0x0, 0x0}, 0},
+ {0x110BA, {0x0, 0x0, 0x0}, 0},
+ {0x11100, {0x0, 0x0, 0x0}, 0},
+ {0x11101, {0x0, 0x0, 0x0}, 0},
+ {0x11102, {0x0, 0x0, 0x0}, 0},
+ {0x11127, {0x0, 0x0, 0x0}, 0},
+ {0x11128, {0x0, 0x0, 0x0}, 0},
+ {0x11129, {0x0, 0x0, 0x0}, 0},
+ {0x1112A, {0x0, 0x0, 0x0}, 0},
+ {0x1112B, {0x0, 0x0, 0x0}, 0},
+ {0x1112D, {0x0, 0x0, 0x0}, 0},
+ {0x1112E, {0x0, 0x0, 0x0}, 0},
+ {0x1112F, {0x0, 0x0, 0x0}, 0},
+ {0x11130, {0x0, 0x0, 0x0}, 0},
+ {0x11131, {0x0, 0x0, 0x0}, 0},
+ {0x11132, {0x0, 0x0, 0x0}, 0},
+ {0x11133, {0x0, 0x0, 0x0}, 0},
+ {0x11134, {0x0, 0x0, 0x0}, 0},
+ {0x11173, {0x0, 0x0, 0x0}, 0},
+ {0x11180, {0x0, 0x0, 0x0}, 0},
+ {0x11181, {0x0, 0x0, 0x0}, 0},
+ {0x111B6, {0x0, 0x0, 0x0}, 0},
+ {0x111B7, {0x0, 0x0, 0x0}, 0},
+ {0x111B8, {0x0, 0x0, 0x0}, 0},
+ {0x111B9, {0x0, 0x0, 0x0}, 0},
+ {0x111BA, {0x0, 0x0, 0x0}, 0},
+ {0x111BB, {0x0, 0x0, 0x0}, 0},
+ {0x111BC, {0x0, 0x0, 0x0}, 0},
+ {0x111BD, {0x0, 0x0, 0x0}, 0},
+ {0x111BE, {0x0, 0x0, 0x0}, 0},
+ {0x111C9, {0x0, 0x0, 0x0}, 0},
+ {0x111CA, {0x0, 0x0, 0x0}, 0},
+ {0x111CB, {0x0, 0x0, 0x0}, 0},
+ {0x111CC, {0x0, 0x0, 0x0}, 0},
+ {0x111CF, {0x0, 0x0, 0x0}, 0},
+ {0x1122F, {0x0, 0x0, 0x0}, 0},
+ {0x11230, {0x0, 0x0, 0x0}, 0},
+ {0x11231, {0x0, 0x0, 0x0}, 0},
+ {0x11234, {0x0, 0x0, 0x0}, 0},
+ {0x11236, {0x0, 0x0, 0x0}, 0},
+ {0x11237, {0x0, 0x0, 0x0}, 0},
+ {0x1123E, {0x0, 0x0, 0x0}, 0},
+ {0x112DF, {0x0, 0x0, 0x0}, 0},
+ {0x112E3, {0x0, 0x0, 0x0}, 0},
+ {0x112E4, {0x0, 0x0, 0x0}, 0},
+ {0x112E5, {0x0, 0x0, 0x0}, 0},
+ {0x112E6, {0x0, 0x0, 0x0}, 0},
+ {0x112E7, {0x0, 0x0, 0x0}, 0},
+ {0x112E8, {0x0, 0x0, 0x0}, 0},
+ {0x112E9, {0x0, 0x0, 0x0}, 0},
+ {0x112EA, {0x0, 0x0, 0x0}, 0},
+ {0x11300, {0x0, 0x0, 0x0}, 0},
+ {0x11301, {0x0, 0x0, 0x0}, 0},
+ {0x1133B, {0x0, 0x0, 0x0}, 0},
+ {0x1133C, {0x0, 0x0, 0x0}, 0},
+ {0x11340, {0x0, 0x0, 0x0}, 0},
+ {0x1134B, {0x11347, 0x1133E, 0x0}, 2},
+ {0x1134C, {0x11347, 0x11357, 0x0}, 2},
+ {0x11366, {0x0, 0x0, 0x0}, 0},
+ {0x11367, {0x0, 0x0, 0x0}, 0},
+ {0x11368, {0x0, 0x0, 0x0}, 0},
+ {0x11369, {0x0, 0x0, 0x0}, 0},
+ {0x1136A, {0x0, 0x0, 0x0}, 0},
+ {0x1136B, {0x0, 0x0, 0x0}, 0},
+ {0x1136C, {0x0, 0x0, 0x0}, 0},
+ {0x11370, {0x0, 0x0, 0x0}, 0},
+ {0x11371, {0x0, 0x0, 0x0}, 0},
+ {0x11372, {0x0, 0x0, 0x0}, 0},
+ {0x11373, {0x0, 0x0, 0x0}, 0},
+ {0x11374, {0x0, 0x0, 0x0}, 0},
+ {0x11438, {0x0, 0x0, 0x0}, 0},
+ {0x11439, {0x0, 0x0, 0x0}, 0},
+ {0x1143A, {0x0, 0x0, 0x0}, 0},
+ {0x1143B, {0x0, 0x0, 0x0}, 0},
+ {0x1143C, {0x0, 0x0, 0x0}, 0},
+ {0x1143D, {0x0, 0x0, 0x0}, 0},
+ {0x1143E, {0x0, 0x0, 0x0}, 0},
+ {0x1143F, {0x0, 0x0, 0x0}, 0},
+ {0x11442, {0x0, 0x0, 0x0}, 0},
+ {0x11443, {0x0, 0x0, 0x0}, 0},
+ {0x11444, {0x0, 0x0, 0x0}, 0},
+ {0x11446, {0x0, 0x0, 0x0}, 0},
+ {0x1145E, {0x0, 0x0, 0x0}, 0},
+ {0x114B3, {0x0, 0x0, 0x0}, 0},
+ {0x114B4, {0x0, 0x0, 0x0}, 0},
+ {0x114B5, {0x0, 0x0, 0x0}, 0},
+ {0x114B6, {0x0, 0x0, 0x0}, 0},
+ {0x114B7, {0x0, 0x0, 0x0}, 0},
+ {0x114B8, {0x0, 0x0, 0x0}, 0},
+ {0x114BA, {0x0, 0x0, 0x0}, 0},
+ {0x114BB, {0x114B9, 0x0, 0x0}, 1},
+ {0x114BC, {0x114B9, 0x114B0, 0x0}, 2},
+ {0x114BE, {0x114B9, 0x114BD, 0x0}, 2},
+ {0x114BF, {0x0, 0x0, 0x0}, 0},
+ {0x114C0, {0x0, 0x0, 0x0}, 0},
+ {0x114C2, {0x0, 0x0, 0x0}, 0},
+ {0x114C3, {0x0, 0x0, 0x0}, 0},
+ {0x115B2, {0x0, 0x0, 0x0}, 0},
+ {0x115B3, {0x0, 0x0, 0x0}, 0},
+ {0x115B4, {0x0, 0x0, 0x0}, 0},
+ {0x115B5, {0x0, 0x0, 0x0}, 0},
+ {0x115BA, {0x115B8, 0x115AF, 0x0}, 2},
+ {0x115BB, {0x115B9, 0x115AF, 0x0}, 2},
+ {0x115BC, {0x0, 0x0, 0x0}, 0},
+ {0x115BD, {0x0, 0x0, 0x0}, 0},
+ {0x115BF, {0x0, 0x0, 0x0}, 0},
+ {0x115C0, {0x0, 0x0, 0x0}, 0},
+ {0x115DC, {0x0, 0x0, 0x0}, 0},
+ {0x115DD, {0x0, 0x0, 0x0}, 0},
+ {0x11633, {0x0, 0x0, 0x0}, 0},
+ {0x11634, {0x0, 0x0, 0x0}, 0},
+ {0x11635, {0x0, 0x0, 0x0}, 0},
+ {0x11636, {0x0, 0x0, 0x0}, 0},
+ {0x11637, {0x0, 0x0, 0x0}, 0},
+ {0x11638, {0x0, 0x0, 0x0}, 0},
+ {0x11639, {0x0, 0x0, 0x0}, 0},
+ {0x1163A, {0x0, 0x0, 0x0}, 0},
+ {0x1163D, {0x0, 0x0, 0x0}, 0},
+ {0x1163F, {0x0, 0x0, 0x0}, 0},
+ {0x11640, {0x0, 0x0, 0x0}, 0},
+ {0x116AB, {0x0, 0x0, 0x0}, 0},
+ {0x116AD, {0x0, 0x0, 0x0}, 0},
+ {0x116B0, {0x0, 0x0, 0x0}, 0},
+ {0x116B1, {0x0, 0x0, 0x0}, 0},
+ {0x116B2, {0x0, 0x0, 0x0}, 0},
+ {0x116B3, {0x0, 0x0, 0x0}, 0},
+ {0x116B4, {0x0, 0x0, 0x0}, 0},
+ {0x116B5, {0x0, 0x0, 0x0}, 0},
+ {0x116B7, {0x0, 0x0, 0x0}, 0},
+ {0x1171D, {0x0, 0x0, 0x0}, 0},
+ {0x1171E, {0x0, 0x0, 0x0}, 0},
+ {0x1171F, {0x0, 0x0, 0x0}, 0},
+ {0x11722, {0x0, 0x0, 0x0}, 0},
+ {0x11723, {0x0, 0x0, 0x0}, 0},
+ {0x11724, {0x0, 0x0, 0x0}, 0},
+ {0x11725, {0x0, 0x0, 0x0}, 0},
+ {0x11727, {0x0, 0x0, 0x0}, 0},
+ {0x11728, {0x0, 0x0, 0x0}, 0},
+ {0x11729, {0x0, 0x0, 0x0}, 0},
+ {0x1172A, {0x0, 0x0, 0x0}, 0},
+ {0x1172B, {0x0, 0x0, 0x0}, 0},
+ {0x1182F, {0x0, 0x0, 0x0}, 0},
+ {0x11830, {0x0, 0x0, 0x0}, 0},
+ {0x11831, {0x0, 0x0, 0x0}, 0},
+ {0x11832, {0x0, 0x0, 0x0}, 0},
+ {0x11833, {0x0, 0x0, 0x0}, 0},
+ {0x11834, {0x0, 0x0, 0x0}, 0},
+ {0x11835, {0x0, 0x0, 0x0}, 0},
+ {0x11836, {0x0, 0x0, 0x0}, 0},
+ {0x11837, {0x0, 0x0, 0x0}, 0},
+ {0x11839, {0x0, 0x0, 0x0}, 0},
+ {0x1183A, {0x0, 0x0, 0x0}, 0},
+ {0x118A0, {0x118C0, 0x0, 0x0}, 1},
+ {0x118A1, {0x118C1, 0x0, 0x0}, 1},
+ {0x118A2, {0x118C2, 0x0, 0x0}, 1},
+ {0x118A3, {0x118C3, 0x0, 0x0}, 1},
+ {0x118A4, {0x118C4, 0x0, 0x0}, 1},
+ {0x118A5, {0x118C5, 0x0, 0x0}, 1},
+ {0x118A6, {0x118C6, 0x0, 0x0}, 1},
+ {0x118A7, {0x118C7, 0x0, 0x0}, 1},
+ {0x118A8, {0x118C8, 0x0, 0x0}, 1},
+ {0x118A9, {0x118C9, 0x0, 0x0}, 1},
+ {0x118AA, {0x118CA, 0x0, 0x0}, 1},
+ {0x118AB, {0x118CB, 0x0, 0x0}, 1},
+ {0x118AC, {0x118CC, 0x0, 0x0}, 1},
+ {0x118AD, {0x118CD, 0x0, 0x0}, 1},
+ {0x118AE, {0x118CE, 0x0, 0x0}, 1},
+ {0x118AF, {0x118CF, 0x0, 0x0}, 1},
+ {0x118B0, {0x118D0, 0x0, 0x0}, 1},
+ {0x118B1, {0x118D1, 0x0, 0x0}, 1},
+ {0x118B2, {0x118D2, 0x0, 0x0}, 1},
+ {0x118B3, {0x118D3, 0x0, 0x0}, 1},
+ {0x118B4, {0x118D4, 0x0, 0x0}, 1},
+ {0x118B5, {0x118D5, 0x0, 0x0}, 1},
+ {0x118B6, {0x118D6, 0x0, 0x0}, 1},
+ {0x118B7, {0x118D7, 0x0, 0x0}, 1},
+ {0x118B8, {0x118D8, 0x0, 0x0}, 1},
+ {0x118B9, {0x118D9, 0x0, 0x0}, 1},
+ {0x118BA, {0x118DA, 0x0, 0x0}, 1},
+ {0x118BB, {0x118DB, 0x0, 0x0}, 1},
+ {0x118BC, {0x118DC, 0x0, 0x0}, 1},
+ {0x118BD, {0x118DD, 0x0, 0x0}, 1},
+ {0x118BE, {0x118DE, 0x0, 0x0}, 1},
+ {0x118BF, {0x118DF, 0x0, 0x0}, 1},
+ {0x11938, {0x11935, 0x11930, 0x0}, 2},
+ {0x1193B, {0x0, 0x0, 0x0}, 0},
+ {0x1193C, {0x0, 0x0, 0x0}, 0},
+ {0x1193E, {0x0, 0x0, 0x0}, 0},
+ {0x11943, {0x0, 0x0, 0x0}, 0},
+ {0x119D4, {0x0, 0x0, 0x0}, 0},
+ {0x119D5, {0x0, 0x0, 0x0}, 0},
+ {0x119D6, {0x0, 0x0, 0x0}, 0},
+ {0x119D7, {0x0, 0x0, 0x0}, 0},
+ {0x119DA, {0x0, 0x0, 0x0}, 0},
+ {0x119DB, {0x0, 0x0, 0x0}, 0},
+ {0x119E0, {0x0, 0x0, 0x0}, 0},
+ {0x11A01, {0x0, 0x0, 0x0}, 0},
+ {0x11A02, {0x0, 0x0, 0x0}, 0},
+ {0x11A03, {0x0, 0x0, 0x0}, 0},
+ {0x11A04, {0x0, 0x0, 0x0}, 0},
+ {0x11A05, {0x0, 0x0, 0x0}, 0},
+ {0x11A06, {0x0, 0x0, 0x0}, 0},
+ {0x11A07, {0x0, 0x0, 0x0}, 0},
+ {0x11A08, {0x0, 0x0, 0x0}, 0},
+ {0x11A09, {0x0, 0x0, 0x0}, 0},
+ {0x11A0A, {0x0, 0x0, 0x0}, 0},
+ {0x11A33, {0x0, 0x0, 0x0}, 0},
+ {0x11A34, {0x0, 0x0, 0x0}, 0},
+ {0x11A35, {0x0, 0x0, 0x0}, 0},
+ {0x11A36, {0x0, 0x0, 0x0}, 0},
+ {0x11A37, {0x0, 0x0, 0x0}, 0},
+ {0x11A38, {0x0, 0x0, 0x0}, 0},
+ {0x11A3B, {0x0, 0x0, 0x0}, 0},
+ {0x11A3C, {0x0, 0x0, 0x0}, 0},
+ {0x11A3D, {0x0, 0x0, 0x0}, 0},
+ {0x11A3E, {0x0, 0x0, 0x0}, 0},
+ {0x11A47, {0x0, 0x0, 0x0}, 0},
+ {0x11A51, {0x0, 0x0, 0x0}, 0},
+ {0x11A52, {0x0, 0x0, 0x0}, 0},
+ {0x11A53, {0x0, 0x0, 0x0}, 0},
+ {0x11A54, {0x0, 0x0, 0x0}, 0},
+ {0x11A55, {0x0, 0x0, 0x0}, 0},
+ {0x11A56, {0x0, 0x0, 0x0}, 0},
+ {0x11A59, {0x0, 0x0, 0x0}, 0},
+ {0x11A5A, {0x0, 0x0, 0x0}, 0},
+ {0x11A5B, {0x0, 0x0, 0x0}, 0},
+ {0x11A8A, {0x0, 0x0, 0x0}, 0},
+ {0x11A8B, {0x0, 0x0, 0x0}, 0},
+ {0x11A8C, {0x0, 0x0, 0x0}, 0},
+ {0x11A8D, {0x0, 0x0, 0x0}, 0},
+ {0x11A8E, {0x0, 0x0, 0x0}, 0},
+ {0x11A8F, {0x0, 0x0, 0x0}, 0},
+ {0x11A90, {0x0, 0x0, 0x0}, 0},
+ {0x11A91, {0x0, 0x0, 0x0}, 0},
+ {0x11A92, {0x0, 0x0, 0x0}, 0},
+ {0x11A93, {0x0, 0x0, 0x0}, 0},
+ {0x11A94, {0x0, 0x0, 0x0}, 0},
+ {0x11A95, {0x0, 0x0, 0x0}, 0},
+ {0x11A96, {0x0, 0x0, 0x0}, 0},
+ {0x11A98, {0x0, 0x0, 0x0}, 0},
+ {0x11A99, {0x0, 0x0, 0x0}, 0},
+ {0x11C30, {0x0, 0x0, 0x0}, 0},
+ {0x11C31, {0x0, 0x0, 0x0}, 0},
+ {0x11C32, {0x0, 0x0, 0x0}, 0},
+ {0x11C33, {0x0, 0x0, 0x0}, 0},
+ {0x11C34, {0x0, 0x0, 0x0}, 0},
+ {0x11C35, {0x0, 0x0, 0x0}, 0},
+ {0x11C36, {0x0, 0x0, 0x0}, 0},
+ {0x11C38, {0x0, 0x0, 0x0}, 0},
+ {0x11C39, {0x0, 0x0, 0x0}, 0},
+ {0x11C3A, {0x0, 0x0, 0x0}, 0},
+ {0x11C3B, {0x0, 0x0, 0x0}, 0},
+ {0x11C3C, {0x0, 0x0, 0x0}, 0},
+ {0x11C3D, {0x0, 0x0, 0x0}, 0},
+ {0x11C3F, {0x0, 0x0, 0x0}, 0},
+ {0x11C92, {0x0, 0x0, 0x0}, 0},
+ {0x11C93, {0x0, 0x0, 0x0}, 0},
+ {0x11C94, {0x0, 0x0, 0x0}, 0},
+ {0x11C95, {0x0, 0x0, 0x0}, 0},
+ {0x11C96, {0x0, 0x0, 0x0}, 0},
+ {0x11C97, {0x0, 0x0, 0x0}, 0},
+ {0x11C98, {0x0, 0x0, 0x0}, 0},
+ {0x11C99, {0x0, 0x0, 0x0}, 0},
+ {0x11C9A, {0x0, 0x0, 0x0}, 0},
+ {0x11C9B, {0x0, 0x0, 0x0}, 0},
+ {0x11C9C, {0x0, 0x0, 0x0}, 0},
+ {0x11C9D, {0x0, 0x0, 0x0}, 0},
+ {0x11C9E, {0x0, 0x0, 0x0}, 0},
+ {0x11C9F, {0x0, 0x0, 0x0}, 0},
+ {0x11CA0, {0x0, 0x0, 0x0}, 0},
+ {0x11CA1, {0x0, 0x0, 0x0}, 0},
+ {0x11CA2, {0x0, 0x0, 0x0}, 0},
+ {0x11CA3, {0x0, 0x0, 0x0}, 0},
+ {0x11CA4, {0x0, 0x0, 0x0}, 0},
+ {0x11CA5, {0x0, 0x0, 0x0}, 0},
+ {0x11CA6, {0x0, 0x0, 0x0}, 0},
+ {0x11CA7, {0x0, 0x0, 0x0}, 0},
+ {0x11CAA, {0x0, 0x0, 0x0}, 0},
+ {0x11CAB, {0x0, 0x0, 0x0}, 0},
+ {0x11CAC, {0x0, 0x0, 0x0}, 0},
+ {0x11CAD, {0x0, 0x0, 0x0}, 0},
+ {0x11CAE, {0x0, 0x0, 0x0}, 0},
+ {0x11CAF, {0x0, 0x0, 0x0}, 0},
+ {0x11CB0, {0x0, 0x0, 0x0}, 0},
+ {0x11CB2, {0x0, 0x0, 0x0}, 0},
+ {0x11CB3, {0x0, 0x0, 0x0}, 0},
+ {0x11CB5, {0x0, 0x0, 0x0}, 0},
+ {0x11CB6, {0x0, 0x0, 0x0}, 0},
+ {0x11D31, {0x0, 0x0, 0x0}, 0},
+ {0x11D32, {0x0, 0x0, 0x0}, 0},
+ {0x11D33, {0x0, 0x0, 0x0}, 0},
+ {0x11D34, {0x0, 0x0, 0x0}, 0},
+ {0x11D35, {0x0, 0x0, 0x0}, 0},
+ {0x11D36, {0x0, 0x0, 0x0}, 0},
+ {0x11D3A, {0x0, 0x0, 0x0}, 0},
+ {0x11D3C, {0x0, 0x0, 0x0}, 0},
+ {0x11D3D, {0x0, 0x0, 0x0}, 0},
+ {0x11D3F, {0x0, 0x0, 0x0}, 0},
+ {0x11D40, {0x0, 0x0, 0x0}, 0},
+ {0x11D41, {0x0, 0x0, 0x0}, 0},
+ {0x11D42, {0x0, 0x0, 0x0}, 0},
+ {0x11D43, {0x0, 0x0, 0x0}, 0},
+ {0x11D44, {0x0, 0x0, 0x0}, 0},
+ {0x11D45, {0x0, 0x0, 0x0}, 0},
+ {0x11D47, {0x0, 0x0, 0x0}, 0},
+ {0x11D90, {0x0, 0x0, 0x0}, 0},
+ {0x11D91, {0x0, 0x0, 0x0}, 0},
+ {0x11D95, {0x0, 0x0, 0x0}, 0},
+ {0x11D97, {0x0, 0x0, 0x0}, 0},
+ {0x11EF3, {0x0, 0x0, 0x0}, 0},
+ {0x11EF4, {0x0, 0x0, 0x0}, 0},
+ {0x16AF0, {0x0, 0x0, 0x0}, 0},
+ {0x16AF1, {0x0, 0x0, 0x0}, 0},
+ {0x16AF2, {0x0, 0x0, 0x0}, 0},
+ {0x16AF3, {0x0, 0x0, 0x0}, 0},
+ {0x16AF4, {0x0, 0x0, 0x0}, 0},
+ {0x16B30, {0x0, 0x0, 0x0}, 0},
+ {0x16B31, {0x0, 0x0, 0x0}, 0},
+ {0x16B32, {0x0, 0x0, 0x0}, 0},
+ {0x16B33, {0x0, 0x0, 0x0}, 0},
+ {0x16B34, {0x0, 0x0, 0x0}, 0},
+ {0x16B35, {0x0, 0x0, 0x0}, 0},
+ {0x16B36, {0x0, 0x0, 0x0}, 0},
+ {0x16E40, {0x16E60, 0x0, 0x0}, 1},
+ {0x16E41, {0x16E61, 0x0, 0x0}, 1},
+ {0x16E42, {0x16E62, 0x0, 0x0}, 1},
+ {0x16E43, {0x16E63, 0x0, 0x0}, 1},
+ {0x16E44, {0x16E64, 0x0, 0x0}, 1},
+ {0x16E45, {0x16E65, 0x0, 0x0}, 1},
+ {0x16E46, {0x16E66, 0x0, 0x0}, 1},
+ {0x16E47, {0x16E67, 0x0, 0x0}, 1},
+ {0x16E48, {0x16E68, 0x0, 0x0}, 1},
+ {0x16E49, {0x16E69, 0x0, 0x0}, 1},
+ {0x16E4A, {0x16E6A, 0x0, 0x0}, 1},
+ {0x16E4B, {0x16E6B, 0x0, 0x0}, 1},
+ {0x16E4C, {0x16E6C, 0x0, 0x0}, 1},
+ {0x16E4D, {0x16E6D, 0x0, 0x0}, 1},
+ {0x16E4E, {0x16E6E, 0x0, 0x0}, 1},
+ {0x16E4F, {0x16E6F, 0x0, 0x0}, 1},
+ {0x16E50, {0x16E70, 0x0, 0x0}, 1},
+ {0x16E51, {0x16E71, 0x0, 0x0}, 1},
+ {0x16E52, {0x16E72, 0x0, 0x0}, 1},
+ {0x16E53, {0x16E73, 0x0, 0x0}, 1},
+ {0x16E54, {0x16E74, 0x0, 0x0}, 1},
+ {0x16E55, {0x16E75, 0x0, 0x0}, 1},
+ {0x16E56, {0x16E76, 0x0, 0x0}, 1},
+ {0x16E57, {0x16E77, 0x0, 0x0}, 1},
+ {0x16E58, {0x16E78, 0x0, 0x0}, 1},
+ {0x16E59, {0x16E79, 0x0, 0x0}, 1},
+ {0x16E5A, {0x16E7A, 0x0, 0x0}, 1},
+ {0x16E5B, {0x16E7B, 0x0, 0x0}, 1},
+ {0x16E5C, {0x16E7C, 0x0, 0x0}, 1},
+ {0x16E5D, {0x16E7D, 0x0, 0x0}, 1},
+ {0x16E5E, {0x16E7E, 0x0, 0x0}, 1},
+ {0x16E5F, {0x16E7F, 0x0, 0x0}, 1},
+ {0x16F4F, {0x0, 0x0, 0x0}, 0},
+ {0x16F8F, {0x0, 0x0, 0x0}, 0},
+ {0x16F90, {0x0, 0x0, 0x0}, 0},
+ {0x16F91, {0x0, 0x0, 0x0}, 0},
+ {0x16F92, {0x0, 0x0, 0x0}, 0},
+ {0x16FE4, {0x0, 0x0, 0x0}, 0},
+ {0x1BC9D, {0x0, 0x0, 0x0}, 0},
+ {0x1BC9E, {0x0, 0x0, 0x0}, 0},
+ {0x1D15E, {0x1D157, 0x1D165, 0x0}, 2},
+ {0x1D15F, {0x1D158, 0x1D165, 0x0}, 2},
+ {0x1D160, {0x1D158, 0x1D165, 0x1D16E}, 3},
+ {0x1D161, {0x1D158, 0x1D165, 0x1D16F}, 3},
+ {0x1D162, {0x1D158, 0x1D165, 0x1D170}, 3},
+ {0x1D163, {0x1D158, 0x1D165, 0x1D171}, 3},
+ {0x1D164, {0x1D158, 0x1D165, 0x1D172}, 3},
+ {0x1D167, {0x0, 0x0, 0x0}, 0},
+ {0x1D168, {0x0, 0x0, 0x0}, 0},
+ {0x1D169, {0x0, 0x0, 0x0}, 0},
+ {0x1D17B, {0x0, 0x0, 0x0}, 0},
+ {0x1D17C, {0x0, 0x0, 0x0}, 0},
+ {0x1D17D, {0x0, 0x0, 0x0}, 0},
+ {0x1D17E, {0x0, 0x0, 0x0}, 0},
+ {0x1D17F, {0x0, 0x0, 0x0}, 0},
+ {0x1D180, {0x0, 0x0, 0x0}, 0},
+ {0x1D181, {0x0, 0x0, 0x0}, 0},
+ {0x1D182, {0x0, 0x0, 0x0}, 0},
+ {0x1D185, {0x0, 0x0, 0x0}, 0},
+ {0x1D186, {0x0, 0x0, 0x0}, 0},
+ {0x1D187, {0x0, 0x0, 0x0}, 0},
+ {0x1D188, {0x0, 0x0, 0x0}, 0},
+ {0x1D189, {0x0, 0x0, 0x0}, 0},
+ {0x1D18A, {0x0, 0x0, 0x0}, 0},
+ {0x1D18B, {0x0, 0x0, 0x0}, 0},
+ {0x1D1AA, {0x0, 0x0, 0x0}, 0},
+ {0x1D1AB, {0x0, 0x0, 0x0}, 0},
+ {0x1D1AC, {0x0, 0x0, 0x0}, 0},
+ {0x1D1AD, {0x0, 0x0, 0x0}, 0},
+ {0x1D1BB, {0x1D1B9, 0x1D165, 0x0}, 2},
+ {0x1D1BC, {0x1D1BA, 0x1D165, 0x0}, 2},
+ {0x1D1BD, {0x1D1B9, 0x1D165, 0x1D16E}, 3},
+ {0x1D1BE, {0x1D1BA, 0x1D165, 0x1D16E}, 3},
+ {0x1D1BF, {0x1D1B9, 0x1D165, 0x1D16F}, 3},
+ {0x1D1C0, {0x1D1BA, 0x1D165, 0x1D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0, 0x0}, 0},
+ {0x1E005, {0x0, 0x0, 0x0}, 0},
+ {0x1E006, {0x0, 0x0, 0x0}, 0},
+ {0x1E008, {0x0, 0x0, 0x0}, 0},
+ {0x1E009, {0x0, 0x0, 0x0}, 0},
+ {0x1E00A, {0x0, 0x0, 0x0}, 0},
+ {0x1E00B, {0x0, 0x0, 0x0}, 0},
+ {0x1E00C, {0x0, 0x0, 0x0}, 0},
+ {0x1E00D, {0x0, 0x0, 0x0}, 0},
+ {0x1E00E, {0x0, 0x0, 0x0}, 0},
+ {0x1E00F, {0x0, 0x0, 0x0}, 0},
+ {0x1E010, {0x0, 0x0, 0x0}, 0},
+ {0x1E011, {0x0, 0x0, 0x0}, 0},
+ {0x1E012, {0x0, 0x0, 0x0}, 0},
+ {0x1E013, {0x0, 0x0, 0x0}, 0},
+ {0x1E014, {0x0, 0x0, 0x0}, 0},
+ {0x1E015, {0x0, 0x0, 0x0}, 0},
+ {0x1E016, {0x0, 0x0, 0x0}, 0},
+ {0x1E017, {0x0, 0x0, 0x0}, 0},
+ {0x1E018, {0x0, 0x0, 0x0}, 0},
+ {0x1E01B, {0x0, 0x0, 0x0}, 0},
+ {0x1E01C, {0x0, 0x0, 0x0}, 0},
+ {0x1E01D, {0x0, 0x0, 0x0}, 0},
+ {0x1E01E, {0x0, 0x0, 0x0}, 0},
+ {0x1E01F, {0x0, 0x0, 0x0}, 0},
+ {0x1E020, {0x0, 0x0, 0x0}, 0},
+ {0x1E021, {0x0, 0x0, 0x0}, 0},
+ {0x1E023, {0x0, 0x0, 0x0}, 0},
+ {0x1E024, {0x0, 0x0, 0x0}, 0},
+ {0x1E026, {0x0, 0x0, 0x0}, 0},
+ {0x1E027, {0x0, 0x0, 0x0}, 0},
+ {0x1E028, {0x0, 0x0, 0x0}, 0},
+ {0x1E029, {0x0, 0x0, 0x0}, 0},
+ {0x1E02A, {0x0, 0x0, 0x0}, 0},
+ {0x1E130, {0x0, 0x0, 0x0}, 0},
+ {0x1E131, {0x0, 0x0, 0x0}, 0},
+ {0x1E132, {0x0, 0x0, 0x0}, 0},
+ {0x1E133, {0x0, 0x0, 0x0}, 0},
+ {0x1E134, {0x0, 0x0, 0x0}, 0},
+ {0x1E135, {0x0, 0x0, 0x0}, 0},
+ {0x1E136, {0x0, 0x0, 0x0}, 0},
+ {0x1E2EC, {0x0, 0x0, 0x0}, 0},
+ {0x1E2ED, {0x0, 0x0, 0x0}, 0},
+ {0x1E2EE, {0x0, 0x0, 0x0}, 0},
+ {0x1E2EF, {0x0, 0x0, 0x0}, 0},
+ {0x1E8D0, {0x0, 0x0, 0x0}, 0},
+ {0x1E8D1, {0x0, 0x0, 0x0}, 0},
+ {0x1E8D2, {0x0, 0x0, 0x0}, 0},
+ {0x1E8D3, {0x0, 0x0, 0x0}, 0},
+ {0x1E8D4, {0x0, 0x0, 0x0}, 0},
+ {0x1E8D5, {0x0, 0x0, 0x0}, 0},
+ {0x1E8D6, {0x0, 0x0, 0x0}, 0},
+ {0x1E900, {0x1E922, 0x0, 0x0}, 1},
+ {0x1E901, {0x1E923, 0x0, 0x0}, 1},
+ {0x1E902, {0x1E924, 0x0, 0x0}, 1},
+ {0x1E903, {0x1E925, 0x0, 0x0}, 1},
+ {0x1E904, {0x1E926, 0x0, 0x0}, 1},
+ {0x1E905, {0x1E927, 0x0, 0x0}, 1},
+ {0x1E906, {0x1E928, 0x0, 0x0}, 1},
+ {0x1E907, {0x1E929, 0x0, 0x0}, 1},
+ {0x1E908, {0x1E92A, 0x0, 0x0}, 1},
+ {0x1E909, {0x1E92B, 0x0, 0x0}, 1},
+ {0x1E90A, {0x1E92C, 0x0, 0x0}, 1},
+ {0x1E90B, {0x1E92D, 0x0, 0x0}, 1},
+ {0x1E90C, {0x1E92E, 0x0, 0x0}, 1},
+ {0x1E90D, {0x1E92F, 0x0, 0x0}, 1},
+ {0x1E90E, {0x1E930, 0x0, 0x0}, 1},
+ {0x1E90F, {0x1E931, 0x0, 0x0}, 1},
+ {0x1E910, {0x1E932, 0x0, 0x0}, 1},
+ {0x1E911, {0x1E933, 0x0, 0x0}, 1},
+ {0x1E912, {0x1E934, 0x0, 0x0}, 1},
+ {0x1E913, {0x1E935, 0x0, 0x0}, 1},
+ {0x1E914, {0x1E936, 0x0, 0x0}, 1},
+ {0x1E915, {0x1E937, 0x0, 0x0}, 1},
+ {0x1E916, {0x1E938, 0x0, 0x0}, 1},
+ {0x1E917, {0x1E939, 0x0, 0x0}, 1},
+ {0x1E918, {0x1E93A, 0x0, 0x0}, 1},
+ {0x1E919, {0x1E93B, 0x0, 0x0}, 1},
+ {0x1E91A, {0x1E93C, 0x0, 0x0}, 1},
+ {0x1E91B, {0x1E93D, 0x0, 0x0}, 1},
+ {0x1E91C, {0x1E93E, 0x0, 0x0}, 1},
+ {0x1E91D, {0x1E93F, 0x0, 0x0}, 1},
+ {0x1E91E, {0x1E940, 0x0, 0x0}, 1},
+ {0x1E91F, {0x1E941, 0x0, 0x0}, 1},
+ {0x1E920, {0x1E942, 0x0, 0x0}, 1},
+ {0x1E921, {0x1E943, 0x0, 0x0}, 1},
+ {0x1E944, {0x0, 0x0, 0x0}, 0},
+ {0x1E945, {0x0, 0x0, 0x0}, 0},
+ {0x1E946, {0x0, 0x0, 0x0}, 0},
+ {0x1E947, {0x0, 0x0, 0x0}, 0},
+ {0x1E948, {0x0, 0x0, 0x0}, 0},
+ {0x1E949, {0x0, 0x0, 0x0}, 0},
+ {0x1E94A, {0x0, 0x0, 0x0}, 0},
+ {0x2F800, {0x4E3D, 0x0, 0x0}, 1},
+ {0x2F801, {0x4E38, 0x0, 0x0}, 1},
+ {0x2F802, {0x4E41, 0x0, 0x0}, 1},
+ {0x2F803, {0x20122, 0x0, 0x0}, 1},
+ {0x2F804, {0x4F60, 0x0, 0x0}, 1},
+ {0x2F805, {0x4FAE, 0x0, 0x0}, 1},
+ {0x2F806, {0x4FBB, 0x0, 0x0}, 1},
+ {0x2F807, {0x5002, 0x0, 0x0}, 1},
+ {0x2F808, {0x507A, 0x0, 0x0}, 1},
+ {0x2F809, {0x5099, 0x0, 0x0}, 1},
+ {0x2F80A, {0x50E7, 0x0, 0x0}, 1},
+ {0x2F80B, {0x50CF, 0x0, 0x0}, 1},
+ {0x2F80C, {0x349E, 0x0, 0x0}, 1},
+ {0x2F80D, {0x2063A, 0x0, 0x0}, 1},
+ {0x2F80E, {0x514D, 0x0, 0x0}, 1},
+ {0x2F80F, {0x5154, 0x0, 0x0}, 1},
+ {0x2F810, {0x5164, 0x0, 0x0}, 1},
+ {0x2F811, {0x5177, 0x0, 0x0}, 1},
+ {0x2F812, {0x2051C, 0x0, 0x0}, 1},
+ {0x2F813, {0x34B9, 0x0, 0x0}, 1},
+ {0x2F814, {0x5167, 0x0, 0x0}, 1},
+ {0x2F815, {0x518D, 0x0, 0x0}, 1},
+ {0x2F816, {0x2054B, 0x0, 0x0}, 1},
+ {0x2F817, {0x5197, 0x0, 0x0}, 1},
+ {0x2F818, {0x51A4, 0x0, 0x0}, 1},
+ {0x2F819, {0x4ECC, 0x0, 0x0}, 1},
+ {0x2F81A, {0x51AC, 0x0, 0x0}, 1},
+ {0x2F81B, {0x51B5, 0x0, 0x0}, 1},
+ {0x2F81C, {0x291DF, 0x0, 0x0}, 1},
+ {0x2F81D, {0x51F5, 0x0, 0x0}, 1},
+ {0x2F81E, {0x5203, 0x0, 0x0}, 1},
+ {0x2F81F, {0x34DF, 0x0, 0x0}, 1},
+ {0x2F820, {0x523B, 0x0, 0x0}, 1},
+ {0x2F821, {0x5246, 0x0, 0x0}, 1},
+ {0x2F822, {0x5272, 0x0, 0x0}, 1},
+ {0x2F823, {0x5277, 0x0, 0x0}, 1},
+ {0x2F824, {0x3515, 0x0, 0x0}, 1},
+ {0x2F825, {0x52C7, 0x0, 0x0}, 1},
+ {0x2F826, {0x52C9, 0x0, 0x0}, 1},
+ {0x2F827, {0x52E4, 0x0, 0x0}, 1},
+ {0x2F828, {0x52FA, 0x0, 0x0}, 1},
+ {0x2F829, {0x5305, 0x0, 0x0}, 1},
+ {0x2F82A, {0x5306, 0x0, 0x0}, 1},
+ {0x2F82B, {0x5317, 0x0, 0x0}, 1},
+ {0x2F82C, {0x5349, 0x0, 0x0}, 1},
+ {0x2F82D, {0x5351, 0x0, 0x0}, 1},
+ {0x2F82E, {0x535A, 0x0, 0x0}, 1},
+ {0x2F82F, {0x5373, 0x0, 0x0}, 1},
+ {0x2F830, {0x537D, 0x0, 0x0}, 1},
+ {0x2F831, {0x537F, 0x0, 0x0}, 1},
+ {0x2F832, {0x537F, 0x0, 0x0}, 1},
+ {0x2F833, {0x537F, 0x0, 0x0}, 1},
+ {0x2F834, {0x20A2C, 0x0, 0x0}, 1},
+ {0x2F835, {0x7070, 0x0, 0x0}, 1},
+ {0x2F836, {0x53CA, 0x0, 0x0}, 1},
+ {0x2F837, {0x53DF, 0x0, 0x0}, 1},
+ {0x2F838, {0x20B63, 0x0, 0x0}, 1},
+ {0x2F839, {0x53EB, 0x0, 0x0}, 1},
+ {0x2F83A, {0x53F1, 0x0, 0x0}, 1},
+ {0x2F83B, {0x5406, 0x0, 0x0}, 1},
+ {0x2F83C, {0x549E, 0x0, 0x0}, 1},
+ {0x2F83D, {0x5438, 0x0, 0x0}, 1},
+ {0x2F83E, {0x5448, 0x0, 0x0}, 1},
+ {0x2F83F, {0x5468, 0x0, 0x0}, 1},
+ {0x2F840, {0x54A2, 0x0, 0x0}, 1},
+ {0x2F841, {0x54F6, 0x0, 0x0}, 1},
+ {0x2F842, {0x5510, 0x0, 0x0}, 1},
+ {0x2F843, {0x5553, 0x0, 0x0}, 1},
+ {0x2F844, {0x5563, 0x0, 0x0}, 1},
+ {0x2F845, {0x5584, 0x0, 0x0}, 1},
+ {0x2F846, {0x5584, 0x0, 0x0}, 1},
+ {0x2F847, {0x5599, 0x0, 0x0}, 1},
+ {0x2F848, {0x55AB, 0x0, 0x0}, 1},
+ {0x2F849, {0x55B3, 0x0, 0x0}, 1},
+ {0x2F84A, {0x55C2, 0x0, 0x0}, 1},
+ {0x2F84B, {0x5716, 0x0, 0x0}, 1},
+ {0x2F84C, {0x5606, 0x0, 0x0}, 1},
+ {0x2F84D, {0x5717, 0x0, 0x0}, 1},
+ {0x2F84E, {0x5651, 0x0, 0x0}, 1},
+ {0x2F84F, {0x5674, 0x0, 0x0}, 1},
+ {0x2F850, {0x5207, 0x0, 0x0}, 1},
+ {0x2F851, {0x58EE, 0x0, 0x0}, 1},
+ {0x2F852, {0x57CE, 0x0, 0x0}, 1},
+ {0x2F853, {0x57F4, 0x0, 0x0}, 1},
+ {0x2F854, {0x580D, 0x0, 0x0}, 1},
+ {0x2F855, {0x578B, 0x0, 0x0}, 1},
+ {0x2F856, {0x5832, 0x0, 0x0}, 1},
+ {0x2F857, {0x5831, 0x0, 0x0}, 1},
+ {0x2F858, {0x58AC, 0x0, 0x0}, 1},
+ {0x2F859, {0x214E4, 0x0, 0x0}, 1},
+ {0x2F85A, {0x58F2, 0x0, 0x0}, 1},
+ {0x2F85B, {0x58F7, 0x0, 0x0}, 1},
+ {0x2F85C, {0x5906, 0x0, 0x0}, 1},
+ {0x2F85D, {0x591A, 0x0, 0x0}, 1},
+ {0x2F85E, {0x5922, 0x0, 0x0}, 1},
+ {0x2F85F, {0x5962, 0x0, 0x0}, 1},
+ {0x2F860, {0x216A8, 0x0, 0x0}, 1},
+ {0x2F861, {0x216EA, 0x0, 0x0}, 1},
+ {0x2F862, {0x59EC, 0x0, 0x0}, 1},
+ {0x2F863, {0x5A1B, 0x0, 0x0}, 1},
+ {0x2F864, {0x5A27, 0x0, 0x0}, 1},
+ {0x2F865, {0x59D8, 0x0, 0x0}, 1},
+ {0x2F866, {0x5A66, 0x0, 0x0}, 1},
+ {0x2F867, {0x36EE, 0x0, 0x0}, 1},
+ {0x2F868, {0x36FC, 0x0, 0x0}, 1},
+ {0x2F869, {0x5B08, 0x0, 0x0}, 1},
+ {0x2F86A, {0x5B3E, 0x0, 0x0}, 1},
+ {0x2F86B, {0x5B3E, 0x0, 0x0}, 1},
+ {0x2F86C, {0x219C8, 0x0, 0x0}, 1},
+ {0x2F86D, {0x5BC3, 0x0, 0x0}, 1},
+ {0x2F86E, {0x5BD8, 0x0, 0x0}, 1},
+ {0x2F86F, {0x5BE7, 0x0, 0x0}, 1},
+ {0x2F870, {0x5BF3, 0x0, 0x0}, 1},
+ {0x2F871, {0x21B18, 0x0, 0x0}, 1},
+ {0x2F872, {0x5BFF, 0x0, 0x0}, 1},
+ {0x2F873, {0x5C06, 0x0, 0x0}, 1},
+ {0x2F874, {0x5F53, 0x0, 0x0}, 1},
+ {0x2F875, {0x5C22, 0x0, 0x0}, 1},
+ {0x2F876, {0x3781, 0x0, 0x0}, 1},
+ {0x2F877, {0x5C60, 0x0, 0x0}, 1},
+ {0x2F878, {0x5C6E, 0x0, 0x0}, 1},
+ {0x2F879, {0x5CC0, 0x0, 0x0}, 1},
+ {0x2F87A, {0x5C8D, 0x0, 0x0}, 1},
+ {0x2F87B, {0x21DE4, 0x0, 0x0}, 1},
+ {0x2F87C, {0x5D43, 0x0, 0x0}, 1},
+ {0x2F87D, {0x21DE6, 0x0, 0x0}, 1},
+ {0x2F87E, {0x5D6E, 0x0, 0x0}, 1},
+ {0x2F87F, {0x5D6B, 0x0, 0x0}, 1},
+ {0x2F880, {0x5D7C, 0x0, 0x0}, 1},
+ {0x2F881, {0x5DE1, 0x0, 0x0}, 1},
+ {0x2F882, {0x5DE2, 0x0, 0x0}, 1},
+ {0x2F883, {0x382F, 0x0, 0x0}, 1},
+ {0x2F884, {0x5DFD, 0x0, 0x0}, 1},
+ {0x2F885, {0x5E28, 0x0, 0x0}, 1},
+ {0x2F886, {0x5E3D, 0x0, 0x0}, 1},
+ {0x2F887, {0x5E69, 0x0, 0x0}, 1},
+ {0x2F888, {0x3862, 0x0, 0x0}, 1},
+ {0x2F889, {0x22183, 0x0, 0x0}, 1},
+ {0x2F88A, {0x387C, 0x0, 0x0}, 1},
+ {0x2F88B, {0x5EB0, 0x0, 0x0}, 1},
+ {0x2F88C, {0x5EB3, 0x0, 0x0}, 1},
+ {0x2F88D, {0x5EB6, 0x0, 0x0}, 1},
+ {0x2F88E, {0x5ECA, 0x0, 0x0}, 1},
+ {0x2F88F, {0x2A392, 0x0, 0x0}, 1},
+ {0x2F890, {0x5EFE, 0x0, 0x0}, 1},
+ {0x2F891, {0x22331, 0x0, 0x0}, 1},
+ {0x2F892, {0x22331, 0x0, 0x0}, 1},
+ {0x2F893, {0x8201, 0x0, 0x0}, 1},
+ {0x2F894, {0x5F22, 0x0, 0x0}, 1},
+ {0x2F895, {0x5F22, 0x0, 0x0}, 1},
+ {0x2F896, {0x38C7, 0x0, 0x0}, 1},
+ {0x2F897, {0x232B8, 0x0, 0x0}, 1},
+ {0x2F898, {0x261DA, 0x0, 0x0}, 1},
+ {0x2F899, {0x5F62, 0x0, 0x0}, 1},
+ {0x2F89A, {0x5F6B, 0x0, 0x0}, 1},
+ {0x2F89B, {0x38E3, 0x0, 0x0}, 1},
+ {0x2F89C, {0x5F9A, 0x0, 0x0}, 1},
+ {0x2F89D, {0x5FCD, 0x0, 0x0}, 1},
+ {0x2F89E, {0x5FD7, 0x0, 0x0}, 1},
+ {0x2F89F, {0x5FF9, 0x0, 0x0}, 1},
+ {0x2F8A0, {0x6081, 0x0, 0x0}, 1},
+ {0x2F8A1, {0x393A, 0x0, 0x0}, 1},
+ {0x2F8A2, {0x391C, 0x0, 0x0}, 1},
+ {0x2F8A3, {0x6094, 0x0, 0x0}, 1},
+ {0x2F8A4, {0x226D4, 0x0, 0x0}, 1},
+ {0x2F8A5, {0x60C7, 0x0, 0x0}, 1},
+ {0x2F8A6, {0x6148, 0x0, 0x0}, 1},
+ {0x2F8A7, {0x614C, 0x0, 0x0}, 1},
+ {0x2F8A8, {0x614E, 0x0, 0x0}, 1},
+ {0x2F8A9, {0x614C, 0x0, 0x0}, 1},
+ {0x2F8AA, {0x617A, 0x0, 0x0}, 1},
+ {0x2F8AB, {0x618E, 0x0, 0x0}, 1},
+ {0x2F8AC, {0x61B2, 0x0, 0x0}, 1},
+ {0x2F8AD, {0x61A4, 0x0, 0x0}, 1},
+ {0x2F8AE, {0x61AF, 0x0, 0x0}, 1},
+ {0x2F8AF, {0x61DE, 0x0, 0x0}, 1},
+ {0x2F8B0, {0x61F2, 0x0, 0x0}, 1},
+ {0x2F8B1, {0x61F6, 0x0, 0x0}, 1},
+ {0x2F8B2, {0x6210, 0x0, 0x0}, 1},
+ {0x2F8B3, {0x621B, 0x0, 0x0}, 1},
+ {0x2F8B4, {0x625D, 0x0, 0x0}, 1},
+ {0x2F8B5, {0x62B1, 0x0, 0x0}, 1},
+ {0x2F8B6, {0x62D4, 0x0, 0x0}, 1},
+ {0x2F8B7, {0x6350, 0x0, 0x0}, 1},
+ {0x2F8B8, {0x22B0C, 0x0, 0x0}, 1},
+ {0x2F8B9, {0x633D, 0x0, 0x0}, 1},
+ {0x2F8BA, {0x62FC, 0x0, 0x0}, 1},
+ {0x2F8BB, {0x6368, 0x0, 0x0}, 1},
+ {0x2F8BC, {0x6383, 0x0, 0x0}, 1},
+ {0x2F8BD, {0x63E4, 0x0, 0x0}, 1},
+ {0x2F8BE, {0x22BF1, 0x0, 0x0}, 1},
+ {0x2F8BF, {0x6422, 0x0, 0x0}, 1},
+ {0x2F8C0, {0x63C5, 0x0, 0x0}, 1},
+ {0x2F8C1, {0x63A9, 0x0, 0x0}, 1},
+ {0x2F8C2, {0x3A2E, 0x0, 0x0}, 1},
+ {0x2F8C3, {0x6469, 0x0, 0x0}, 1},
+ {0x2F8C4, {0x647E, 0x0, 0x0}, 1},
+ {0x2F8C5, {0x649D, 0x0, 0x0}, 1},
+ {0x2F8C6, {0x6477, 0x0, 0x0}, 1},
+ {0x2F8C7, {0x3A6C, 0x0, 0x0}, 1},
+ {0x2F8C8, {0x654F, 0x0, 0x0}, 1},
+ {0x2F8C9, {0x656C, 0x0, 0x0}, 1},
+ {0x2F8CA, {0x2300A, 0x0, 0x0}, 1},
+ {0x2F8CB, {0x65E3, 0x0, 0x0}, 1},
+ {0x2F8CC, {0x66F8, 0x0, 0x0}, 1},
+ {0x2F8CD, {0x6649, 0x0, 0x0}, 1},
+ {0x2F8CE, {0x3B19, 0x0, 0x0}, 1},
+ {0x2F8CF, {0x6691, 0x0, 0x0}, 1},
+ {0x2F8D0, {0x3B08, 0x0, 0x0}, 1},
+ {0x2F8D1, {0x3AE4, 0x0, 0x0}, 1},
+ {0x2F8D2, {0x5192, 0x0, 0x0}, 1},
+ {0x2F8D3, {0x5195, 0x0, 0x0}, 1},
+ {0x2F8D4, {0x6700, 0x0, 0x0}, 1},
+ {0x2F8D5, {0x669C, 0x0, 0x0}, 1},
+ {0x2F8D6, {0x80AD, 0x0, 0x0}, 1},
+ {0x2F8D7, {0x43D9, 0x0, 0x0}, 1},
+ {0x2F8D8, {0x6717, 0x0, 0x0}, 1},
+ {0x2F8D9, {0x671B, 0x0, 0x0}, 1},
+ {0x2F8DA, {0x6721, 0x0, 0x0}, 1},
+ {0x2F8DB, {0x675E, 0x0, 0x0}, 1},
+ {0x2F8DC, {0x6753, 0x0, 0x0}, 1},
+ {0x2F8DD, {0x233C3, 0x0, 0x0}, 1},
+ {0x2F8DE, {0x3B49, 0x0, 0x0}, 1},
+ {0x2F8DF, {0x67FA, 0x0, 0x0}, 1},
+ {0x2F8E0, {0x6785, 0x0, 0x0}, 1},
+ {0x2F8E1, {0x6852, 0x0, 0x0}, 1},
+ {0x2F8E2, {0x6885, 0x0, 0x0}, 1},
+ {0x2F8E3, {0x2346D, 0x0, 0x0}, 1},
+ {0x2F8E4, {0x688E, 0x0, 0x0}, 1},
+ {0x2F8E5, {0x681F, 0x0, 0x0}, 1},
+ {0x2F8E6, {0x6914, 0x0, 0x0}, 1},
+ {0x2F8E7, {0x3B9D, 0x0, 0x0}, 1},
+ {0x2F8E8, {0x6942, 0x0, 0x0}, 1},
+ {0x2F8E9, {0x69A3, 0x0, 0x0}, 1},
+ {0x2F8EA, {0x69EA, 0x0, 0x0}, 1},
+ {0x2F8EB, {0x6AA8, 0x0, 0x0}, 1},
+ {0x2F8EC, {0x236A3, 0x0, 0x0}, 1},
+ {0x2F8ED, {0x6ADB, 0x0, 0x0}, 1},
+ {0x2F8EE, {0x3C18, 0x0, 0x0}, 1},
+ {0x2F8EF, {0x6B21, 0x0, 0x0}, 1},
+ {0x2F8F0, {0x238A7, 0x0, 0x0}, 1},
+ {0x2F8F1, {0x6B54, 0x0, 0x0}, 1},
+ {0x2F8F2, {0x3C4E, 0x0, 0x0}, 1},
+ {0x2F8F3, {0x6B72, 0x0, 0x0}, 1},
+ {0x2F8F4, {0x6B9F, 0x0, 0x0}, 1},
+ {0x2F8F5, {0x6BBA, 0x0, 0x0}, 1},
+ {0x2F8F6, {0x6BBB, 0x0, 0x0}, 1},
+ {0x2F8F7, {0x23A8D, 0x0, 0x0}, 1},
+ {0x2F8F8, {0x21D0B, 0x0, 0x0}, 1},
+ {0x2F8F9, {0x23AFA, 0x0, 0x0}, 1},
+ {0x2F8FA, {0x6C4E, 0x0, 0x0}, 1},
+ {0x2F8FB, {0x23CBC, 0x0, 0x0}, 1},
+ {0x2F8FC, {0x6CBF, 0x0, 0x0}, 1},
+ {0x2F8FD, {0x6CCD, 0x0, 0x0}, 1},
+ {0x2F8FE, {0x6C67, 0x0, 0x0}, 1},
+ {0x2F8FF, {0x6D16, 0x0, 0x0}, 1},
+ {0x2F900, {0x6D3E, 0x0, 0x0}, 1},
+ {0x2F901, {0x6D77, 0x0, 0x0}, 1},
+ {0x2F902, {0x6D41, 0x0, 0x0}, 1},
+ {0x2F903, {0x6D69, 0x0, 0x0}, 1},
+ {0x2F904, {0x6D78, 0x0, 0x0}, 1},
+ {0x2F905, {0x6D85, 0x0, 0x0}, 1},
+ {0x2F906, {0x23D1E, 0x0, 0x0}, 1},
+ {0x2F907, {0x6D34, 0x0, 0x0}, 1},
+ {0x2F908, {0x6E2F, 0x0, 0x0}, 1},
+ {0x2F909, {0x6E6E, 0x0, 0x0}, 1},
+ {0x2F90A, {0x3D33, 0x0, 0x0}, 1},
+ {0x2F90B, {0x6ECB, 0x0, 0x0}, 1},
+ {0x2F90C, {0x6EC7, 0x0, 0x0}, 1},
+ {0x2F90D, {0x23ED1, 0x0, 0x0}, 1},
+ {0x2F90E, {0x6DF9, 0x0, 0x0}, 1},
+ {0x2F90F, {0x6F6E, 0x0, 0x0}, 1},
+ {0x2F910, {0x23F5E, 0x0, 0x0}, 1},
+ {0x2F911, {0x23F8E, 0x0, 0x0}, 1},
+ {0x2F912, {0x6FC6, 0x0, 0x0}, 1},
+ {0x2F913, {0x7039, 0x0, 0x0}, 1},
+ {0x2F914, {0x701E, 0x0, 0x0}, 1},
+ {0x2F915, {0x701B, 0x0, 0x0}, 1},
+ {0x2F916, {0x3D96, 0x0, 0x0}, 1},
+ {0x2F917, {0x704A, 0x0, 0x0}, 1},
+ {0x2F918, {0x707D, 0x0, 0x0}, 1},
+ {0x2F919, {0x7077, 0x0, 0x0}, 1},
+ {0x2F91A, {0x70AD, 0x0, 0x0}, 1},
+ {0x2F91B, {0x20525, 0x0, 0x0}, 1},
+ {0x2F91C, {0x7145, 0x0, 0x0}, 1},
+ {0x2F91D, {0x24263, 0x0, 0x0}, 1},
+ {0x2F91E, {0x719C, 0x0, 0x0}, 1},
+ {0x2F91F, {0x243AB, 0x0, 0x0}, 1},
+ {0x2F920, {0x7228, 0x0, 0x0}, 1},
+ {0x2F921, {0x7235, 0x0, 0x0}, 1},
+ {0x2F922, {0x7250, 0x0, 0x0}, 1},
+ {0x2F923, {0x24608, 0x0, 0x0}, 1},
+ {0x2F924, {0x7280, 0x0, 0x0}, 1},
+ {0x2F925, {0x7295, 0x0, 0x0}, 1},
+ {0x2F926, {0x24735, 0x0, 0x0}, 1},
+ {0x2F927, {0x24814, 0x0, 0x0}, 1},
+ {0x2F928, {0x737A, 0x0, 0x0}, 1},
+ {0x2F929, {0x738B, 0x0, 0x0}, 1},
+ {0x2F92A, {0x3EAC, 0x0, 0x0}, 1},
+ {0x2F92B, {0x73A5, 0x0, 0x0}, 1},
+ {0x2F92C, {0x3EB8, 0x0, 0x0}, 1},
+ {0x2F92D, {0x3EB8, 0x0, 0x0}, 1},
+ {0x2F92E, {0x7447, 0x0, 0x0}, 1},
+ {0x2F92F, {0x745C, 0x0, 0x0}, 1},
+ {0x2F930, {0x7471, 0x0, 0x0}, 1},
+ {0x2F931, {0x7485, 0x0, 0x0}, 1},
+ {0x2F932, {0x74CA, 0x0, 0x0}, 1},
+ {0x2F933, {0x3F1B, 0x0, 0x0}, 1},
+ {0x2F934, {0x7524, 0x0, 0x0}, 1},
+ {0x2F935, {0x24C36, 0x0, 0x0}, 1},
+ {0x2F936, {0x753E, 0x0, 0x0}, 1},
+ {0x2F937, {0x24C92, 0x0, 0x0}, 1},
+ {0x2F938, {0x7570, 0x0, 0x0}, 1},
+ {0x2F939, {0x2219F, 0x0, 0x0}, 1},
+ {0x2F93A, {0x7610, 0x0, 0x0}, 1},
+ {0x2F93B, {0x24FA1, 0x0, 0x0}, 1},
+ {0x2F93C, {0x24FB8, 0x0, 0x0}, 1},
+ {0x2F93D, {0x25044, 0x0, 0x0}, 1},
+ {0x2F93E, {0x3FFC, 0x0, 0x0}, 1},
+ {0x2F93F, {0x4008, 0x0, 0x0}, 1},
+ {0x2F940, {0x76F4, 0x0, 0x0}, 1},
+ {0x2F941, {0x250F3, 0x0, 0x0}, 1},
+ {0x2F942, {0x250F2, 0x0, 0x0}, 1},
+ {0x2F943, {0x25119, 0x0, 0x0}, 1},
+ {0x2F944, {0x25133, 0x0, 0x0}, 1},
+ {0x2F945, {0x771E, 0x0, 0x0}, 1},
+ {0x2F946, {0x771F, 0x0, 0x0}, 1},
+ {0x2F947, {0x771F, 0x0, 0x0}, 1},
+ {0x2F948, {0x774A, 0x0, 0x0}, 1},
+ {0x2F949, {0x4039, 0x0, 0x0}, 1},
+ {0x2F94A, {0x778B, 0x0, 0x0}, 1},
+ {0x2F94B, {0x4046, 0x0, 0x0}, 1},
+ {0x2F94C, {0x4096, 0x0, 0x0}, 1},
+ {0x2F94D, {0x2541D, 0x0, 0x0}, 1},
+ {0x2F94E, {0x784E, 0x0, 0x0}, 1},
+ {0x2F94F, {0x788C, 0x0, 0x0}, 1},
+ {0x2F950, {0x78CC, 0x0, 0x0}, 1},
+ {0x2F951, {0x40E3, 0x0, 0x0}, 1},
+ {0x2F952, {0x25626, 0x0, 0x0}, 1},
+ {0x2F953, {0x7956, 0x0, 0x0}, 1},
+ {0x2F954, {0x2569A, 0x0, 0x0}, 1},
+ {0x2F955, {0x256C5, 0x0, 0x0}, 1},
+ {0x2F956, {0x798F, 0x0, 0x0}, 1},
+ {0x2F957, {0x79EB, 0x0, 0x0}, 1},
+ {0x2F958, {0x412F, 0x0, 0x0}, 1},
+ {0x2F959, {0x7A40, 0x0, 0x0}, 1},
+ {0x2F95A, {0x7A4A, 0x0, 0x0}, 1},
+ {0x2F95B, {0x7A4F, 0x0, 0x0}, 1},
+ {0x2F95C, {0x2597C, 0x0, 0x0}, 1},
+ {0x2F95D, {0x25AA7, 0x0, 0x0}, 1},
+ {0x2F95E, {0x25AA7, 0x0, 0x0}, 1},
+ {0x2F95F, {0x7AEE, 0x0, 0x0}, 1},
+ {0x2F960, {0x4202, 0x0, 0x0}, 1},
+ {0x2F961, {0x25BAB, 0x0, 0x0}, 1},
+ {0x2F962, {0x7BC6, 0x0, 0x0}, 1},
+ {0x2F963, {0x7BC9, 0x0, 0x0}, 1},
+ {0x2F964, {0x4227, 0x0, 0x0}, 1},
+ {0x2F965, {0x25C80, 0x0, 0x0}, 1},
+ {0x2F966, {0x7CD2, 0x0, 0x0}, 1},
+ {0x2F967, {0x42A0, 0x0, 0x0}, 1},
+ {0x2F968, {0x7CE8, 0x0, 0x0}, 1},
+ {0x2F969, {0x7CE3, 0x0, 0x0}, 1},
+ {0x2F96A, {0x7D00, 0x0, 0x0}, 1},
+ {0x2F96B, {0x25F86, 0x0, 0x0}, 1},
+ {0x2F96C, {0x7D63, 0x0, 0x0}, 1},
+ {0x2F96D, {0x4301, 0x0, 0x0}, 1},
+ {0x2F96E, {0x7DC7, 0x0, 0x0}, 1},
+ {0x2F96F, {0x7E02, 0x0, 0x0}, 1},
+ {0x2F970, {0x7E45, 0x0, 0x0}, 1},
+ {0x2F971, {0x4334, 0x0, 0x0}, 1},
+ {0x2F972, {0x26228, 0x0, 0x0}, 1},
+ {0x2F973, {0x26247, 0x0, 0x0}, 1},
+ {0x2F974, {0x4359, 0x0, 0x0}, 1},
+ {0x2F975, {0x262D9, 0x0, 0x0}, 1},
+ {0x2F976, {0x7F7A, 0x0, 0x0}, 1},
+ {0x2F977, {0x2633E, 0x0, 0x0}, 1},
+ {0x2F978, {0x7F95, 0x0, 0x0}, 1},
+ {0x2F979, {0x7FFA, 0x0, 0x0}, 1},
+ {0x2F97A, {0x8005, 0x0, 0x0}, 1},
+ {0x2F97B, {0x264DA, 0x0, 0x0}, 1},
+ {0x2F97C, {0x26523, 0x0, 0x0}, 1},
+ {0x2F97D, {0x8060, 0x0, 0x0}, 1},
+ {0x2F97E, {0x265A8, 0x0, 0x0}, 1},
+ {0x2F97F, {0x8070, 0x0, 0x0}, 1},
+ {0x2F980, {0x2335F, 0x0, 0x0}, 1},
+ {0x2F981, {0x43D5, 0x0, 0x0}, 1},
+ {0x2F982, {0x80B2, 0x0, 0x0}, 1},
+ {0x2F983, {0x8103, 0x0, 0x0}, 1},
+ {0x2F984, {0x440B, 0x0, 0x0}, 1},
+ {0x2F985, {0x813E, 0x0, 0x0}, 1},
+ {0x2F986, {0x5AB5, 0x0, 0x0}, 1},
+ {0x2F987, {0x267A7, 0x0, 0x0}, 1},
+ {0x2F988, {0x267B5, 0x0, 0x0}, 1},
+ {0x2F989, {0x23393, 0x0, 0x0}, 1},
+ {0x2F98A, {0x2339C, 0x0, 0x0}, 1},
+ {0x2F98B, {0x8201, 0x0, 0x0}, 1},
+ {0x2F98C, {0x8204, 0x0, 0x0}, 1},
+ {0x2F98D, {0x8F9E, 0x0, 0x0}, 1},
+ {0x2F98E, {0x446B, 0x0, 0x0}, 1},
+ {0x2F98F, {0x8291, 0x0, 0x0}, 1},
+ {0x2F990, {0x828B, 0x0, 0x0}, 1},
+ {0x2F991, {0x829D, 0x0, 0x0}, 1},
+ {0x2F992, {0x52B3, 0x0, 0x0}, 1},
+ {0x2F993, {0x82B1, 0x0, 0x0}, 1},
+ {0x2F994, {0x82B3, 0x0, 0x0}, 1},
+ {0x2F995, {0x82BD, 0x0, 0x0}, 1},
+ {0x2F996, {0x82E6, 0x0, 0x0}, 1},
+ {0x2F997, {0x26B3C, 0x0, 0x0}, 1},
+ {0x2F998, {0x82E5, 0x0, 0x0}, 1},
+ {0x2F999, {0x831D, 0x0, 0x0}, 1},
+ {0x2F99A, {0x8363, 0x0, 0x0}, 1},
+ {0x2F99B, {0x83AD, 0x0, 0x0}, 1},
+ {0x2F99C, {0x8323, 0x0, 0x0}, 1},
+ {0x2F99D, {0x83BD, 0x0, 0x0}, 1},
+ {0x2F99E, {0x83E7, 0x0, 0x0}, 1},
+ {0x2F99F, {0x8457, 0x0, 0x0}, 1},
+ {0x2F9A0, {0x8353, 0x0, 0x0}, 1},
+ {0x2F9A1, {0x83CA, 0x0, 0x0}, 1},
+ {0x2F9A2, {0x83CC, 0x0, 0x0}, 1},
+ {0x2F9A3, {0x83DC, 0x0, 0x0}, 1},
+ {0x2F9A4, {0x26C36, 0x0, 0x0}, 1},
+ {0x2F9A5, {0x26D6B, 0x0, 0x0}, 1},
+ {0x2F9A6, {0x26CD5, 0x0, 0x0}, 1},
+ {0x2F9A7, {0x452B, 0x0, 0x0}, 1},
+ {0x2F9A8, {0x84F1, 0x0, 0x0}, 1},
+ {0x2F9A9, {0x84F3, 0x0, 0x0}, 1},
+ {0x2F9AA, {0x8516, 0x0, 0x0}, 1},
+ {0x2F9AB, {0x273CA, 0x0, 0x0}, 1},
+ {0x2F9AC, {0x8564, 0x0, 0x0}, 1},
+ {0x2F9AD, {0x26F2C, 0x0, 0x0}, 1},
+ {0x2F9AE, {0x455D, 0x0, 0x0}, 1},
+ {0x2F9AF, {0x4561, 0x0, 0x0}, 1},
+ {0x2F9B0, {0x26FB1, 0x0, 0x0}, 1},
+ {0x2F9B1, {0x270D2, 0x0, 0x0}, 1},
+ {0x2F9B2, {0x456B, 0x0, 0x0}, 1},
+ {0x2F9B3, {0x8650, 0x0, 0x0}, 1},
+ {0x2F9B4, {0x865C, 0x0, 0x0}, 1},
+ {0x2F9B5, {0x8667, 0x0, 0x0}, 1},
+ {0x2F9B6, {0x8669, 0x0, 0x0}, 1},
+ {0x2F9B7, {0x86A9, 0x0, 0x0}, 1},
+ {0x2F9B8, {0x8688, 0x0, 0x0}, 1},
+ {0x2F9B9, {0x870E, 0x0, 0x0}, 1},
+ {0x2F9BA, {0x86E2, 0x0, 0x0}, 1},
+ {0x2F9BB, {0x8779, 0x0, 0x0}, 1},
+ {0x2F9BC, {0x8728, 0x0, 0x0}, 1},
+ {0x2F9BD, {0x876B, 0x0, 0x0}, 1},
+ {0x2F9BE, {0x8786, 0x0, 0x0}, 1},
+ {0x2F9BF, {0x45D7, 0x0, 0x0}, 1},
+ {0x2F9C0, {0x87E1, 0x0, 0x0}, 1},
+ {0x2F9C1, {0x8801, 0x0, 0x0}, 1},
+ {0x2F9C2, {0x45F9, 0x0, 0x0}, 1},
+ {0x2F9C3, {0x8860, 0x0, 0x0}, 1},
+ {0x2F9C4, {0x8863, 0x0, 0x0}, 1},
+ {0x2F9C5, {0x27667, 0x0, 0x0}, 1},
+ {0x2F9C6, {0x88D7, 0x0, 0x0}, 1},
+ {0x2F9C7, {0x88DE, 0x0, 0x0}, 1},
+ {0x2F9C8, {0x4635, 0x0, 0x0}, 1},
+ {0x2F9C9, {0x88FA, 0x0, 0x0}, 1},
+ {0x2F9CA, {0x34BB, 0x0, 0x0}, 1},
+ {0x2F9CB, {0x278AE, 0x0, 0x0}, 1},
+ {0x2F9CC, {0x27966, 0x0, 0x0}, 1},
+ {0x2F9CD, {0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C, {0x9415, 0x0, 0x0}, 1},
+ {0x2F9ED, {0x28BFA, 0x0, 0x0}, 1},
+ {0x2F9EE, {0x958B, 0x0, 0x0}, 1},
+ {0x2F9EF, {0x4995, 0x0, 0x0}, 1},
+ {0x2F9F0, {0x95B7, 0x0, 0x0}, 1},
+ {0x2F9F1, {0x28D77, 0x0, 0x0}, 1},
+ {0x2F9F2, {0x49E6, 0x0, 0x0}, 1},
+ {0x2F9F3, {0x96C3, 0x0, 0x0}, 1},
+ {0x2F9F4, {0x5DB2, 0x0, 0x0}, 1},
+ {0x2F9F5, {0x9723, 0x0, 0x0}, 1},
+ {0x2F9F6, {0x29145, 0x0, 0x0}, 1},
+ {0x2F9F7, {0x2921A, 0x0, 0x0}, 1},
+ {0x2F9F8, {0x4A6E, 0x0, 0x0}, 1},
+ {0x2F9F9, {0x4A76, 0x0, 0x0}, 1},
+ {0x2F9FA, {0x97E0, 0x0, 0x0}, 1},
+ {0x2F9FB, {0x2940A, 0x0, 0x0}, 1},
+ {0x2F9FC, {0x4AB2, 0x0, 0x0}, 1},
+ {0x2F9FD, {0x29496, 0x0, 0x0}, 1},
+ {0x2F9FE, {0x980B, 0x0, 0x0}, 1},
+ {0x2F9FF, {0x980B, 0x0, 0x0}, 1},
+ {0x2FA00, {0x9829, 0x0, 0x0}, 1},
+ {0x2FA01, {0x295B6, 0x0, 0x0}, 1},
+ {0x2FA02, {0x98E2, 0x0, 0x0}, 1},
+ {0x2FA03, {0x4B33, 0x0, 0x0}, 1},
+ {0x2FA04, {0x9929, 0x0, 0x0}, 1},
+ {0x2FA05, {0x99A7, 0x0, 0x0}, 1},
+ {0x2FA06, {0x99C2, 0x0, 0x0}, 1},
+ {0x2FA07, {0x99FE, 0x0, 0x0}, 1},
+ {0x2FA08, {0x4BCE, 0x0, 0x0}, 1},
+ {0x2FA09, {0x29B30, 0x0, 0x0}, 1},
+ {0x2FA0A, {0x9B12, 0x0, 0x0}, 1},
+ {0x2FA0B, {0x9C40, 0x0, 0x0}, 1},
+ {0x2FA0C, {0x9CFD, 0x0, 0x0}, 1},
+ {0x2FA0D, {0x4CCE, 0x0, 0x0}, 1},
+ {0x2FA0E, {0x4CED, 0x0, 0x0}, 1},
+ {0x2FA0F, {0x9D67, 0x0, 0x0}, 1},
+ {0x2FA10, {0x2A0CE, 0x0, 0x0}, 1},
+ {0x2FA11, {0x4CF8, 0x0, 0x0}, 1},
+ {0x2FA12, {0x2A105, 0x0, 0x0}, 1},
+ {0x2FA13, {0x2A20E, 0x0, 0x0}, 1},
+ {0x2FA14, {0x2A291, 0x0, 0x0}, 1},
+ {0x2FA15, {0x9EBB, 0x0, 0x0}, 1},
+ {0x2FA16, {0x4D56, 0x0, 0x0}, 1},
+ {0x2FA17, {0x9EF9, 0x0, 0x0}, 1},
+ {0x2FA18, {0x9EFE, 0x0, 0x0}, 1},
+ {0x2FA19, {0x9F05, 0x0, 0x0}, 1},
+ {0x2FA1A, {0x9F0F, 0x0, 0x0}, 1},
+ {0x2FA1B, {0x9F16, 0x0, 0x0}, 1},
+ {0x2FA1C, {0x9F3B, 0x0, 0x0}, 1},
+ {0x2FA1D, {0x2A600, 0x0, 0x0}, 1},
+ {0xE0100, {0x0, 0x0, 0x0}, 0},
+ {0xE0101, {0x0, 0x0, 0x0}, 0},
+ {0xE0102, {0x0, 0x0, 0x0}, 0},
+ {0xE0103, {0x0, 0x0, 0x0}, 0},
+ {0xE0104, {0x0, 0x0, 0x0}, 0},
+ {0xE0105, {0x0, 0x0, 0x0}, 0},
+ {0xE0106, {0x0, 0x0, 0x0}, 0},
+ {0xE0107, {0x0, 0x0, 0x0}, 0},
+ {0xE0108, {0x0, 0x0, 0x0}, 0},
+ {0xE0109, {0x0, 0x0, 0x0}, 0},
+ {0xE010A, {0x0, 0x0, 0x0}, 0},
+ {0xE010B, {0x0, 0x0, 0x0}, 0},
+ {0xE010C, {0x0, 0x0, 0x0}, 0},
+ {0xE010D, {0x0, 0x0, 0x0}, 0},
+ {0xE010E, {0x0, 0x0, 0x0}, 0},
+ {0xE010F, {0x0, 0x0, 0x0}, 0},
+ {0xE0110, {0x0, 0x0, 0x0}, 0},
+ {0xE0111, {0x0, 0x0, 0x0}, 0},
+ {0xE0112, {0x0, 0x0, 0x0}, 0},
+ {0xE0113, {0x0, 0x0, 0x0}, 0},
+ {0xE0114, {0x0, 0x0, 0x0}, 0},
+ {0xE0115, {0x0, 0x0, 0x0}, 0},
+ {0xE0116, {0x0, 0x0, 0x0}, 0},
+ {0xE0117, {0x0, 0x0, 0x0}, 0},
+ {0xE0118, {0x0, 0x0, 0x0}, 0},
+ {0xE0119, {0x0, 0x0, 0x0}, 0},
+ {0xE011A, {0x0, 0x0, 0x0}, 0},
+ {0xE011B, {0x0, 0x0, 0x0}, 0},
+ {0xE011C, {0x0, 0x0, 0x0}, 0},
+ {0xE011D, {0x0, 0x0, 0x0}, 0},
+ {0xE011E, {0x0, 0x0, 0x0}, 0},
+ {0xE011F, {0x0, 0x0, 0x0}, 0},
+ {0xE0120, {0x0, 0x0, 0x0}, 0},
+ {0xE0121, {0x0, 0x0, 0x0}, 0},
+ {0xE0122, {0x0, 0x0, 0x0}, 0},
+ {0xE0123, {0x0, 0x0, 0x0}, 0},
+ {0xE0124, {0x0, 0x0, 0x0}, 0},
+ {0xE0125, {0x0, 0x0, 0x0}, 0},
+ {0xE0126, {0x0, 0x0, 0x0}, 0},
+ {0xE0127, {0x0, 0x0, 0x0}, 0},
+ {0xE0128, {0x0, 0x0, 0x0}, 0},
+ {0xE0129, {0x0, 0x0, 0x0}, 0},
+ {0xE012A, {0x0, 0x0, 0x0}, 0},
+ {0xE012B, {0x0, 0x0, 0x0}, 0},
+ {0xE012C, {0x0, 0x0, 0x0}, 0},
+ {0xE012D, {0x0, 0x0, 0x0}, 0},
+ {0xE012E, {0x0, 0x0, 0x0}, 0},
+ {0xE012F, {0x0, 0x0, 0x0}, 0},
+ {0xE0130, {0x0, 0x0, 0x0}, 0},
+ {0xE0131, {0x0, 0x0, 0x0}, 0},
+ {0xE0132, {0x0, 0x0, 0x0}, 0},
+ {0xE0133, {0x0, 0x0, 0x0}, 0},
+ {0xE0134, {0x0, 0x0, 0x0}, 0},
+ {0xE0135, {0x0, 0x0, 0x0}, 0},
+ {0xE0136, {0x0, 0x0, 0x0}, 0},
+ {0xE0137, {0x0, 0x0, 0x0}, 0},
+ {0xE0138, {0x0, 0x0, 0x0}, 0},
+ {0xE0139, {0x0, 0x0, 0x0}, 0},
+ {0xE013A, {0x0, 0x0, 0x0}, 0},
+ {0xE013B, {0x0, 0x0, 0x0}, 0},
+ {0xE013C, {0x0, 0x0, 0x0}, 0},
+ {0xE013D, {0x0, 0x0, 0x0}, 0},
+ {0xE013E, {0x0, 0x0, 0x0}, 0},
+ {0xE013F, {0x0, 0x0, 0x0}, 0},
+ {0xE0140, {0x0, 0x0, 0x0}, 0},
+ {0xE0141, {0x0, 0x0, 0x0}, 0},
+ {0xE0142, {0x0, 0x0, 0x0}, 0},
+ {0xE0143, {0x0, 0x0, 0x0}, 0},
+ {0xE0144, {0x0, 0x0, 0x0}, 0},
+ {0xE0145, {0x0, 0x0, 0x0}, 0},
+ {0xE0146, {0x0, 0x0, 0x0}, 0},
+ {0xE0147, {0x0, 0x0, 0x0}, 0},
+ {0xE0148, {0x0, 0x0, 0x0}, 0},
+ {0xE0149, {0x0, 0x0, 0x0}, 0},
+ {0xE014A, {0x0, 0x0, 0x0}, 0},
+ {0xE014B, {0x0, 0x0, 0x0}, 0},
+ {0xE014C, {0x0, 0x0, 0x0}, 0},
+ {0xE014D, {0x0, 0x0, 0x0}, 0},
+ {0xE014E, {0x0, 0x0, 0x0}, 0},
+ {0xE014F, {0x0, 0x0, 0x0}, 0},
+ {0xE0150, {0x0, 0x0, 0x0}, 0},
+ {0xE0151, {0x0, 0x0, 0x0}, 0},
+ {0xE0152, {0x0, 0x0, 0x0}, 0},
+ {0xE0153, {0x0, 0x0, 0x0}, 0},
+ {0xE0154, {0x0, 0x0, 0x0}, 0},
+ {0xE0155, {0x0, 0x0, 0x0}, 0},
+ {0xE0156, {0x0, 0x0, 0x0}, 0},
+ {0xE0157, {0x0, 0x0, 0x0}, 0},
+ {0xE0158, {0x0, 0x0, 0x0}, 0},
+ {0xE0159, {0x0, 0x0, 0x0}, 0},
+ {0xE015A, {0x0, 0x0, 0x0}, 0},
+ {0xE015B, {0x0, 0x0, 0x0}, 0},
+ {0xE015C, {0x0, 0x0, 0x0}, 0},
+ {0xE015D, {0x0, 0x0, 0x0}, 0},
+ {0xE015E, {0x0, 0x0, 0x0}, 0},
+ {0xE015F, {0x0, 0x0, 0x0}, 0},
+ {0xE0160, {0x0, 0x0, 0x0}, 0},
+ {0xE0161, {0x0, 0x0, 0x0}, 0},
+ {0xE0162, {0x0, 0x0, 0x0}, 0},
+ {0xE0163, {0x0, 0x0, 0x0}, 0},
+ {0xE0164, {0x0, 0x0, 0x0}, 0},
+ {0xE0165, {0x0, 0x0, 0x0}, 0},
+ {0xE0166, {0x0, 0x0, 0x0}, 0},
+ {0xE0167, {0x0, 0x0, 0x0}, 0},
+ {0xE0168, {0x0, 0x0, 0x0}, 0},
+ {0xE0169, {0x0, 0x0, 0x0}, 0},
+ {0xE016A, {0x0, 0x0, 0x0}, 0},
+ {0xE016B, {0x0, 0x0, 0x0}, 0},
+ {0xE016C, {0x0, 0x0, 0x0}, 0},
+ {0xE016D, {0x0, 0x0, 0x0}, 0},
+ {0xE016E, {0x0, 0x0, 0x0}, 0},
+ {0xE016F, {0x0, 0x0, 0x0}, 0},
+ {0xE0170, {0x0, 0x0, 0x0}, 0},
+ {0xE0171, {0x0, 0x0, 0x0}, 0},
+ {0xE0172, {0x0, 0x0, 0x0}, 0},
+ {0xE0173, {0x0, 0x0, 0x0}, 0},
+ {0xE0174, {0x0, 0x0, 0x0}, 0},
+ {0xE0175, {0x0, 0x0, 0x0}, 0},
+ {0xE0176, {0x0, 0x0, 0x0}, 0},
+ {0xE0177, {0x0, 0x0, 0x0}, 0},
+ {0xE0178, {0x0, 0x0, 0x0}, 0},
+ {0xE0179, {0x0, 0x0, 0x0}, 0},
+ {0xE017A, {0x0, 0x0, 0x0}, 0},
+ {0xE017B, {0x0, 0x0, 0x0}, 0},
+ {0xE017C, {0x0, 0x0, 0x0}, 0},
+ {0xE017D, {0x0, 0x0, 0x0}, 0},
+ {0xE017E, {0x0, 0x0, 0x0}, 0},
+ {0xE017F, {0x0, 0x0, 0x0}, 0},
+ {0xE0180, {0x0, 0x0, 0x0}, 0},
+ {0xE0181, {0x0, 0x0, 0x0}, 0},
+ {0xE0182, {0x0, 0x0, 0x0}, 0},
+ {0xE0183, {0x0, 0x0, 0x0}, 0},
+ {0xE0184, {0x0, 0x0, 0x0}, 0},
+ {0xE0185, {0x0, 0x0, 0x0}, 0},
+ {0xE0186, {0x0, 0x0, 0x0}, 0},
+ {0xE0187, {0x0, 0x0, 0x0}, 0},
+ {0xE0188, {0x0, 0x0, 0x0}, 0},
+ {0xE0189, {0x0, 0x0, 0x0}, 0},
+ {0xE018A, {0x0, 0x0, 0x0}, 0},
+ {0xE018B, {0x0, 0x0, 0x0}, 0},
+ {0xE018C, {0x0, 0x0, 0x0}, 0},
+ {0xE018D, {0x0, 0x0, 0x0}, 0},
+ {0xE018E, {0x0, 0x0, 0x0}, 0},
+ {0xE018F, {0x0, 0x0, 0x0}, 0},
+ {0xE0190, {0x0, 0x0, 0x0}, 0},
+ {0xE0191, {0x0, 0x0, 0x0}, 0},
+ {0xE0192, {0x0, 0x0, 0x0}, 0},
+ {0xE0193, {0x0, 0x0, 0x0}, 0},
+ {0xE0194, {0x0, 0x0, 0x0}, 0},
+ {0xE0195, {0x0, 0x0, 0x0}, 0},
+ {0xE0196, {0x0, 0x0, 0x0}, 0},
+ {0xE0197, {0x0, 0x0, 0x0}, 0},
+ {0xE0198, {0x0, 0x0, 0x0}, 0},
+ {0xE0199, {0x0, 0x0, 0x0}, 0},
+ {0xE019A, {0x0, 0x0, 0x0}, 0},
+ {0xE019B, {0x0, 0x0, 0x0}, 0},
+ {0xE019C, {0x0, 0x0, 0x0}, 0},
+ {0xE019D, {0x0, 0x0, 0x0}, 0},
+ {0xE019E, {0x0, 0x0, 0x0}, 0},
+ {0xE019F, {0x0, 0x0, 0x0}, 0},
+ {0xE01A0, {0x0, 0x0, 0x0}, 0},
+ {0xE01A1, {0x0, 0x0, 0x0}, 0},
+ {0xE01A2, {0x0, 0x0, 0x0}, 0},
+ {0xE01A3, {0x0, 0x0, 0x0}, 0},
+ {0xE01A4, {0x0, 0x0, 0x0}, 0},
+ {0xE01A5, {0x0, 0x0, 0x0}, 0},
+ {0xE01A6, {0x0, 0x0, 0x0}, 0},
+ {0xE01A7, {0x0, 0x0, 0x0}, 0},
+ {0xE01A8, {0x0, 0x0, 0x0}, 0},
+ {0xE01A9, {0x0, 0x0, 0x0}, 0},
+ {0xE01AA, {0x0, 0x0, 0x0}, 0},
+ {0xE01AB, {0x0, 0x0, 0x0}, 0},
+ {0xE01AC, {0x0, 0x0, 0x0}, 0},
+ {0xE01AD, {0x0, 0x0, 0x0}, 0},
+ {0xE01AE, {0x0, 0x0, 0x0}, 0},
+ {0xE01AF, {0x0, 0x0, 0x0}, 0},
+ {0xE01B0, {0x0, 0x0, 0x0}, 0},
+ {0xE01B1, {0x0, 0x0, 0x0}, 0},
+ {0xE01B2, {0x0, 0x0, 0x0}, 0},
+ {0xE01B3, {0x0, 0x0, 0x0}, 0},
+ {0xE01B4, {0x0, 0x0, 0x0}, 0},
+ {0xE01B5, {0x0, 0x0, 0x0}, 0},
+ {0xE01B6, {0x0, 0x0, 0x0}, 0},
+ {0xE01B7, {0x0, 0x0, 0x0}, 0},
+ {0xE01B8, {0x0, 0x0, 0x0}, 0},
+ {0xE01B9, {0x0, 0x0, 0x0}, 0},
+ {0xE01BA, {0x0, 0x0, 0x0}, 0},
+ {0xE01BB, {0x0, 0x0, 0x0}, 0},
+ {0xE01BC, {0x0, 0x0, 0x0}, 0},
+ {0xE01BD, {0x0, 0x0, 0x0}, 0},
+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E01E0, {0x0, 0x0, 0x0}, 0},
+ {0xE01E1, {0x0, 0x0, 0x0}, 0},
+ {0xE01E2, {0x0, 0x0, 0x0}, 0},
+ {0xE01E3, {0x0, 0x0, 0x0}, 0},
+ {0xE01E4, {0x0, 0x0, 0x0}, 0},
+ {0xE01E5, {0x0, 0x0, 0x0}, 0},
+ {0xE01E6, {0x0, 0x0, 0x0}, 0},
+ {0xE01E7, {0x0, 0x0, 0x0}, 0},
+ {0xE01E8, {0x0, 0x0, 0x0}, 0},
+ {0xE01E9, {0x0, 0x0, 0x0}, 0},
+ {0xE01EA, {0x0, 0x0, 0x0}, 0},
+ {0xE01EB, {0x0, 0x0, 0x0}, 0},
+ {0xE01EC, {0x0, 0x0, 0x0}, 0},
+ {0xE01ED, {0x0, 0x0, 0x0}, 0},
+ {0xE01EE, {0x0, 0x0, 0x0}, 0},
+ {0xE01EF, {0x0, 0x0, 0x0}, 0},
+};
+enum { WP_FOLD_N = (int)(sizeof(WP_FOLD) / sizeof(WP_FOLD[0])) };
+
+#endif /* WORDPIECE_UNICODE_H */
diff --git a/libffwd/vec.c b/libffwd/vec.c
new file mode 100644
index 0000000..ec6b27d
--- /dev/null
+++ b/libffwd/vec.c
@@ -0,0 +1,47 @@
+#include "ffwd.h"
+
+#include <math.h>
+
+/* Vector helpers */
+
+int ffwd_l2_normalize(float *vec, int dim) {
+ if (!vec || dim <= 0)
+ return -1;
+
+ float norm_sq = 0.0f;
+ for (int i = 0; i < dim; i++)
+ norm_sq += vec[i] * vec[i];
+
+ if (!(norm_sq > 0.0f) || !isfinite(norm_sq))
+ return -1;
+
+ float inv_norm = 1.0f / sqrtf(norm_sq);
+ for (int i = 0; i < dim; i++)
+ vec[i] *= inv_norm;
+ return 0;
+}
+
+float ffwd_cosine_similarity(const float *a, const float *b, int dim) {
+ if (!a || !b || dim <= 0)
+ return 0.0f;
+
+ float dot = 0.0f;
+ float norm_a_sq = 0.0f;
+ float norm_b_sq = 0.0f;
+ for (int i = 0; i < dim; i++) {
+ float av = a[i];
+ float bv = b[i];
+ dot += av * bv;
+ norm_a_sq += av * av;
+ norm_b_sq += bv * bv;
+ }
+
+ if (!(norm_a_sq > 0.0f) || !(norm_b_sq > 0.0f) || !isfinite(norm_a_sq) || !isfinite(norm_b_sq) ||
+ !isfinite(dot))
+ return 0.0f;
+
+ double denom = sqrt((double)norm_a_sq) * sqrt((double)norm_b_sq);
+ if (!(denom > 0.0) || !isfinite(denom))
+ return 0.0f;
+ return (float)((double)dot / denom);
+}
diff --git a/libffwd/wordpiece.c b/libffwd/wordpiece.c
new file mode 100644
index 0000000..dc0d995
--- /dev/null
+++ b/libffwd/wordpiece.c
@@ -0,0 +1,679 @@
+/*
+ * BERT-family WordPiece tokenizer.
+ *
+ * Pipeline matching transformers' BertTokenizer:
+ * BasicTokenizer: clean control/whitespace -> space CJK ideographs ->
+ * whitespace split -> lowercase + strip accents, if enabled ->
+ * split on punctuation.
+ * WordPiece: greedy longest-match-first against vocab.txt, with continuation
+ * pieces marked "##". If any piece fails, the whole token becomes [UNK].
+ *
+ * Unicode handling fully matches transformers using generated tables
+ * (unicode.h): Unicode category for punctuation/control, full Zs set for
+ * whitespace, BERT ideograph ranges for CJK splitting, and a lowercase + NFD +
+ * strip-marks table for do_lower_case, with Hangul decomposed by formula.
+ *
+ * Cased and uncased multilingual encoders, such as
+ * bert-base-multilingual-cased / -uncased, match Hugging Face exactly,
+ * including Greek, Cyrillic, Vietnamese, and Korean.
+ *
+ * Folding is per-codepoint, matching transformers, which lowercases one
+ * character at a time, with no context-sensitive Greek final sigma.
+ */
+
+#include "wordpiece.h"
+
+#include "unicode.h"
+
+#include <stdint.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+/* string -> int open-addressing map */
+
+typedef struct {
+ const char *key; /* points into tok->id_to_token; not owned */
+ int val;
+} wp_entry_t;
+
+static uint64_t fnv1a_hash(const char *s) {
+ uint64_t h = 1469598103934665603ULL;
+ for (const unsigned char *p = (const unsigned char *)s; *p; p++) {
+ h ^= (uint64_t)*p;
+ h *= 1099511628211ULL;
+ }
+ return h;
+}
+
+static int next_pow2(int x) {
+ int p = 1;
+ while (p < x)
+ p <<= 1;
+ return p;
+}
+
+static void map_put(wp_entry_t *map, int cap, const char *key, int val) {
+ uint64_t mask = (uint64_t)cap - 1;
+ int pos = (int)(fnv1a_hash(key) & mask);
+ while (map[pos].key) {
+ if (!strcmp(map[pos].key, key)) {
+ map[pos].val = val; /* keep the first/lowest id, like a dict insert */
+ return;
+ }
+ pos = (int)((pos + 1) & (int)mask);
+ }
+ map[pos].key = key;
+ map[pos].val = val;
+}
+
+static int map_get(const wp_entry_t *map, int cap, const char *key) {
+ if (!map)
+ return -1;
+ uint64_t mask = (uint64_t)cap - 1;
+ int pos = (int)(fnv1a_hash(key) & mask);
+ while (map[pos].key) {
+ if (!strcmp(map[pos].key, key))
+ return map[pos].val;
+ pos = (int)((pos + 1) & (int)mask);
+ }
+ return -1;
+}
+
+/* UTF-8 helpers */
+
+/* Decode one codepoint. Returns bytes consumed (>=1).
+ * On malformed lead byte, emits U+FFFD and consumes one byte so iteration advances. */
+static int utf8_decode(const unsigned char *p, const unsigned char *end, uint32_t *cp) {
+ unsigned char c = p[0];
+ if (c < 0x80) {
+ *cp = c;
+ return 1;
+ }
+ int n;
+ uint32_t v;
+ if ((c & 0xE0) == 0xC0) {
+ n = 2;
+ v = c & 0x1F;
+ } else if ((c & 0xF0) == 0xE0) {
+ n = 3;
+ v = c & 0x0F;
+ } else if ((c & 0xF8) == 0xF0) {
+ n = 4;
+ v = c & 0x07;
+ } else {
+ *cp = 0xFFFD;
+ return 1;
+ }
+ if (p + n > end) {
+ *cp = 0xFFFD;
+ return 1;
+ }
+ for (int i = 1; i < n; i++) {
+ if ((p[i] & 0xC0) != 0x80) {
+ *cp = 0xFFFD;
+ return 1;
+ }
+ v = (v << 6) | (p[i] & 0x3F);
+ }
+ *cp = v;
+ return n;
+}
+
+static int utf8_encode(uint32_t cp, char out[4]) {
+ if (cp < 0x80) {
+ out[0] = (char)cp;
+ return 1;
+ }
+ if (cp < 0x800) {
+ out[0] = (char)(0xC0 | (cp >> 6));
+ out[1] = (char)(0x80 | (cp & 0x3F));
+ return 2;
+ }
+ if (cp < 0x10000) {
+ out[0] = (char)(0xE0 | (cp >> 12));
+ out[1] = (char)(0x80 | ((cp >> 6) & 0x3F));
+ out[2] = (char)(0x80 | (cp & 0x3F));
+ return 3;
+ }
+ out[0] = (char)(0xF0 | (cp >> 18));
+ out[1] = (char)(0x80 | ((cp >> 12) & 0x3F));
+ out[2] = (char)(0x80 | ((cp >> 6) & 0x3F));
+ out[3] = (char)(0x80 | (cp & 0x3F));
+ return 4;
+}
+
+/* Unicode classification */
+
+static int wp_is_whitespace(uint32_t cp) {
+ if (cp == ' ' || cp == '\t' || cp == '\n' || cp == '\r')
+ return 1;
+ return cp == 0x00A0 || cp == 0x1680 || (cp >= 0x2000 && cp <= 0x200A) || cp == 0x2028 ||
+ cp == 0x2029 || cp == 0x202F || cp == 0x205F || cp == 0x3000;
+}
+
+/* Binary search a sorted, non-overlapping [lo, hi] range table. */
+static int wp_in_ranges(uint32_t cp, const wp_range_t *r, int n) {
+ int lo = 0, hi = n - 1;
+ while (lo <= hi) {
+ int mid = (lo + hi) >> 1;
+ if (cp < r[mid].lo)
+ hi = mid - 1;
+ else if (cp > r[mid].hi)
+ lo = mid + 1;
+ else
+ return 1;
+ }
+ return 0;
+}
+
+/* Match transformers' _is_control:
+ * tab/newline/carriage-return are whitespace, not control, and fall through to
+ * wp_is_whitespace; everything else is Unicode category Cc, Cf, or Co. */
+static int wp_is_control(uint32_t cp) {
+ if (cp == '\t' || cp == '\n' || cp == '\r')
+ return 0;
+ return wp_in_ranges(cp, WP_CONTROL_RANGES, WP_CONTROL_RANGES_N);
+}
+
+/* transformers' _is_punctuation: the ASCII non-alphanumeric set plus every
+ * Unicode category P* codepoint, both folded into the generated table. */
+static int wp_is_punct(uint32_t cp) { return wp_in_ranges(cp, WP_PUNCT_RANGES, WP_PUNCT_RANGES_N); }
+
+static int wp_is_cjk(uint32_t cp) {
+ return (cp >= 0x4E00 && cp <= 0x9FFF) || (cp >= 0x3400 && cp <= 0x4DBF) ||
+ (cp >= 0x20000 && cp <= 0x2A6DF) || (cp >= 0x2A700 && cp <= 0x2B73F) ||
+ (cp >= 0x2B740 && cp <= 0x2B81F) || (cp >= 0x2B820 && cp <= 0x2CEAF) ||
+ (cp >= 0xF900 && cp <= 0xFAFF) || (cp >= 0x2F800 && cp <= 0x2FA1F);
+}
+
+/* Hangul syllable decomposition constants for the standard algorithm.
+ * Hangul syllables are not cased, so their do_lower_case fold is canonical NFD:
+ * leading (L), vowel (V), and optional trailing (T) jamo.
+ * None are combining marks, so they stay out of the generated WP_FOLD table. */
+enum {
+ WP_HANGUL_S = 0xAC00,
+ WP_HANGUL_L = 0x1100,
+ WP_HANGUL_V = 0x1161,
+ WP_HANGUL_T = 0x11A7,
+ WP_HANGUL_TCOUNT = 28,
+ WP_HANGUL_NCOUNT = 588,
+ WP_HANGUL_SCOUNT = 11172
+};
+
+/* Apply do_lower_case to one codepoint:
+ * lowercase using Python-compatible str.lower behavior, then NFD,
+ * then drop combining marks.
+ * Writes 0..3 output codepoints to out and the count to *n_out.
+ * 0 outputs means the codepoint was a dropped mark.
+ * Hangul decomposes by formula; all else uses WP_FOLD or identity. */
+static void wp_fold(uint32_t cp, uint32_t out[3], int *n_out) {
+ if (cp >= WP_HANGUL_S && cp < WP_HANGUL_S + WP_HANGUL_SCOUNT) {
+ int s = (int)(cp - WP_HANGUL_S);
+ out[0] = (uint32_t)(WP_HANGUL_L + s / WP_HANGUL_NCOUNT);
+ out[1] = (uint32_t)(WP_HANGUL_V + (s % WP_HANGUL_NCOUNT) / WP_HANGUL_TCOUNT);
+ int t = s % WP_HANGUL_TCOUNT;
+ if (t == 0) {
+ *n_out = 2;
+ } else {
+ out[2] = (uint32_t)(WP_HANGUL_T + t);
+ *n_out = 3;
+ }
+ return;
+ }
+ int lo = 0, hi = WP_FOLD_N - 1;
+ while (lo <= hi) {
+ int mid = (lo + hi) >> 1;
+ if (cp < WP_FOLD[mid].cp) {
+ hi = mid - 1;
+ } else if (cp > WP_FOLD[mid].cp) {
+ lo = mid + 1;
+ } else {
+ int n = WP_FOLD[mid].n;
+ for (int i = 0; i < n; i++)
+ out[i] = WP_FOLD[mid].out[i];
+ *n_out = n;
+ return;
+ }
+ }
+ out[0] = cp;
+ *n_out = 1;
+}
+
+/* workspace */
+
+struct tok_wp_workspace {
+ uint32_t *cps; /* cleaned + CJK-spaced codepoints of the whole input */
+ int cps_cap;
+ uint32_t *norm; /* one word's normalized codepoints */
+ int norm_cap;
+ char *wbuf; /* one sub-word's UTF-8 bytes */
+ int wbuf_cap;
+ int *boff; /* byte offset of each codepoint within wbuf (+1 sentinel) */
+ int boff_cap;
+ char *look; /* "##" + candidate substring, for vocab lookup */
+ int look_cap;
+ int *ids; /* output ids */
+ int ids_cap;
+};
+
+static int grow_u32(uint32_t **buf, int *cap, int need) {
+ if (*cap >= need)
+ return 0;
+ int n = *cap ? *cap : 64;
+ while (n < need)
+ n *= 2;
+ uint32_t *p = (uint32_t *)realloc(*buf, (size_t)n * sizeof(uint32_t));
+ if (!p)
+ return -1;
+ *buf = p;
+ *cap = n;
+ return 0;
+}
+
+static int grow_int(int **buf, int *cap, int need) {
+ if (*cap >= need)
+ return 0;
+ int n = *cap ? *cap : 64;
+ while (n < need)
+ n *= 2;
+ int *p = (int *)realloc(*buf, (size_t)n * sizeof(int));
+ if (!p)
+ return -1;
+ *buf = p;
+ *cap = n;
+ return 0;
+}
+
+static int grow_char(char **buf, int *cap, int need) {
+ if (*cap >= need)
+ return 0;
+ int n = *cap ? *cap : 256;
+ while (n < need)
+ n *= 2;
+ char *p = (char *)realloc(*buf, (size_t)n);
+ if (!p)
+ return -1;
+ *buf = p;
+ *cap = n;
+ return 0;
+}
+
+tok_wp_workspace_t *tok_wp_workspace_new(void) {
+ return (tok_wp_workspace_t *)calloc(1, sizeof(tok_wp_workspace_t));
+}
+
+void tok_wp_workspace_free(tok_wp_workspace_t *ws) {
+ if (!ws)
+ return;
+ free(ws->cps);
+ free(ws->norm);
+ free(ws->wbuf);
+ free(ws->boff);
+ free(ws->look);
+ free(ws->ids);
+ free(ws);
+}
+
+/* WordPiece core */
+
+/* Append the WordPiece ids of one BasicTokenizer sub-word (codepoints
+ * word[0..n)) to ws->ids[*n_out]. The whole sub-word maps to [UNK] when it is
+ * too long or any greedy piece misses the vocab. Returns 0 / -1 on OOM. */
+static int
+tok_wp_subword(const tok_wp_t *tok, tok_wp_workspace_t *ws, const uint32_t *word, int n, int *n_out) {
+ if (n == 0)
+ return 0;
+ if (n > tok->max_chars_per_word) {
+ if (grow_int(&ws->ids, &ws->ids_cap, *n_out + 1) != 0)
+ return -1;
+ ws->ids[(*n_out)++] = tok->unk_id;
+ return 0;
+ }
+
+ /* Materialize the sub-word as UTF-8 with per-codepoint byte offsets. */
+ if (grow_int(&ws->boff, &ws->boff_cap, n + 1) != 0 ||
+ grow_char(&ws->wbuf, &ws->wbuf_cap, n * 4 + 1) != 0)
+ return -1;
+ int bytes = 0;
+ for (int i = 0; i < n; i++) {
+ ws->boff[i] = bytes;
+ bytes += utf8_encode(word[i], ws->wbuf + bytes);
+ }
+ ws->boff[n] = bytes;
+
+ int start_count = *n_out;
+ int start = 0;
+ int bad = 0;
+ while (start < n) {
+ int end = n;
+ int matched = -1;
+ int matched_end = start;
+ while (start < end) {
+ int seg = ws->boff[end] - ws->boff[start];
+ int lp = 0;
+ if (grow_char(&ws->look, &ws->look_cap, seg + 3) != 0)
+ return -1;
+ if (start > 0) {
+ ws->look[lp++] = '#';
+ ws->look[lp++] = '#';
+ }
+ memcpy(ws->look + lp, ws->wbuf + ws->boff[start], (size_t)seg);
+ ws->look[lp + seg] = '\0';
+ int id = map_get((const wp_entry_t *)tok->vocab_map, tok->vocab_map_cap, ws->look);
+ if (id >= 0) {
+ matched = id;
+ matched_end = end;
+ break;
+ }
+ end--;
+ }
+ if (matched < 0) {
+ bad = 1;
+ break;
+ }
+ if (grow_int(&ws->ids, &ws->ids_cap, *n_out + 1) != 0)
+ return -1;
+ ws->ids[(*n_out)++] = matched;
+ start = matched_end;
+ }
+ if (bad) {
+ *n_out = start_count; /* discard partial pieces; emit one [UNK] */
+ if (grow_int(&ws->ids, &ws->ids_cap, *n_out + 1) != 0)
+ return -1;
+ ws->ids[(*n_out)++] = tok->unk_id;
+ }
+ return 0;
+}
+
+/* Run the full BasicTokenizer + WordPiece pipeline into ws->ids.
+ * Returns the token count, or -1 on allocation failure. */
+static int tok_wp_run(const tok_wp_t *tok, tok_wp_workspace_t *ws, const char *text) {
+ /* clean_text + tokenize_chinese_chars, in one pass over the input. */
+ const unsigned char *p = (const unsigned char *)text;
+ const unsigned char *end = p + strlen(text);
+ int n_cps = 0;
+ while (p < end) {
+ uint32_t cp;
+ p += utf8_decode(p, end, &cp);
+ if (cp == 0 || cp == 0xFFFD || wp_is_control(cp))
+ continue;
+ if (wp_is_whitespace(cp)) {
+ if (grow_u32(&ws->cps, &ws->cps_cap, n_cps + 1) != 0)
+ return -1;
+ ws->cps[n_cps++] = ' ';
+ continue;
+ }
+ int extra = wp_is_cjk(cp) ? 3 : 1;
+ if (grow_u32(&ws->cps, &ws->cps_cap, n_cps + extra) != 0)
+ return -1;
+ if (extra == 3) {
+ ws->cps[n_cps++] = ' ';
+ ws->cps[n_cps++] = cp;
+ ws->cps[n_cps++] = ' ';
+ } else {
+ ws->cps[n_cps++] = cp;
+ }
+ }
+
+ int n_out = 0;
+ int i = 0;
+ while (i < n_cps) {
+ if (ws->cps[i] == ' ') {
+ i++;
+ continue;
+ }
+ int wstart = i;
+ while (i < n_cps && ws->cps[i] != ' ')
+ i++;
+ int wlen = i - wstart;
+
+ /* lowercase + strip accents; the fold can drop a codepoint (combining
+ * mark) or expand it to up to 3 (Hangul, a few ligatures). */
+ int m = 0;
+ if (grow_u32(&ws->norm, &ws->norm_cap, tok->do_lower_case ? wlen * 3 : wlen) != 0)
+ return -1;
+ for (int k = 0; k < wlen; k++) {
+ uint32_t cp = ws->cps[wstart + k];
+ if (tok->do_lower_case) {
+ uint32_t out[3];
+ int no = 0;
+ wp_fold(cp, out, &no);
+ for (int j = 0; j < no; j++)
+ ws->norm[m++] = out[j];
+ } else {
+ ws->norm[m++] = cp;
+ }
+ }
+
+ /* split_on_punc, then WordPiece each piece. */
+ int run = 0;
+ for (int k = 0; k < m; k++) {
+ if (wp_is_punct(ws->norm[k])) {
+ if (run > 0 && tok_wp_subword(tok, ws, ws->norm + (k - run), run, &n_out) != 0)
+ return -1;
+ run = 0;
+ if (tok_wp_subword(tok, ws, ws->norm + k, 1, &n_out) != 0)
+ return -1;
+ } else {
+ run++;
+ }
+ }
+ if (run > 0 && tok_wp_subword(tok, ws, ws->norm + (m - run), run, &n_out) != 0)
+ return -1;
+ }
+ return n_out;
+}
+
+/* loading */
+
+static char *read_file(const char *path, long *out_len) {
+ FILE *f = fopen(path, "rb");
+ if (!f)
+ return NULL;
+ if (fseek(f, 0, SEEK_END) != 0) {
+ fclose(f);
+ return NULL;
+ }
+ long len = ftell(f);
+ if (len < 0 || fseek(f, 0, SEEK_SET) != 0) {
+ fclose(f);
+ return NULL;
+ }
+ char *buf = (char *)malloc((size_t)len + 1);
+ if (!buf) {
+ fclose(f);
+ return NULL;
+ }
+ size_t rd = fread(buf, 1, (size_t)len, f);
+ fclose(f);
+ if (rd != (size_t)len) {
+ free(buf);
+ return NULL;
+ }
+ buf[len] = '\0';
+ if (out_len)
+ *out_len = len;
+ return buf;
+}
+
+/* do_lower_case from config.json: default true (BERT uncased). A
+ * lightweight scan is enough; we only need one boolean and avoid a JSON dep
+ * here, mirroring how the config layer reads small flags. */
+static int read_do_lower_case(const char *model_dir) {
+ char path[2048];
+ snprintf(path, sizeof(path), "%s/tokenizer_config.json", model_dir);
+ char *buf = read_file(path, NULL);
+ if (!buf)
+ return 1;
+ int result = 1;
+ const char *k = strstr(buf, "\"do_lower_case\"");
+ if (k) {
+ const char *c = strchr(k, ':');
+ if (c) {
+ c++;
+ while (*c == ' ' || *c == '\t' || *c == '\n' || *c == '\r')
+ c++;
+ if (!strncmp(c, "false", 5))
+ result = 0;
+ }
+ }
+ free(buf);
+ return result;
+}
+
+tok_wp_t *tok_wp_load(const char *model_dir) {
+ if (!model_dir)
+ return NULL;
+ char path[2048];
+ snprintf(path, sizeof(path), "%s/vocab.txt", model_dir);
+ long len = 0;
+ char *buf = read_file(path, &len);
+ if (!buf) {
+ fprintf(stderr, "wordpiece: cannot read %s\n", path);
+ return NULL;
+ }
+
+ /* Count lines (one token each); a single trailing newline adds no token. */
+ int count = 0;
+ for (long i = 0; i < len; i++)
+ if (buf[i] == '\n')
+ count++;
+ if (len > 0 && buf[len - 1] != '\n')
+ count++;
+
+ tok_wp_t *tok = (tok_wp_t *)calloc(1, sizeof(*tok));
+ char **id_to_token = (char **)calloc((size_t)(count > 0 ? count : 1), sizeof(char *));
+ if (!tok || !id_to_token) {
+ free(buf);
+ free(tok);
+ free(id_to_token);
+ return NULL;
+ }
+
+ int n = 0;
+ char *line = buf;
+ for (long i = 0; i <= len && n < count; i++) {
+ if (i == len || buf[i] == '\n') {
+ char *e = buf + i;
+ if (e > line && e[-1] == '\r')
+ e[-1] = '\0';
+ else
+ *e = '\0';
+ id_to_token[n] = strdup(line);
+ if (!id_to_token[n]) {
+ for (int j = 0; j < n; j++)
+ free(id_to_token[j]);
+ free(id_to_token);
+ free(tok);
+ free(buf);
+ return NULL;
+ }
+ n++;
+ line = buf + i + 1;
+ }
+ }
+ free(buf);
+
+ tok->id_to_token = id_to_token;
+ tok->vocab_size = n;
+ tok->do_lower_case = read_do_lower_case(model_dir);
+ tok->max_chars_per_word = 100;
+
+ int cap = next_pow2(n * 2 < 16 ? 16 : n * 2);
+ wp_entry_t *map = (wp_entry_t *)calloc((size_t)cap, sizeof(wp_entry_t));
+ if (!map) {
+ tok_wp_free(tok);
+ return NULL;
+ }
+ for (int i = 0; i < n; i++)
+ map_put(map, cap, id_to_token[i], i);
+ tok->vocab_map = map;
+ tok->vocab_map_cap = cap;
+
+ tok->unk_id = map_get(map, cap, "[UNK]");
+ if (tok->unk_id < 0) {
+ fprintf(stderr, "wordpiece: vocab.txt has no [UNK] token\n");
+ tok_wp_free(tok);
+ return NULL;
+ }
+ return tok;
+}
+
+/* public API*/
+
+const char *tok_wp_decode(const tok_wp_t *tok, int id) {
+ if (!tok || id < 0 || id >= tok->vocab_size)
+ return NULL;
+ return tok->id_to_token[id];
+}
+
+int tok_wp_token_id(const tok_wp_t *tok, const char *token) {
+ if (!tok || !token)
+ return -1;
+ return map_get((const wp_entry_t *)tok->vocab_map, tok->vocab_map_cap, token);
+}
+
+int tok_wp_encode_into(const tok_wp_t *tok,
+ tok_wp_workspace_t *ws,
+ const char *text,
+ int *out_ids,
+ int out_cap,
+ int *out_n_tokens) {
+ if (out_n_tokens)
+ *out_n_tokens = 0;
+ if (!tok || !ws || !text)
+ return -1;
+ int n = tok_wp_run(tok, ws, text);
+ if (n < 0)
+ return -1;
+ if (out_n_tokens)
+ *out_n_tokens = n;
+ if (!out_ids || out_cap < n)
+ return out_ids ? -2 : -1;
+ memcpy(out_ids, ws->ids, (size_t)n * sizeof(int));
+ return 0;
+}
+
+int *tok_wp_encode_with_workspace(const tok_wp_t *tok,
+ tok_wp_workspace_t *ws,
+ const char *text,
+ int *out_n_tokens) {
+ if (out_n_tokens)
+ *out_n_tokens = 0;
+ if (!tok || !ws || !text)
+ return NULL;
+ int n = tok_wp_run(tok, ws, text);
+ if (n < 0)
+ return NULL;
+ int *ids = (int *)malloc((size_t)(n > 0 ? n : 1) * sizeof(int));
+ if (!ids)
+ return NULL;
+ memcpy(ids, ws->ids, (size_t)n * sizeof(int));
+ if (out_n_tokens)
+ *out_n_tokens = n;
+ return ids;
+}
+
+int *tok_wp_encode(const tok_wp_t *tok, const char *text, int *out_n) {
+ if (out_n)
+ *out_n = 0;
+ tok_wp_workspace_t *ws = tok_wp_workspace_new();
+ if (!ws)
+ return NULL;
+ int *ids = tok_wp_encode_with_workspace(tok, ws, text, out_n);
+ tok_wp_workspace_free(ws);
+ return ids;
+}
+
+void tok_wp_free(tok_wp_t *tok) {
+ if (!tok)
+ return;
+ if (tok->id_to_token) {
+ for (int i = 0; i < tok->vocab_size; i++)
+ free(tok->id_to_token[i]);
+ free(tok->id_to_token);
+ }
+ free(tok->vocab_map);
+ free(tok);
+}
diff --git a/libffwd/wordpiece.h b/libffwd/wordpiece.h
new file mode 100644
index 0000000..f8a63d6
--- /dev/null
+++ b/libffwd/wordpiece.h
@@ -0,0 +1,72 @@
+/*
+ * BERT-family WordPiece tokenizer.
+ *
+ * Implements BERT tokenization: BasicTokenizer (cleanup, optional lowercase
+ * and accent stripping, CJK spacing, whitespace splitting, and punctuation
+ * splitting), then greedy longest-match WordPiece using vocab.txt.
+ *
+ * Encodes text only. The frontend adds [CLS]/[SEP], just as the byte-level BPE
+ * backend leaves terminal and separator tokens to the frontend.
+ *
+ * Public API mirrors bpe.h: load, encode with reusable workspace, decode,
+ * resolve named special tokens, and free. This lets both tokenizers share one
+ * tokenizer interface later.
+ */
+
+#ifndef TOK_WP_H
+#define TOK_WP_H
+
+typedef struct {
+ char **id_to_token; /* [vocab_size] vocab.txt entries, line order = id */
+ int vocab_size;
+ int unk_id; /* [UNK] id, resolved at load */
+ int do_lower_case; /* lowercase + strip accents before WordPiece */
+ int max_chars_per_word; /* words longer than this map to [UNK] (BERT: 100) */
+
+ /* Opaque token-string -> id hash map. */
+ void *vocab_map;
+ int vocab_map_cap;
+} tok_wp_t;
+
+typedef struct tok_wp_workspace tok_wp_workspace_t;
+
+/* Load <model_dir>/vocab.txt and do_lower_case from
+ * <model_dir>/tokenizer_config.json; defaults to lowercase.
+ * Returns NULL on error: missing vocab.txt, missing [UNK], or allocation failure. */
+tok_wp_t *tok_wp_load(const char *model_dir);
+
+/* Decode one id to its vocab token string, or NULL.
+ * Returns an internal pointer. */
+const char *tok_wp_decode(const tok_wp_t *tok, int id);
+
+/* Resolve a named token (e.g. "[CLS]") to its id, or -1 when absent. */
+int tok_wp_token_id(const tok_wp_t *tok, const char *token);
+
+/* Encode UTF-8 text into a malloc'd id array and set *out_n_tokens.
+ * Returns NULL on error and sets *out_n_tokens = 0. */
+int *tok_wp_encode(const tok_wp_t *tok, const char *text, int *out_n_tokens);
+
+/* Reusable scratch space for repeated encoding with fewer allocations. */
+tok_wp_workspace_t *tok_wp_workspace_new(void);
+void tok_wp_workspace_free(tok_wp_workspace_t *ws);
+
+/* Encode into caller-provided out_ids[0..out_cap-1].
+ * Returns 0 on success, -1 on error, or -2 if out_cap is too small.
+ * If non-NULL, *out_n_tokens is always set to tokens needed/emitted. */
+int tok_wp_encode_into(const tok_wp_t *tok,
+ tok_wp_workspace_t *ws,
+ const char *text,
+ int *out_ids,
+ int out_cap,
+ int *out_n_tokens);
+
+/* Same tokenization as tok_wp_encode().
+ * Reuses ws internally and only allocates the returned int[]. */
+int *tok_wp_encode_with_workspace(const tok_wp_t *tok,
+ tok_wp_workspace_t *ws,
+ const char *text,
+ int *out_n_tokens);
+
+void tok_wp_free(tok_wp_t *tok);
+
+#endif /* TOK_WP_H */