Skip to content

Commit 10bb7c4

Browse files
committed
feat: use prefetch_write only if prfchw is enabled
1 parent b7a85da commit 10bb7c4

File tree

2 files changed

+14
-5
lines changed

2 files changed

+14
-5
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,5 +61,5 @@ jobs:
6161
with:
6262
cache-on-failure: true
6363

64-
- name: bench
64+
- name: Run benchmarks
6565
run: cargo bench --all-features -v

src/lib.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -166,12 +166,21 @@ impl<T> Producer<T> {
166166

167167
#[cfg(any(
168168
target_arch = "x86",
169-
all(target_arch = "x86_64", target_feature = "sse")
169+
all(
170+
target_arch = "x86_64",
171+
any(target_feature = "prfchw", target_feature = "sse")
172+
)
170173
))]
171174
unsafe {
172175
let next_index = next_head & self.queue.0.mask.0;
173176
let next_slot = self.queue.0.buffer.0.add(next_index);
174-
prefetch_write(next_slot as *const u8);
177+
prefetch_read(next_slot as *const u8);
178+
// check if prfchw is available
179+
if is_x86_feature_detected!("sse") {
180+
prefetch_read(next_slot as *const u8);
181+
} else {
182+
prefetch_write(next_slot as *const u8);
183+
}
175184
}
176185

177186
let cached_tail = unsafe { *self.cached_tail.0.get() };
@@ -332,7 +341,7 @@ impl<T> Consumer<T> {
332341
#[inline(always)]
333342
pub fn peek(&self) -> Option<&T> {
334343
let tail = unsafe { *self.tail.0.get() };
335-
let head = self.queue.0.head.0.load(Ordering::Relaxed);
344+
let head = self.queue.0.head.0.load(Ordering::Acquire);
336345

337346
if tail == head {
338347
return None;
@@ -397,7 +406,7 @@ fn prefetch_read(p: *const u8) {
397406

398407
#[cfg(any(
399408
target_arch = "x86",
400-
all(target_arch = "x86_64", target_feature = "sse")
409+
all(target_arch = "x86_64", target_feature = "prfchw")
401410
))]
402411
#[inline(always)]
403412
fn prefetch_write(p: *const u8) {

0 commit comments

Comments
 (0)