aboutsummaryrefslogtreecommitdiff
path: root/libffwd/alloc.c
diff options
context:
space:
mode:
authorOnur Gündüz <ogunduz@gmail.com>2026-09-29 13:11:00 +0200
committerOnur Gündüz <ogunduz@gmail.com>2026-09-29 13:11:00 +0200
commit37cbaef9ceb828c667da8f398027ba5415ee7475 (patch)
tree6103e92a9030766e78a35df00f7a1155d0d0ecf5 /libffwd/alloc.c
parentcf7d8169ec12cb3adf90d4ff78b3257e74985302 (diff)
downloadlangdet-37cbaef9ceb828c667da8f398027ba5415ee7475.tar.gz
langdet-37cbaef9ceb828c667da8f398027ba5415ee7475.zip
Rename CPU library API and sources to langdet
Diffstat (limited to 'libffwd/alloc.c')
-rw-r--r--libffwd/alloc.c65
1 files changed, 0 insertions, 65 deletions
diff --git a/libffwd/alloc.c b/libffwd/alloc.c
deleted file mode 100644
index ba21fbb..0000000
--- a/libffwd/alloc.c
+++ /dev/null
@@ -1,65 +0,0 @@
-#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 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;
-}
-
-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);
-}