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

{{ scalar("scalar_min", "vpminsd", from, to, type="i32") }}
{{ scalar("scalar_max", "vpmaxsd", from, to, type="i32") }}
{{ scalar("scalar_mul", "vpmulld", from, to, type="i32") }}
{{ scalar("scalar_add", "vpaddd", from, to, type="i32") }}
{{ scalar("scalar_sub", "vpsubd", from, to, type="i32") }}
{{ scalar("scalar_sub_flipped", "vpsubd", from, to, type="i32", flipped=true) }}

{{L}}leaky_relu:
    // can only use ymm12 to ymm15
    // ymm15 <- alpha
    vbroadcastss    ymm15, dword ptr [rdi + 8]
    // ymm14 <- all zero
    vpxor          ymm14, ymm14, ymm14

    {% for reg in range(from, to + 1) %}
        vpmulld     ymm12, ymm{{reg}}, ymm15
        vpcmpgtd    ymm13, ymm14, ymm{{reg}}
        vblendvps   ymm{{reg}}, ymm{{reg}}, ymm12, ymm13
    {% endfor %}

    jmp    {{L}}non_linear_loop
