Skip to content
Open
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
12 changes: 12 additions & 0 deletions hugr-llvm/src/extension/float.rs
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,17 @@ fn emit_float_op<'c, H: HugrView<Node = Node>>(
.as_basic_value_enum(),
])
}),
FloatOps::fround => emit_custom_unary_op(context, args, |ctx, v, _| {
let float_ty = ctx.iw_context().f64_type().as_basic_type_enum();
let func = get_intrinsic(ctx.get_current_module(), "llvm.round.f64", [float_ty])?;
Ok(vec![
ctx.builder()
.build_call(func, &[v.into()], "")?
.try_as_basic_value()
.unwrap_basic()
.as_basic_value_enum(),
])
}),
// Missing ops, not supported by inkwell
FloatOps::fmax
| FloatOps::fmin
Expand Down Expand Up @@ -215,6 +226,7 @@ mod test {
#[case::fmul(FloatOps::fmul)]
#[case::fdiv(FloatOps::fdiv)]
#[case::fpow(FloatOps::fpow)]
#[case::fround(FloatOps::fround)]
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The thing that worries me here is that fround appears to be unary, whereas all the others seem to be binary (taking two floats)....

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not true, fneg is also unary and appears in the test cases.

fn float_operations(mut llvm_ctx: TestContext, #[case] op: FloatOps) {
let name: &str = op.into();
let hugr = test_float_op(op);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
---
source: hugr-llvm/src/extension/float.rs
assertion_line: 234
expression: mod_str
---
; ModuleID = 'test_context'
source_filename = "test_context"

define internal double @_hl.main.1(double %0) {
alloca_block:
br label %entry_block

entry_block: ; preds = %alloca_block
%1 = call double @llvm.round.f64(double %0)
ret double %1
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.round.f64(double) #0

attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
source: hugr-llvm/src/extension/float.rs
assertion_line: 234
expression: mod_str
---
; ModuleID = 'test_context'
source_filename = "test_context"

define internal double @_hl.main.1(double %0) {
alloca_block:
%"0" = alloca double, align 8
%"2_0" = alloca double, align 8
%"4_0" = alloca double, align 8
br label %entry_block

entry_block: ; preds = %alloca_block
store double %0, ptr %"2_0", align 8
%"2_01" = load double, ptr %"2_0", align 8
%1 = call double @llvm.round.f64(double %"2_01")
store double %1, ptr %"4_0", align 8
%"4_02" = load double, ptr %"4_0", align 8
store double %"4_02", ptr %"0", align 8
%"03" = load double, ptr %"0", align 8
ret double %"03"
}

; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)
declare double @llvm.round.f64(double) #0

attributes #0 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }
Loading