// Copyright 2018 Tencent
// SPDX-License-Identifier: BSD-3-Clause

#version 450

layout (constant_id = 0) const int op_type = 0;
layout (constant_id = 1) const uint n = 0;

layout (binding = 0) buffer bottom_top_blob { sfpvec4 bottom_top_blob_data[]; };

layout (push_constant) uniform parameter
{
    uint n;
} p;

void main()
{
    const uint gi = gl_GlobalInvocationID.x;

    if (gi >= psc(n))
        return;

    afpvec4 v = buffer_ld4(bottom_top_blob_data, gi);

    afpvec4 res;

    if (op_type == 0) res = abs(v);
    if (op_type == 1) res = -v;
    if (op_type == 2) res = floor(v);
    if (op_type == 3) res = ceil(v);
    if (op_type == 4) res = v * v;
    if (op_type == 5) res = sqrt(v);
    if (op_type == 6) res = inversesqrt(v);
    if (op_type == 7) res = exp(v);
    if (op_type == 8) res = log(v);
    if (op_type == 9) res = sin(v);
    if (op_type == 10) res = cos(v);
    if (op_type == 11) res = tan(v);
    if (op_type == 12) res = asin(v);
    if (op_type == 13) res = acos(v);
    if (op_type == 14) res = atan(v);
    if (op_type == 15) res = afp(1.f) / v;
#if NCNN_moltenvk
    if (op_type == 16) res = afpvec4(tanh(vec4(v)));
#else
    if (op_type == 16) res = tanh(v);
#endif
    if (op_type == 17) res = log(v) * afp(0.434294481903);
    if (op_type == 18) res = round(v);
    if (op_type == 19) res = trunc(v);

    buffer_st4(bottom_top_blob_data, gi, res);
}
