1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
//! `core_arch`

#[macro_use]
mod macros;

#[cfg(any(target_arch = "riscv32", target_arch = "riscv64", doc))]
mod riscv_shared;

#[cfg(any(target_arch = "arm", target_arch = "aarch64", doc))]
mod arm_shared;

mod simd;

#[doc = include_str!("core_arch_docs.md")]
#[stable(feature = "simd_arch", since = "1.27.0")]
pub mod arch {
    /// 特定于平台的用于 `x86` 平台的内部函数。
    ///
    /// 有关更多详细信息,请参见 [模块级文档](../index.html)。
    #[cfg(any(target_arch = "x86", doc))]
    #[doc(cfg(target_arch = "x86"))]
    #[stable(feature = "simd_x86", since = "1.27.0")]
    pub mod x86 {
        #[stable(feature = "simd_x86", since = "1.27.0")]
        pub use crate::core_arch::x86::*;
    }

    /// 特定于平台的用于 `x86_64` 平台的内部函数。
    ///
    /// 有关更多详细信息,请参见 [模块级文档](../index.html)。
    #[cfg(any(target_arch = "x86_64", doc))]
    #[doc(cfg(target_arch = "x86_64"))]
    #[stable(feature = "simd_x86", since = "1.27.0")]
    pub mod x86_64 {
        #[stable(feature = "simd_x86", since = "1.27.0")]
        pub use crate::core_arch::x86::*;
        #[stable(feature = "simd_x86", since = "1.27.0")]
        pub use crate::core_arch::x86_64::*;
    }

    /// 特定于平台的用于 `arm` 平台的内部函数。
    ///
    /// 有关更多详细信息,请参见 [模块级文档](../index.html)。
    #[cfg(any(target_arch = "arm", doc))]
    #[doc(cfg(target_arch = "arm"))]
    #[unstable(feature = "stdsimd", issue = "27731")]
    pub mod arm {
        pub use crate::core_arch::arm::*;
    }

    /// 特定于平台的用于 `aarch64` 平台的内部函数。
    ///
    /// 有关更多详细信息,请参见 [模块级文档](../index.html)。
    #[cfg(any(target_arch = "aarch64", doc))]
    #[doc(cfg(target_arch = "aarch64"))]
    #[stable(feature = "neon_intrinsics", since = "1.59.0")]
    pub mod aarch64 {
        #[stable(feature = "neon_intrinsics", since = "1.59.0")]
        pub use crate::core_arch::aarch64::*;
    }

    /// 特定于平台的用于 `riscv32` 平台的内部函数。
    ///
    /// 有关更多详细信息,请参见 [模块级文档](../index.html)。
    #[cfg(any(target_arch = "riscv32", doc))]
    #[doc(cfg(any(target_arch = "riscv32")))]
    #[unstable(feature = "stdsimd", issue = "27731")]
    pub mod riscv32 {
        pub use crate::core_arch::riscv_shared::*;
    }

    /// 特定于平台的用于 `riscv64` 平台的内部函数。
    ///
    /// 有关更多详细信息,请参见 [模块级文档](../index.html)。
    #[cfg(any(target_arch = "riscv64", doc))]
    #[doc(cfg(any(target_arch = "riscv64")))]
    #[unstable(feature = "stdsimd", issue = "27731")]
    pub mod riscv64 {
        pub use crate::core_arch::riscv64::*;
        // RISC-V RV64 支持当前规范 (2022-01-05) 中的所有 RV32 指令。
        // 模块 `riscv_shared` 包括所有 RISC-V 平台下可用的指令,即
        // RISC-V RV32 指令。
        pub use crate::core_arch::riscv_shared::*;
    }

    /// 特定于平台的用于 `wasm32` 平台的内部函数。
    ///
    /// 该模块提供特定于 WebAssembly 体系结构的内部函数。
    /// 在这里,您会发现特定于 WebAssembly 的内部函数,它们不会在 `std` 的跨平台抽象中以其他方式出现,您还会发现利用 WebAssembly 提案 (如 [原子性][atomics] 和 [simd]) 的函数。
    ///
    /// `wasm32` 模块中的内部函数是根据它们所代表的 WebAssembly 指令建模的。大多数函数都以它们想要对应的指令命名,arguments/results 对应指令本身的类型签名。
    /// 稳定的 WebAssembly 指令是 [在线文档][instrdoc]。
    ///
    /// [instrdoc]: https://webassembly.github.io/spec/core/valid/instructions.html
    ///
    /// 如果一个提案在 WebAssembly 本身中还不稳定,那么这个函数中的函数可能是不稳定的,需要使用 Rust 的夜间通道。由于提案本身具有稳定性,该模块中的内部函数也应该是稳定的。
    ///
    /// [atomics]: https://github.com/webassembly/threads
    /// [simd]: https://github.com/webassembly/simd
    ///
    /// 有关 `arch` 模块和平台内部函数的一般信息,请参见 [模块级文档](../index.html)。
    ///
    /// ## Atomics
    ///
    /// [线程提案][atomics] for WebAssembly 添加了许多有关处理多线程程序的指令。[atomics] 提案中添加的大多数指令都通过 `std::sync::atomic` 模块在 Rust 中公开。
    /// 但是,某些指令在 Rust 中没有直接等效项,因此它们在此处公开。
    ///
    /// 请注意,在 [原子性][atomics] 提案中添加的指令可以在具有共享 wasm 内存和不具有共享 wasm 内存的上下文中工作。
    /// 这些内部函数始终在标准库中可用,但除非您使用 `-Ctarget-feature=+atomics` 重新编译标准库 (和所有代码),否则您可能无法高效地使用它们。
    ///
    /// 还值得指出的是,截至撰写本文时,多线程 WebAssembly 及其在 Rust 中的描述仍处于 "早期" 阶段。件基本上可以工作,但它通常需要大量的手动设置。
    /// 这个时候它不像 "只需调用 `std::thread::spawn`" 那么简单,但希望有一天它能被实现!
    ///
    /// ## SIMD
    ///
    /// WebAssembly 的 [simd 提案][simd] 添加了一个新的 `v128` 类型,用于
    /// 128 位 SIMD 寄存器。它还添加了大量指令以对 `v128` 类型进行操作以执行数据处理。例如,在 wasm 上使用 SIMD 与在 `x86_64` 上使用类似。
    /// 您将编写一个函数,例如:
    ///
    /// ```rust,ignore
    /// #[cfg(target_arch = "wasm32")]
    /// #[target_feature(enable = "simd128")]
    /// unsafe fn uses_simd() {
    ///     use std::arch::wasm32::*;
    ///     // ...
    /// }
    /// ```
    ///
    /// 然而,与 `x86_64` 不同的是,WebAssembly 目前没有在运行时动态检测是否支持 SIMD (这是 [条件部分][condsections] 和 [特性检测][feature detection] 提案的动机之一,但这还处于早期阶段)。
    ///
    /// 这意味着您的二进制文件将具有 SIMD,并且只能在支持 SIMD 的引擎上运行,或者根本不具有 SIMD。
    /// 为了兼容,标准库本身内部未使用任何 SIMD。
    /// 确定如何最好地使用 SIMD 发送 WebAssembly 二进制文件在很大程度上取决于您,因为根据您的情况,它可能非常细微。
    ///
    /// [condsections]: https://github.com/webassembly/conditional-sections
    /// [feature detection]: https://github.com/WebAssembly/feature-detection
    ///
    /// 要在编译时启用 SIMD 支持,您需要执行以下两项操作之一:
    ///
    /// * 首先,您可以使用 `#[target_feature(enable = "simd128")]` 注解函数。这将导致仅一个函数可以使用 SIMD 支持,并且在这种情况下,内部函数将像往常一样被内联。
    ///
    /// * 其次,您可以使用 `-Ctarget-feature=+simd128` 编译程序。
    ///   该编译标志毯可为您的整个编译提供 SIMD 支持。请注意,除非您使用 [重新编译标准库][buildstd],否则这不包括标准库。
    ///
    /// [buildstd]: https://doc.rust-lang.org/nightly/cargo/reference/unstable.html#build-std
    ///
    /// 如果通过这两种途径之一启用 SIMD,那么您将拥有一个使用 SIMD 指令的 WebAssembly 二进制文件,并且需要相应地进行运送。
    /// 还要注意,如果您调用 SIMD 内部函数但未通过这两种机制之一启用 SIMD,则程序中仍将生成 SIMD。
    /// 这意味着要生成没有 SIMD 的二进制文件,您将需要避免上述两个选项以及调用此模块中的任何内部函数。
    ///
    ///
    ///
    ///
    ///
    ///
    ///
    ///
    ///
    ///
    ///
    ///
    ///
    ///
    ///
    ///
    ///
    ///
    ///
    ///
    ///
    ///
    ///
    ///
    ///
    ///
    ///
    ///
    ///
    ///
    ///
    ///
    ///
    ///
    ///
    #[cfg(any(target_arch = "wasm32", doc))]
    #[doc(cfg(target_arch = "wasm32"))]
    #[stable(feature = "simd_wasm32", since = "1.33.0")]
    pub mod wasm32 {
        #[stable(feature = "simd_wasm32", since = "1.33.0")]
        pub use crate::core_arch::wasm32::*;
    }

    /// 特定于平台的用于 `wasm64` 平台的内部函数。
    ///
    /// 有关更多详细信息,请参见 [模块级文档](../index.html)。
    #[cfg(any(target_arch = "wasm64", doc))]
    #[doc(cfg(target_arch = "wasm64"))]
    #[unstable(feature = "simd_wasm64", issue = "90599")]
    pub mod wasm64 {
        #[unstable(feature = "simd_wasm64", issue = "90599")]
        pub use crate::core_arch::wasm32::*;
    }

    /// 特定于平台的用于 `wasm` 目标家庭的内部函数。
    ///
    /// 有关更多详细信息,请参见 [模块级文档](../index.html)。
    #[cfg(any(target_family = "wasm", doc))]
    #[doc(cfg(target_family = "wasm"))]
    #[unstable(feature = "simd_wasm64", issue = "90599")]
    pub mod wasm {
        #[unstable(feature = "simd_wasm64", issue = "90599")]
        pub use crate::core_arch::wasm32::*;
    }

    /// 特定于平台的用于 `mips` 平台的内部函数。
    ///
    /// 有关更多详细信息,请参见 [模块级文档](../index.html)。
    #[cfg(any(target_arch = "mips", doc))]
    #[doc(cfg(target_arch = "mips"))]
    #[unstable(feature = "stdsimd", issue = "27731")]
    pub mod mips {
        pub use crate::core_arch::mips::*;
    }

    /// 特定于平台的用于  `mips64` 平台的内部函数。
    ///
    /// 有关更多详细信息,请参见 [模块级文档](../index.html)。
    #[cfg(any(target_arch = "mips64", doc))]
    #[doc(cfg(target_arch = "mips64"))]
    #[unstable(feature = "stdsimd", issue = "27731")]
    pub mod mips64 {
        pub use crate::core_arch::mips::*;
    }

    /// 特定于平台的用于 `PowerPC` 平台的内部函数。
    ///
    /// 有关更多详细信息,请参见 [模块级文档](../index.html)。
    #[cfg(any(target_arch = "powerpc", doc))]
    #[doc(cfg(target_arch = "powerpc"))]
    #[unstable(feature = "stdsimd", issue = "27731")]
    pub mod powerpc {
        pub use crate::core_arch::powerpc::*;
    }

    /// 特定于平台的用于 `PowerPC64` 平台的内部函数。
    ///
    /// 有关更多详细信息,请参见 [模块级文档](../index.html)。
    #[cfg(any(target_arch = "powerpc64", doc))]
    #[doc(cfg(target_arch = "powerpc64"))]
    #[unstable(feature = "stdsimd", issue = "27731")]
    pub mod powerpc64 {
        pub use crate::core_arch::powerpc64::*;
    }

    /// 特定于平台的用于 `NVPTX` 平台的内部函数。
    ///
    /// 有关更多详细信息,请参见 [模块级文档](../index.html)。
    #[cfg(any(target_arch = "nvptx64", doc))]
    #[doc(cfg(target_arch = "nvptx64"))]
    #[unstable(feature = "stdsimd", issue = "27731")]
    pub mod nvptx {
        pub use crate::core_arch::nvptx::*;
    }
}

mod simd_llvm;

#[cfg(any(target_arch = "x86", target_arch = "x86_64", doc))]
#[doc(cfg(any(target_arch = "x86", target_arch = "x86_64")))]
mod x86;
#[cfg(any(target_arch = "x86_64", doc))]
#[doc(cfg(target_arch = "x86_64"))]
mod x86_64;

#[cfg(any(target_arch = "aarch64", doc))]
#[doc(cfg(target_arch = "aarch64"))]
mod aarch64;
#[cfg(any(target_arch = "arm", doc))]
#[doc(cfg(any(target_arch = "arm")))]
mod arm;

#[cfg(any(target_arch = "riscv64", doc))]
#[doc(cfg(any(target_arch = "riscv64")))]
mod riscv64;

#[cfg(any(target_family = "wasm", doc))]
#[doc(cfg(target_family = "wasm"))]
mod wasm32;

#[cfg(any(target_arch = "mips", target_arch = "mips64", doc))]
#[doc(cfg(any(target_arch = "mips", target_arch = "mips64")))]
mod mips;

#[cfg(any(target_arch = "powerpc", target_arch = "powerpc64", doc))]
#[doc(cfg(any(target_arch = "powerpc", target_arch = "powerpc64")))]
mod powerpc;

#[cfg(any(target_arch = "powerpc64", doc))]
#[doc(cfg(target_arch = "powerpc64"))]
mod powerpc64;

#[cfg(any(target_arch = "nvptx64", doc))]
#[doc(cfg(target_arch = "nvptx64"))]
mod nvptx;