3838MLD_MUST_CHECK_RETURN_VALUE
3939static MLD_INLINE int mld_ntt_native (int32_t data [MLDSA_N ])
4040{
41+ if (!mld_sys_check_capability (MLD_SYS_CAP_AARCH64_NEON ))
42+ {
43+ return MLD_NATIVE_FUNC_FALLBACK ;
44+ }
4145 mld_ntt_aarch64_asm (data , mld_aarch64_ntt_zetas_layer123456 ,
4246 mld_aarch64_ntt_zetas_layer78 );
4347 return MLD_NATIVE_FUNC_SUCCESS ;
@@ -46,6 +50,10 @@ static MLD_INLINE int mld_ntt_native(int32_t data[MLDSA_N])
4650MLD_MUST_CHECK_RETURN_VALUE
4751static MLD_INLINE int mld_intt_native (int32_t data [MLDSA_N ])
4852{
53+ if (!mld_sys_check_capability (MLD_SYS_CAP_AARCH64_NEON ))
54+ {
55+ return MLD_NATIVE_FUNC_FALLBACK ;
56+ }
4957 mld_intt_aarch64_asm (data , mld_aarch64_intt_zetas_layer78 ,
5058 mld_aarch64_intt_zetas_layer123456 );
5159 return MLD_NATIVE_FUNC_SUCCESS ;
@@ -56,8 +64,8 @@ static MLD_INLINE int mld_rej_uniform_native(int32_t *r, unsigned len,
5664 const uint8_t * buf ,
5765 unsigned buflen )
5866{
59- if (len != MLDSA_N ||
60- buflen % 24 != 0 ) /* NEON support is mandatory for AArch64 */
67+ if (! mld_sys_check_capability ( MLD_SYS_CAP_AARCH64_NEON ) || len != MLDSA_N ||
68+ buflen % 24 != 0 )
6169 {
6270 return MLD_NATIVE_FUNC_FALLBACK ;
6371 }
@@ -76,7 +84,8 @@ static MLD_INLINE int mld_rej_uniform_eta2_native(int32_t *r, unsigned len,
7684{
7785 uint64_t outlen ;
7886 /* AArch64 implementation assumes specific buffer lengths */
79- if (len != MLDSA_N || buflen != MLD_AARCH64_REJ_UNIFORM_ETA2_BUFLEN )
87+ if (!mld_sys_check_capability (MLD_SYS_CAP_AARCH64_NEON ) || len != MLDSA_N ||
88+ buflen != MLD_AARCH64_REJ_UNIFORM_ETA2_BUFLEN )
8089 {
8190 return MLD_NATIVE_FUNC_FALLBACK ;
8291 }
@@ -104,7 +113,8 @@ static MLD_INLINE int mld_rej_uniform_eta4_native(int32_t *r, unsigned len,
104113{
105114 uint64_t outlen ;
106115 /* AArch64 implementation assumes specific buffer lengths */
107- if (len != MLDSA_N || buflen != MLD_AARCH64_REJ_UNIFORM_ETA4_BUFLEN )
116+ if (!mld_sys_check_capability (MLD_SYS_CAP_AARCH64_NEON ) || len != MLDSA_N ||
117+ buflen != MLD_AARCH64_REJ_UNIFORM_ETA4_BUFLEN )
108118 {
109119 return MLD_NATIVE_FUNC_FALLBACK ;
110120 }
@@ -131,6 +141,10 @@ static MLD_INLINE int mld_rej_uniform_eta4_native(int32_t *r, unsigned len,
131141MLD_MUST_CHECK_RETURN_VALUE
132142static MLD_INLINE int mld_poly_decompose_32_native (int32_t * a1 , int32_t * a0 )
133143{
144+ if (!mld_sys_check_capability (MLD_SYS_CAP_AARCH64_NEON ))
145+ {
146+ return MLD_NATIVE_FUNC_FALLBACK ;
147+ }
134148 mld_poly_decompose_32_aarch64_asm (a1 , a0 );
135149 return MLD_NATIVE_FUNC_SUCCESS ;
136150}
@@ -141,6 +155,10 @@ static MLD_INLINE int mld_poly_decompose_32_native(int32_t *a1, int32_t *a0)
141155MLD_MUST_CHECK_RETURN_VALUE
142156static MLD_INLINE int mld_poly_decompose_88_native (int32_t * a1 , int32_t * a0 )
143157{
158+ if (!mld_sys_check_capability (MLD_SYS_CAP_AARCH64_NEON ))
159+ {
160+ return MLD_NATIVE_FUNC_FALLBACK ;
161+ }
144162 mld_poly_decompose_88_aarch64_asm (a1 , a0 );
145163 return MLD_NATIVE_FUNC_SUCCESS ;
146164}
@@ -151,6 +169,10 @@ static MLD_INLINE int mld_poly_decompose_88_native(int32_t *a1, int32_t *a0)
151169MLD_MUST_CHECK_RETURN_VALUE
152170static MLD_INLINE int mld_poly_caddq_native (int32_t a [MLDSA_N ])
153171{
172+ if (!mld_sys_check_capability (MLD_SYS_CAP_AARCH64_NEON ))
173+ {
174+ return MLD_NATIVE_FUNC_FALLBACK ;
175+ }
154176 mld_poly_caddq_aarch64_asm (a );
155177 return MLD_NATIVE_FUNC_SUCCESS ;
156178}
@@ -161,6 +183,10 @@ static MLD_INLINE int mld_poly_caddq_native(int32_t a[MLDSA_N])
161183MLD_MUST_CHECK_RETURN_VALUE
162184static MLD_INLINE int mld_poly_use_hint_32_native (int32_t * a , const int32_t * h )
163185{
186+ if (!mld_sys_check_capability (MLD_SYS_CAP_AARCH64_NEON ))
187+ {
188+ return MLD_NATIVE_FUNC_FALLBACK ;
189+ }
164190 mld_poly_use_hint_32_aarch64_asm (a , h );
165191 return MLD_NATIVE_FUNC_SUCCESS ;
166192}
@@ -171,6 +197,10 @@ static MLD_INLINE int mld_poly_use_hint_32_native(int32_t *a, const int32_t *h)
171197MLD_MUST_CHECK_RETURN_VALUE
172198static MLD_INLINE int mld_poly_use_hint_88_native (int32_t * a , const int32_t * h )
173199{
200+ if (!mld_sys_check_capability (MLD_SYS_CAP_AARCH64_NEON ))
201+ {
202+ return MLD_NATIVE_FUNC_FALLBACK ;
203+ }
174204 mld_poly_use_hint_88_aarch64_asm (a , h );
175205 return MLD_NATIVE_FUNC_SUCCESS ;
176206}
@@ -181,6 +211,10 @@ static MLD_INLINE int mld_poly_use_hint_88_native(int32_t *a, const int32_t *h)
181211MLD_MUST_CHECK_RETURN_VALUE
182212static MLD_INLINE int mld_poly_chknorm_native (const int32_t * a , int32_t B )
183213{
214+ if (!mld_sys_check_capability (MLD_SYS_CAP_AARCH64_NEON ))
215+ {
216+ return MLD_NATIVE_FUNC_FALLBACK ;
217+ }
184218 return mld_poly_chknorm_aarch64_asm (a , B );
185219}
186220
@@ -189,6 +223,10 @@ static MLD_INLINE int mld_poly_chknorm_native(const int32_t *a, int32_t B)
189223MLD_MUST_CHECK_RETURN_VALUE
190224static MLD_INLINE int mld_polyz_unpack_17_native (int32_t * r , const uint8_t * buf )
191225{
226+ if (!mld_sys_check_capability (MLD_SYS_CAP_AARCH64_NEON ))
227+ {
228+ return MLD_NATIVE_FUNC_FALLBACK ;
229+ }
192230 mld_polyz_unpack_17_aarch64_asm (r , buf , mld_polyz_unpack_17_indices );
193231 return MLD_NATIVE_FUNC_SUCCESS ;
194232}
@@ -200,6 +238,10 @@ static MLD_INLINE int mld_polyz_unpack_17_native(int32_t *r, const uint8_t *buf)
200238MLD_MUST_CHECK_RETURN_VALUE
201239static MLD_INLINE int mld_polyz_unpack_19_native (int32_t * r , const uint8_t * buf )
202240{
241+ if (!mld_sys_check_capability (MLD_SYS_CAP_AARCH64_NEON ))
242+ {
243+ return MLD_NATIVE_FUNC_FALLBACK ;
244+ }
203245 mld_polyz_unpack_19_aarch64_asm (r , buf , mld_polyz_unpack_19_indices );
204246 return MLD_NATIVE_FUNC_SUCCESS ;
205247}
@@ -213,6 +255,10 @@ MLD_MUST_CHECK_RETURN_VALUE
213255static MLD_INLINE int mld_poly_pointwise_montgomery_native (
214256 int32_t a [MLDSA_N ], const int32_t b [MLDSA_N ])
215257{
258+ if (!mld_sys_check_capability (MLD_SYS_CAP_AARCH64_NEON ))
259+ {
260+ return MLD_NATIVE_FUNC_FALLBACK ;
261+ }
216262 mld_poly_pointwise_montgomery_aarch64_asm (a , b );
217263 return MLD_NATIVE_FUNC_SUCCESS ;
218264}
@@ -225,6 +271,10 @@ static MLD_INLINE int mld_polyvecl_pointwise_acc_montgomery_l4_native(
225271 int32_t w [MLDSA_N ], const int32_t u [4 ][MLDSA_N ],
226272 const int32_t v [4 ][MLDSA_N ])
227273{
274+ if (!mld_sys_check_capability (MLD_SYS_CAP_AARCH64_NEON ))
275+ {
276+ return MLD_NATIVE_FUNC_FALLBACK ;
277+ }
228278 mld_polyvecl_pointwise_acc_montgomery_l4_aarch64_asm (w , u , v );
229279 return MLD_NATIVE_FUNC_SUCCESS ;
230280}
@@ -236,6 +286,10 @@ static MLD_INLINE int mld_polyvecl_pointwise_acc_montgomery_l5_native(
236286 int32_t w [MLDSA_N ], const int32_t u [5 ][MLDSA_N ],
237287 const int32_t v [5 ][MLDSA_N ])
238288{
289+ if (!mld_sys_check_capability (MLD_SYS_CAP_AARCH64_NEON ))
290+ {
291+ return MLD_NATIVE_FUNC_FALLBACK ;
292+ }
239293 mld_polyvecl_pointwise_acc_montgomery_l5_aarch64_asm (w , u , v );
240294 return MLD_NATIVE_FUNC_SUCCESS ;
241295}
@@ -247,6 +301,10 @@ static MLD_INLINE int mld_polyvecl_pointwise_acc_montgomery_l7_native(
247301 int32_t w [MLDSA_N ], const int32_t u [7 ][MLDSA_N ],
248302 const int32_t v [7 ][MLDSA_N ])
249303{
304+ if (!mld_sys_check_capability (MLD_SYS_CAP_AARCH64_NEON ))
305+ {
306+ return MLD_NATIVE_FUNC_FALLBACK ;
307+ }
250308 mld_polyvecl_pointwise_acc_montgomery_l7_aarch64_asm (w , u , v );
251309 return MLD_NATIVE_FUNC_SUCCESS ;
252310}
0 commit comments