|
@@ -164,6 +164,35 @@ void gen_vector_scalar_ctor(FILE *stream, Stmt stmt, size_t n, Type_Def type_def
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
|
|
+void gen_vector_eq(FILE *stream, Stmt stmt, size_t n, Type type)
|
|
|
|
+{
|
|
|
|
+ Type_Def type_def = type_defs[type];
|
|
|
|
+ const char *vector_type = make_vector_type(n, type_def);
|
|
|
|
+ const char *vector_prefix = make_vector_prefix(n, type_def);
|
|
|
|
+ const char *name = temp_sprintf("%s_eq", vector_prefix);
|
|
|
|
+
|
|
|
|
+ static_assert(OP_ARITY >= 2, "This code assumes that operation's arity is at least 2");
|
|
|
|
+ gen_func_sig(stream, "bool", name, vector_type, op_arg_names, 2);
|
|
|
|
+ switch (stmt) {
|
|
|
|
+ case STMT_DECL: {
|
|
|
|
+ fprintf(stream, ";\n");
|
|
|
|
+ } break;
|
|
|
|
+ case STMT_IMPL: {
|
|
|
|
+ fprintf(stream, "\n");
|
|
|
|
+ fprintf(stream, "{\n");
|
|
|
|
+ assert(n <= VECTOR_MAX_SIZE);
|
|
|
|
+ for (size_t i = 0; i < n; ++i) {
|
|
|
|
+ fprintf(stream, " if (%s.%s != %s.%s) return false;\n",
|
|
|
|
+ op_arg_names[0], vector_comps[i],
|
|
|
|
+ op_arg_names[1], vector_comps[i]);
|
|
|
|
+ }
|
|
|
|
+ fprintf(stream, " return true;\n");
|
|
|
|
+ fprintf(stream, "}\n");
|
|
|
|
+ } break;
|
|
|
|
+ default: UNREACHABLE(temp_sprintf("invalid stmt: %d", stmt));
|
|
|
|
+ }
|
|
|
|
+}
|
|
|
|
+
|
|
void gen_vector_op(FILE *stream, Stmt stmt, size_t n, Type type, Op_Type op_type)
|
|
void gen_vector_op(FILE *stream, Stmt stmt, size_t n, Type type, Op_Type op_type)
|
|
{
|
|
{
|
|
Type_Def type_def = type_defs[type];
|
|
Type_Def type_def = type_defs[type];
|
|
@@ -602,6 +631,7 @@ int main()
|
|
fprintf(stream, "#define LA_H_\n");
|
|
fprintf(stream, "#define LA_H_\n");
|
|
fprintf(stream, "\n");
|
|
fprintf(stream, "\n");
|
|
fprintf(stream, "#include <math.h>\n");
|
|
fprintf(stream, "#include <math.h>\n");
|
|
|
|
+ fprintf(stream, "#include <stdbool.h>\n");
|
|
fprintf(stream, "\n");
|
|
fprintf(stream, "\n");
|
|
fprintf(stream, "#ifndef LADEF\n");
|
|
fprintf(stream, "#ifndef LADEF\n");
|
|
fprintf(stream, "#define LADEF static inline\n");
|
|
fprintf(stream, "#define LADEF static inline\n");
|
|
@@ -640,6 +670,7 @@ int main()
|
|
for (Op_Type op = 0; op < COUNT_OPS; ++op) {
|
|
for (Op_Type op = 0; op < COUNT_OPS; ++op) {
|
|
gen_vector_op(stream, STMT_DECL, n, type, op);
|
|
gen_vector_op(stream, STMT_DECL, n, type, op);
|
|
}
|
|
}
|
|
|
|
+
|
|
for (Fun_Type fun = 0; fun < COUNT_FUNS; ++fun) {
|
|
for (Fun_Type fun = 0; fun < COUNT_FUNS; ++fun) {
|
|
if (fun_defs[fun].name_for_type[type]) {
|
|
if (fun_defs[fun].name_for_type[type]) {
|
|
gen_vector_fun(stream, STMT_DECL, n, type, fun);
|
|
gen_vector_fun(stream, STMT_DECL, n, type, fun);
|
|
@@ -651,6 +682,11 @@ int main()
|
|
}
|
|
}
|
|
fprintf(stream, "\n");
|
|
fprintf(stream, "\n");
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ static_assert(COUNT_TYPES == 4, "Amount of types has changed");
|
|
|
|
+ gen_vector_eq(stream, STMT_DECL, n, TYPE_INT);
|
|
|
|
+ gen_vector_eq(stream, STMT_DECL, n, TYPE_UNSIGNED_INT);
|
|
|
|
+ fprintf(stream, "\n");
|
|
}
|
|
}
|
|
|
|
|
|
fprintf(stream, "#endif // LA_H_\n");
|
|
fprintf(stream, "#endif // LA_H_\n");
|
|
@@ -696,6 +732,7 @@ int main()
|
|
gen_vector_op(stream, STMT_IMPL, n, type, op);
|
|
gen_vector_op(stream, STMT_IMPL, n, type, op);
|
|
fputc('\n', stream);
|
|
fputc('\n', stream);
|
|
}
|
|
}
|
|
|
|
+
|
|
for (Fun_Type fun = 0; fun < COUNT_FUNS; ++fun) {
|
|
for (Fun_Type fun = 0; fun < COUNT_FUNS; ++fun) {
|
|
if (fun_defs[fun].name_for_type[type]) {
|
|
if (fun_defs[fun].name_for_type[type]) {
|
|
gen_vector_fun(stream, STMT_IMPL, n, type, fun);
|
|
gen_vector_fun(stream, STMT_IMPL, n, type, fun);
|
|
@@ -709,6 +746,11 @@ int main()
|
|
fputc('\n', stream);
|
|
fputc('\n', stream);
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
+
|
|
|
|
+ static_assert(COUNT_TYPES == 4, "Amount of types has changed");
|
|
|
|
+ gen_vector_eq(stream, STMT_IMPL, n, TYPE_INT);
|
|
|
|
+ gen_vector_eq(stream, STMT_IMPL, n, TYPE_UNSIGNED_INT);
|
|
|
|
+ fputc('\n', stream);
|
|
}
|
|
}
|
|
fprintf(stream, "#endif // LA_IMPLEMENTATION\n");
|
|
fprintf(stream, "#endif // LA_IMPLEMENTATION\n");
|
|
}
|
|
}
|