diff options
| author | bjorn3 <bjorn3@users.noreply.github.com> | 2022-01-09 17:19:11 +0100 |
|---|---|---|
| committer | bjorn3 <bjorn3@users.noreply.github.com> | 2022-01-09 17:19:11 +0100 |
| commit | baad993daead9ddc127dd897035f6616f4e367f6 (patch) | |
| tree | ca8754f9e0c4d324dca7193a22375b36109fcf62 /src | |
| parent | 300974714c96524806b44e36c5d6a7d0e854fc3e (diff) | |
| download | rust-baad993daead9ddc127dd897035f6616f4e367f6.tar.gz rust-baad993daead9ddc127dd897035f6616f4e367f6.zip | |
Dedup codegen_operand calls in codegen_float_intrinsic_call
This reduces the amount of llvm ir lines for this function by a little over half from 1662 to 781.
Diffstat (limited to 'src')
| -rw-r--r-- | src/intrinsics/mod.rs | 105 |
1 files changed, 58 insertions, 47 deletions
diff --git a/src/intrinsics/mod.rs b/src/intrinsics/mod.rs index 0d667847b9a..8da6c7ae9eb 100644 --- a/src/intrinsics/mod.rs +++ b/src/intrinsics/mod.rs @@ -414,73 +414,84 @@ fn codegen_float_intrinsic_call<'tcx>( ) -> bool { macro call_intrinsic_match { ($fx:expr, $intrinsic:expr, $ret:expr, $args:expr, $( - $name:ident($($arg:ident),*) -> $ty:ident => $func:ident, + $name:ident($arg_count:literal) -> $ty:ident => $func:ident, )*) => { - let res = match $intrinsic { + let (name, arg_count, ty) = match $intrinsic { $( - sym::$name => { - if let [$(ref $arg),*] = *$args { - let args = [$(codegen_operand($fx, $arg),)*]; - Some($fx.easy_call(stringify!($func), &args, $fx.tcx.types.$ty)) - } else { - None - } - } + sym::$name => (stringify!($func), $arg_count, $fx.tcx.types.$ty), )* _ => return false, }; - if let Some(res) = res { - $ret.write_cvalue($fx, res); - } else { + if $args.len() != arg_count { bug!("wrong number of args for intrinsic {:?}", $intrinsic); } + let (a, b, c); + let args = match $args { + [x] => { + a = [codegen_operand($fx, x)]; + &a as &[_] + } + [x, y] => { + b = [codegen_operand($fx, x), codegen_operand($fx, y)]; + &b + } + [x, y, z] => { + c = [codegen_operand($fx, x), codegen_operand($fx, y), codegen_operand($fx, z)]; + &c + } + _ => unreachable!(), + }; + + let res = $fx.easy_call(name, &args, ty); + $ret.write_cvalue($fx, res); + true } } call_intrinsic_match! { fx, intrinsic, ret, args, - expf32(flt) -> f32 => expf, - expf64(flt) -> f64 => exp, - exp2f32(flt) -> f32 => exp2f, - exp2f64(flt) -> f64 => exp2, - sqrtf32(flt) -> f32 => sqrtf, - sqrtf64(flt) -> f64 => sqrt, - powif32(a, x) -> f32 => __powisf2, // compiler-builtins - powif64(a, x) -> f64 => __powidf2, // compiler-builtins - powf32(a, x) -> f32 => powf, - powf64(a, x) -> f64 => pow, - logf32(flt) -> f32 => logf, - logf64(flt) -> f64 => log, - log2f32(flt) -> f32 => log2f, - log2f64(flt) -> f64 => log2, - log10f32(flt) -> f32 => log10f, - log10f64(flt) -> f64 => log10, - fabsf32(flt) -> f32 => fabsf, - fabsf64(flt) -> f64 => fabs, - fmaf32(x, y, z) -> f32 => fmaf, - fmaf64(x, y, z) -> f64 => fma, - copysignf32(x, y) -> f32 => copysignf, - copysignf64(x, y) -> f64 => copysign, + expf32(1) -> f32 => expf, + expf64(1) -> f64 => exp, + exp2f32(1) -> f32 => exp2f, + exp2f64(1) -> f64 => exp2, + sqrtf32(1) -> f32 => sqrtf, + sqrtf64(1) -> f64 => sqrt, + powif32(2) -> f32 => __powisf2, // compiler-builtins + powif64(2) -> f64 => __powidf2, // compiler-builtins + powf32(2) -> f32 => powf, + powf64(2) -> f64 => pow, + logf32(1) -> f32 => logf, + logf64(1) -> f64 => log, + log2f32(1) -> f32 => log2f, + log2f64(1) -> f64 => log2, + log10f32(1) -> f32 => log10f, + log10f64(1) -> f64 => log10, + fabsf32(1) -> f32 => fabsf, + fabsf64(1) -> f64 => fabs, + fmaf32(3) -> f32 => fmaf, + fmaf64(3) -> f64 => fma, + copysignf32(2) -> f32 => copysignf, + copysignf64(2) -> f64 => copysign, // rounding variants // FIXME use clif insts - floorf32(flt) -> f32 => floorf, - floorf64(flt) -> f64 => floor, - ceilf32(flt) -> f32 => ceilf, - ceilf64(flt) -> f64 => ceil, - truncf32(flt) -> f32 => truncf, - truncf64(flt) -> f64 => trunc, - roundf32(flt) -> f32 => roundf, - roundf64(flt) -> f64 => round, + floorf32(1) -> f32 => floorf, + floorf64(1) -> f64 => floor, + ceilf32(1) -> f32 => ceilf, + ceilf64(1) -> f64 => ceil, + truncf32(1) -> f32 => truncf, + truncf64(1) -> f64 => trunc, + roundf32(1) -> f32 => roundf, + roundf64(1) -> f64 => round, // trigonometry - sinf32(flt) -> f32 => sinf, - sinf64(flt) -> f64 => sin, - cosf32(flt) -> f32 => cosf, - cosf64(flt) -> f64 => cos, + sinf32(1) -> f32 => sinf, + sinf64(1) -> f64 => sin, + cosf32(1) -> f32 => cosf, + cosf64(1) -> f64 => cos, } } |
