diff options
| author | Onur Gündüz <ogunduz@gmail.com> | 2026-09-29 12:54:13 +0200 |
|---|---|---|
| committer | Onur Gündüz <ogunduz@gmail.com> | 2026-09-29 12:54:13 +0200 |
| commit | 91871be6ece9317c5d49353f6474583e7e28168d (patch) | |
| tree | 8cabf2546322a9e1b724bf8413f32de54378824f /libffwd/generic.c | |
| parent | 35ab9c12ba4d396e6cba99d6ea947e26becedad4 (diff) | |
| download | langdet-91871be6ece9317c5d49353f6474583e7e28168d.tar.gz langdet-91871be6ece9317c5d49353f6474583e7e28168d.zip | |
Add native CPU language detection CLI
Diffstat (limited to 'libffwd/generic.c')
| -rw-r--r-- | libffwd/generic.c | 44 |
1 files changed, 44 insertions, 0 deletions
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]; +} |
