Skip to content

Commit eb6b92f

Browse files
authored
Unconditionally flag as #![no_std] (rust-lang#196)
This is more idiomatic for no-std-compatible crates where imports are unconditionally rewritten to `core` and then only when necessary `std` is pulled in explicitly.
1 parent d985a84 commit eb6b92f

File tree

10 files changed

+60
-52
lines changed

10 files changed

+60
-52
lines changed

src/lib.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -128,10 +128,11 @@
128128
cast_possible_truncation, cast_precision_loss,
129129
shadow_reuse, cyclomatic_complexity, similar_names,
130130
doc_markdown, many_single_char_names))]
131-
#![cfg_attr(not(feature = "std"), no_std)]
131+
#![no_std]
132132

133-
#[cfg(not(feature = "std"))]
134-
extern crate core as std;
133+
#[cfg(any(feature = "std", test))]
134+
#[macro_use]
135+
extern crate std;
135136

136137
#[cfg(test)]
137138
extern crate stdsimd_test;

src/macros.rs

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -63,8 +63,8 @@ macro_rules! define_impl {
6363
slice: &mut [$elemty],
6464
offset: usize,
6565
) {
66-
use std::mem::size_of;
67-
use std::ptr;
66+
use core::mem::size_of;
67+
use core::ptr;
6868

6969
ptr::copy_nonoverlapping(
7070
&self as *const $name as *const u8,
@@ -83,8 +83,8 @@ macro_rules! define_impl {
8383
slice: &[$elemty],
8484
offset: usize,
8585
) -> $name {
86-
use std::mem::size_of;
87-
use std::ptr;
86+
use core::mem::size_of;
87+
use core::ptr;
8888

8989
let mut x = $name::splat(0 as $elemty);
9090
ptr::copy_nonoverlapping(
@@ -133,7 +133,7 @@ macro_rules! define_from {
133133
impl From<$from> for $to {
134134
#[inline(always)]
135135
fn from(f: $from) -> $to {
136-
unsafe { ::std::mem::transmute(f) }
136+
unsafe { ::core::mem::transmute(f) }
137137
}
138138
}
139139
)+
@@ -143,75 +143,75 @@ macro_rules! define_from {
143143
macro_rules! define_common_ops {
144144
($($ty:ident),+) => {
145145
$(
146-
impl ::std::ops::Add for $ty {
146+
impl ::core::ops::Add for $ty {
147147
type Output = Self;
148148
#[inline(always)]
149149
fn add(self, other: Self) -> Self {
150150
unsafe { simd_add(self, other) }
151151
}
152152
}
153153

154-
impl ::std::ops::Sub for $ty {
154+
impl ::core::ops::Sub for $ty {
155155
type Output = Self;
156156
#[inline(always)]
157157
fn sub(self, other: Self) -> Self {
158158
unsafe { simd_sub(self, other) }
159159
}
160160
}
161161

162-
impl ::std::ops::Mul for $ty {
162+
impl ::core::ops::Mul for $ty {
163163
type Output = Self;
164164
#[inline(always)]
165165
fn mul(self, other: Self) -> Self {
166166
unsafe { simd_mul(self, other) }
167167
}
168168
}
169169

170-
impl ::std::ops::Div for $ty {
170+
impl ::core::ops::Div for $ty {
171171
type Output = Self;
172172
#[inline(always)]
173173
fn div(self, other: Self) -> Self {
174174
unsafe { simd_div(self, other) }
175175
}
176176
}
177177

178-
impl ::std::ops::Rem for $ty {
178+
impl ::core::ops::Rem for $ty {
179179
type Output = Self;
180180
#[inline(always)]
181181
fn rem(self, other: Self) -> Self {
182182
unsafe { simd_rem(self, other) }
183183
}
184184
}
185185

186-
impl ::std::ops::AddAssign for $ty {
186+
impl ::core::ops::AddAssign for $ty {
187187
#[inline(always)]
188188
fn add_assign(&mut self, other: Self) {
189189
*self = *self + other;
190190
}
191191
}
192192

193-
impl ::std::ops::SubAssign for $ty {
193+
impl ::core::ops::SubAssign for $ty {
194194
#[inline(always)]
195195
fn sub_assign(&mut self, other: Self) {
196196
*self = *self - other;
197197
}
198198
}
199199

200-
impl ::std::ops::MulAssign for $ty {
200+
impl ::core::ops::MulAssign for $ty {
201201
#[inline(always)]
202202
fn mul_assign(&mut self, other: Self) {
203203
*self = *self * other;
204204
}
205205
}
206206

207-
impl ::std::ops::DivAssign for $ty {
207+
impl ::core::ops::DivAssign for $ty {
208208
#[inline(always)]
209209
fn div_assign(&mut self, other: Self) {
210210
*self = *self / other;
211211
}
212212
}
213213

214-
impl ::std::ops::RemAssign for $ty {
214+
impl ::core::ops::RemAssign for $ty {
215215
#[inline(always)]
216216
fn rem_assign(&mut self, other: Self) {
217217
*self = *self % other;
@@ -225,28 +225,28 @@ macro_rules! define_common_ops {
225225
macro_rules! define_shifts {
226226
($ty:ident, $elem:ident, $($by:ident),+) => {
227227
$(
228-
impl ::std::ops::Shl<$by> for $ty {
228+
impl ::core::ops::Shl<$by> for $ty {
229229
type Output = Self;
230230
#[inline(always)]
231231
fn shl(self, other: $by) -> Self {
232232
unsafe { simd_shl(self, $ty::splat(other as $elem)) }
233233
}
234234
}
235-
impl ::std::ops::Shr<$by> for $ty {
235+
impl ::core::ops::Shr<$by> for $ty {
236236
type Output = Self;
237237
#[inline(always)]
238238
fn shr(self, other: $by) -> Self {
239239
unsafe { simd_shr(self, $ty::splat(other as $elem)) }
240240
}
241241
}
242242

243-
impl ::std::ops::ShlAssign<$by> for $ty {
243+
impl ::core::ops::ShlAssign<$by> for $ty {
244244
#[inline(always)]
245245
fn shl_assign(&mut self, other: $by) {
246246
*self = *self << other;
247247
}
248248
}
249-
impl ::std::ops::ShrAssign<$by> for $ty {
249+
impl ::core::ops::ShrAssign<$by> for $ty {
250250
#[inline(always)]
251251
fn shr_assign(&mut self, other: $by) {
252252
*self = *self >> other;
@@ -260,7 +260,7 @@ macro_rules! define_shifts {
260260
macro_rules! define_float_ops {
261261
($($ty:ident),+) => {
262262
$(
263-
impl ::std::ops::Neg for $ty {
263+
impl ::core::ops::Neg for $ty {
264264
type Output = Self;
265265
#[inline(always)]
266266
fn neg(self) -> Self {
@@ -274,7 +274,7 @@ macro_rules! define_float_ops {
274274
macro_rules! define_signed_integer_ops {
275275
($($ty:ident),+) => {
276276
$(
277-
impl ::std::ops::Neg for $ty {
277+
impl ::core::ops::Neg for $ty {
278278
type Output = Self;
279279
#[inline(always)]
280280
fn neg(self) -> Self {
@@ -288,48 +288,48 @@ macro_rules! define_signed_integer_ops {
288288
macro_rules! define_integer_ops {
289289
($(($ty:ident, $elem:ident)),+) => {
290290
$(
291-
impl ::std::ops::Not for $ty {
291+
impl ::core::ops::Not for $ty {
292292
type Output = Self;
293293
#[inline(always)]
294294
fn not(self) -> Self {
295295
$ty::splat(!0) ^ self
296296
}
297297
}
298298

299-
impl ::std::ops::BitAnd for $ty {
299+
impl ::core::ops::BitAnd for $ty {
300300
type Output = Self;
301301
#[inline(always)]
302302
fn bitand(self, other: Self) -> Self {
303303
unsafe { simd_and(self, other) }
304304
}
305305
}
306-
impl ::std::ops::BitOr for $ty {
306+
impl ::core::ops::BitOr for $ty {
307307
type Output = Self;
308308
#[inline(always)]
309309
fn bitor(self, other: Self) -> Self {
310310
unsafe { simd_or(self, other) }
311311
}
312312
}
313-
impl ::std::ops::BitXor for $ty {
313+
impl ::core::ops::BitXor for $ty {
314314
type Output = Self;
315315
#[inline(always)]
316316
fn bitxor(self, other: Self) -> Self {
317317
unsafe { simd_xor(self, other) }
318318
}
319319
}
320-
impl ::std::ops::BitAndAssign for $ty {
320+
impl ::core::ops::BitAndAssign for $ty {
321321
#[inline(always)]
322322
fn bitand_assign(&mut self, other: Self) {
323323
*self = *self & other;
324324
}
325325
}
326-
impl ::std::ops::BitOrAssign for $ty {
326+
impl ::core::ops::BitOrAssign for $ty {
327327
#[inline(always)]
328328
fn bitor_assign(&mut self, other: Self) {
329329
*self = *self | other;
330330
}
331331
}
332-
impl ::std::ops::BitXorAssign for $ty {
332+
impl ::core::ops::BitXorAssign for $ty {
333333
#[inline(always)]
334334
fn bitxor_assign(&mut self, other: Self) {
335335
*self = *self ^ other;
@@ -341,12 +341,12 @@ macro_rules! define_integer_ops {
341341
u8, u16, u32, u64, usize,
342342
i8, i16, i32, i64, isize);
343343

344-
impl ::std::fmt::LowerHex for $ty {
345-
fn fmt(&self, f: &mut ::std::fmt::Formatter)
346-
-> ::std::fmt::Result {
344+
impl ::core::fmt::LowerHex for $ty {
345+
fn fmt(&self, f: &mut ::core::fmt::Formatter)
346+
-> ::core::fmt::Result {
347347
write!(f, "{}(", stringify!($ty))?;
348-
let n = ::std::mem::size_of_val(self)
349-
/ ::std::mem::size_of::<$elem>();
348+
let n = ::core::mem::size_of_val(self)
349+
/ ::core::mem::size_of::<$elem>();
350350
for i in 0..n {
351351
if i > 0 {
352352
write!(f, ", ")?;

src/runtime/cache.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
//! Cache of run-time feature detection
22
3+
use core::sync::atomic::{AtomicUsize, Ordering};
4+
use core::usize;
5+
36
use super::bit;
4-
use std::sync::atomic::{AtomicUsize, Ordering};
57

68
/// This global variable is a bitset used to cache the features supported by
79
/// the
810
/// CPU.
9-
static CACHE: AtomicUsize = AtomicUsize::new(::std::usize::MAX);
11+
static CACHE: AtomicUsize = AtomicUsize::new(usize::MAX);
1012

1113
/// Test the `bit` of the storage. If the storage has not been initialized,
1214
/// initializes it with the result of `f()`.
@@ -22,7 +24,7 @@ pub fn test<F>(bit: u32, f: F) -> bool
2224
where
2325
F: FnOnce() -> usize,
2426
{
25-
if CACHE.load(Ordering::Relaxed) == ::std::usize::MAX {
27+
if CACHE.load(Ordering::Relaxed) == usize::MAX {
2628
CACHE.store(f(), Ordering::Relaxed);
2729
}
2830
bit::test(CACHE.load(Ordering::Relaxed), bit)

src/runtime/linux/cpuinfo.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
//! Reads /proc/cpuinfo on Linux systems
22
3+
use std::prelude::v1::*;
4+
35
/// cpuinfo
46
pub struct CpuInfo {
57
raw: String,

src/runtime/x86.rs

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@
1616
//! in a global `AtomicUsize` variable. The query is performed by just checking
1717
//! whether the feature bit in this global variable is set or cleared.
1818
19+
use core::mem;
20+
1921
use super::bit;
2022

2123
/// This macro maps the string-literal feature names to values of the
@@ -271,11 +273,11 @@ pub fn detect_features() -> usize {
271273
edx,
272274
} = __cpuid(0);
273275
let vendor_id: [[u8; 4]; 3] = [
274-
::std::mem::transmute(ebx),
275-
::std::mem::transmute(edx),
276-
::std::mem::transmute(ecx),
276+
mem::transmute(ebx),
277+
mem::transmute(edx),
278+
mem::transmute(ecx),
277279
];
278-
let vendor_id: [u8; 12] = ::std::mem::transmute(vendor_id);
280+
let vendor_id: [u8; 12] = mem::transmute(vendor_id);
279281
(max_leaf, vendor_id)
280282
};
281283

src/x86/i586/avx.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,8 @@
1313
//! [amd64_ref]: http://support.amd.com/TechDocs/24594.pdf
1414
//! [wiki]: https://en.wikipedia.org/wiki/Advanced_Vector_Extensions
1515
16-
use std::mem;
17-
use std::ptr;
16+
use core::mem;
17+
use core::ptr;
1818

1919
#[cfg(test)]
2020
use stdsimd_test::assert_instr;

src/x86/i586/cpuid.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@ pub struct CpuidResult {
4545
#[inline(always)]
4646
#[cfg_attr(test, assert_instr(cpuid))]
4747
pub unsafe fn __cpuid_count(leaf: u32, sub_leaf: u32) -> CpuidResult {
48-
let mut r = ::std::mem::uninitialized::<CpuidResult>();
48+
let mut r = ::core::mem::uninitialized::<CpuidResult>();
4949
if cfg!(target_arch = "x86") {
5050
asm!("cpuid"
5151
: "={eax}"(r.eax), "={ebx}"(r.ebx), "={ecx}"(r.ecx), "={edx}"(r.edx)

src/x86/i586/sse.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
11
//! Streaming SIMD Extensions (SSE)
22
3+
use core::mem;
4+
use core::ptr;
5+
36
use simd_llvm::simd_shuffle4;
47
use v128::*;
58
use v64::f32x2;
69
use x86::c_void;
7-
use std::mem;
8-
use std::ptr;
910

1011
#[cfg(test)]
1112
use stdsimd_test::assert_instr;

src/x86/i586/sse2.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
#[cfg(test)]
44
use stdsimd_test::assert_instr;
55

6-
use std::mem;
7-
use x86::c_void;
8-
use std::ptr;
6+
use core::mem;
7+
use core::ptr;
98

109
use simd_llvm::{simd_cast, simd_shuffle16, simd_shuffle2, simd_shuffle4,
1110
simd_shuffle8};
11+
use x86::c_void;
1212
use x86::__m128i;
1313
use v128::*;
1414
use v64::*;

src/x86/i586/sse41.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
//! Streaming SIMD Extensions 4.1 (SSE4.1)
22
3-
use std::mem;
3+
use core::mem;
44

55
#[cfg(test)]
66
use stdsimd_test::assert_instr;

0 commit comments

Comments
 (0)