Skip to content

Commit

Permalink
Format in mod.rs
Browse files Browse the repository at this point in the history
Modernize `impl_lcm_array` macro to avoid warnings
    * Warnings because `skip` is not a valid `cfg` flag; use extra case
    instead
    * `?` has been stabilized in rust and is more precise than `*`

Disable compilation of avx2 code on i686 architectures

chore: bump patch version
  • Loading branch information
tvsfx committed Oct 11, 2024
1 parent bd37b72 commit cdef661
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 26 deletions.
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "b64-ct"
version = "0.1.2"
version = "0.1.3"
authors = ["Fortanix, Inc."]
license = "MPL-2.0"
edition = "2018"
Expand All @@ -24,7 +24,7 @@ readme = "README.md"
[features]
default = ["std"]
std = []
nightly = [] # Used only for testing
nightly = [] # Used only for testing

[dev-dependencies]
rand = "0.7"
Expand Down
20 changes: 10 additions & 10 deletions src/decode/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[cfg(target_arch = "x86_64")]
mod avx2;
mod lut_align64;

Expand Down Expand Up @@ -171,7 +171,7 @@ fn decode64<D: Decoder, P: Packer>(input: &[u8], decoder: D, packer: P) -> Resul
}

pub(super) fn decode64_arch(input: &[u8]) -> Result<Vec<u8>, Error> {
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[cfg(target_arch = "x86_64")]
unsafe {
if is_x86_feature_detected!("avx2")
&& is_x86_feature_detected!("bmi1")
Expand All @@ -190,20 +190,20 @@ mod tests {
use super::*;

use crate::test_support::rand_base64_size;
use crate::{ToBase64};
use crate::ToBase64;

#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[cfg(target_arch = "x86_64")]
pub(super) fn test_avx2() -> avx2::Avx2 {
unsafe { avx2::Avx2::new() }
}

generate_tests![
decoders<D>: {
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] avx2, test_avx2();
#[cfg(target_arch = "x86_64")] avx2, test_avx2();
lut_align64, lut_align64::LutAlign64;
},
packers<P>: {
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] avx2, test_avx2();
#[cfg(target_arch = "x86_64")] avx2, test_avx2();
simple, Simple;
},
tests: {
Expand Down Expand Up @@ -367,7 +367,7 @@ mod tests {

let mut v: Vec<u8> = vec![];
let bytes_per_line = BASE64_PEM_WRAP * 3 / 4;
for _i in 0..2*bytes_per_line {
for _i in 0..2 * bytes_per_line {
let encoded = v.to_base64(BASE64_PEM);
let decoded = decode64(encoded.as_bytes(), decoder, packer).unwrap();
assert_eq!(v, decoded);
Expand All @@ -393,15 +393,15 @@ mod tests {

#[cfg(all(test, feature = "nightly"))]
mod benches {
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[cfg(target_arch = "x86_64")]
use super::tests::test_avx2;
use super::*;

use test::Bencher;

use crate::test_support::rand_base64_size;

#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[cfg(target_arch = "x86_64")]
#[bench]
fn avx2_1mb(b: &mut Bencher) {
let input = rand_base64_size(1024 * 1024);
Expand All @@ -420,7 +420,7 @@ mod benches {
});
}

#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[cfg(target_arch = "x86_64")]
#[bench]
fn avx2_1kb(b: &mut Bencher) {
let input = rand_base64_size(1024);
Expand Down
26 changes: 13 additions & 13 deletions src/encode/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */

#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[cfg(target_arch = "x86_64")]
mod avx2;
mod lut_align64;

Expand Down Expand Up @@ -59,16 +59,16 @@ trait SplitArrayExt {
impl<T> SplitArrayExt for T {}

macro_rules! impl_lcm_array {
($($am:ident / )* $a:literal, $($bm:ident / )* $b:literal, $lcm:literal) => {
($($am:ident / )? $a:literal, $($bm:ident / )? $b:literal, $lcm:literal) => {
impl Lcm for ([u8; $a], [u8; $b]) {
type Array = [u8; $lcm];
}

impl_lcm_array!(@split $($am / )* $a, $lcm);
impl_lcm_array!(@split $($bm / )* $b, $lcm);
impl_lcm_array!(@split $($am / )? $a, $lcm);
impl_lcm_array!(@split $($bm / )? $b, $lcm);
};
(@split $($nm:ident / )* $n:literal, $lcm:literal) => {
$(#[cfg(all(not($nm), $nm))])*
(@split $nm:ident / $n:literal, $lcm:literal) => {};
(@split $n:literal, $lcm:literal) => {
impl<T> SplitArray<[T; $n]> for [T; $lcm] {
type Output = [[T; $n]; $lcm / $n];

Expand Down Expand Up @@ -181,7 +181,7 @@ where
}

pub(super) fn encode64_arch(input: &[u8], config: crate::Config) -> String {
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[cfg(target_arch = "x86_64")]
unsafe {
if is_x86_feature_detected!("avx2") {
let avx2 = avx2::Avx2::new();
Expand All @@ -197,19 +197,19 @@ mod tests {

use crate::{Config, Newline, STANDARD, URL_SAFE};

#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[cfg(target_arch = "x86_64")]
pub(super) fn test_avx2() -> avx2::Avx2 {
unsafe { avx2::Avx2::new() }
}

generate_tests![
encoders<E>: {
lut_align64, lut_align64::LutAlign64;
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] avx2, test_avx2();
#[cfg(target_arch = "x86_64")] avx2, test_avx2();
},
unpackers<U>: {
simple, Simple;
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))] avx2, test_avx2();
#[cfg(target_arch = "x86_64")] avx2, test_avx2();
},
tests: {
encode,
Expand Down Expand Up @@ -271,15 +271,15 @@ mod tests {

#[cfg(all(test, feature = "nightly"))]
mod benches {
#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[cfg(target_arch = "x86_64")]
use super::tests::test_avx2;
use super::*;

use test::Bencher;

use rand::{thread_rng, RngCore};

#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[cfg(target_arch = "x86_64")]
#[bench]
fn avx2_1mb(b: &mut Bencher) {
let mut input = std::vec![0; 1024*1024];
Expand All @@ -300,7 +300,7 @@ mod benches {
});
}

#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[cfg(target_arch = "x86_64")]
#[bench]
fn avx2_1kb(b: &mut Bencher) {
let mut input = std::vec![0; 1024];
Expand Down
2 changes: 1 addition & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ mod test_support;
#[macro_use]
mod misc;

#[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
#[cfg(target_arch = "x86_64")]
mod avx2;
mod lut_align64;

Expand Down

0 comments on commit cdef661

Please sign in to comment.