Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/llvm.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,9 @@ extern char *jitc_llvm_target_features;
/// Vector width of code generated by the LLVM backend
extern uint32_t jitc_llvm_vector_width;

/// CPU FMA instruction set support
extern bool jitc_llvm_fma_support;

/// Should the LLVM IR use typed (e.g., "i8*") or untyped ("ptr") pointers?
extern bool jitc_llvm_opaque_pointers;

Expand Down
6 changes: 6 additions & 0 deletions src/llvm_core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,9 @@ char *jitc_llvm_target_features = nullptr;
/// Vector width of code generated by the LLVM backend
uint32_t jitc_llvm_vector_width = 0;

/// CPU FMA instruction set support
bool jitc_llvm_fma_support = false;

/// Should the LLVM IR use typed (e.g., "i8*") or untyped ("ptr") pointers?
bool jitc_llvm_opaque_pointers = false;

Expand Down Expand Up @@ -103,6 +106,9 @@ bool jitc_llvm_init() {
}
}

if (strstr(jitc_llvm_target_features, "+fma"))
jitc_llvm_fma_support = true;

jitc_llvm_vector_width = 1;

if (strstr(jitc_llvm_target_features, "+sse4.2"))
Expand Down
15 changes: 11 additions & 4 deletions src/llvm_eval.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -519,10 +519,17 @@ static void jitc_llvm_render_var(uint32_t index, Variable *v) {

case VarKind::Fma:
if (jitc_is_float(v)) {
fmt_intrinsic("declare $T @llvm.fma.v$w$h($T, $T, $T)\n",
v, v, a0, a1, a2);
fmt(" $v = call $T @llvm.fma.v$w$h($V, $V, $V)\n",
v, v, v, a0, a1, a2);
if(jitc_llvm_fma_support) {
fmt_intrinsic("declare $T @llvm.fma.v$w$h($T, $T, $T)\n",
v, v, a0, a1, a2);
fmt(" $v = call $T @llvm.fma.v$w$h($V, $V, $V)\n",
v, v, v, a0, a1, a2);
} else {
fmt(" $v_0 = fmul $V, $v\n"
" $v = fadd $V_0, $v\n",
v, a0, a1,
v, v, a2);
}
} else {
fmt(" $v_0 = mul $V, $v\n"
" $v = add $V_0, $v\n",
Expand Down