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
//! `core_arch`

#[macro_use]
mod macros;

#[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` 平台的平台特定的内联函数。
    ///
    /// 有关更多详细信息,请参见 [module documentation](../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` 平台的平台特定的内联函数。
    ///
    /// 有关更多详细信息,请参见 [module documentation](../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` 平台的平台特定的内联函数。
    ///
    /// 有关更多详细信息,请参见 [module documentation](../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` 平台的平台特定的内联函数。
    ///
    /// 有关更多详细信息,请参见 [module documentation](../index.html)。
    #[cfg(any(target_arch = "aarch64", doc))]
    #[doc(cfg(target_arch = "aarch64"))]
    #[unstable(feature = "stdsimd", issue = "27731")]
    pub mod aarch64 {
        pub use crate::core_arch::aarch64::*;
    }

    /// `wasm32` 平台的平台特定的内联函数。
    ///
    /// 该模块提供特定于 WebAssembly 体系结构的内联函数。
    /// 在这里,您会发现特定于 WebAssembly 的内联函数,它们不会在 `std` 的跨平台抽象中以其他方式出现,您还会发现利用 WebAssembly 提案 (如 [atomics] 和 [simd]) 的函数。
    ///
    /// `wasm32` 模块中的内联函数是根据它们所代表的 WebAssembly 指令建模的。大多数函数都以它们想要对应的指令命名,arguments/results 对应指令本身的类型签名。
    /// 稳定的 WebAssembly 指令是 [documented online][instrdoc]。
    ///
    /// [instrdoc]: https://webassembly.github.io/spec/core/valid/instructions.html
    ///
    /// 如果一个提案在 WebAssembly 本身中还不稳定,那么这个函数中的函数可能是不稳定的,需要使用 Rust 的 nightly 通道。由于提案本身稳定,该模块中的内联函数也应该稳定。
    ///
    /// [atomics]: https://github.com/webassembly/threads
    /// [simd]: https://github.com/webassembly/simd
    ///
    /// 有关 `arch` 模块和平台内联函数的一般信息,请参见 [module documentation](../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。
    /// 确定如何最好地将 WebAssembly 二进制文件与 SIMD 一起交付,很大程度上取决于您的情况,具体取决于您的情况。
    ///
    /// [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 支持。请注意,除非您使用 [recompile the standard library][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::*;
    }

    /// `mips` 平台的平台特定的内联函数。
    ///
    /// 有关更多详细信息,请参见 [module documentation](../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` 平台的平台特定的内联函数。
    ///
    /// 有关更多详细信息,请参见 [module documentation](../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` 平台的平台特定的内联函数。
    ///
    /// 有关更多详细信息,请参见 [module documentation](../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` 平台的平台特定的内联函数。
    ///
    /// 有关更多详细信息,请参见 [module documentation](../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` 平台的平台特定的内联函数。
    ///
    /// 有关更多详细信息,请参见 [module documentation](../index.html)。
    #[cfg(any(target_arch = "nvptx", target_arch = "nvptx64", doc))]
    #[doc(cfg(any(target_arch = "nvptx", 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 = "wasm32", doc))]
#[doc(cfg(target_arch = "wasm32"))]
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 = "nvptx", target_arch = "nvptx64", doc))]
#[doc(cfg(any(target_arch = "nvptx", target_arch = "nvptx64")))]
mod nvptx;