From 3d45616386fb0d06d2b81660d339803849ecc62e Mon Sep 17 00:00:00 2001 From: Lokathor Date: Wed, 23 Nov 2022 09:43:02 -0700 Subject: [PATCH 1/5] Clearly specify the instruction_set inlining restrictions --- src/attributes/codegen.md | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/src/attributes/codegen.md b/src/attributes/codegen.md index 69ad341d1..27230e426 100644 --- a/src/attributes/codegen.md +++ b/src/attributes/codegen.md @@ -355,15 +355,16 @@ trait object whose methods are attributed. ## The `instruction_set` attribute -The *`instruction_set` attribute* may be applied to a function to enable code generation for a specific -instruction set supported by the target architecture. It uses the [_MetaListPath_] syntax and a path -comprised of the architecture and instruction set to specify how to generate the code for -architectures where a single program may utilize multiple instruction sets. +On some CPU architectures it is possible to mix more than one instruction set into a single program. +The `instruction_set` attribute lets you control which instruction set a particular function will be generated for. +It uses the [_MetaListPath_] syntax, and a path comprised of the architecture family name and instruction set name. -The following values are available on targets for the `ARMv4` and `ARMv5te` architectures: +[_MetaListPath_]: ../attributes.md#meta-item-attribute-syntax + +For the `ARMv4T` and `ARMv5te` architectures, the following are supported: -* `arm::a32` - Uses ARM code. -* `arm::t32` - Uses Thumb code. +* `arm::a32` - Generate the function as A32 "ARM" code. +* `arm::t32` - Generate the function as T32 "Thumb" code. ```rust,ignore @@ -374,4 +375,8 @@ fn foo_arm_code() {} fn bar_thumb_code() {} ``` -[_MetaListPath_]: ../attributes.md#meta-item-attribute-syntax +The rules for inlining functions using the `instruction_set` attribute are slightly more strict than normal: + +* If a function has an `instruction_set` attribute, then the function is assumed to require the given instruction set and it won't inline into a function of another instruction set. +* If a function does not have an `instruction_set` attribute but *does* contain inline assembly, then the inline assembly is assumed to require the default instruction set of the build target and so inlining between instruction sets won't happen. +* Otherwise, a function is assumed to not rely on a particular instruction set and the function *may* be inlined into any calling function (all other restrictions on inlining still apply). From df9643a33ca6a2507f7d93cb1cc57926ae348558 Mon Sep 17 00:00:00 2001 From: Lokathor Date: Wed, 18 Jan 2023 10:59:32 -0700 Subject: [PATCH 2/5] Update codegen.md --- src/attributes/codegen.md | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/attributes/codegen.md b/src/attributes/codegen.md index 27230e426..bcd93dbe7 100644 --- a/src/attributes/codegen.md +++ b/src/attributes/codegen.md @@ -375,8 +375,9 @@ fn foo_arm_code() {} fn bar_thumb_code() {} ``` -The rules for inlining functions using the `instruction_set` attribute are slightly more strict than normal: +If your function has neither the instruction_set attribute nor inline assembly, then the code you write within that function should not presume any particular instruction set. +This ends up creating a limitation to how often code is inlined: -* If a function has an `instruction_set` attribute, then the function is assumed to require the given instruction set and it won't inline into a function of another instruction set. -* If a function does not have an `instruction_set` attribute but *does* contain inline assembly, then the inline assembly is assumed to require the default instruction set of the build target and so inlining between instruction sets won't happen. -* Otherwise, a function is assumed to not rely on a particular instruction set and the function *may* be inlined into any calling function (all other restrictions on inlining still apply). +* If a function has an `instruction_set` attribute it won't inline into a function of another instruction set. +* If a function does not have an `instruction_set` attribute but *does* contain inline assembly, then the inline assembly is assumed to require the default instruction set of the build target, and so inlining between different instruction sets won't happen. +* Otherwise, inlining happens normally. From 236e01489cfde28df78a04a1ab72ffaae9d2f09b Mon Sep 17 00:00:00 2001 From: Lokathor Date: Sat, 27 May 2023 20:30:35 -0600 Subject: [PATCH 3/5] Update src/attributes/codegen.md Co-authored-by: Eric Huss --- src/attributes/codegen.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/attributes/codegen.md b/src/attributes/codegen.md index bcd93dbe7..31b9f7cf3 100644 --- a/src/attributes/codegen.md +++ b/src/attributes/codegen.md @@ -355,8 +355,8 @@ trait object whose methods are attributed. ## The `instruction_set` attribute -On some CPU architectures it is possible to mix more than one instruction set into a single program. -The `instruction_set` attribute lets you control which instruction set a particular function will be generated for. +The *`instruction_set` [attribute]* may be applied to a function to control which instruction set the function will be generated for. +This allows mixing more than one instruction set in a single program on CPU architectures that support it. It uses the [_MetaListPath_] syntax, and a path comprised of the architecture family name and instruction set name. [_MetaListPath_]: ../attributes.md#meta-item-attribute-syntax From a38bdf7e0f8d300e1c2c849d52615a837cfe8978 Mon Sep 17 00:00:00 2001 From: Lokathor Date: Sat, 27 May 2023 20:31:34 -0600 Subject: [PATCH 4/5] Update src/attributes/codegen.md Co-authored-by: Eric Huss --- src/attributes/codegen.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/attributes/codegen.md b/src/attributes/codegen.md index 31b9f7cf3..dc3b2e0d0 100644 --- a/src/attributes/codegen.md +++ b/src/attributes/codegen.md @@ -375,7 +375,7 @@ fn foo_arm_code() {} fn bar_thumb_code() {} ``` -If your function has neither the instruction_set attribute nor inline assembly, then the code you write within that function should not presume any particular instruction set. +If your function has neither the `instruction_set` attribute nor inline assembly, then the code you write within that function should not presume any particular instruction set. This ends up creating a limitation to how often code is inlined: * If a function has an `instruction_set` attribute it won't inline into a function of another instruction set. From 188499dd6dcae90be4e8d5035b4d95ecb2299b88 Mon Sep 17 00:00:00 2001 From: Lokathor Date: Tue, 27 Jun 2023 13:10:11 -0600 Subject: [PATCH 5/5] Update codegen.md --- src/attributes/codegen.md | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/src/attributes/codegen.md b/src/attributes/codegen.md index dc3b2e0d0..7dd64373a 100644 --- a/src/attributes/codegen.md +++ b/src/attributes/codegen.md @@ -361,6 +361,10 @@ It uses the [_MetaListPath_] syntax, and a path comprised of the architecture fa [_MetaListPath_]: ../attributes.md#meta-item-attribute-syntax +It is a compilation error to use the `instruction_set` attribute on a target that does not support it. + +### On ARM + For the `ARMv4T` and `ARMv5te` architectures, the following are supported: * `arm::a32` - Generate the function as A32 "ARM" code. @@ -375,9 +379,7 @@ fn foo_arm_code() {} fn bar_thumb_code() {} ``` -If your function has neither the `instruction_set` attribute nor inline assembly, then the code you write within that function should not presume any particular instruction set. -This ends up creating a limitation to how often code is inlined: +Using the `instruction_set` attribute has the following effects: -* If a function has an `instruction_set` attribute it won't inline into a function of another instruction set. -* If a function does not have an `instruction_set` attribute but *does* contain inline assembly, then the inline assembly is assumed to require the default instruction set of the build target, and so inlining between different instruction sets won't happen. -* Otherwise, inlining happens normally. +* If the address of the function is taken as a function pointer, the low bit of the address will be set to 0 (arm) or 1 (thumb) depending on the instruction set. +* Any inline assembly in the function must use the specified instruction set instead of the target default.