Simple Graphics Library 1.0.0.0
Runtime-independent image processing primitives
Loading...
Searching...
No Matches
neon.h
1/*
2 * SPDX-License-Identifier: MIT
3 *
4 * Copyright (c) 2025 Dylan Hong
5 *
6 * This code is released under the MIT License.
7 * For conditions of distribution and use, see the LICENSE file.
8 */
9#ifndef SGL_FIXED_POINT_NEON_H_
10#define SGL_FIXED_POINT_NEON_H_
11
12#include <arm_neon.h>
13
18typedef int16x8_t sgl_simd_q11_t;
20typedef int32x4_t sgl_simd_q11_ext_t;
21
31{
32 int32x4_t prod_lo;
33 int32x4_t prod_hi;
34 sgl_simd_q11_t result;
35
36 prod_lo = vmull_s16(vget_low_s16(a), vget_low_s16(b));
37 prod_hi = vmull_s16(vget_high_s16(a), vget_high_s16(b));
38
39 /*
40 * Rounding shift right removes eleven Q22 fractional bits and restores
41 * the Q11 scale.
42 */
43 prod_lo = vrshrq_n_s32(prod_lo, SGL_Q11_FRAC_BITS);
44 prod_hi = vrshrq_n_s32(prod_hi, SGL_Q11_FRAC_BITS);
45
46 result = vcombine_s16(vqmovn_s32(prod_lo), vqmovn_s32(prod_hi));
47
48 return result;
49}
50
63{
64 int64x2_t prod0;
65 int64x2_t prod1;
66 sgl_simd_q11_ext_t result;
67
68 prod0 = vmull_s32(vget_low_s32(a), vget_low_s32(b));
69 prod1 = vmull_s32(vget_high_s32(a), vget_high_s32(b));
70 /*
71 * Rounding shift right removes eleven Q22 fractional bits before the
72 * values are narrowed back to 32-bit Q11 lanes.
73 */
74 result = vcombine_s32(
75 vqrshrn_n_s64(prod0, SGL_Q11_FRAC_BITS),
76 vqrshrn_n_s64(prod1, SGL_Q11_FRAC_BITS));
77
78 return result;
79}
80
88 int32x4_t lo,
89 int32x4_t hi)
90{
91 uint16x4_t u16_lo;
92 uint16x4_t u16_hi;
93 uint8x8_t result;
94
95 u16_lo = vqmovun_s32(lo);
96 u16_hi = vqmovun_s32(hi);
97 result = vqmovn_u16(vcombine_u16(u16_lo, u16_hi));
98
99 return result;
100}
101
104#endif /* !SGL_FIXED_POINT_NEON_H_ */
#define SGL_ALWAYS_INLINE
Requests compiler-enforced inlining.
int16x8_t sgl_simd_q11_t
Eight signed 16-bit Q11 lanes.
Definition neon.h:18
static sgl_simd_q11_ext_t sgl_simd_q11_ext_mul(sgl_simd_q11_ext_t a, sgl_simd_q11_ext_t b)
Multiplies four extended Q11 lane pairs.
Definition neon.h:60
static sgl_simd_q11_t sgl_simd_q11_mul(sgl_simd_q11_t a, sgl_simd_q11_t b)
Multiplies eight Q11 lane pairs with rounding and saturation.
Definition neon.h:28
#define SGL_Q11_FRAC_BITS
Number of fractional bits in a Q11 value.
Definition generic.h:26
static uint8x8_t sgl_simd_clamp_u8_i32(int32x4_t lo, int32x4_t hi)
Saturates eight signed 32-bit channel lanes to unsigned bytes.
Definition neon.h:87
int32x4_t sgl_simd_q11_ext_t
Four signed 32-bit extended Q11 lanes.
Definition neon.h:20