Skip to content
This repository was archived by the owner on May 28, 2025. It is now read-only.

Commit 3954b27

Browse files
Add conversions between vendor intrinsics (rust-lang#144)
* Add x86 vendor conversions * Add wasm32 vendor types * Add arm vendor types * Add powerpc vendor types
1 parent ac749a1 commit 3954b27

File tree

10 files changed

+186
-95
lines changed

10 files changed

+186
-95
lines changed

crates/core_simd/src/lib.rs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#![no_std]
22
#![allow(incomplete_features)]
3-
#![feature(repr_simd, platform_intrinsics, simd_ffi, const_generics)]
3+
#![feature(repr_simd, platform_intrinsics, simd_ffi, const_generics, stdsimd)]
44
#![warn(missing_docs)]
55
//! Portable SIMD module.
66
@@ -9,8 +9,6 @@ mod first;
99
#[macro_use]
1010
mod permute;
1111
#[macro_use]
12-
mod transmute;
13-
#[macro_use]
1412
mod reduction;
1513

1614
mod select;
@@ -25,6 +23,7 @@ mod intrinsics;
2523
mod iter;
2624
mod ops;
2725
mod round;
26+
mod vendor;
2827

2928
mod math;
3029

crates/core_simd/src/transmute.rs

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -1,28 +0,0 @@
1-
/// Provides implementations of `From<$a> for $b` and `From<$b> for $a` that transmutes the value.
2-
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
3-
macro_rules! from_transmute {
4-
{ unsafe $a:ty => $b:ty } => {
5-
from_transmute!{ @impl $a => $b }
6-
from_transmute!{ @impl $b => $a }
7-
};
8-
{ @impl $from:ty => $to:ty } => {
9-
impl core::convert::From<$from> for $to {
10-
#[inline]
11-
fn from(value: $from) -> $to {
12-
unsafe { core::mem::transmute(value) }
13-
}
14-
}
15-
};
16-
}
17-
18-
/// Provides implementations of `From<$generic> for core::arch::{x86, x86_64}::$intel` and
19-
/// vice-versa that transmutes the value.
20-
macro_rules! from_transmute_x86 {
21-
{ unsafe $generic:ty => $intel:ident } => {
22-
#[cfg(target_arch = "x86")]
23-
from_transmute! { unsafe $generic => core::arch::x86::$intel }
24-
25-
#[cfg(target_arch = "x86_64")]
26-
from_transmute! { unsafe $generic => core::arch::x86_64::$intel }
27-
}
28-
}

crates/core_simd/src/vector/float.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -201,10 +201,6 @@ where
201201

202202
impl_float_vector! { SimdF32, f32, SimdU32, Mask32, SimdI32 }
203203

204-
from_transmute_x86! { unsafe f32x4 => __m128 }
205-
from_transmute_x86! { unsafe f32x8 => __m256 }
206-
//from_transmute_x86! { unsafe f32x16 => __m512 }
207-
208204
/// A SIMD vector of containing `LANES` `f64` values.
209205
#[repr(simd)]
210206
pub struct SimdF64<const LANES: usize>([f64; LANES])
@@ -213,10 +209,6 @@ where
213209

214210
impl_float_vector! { SimdF64, f64, SimdU64, Mask64, SimdI64 }
215211

216-
from_transmute_x86! { unsafe f64x2 => __m128d }
217-
from_transmute_x86! { unsafe f64x4 => __m256d }
218-
//from_transmute_x86! { unsafe f64x8 => __m512d }
219-
220212
/// Vector of two `f32` values
221213
pub type f32x2 = SimdF32<2>;
222214

crates/core_simd/src/vector/int.rs

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -67,18 +67,6 @@ where
6767

6868
impl_integer_vector! { SimdIsize, isize, MaskSize, SimdIsize }
6969

70-
#[cfg(target_pointer_width = "32")]
71-
from_transmute_x86! { unsafe isizex4 => __m128i }
72-
#[cfg(target_pointer_width = "32")]
73-
from_transmute_x86! { unsafe isizex8 => __m256i }
74-
75-
#[cfg(target_pointer_width = "64")]
76-
from_transmute_x86! { unsafe isizex2 => __m128i }
77-
#[cfg(target_pointer_width = "64")]
78-
from_transmute_x86! { unsafe isizex4 => __m256i }
79-
//#[cfg(target_pointer_width = "64")]
80-
//from_transmute_x86! { unsafe isizex8 => __m512i }
81-
8270
/// A SIMD vector of containing `LANES` `i16` values.
8371
#[repr(simd)]
8472
pub struct SimdI16<const LANES: usize>([i16; LANES])
@@ -87,10 +75,6 @@ where
8775

8876
impl_integer_vector! { SimdI16, i16, Mask16, SimdI16 }
8977

90-
from_transmute_x86! { unsafe i16x8 => __m128i }
91-
from_transmute_x86! { unsafe i16x16 => __m256i }
92-
//from_transmute_x86! { unsafe i16x32 => __m512i }
93-
9478
/// A SIMD vector of containing `LANES` `i32` values.
9579
#[repr(simd)]
9680
pub struct SimdI32<const LANES: usize>([i32; LANES])
@@ -99,10 +83,6 @@ where
9983

10084
impl_integer_vector! { SimdI32, i32, Mask32, SimdI32 }
10185

102-
from_transmute_x86! { unsafe i32x4 => __m128i }
103-
from_transmute_x86! { unsafe i32x8 => __m256i }
104-
//from_transmute_x86! { unsafe i32x16 => __m512i }
105-
10686
/// A SIMD vector of containing `LANES` `i64` values.
10787
#[repr(simd)]
10888
pub struct SimdI64<const LANES: usize>([i64; LANES])
@@ -111,10 +91,6 @@ where
11191

11292
impl_integer_vector! { SimdI64, i64, Mask64, SimdI64 }
11393

114-
from_transmute_x86! { unsafe i64x2 => __m128i }
115-
from_transmute_x86! { unsafe i64x4 => __m256i }
116-
//from_transmute_x86! { unsafe i64x8 => __m512i }
117-
11894
/// A SIMD vector of containing `LANES` `i8` values.
11995
#[repr(simd)]
12096
pub struct SimdI8<const LANES: usize>([i8; LANES])
@@ -123,10 +99,6 @@ where
12399

124100
impl_integer_vector! { SimdI8, i8, Mask8, SimdI8 }
125101

126-
from_transmute_x86! { unsafe i8x16 => __m128i }
127-
from_transmute_x86! { unsafe i8x32 => __m256i }
128-
//from_transmute_x86! { unsafe i8x64 => __m512i }
129-
130102
/// Vector of two `isize` values
131103
pub type isizex2 = SimdIsize<2>;
132104

crates/core_simd/src/vector/uint.rs

Lines changed: 0 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,6 @@ where
3636

3737
impl_unsigned_vector! { SimdUsize, usize }
3838

39-
#[cfg(target_pointer_width = "32")]
40-
from_transmute_x86! { unsafe usizex4 => __m128i }
41-
#[cfg(target_pointer_width = "32")]
42-
from_transmute_x86! { unsafe usizex8 => __m256i }
43-
44-
#[cfg(target_pointer_width = "64")]
45-
from_transmute_x86! { unsafe usizex2 => __m128i }
46-
#[cfg(target_pointer_width = "64")]
47-
from_transmute_x86! { unsafe usizex4 => __m256i }
48-
//#[cfg(target_pointer_width = "64")]
49-
//from_transmute_x86! { unsafe usizex8 => __m512i }
50-
5139
/// A SIMD vector of containing `LANES` `u16` values.
5240
#[repr(simd)]
5341
pub struct SimdU16<const LANES: usize>([u16; LANES])
@@ -56,10 +44,6 @@ where
5644

5745
impl_unsigned_vector! { SimdU16, u16 }
5846

59-
from_transmute_x86! { unsafe u16x8 => __m128i }
60-
from_transmute_x86! { unsafe u16x16 => __m256i }
61-
//from_transmute_x86! { unsafe u16x32 => __m512i }
62-
6347
/// A SIMD vector of containing `LANES` `u32` values.
6448
#[repr(simd)]
6549
pub struct SimdU32<const LANES: usize>([u32; LANES])
@@ -68,10 +52,6 @@ where
6852

6953
impl_unsigned_vector! { SimdU32, u32 }
7054

71-
from_transmute_x86! { unsafe u32x4 => __m128i }
72-
from_transmute_x86! { unsafe u32x8 => __m256i }
73-
//from_transmute_x86! { unsafe u32x16 => __m512i }
74-
7555
/// A SIMD vector of containing `LANES` `u64` values.
7656
#[repr(simd)]
7757
pub struct SimdU64<const LANES: usize>([u64; LANES])
@@ -80,10 +60,6 @@ where
8060

8161
impl_unsigned_vector! { SimdU64, u64 }
8262

83-
from_transmute_x86! { unsafe u64x2 => __m128i }
84-
from_transmute_x86! { unsafe u64x4 => __m256i }
85-
//from_transmute_x86! { unsafe u64x8 => __m512i }
86-
8763
/// A SIMD vector of containing `LANES` `u8` values.
8864
#[repr(simd)]
8965
pub struct SimdU8<const LANES: usize>([u8; LANES])
@@ -92,10 +68,6 @@ where
9268

9369
impl_unsigned_vector! { SimdU8, u8 }
9470

95-
from_transmute_x86! { unsafe u8x16 => __m128i }
96-
from_transmute_x86! { unsafe u8x32 => __m256i }
97-
//from_transmute_x86! { unsafe u8x64 => __m512i }
98-
9971
/// Vector of two `usize` values
10072
pub type usizex2 = SimdUsize<2>;
10173

crates/core_simd/src/vendor.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
/// Provides implementations of `From<$a> for $b` and `From<$b> for $a` that transmutes the value.
2+
macro_rules! from_transmute {
3+
{ unsafe $a:ty => $b:ty } => {
4+
from_transmute!{ @impl $a => $b }
5+
from_transmute!{ @impl $b => $a }
6+
};
7+
{ @impl $from:ty => $to:ty } => {
8+
impl core::convert::From<$from> for $to {
9+
#[inline]
10+
fn from(value: $from) -> $to {
11+
unsafe { core::mem::transmute(value) }
12+
}
13+
}
14+
};
15+
}
16+
17+
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
18+
mod x86;
19+
20+
#[cfg(any(target_arch = "wasm32"))]
21+
mod wasm32;
22+
23+
#[cfg(any(target_arch = "arm", target_arch = "aarch64"))]
24+
mod arm;
25+
26+
#[cfg(any(target_arch = "powerpc", target_arch = "powerpc64"))]
27+
mod powerpc;

crates/core_simd/src/vendor/arm.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
use crate::*;
2+
3+
#[cfg(target_arch = "arm")]
4+
use core::arch::arm::*;
5+
6+
#[cfg(target_arch = "aarch64")]
7+
use core::arch::aarch64::*;
8+
9+
from_transmute! { unsafe f32x2 => float32x2_t }
10+
from_transmute! { unsafe f32x4 => float32x4_t }
11+
12+
from_transmute! { unsafe u8x8 => uint8x8_t }
13+
from_transmute! { unsafe u8x16 => uint8x16_t }
14+
from_transmute! { unsafe i8x8 => int8x8_t }
15+
from_transmute! { unsafe i8x16 => int8x16_t }
16+
from_transmute! { unsafe u8x8 => poly8x8_t }
17+
from_transmute! { unsafe u8x16 => poly8x16_t }
18+
19+
from_transmute! { unsafe u16x4 => uint16x4_t }
20+
from_transmute! { unsafe u16x8 => uint16x8_t }
21+
from_transmute! { unsafe i16x4 => int16x4_t }
22+
from_transmute! { unsafe i16x8 => int16x8_t }
23+
from_transmute! { unsafe u16x4 => poly16x4_t }
24+
from_transmute! { unsafe u16x8 => poly16x8_t }
25+
26+
from_transmute! { unsafe u32x2 => uint32x2_t }
27+
from_transmute! { unsafe u32x4 => uint32x4_t }
28+
from_transmute! { unsafe i32x2 => int32x2_t }
29+
from_transmute! { unsafe i32x4 => int32x4_t }
30+
31+
from_transmute! { unsafe SimdU64<1> => uint64x1_t }
32+
from_transmute! { unsafe u64x2 => uint64x2_t }
33+
from_transmute! { unsafe SimdI64<1> => int64x1_t }
34+
from_transmute! { unsafe i64x2 => int64x2_t }
35+
from_transmute! { unsafe SimdU64<1> => poly64x1_t }
36+
from_transmute! { unsafe u64x2 => poly64x2_t }
37+
38+
#[cfg(target_arch = "arm")]
39+
mod arm {
40+
use super::*;
41+
from_transmute! { unsafe SimdU8<4> => uint8x4_t }
42+
from_transmute! { unsafe SimdI8<4> => int8x4_t }
43+
44+
from_transmute! { unsafe SimdU16<2> => uint16x2_t }
45+
from_transmute! { unsafe SimdI16<2> => int16x2_t }
46+
}
47+
48+
#[cfg(target_arch = "aarch64")]
49+
mod aarch64 {
50+
use super::*;
51+
from_transmute! { unsafe SimdF64<1> => float64x1_t }
52+
from_transmute! { unsafe f64x2 => float64x2_t }
53+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
use crate::*;
2+
3+
#[cfg(target_arch = "powerpc")]
4+
use core::arch::powerpc::*;
5+
6+
#[cfg(target_arch = "powerpc64")]
7+
use core::arch::powerpc64::*;
8+
9+
from_transmute! { unsafe f64x2 => vector_double }
10+
from_transmute! { unsafe i64x2 => vector_signed_long }
11+
from_transmute! { unsafe u64x2 => vector_unsigned_long }

crates/core_simd/src/vendor/wasm32.rs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
use crate::*;
2+
use core::arch::wasm32::v128;
3+
4+
from_transmute! { unsafe u8x16 => v128 }
5+
from_transmute! { unsafe i8x16 => v128 }
6+
7+
from_transmute! { unsafe u16x8 => v128 }
8+
from_transmute! { unsafe i16x8 => v128 }
9+
10+
from_transmute! { unsafe u32x4 => v128 }
11+
from_transmute! { unsafe i32x4 => v128 }
12+
from_transmute! { unsafe f32x4 => v128 }
13+
14+
from_transmute! { unsafe u64x2 => v128 }
15+
from_transmute! { unsafe i64x2 => v128 }
16+
from_transmute! { unsafe f64x2 => v128 }
17+
18+
#[cfg(target_pointer_width = "32")]
19+
mod p32 {
20+
use super::*;
21+
from_transmute! { unsafe usizex4 => v128 }
22+
from_transmute! { unsafe isizex4 => v128 }
23+
}
24+
25+
#[cfg(target_pointer_width = "64")]
26+
mod p64 {
27+
use super::*;
28+
from_transmute! { unsafe usizex2 => v128 }
29+
from_transmute! { unsafe isizex2 => v128 }
30+
}

crates/core_simd/src/vendor/x86.rs

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
use crate::*;
2+
3+
#[cfg(any(target_arch = "x86"))]
4+
use core::arch::x86::*;
5+
6+
#[cfg(target_arch = "x86_64")]
7+
use core::arch::x86_64::*;
8+
9+
from_transmute! { unsafe u8x16 => __m128i }
10+
from_transmute! { unsafe u8x32 => __m256i }
11+
//from_transmute! { unsafe u8x64 => __m512i }
12+
from_transmute! { unsafe i8x16 => __m128i }
13+
from_transmute! { unsafe i8x32 => __m256i }
14+
//from_transmute! { unsafe i8x64 => __m512i }
15+
16+
from_transmute! { unsafe u16x8 => __m128i }
17+
from_transmute! { unsafe u16x16 => __m256i }
18+
from_transmute! { unsafe u16x32 => __m512i }
19+
from_transmute! { unsafe i16x8 => __m128i }
20+
from_transmute! { unsafe i16x16 => __m256i }
21+
from_transmute! { unsafe i16x32 => __m512i }
22+
23+
from_transmute! { unsafe u32x4 => __m128i }
24+
from_transmute! { unsafe u32x8 => __m256i }
25+
from_transmute! { unsafe u32x16 => __m512i }
26+
from_transmute! { unsafe i32x4 => __m128i }
27+
from_transmute! { unsafe i32x8 => __m256i }
28+
from_transmute! { unsafe i32x16 => __m512i }
29+
from_transmute! { unsafe f32x4 => __m128 }
30+
from_transmute! { unsafe f32x8 => __m256 }
31+
from_transmute! { unsafe f32x16 => __m512 }
32+
33+
from_transmute! { unsafe u64x2 => __m128i }
34+
from_transmute! { unsafe u64x4 => __m256i }
35+
from_transmute! { unsafe u64x8 => __m512i }
36+
from_transmute! { unsafe i64x2 => __m128i }
37+
from_transmute! { unsafe i64x4 => __m256i }
38+
from_transmute! { unsafe i64x8 => __m512i }
39+
from_transmute! { unsafe f64x2 => __m128d }
40+
from_transmute! { unsafe f64x4 => __m256d }
41+
from_transmute! { unsafe f64x8 => __m512d }
42+
43+
#[cfg(target_pointer_width = "32")]
44+
mod p32 {
45+
use super::*;
46+
from_transmute! { unsafe usizex4 => __m128i }
47+
from_transmute! { unsafe usizex8 => __m256i }
48+
from_transmute! { unsafe SimdUsize<16> => __m512i }
49+
from_transmute! { unsafe isizex4 => __m128i }
50+
from_transmute! { unsafe isizex8 => __m256i }
51+
from_transmute! { unsafe SimdIsize<16> => __m512i }
52+
}
53+
54+
#[cfg(target_pointer_width = "64")]
55+
mod p64 {
56+
use super::*;
57+
from_transmute! { unsafe usizex2 => __m128i }
58+
from_transmute! { unsafe usizex4 => __m256i }
59+
from_transmute! { unsafe usizex8 => __m512i }
60+
from_transmute! { unsafe isizex2 => __m128i }
61+
from_transmute! { unsafe isizex4 => __m256i }
62+
from_transmute! { unsafe isizex8 => __m512i }
63+
}

0 commit comments

Comments
 (0)