-
-
Notifications
You must be signed in to change notification settings - Fork 15.4k
Make sin, cos, exp, exp2, log, log2, log10 generic #160989
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
N1ark
wants to merge
3
commits into
rust-lang:main
Choose a base branch
from
N1ark:08-12-generic-float-intrinsincs
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -62,22 +62,8 @@ fn get_simple_intrinsic<'gcc, 'tcx>( | |
| sym::sqrtf64 => "sqrt", | ||
| sym::powif32 => "__builtin_powif", | ||
| sym::powif64 => "__builtin_powi", | ||
| sym::sinf32 => "sinf", | ||
| sym::sinf64 => "sin", | ||
| sym::cosf32 => "cosf", | ||
| sym::cosf64 => "cos", | ||
| sym::powf32 => "powf", | ||
| sym::powf64 => "pow", | ||
| sym::expf32 => "expf", | ||
| sym::expf64 => "exp", | ||
| sym::exp2f32 => "exp2f", | ||
| sym::exp2f64 => "exp2", | ||
| sym::logf32 => "logf", | ||
| sym::logf64 => "log", | ||
| sym::log10f32 => "log10f", | ||
| sym::log10f64 => "log10", | ||
| sym::log2f32 => "log2f", | ||
| sym::log2f64 => "log2", | ||
| sym::fmaf32 => "fmaf", | ||
| sym::fmaf64 => "fma", | ||
| // FIXME: calling `fma` from libc without FMA target feature uses expensive software emulation | ||
|
|
@@ -117,16 +103,18 @@ fn get_simple_function_f128<'gcc, 'tcx>( | |
| let f128_type = cx.type_f128(); | ||
| let func_name = match name { | ||
| sym::ceilf128 => "ceilf128", | ||
| sym::cos => "cosf128", | ||
| sym::fabs => "fabsf128", | ||
| sym::expf128 => "expf128", | ||
| sym::exp2f128 => "exp2f128", | ||
| sym::exp => "expf128", | ||
| sym::exp2 => "exp2f128", | ||
| sym::floorf128 => "floorf128", | ||
| sym::logf128 => "logf128", | ||
| sym::log2f128 => "log2f128", | ||
| sym::log10f128 => "log10f128", | ||
| sym::log => "logf128", | ||
| sym::log2 => "log2f128", | ||
| sym::log10 => "log10f128", | ||
| sym::truncf128 => "truncf128", | ||
| sym::roundf128 => "roundf128", | ||
| sym::round_ties_even_f128 => "roundevenf128", | ||
| sym::sin => "sinf128", | ||
| sym::sqrtf128 => "sqrtf128", | ||
| _ => span_bug!(span, "used get_simple_function_f128 for non-unary f128 intrinsic"), | ||
| }; | ||
|
|
@@ -140,24 +128,6 @@ fn get_simple_function_f128<'gcc, 'tcx>( | |
| ) | ||
| } | ||
|
|
||
| fn generic_f16_builtin<'gcc, 'tcx>( | ||
| cx: &CodegenCx<'gcc, 'tcx>, | ||
| name: Symbol, | ||
| args: &[OperandRef<'tcx, RValue<'gcc>>], | ||
| ) -> RValue<'gcc> { | ||
| let f32_type = cx.type_f32(); | ||
| let builtin_name = match name { | ||
| sym::fabs => "fabsf", | ||
| _ => unreachable!(), | ||
| }; | ||
|
|
||
| let func = cx.context.get_builtin_function(builtin_name); | ||
| let args: Vec<_> = | ||
| args.iter().map(|arg| cx.context.new_cast(None, arg.immediate(), f32_type)).collect(); | ||
| let result = cx.context.new_call(None, func, &args); | ||
| cx.context.new_cast(None, result, cx.type_f16()) | ||
| } | ||
|
|
||
| fn f16_builtin<'gcc, 'tcx>( | ||
| cx: &CodegenCx<'gcc, 'tcx>, | ||
| name: Symbol, | ||
|
|
@@ -167,17 +137,19 @@ fn f16_builtin<'gcc, 'tcx>( | |
| let builtin_name = match name { | ||
| sym::ceilf16 => "__builtin_ceilf", | ||
| sym::copysignf16 => "__builtin_copysignf", | ||
| sym::expf16 => "expf", | ||
| sym::exp2f16 => "exp2f", | ||
| sym::cos => "cosf", | ||
| sym::exp => "expf", | ||
| sym::exp2 => "exp2f", | ||
| sym::fabs => "fabsf", | ||
| sym::floorf16 => "__builtin_floorf", | ||
| sym::fmaf16 => "fmaf", | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is wrong, |
||
| sym::logf16 => "logf", | ||
| sym::log2f16 => "log2f", | ||
| sym::log10f16 => "log10f", | ||
| sym::log => "logf", | ||
| sym::log2 => "log2f", | ||
| sym::log10 => "log10f", | ||
| sym::powf16 => "__builtin_powf", | ||
| sym::roundf16 => "__builtin_roundf", | ||
| sym::round_ties_even_f16 => "__builtin_rintf", | ||
| sym::sin => "sinf", | ||
| sym::sqrtf16 => "__builtin_sqrtf", | ||
| sym::truncf16 => "__builtin_truncf", | ||
| _ => unreachable!(), | ||
|
|
@@ -246,13 +218,8 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc | |
| } | ||
| sym::ceilf16 | ||
| | sym::copysignf16 | ||
| | sym::expf16 | ||
| | sym::exp2f16 | ||
| | sym::floorf16 | ||
| | sym::fmaf16 | ||
| | sym::logf16 | ||
| | sym::log2f16 | ||
| | sym::log10f16 | ||
| | sym::powf16 | ||
| | sym::roundf16 | ||
| | sym::round_ties_even_f16 | ||
|
|
@@ -264,11 +231,6 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc | |
| | sym::roundf128 | ||
| | sym::round_ties_even_f128 | ||
| | sym::sqrtf128 | ||
| | sym::expf128 | ||
| | sym::exp2f128 | ||
| | sym::logf128 | ||
| | sym::log2f128 | ||
| | sym::log10f128 | ||
| if self.cx.supports_f128_type => | ||
| { | ||
| let func = get_simple_function_f128(span, self, name); | ||
|
|
@@ -452,16 +414,55 @@ impl<'a, 'gcc, 'tcx> IntrinsicCallBuilderMethods<'tcx> for Builder<'a, 'gcc, 'tc | |
| } | ||
| } | ||
| } | ||
| sym::fabs => 'fabs: { | ||
| sym::fabs | ||
| | sym::exp | ||
| | sym::exp2 | ||
| | sym::log | ||
| | sym::log10 | ||
| | sym::log2 | ||
| | sym::sin | ||
| | sym::cos => 'float_unop: { | ||
| let ty = args[0].layout.ty; | ||
| let ty::Float(float_ty) = *ty.kind() else { | ||
| span_bug!(span, "expected float type for fabs intrinsic: {:?}", ty); | ||
| }; | ||
| let func = match float_ty { | ||
| ty::FloatTy::F16 => break 'fabs generic_f16_builtin(self, name, args), | ||
| ty::FloatTy::F32 => self.context.get_builtin_function("fabsf"), | ||
| ty::FloatTy::F64 => self.context.get_builtin_function("fabs"), | ||
| ty::FloatTy::F128 => get_simple_function_f128(span, self, name), | ||
| use ty::FloatTy::*; | ||
| let func = match (name, float_ty) { | ||
| (sym::fabs, F32) => self.context.get_builtin_function("fabsf"), | ||
| (sym::fabs, F64) => self.context.get_builtin_function("fabs"), | ||
|
|
||
| (sym::exp, F32) => self.context.get_builtin_function("expf"), | ||
| (sym::exp, F64) => self.context.get_builtin_function("exp"), | ||
|
|
||
| (sym::exp2, F32) => self.context.get_builtin_function("exp2f"), | ||
| (sym::exp2, F64) => self.context.get_builtin_function("exp2"), | ||
|
|
||
| (sym::log, F32) => self.context.get_builtin_function("logf"), | ||
| (sym::log, F64) => self.context.get_builtin_function("log"), | ||
|
|
||
| (sym::log10, F32) => self.context.get_builtin_function("log10f"), | ||
| (sym::log10, F64) => self.context.get_builtin_function("log10"), | ||
|
|
||
| (sym::log2, F32) => self.context.get_builtin_function("log2f"), | ||
| (sym::log2, F64) => self.context.get_builtin_function("log2"), | ||
|
|
||
| (sym::sin, F32) => self.context.get_builtin_function("sinf"), | ||
| (sym::sin, F64) => self.context.get_builtin_function("sin"), | ||
|
|
||
| (sym::cos, F32) => self.context.get_builtin_function("cosf"), | ||
| (sym::cos, F64) => self.context.get_builtin_function("cos"), | ||
|
|
||
| (_, F32 | F64) => unreachable!(), | ||
|
|
||
| (_, F16) => break 'float_unop f16_builtin(self, name, args), | ||
| (_, F128) => { | ||
| if !self.cx.supports_f128_type { | ||
| // Fall back to default body | ||
| let fallback = Instance::new_raw(instance.def_id(), instance.args); | ||
| return IntrinsicResult::Fallback(fallback); | ||
| } | ||
| get_simple_function_f128(span, self, name) | ||
| } | ||
| }; | ||
| self.cx.context.new_call( | ||
| self.location, | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We could use a fallback for these too, it's just zeroing the sign bit