mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Christian Schrefl <chrisi.schrefl@gmail.com>
To: "Miguel Ojeda" <ojeda@kernel.org>,
	"Alex Gaynor" <alex.gaynor@gmail.com>,
	"Boqun Feng" <boqun.feng@gmail.com>,
	"Gary Guo" <gary@garyguo.net>,
	"Björn Roy Baron" <bjorn3_gh@protonmail.com>,
	"Benno Lossin" <benno.lossin@proton.me>,
	"Andreas Hindborg" <a.hindborg@kernel.org>,
	"Alice Ryhl" <aliceryhl@google.com>,
	"Trevor Gross" <tmgross@umich.edu>,
	"Arnd Bergmann" <arnd@arndb.de>
Cc: Andrew Lunn <andrew@lunn.ch>,
	rust-for-linux@vger.kernel.org,  linux-kernel@vger.kernel.org,
	Christian Schrefl <chrisi.schrefl@gmail.com>
Subject: [PATCH RFC WIP] rust: remove x86 panicking intrinsics.
Date: Sat, 01 Feb 2025 15:39:16 +0100	[thread overview]
Message-ID: <20250201-remove_intrinsic-v1-1-4283ce8e4764@gmail.com> (raw)

This removes the panicking implementation of the x86 intrinsics.

This requires a PR [0] for the rust core library to remove the need for
the `__udivti3` intrinsic. This PR disables formatting support for the
`i/u128` rust primitives when the `no_iu128_fmt` config option is set.

In order to remove the need for the other intrinsics a recent rust
version is required (Tested with 1.84).

Link: https://github.com/rust-lang/rust/pull/136385 [0]
Signed-off-by: Christian Schrefl <chrisi.schrefl@gmail.com>
---
This patch removes the need to use `define_panicking_intrinsics` for
adding stub intrinsics implementations on x86.

This came up in a discussion [0] on my 32-bit arm support. The 
`define_panicking_intrinsics` macro is kept, because it will still be 
needed for 32-bit arm (and possibly other architecures).

Removing the `__udivti3` intrinsic requires a Rust PR [1] and the other
intrinsics only require a recent rust version (tested with 1.84), 
so when building with older rust versions would still require these
intrinsics.

For now this is mostly done as a demonstration that this should be
possible to do once the MSRV is bumped high enough (and possibly my
Rust PR is merged).

I have tested building a x86_64 kernel and running the rust samples
in qemu.

Link: https://lore.kernel.org/rust-for-linux/defddc25-eb8b-420a-b64c-6ce57ebb3f6b@gmail.com/ [0]
Link: https://github.com/rust-lang/rust/pull/136385 [1]
---
 rust/Makefile             | 15 +--------------
 rust/compiler_builtins.rs | 37 +------------------------------------
 2 files changed, 2 insertions(+), 50 deletions(-)

diff --git a/rust/Makefile b/rust/Makefile
index a40a3936126d603836e0ec9b42a1285916b60e45..7d3be8fb257a7f2cb9ddb69ce6b6529ce989aee7 100644
--- a/rust/Makefile
+++ b/rust/Makefile
@@ -53,7 +53,7 @@ rustdoc_test_kernel_quiet=>/dev/null
 endif
 
 core-cfgs = \
-    --cfg no_fp_fmt_parse
+    --cfg no_fp_fmt_parse --cfg no_iu128_fmt
 
 quiet_cmd_rustdoc = RUSTDOC $(if $(rustdoc_host),H, ) $<
       cmd_rustdoc = \
@@ -388,19 +388,6 @@ rust-analyzer:
 		$(rustc_sysroot) $(RUST_LIB_SRC) $(if $(KBUILD_EXTMOD),$(srcroot)) \
 		> rust-project.json
 
-redirect-intrinsics = \
-	__addsf3 __eqsf2 __extendsfdf2 __gesf2 __lesf2 __ltsf2 __mulsf3 __nesf2 __truncdfsf2 __unordsf2 \
-	__adddf3 __eqdf2 __ledf2 __ltdf2 __muldf3 __unorddf2 \
-	__muloti4 __multi3 \
-	__udivmodti4 __udivti3 __umodti3
-
-ifneq ($(or $(CONFIG_ARM64),$(and $(CONFIG_RISCV),$(CONFIG_64BIT))),)
-	# These intrinsics are defined for ARM64 and RISCV64
-	redirect-intrinsics += \
-		__ashrti3 \
-		__ashlti3 __lshrti3
-endif
-
 define rule_rustc_library
 	$(call cmd_and_fixdep,rustc_library)
 	$(call cmd,gen_objtooldep)
diff --git a/rust/compiler_builtins.rs b/rust/compiler_builtins.rs
index f14b8d7caf89964198313deace1bcb06fea82964..c4ca246abd8e789bb0ed8d8b6736a88ce3f961f7 100644
--- a/rust/compiler_builtins.rs
+++ b/rust/compiler_builtins.rs
@@ -25,6 +25,7 @@
 #![no_builtins]
 #![no_std]
 
+#[expect(unused_macros)]
 macro_rules! define_panicking_intrinsics(
     ($reason: tt, { $($ident: ident, )* }) => {
         $(
@@ -37,41 +38,5 @@ pub extern "C" fn $ident() {
     }
 );
 
-define_panicking_intrinsics!("`f32` should not be used", {
-    __addsf3,
-    __eqsf2,
-    __extendsfdf2,
-    __gesf2,
-    __lesf2,
-    __ltsf2,
-    __mulsf3,
-    __nesf2,
-    __truncdfsf2,
-    __unordsf2,
-});
-
-define_panicking_intrinsics!("`f64` should not be used", {
-    __adddf3,
-    __eqdf2,
-    __ledf2,
-    __ltdf2,
-    __muldf3,
-    __unorddf2,
-});
-
-define_panicking_intrinsics!("`i128` should not be used", {
-    __ashrti3,
-    __muloti4,
-    __multi3,
-});
-
-define_panicking_intrinsics!("`u128` should not be used", {
-    __ashlti3,
-    __lshrti3,
-    __udivmodti4,
-    __udivti3,
-    __umodti3,
-});
-
 // NOTE: if you are adding a new intrinsic here, you should also add it to
 // `redirect-intrinsics` in `rust/Makefile`.

---
base-commit: ffd294d346d185b70e28b1a28abe367bbfe53c04
change-id: 20250201-remove_intrinsic-27749d5f93ac

Best regards,
-- 
Christian Schrefl <chrisi.schrefl@gmail.com>


                 reply	other threads:[~2025-02-01 14:39 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20250201-remove_intrinsic-v1-1-4283ce8e4764@gmail.com \
    --to=chrisi.schrefl@gmail.com \
    --cc=a.hindborg@kernel.org \
    --cc=alex.gaynor@gmail.com \
    --cc=aliceryhl@google.com \
    --cc=andrew@lunn.ch \
    --cc=arnd@arndb.de \
    --cc=benno.lossin@proton.me \
    --cc=bjorn3_gh@protonmail.com \
    --cc=boqun.feng@gmail.com \
    --cc=gary@garyguo.net \
    --cc=linux-kernel@vger.kernel.org \
    --cc=ojeda@kernel.org \
    --cc=rust-for-linux@vger.kernel.org \
    --cc=tmgross@umich.edu \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®