Skip to content

Commit 45585ee

Browse files
authored
Fix various conditions around ASM selection (#1713)
- Log the correct CPU feature if "nasm" feature is disabled - Enable choosing SSE2 and SSSE3 optimization levels - Fix a crash that would occur from attempting to call SSSE3 assembly when SSE2 optimization level is selected
1 parent bb2c0e6 commit 45585ee

File tree

2 files changed

+22
-5
lines changed

2 files changed

+22
-5
lines changed

src/asm/dist.rs

-1
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,6 @@ mod x86_64 {
280280
CpuFeatureLevel::len()] = {
281281
let mut out = [[None; DIST_FNS_LENGTH]; CpuFeatureLevel::len()];
282282

283-
out[CpuFeatureLevel::SSE2 as usize] = SAD_HBD_FNS_SSSE3;
284283
out[CpuFeatureLevel::SSSE3 as usize] = SAD_HBD_FNS_SSSE3;
285284
out[CpuFeatureLevel::AVX2 as usize] = SAD_HBD_FNS_SSSE3;
286285

src/cpu_features.rs

+22-4
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,21 @@
77
// Media Patent License 1.0 was not distributed with this source code in the
88
// PATENTS file, you can obtain it at www.aomedia.org/license/patent.
99

10-
#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
10+
#[cfg(not(all(
11+
feature = "nasm",
12+
any(target_arch = "x86", target_arch = "x86_64")
13+
)))]
1114
pub use native::*;
12-
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
15+
#[cfg(all(
16+
feature = "nasm",
17+
any(target_arch = "x86", target_arch = "x86_64")
18+
))]
1319
pub use x86::*;
1420

15-
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
21+
#[cfg(all(
22+
feature = "nasm",
23+
any(target_arch = "x86", target_arch = "x86_64")
24+
))]
1625
mod x86 {
1726
use arg_enum_proc_macro::ArgEnum;
1827
use std::env;
@@ -42,13 +51,19 @@ mod x86 {
4251
fn default() -> CpuFeatureLevel {
4352
let detected: CpuFeatureLevel = if is_x86_feature_detected!("avx2") {
4453
CpuFeatureLevel::AVX2
54+
} else if is_x86_feature_detected!("ssse3") {
55+
CpuFeatureLevel::SSSE3
56+
} else if is_x86_feature_detected!("sse2") {
57+
CpuFeatureLevel::SSE2
4558
} else {
4659
CpuFeatureLevel::NATIVE
4760
};
4861
let manual: CpuFeatureLevel = match env::var("RAV1E_CPU_TARGET") {
4962
Ok(feature) => match feature.as_ref() {
5063
"rust" => CpuFeatureLevel::NATIVE,
5164
"avx2" => CpuFeatureLevel::AVX2,
65+
"ssse3" => CpuFeatureLevel::SSSE3,
66+
"sse2" => CpuFeatureLevel::SSE2,
5267
_ => detected,
5368
},
5469
Err(_e) => detected,
@@ -62,7 +77,10 @@ mod x86 {
6277
}
6378
}
6479

65-
#[cfg(not(any(target_arch = "x86", target_arch = "x86_64")))]
80+
#[cfg(not(all(
81+
feature = "nasm",
82+
any(target_arch = "x86", target_arch = "x86_64")
83+
)))]
6684
mod native {
6785
use arg_enum_proc_macro::ArgEnum;
6886

0 commit comments

Comments
 (0)