2023-04-12 13:37:49 +00:00
|
|
|
#!/usr/bin/python3
|
2024-01-01 18:12:26 +00:00
|
|
|
# Copyright (C) 2023-2024 Free Software Foundation, Inc.
|
2023-04-12 13:37:49 +00:00
|
|
|
# This file is part of the GNU C Library.
|
|
|
|
#
|
|
|
|
# The GNU C Library is free software; you can redistribute it and/or
|
|
|
|
# modify it under the terms of the GNU Lesser General Public
|
|
|
|
# License as published by the Free Software Foundation; either
|
|
|
|
# version 2.1 of the License, or (at your option) any later version.
|
|
|
|
#
|
|
|
|
# The GNU C Library is distributed in the hope that it will be useful,
|
|
|
|
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
# Lesser General Public License for more details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU Lesser General Public
|
|
|
|
# License along with the GNU C Library; if not, see
|
|
|
|
# <https://www.gnu.org/licenses/>.
|
|
|
|
|
|
|
|
import sys
|
|
|
|
|
|
|
|
TEMPLATE = """
|
|
|
|
#include <math.h>
|
|
|
|
#include <arm_neon.h>
|
|
|
|
|
2023-11-21 14:39:39 +00:00
|
|
|
#define STRIDE {rowlen}
|
2023-04-12 13:37:49 +00:00
|
|
|
|
2023-11-21 14:39:39 +00:00
|
|
|
#define CALL_BENCH_FUNC_1(v, i) (__extension__ ({{ \\
|
|
|
|
{rtype} mx0 = {fname}(vld1q_f{prec_short} (&variants[v].in->arg0[i * STRIDE])); \\
|
2023-04-12 13:37:49 +00:00
|
|
|
mx0; }}))
|
|
|
|
|
2023-11-21 14:39:39 +00:00
|
|
|
#define CALL_BENCH_FUNC_2(v, i) (__extension__ ({{ \\
|
|
|
|
{rtype} mx0 = {fname}(vld1q_f{prec_short} (&variants[v].in->arg0[i * STRIDE]), \\
|
|
|
|
vld1q_f{prec_short} (&variants[v].in->arg1[i * STRIDE])); \\
|
|
|
|
mx0; }}))
|
|
|
|
|
|
|
|
struct args_1
|
|
|
|
{{
|
|
|
|
{stype} arg0[{nelems}];
|
|
|
|
}};
|
|
|
|
|
|
|
|
struct args_2
|
2023-04-12 13:37:49 +00:00
|
|
|
{{
|
2023-11-21 14:39:39 +00:00
|
|
|
{stype} arg0[{nelems}];
|
|
|
|
{stype} arg1[{nelems}];
|
2023-04-12 13:37:49 +00:00
|
|
|
}};
|
|
|
|
|
|
|
|
struct _variants
|
|
|
|
{{
|
|
|
|
const char *name;
|
2023-11-21 14:39:39 +00:00
|
|
|
const struct args_{arity} *in;
|
2023-04-12 13:37:49 +00:00
|
|
|
}};
|
|
|
|
|
2023-11-21 14:39:39 +00:00
|
|
|
static const struct args_{arity} in0 = {{
|
2023-04-12 13:37:49 +00:00
|
|
|
{in_data}
|
|
|
|
}};
|
|
|
|
|
|
|
|
static const struct _variants variants[1] = {{
|
2023-11-21 14:39:39 +00:00
|
|
|
{{"", &in0}},
|
2023-04-12 13:37:49 +00:00
|
|
|
}};
|
|
|
|
|
|
|
|
#define NUM_VARIANTS 1
|
2023-11-21 14:39:39 +00:00
|
|
|
#define NUM_SAMPLES(i) ({nelems} / STRIDE)
|
2023-04-12 13:37:49 +00:00
|
|
|
#define VARIANT(i) (variants[i].name)
|
|
|
|
|
|
|
|
static {rtype} volatile ret;
|
|
|
|
|
2023-11-21 14:39:39 +00:00
|
|
|
#define BENCH_FUNC(i, j) ({{ ret = CALL_BENCH_FUNC_{arity}(i, j); }})
|
2023-04-12 13:37:49 +00:00
|
|
|
#define FUNCNAME "{fname}"
|
|
|
|
#include <bench-libmvec-skeleton.c>
|
|
|
|
"""
|
|
|
|
|
|
|
|
def main(name):
|
|
|
|
_, prec, _, func = name.split("-")
|
|
|
|
scalar_to_advsimd_type = {"double": "float64x2_t", "float": "float32x4_t"}
|
2023-11-21 14:39:39 +00:00
|
|
|
rowlen = {"double": 2, "float": 4}[prec]
|
2023-04-12 13:37:49 +00:00
|
|
|
rtype = scalar_to_advsimd_type[prec]
|
|
|
|
atype = scalar_to_advsimd_type[prec]
|
|
|
|
prec_short = {"double": 64, "float": 32}[prec]
|
2023-11-21 14:39:39 +00:00
|
|
|
input_filename = {"double": f"{func}-inputs", "float": f"{func}f-inputs"}[prec]
|
|
|
|
|
|
|
|
with open(f"../benchtests/libmvec/{input_filename}") as f:
|
|
|
|
input_file = f.readlines()
|
|
|
|
in_vals = (l.strip() for l in input_file if l and not l.startswith("#"))
|
|
|
|
# Split in case of multivariate signature
|
|
|
|
in_vals = (l.split(", ") for l in in_vals)
|
|
|
|
# Transpose
|
|
|
|
in_vals = list(zip(*in_vals))
|
|
|
|
in_data = ",\n".join("{" + (", ".join(val for val in col) + "}")
|
|
|
|
for col in in_vals)
|
|
|
|
|
|
|
|
arity = [l for l in input_file if l.startswith("## args: ")][0].count(prec)
|
|
|
|
fname = f"_ZGVnN{rowlen}{'v' * arity}_{func}{'f' if prec == 'float' else ''}"
|
|
|
|
|
|
|
|
print(TEMPLATE.format(rowlen=rowlen,
|
2023-04-12 13:37:49 +00:00
|
|
|
rtype=rtype,
|
|
|
|
atype=atype,
|
|
|
|
fname=fname,
|
|
|
|
prec_short=prec_short,
|
|
|
|
in_data=in_data,
|
2023-11-21 14:39:39 +00:00
|
|
|
stype=prec,
|
|
|
|
arity=arity,
|
|
|
|
nelems=len(in_vals[0])))
|
2023-04-12 13:37:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == "__main__":
|
|
|
|
main(sys.argv[1])
|