← Back to C-Kernel-Engine Docs Doxygen Source Documentation
 
Loading...
Searching...
No Matches
checked_float_buffer.h
Go to the documentation of this file.
1#ifndef CK_CHECKED_FLOAT_BUFFER_H
2#define CK_CHECKED_FLOAT_BUFFER_H
3#include <stdint.h>
4#include <stddef.h>
5#include <math.h>
6static inline int ck_checked_span(size_t rows, size_t width, size_t stride, size_t *span) {
7 if (!rows || !width || stride < width || rows - 1 > (SIZE_MAX - width) / stride) return 0;
8 *span = (rows - 1) * stride + width;
9 return *span <= SIZE_MAX / sizeof(float);
10}
11static inline int ck_checked_region(const float *ptr, size_t n) {
12 return ptr && (uintptr_t)ptr % _Alignof(float) == 0 && n <= SIZE_MAX / sizeof(float)
13 && (uintptr_t)ptr <= UINTPTR_MAX - n * sizeof(float);
14}
15static inline int ck_checked_overlap(const float *a, size_t na, const float *b, size_t nb) {
16 return (uintptr_t)a < (uintptr_t)b + nb * sizeof(float)
17 && (uintptr_t)b < (uintptr_t)a + na * sizeof(float);
18}
19static inline int ck_checked_finite(const float *ptr, size_t n) {
20 for (size_t i = 0; i < n; ++i) if (!isfinite(ptr[i])) return 0;
21 return 1;
22}
23#endif
static int ck_checked_finite(const float *ptr, size_t n)
static int ck_checked_span(size_t rows, size_t width, size_t stride, size_t *span)
static int ck_checked_region(const float *ptr, size_t n)
static int ck_checked_overlap(const float *a, size_t na, const float *b, size_t nb)