|
@@ -7,6 +7,11 @@
|
|
|
#define VECTOR_MAX_SIZE 4
|
|
|
static_assert(VECTOR_MIN_SIZE <= VECTOR_MAX_SIZE, "Max vector size may not be less than the min vector size, c'mon");
|
|
|
|
|
|
+typedef enum {
|
|
|
+ STMT_DECL,
|
|
|
+ STMT_IMPL,
|
|
|
+} Stmt;
|
|
|
+
|
|
|
typedef enum {
|
|
|
TYPE_FLOAT = 0,
|
|
|
TYPE_DOUBLE,
|
|
@@ -529,30 +534,26 @@ const char *funcs_sqrt_defined_for[COUNT_TYPES] = {
|
|
|
[TYPE_DOUBLE] = "sqrt",
|
|
|
};
|
|
|
|
|
|
-void gen_vector_len_sig(FILE *stream, size_t n, Type_Def type_def)
|
|
|
+void gen_vector_len(FILE *stream, Stmt stmt, size_t n, Type_Def type_def, const char *sqrt_name)
|
|
|
{
|
|
|
Short_String vector_type = make_vector_type(n, type_def);
|
|
|
Short_String vector_prefix = make_vector_prefix(n, type_def);
|
|
|
Short_String func_name = shortf("%s_len", vector_prefix.cstr);
|
|
|
- gen_func_sig(stream, type_def.name, func_name.cstr, vector_type.cstr, &sqrlen_arg_name, 1);
|
|
|
-}
|
|
|
-
|
|
|
-void gen_vector_len_decl(FILE *stream, size_t n, Type_Def type_def)
|
|
|
-{
|
|
|
- gen_vector_len_sig(stream, n, type_def);
|
|
|
- fprintf(stream, ";\n");
|
|
|
-}
|
|
|
|
|
|
-void gen_vector_len_impl(FILE *stream, size_t n, Type_Def type_def, const char *sqrt_name)
|
|
|
-{
|
|
|
- Short_String vector_prefix = make_vector_prefix(n, type_def);
|
|
|
- Short_String sqrlen_name = shortf("%s_sqrlen", vector_prefix.cstr);
|
|
|
+ gen_func_sig(stream, type_def.name, func_name.cstr, vector_type.cstr, &sqrlen_arg_name, 1);
|
|
|
|
|
|
- gen_vector_len_sig(stream, n, type_def);
|
|
|
- fprintf(stream, "\n");
|
|
|
- fprintf(stream, "{\n");
|
|
|
- fprintf(stream, " return %s(%s(%s));\n", sqrt_name, sqrlen_name.cstr, sqrlen_arg_name);
|
|
|
- fprintf(stream, "}\n");
|
|
|
+ if (stmt == STMT_DECL) {
|
|
|
+ fprintf(stream, ";\n");
|
|
|
+ } else if (stmt == STMT_IMPL) {
|
|
|
+ Short_String sqrlen_name = shortf("%s_sqrlen", vector_prefix.cstr);
|
|
|
+ fprintf(stream, "\n");
|
|
|
+ fprintf(stream, "{\n");
|
|
|
+ fprintf(stream, " return %s(%s(%s));\n", sqrt_name, sqrlen_name.cstr, sqrlen_arg_name);
|
|
|
+ fprintf(stream, "}\n");
|
|
|
+ } else {
|
|
|
+ assert(0 && "unreachable");
|
|
|
+ exit(69);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
char *vector_convert_arg = "a";
|
|
@@ -658,7 +659,7 @@ int main()
|
|
|
}
|
|
|
gen_vector_sqrlen_decl(stream, n, type_defs[type]);
|
|
|
if (funcs_sqrt_defined_for[type]) {
|
|
|
- gen_vector_len_decl(stream, n, type_defs[type]);
|
|
|
+ gen_vector_len(stream, STMT_DECL, n, type_defs[type], funcs_sqrt_defined_for[type]);
|
|
|
}
|
|
|
fprintf(stream, "\n");
|
|
|
}
|
|
@@ -716,7 +717,7 @@ int main()
|
|
|
gen_vector_sqrlen_impl(stream, n, type_defs[type]);
|
|
|
fputc('\n', stream);
|
|
|
if (funcs_sqrt_defined_for[type]) {
|
|
|
- gen_vector_len_impl(stream, n, type_defs[type], funcs_sqrt_defined_for[type]);
|
|
|
+ gen_vector_len(stream, STMT_IMPL, n, type_defs[type], funcs_sqrt_defined_for[type]);
|
|
|
fputc('\n', stream);
|
|
|
}
|
|
|
}
|