Low level routines
LLR is a collection of low level C and C++ routines for array and image processing, with SIMD optimized implementations for SSE4.1, AVX2 and AVX512. The library provides aligned memory helpers, endian utilities, and high performance primitives for numerical arrays, typically used as a foundation for cryio, qtsnbl and auxygen.
Modules
C API
avx.h / avx.c AVX runtime detection and aligned allocation.
int is_avx_supported()– CPU AVX capability testvoid *llr_aligned_malloc(size_t size, size_t alignment)void llr_aligned_free(void *ptr)
sumroi.h / sumroi.c Rectangular region of interest sum of double frames.
double sum_roi(...)andsum_roi_positive(...)dispatchers- SIMD variants: SSE4, AVX, AVX512, scalar FPU
sumarr.h / sumarr.c Element wise array addition with optional negative clamp.
void sum_array(size_t size,double *array1,const double *array2,const double *neg)
subarr.h / subarr.c Element wise subtraction with optional negative clamp.
void sub_array(size_t size,double *array1,const double *array2,const double *neg)
setarrval.h / setarrval.c Replace matching values in an array.
int set_array_value(double *array,size_t size,const double *input,const double *output,size_t count)
setarrneg.h / setarrneg.c Replace negative values.
void set_array_negatives_as(double *array,size_t size,double value)
minmax.h / minmax.c Min/max reduction for double and uint16.
void min_max(const double *array,size_t size,double *min,double *max)void min_max_u16(const uint16_t *array,size_t size,uint16_t *min,uint16_t *max)
divide.h / divide.c In place division by scalar.
void divide(size_t size,double *array,double value)
sumcolrow.h / sumcolrow.c Column and row sums of 2D double arrays.
void sum_col(...),void sum_row(...),void sum_col_row(...)
autobounds.h / autobounds.c Histogram based auto bounds.
void auto_bound(const double *array,size_t size,double upper,double phi_lo,double phi_hi,double *lo,double *hi)- Histogram helpers
auto_bound_hist_*
ushrt2dbl.h / ushrt2dbl.c Conversion uint16 to double.
void ushrt2dbl(const uint16_t *array,size_t size,double *result)
llrendian.h
C++ endian and byteswap helpers in namespace llr.
bswap16/32/64,byteswap<T>,from_big_endian<T>,from_little_endian<T>,is_little_endian()
C++ API
sivec.h
template<typename T, size_t Align = 64, typename Derived = void> class SiVec
Aligned vector with SIMD aware operations: push, resize, zeroify, sum, mean, min_max, auto_bound, median,
set_negatives_as, log, bitmask, bounds, split, view, base64.
siframe.h
template<typename T, size_t Align = 64> class SiFrame : public SiVec<T, Align, SiFrame<T, Align>>
2D frame view with rotation, flip, transposition, sum, mean_col_row.
Umbrella header:
#include <llr/llr.h>
includes avx, sumroi, sumarr, setarrval, minmax, subarr.
Build
Requires CMake >= 3.27, C90, C++17.
cmake -B build -DLLR_BUILD_TESTS=ON
cmake --build build
Options:
NO_AVX– disable AVX/AVX2, defines-DNO_AVX=1. Otherwise MSVC gets/arch:AVX2and Unix gets-march=native.LLR_BUILD_TESTS– enable GoogleTest unit tests.LLR_BUILD_BENCHES– build Google Benchmark benchmarks.
Targets:
llr– aggregate static library with all public headersllr_avx,llr_sumroi,llr_sumarr,llr_subarr,llr_setarrval,llr_minmax,llr_autobounds,llr_sumcolrow,llr_ushrt2dbl,llr_divide,llr_setarrneg
Install layout:
- libraries →
lib/ - headers →
include/llr/
Tests are built via tests/tests.cmake, use CTest and download test EDF data automatically. Benchmarks are optional.
Usage in pylatus
The parent build adds llr as a subdirectory and includes its headers globally.
- cryio – links
llr, usessiframe.h,llrendian.h,setarrval.h - qtsnbl – links
llr_autobounds,llr_sumcolrow,llr_divide,llr_minmax, usessiframe.h,sivec.h - auxygen – uses
sivec.handminmax.hvia global include
Example:
#include <llr/avx.h>
#include <llr/sumroi.h>
if (is_avx_supported()) {
double s = sum_roi(x1, x2, y1, y2, dim2, array);
}
The SIMD variant is chosen at compile time. The preprocessor selects AVX512 → AVX2 → SSE4.1 → scalar FPU according to
the flags the build sets (-march=native on unix, /arch:AVX2 on MSVC, or NO_AVX), so a binary carries one
implementation and will not adapt to a different CPU at run time. is_avx_supported() is a separate CPU capability
query, not a dispatcher.
License
GPL-3.0+