libsnobol4 1.0.2
High-performance SNOBOL4-style pattern matching library
Loading...
Searching...
No Matches
simd.h
Go to the documentation of this file.
1#pragma once
2
3#ifdef __cplusplus
4extern "C" {
5#endif
6
7
19
20#include <stdint.h>
21#include "snobol/c23_compat.h"
22
23/* ---------------------------------------------------------------------------
24 * SIMD capability detection
25 * ---------------------------------------------------------------------------
26 */
27
30#ifdef __AVX2__
31#define SNOBOL_HAS_AVX2 1
32#else
33#define SNOBOL_HAS_AVX2 0
34#endif
35
38#if defined(__ARM_NEON) || defined(__ARM_NEON__) || defined(__aarch64__)
39#define SNOBOL_HAS_NEON 1
40#else
41#define SNOBOL_HAS_NEON 0
42#endif
43
46#define SNOBOL_HAS_SIMD (SNOBOL_HAS_AVX2 || SNOBOL_HAS_NEON)
47
48/* ---------------------------------------------------------------------------
49 * SIMD width constants
50 * ---------------------------------------------------------------------------
51 */
52
58#if SNOBOL_HAS_AVX2
59enum { SNOBOL_SIMD_WIDTH = 32 };
60#elif SNOBOL_HAS_NEON
61enum { SNOBOL_SIMD_WIDTH = 16 };
62#else
63enum { SNOBOL_SIMD_WIDTH = 1 };
64#endif
65
66/* ---------------------------------------------------------------------------
67 * SIMD NFA state type
68 *
69 * An NFA state set is represented as a bitmask where each bit corresponds
70 * to one NFA state. The maximum number of states is limited by the SIMD
71 * register width (256 for AVX2, 128 for NEON).
72 * ---------------------------------------------------------------------------
73 */
74
75#if SNOBOL_HAS_AVX2
76#include <immintrin.h>
77typedef __m256i simd_reg_t;
78enum { SNOBOL_SIMD_NFA_MAX_STATES = 256 };
79
80#elif SNOBOL_HAS_NEON
81#include <arm_neon.h>
82typedef uint8x16_t simd_reg_t;
83enum { SNOBOL_SIMD_NFA_MAX_STATES = 128 };
84
85#else
86/* Scalar fallback: use uint64_t[4] (256 bits) */
87typedef uint64_t simd_reg_t[4];
89#endif
90
91#ifdef __cplusplus
92}
93#endif
@ SNOBOL_SIMD_WIDTH
Definition simd.h:63
@ SNOBOL_SIMD_NFA_MAX_STATES
Definition simd.h:88
uint64_t simd_reg_t[4]
Definition simd.h:87