Skip to content

Commit 4b65334

Browse files
committed
fix translation
1 parent 0c72142 commit 4b65334

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

src/unsafe/asm.md

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -99,16 +99,16 @@ In this case we put it in an arbitrary general purpose register by specifying `r
9999
The compiler will choose an appropriate register to insert into
100100
the template and will read the variable from there after the inline assembly finishes executing.
101101
-->
102-
`u64`型の変数`x``5`の値を書き込んでいます。
102+
これは`u64`型の変数`x``5`の値を書き込んでいます。
103103
命令を指定するために利用している文字列リテラルが、実はテンプレート文字列になっています。
104104
これはRustの[フォーマット文字列][format-syntax]と同じルールに従います。
105105
ですが、テンプレートに挿入される引数が、みなさんがよく知っているものとは少し違っています。
106106
まず、変数がインラインアセンブリの入力なのか出力なのかを指定する必要があります。
107107
上記の例では出力となっています。
108-
`out`と書くことでそれを宣言しています
108+
`out`と書くことで出力であると宣言しています
109109
また、アセンブリが変数をどの種類のレジスタに格納するかも指定する必要があります。
110-
上の例では、`reg`を指定することで任意の汎用レジスタに格納しています
111-
コンパイラはテンプレートに挿入すべき適切なレジスタを選び、インラインアセンブリの実行終了後、そのレジスタから変数を読みこみます。
110+
上の例では、`reg`を指定して任意の汎用レジスタに格納しています
111+
コンパイラはテンプレートに挿入する適切なレジスタを選び、インラインアセンブリの実行終了後、そのレジスタから変数を読みこみます。
112112

113113
[format-syntax]: https://doc.rust-lang.org/std/fmt/#syntax
114114

@@ -155,7 +155,7 @@ together with newlines between them. This makes it easy to format assembly
155155
code.
156156
-->
157157
まず、`asm!`では複数のテンプレート文字列を引数として利用できます。
158-
それぞれの文字列は、あたかも改行を挟んで結合されたかのように、独立したアセンブリコードとして扱われます。
158+
それぞれの文字列は、改行を挟んで結合されたのと同じように、独立したアセンブリコードとして扱われます。
159159
このおかげで、アセンブリコードを容易にフォーマットできます。
160160

161161
<!--
@@ -169,15 +169,15 @@ For inline assembly templates this is particularly useful as arguments are often
169169
For more complex inline assembly using this facility is generally recommended, as it improves
170170
readability, and allows reordering instructions without changing the argument order.
171171
-->
172-
そして、他のフォーマット文字列と同じように引数の番号や名前で指定できます
173-
インラインアセンブリのテンプレートでは、引数が2回以上利用されることが多いため、これは特に有用です
172+
そして、他のフォーマット文字列と同じように引数を番号や名前で指定できます
173+
インラインアセンブリのテンプレートでは、引数が2回以上利用されることが多いため、これは特に便利です
174174
より複雑なインラインアセンブリを書く場合、この機能を使うのが推奨されます。
175175
可読性が向上し、引数の順序を変えることなく命令を並べ替えることができるからです。
176176

177177
<!--
178178
We can further refine the above example to avoid the `mov` instruction:
179179
-->
180-
上記の例をさらに改善して、`mov`命令を避けることもできます
180+
上記の例をさらに改善して、`mov`命令をやめることもできます
181181

182182
```rust
183183
# #[cfg(target_arch = "x86_64")] {
@@ -272,7 +272,7 @@ The above could work well in unoptimized cases (`Debug` mode), but if you want o
272272
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.
273273
-->
274274
というのも、最適化されている場合、コンパイラは`b``c`が同じ値だと知っているので、
275-
`b``c`の入力に同じレジスタを割り当てる場合があるのです
275+
`b``c`の入力に同じレジスタを割り当てる場合があります
276276
しかし、`a`については`inlateout`ではなく`inout`を使っているので、独立したレジスタを割り当てる必要があります。
277277
もし`inlateout`が使われていたら、`a``c`に同じレジスタが割り当てられたかもしれません。
278278
そうすると、最初の命令によって`c`の値が上書きされ、アセンブリコードが間違った結果を引き起こします。

0 commit comments

Comments
 (0)