From 2c94c79a44a663389fb4a0b6ff4d1a3d6206a8a9 Mon Sep 17 00:00:00 2001 From: Emmanuel Gil Peyrot Date: Wed, 4 Oct 2023 14:27:32 +0200 Subject: [PATCH] Use core and alloc a bit more We still depend mostly on std::io and std::fs, but the rest can be done without std. --- src/arch/ssse3.rs | 14 +++++--------- src/arch/wasm.rs | 2 +- src/decoder.rs | 2 +- src/worker/rayon.rs | 2 +- tests/reftest/mod.rs | 2 +- 5 files changed, 9 insertions(+), 13 deletions(-) diff --git a/src/arch/ssse3.rs b/src/arch/ssse3.rs index e0bd2e43..d4c86b48 100644 --- a/src/arch/ssse3.rs +++ b/src/arch/ssse3.rs @@ -1,7 +1,8 @@ +use core::ptr; #[cfg(target_arch = "x86")] -use std::arch::x86::*; +use core::arch::x86::*; #[cfg(target_arch = "x86_64")] -use std::arch::x86_64::*; +use core::arch::x86_64::*; #[cfg(any(target_arch = "x86", target_arch = "x86_64"))] #[target_feature(enable = "ssse3")] @@ -139,11 +140,6 @@ pub unsafe fn dequantize_and_idct_block_8x8( .unwrap() ); - #[cfg(target_arch = "x86")] - use std::arch::x86::*; - #[cfg(target_arch = "x86_64")] - use std::arch::x86_64::*; - const SHIFT: i32 = 3; // Read the DCT coefficients, scale them up and dequantize them. @@ -183,7 +179,7 @@ pub unsafe fn dequantize_and_idct_block_8x8( _mm_setzero_si128(), ), ); - std::ptr::copy_nonoverlapping::( + ptr::copy_nonoverlapping::( buf.as_ptr(), output.as_mut_ptr().wrapping_add(output_linestride * i) as *mut _, 8, @@ -277,7 +273,7 @@ pub unsafe fn color_convert_line_ycbcr(y: &[u8], cb: &[u8], cr: &[u8], output: & let mut data = [0u8; 32]; _mm_storeu_si128(data.as_mut_ptr() as *mut _, rgb_low); _mm_storeu_si128(data.as_mut_ptr().wrapping_add(16) as *mut _, rgb_hi); - std::ptr::copy_nonoverlapping::( + ptr::copy_nonoverlapping::( data.as_ptr(), output.as_mut_ptr().wrapping_add(24 * i), 24, diff --git a/src/arch/wasm.rs b/src/arch/wasm.rs index 7a94551f..c65538dc 100644 --- a/src/arch/wasm.rs +++ b/src/arch/wasm.rs @@ -1,5 +1,5 @@ #[cfg(target_arch = "wasm32")] -use std::arch::wasm32::*; +use core::arch::wasm32::*; #[cfg(target_arch = "wasm32")] #[target_feature(enable = "simd128")] diff --git a/src/decoder.rs b/src/decoder.rs index e4fa5f64..0d64f43b 100644 --- a/src/decoder.rs +++ b/src/decoder.rs @@ -16,7 +16,7 @@ use alloc::{format, vec}; use core::cmp; use core::mem; use core::ops::Range; -use std::convert::TryInto; +use core::convert::TryInto; use std::io::Read; pub const MAX_COMPONENTS: usize = 4; diff --git a/src/worker/rayon.rs b/src/worker/rayon.rs index ec7df258..c48ce819 100644 --- a/src/worker/rayon.rs +++ b/src/worker/rayon.rs @@ -10,7 +10,7 @@ use crate::parser::Component; use crate::upsampler::Upsampler; use crate::{decoder::MAX_COMPONENTS, parser::Dimensions}; -use std::sync::Arc; +use alloc::sync::Arc; use super::{RowData, Worker}; diff --git a/tests/reftest/mod.rs b/tests/reftest/mod.rs index 9b2eeab0..6c42f5e0 100644 --- a/tests/reftest/mod.rs +++ b/tests/reftest/mod.rs @@ -1,6 +1,6 @@ use jpeg; use png; -use std::cmp; +use core::cmp; use std::fs::File; use std::path::Path;