Skip to content

Commit

Permalink
...and fix the build on x86 again
Browse files Browse the repository at this point in the history
  • Loading branch information
chengsun committed May 28, 2022
1 parent 720646c commit aad4b90
Show file tree
Hide file tree
Showing 7 changed files with 60 additions and 48 deletions.
16 changes: 8 additions & 8 deletions benches/benches.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ fn bench_parser(c: &mut Criterion) {
group.throughput(Throughput::Bytes(input_pp.len() as u64));
group.bench_function("rust-sexp",
|b| b.iter(|| {
let mut parser = parser::State::from_sexp_factory(rust_parser::SexpFactory::new());
let result = parser.process_all(parser::SegmentIndex::EntireFile, input_pp).unwrap();
let mut parser = parser::parser_from_sexp_factory(rust_parser::SexpFactory::new());
let result = parser.process(parser::SegmentIndex::EntireFile, input_pp).unwrap();
black_box(result)
}));
group.bench_function("rust-tape",
|b| b.iter(|| {
let mut parser = parser::State::from_visitor(rust_parser::TapeVisitor::new());
let result = parser.process_all(parser::SegmentIndex::EntireFile,input_pp).unwrap();
let mut parser = parser::parser_from_visitor(rust_parser::TapeVisitor::new());
let result = parser.process(parser::SegmentIndex::EntireFile,input_pp).unwrap();
black_box(result)
}));
group.finish();
Expand All @@ -32,14 +32,14 @@ fn bench_parser(c: &mut Criterion) {
group.throughput(Throughput::Bytes(input_mach.len() as u64));
group.bench_function("rust-sexp",
|b| b.iter(|| {
let mut parser = parser::State::from_sexp_factory(rust_parser::SexpFactory::new());
let result = parser.process_all(parser::SegmentIndex::EntireFile,input_mach).unwrap();
let mut parser = parser::parser_from_sexp_factory(rust_parser::SexpFactory::new());
let result = parser.process(parser::SegmentIndex::EntireFile,input_mach).unwrap();
black_box(result)
}));
group.bench_function("rust-tape",
|b| b.iter(|| {
let mut parser = parser::State::from_visitor(rust_parser::TapeVisitor::new());
let result = parser.process_all(parser::SegmentIndex::EntireFile,input_mach).unwrap();
let mut parser = parser::parser_from_visitor(rust_parser::TapeVisitor::new());
let result = parser.process(parser::SegmentIndex::EntireFile,input_mach).unwrap();
black_box(result)
}));
group.finish();
Expand Down
13 changes: 7 additions & 6 deletions src/clmul.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
#[cfg(target_arch = "x86")]
use core::arch::x86::*;
#[cfg(target_arch = "x86_64")]
use core::arch::x86_64::*;

pub trait Clmul {
fn clmul(&self, input: u64) -> u64;
}
Expand Down Expand Up @@ -32,6 +27,12 @@ impl Clmul for Generic {

#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
mod x86 {
use super::Clmul;
#[cfg(target_arch = "x86")]
use core::arch::x86::*;
#[cfg(target_arch = "x86_64")]
use core::arch::x86_64::*;

#[derive(Copy, Clone, Debug)]
pub struct Sse2Pclmulqdq { _feature_detected_witness: () }

Expand Down Expand Up @@ -62,7 +63,7 @@ mod x86 {
}

#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
pub use x86;
pub use x86::*;

impl Clmul for Box<dyn Clmul> {
fn clmul(&self, input: u64) -> u64 {
Expand Down
4 changes: 0 additions & 4 deletions src/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -184,8 +184,6 @@ impl<ClassifierT: structural::Classifier, Stage2T: Stage2> State<ClassifierT, St
}

pub fn process_streaming<BufReadT: BufRead>(&mut self, segment_index: SegmentIndex, buf_reader: &mut BufReadT) -> Result<Stage2T::Return, Error> {
use structural::Classifier;

let mut input_index = 0;
let mut indices_len = 0;
let mut indices_buffer = [0; INDICES_BUFFER_MAX_LEN];
Expand Down Expand Up @@ -274,8 +272,6 @@ impl<ClassifierT: structural::Classifier, Stage2T: Stage2> State<ClassifierT, St
}

pub fn process_all(&mut self, segment_index: SegmentIndex, input: &[u8]) -> Result<Stage2T::Return, Error> {
use structural::Classifier;

let mut input_index = 0;
let mut indices_len = 0;
let mut indices_buffer = [0; INDICES_BUFFER_MAX_LEN];
Expand Down
14 changes: 8 additions & 6 deletions src/start_stop_transitions.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
#[cfg(target_arch = "x86")]
use core::arch::x86::*;
#[cfg(target_arch = "x86_64")]
use core::arch::x86_64::*;

use crate::clmul;
use crate::xor_masked_adjacent;

Expand Down Expand Up @@ -34,6 +29,13 @@ impl<ClmulT: clmul::Clmul, XorMaskedAdjacentT: xor_masked_adjacent::XorMaskedAdj

#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
mod x86 {
#[cfg(target_arch = "x86")]
use core::arch::x86::*;
#[cfg(target_arch = "x86_64")]
use core::arch::x86_64::*;

use super::StartStopTransitions;

pub struct Bmi2 { _feature_detected_witness: () }

impl Bmi2 {
Expand Down Expand Up @@ -69,7 +71,7 @@ mod x86 {
}

#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
pub use x86;
pub use x86::*;

impl StartStopTransitions for Box<dyn StartStopTransitions> {
fn start_stop_transitions(&self, start: u64, stop: u64, prev_state: bool) -> (u64, bool) {
Expand Down
34 changes: 21 additions & 13 deletions src/structural.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,4 @@
#[cfg(target_arch = "x86")]
use core::arch::x86::*;
#[cfg(target_arch = "x86_64")]
use core::arch::x86_64::*;

use crate::{clmul, xor_masked_adjacent, vector_classifier, utils, find_quote_transitions, ranges};
use vector_classifier::ClassifierBuilder;
use clmul::Clmul;
use crate::vector_classifier;

pub enum CallbackResult {
Continue,
Expand All @@ -22,7 +15,7 @@ pub trait Classifier {
(&mut self, input_buf: &[u8], f: F);
}

#[derive(Debug, Eq, PartialEq)]
#[derive(Copy, Clone, Debug, Eq, PartialEq)]
pub struct Generic {
escape: bool,
quote_state: bool,
Expand Down Expand Up @@ -87,7 +80,18 @@ pub fn not_atom_like_lookup_tables() -> vector_classifier::LookupTables {

#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
mod x86 {
#[derive(Debug)]
#[cfg(target_arch = "x86")]
use core::arch::x86::*;
#[cfg(target_arch = "x86_64")]
use core::arch::x86_64::*;

use crate::{clmul, vector_classifier, xor_masked_adjacent, utils, find_quote_transitions, ranges};
use vector_classifier::ClassifierBuilder;
use clmul::Clmul;

use super::{Classifier, CallbackResult, Generic, not_atom_like_lookup_tables};

#[derive(Clone, Debug)]
pub struct Avx2 {
/* constants */
clmul: clmul::Sse2Pclmulqdq,
Expand Down Expand Up @@ -144,6 +148,11 @@ mod x86 {
self.generic.atom_like = self.atom_like;
}

pub fn get_generic_state(&mut self) -> Generic {
self.copy_state_to_generic();
self.generic
}

#[target_feature(enable = "avx2,bmi2,sse2,ssse3,pclmulqdq")]
#[inline]
unsafe fn classify_one_avx2(&self, input: __m256i) -> ClassifyOneAvx2
Expand Down Expand Up @@ -246,7 +255,7 @@ mod x86 {
}

#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
pub use x86;
pub use x86::*;

#[cfg(test)]
mod tests {
Expand Down Expand Up @@ -296,8 +305,7 @@ mod tests {
match Avx2::new() {
Some(mut avx2) => {
avx2.run_test(input, output);
avx2.copy_state_to_generic();
assert_eq!(generic, avx2.generic);
assert_eq!(generic, avx2.get_generic_state());
},
None => (),
}
Expand Down
13 changes: 8 additions & 5 deletions src/vector_classifier.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
use std::collections::HashMap;
#[cfg(target_arch = "x86")]
use core::arch::x86::*;
#[cfg(target_arch = "x86_64")]
use core::arch::x86_64::*;

#[derive(Clone, Debug)]
pub struct LookupTables {
Expand Down Expand Up @@ -133,6 +129,13 @@ impl ClassifierBuilder for GenericBuilder {

#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
mod x86 {
#[cfg(target_arch = "x86")]
use core::arch::x86::*;
#[cfg(target_arch = "x86_64")]
use core::arch::x86_64::*;

use super::{Classifier, ClassifierBuilder, GenericClassifier, LookupTables};

#[derive(Clone, Debug)]
pub struct Ssse3Classifier {
generic: GenericClassifier,
Expand Down Expand Up @@ -258,7 +261,7 @@ mod x86 {
}

#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
pub use x86;
pub use x86::*;

pub struct RuntimeDetectBuilder {}

Expand Down
14 changes: 8 additions & 6 deletions src/xor_masked_adjacent.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,3 @@
#[cfg(target_arch = "x86")]
use core::arch::x86::*;
#[cfg(target_arch = "x86_64")]
use core::arch::x86_64::*;

pub trait XorMaskedAdjacent {
fn xor_masked_adjacent(&self, bitstring: u64, mask: u64, lo_fill: bool) -> u64;
}
Expand All @@ -27,6 +22,13 @@ impl XorMaskedAdjacent for Generic {

#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
mod x86 {
#[cfg(target_arch = "x86")]
use core::arch::x86::*;
#[cfg(target_arch = "x86_64")]
use core::arch::x86_64::*;

use super::XorMaskedAdjacent;

#[derive(Copy, Clone, Debug)]
pub struct Bmi2 {
_feature_detected_witness: ()
Expand Down Expand Up @@ -61,7 +63,7 @@ mod x86 {
}

#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
pub use x86;
pub use x86::*;

impl XorMaskedAdjacent for Box<dyn XorMaskedAdjacent> {
#[inline(always)]
Expand Down

0 comments on commit aad4b90

Please sign in to comment.