aboutsummaryrefslogtreecommitdiff
path: root/src/llvm_backend_proc.cpp
diff options
context:
space:
mode:
authorgingerBill <bill@gingerbill.org>2022-05-26 18:06:26 +0100
committergingerBill <bill@gingerbill.org>2022-05-26 18:06:26 +0100
commit421d45a7a76e53946e7441212af9d08a0d93ff68 (patch)
tree557382f5a94f47c7de7ad35a7187972ce9adda52 /src/llvm_backend_proc.cpp
parent20e7b5c88acb2e0cee64ccdec7247227306a345f (diff)
Add `intrinsics.fused_mul_add`
Diffstat (limited to 'src/llvm_backend_proc.cpp')
-rw-r--r--src/llvm_backend_proc.cpp25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/llvm_backend_proc.cpp b/src/llvm_backend_proc.cpp
index 4c4000fec..a5dda7815 100644
--- a/src/llvm_backend_proc.cpp
+++ b/src/llvm_backend_proc.cpp
@@ -2005,6 +2005,31 @@ lbValue lb_build_builtin_proc(lbProcedure *p, Ast *expr, TypeAndValue const &tv,
return res;
}
+ case BuiltinProc_fused_mul_add:
+ {
+ Type *type = tv.type;
+ lbValue x = lb_emit_conv(p, lb_build_expr(p, ce->args[0]), type);
+ lbValue y = lb_emit_conv(p, lb_build_expr(p, ce->args[1]), type);
+ lbValue z = lb_emit_conv(p, lb_build_expr(p, ce->args[2]), type);
+
+
+ char const *name = "llvm.fma";
+ LLVMTypeRef types[1] = {lb_type(p->module, type)};
+ unsigned id = LLVMLookupIntrinsicID(name, gb_strlen(name));
+ GB_ASSERT_MSG(id != 0, "Unable to find %s.%s", name, LLVMPrintTypeToString(types[0]));
+ LLVMValueRef ip = LLVMGetIntrinsicDeclaration(p->module->mod, id, types, gb_count_of(types));
+
+ LLVMValueRef args[3] = {};
+ args[0] = x.value;
+ args[1] = y.value;
+ args[2] = z.value;
+
+ lbValue res = {};
+ res.value = LLVMBuildCall(p->builder, ip, args, gb_count_of(args), "");
+ res.type = type;
+ return res;
+ }
+
case BuiltinProc_mem_copy:
{
lbValue dst = lb_build_expr(p, ce->args[0]);