nano-ui-sdl-0.1.0.0: cbits/nano_ui_simd.h
#ifndef NANO_UI_SIMD_H
#define NANO_UI_SIMD_H
#include <stdint.h>
#include <stdbool.h>
#if defined(__AVX2__)
#include <immintrin.h>
#define NANO_UI_HAS_AVX2 1
#endif
// Returns true if quad AABB [qx0, qy0, qx1, qy1] intersects [dx0, dy0, dx1, dy1]
static inline bool nano_ui_aabb_intersects(
float qx0, float qy0, float qx1, float qy1,
float dx0, float dy0, float dx1, float dy1)
{
return !(qx1 < dx0 || qx0 > dx1 || qy1 < dy0 || qy0 > dy1);
}
#if defined(NANO_UI_HAS_AVX2)
// Tests 8 quad bounding boxes against damage rect [dx0, dy0, dx1, dy1].
// Returns an 8-bit mask where bit i is 1 if quad i intersects the damage rectangle.
static inline uint32_t nano_ui_cull_8_quads_avx2(
__m256 qx0, __m256 qy0, __m256 qx1, __m256 qy1,
__m256 dx0, __m256 dy0, __m256 dx1, __m256 dy1)
{
__m256 outside = _mm256_or_ps(
_mm256_cmp_ps(qx1, dx0, _CMP_LT_OQ),
_mm256_or_ps(
_mm256_cmp_ps(qx0, dx1, _CMP_GT_OQ),
_mm256_or_ps(
_mm256_cmp_ps(qy1, dy0, _CMP_LT_OQ),
_mm256_cmp_ps(qy0, dy1, _CMP_GT_OQ)
)
)
);
uint32_t out_mask = (uint32_t)_mm256_movemask_ps(outside);
return (~out_mask) & 0xFF;
}
#endif
#endif // NANO_UI_SIMD_H