Skip to content

Commit dc4dc99

Browse files
committed
Change to various generic impls
1 parent 054f25f commit dc4dc99

File tree

8 files changed

+370
-400
lines changed

8 files changed

+370
-400
lines changed

crates/core_simd/src/fmt.rs

Lines changed: 25 additions & 77 deletions
Original file line numberDiff line numberDiff line change
@@ -1,88 +1,36 @@
1-
macro_rules! debug_wrapper {
2-
{ $($trait:ident => $name:ident,)* } => {
1+
macro_rules! impl_fmt_trait {
2+
{ $($trait:ident,)* } => {
33
$(
4-
pub(crate) fn $name<T: core::fmt::$trait>(slice: &[T], f: &mut core::fmt::Formatter) -> core::fmt::Result {
5-
#[repr(transparent)]
6-
struct Wrapper<'a, T: core::fmt::$trait>(&'a T);
4+
impl<Element, const LANES: usize> core::fmt::$trait for crate::Simd<Element, LANES>
5+
where
6+
crate::LaneCount<LANES>: crate::SupportedLaneCount,
7+
Element: crate::SimdElement + core::fmt::$trait,
8+
{
9+
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
10+
#[repr(transparent)]
11+
struct Wrapper<'a, T: core::fmt::$trait>(&'a T);
712

8-
impl<T: core::fmt::$trait> core::fmt::Debug for Wrapper<'_, T> {
9-
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
10-
self.0.fmt(f)
13+
impl<T: core::fmt::$trait> core::fmt::Debug for Wrapper<'_, T> {
14+
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
15+
self.0.fmt(f)
16+
}
1117
}
12-
}
13-
14-
f.debug_list()
15-
.entries(slice.iter().map(|x| Wrapper(x)))
16-
.finish()
17-
}
18-
)*
19-
}
20-
}
2118

22-
debug_wrapper! {
23-
Debug => format,
24-
Binary => format_binary,
25-
LowerExp => format_lower_exp,
26-
UpperExp => format_upper_exp,
27-
Octal => format_octal,
28-
LowerHex => format_lower_hex,
29-
UpperHex => format_upper_hex,
30-
}
31-
32-
macro_rules! impl_fmt_trait {
33-
{ $($type:ident => $(($trait:ident, $format:ident)),*;)* } => {
34-
$( // repeat type
35-
$( // repeat trait
36-
impl<const LANES: usize> core::fmt::$trait for crate::$type<LANES>
37-
where
38-
crate::LaneCount<LANES>: crate::SupportedLaneCount,
39-
{
40-
fn fmt(&self, f: &mut core::fmt::Formatter) -> core::fmt::Result {
41-
$format(self.as_ref(), f)
42-
}
19+
f.debug_list()
20+
.entries(self.as_array().iter().map(|x| Wrapper(x)))
21+
.finish()
4322
}
44-
)*
23+
}
4524
)*
46-
};
47-
{ integers: $($type:ident,)* } => {
48-
impl_fmt_trait! {
49-
$($type =>
50-
(Debug, format),
51-
(Binary, format_binary),
52-
(LowerExp, format_lower_exp),
53-
(UpperExp, format_upper_exp),
54-
(Octal, format_octal),
55-
(LowerHex, format_lower_hex),
56-
(UpperHex, format_upper_hex);
57-
)*
58-
}
59-
};
60-
{ floats: $($type:ident,)* } => {
61-
impl_fmt_trait! {
62-
$($type =>
63-
(Debug, format),
64-
(LowerExp, format_lower_exp),
65-
(UpperExp, format_upper_exp);
66-
)*
67-
}
68-
};
69-
{ masks: $($type:ident,)* } => {
70-
impl_fmt_trait! {
71-
$($type =>
72-
(Debug, format);
73-
)*
74-
}
7525
}
7626
}
7727

7828
impl_fmt_trait! {
79-
integers:
80-
SimdU8, SimdU16, SimdU32, SimdU64,
81-
SimdI8, SimdI16, SimdI32, SimdI64,
82-
SimdUsize, SimdIsize,
83-
}
84-
85-
impl_fmt_trait! {
86-
floats:
87-
SimdF32, SimdF64,
29+
Debug,
30+
Binary,
31+
LowerExp,
32+
UpperExp,
33+
Octal,
34+
LowerHex,
35+
UpperHex,
8836
}

crates/core_simd/src/lib.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
#![allow(incomplete_features)]
33
#![feature(
44
const_evaluatable_checked,
5+
const_fn_trait_bound,
56
const_generics,
67
platform_intrinsics,
78
repr_simd,

crates/core_simd/src/permute.rs

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
macro_rules! impl_shuffle_lane {
2-
{ $name:ident, $fn:ident, $n:literal } => {
3-
impl $name<$n> {
2+
{ $fn:ident, $n:literal } => {
3+
impl<Element> crate::Simd<Element, $n>
4+
where
5+
Element: crate::SimdElement,
6+
{
47
/// A const SIMD shuffle that takes 2 SIMD vectors and produces another vector, using
58
/// the indices in the const parameter. The first or "self" vector will have its lanes
69
/// indexed from 0, and the second vector will have its first lane indexed at $n.
@@ -138,12 +141,8 @@ macro_rules! impl_shuffle_lane {
138141
}
139142
}
140143

141-
macro_rules! impl_shuffle_2pow_lanes {
142-
{ $name:ident } => {
143-
impl_shuffle_lane!{ $name, simd_shuffle2, 2 }
144-
impl_shuffle_lane!{ $name, simd_shuffle4, 4 }
145-
impl_shuffle_lane!{ $name, simd_shuffle8, 8 }
146-
impl_shuffle_lane!{ $name, simd_shuffle16, 16 }
147-
impl_shuffle_lane!{ $name, simd_shuffle32, 32 }
148-
}
149-
}
144+
impl_shuffle_lane! { simd_shuffle2, 2 }
145+
impl_shuffle_lane! { simd_shuffle4, 4 }
146+
impl_shuffle_lane! { simd_shuffle8, 8 }
147+
impl_shuffle_lane! { simd_shuffle16, 16 }
148+
impl_shuffle_lane! { simd_shuffle32, 32 }

0 commit comments

Comments
 (0)