Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 8c8fc6a

Browse files
committed
Use native cranelift instructions when lowering float intrinsics
1 parent 0c5b61f commit 8c8fc6a

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

src/intrinsics/mod.rs

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,38 @@ fn codegen_float_intrinsic_call<'tcx>(
301301
_ => unreachable!(),
302302
};
303303

304-
let res = fx.easy_call(name, &args, ty);
304+
let layout = fx.layout_of(ty);
305+
let res = match intrinsic {
306+
sym::copysignf32 | sym::copysignf64 => {
307+
let a = args[0].load_scalar(fx);
308+
let b = args[1].load_scalar(fx);
309+
CValue::by_val(fx.bcx.ins().fcopysign(a, b), layout)
310+
}
311+
sym::fabsf32
312+
| sym::fabsf64
313+
| sym::floorf32
314+
| sym::floorf64
315+
| sym::ceilf32
316+
| sym::ceilf64
317+
| sym::truncf32
318+
| sym::truncf64 => {
319+
let a = args[0].load_scalar(fx);
320+
321+
let val = match intrinsic {
322+
sym::fabsf32 | sym::fabsf64 => fx.bcx.ins().fabs(a),
323+
sym::floorf32 | sym::floorf64 => fx.bcx.ins().floor(a),
324+
sym::ceilf32 | sym::ceilf64 => fx.bcx.ins().ceil(a),
325+
sym::truncf32 | sym::truncf64 => fx.bcx.ins().trunc(a),
326+
_ => unreachable!(),
327+
};
328+
329+
CValue::by_val(val, layout)
330+
}
331+
// These intrinsics aren't supported natively by Cranelift.
332+
// Lower them to a libcall.
333+
_ => fx.easy_call(name, &args, ty),
334+
};
335+
305336
ret.write_cvalue(fx, res);
306337

307338
true

0 commit comments

Comments
 (0)