Skip to content

Commit ad990b2

Browse files
committed
Genericize exp, exp2, log, log2, log10
1 parent e9c35d0 commit ad990b2

File tree

17 files changed

+159
-299
lines changed

17 files changed

+159
-299
lines changed

compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -314,14 +314,6 @@ fn codegen_float_intrinsic_call<'tcx>(
314314
ret: CPlace<'tcx>,
315315
) -> bool {
316316
let (name, arg_count, ty, clif_ty) = match intrinsic {
317-
sym::expf16 => ("expf16", 1, fx.tcx.types.f16, types::F16),
318-
sym::expf32 => ("expf", 1, fx.tcx.types.f32, types::F32),
319-
sym::expf64 => ("exp", 1, fx.tcx.types.f64, types::F64),
320-
sym::expf128 => ("expf128", 1, fx.tcx.types.f128, types::F128),
321-
sym::exp2f16 => ("exp2f16", 1, fx.tcx.types.f16, types::F16),
322-
sym::exp2f32 => ("exp2f", 1, fx.tcx.types.f32, types::F32),
323-
sym::exp2f64 => ("exp2", 1, fx.tcx.types.f64, types::F64),
324-
sym::exp2f128 => ("exp2f128", 1, fx.tcx.types.f128, types::F128),
325317
sym::powif16 => ("__powisf2", 2, fx.tcx.types.f16, types::F16), // compiler-builtins
326318
sym::powif32 => ("__powisf2", 2, fx.tcx.types.f32, types::F32), // compiler-builtins
327319
sym::powif64 => ("__powidf2", 2, fx.tcx.types.f64, types::F64), // compiler-builtins
@@ -330,18 +322,6 @@ fn codegen_float_intrinsic_call<'tcx>(
330322
sym::powf32 => ("powf", 2, fx.tcx.types.f32, types::F32),
331323
sym::powf64 => ("pow", 2, fx.tcx.types.f64, types::F64),
332324
sym::powf128 => ("powf128", 2, fx.tcx.types.f128, types::F128),
333-
sym::logf16 => ("logf16", 1, fx.tcx.types.f16, types::F16),
334-
sym::logf32 => ("logf", 1, fx.tcx.types.f32, types::F32),
335-
sym::logf64 => ("log", 1, fx.tcx.types.f64, types::F64),
336-
sym::logf128 => ("logf128", 1, fx.tcx.types.f128, types::F128),
337-
sym::log2f16 => ("log2f16", 1, fx.tcx.types.f16, types::F16),
338-
sym::log2f32 => ("log2f", 1, fx.tcx.types.f32, types::F32),
339-
sym::log2f64 => ("log2", 1, fx.tcx.types.f64, types::F64),
340-
sym::log2f128 => ("log2f128", 1, fx.tcx.types.f128, types::F128),
341-
sym::log10f16 => ("log10f16", 1, fx.tcx.types.f16, types::F16),
342-
sym::log10f32 => ("log10f", 1, fx.tcx.types.f32, types::F32),
343-
sym::log10f64 => ("log10", 1, fx.tcx.types.f64, types::F64),
344-
sym::log10f128 => ("log10f128", 1, fx.tcx.types.f128, types::F128),
345325
sym::fmaf16 => ("fmaf16", 3, fx.tcx.types.f16, types::F16),
346326
sym::fmaf32 => ("fmaf", 3, fx.tcx.types.f32, types::F32),
347327
sym::fmaf64 => ("fma", 3, fx.tcx.types.f64, types::F64),
@@ -1111,6 +1091,11 @@ fn codegen_regular_intrinsic_call<'tcx>(
11111091
| sym::sqrt
11121092
| sym::sin
11131093
| sym::cos
1094+
| sym::exp
1095+
| sym::exp2
1096+
| sym::log
1097+
| sym::log2
1098+
| sym::log10
11141099
| sym::floor
11151100
| sym::ceil
11161101
| sym::trunc
@@ -1146,6 +1131,26 @@ fn codegen_regular_intrinsic_call<'tcx>(
11461131
(sym::cos, F32) => Err("cosf"),
11471132
(sym::cos, F64) => Err("cos"),
11481133
(sym::cos, F128) => Err("cosf128"),
1134+
(sym::exp, F16) => Err("expf16"),
1135+
(sym::exp, F32) => Err("expf"),
1136+
(sym::exp, F64) => Err("exp"),
1137+
(sym::exp, F128) => Err("expf128"),
1138+
(sym::exp2, F16) => Err("exp2f16"),
1139+
(sym::exp2, F32) => Err("exp2f"),
1140+
(sym::exp2, F64) => Err("exp2"),
1141+
(sym::exp2, F128) => Err("exp2f128"),
1142+
(sym::log, F16) => Err("logf16"),
1143+
(sym::log, F32) => Err("logf"),
1144+
(sym::log, F64) => Err("log"),
1145+
(sym::log, F128) => Err("logf128"),
1146+
(sym::log2, F16) => Err("log2f16"),
1147+
(sym::log2, F32) => Err("log2f"),
1148+
(sym::log2, F64) => Err("log2"),
1149+
(sym::log2, F128) => Err("log2f128"),
1150+
(sym::log10, F16) => Err("log10f16"),
1151+
(sym::log10, F32) => Err("log10f"),
1152+
(sym::log10, F64) => Err("log10"),
1153+
(sym::log10, F128) => Err("log10f128"),
11491154
(sym::floor, F32 | F64) => Ok(fx.bcx.ins().floor(x)),
11501155
(sym::floor, F16) => Err("floorf16"),
11511156
(sym::floor, F128) => Err("floorf128"),

compiler/rustc_codegen_gcc/src/intrinsic/mod.rs

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,16 +49,6 @@ fn get_simple_intrinsic<'gcc, 'tcx>(
4949
sym::powif64 => "__builtin_powi",
5050
sym::powf32 => "powf",
5151
sym::powf64 => "pow",
52-
sym::expf32 => "expf",
53-
sym::expf64 => "exp",
54-
sym::exp2f32 => "exp2f",
55-
sym::exp2f64 => "exp2",
56-
sym::logf32 => "logf",
57-
sym::logf64 => "log",
58-
sym::log10f32 => "log10f",
59-
sym::log10f64 => "log10",
60-
sym::log2f32 => "log2f",
61-
sym::log2f64 => "log2",
6252
sym::fmaf32 => "fmaf",
6353
sym::fmaf64 => "fma",
6454
// FIXME: calling `fma` from libc without FMA target feature uses expensive software emulation
@@ -419,6 +409,11 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
419409
| sym::sqrt
420410
| sym::sin
421411
| sym::cos
412+
| sym::exp
413+
| sym::exp2
414+
| sym::log
415+
| sym::log2
416+
| sym::log10
422417
| sym::floor
423418
| sym::ceil
424419
| sym::trunc
@@ -451,6 +446,16 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc
451446
(sym::sin, F64) => Builtin("sin"),
452447
(sym::cos, F32) => Builtin("cosf"),
453448
(sym::cos, F64) => Builtin("cos"),
449+
(sym::exp, F32) => Builtin("expf"),
450+
(sym::exp, F64) => Builtin("exp"),
451+
(sym::exp2, F32) => Builtin("exp2f"),
452+
(sym::exp2, F64) => Builtin("exp2"),
453+
(sym::log, F32) => Builtin("logf"),
454+
(sym::log, F64) => Builtin("log"),
455+
(sym::log2, F32) => Builtin("log2f"),
456+
(sym::log2, F64) => Builtin("log2"),
457+
(sym::log10, F32) => Builtin("log10f"),
458+
(sym::log10, F64) => Builtin("log10"),
454459
(sym::floor, F16) => BuiltinF16Cast("__builtin_floorf"),
455460
(sym::floor, F32) => Builtin("floorf"),
456461
(sym::floor, F64) => Builtin("floor"),

compiler/rustc_codegen_llvm/src/intrinsic.rs

Lines changed: 10 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -58,31 +58,6 @@ fn call_simple_intrinsic<'ll, 'tcx>(
5858
sym::powf64 => ("llvm.pow", &[bx.type_f64()]),
5959
sym::powf128 => ("llvm.pow", &[bx.type_f128()]),
6060

61-
sym::expf16 => ("llvm.exp", &[bx.type_f16()]),
62-
sym::expf32 => ("llvm.exp", &[bx.type_f32()]),
63-
sym::expf64 => ("llvm.exp", &[bx.type_f64()]),
64-
sym::expf128 => ("llvm.exp", &[bx.type_f128()]),
65-
66-
sym::exp2f16 => ("llvm.exp2", &[bx.type_f16()]),
67-
sym::exp2f32 => ("llvm.exp2", &[bx.type_f32()]),
68-
sym::exp2f64 => ("llvm.exp2", &[bx.type_f64()]),
69-
sym::exp2f128 => ("llvm.exp2", &[bx.type_f128()]),
70-
71-
sym::logf16 => ("llvm.log", &[bx.type_f16()]),
72-
sym::logf32 => ("llvm.log", &[bx.type_f32()]),
73-
sym::logf64 => ("llvm.log", &[bx.type_f64()]),
74-
sym::logf128 => ("llvm.log", &[bx.type_f128()]),
75-
76-
sym::log10f16 => ("llvm.log10", &[bx.type_f16()]),
77-
sym::log10f32 => ("llvm.log10", &[bx.type_f32()]),
78-
sym::log10f64 => ("llvm.log10", &[bx.type_f64()]),
79-
sym::log10f128 => ("llvm.log10", &[bx.type_f128()]),
80-
81-
sym::log2f16 => ("llvm.log2", &[bx.type_f16()]),
82-
sym::log2f32 => ("llvm.log2", &[bx.type_f32()]),
83-
sym::log2f64 => ("llvm.log2", &[bx.type_f64()]),
84-
sym::log2f128 => ("llvm.log2", &[bx.type_f128()]),
85-
8661
sym::fmaf16 => ("llvm.fma", &[bx.type_f16()]),
8762
sym::fmaf32 => ("llvm.fma", &[bx.type_f32()]),
8863
sym::fmaf64 => ("llvm.fma", &[bx.type_f64()]),
@@ -458,6 +433,11 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
458433
| sym::sqrt
459434
| sym::sin
460435
| sym::cos
436+
| sym::exp
437+
| sym::exp2
438+
| sym::log
439+
| sym::log2
440+
| sym::log10
461441
| sym::floor
462442
| sym::ceil
463443
| sym::trunc
@@ -473,6 +453,11 @@ impl<'ll, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'_, 'll, 'tcx> {
473453
sym::sqrt => "llvm.sqrt",
474454
sym::sin => "llvm.sin",
475455
sym::cos => "llvm.cos",
456+
sym::exp => "llvm.exp",
457+
sym::exp2 => "llvm.exp2",
458+
sym::log => "llvm.log",
459+
sym::log2 => "llvm.log2",
460+
sym::log10 => "llvm.log10",
476461
sym::floor => "llvm.floor",
477462
sym::ceil => "llvm.ceil",
478463
sym::trunc => "llvm.trunc",

compiler/rustc_hir_analysis/src/check/intrinsic.rs

Lines changed: 8 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -97,14 +97,8 @@ fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: LocalDefId) -> hi
9797
| sym::ctpop
9898
| sym::cttz
9999
| sym::discriminant_value
100-
| sym::exp2f16
101-
| sym::exp2f32
102-
| sym::exp2f64
103-
| sym::exp2f128
104-
| sym::expf16
105-
| sym::expf32
106-
| sym::expf64
107-
| sym::expf128
100+
| sym::exp
101+
| sym::exp2
108102
| sym::fabs
109103
| sym::fadd_algebraic
110104
| sym::fdiv_algebraic
@@ -123,18 +117,9 @@ fn intrinsic_operation_unsafety(tcx: TyCtxt<'_>, intrinsic_id: LocalDefId) -> hi
123117
| sym::frem_algebraic
124118
| sym::fsub_algebraic
125119
| sym::is_val_statically_known
126-
| sym::log2f16
127-
| sym::log2f32
128-
| sym::log2f64
129-
| sym::log2f128
130-
| sym::log10f16
131-
| sym::log10f32
132-
| sym::log10f64
133-
| sym::log10f128
134-
| sym::logf16
135-
| sym::logf32
136-
| sym::logf64
137-
| sym::logf128
120+
| sym::log
121+
| sym::log2
122+
| sym::log10
138123
| sym::maximum_number_nsz_f16
139124
| sym::maximum_number_nsz_f32
140125
| sym::maximum_number_nsz_f64
@@ -386,30 +371,9 @@ pub(crate) fn check_intrinsic_type(
386371
sym::powf64 => (0, 0, vec![tcx.types.f64, tcx.types.f64], tcx.types.f64),
387372
sym::powf128 => (0, 0, vec![tcx.types.f128, tcx.types.f128], tcx.types.f128),
388373

389-
sym::expf16 => (0, 0, vec![tcx.types.f16], tcx.types.f16),
390-
sym::expf32 => (0, 0, vec![tcx.types.f32], tcx.types.f32),
391-
sym::expf64 => (0, 0, vec![tcx.types.f64], tcx.types.f64),
392-
sym::expf128 => (0, 0, vec![tcx.types.f128], tcx.types.f128),
393-
394-
sym::exp2f16 => (0, 0, vec![tcx.types.f16], tcx.types.f16),
395-
sym::exp2f32 => (0, 0, vec![tcx.types.f32], tcx.types.f32),
396-
sym::exp2f64 => (0, 0, vec![tcx.types.f64], tcx.types.f64),
397-
sym::exp2f128 => (0, 0, vec![tcx.types.f128], tcx.types.f128),
398-
399-
sym::logf16 => (0, 0, vec![tcx.types.f16], tcx.types.f16),
400-
sym::logf32 => (0, 0, vec![tcx.types.f32], tcx.types.f32),
401-
sym::logf64 => (0, 0, vec![tcx.types.f64], tcx.types.f64),
402-
sym::logf128 => (0, 0, vec![tcx.types.f128], tcx.types.f128),
403-
404-
sym::log10f16 => (0, 0, vec![tcx.types.f16], tcx.types.f16),
405-
sym::log10f32 => (0, 0, vec![tcx.types.f32], tcx.types.f32),
406-
sym::log10f64 => (0, 0, vec![tcx.types.f64], tcx.types.f64),
407-
sym::log10f128 => (0, 0, vec![tcx.types.f128], tcx.types.f128),
408-
409-
sym::log2f16 => (0, 0, vec![tcx.types.f16], tcx.types.f16),
410-
sym::log2f32 => (0, 0, vec![tcx.types.f32], tcx.types.f32),
411-
sym::log2f64 => (0, 0, vec![tcx.types.f64], tcx.types.f64),
412-
sym::log2f128 => (0, 0, vec![tcx.types.f128], tcx.types.f128),
374+
sym::exp | sym::exp2 | sym::log | sym::log10 | sym::log2 => {
375+
(1, 0, vec![param(0)], param(0))
376+
}
413377

414378
sym::fmaf16 => (0, 0, vec![tcx.types.f16, tcx.types.f16, tcx.types.f16], tcx.types.f16),
415379
sym::fmaf32 => (0, 0, vec![tcx.types.f32, tcx.types.f32, tcx.types.f32], tcx.types.f32),

compiler/rustc_span/src/symbol.rs

Lines changed: 5 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -869,16 +869,10 @@ symbols! {
869869
exhaustive_integer_patterns,
870870
exhaustive_patterns,
871871
existential_type,
872-
exp2f16,
873-
exp2f32,
874-
exp2f64,
875-
exp2f128,
872+
exp,
873+
exp2,
876874
expect,
877875
expected,
878-
expf16,
879-
expf32,
880-
expf64,
881-
expf128,
882876
explicit_extern_abis,
883877
explicit_generic_args_with_impl_trait,
884878
explicit_tail_calls,
@@ -1156,19 +1150,10 @@ symbols! {
11561150
loaded_from_disk,
11571151
local,
11581152
local_inner_macros,
1159-
log2f16,
1160-
log2f32,
1161-
log2f64,
1162-
log2f128,
1163-
log10f16,
1164-
log10f32,
1165-
log10f64,
1166-
log10f128,
1153+
log,
1154+
log2,
1155+
log10,
11671156
log_syntax,
1168-
logf16,
1169-
logf32,
1170-
logf64,
1171-
logf128,
11721157
loongarch32,
11731158
loongarch64,
11741159
loongarch_target_feature,

0 commit comments

Comments
 (0)