Function arm_hard_swish_f16

Function Documentation

arm_cmsis_nn_status arm_hard_swish_f16(const float16_t *input, float16_t *output, int32_t size)

Hard swish activation for float16 data.

Computes output[i] = input[i] * min(max(input[i] + 3, 0), 6) / 6 elementwise. The scalar leg widens each element to float32, evaluates the gate and the product there exactly as in arm_hard_swish_f32, and narrows only the final product, so it is single-rounded. The MVE (cortex-m55) leg evaluates the same expression in float16 throughout, scaling the gate by 1/6 before the product so that the multiplier stays in [0, 1]; it rounds the gate and the product separately and so can sit up to 2 float16 ulp away from the scalar leg in the curved region -3 < x < 3. The saturated regions are exact and identical on both legs (x >= 3 returns x bit-exactly, x <= -3 returns zero), as is the NaN/Inf behavior below; NaN lanes agree in NaN-ness but not necessarily in payload. In-place operation (output == input) is supported on both legs.

Note

NaN and Inf behave as in arm_hard_swish_f32, at every optimization level on the gated toolchains (see docs/guides/verification.md): NaN propagates through the final multiply (NaN-ness only, not a particular payload), +Inf returns +Inf, and -Inf returns NaN because the gate is 0 there and (-Inf) * 0 is NaN by IEEE 754, matching TFLite’s float hard-swish reference rather than the mathematical limit 0.

Note

Nothing in this kernel converts between half and single precision any more, and the float16 kernels that still do are not tied to a particular assembler: they go through Include/Internal/arm_nn_vcvt_f16.h, which emits the scalar form of VCVTB/VCVTT wherever the vector form would be mis-encoded (binutils below 2.43). Under CMake the probe measures the assembler in use and selects the form; a build that never runs it &#8212; the CMSIS-Pack Source Cvariant, module.mk, or a CMake project that wires its architecture flags where the probe cannot read them &#8212; falls back to the compiler major, which is right for every Arm GNU release and wrong only for a GCC 14 or newer driver paired by hand with an older binutils. Check as --version if you assembled that pair yourself. See docs/guides/toolchains.md.

Parameters:
  • input[in] Pointer to the input samples.

  • output[out] Pointer to the output samples.

  • size[in] Number of elements to process. Must be at least 1.

Returns:

ARM_CMSIS_NN_SUCCESS on success or ARM_CMSIS_NN_ARG_ERROR on invalid arguments.