Skip to content

Commit 914a935

Browse files
committed
Merge branch 'master' into minor-edits
2 parents 9153f28 + 6af3f81 commit 914a935

File tree

3 files changed

+12
-10
lines changed

3 files changed

+12
-10
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ Please see the [CONTRIBUTING.md] file for more details.
3535

3636
## Translations to other languages
3737

38+
* [Bulgarian](https://github.com/kberov/rust-by-example-bg)
3839
* [Chinese](https://github.com/rust-lang-cn/rust-by-example-cn)
3940
* [Japanese](https://github.com/rust-lang-ja/rust-by-example-ja)
4041
* [French](https://github.com/Songbird0/FR_RBE)

src/index.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,9 @@ Now let's begin!
2121

2222
- [Types](types.md) - Learn about changing and defining types.
2323

24-
- [Conversion](conversion.md)
24+
- [Conversion](conversion.md) - Convert between different types, such as strings, integers, and floats.
2525

26-
- [Expressions](expression.md)
26+
- [Expressions](expression.md) - Learn about Expressions & how to use them.
2727

2828
- [Flow of Control](flow_control.md) - `if`/`else`, `for`, and others.
2929

@@ -43,7 +43,7 @@ Now let's begin!
4343

4444
- [Traits](trait.md) - A trait is a collection of methods defined for an unknown type: `Self`
4545

46-
- [Macros](macros.md)
46+
- [Macros](macros.md) - Macros are a way of writing code that writes other code, which is known as metaprogramming.
4747

4848
- [Error handling](error.md) - Learn Rust way of handling failures.
4949

@@ -53,9 +53,9 @@ Now let's begin!
5353

5454
- [Testing](testing.md) - All sorts of testing in Rust.
5555

56-
- [Unsafe Operations](unsafe.md)
56+
- [Unsafe Operations](unsafe.md) - Learn about entering a block of unsafe operations.
5757

58-
- [Compatibility](compatibility.md)
58+
- [Compatibility](compatibility.md) - Handling Rust's evolution and potential compatibility issues.
5959

6060
- [Meta](meta.md) - Documentation, Benchmarking.
6161

src/unsafe/asm.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,8 +139,8 @@ can be written at any time, and can therefore not share its location with any ot
139139
However, to guarantee optimal performance it is important to use as few registers as possible,
140140
so they won't have to be saved and reloaded around the inline assembly block.
141141
To achieve this Rust provides a `lateout` specifier. This can be used on any output that is
142-
written only after all inputs have been consumed.
143-
There is also a `inlateout` variant of this specifier.
142+
written only after all inputs have been consumed. There is also an `inlateout` variant of this
143+
specifier.
144144

145145
Here is an example where `inlateout` *cannot* be used in `release` mode or other optimized cases:
146146

@@ -163,11 +163,12 @@ unsafe {
163163
assert_eq!(a, 12);
164164
# }
165165
```
166-
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.
167166

168-
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 could overwrite the value of `c` and cause the assembly code to produce the wrong result.
167+
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.
169168

170-
However the following example can use `inlateout` since the output is only modified after all input registers have been read:
169+
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`.
170+
171+
However, the following example can use `inlateout` since the output is only modified after all input registers have been read:
171172

172173
```rust
173174
# #[cfg(target_arch = "x86_64")] {

0 commit comments

Comments
 (0)