Skip to content

Commit f45e913

Browse files
alexcrichtonAmanieu
authored andcommitted
wasm: Add missing #[target_feature] to simd ctors
This is a resubmission of #1609 which was ruled optional but not necessary at the time but it's now necessary. These weren't originally applied as they weren't allowed in a `const` context but that's no longer applicable. At the same time though be sure to add some small tests to ensure that these intrinsics can be used in a `const` context.
1 parent 945fecc commit f45e913

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

.github/workflows/main.yml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,8 @@ jobs:
103103
# Temporarily disabled due to fallout from SIMD ABI checking.
104104
#- tuple: loongarch64-unknown-linux-gnu
105105
# os: ubuntu-latest
106-
#- tuple: wasm32-wasip1
107-
# os: ubuntu-latest
106+
- tuple: wasm32-wasip1
107+
os: ubuntu-latest
108108

109109
# macOS targets
110110
- tuple: x86_64-apple-darwin

crates/core_arch/src/wasm32/simd128.rs

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -663,6 +663,7 @@ pub unsafe fn v128_store64_lane<const L: usize>(v: v128, m: *mut u64) {
663663
#[doc(alias("v128.const"))]
664664
#[stable(feature = "wasm_simd", since = "1.54.0")]
665665
#[rustc_const_stable(feature = "wasm_simd", since = "1.54.0")]
666+
#[target_feature(enable = "simd128")]
666667
pub const fn i8x16(
667668
a0: i8,
668669
a1: i8,
@@ -695,6 +696,7 @@ pub const fn i8x16(
695696
#[doc(alias("v128.const"))]
696697
#[stable(feature = "wasm_simd", since = "1.54.0")]
697698
#[rustc_const_stable(feature = "wasm_simd", since = "1.54.0")]
699+
#[target_feature(enable = "simd128")]
698700
pub const fn u8x16(
699701
a0: u8,
700702
a1: u8,
@@ -741,6 +743,7 @@ pub const fn u8x16(
741743
#[doc(alias("v128.const"))]
742744
#[stable(feature = "wasm_simd", since = "1.54.0")]
743745
#[rustc_const_stable(feature = "wasm_simd", since = "1.54.0")]
746+
#[target_feature(enable = "simd128")]
744747
pub const fn i16x8(a0: i16, a1: i16, a2: i16, a3: i16, a4: i16, a5: i16, a6: i16, a7: i16) -> v128 {
745748
simd::i16x8::new(a0, a1, a2, a3, a4, a5, a6, a7).v128()
746749
}
@@ -753,6 +756,7 @@ pub const fn i16x8(a0: i16, a1: i16, a2: i16, a3: i16, a4: i16, a5: i16, a6: i16
753756
#[doc(alias("v128.const"))]
754757
#[stable(feature = "wasm_simd", since = "1.54.0")]
755758
#[rustc_const_stable(feature = "wasm_simd", since = "1.54.0")]
759+
#[target_feature(enable = "simd128")]
756760
pub const fn u16x8(a0: u16, a1: u16, a2: u16, a3: u16, a4: u16, a5: u16, a6: u16, a7: u16) -> v128 {
757761
simd::u16x8::new(a0, a1, a2, a3, a4, a5, a6, a7).v128()
758762
}
@@ -766,6 +770,7 @@ pub const fn u16x8(a0: u16, a1: u16, a2: u16, a3: u16, a4: u16, a5: u16, a6: u16
766770
#[doc(alias("v128.const"))]
767771
#[stable(feature = "wasm_simd", since = "1.54.0")]
768772
#[rustc_const_stable(feature = "wasm_simd", since = "1.54.0")]
773+
#[target_feature(enable = "simd128")]
769774
pub const fn i32x4(a0: i32, a1: i32, a2: i32, a3: i32) -> v128 {
770775
simd::i32x4::new(a0, a1, a2, a3).v128()
771776
}
@@ -778,6 +783,7 @@ pub const fn i32x4(a0: i32, a1: i32, a2: i32, a3: i32) -> v128 {
778783
#[doc(alias("v128.const"))]
779784
#[stable(feature = "wasm_simd", since = "1.54.0")]
780785
#[rustc_const_stable(feature = "wasm_simd", since = "1.54.0")]
786+
#[target_feature(enable = "simd128")]
781787
pub const fn u32x4(a0: u32, a1: u32, a2: u32, a3: u32) -> v128 {
782788
simd::u32x4::new(a0, a1, a2, a3).v128()
783789
}
@@ -791,6 +797,7 @@ pub const fn u32x4(a0: u32, a1: u32, a2: u32, a3: u32) -> v128 {
791797
#[doc(alias("v128.const"))]
792798
#[stable(feature = "wasm_simd", since = "1.54.0")]
793799
#[rustc_const_stable(feature = "wasm_simd", since = "1.54.0")]
800+
#[target_feature(enable = "simd128")]
794801
pub const fn i64x2(a0: i64, a1: i64) -> v128 {
795802
simd::i64x2::new(a0, a1).v128()
796803
}
@@ -803,6 +810,7 @@ pub const fn i64x2(a0: i64, a1: i64) -> v128 {
803810
#[doc(alias("v128.const"))]
804811
#[stable(feature = "wasm_simd", since = "1.54.0")]
805812
#[rustc_const_stable(feature = "wasm_simd", since = "1.54.0")]
813+
#[target_feature(enable = "simd128")]
806814
pub const fn u64x2(a0: u64, a1: u64) -> v128 {
807815
simd::u64x2::new(a0, a1).v128()
808816
}
@@ -816,6 +824,7 @@ pub const fn u64x2(a0: u64, a1: u64) -> v128 {
816824
#[doc(alias("v128.const"))]
817825
#[stable(feature = "wasm_simd", since = "1.54.0")]
818826
#[rustc_const_stable(feature = "wasm_simd_const", since = "1.56.0")]
827+
#[target_feature(enable = "simd128")]
819828
pub const fn f32x4(a0: f32, a1: f32, a2: f32, a3: f32) -> v128 {
820829
simd::f32x4::new(a0, a1, a2, a3).v128()
821830
}
@@ -829,6 +838,7 @@ pub const fn f32x4(a0: f32, a1: f32, a2: f32, a3: f32) -> v128 {
829838
#[doc(alias("v128.const"))]
830839
#[stable(feature = "wasm_simd", since = "1.54.0")]
831840
#[rustc_const_stable(feature = "wasm_simd_const", since = "1.56.0")]
841+
#[target_feature(enable = "simd128")]
832842
pub const fn f64x2(a0: f64, a1: f64) -> v128 {
833843
simd::f64x2::new(a0, a1).v128()
834844
}
@@ -4207,6 +4217,17 @@ mod tests {
42074217
use std::num::Wrapping;
42084218
use std::prelude::v1::*;
42094219

4220+
const _C1: v128 = i8x16(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
4221+
const _C2: v128 = u8x16(0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15);
4222+
const _C3: v128 = i16x8(0, 1, 2, 3, 4, 5, 6, 7);
4223+
const _C4: v128 = u16x8(0, 1, 2, 3, 4, 5, 6, 7);
4224+
const _C5: v128 = i32x4(0, 1, 2, 3);
4225+
const _C6: v128 = u32x4(0, 1, 2, 3);
4226+
const _C7: v128 = i64x2(0, 1);
4227+
const _C8: v128 = u64x2(0, 1);
4228+
const _C9: v128 = f32x4(0.0, 1.0, 2.0, 3.0);
4229+
const _C10: v128 = f64x2(0.0, 1.0);
4230+
42104231
fn compare_bytes(a: v128, b: v128) {
42114232
let a: [u8; 16] = unsafe { transmute(a) };
42124233
let b: [u8; 16] = unsafe { transmute(b) };

0 commit comments

Comments
 (0)