@@ -1475,6 +1475,25 @@ pub fn v128_load_at(memory: &[u8], address: usize) -> Result<V128, TrapCode> {
14751475 memory:: load_at :: < u128 > ( memory, address) . map ( V128 :: from)
14761476}
14771477
1478+ macro_rules! impl_v128_lowN_zero_for {
1479+ (
1480+ $( fn $name: ident( bits: $bits_ty: ty) -> V128 ; ) *
1481+ ) => {
1482+ $(
1483+ #[ doc = concat!( "Executes a Wasmi specific `" , stringify!( $name) , "` instruction." ) ]
1484+ #[ doc = "" ]
1485+ #[ doc = concat!( "Returns a [`V128`] value with the first `" , stringify!( $bits_ty) , "` lane set to `bits` and all others to zero." ) ]
1486+ pub fn $name( bits: $bits_ty) -> V128 {
1487+ V128 :: splat:: <$bits_ty>( 0 ) . replace_lane:: <$bits_ty>( <$bits_ty as IntoLaneIdx >:: LaneIdx :: zero( ) , bits)
1488+ }
1489+ ) *
1490+ } ;
1491+ }
1492+ impl_v128_lowN_zero_for ! {
1493+ fn v128_low32_zero( bits: u32 ) -> V128 ;
1494+ fn v128_low64_zero( bits: u64 ) -> V128 ;
1495+ }
1496+
14781497macro_rules! impl_v128_loadN_zero_for {
14791498 (
14801499 $( fn $name: ident( memory: & [ u8 ] , ptr: u64 , offset: u64 ) -> Result <V128 , TrapCode > = $ty: ty; ) *
@@ -1626,7 +1645,7 @@ impl_v128_loadN_lane_at_for! {
16261645/// Usually `T` is an array of `U` where `U` fits multiple times into `Self`.
16271646/// An example of this is that `u64` can be split into `[u32; 2]`.
16281647///
1629- /// This is a helper trait to implement [`V128::load_nxm `] generically.
1648+ /// This is a helper trait to implement [`V128::widen_nxm `] generically.
16301649trait SplitInto < T > {
16311650 type Output ;
16321651 fn split_into ( self ) -> Self :: Output ;
@@ -1661,7 +1680,7 @@ impl_split_into_for! {
16611680
16621681/// Allows to extend all items in an array from `T` to `Ext`.
16631682///
1664- /// This is a helper trait to implement [`V128::load_nxm `] generically.
1683+ /// This is a helper trait to implement [`V128::widen_nxm `] generically.
16651684trait ExtendArray < T > {
16661685 type Output ;
16671686 fn extend_array ( self ) -> Self :: Output ;
@@ -1679,7 +1698,7 @@ where
16791698
16801699impl V128 {
16811700 /// Interprets `bits` as array of `Narrow` and distribute the (sign) extended items as [`V128`].
1682- fn load_nxm < Narrow , Wide > ( bits : u64 ) -> V128
1701+ fn widen_nxm < Narrow , Wide > ( bits : u64 ) -> V128
16831702 where
16841703 u64 : SplitInto < Narrow , Output : ExtendArray < Wide , Output : Into < <Wide as IntoLanes >:: Lanes > > > ,
16851704 Wide : IntoLanes ,
@@ -1688,6 +1707,33 @@ impl V128 {
16881707 }
16891708}
16901709
1710+ macro_rules! impl_v128_widen_mxn {
1711+ (
1712+ $( fn $name: ident( bits: u64 ) -> V128 = ( $n: ty => $w: ty) ; ) *
1713+ ) => {
1714+ $(
1715+ #[ doc = concat!( "Executes a specialized Wasmi `" , stringify!( $name) , "` instruction." ) ]
1716+ #[ doc = "" ]
1717+ #[ doc = concat!( "Returns a [`V128`] where each lane is widened from `" , stringify!( $n) , "` to `" , stringify!( $w) , "`." ) ]
1718+ #[ doc = "" ]
1719+ #[ doc = " # Note" ]
1720+ #[ doc = "" ]
1721+ #[ doc = concat!( "The `bits` argument is reinterpreted as array of `" , stringify!( $n) , "`." ) ]
1722+ pub fn $name( bits: u64 ) -> V128 {
1723+ V128 :: widen_nxm:: <$n, $w>( bits)
1724+ }
1725+ ) *
1726+ } ;
1727+ }
1728+ impl_v128_widen_mxn ! {
1729+ fn v128_widen8x8_s( bits: u64 ) -> V128 = ( i8 => i16 ) ;
1730+ fn v128_widen8x8_u( bits: u64 ) -> V128 = ( u8 => u16 ) ;
1731+ fn v128_widen16x4_s( bits: u64 ) -> V128 = ( i16 => i32 ) ;
1732+ fn v128_widen16x4_u( bits: u64 ) -> V128 = ( u16 => u32 ) ;
1733+ fn v128_widen32x2_s( bits: u64 ) -> V128 = ( i32 => i64 ) ;
1734+ fn v128_widen32x2_u( bits: u64 ) -> V128 = ( u32 => u64 ) ;
1735+ }
1736+
16911737macro_rules! impl_v128_load_mxn {
16921738 (
16931739 $( fn $name: ident( memory: & [ u8 ] , ptr: u64 , offset: u64 ) -> Result <V128 , TrapCode > = ( $n: ty => $w: ty) ; ) *
@@ -1700,7 +1746,7 @@ macro_rules! impl_v128_load_mxn {
17001746 /// - If `ptr + offset` overflows.
17011747 /// - If `ptr + offset` loads out of bounds from `memory`.
17021748 pub fn $name( memory: & [ u8 ] , ptr: u64 , offset: u64 ) -> Result <V128 , TrapCode > {
1703- memory:: load:: <u64 >( memory, ptr, offset) . map( V128 :: load_nxm :: <$n, $w>)
1749+ memory:: load:: <u64 >( memory, ptr, offset) . map( V128 :: widen_nxm :: <$n, $w>)
17041750 }
17051751 ) *
17061752 } ;
@@ -1725,7 +1771,7 @@ macro_rules! impl_v128_load_mxn_at {
17251771 ///
17261772 /// If `address` loads out of bounds from `memory`.
17271773 pub fn $name( memory: & [ u8 ] , address: usize ) -> Result <V128 , TrapCode > {
1728- memory:: load_at:: <u64 >( memory, address) . map( V128 :: load_nxm :: <$n, $w>)
1774+ memory:: load_at:: <u64 >( memory, address) . map( V128 :: widen_nxm :: <$n, $w>)
17291775 }
17301776 ) *
17311777 } ;
0 commit comments