Skip to content

Commit cc4bbdf

Browse files
committed
Merge pull request #96 from pocket7878/inline-assembly
6.2.0 Inline Assembly
2 parents 7c0304b + 9bdb522 commit cc4bbdf

File tree

1 file changed

+110
-65
lines changed

1 file changed

+110
-65
lines changed

1.6/ja/book/inline-assembly.md

Lines changed: 110 additions & 65 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,43 @@
1-
% Inline Assembly
1+
% インラインアセンブリ
2+
<!-- % Inline Assembly -->
23

3-
For extremely low-level manipulations and performance reasons, one
4-
might wish to control the CPU directly. Rust supports using inline
5-
assembly to do this via the `asm!` macro. The syntax roughly matches
6-
that of GCC & Clang:
4+
<!-- For extremely low-level manipulations and performance reasons, one -->
5+
<!-- might wish to control the CPU directly. Rust supports using inline -->
6+
<!-- assembly to do this via the `asm!` macro. The syntax roughly matches -->
7+
<!-- that of GCC & Clang: -->
8+
極めて低レベルな技巧やパフォーマンス上の理由から、CPUを直接コントロールしたいと思う人もいるでしょう。
9+
Rustはそのような処理を行うためにインラインアセンブリを `asm!` マクロによってサポートしています。
10+
インラインアセンブリの構文はGCCやClangのものとおおまかに一致しています。
711

812
```ignore
9-
asm!(assembly template
10-
: output operands
11-
: input operands
12-
: clobbers
13-
: options
13+
# // asm!(assembly template
14+
asm!(アセンブリのテンプレート
15+
# // : output operands
16+
: 出力オペランド
17+
# // : input operands
18+
: 入力オペランド
19+
# // : clobbers
20+
: 破壊されるデータ
21+
# // : options
22+
: オプション
1423
);
1524
```
1625

17-
Any use of `asm` is feature gated (requires `#![feature(asm)]` on the
18-
crate to allow) and of course requires an `unsafe` block.
26+
<!-- Any use of `asm` is feature gated (requires `#![feature(asm)]` on the -->
27+
<!-- crate to allow) and of course requires an `unsafe` block. -->
28+
`asm` のいかなる利用もフィーチャーゲートの対象です(利用するには `#![feature(asm)]` がクレートに必要になります)、
29+
そしてもちろん `unsafe` ブロックも必要です。
1930

20-
> **Note**: the examples here are given in x86/x86-64 assembly, but
21-
> all platforms are supported.
31+
<!-- > **Note**: the examples here are given in x86/x86-64 assembly, but -->
32+
<!-- > all platforms are supported. -->
33+
> **メモ**: ここでの例はx86/x86-64のアセンブリで示されますが、すべてのプラットフォームがサポートされています。
2234
23-
## Assembly template
35+
<!-- ## Assembly template -->
36+
## アセンブリテンプレート
2437

25-
The `assembly template` is the only required parameter and must be a
26-
literal string (i.e. `""`)
38+
<!-- The `assembly template` is the only required parameter and must be a -->
39+
<!-- literal string (i.e. `""`) -->
40+
`アセンブリテンプレート` のみが要求されるパラメータであり、文字列リテラル (例: "") である必要があります。
2741

2842
```rust
2943
#![feature(asm)]
@@ -35,7 +49,8 @@ fn foo() {
3549
}
3650
}
3751

38-
// other platforms
52+
# // other platforms
53+
// その他のプラットフォーム
3954
#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
4055
fn foo() { /* ... */ }
4156

@@ -46,10 +61,12 @@ fn main() {
4661
}
4762
```
4863

49-
(The `feature(asm)` and `#[cfg]`s are omitted from now on.)
64+
<!-- (The `feature(asm)` and `#[cfg]`s are omitted from now on.) -->
65+
以後は、 `feature(asm)``#[cfg]` は省略して示します。
5066

51-
Output operands, input operands, clobbers and options are all optional
52-
but you must add the right number of `:` if you skip them:
67+
<!-- Output operands, input operands, clobbers and options are all optional -->
68+
<!-- but you must add the right number of `:` if you skip them: -->
69+
出力オペランド、入力オペランド、破壊されるデータ、オプションはすべて省略可能ですが、省略する場合は `:` を正しい数書く必要が有ります。
5370

5471
```rust
5572
# #![feature(asm)]
@@ -63,7 +80,8 @@ asm!("xor %eax, %eax"
6380
# } }
6481
```
6582

66-
Whitespace also doesn't matter:
83+
<!-- Whitespace also doesn't matter: -->
84+
空白も必要ではありません:
6785

6886
```rust
6987
# #![feature(asm)]
@@ -73,11 +91,14 @@ asm!("xor %eax, %eax" ::: "{eax}");
7391
# } }
7492
```
7593

76-
## Operands
94+
<!-- ## Operands -->
95+
## オペランド
7796

78-
Input and output operands follow the same format: `:
79-
"constraints1"(expr1), "constraints2"(expr2), ..."`. Output operand
80-
expressions must be mutable lvalues, or not yet assigned:
97+
<!-- Input and output operands follow the same format: `: -->
98+
<!-- "constraints1"(expr1), "constraints2"(expr2), ..."`. Output operand -->
99+
<!-- expressions must be mutable lvalues, or not yet assigned: -->
100+
入力と出力のオペランドは、 `: "制約1"(式1), "制約2"(式2), ...` というフォーマットに従います。
101+
出力オペランドの式は変更可能な左辺値か、アサインされていない状態でなければなりません。
81102

82103
```rust
83104
# #![feature(asm)]
@@ -100,11 +121,13 @@ fn main() {
100121
}
101122
```
102123

103-
If you would like to use real operands in this position, however,
104-
you are required to put curly braces `{}` around the register that
105-
you want, and you are required to put the specific size of the
106-
operand. This is useful for very low level programming, where
107-
which register you use is important:
124+
<!-- If you would like to use real operands in this position, however, -->
125+
<!-- you are required to put curly braces `{}` around the register that -->
126+
<!-- you want, and you are required to put the specific size of the -->
127+
<!-- operand. This is useful for very low level programming, where -->
128+
<!-- which register you use is important: -->
129+
もし本当のオペランドをここで利用したい場合、 波括弧 `{}` で利用したいレジスタの周りを囲む必要があり、また、オペランドの特有のサイズを置く必要があります。
130+
これは、どのレジスタを利用するかが重要になる低レベルなプログラミングで有用です。
108131

109132
```rust
110133
# #![feature(asm)]
@@ -116,44 +139,63 @@ result
116139
# }
117140
```
118141

119-
## Clobbers
142+
<!-- ## Clobbers -->
143+
## 破壊されるデータ
120144

121-
Some instructions modify registers which might otherwise have held
122-
different values so we use the clobbers list to indicate to the
123-
compiler not to assume any values loaded into those registers will
124-
stay valid.
145+
<!-- Some instructions modify registers which might otherwise have held -->
146+
<!-- different values so we use the clobbers list to indicate to the -->
147+
<!-- compiler not to assume any values loaded into those registers will -->
148+
<!-- stay valid. -->
149+
幾つかのインストラクションは異なる値を持っている可能性のあるレジスタを変更する事があります、
150+
そのため、コンパイラがそれらのレジスタに格納された値が処理後にも有効であると思わないように、
151+
破壊されるデータのリストを利用します。
125152

126153
```rust
127154
# #![feature(asm)]
128155
# #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
129156
# fn main() { unsafe {
130-
// Put the value 0x200 in eax
131-
asm!("mov $$0x200, %eax" : /* no outputs */ : /* no inputs */ : "{eax}");
157+
# // Put the value 0x200 in eax
158+
// eaxに0x200を格納します
159+
# // asm!("mov $$0x200, %eax" : /* no outputs */ : /* no inputs */ : "{eax}");
160+
asm!("mov $$0x200, %eax" : /* 出力なし */ : /* 入力無し */ : "{eax}");
132161
# } }
133162
```
134163

135-
Input and output registers need not be listed since that information
136-
is already communicated by the given constraints. Otherwise, any other
137-
registers used either implicitly or explicitly should be listed.
138-
139-
If the assembly changes the condition code register `cc` should be
140-
specified as one of the clobbers. Similarly, if the assembly modifies
141-
memory, `memory` should also be specified.
142-
143-
## Options
144-
145-
The last section, `options` is specific to Rust. The format is comma
146-
separated literal strings (i.e. `:"foo", "bar", "baz"`). It's used to
147-
specify some extra info about the inline assembly:
148-
149-
Current valid options are:
150-
151-
1. *volatile* - specifying this is analogous to
152-
`__asm__ __volatile__ (...)` in gcc/clang.
153-
2. *alignstack* - certain instructions expect the stack to be
154-
aligned a certain way (i.e. SSE) and specifying this indicates to
155-
the compiler to insert its usual stack alignment code
156-
3. *intel* - use intel syntax instead of the default AT&T.
164+
<!-- Input and output registers need not be listed since that information -->
165+
<!-- is already communicated by the given constraints. Otherwise, any other -->
166+
<!-- registers used either implicitly or explicitly should be listed. -->
167+
入力と出力のレジスタは変更される可能性があることが制約によってすでに伝わっているためにリストに載せる必要はありません。
168+
それ以外では、その他の暗黙的、明示的に利用されるレジスタをリストに載せる必要があります。
169+
170+
<!-- If the assembly changes the condition code register `cc` should be -->
171+
<!-- specified as one of the clobbers. Similarly, if the assembly modifies -->
172+
<!-- memory, `memory` should also be specified. -->
173+
もしアセンブリが条件コードを変更する場合レジスタ `cc` も破壊されるデータのリストに指定する必要があります。
174+
同様に、もしアセンブリがメモリを変更する場合 `memory` もリストに指定する必要があります。
175+
176+
<!-- ## Options -->
177+
## オプション
178+
179+
<!-- The last section, `options` is specific to Rust. The format is comma -->
180+
<!-- separated literal strings (i.e. `:"foo", "bar", "baz"`). It's used to -->
181+
<!-- specify some extra info about the inline assembly: -->
182+
最後のセクション、 `options` はRust特有のものです。
183+
`options` の形式は、コンマで区切られた文字列リテラルのリスト(例: `:"foo", "bar", "baz"`)です。
184+
これはインラインアセンブリについての追加の情報を指定するために利用されます:
185+
186+
<!-- Current valid options are: -->
187+
現在有効なオプションは以下の通りです:
188+
189+
<!-- 1. *volatile* - specifying this is analogous to-->
190+
<!-- `__asm__ __volatile__ (...)` in gcc/clang.-->
191+
<!-- 2. *alignstack* - certain instructions expect the stack to be-->
192+
<!-- aligned a certain way (i.e. SSE) and specifying this indicates to-->
193+
<!-- the compiler to insert its usual stack alignment code-->
194+
<!-- 3. *intel* - use intel syntax instead of the default AT&T.-->
195+
1. *volatile* - このオプションを指定することは、gcc/clangで `__asm__ __volatile__ (...)` を指定することと類似しています。
196+
2. *alignstack* - いくつかのインストラクションはスタックが決まった方式(例: SSE)でアラインされていることを期待しています、
197+
このオプションを指定することはコンパイラに通常のスタックをアラインメントするコードの挿入を指示します。
198+
3. *intel* - デフォルトのAT&T構文の代わりにインテル構文を利用することを意味しています。
157199

158200
```rust
159201
# #![feature(asm)]
@@ -167,11 +209,14 @@ println!("eax is currently {}", result);
167209
# }
168210
```
169211

170-
## More Information
212+
<!-- ## More Information -->
213+
## さらなる情報
171214

172-
The current implementation of the `asm!` macro is a direct binding to [LLVM's
173-
inline assembler expressions][llvm-docs], so be sure to check out [their
174-
documentation as well][llvm-docs] for more information about clobbers,
175-
constraints, etc.
215+
<!-- The current implementation of the `asm!` macro is a direct binding to [LLVM's -->
216+
<!-- inline assembler expressions][llvm-docs], so be sure to check out [their -->
217+
<!-- documentation as well][llvm-docs] for more information about clobbers, -->
218+
<!-- constraints, etc. -->
219+
現在の `asm!` マクロの実装は [LLVMのインラインアセンブリ表現][llvm-docs] への直接的なバインディングです、
220+
そのため破壊されるデータのリストや、制約、その他の情報について [LLVMのドキュメント][llvm-docs] を確認してください。
176221

177222
[llvm-docs]: http://llvm.org/docs/LangRef.html#inline-assembler-expressions

0 commit comments

Comments
 (0)