// vim: set syntax=asm :
{% from "fma_mmm_ymm_ops.j2" import scalar %}

{{ scalar("scalar_min", "vminps", from, to, type=type) }}
{{ scalar("scalar_max", "vmaxps", from, to, type=type) }}
{{ scalar("scalar_add", "vaddps", from, to, type=type) }}
{{ scalar("scalar_mul", "vmulps", from, to, type=type) }}
{{ scalar("scalar_sub", "vsubps", from, to, type=type) }}
{{ scalar("scalar_sub_flipped", "vsubps", from, to, type=type, flipped=true) }}

{{L}}leaky_relu:
    // can only use ymm12 to ymm15
    // ymm15 <- alpha
    {% if type == "f32" %}
        vbroadcastss    ymm15, dword ptr [rdi + 8]
    {% else %}
        pinsrw          xmm15, word ptr [rdi + 8], 0
        vcvtph2ps       ymm15, xmm15
        vbroadcastss    ymm15, xmm15
    {% endif %}

    // ymm14 <- all zero
    vpxor           ymm14, ymm14, ymm14

    {% for reg in range(from, to + 1) %}
        // ymm12 <- alpha * x
        vmulps      ymm12, ymm{{reg}}, ymm15
        vcmpps     ymm13, ymm14, ymm{{reg}}, 1 // 1 means LT
        vblendvps   ymm{{reg}}, ymm12, ymm{{reg}}, ymm13
    {% endfor %}
    // select muled of orginal

    jmp    {{L}}non_linear_loop

{{L}}q_scale:
{{L}}q_shl:
{{L}}q_shr:
    jmp {{L}}unsupported
