Skip to content

Commit 371220d

Browse files
committed
fix: cross-platform build (gate SIMD on x86_64, scope wayland/x11 to linux)
The v0.4.0 tree was implicitly x86_64-only and pulled linux-only display servers into Windows/macOS builds. Two surgical fixes: simd_queue.rs: - Gate the AVX2 + BMI1 implementation of remove_order_by_size_simd on cfg(target_arch = "x86_64") and the use of std::arch::x86_64::* with it. - Add a scalar fallback under cfg(not(target_arch = "x86_64")) with the same signature (still `unsafe fn` for parity, even though the scalar path doesn't require any unsafe behaviour at runtime). - Validated by single-file rustc on aarch64-unknown-linux-gnu - the fallback compiles clean. Cargo.toml: - Move eframe's `wayland` / `x11` features to a [target.'cfg(target_os = "linux")'.dependencies] block so non-Linux builds no longer pull in wayland-scanner / x11-dl. The base entry retains `wgpu` and `glow`, and the Linux block adds the X11 / Wayland features on top via cargo's feature unification. Net effect: - Apple Silicon (aarch64-apple-darwin) and other non-x86_64 targets can now compile the engine. - Windows + macOS x86_64 builds no longer carry the X11/Wayland deps. Host (x86_64-linux) tree remains clippy-clean (-D warnings) and fmt-check clean; all 13 lib tests still pass.
1 parent 5b3b8c5 commit 371220d

2 files changed

Lines changed: 53 additions & 6 deletions

File tree

Cargo.toml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[package]
22
name = "binance_l3_est"
3-
version = "0.4.0"
3+
version = "0.4.1"
44
edition = "2024"
55
authors = ["OctopusTakopi"]
66
repository = "https://github.com/OctopusTakopi/binance_l3_est"
@@ -9,8 +9,12 @@ license = "MIT"
99
keywords = ["order book", "binance", "trading", "hft", "visualization"]
1010

1111
[dependencies]
12-
eframe = { version = "0.32.0", features = ["wgpu", "glow", "wayland", "x11"] }
12+
# wayland/x11 features are linux-only and live in the target block below.
13+
eframe = { version = "0.32.0", features = ["wgpu", "glow"] }
1314
wgpu = { version = "25.0", features = ["vulkan", "vulkan-portability"] }
15+
16+
[target.'cfg(target_os = "linux")'.dependencies]
17+
eframe = { version = "0.32.0", features = ["wayland", "x11"] }
1418
egui = { version = "0.32.0", features = ["default"] }
1519
jiff = { version = "0.2", features = ["serde"] }
1620
smallstr = { version = "0.3", features = ["serde", "std"] }

src/engine/simd_queue.rs

Lines changed: 47 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
#[cfg(target_arch = "x86_64")]
12
use std::arch::x86_64::*;
23

34
pub const NULL_BLOCK: u32 = u32::MAX;
@@ -234,12 +235,22 @@ impl QueuePtrs {
234235
}
235236
}
236237

238+
/// Find an order whose size exactly matches `target_size` and zero it in
239+
/// place. Returns `true` if a match was found.
240+
///
241+
/// On x86_64 this uses an AVX2 + BMI1 vector compare; on other
242+
/// architectures it walks the queue scalarly. The `unsafe` qualifier is
243+
/// kept on every target for signature parity (the SIMD path requires
244+
/// AVX2/BMI1 at runtime).
245+
///
237246
/// # Safety
238247
///
239-
/// The CPU must support the AVX2 + BMI1 target features (this fn is gated by
240-
/// `#[target_feature]` and can only be called on hardware where those flags
241-
/// are present). The caller is also responsible for not aliasing `pool`
242-
/// elsewhere for the duration of the call.
248+
/// On x86_64 the CPU must support the AVX2 + BMI1 target features (the fn
249+
/// is gated by `#[target_feature]` and can only be called on hardware
250+
/// where those flags are present). On all targets the caller is
251+
/// responsible for not aliasing `pool` elsewhere for the duration of the
252+
/// call.
253+
#[cfg(target_arch = "x86_64")]
243254
#[target_feature(enable = "avx2,bmi1")]
244255
pub unsafe fn remove_order_by_size_simd(
245256
&self,
@@ -283,4 +294,36 @@ impl QueuePtrs {
283294
}
284295
false
285296
}
297+
298+
/// Scalar fallback for non-x86_64 targets. Same contract as the SIMD
299+
/// version above.
300+
#[cfg(not(target_arch = "x86_64"))]
301+
pub unsafe fn remove_order_by_size_simd(
302+
&self,
303+
pool: &mut GlobalOrderPool,
304+
target_size: u64,
305+
) -> bool {
306+
let mut curr_block_idx = self.head_block;
307+
while curr_block_idx != NULL_BLOCK {
308+
let block = pool.get_block_mut(curr_block_idx);
309+
for i in 0u32..4 {
310+
if curr_block_idx == self.head_block && i < self.head_offset {
311+
continue;
312+
}
313+
if curr_block_idx == self.tail_block && i >= self.tail_offset {
314+
continue;
315+
}
316+
let slot = &mut block.sizes[i as usize];
317+
if *slot > 0 && *slot == target_size {
318+
*slot = 0;
319+
return true;
320+
}
321+
}
322+
if curr_block_idx == self.tail_block {
323+
break;
324+
}
325+
curr_block_idx = block.next_block_idx;
326+
}
327+
false
328+
}
286329
}

0 commit comments

Comments
 (0)