From 9d9eb2323b34188b5b27009d3607a4f4c35f4cca Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9A=D1=80=D0=B0=D1=81=D0=B8=D0=BC=D0=B8=D1=80=20=D0=91?= =?UTF-8?q?=D0=B5=D1=80=D0=BE=D0=B2?= Date: Wed, 1 Nov 2023 02:00:07 +0200 Subject: [PATCH 1/3] Link to the Bulgarian translation --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index 2529a3fad3..093351e690 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,7 @@ Please see the [CONTRIBUTING.md] file for more details. ## Translations to other languages +* [Bulgarian](https://github.com/kberov/rust-by-example-bg) * [Chinese](https://github.com/rust-lang-cn/rust-by-example-cn) * [Japanese](https://github.com/rust-lang-ja/rust-by-example-ja) * [French](https://github.com/Songbird0/FR_RBE) From 93b0b9ab3b8a00699bec1535108a232755ffbc9b Mon Sep 17 00:00:00 2001 From: Ravi Makhija Date: Fri, 3 Nov 2023 13:25:11 -0400 Subject: [PATCH 2/3] Fix asm example explanation for `inlateout` usage --- src/unsafe/asm.md | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/src/unsafe/asm.md b/src/unsafe/asm.md index cbe52c8407..a2b5b079c5 100644 --- a/src/unsafe/asm.md +++ b/src/unsafe/asm.md @@ -139,8 +139,8 @@ can be written at any time, and can therefore not share its location with any ot However, to guarantee optimal performance it is important to use as few registers as possible, so they won't have to be saved and reloaded around the inline assembly block. To achieve this Rust provides a `lateout` specifier. This can be used on any output that is -written only after all inputs have been consumed. -There is also a `inlateout` variant of this specifier. +written only after all inputs have been consumed. There is also an `inlateout` variant of this +specifier. Here is an example where `inlateout` *cannot* be used in `release` mode or other optimized cases: @@ -163,11 +163,12 @@ unsafe { assert_eq!(a, 12); # } ``` -The above could work well in unoptimized cases (`Debug` mode), but if you want optimized performance (`release` mode or other optimized cases), it could not work. -That is because in optimized cases, the compiler is free to allocate the same register for inputs `b` and `c` since it knows they have the same value. However it must allocate a separate register for `a` since it uses `inout` and not `inlateout`. If `inlateout` was used, then `a` and `c` could be allocated to the same register, in which case the first instruction to overwrite the value of `c` and cause the assembly code to produce the wrong result. +In unoptimized cases (e.g. `Debug` mode), replacing `inout(reg) a` with `inlateout(reg) a` in the above example can continue to give the expected result. However, with `release` mode or other optimized cases, using `inlateout(reg) a` can instead lead to the final value `a = 16`, causing the assertion to fail. -However the following example can use `inlateout` since the output is only modified after all input registers have been read: +This is because in optimized cases, the compiler is free to allocate the same register for inputs `b` and `c` since it knows that they have the same value. Furthermore, when `inlateout` is used, `a` and `c` could be allocated to the same register, in which case the first `add` instruction would overwrite the initial load from variable `c`. This is in contrast to how using `inout(reg) a` ensures a separate register is allocated for `a`. + +However, the following example can use `inlateout` since the output is only modified after all input registers have been read: ```rust # #[cfg(target_arch = "x86_64")] { From 5ce3cc12784dff17851507cd58e6506637f012a9 Mon Sep 17 00:00:00 2001 From: Aryan Malik Date: Wed, 8 Nov 2023 00:36:25 +0530 Subject: [PATCH 3/3] Update index.md: Added descriptions for the 'leftover' points --- src/index.md | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/src/index.md b/src/index.md index ecadff4ccf..e42c196d1f 100644 --- a/src/index.md +++ b/src/index.md @@ -21,9 +21,9 @@ Now let's begin! - [Types](types.md) - Learn about changing and defining types. -- [Conversion](conversion.md) +- [Conversion](conversion.md) - Convert between different types, such as strings, integers, and floats. -- [Expressions](expression.md) +- [Expressions](expression.md) - Learn about Expressions & how to use them. - [Flow of Control](flow_control.md) - `if`/`else`, `for`, and others. @@ -43,7 +43,7 @@ Now let's begin! - [Traits](trait.md) - A trait is a collection of methods defined for an unknown type: `Self` -- [Macros](macros.md) +- [Macros](macros.md) - Macros are a way of writing code that writes other code, which is known as metaprogramming. - [Error handling](error.md) - Learn Rust way of handling failures. @@ -53,9 +53,9 @@ Now let's begin! - [Testing](testing.md) - All sorts of testing in Rust. -- [Unsafe Operations](unsafe.md) +- [Unsafe Operations](unsafe.md) - Learn about entering a block of unsafe operations. -- [Compatibility](compatibility.md) +- [Compatibility](compatibility.md) - Handling Rust's evolution and potential compatibility issues. - [Meta](meta.md) - Documentation, Benchmarking.