Skip to content

Commit c249157

Browse files
authored
Consolidate AVX2 and SSE4.2 generation into one module (#178)
This PR is stacked on top of #177. After adding the `Level` trait as an abstraction, we can use it to merge the AVX2 and SSE4.2 implementations into a single module. Most of the logic is the same, except for a few functions which need to do something different if AVX2 is supported. This gets rid of a lot of duplicate code.
1 parent 0bfdf90 commit c249157

5 files changed

Lines changed: 1496 additions & 1595 deletions

File tree

fearless_simd_gen/src/arch/x86.rs

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// SPDX-License-Identifier: Apache-2.0 OR MIT
33

44
use crate::types::{ScalarType, VecType};
5-
use proc_macro2::{Ident, Span, TokenStream};
5+
use proc_macro2::{Ident, TokenStream};
66
use quote::{format_ident, quote};
77

88
pub(crate) fn translate_op(op: &str) -> Option<&'static str> {
@@ -28,17 +28,6 @@ pub(crate) fn translate_op(op: &str) -> Option<&'static str> {
2828
})
2929
}
3030

31-
pub(crate) fn arch_ty(ty: &VecType) -> Ident {
32-
let suffix = match (ty.scalar, ty.scalar_bits) {
33-
(ScalarType::Float, 32) => "",
34-
(ScalarType::Float, 64) => "d",
35-
(ScalarType::Float, _) => unimplemented!(),
36-
(ScalarType::Unsigned | ScalarType::Int | ScalarType::Mask, _) => "i",
37-
};
38-
let name = format!("__m{}{}", ty.scalar_bits * ty.len, suffix);
39-
Ident::new(&name, Span::call_site())
40-
}
41-
4231
pub(crate) fn expr(op: &str, ty: &VecType, args: &[TokenStream]) -> TokenStream {
4332
if let Some(op_name) = translate_op(op) {
4433
let sign_aware = matches!(op, "max" | "min");

fearless_simd_gen/src/main.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,13 @@ use crate::level::Level as _;
1616
mod arch;
1717
mod generic;
1818
mod level;
19-
mod mk_avx2;
2019
mod mk_fallback;
2120
mod mk_neon;
2221
mod mk_ops;
2322
mod mk_simd_trait;
2423
mod mk_simd_types;
25-
mod mk_sse4_2;
2624
mod mk_wasm;
25+
mod mk_x86;
2726
mod ops;
2827
mod types;
2928

@@ -65,8 +64,8 @@ impl Module {
6564
Self::Neon => mk_neon::Neon.make_module(),
6665
Self::Wasm => mk_wasm::WasmSimd128.make_module(),
6766
Self::Fallback => mk_fallback::Fallback.make_module(),
68-
Self::Sse4_2 => mk_sse4_2::Sse4_2.make_module(),
69-
Self::Avx2 => mk_avx2::Avx2.make_module(),
67+
Self::Sse4_2 => mk_x86::X86::Sse4_2.make_module(),
68+
Self::Avx2 => mk_x86::X86::Avx2.make_module(),
7069
}
7170
}
7271

fearless_simd_gen/src/mk_avx2.rs

Lines changed: 0 additions & 333 deletions
This file was deleted.

0 commit comments

Comments
 (0)