Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
119 changes: 115 additions & 4 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ jobs:
- uses: actions/setup-node@v5
with:
node-version: 22
cache: 'yarn'
cache: "yarn"
- name: Install dependencies
run: yarn install
- name: Download fixtures
Expand All @@ -58,7 +58,7 @@ jobs:
- uses: actions/setup-node@v5
with:
node-version: 22
cache: 'yarn'
cache: "yarn"
- name: Install dependencies
run: yarn install
- name: Download fixtures
Expand All @@ -69,6 +69,110 @@ jobs:
run: cargo miri test
env:
MIRIFLAGS: "-Zmiri-disable-isolation"

asan:
name: ASAN - Linux-x86_64 - ${{ matrix.asan.flag }}
runs-on: ubuntu-24.04
strategy:
fail-fast: false
matrix:
asan:
- flag: sanitizer=address
options: detect_leaks=1 detect_stack_use_after_return=1
- flag: sanitizer=memory
options: ""
- flag: sanitizer=safestack
options: ""

steps:
- uses: actions/checkout@v5

- name: Setup node
uses: actions/setup-node@v5
with:
node-version: 22
cache: "yarn"

- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: nightly
components: rust-src

- name: Install dependencies
run: yarn install --immutable --mode=skip-build

- name: Download fixtures
run: node download-fixtures.js
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Test with ASAN
run: cargo test --tests --target x86_64-unknown-linux-gnu
env:
RUST_TARGET: x86_64-unknown-linux-gnu
RUST_BACKTRACE: 1
RUSTFLAGS: "-Z${{ matrix.asan.flag }}"
ASAN_OPTIONS: ${{ matrix.asan.options }}
CARGO_UNSTABLE_BUILD_STD: std,panic_abort


asan-win32:
name: ASAN - Windows-x86_64
runs-on: windows-latest

steps:
- uses: actions/checkout@v5

- name: Setup node
uses: actions/setup-node@v5
with:
node-version: 22
cache: "yarn"

- name: Install Rust
uses: dtolnay/rust-toolchain@stable
with:
toolchain: nightly
components: rust-src

- name: Install dependencies
run: yarn install --immutable --mode=skip-build

- name: Download fixtures
run: node download-fixtures.js
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}

- name: Test with ASAN (Windows)
shell: pwsh
run: |
# Set ASAN environment variables for Windows
$env:ASAN_OPTIONS = "windows_hook_rtl_allocators=true:detect_leaks=0:print_stats=1:check_initialization_order=true:strict_string_checks=true"

# Find and set the path to the ASAN runtime DLL
$vsPath = & "${env:ProgramFiles(x86)}\Microsoft Visual Studio\Installer\vswhere.exe" -latest -property installationPath
$asanDllPath = Get-ChildItem -Path "$vsPath\VC\Tools\MSVC" -Recurse -Filter "clang_rt.asan_dynamic-x86_64.dll" | Select-Object -First 1
if ($asanDllPath) {
$env:PATH = "$($asanDllPath.DirectoryName);$env:PATH"
Write-Host "Found ASAN DLL at: $($asanDllPath.FullName)"
}
cargo test --tests --target x86_64-pc-windows-msvc
env:
RUSTFLAGS: -Zsanitizer=address
RUST_BACKTRACE: 1
CARGO_PROFILE_DEV_OPT_LEVEL: 1
CARGO_UNSTABLE_BUILD_STD: std,panic_abort

- name: Upload ASAN logs (Windows)
if: failure()
uses: actions/upload-artifact@v4
with:
name: windows-asan-logs
path: |
asan.log*
*.asan.log

bench:
strategy:
matrix:
Expand All @@ -94,7 +198,7 @@ jobs:
- uses: actions/setup-node@v5
with:
node-version: 22
cache: 'yarn'
cache: "yarn"
- name: Install dependencies
run: yarn install
- name: Download fixtures
Expand All @@ -104,4 +208,11 @@ jobs:
- name: Run benchmarks
run: cargo bench
env:
RUSTFLAGS: '-C target-cpu=native'
RUSTFLAGS: "-C target-cpu=native"

done:
runs-on: ubuntu-latest
needs: [test, miri, asan, asan-win32, bench]
steps:
- run: exit 1
if: ${{ always() && (contains(needs.*.result, 'failure') || contains(needs.*.result, 'cancelled')) }}
38 changes: 20 additions & 18 deletions src/simd/avx2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -220,25 +220,27 @@ pub unsafe fn format_string(value: &str, dst: &mut [u8]) -> usize {
// Handle remaining bytes
let mut placeholder: [u8; LANES] = [0; LANES];
while nb > 0 {
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
let v = {
std::ptr::copy_nonoverlapping(sptr, placeholder.as_mut_ptr(), nb);
Simd256u::loadu(placeholder.as_ptr())
};
#[cfg(any(target_os = "linux", target_os = "macos"))]
let v = {
if check_cross_page(sptr, LANES) {
std::ptr::copy_nonoverlapping(sptr, placeholder.as_mut_ptr(), nb);
Simd256u::loadu(placeholder.as_ptr())
} else {
#[cfg(any(debug_assertions, miri))]
{
std::ptr::copy_nonoverlapping(sptr, placeholder.as_mut_ptr(), nb);
Simd256u::loadu(placeholder.as_ptr())
}
#[cfg(not(any(debug_assertions, miri)))]
{
Simd256u::loadu(sptr)
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
{
std::ptr::copy_nonoverlapping(sptr, placeholder[..].as_mut_ptr(), nb);
Simd256u::loadu(placeholder[..].as_ptr())
}
#[cfg(any(target_os = "linux", target_os = "macos"))]
{
if check_cross_page(sptr, LANES) {
std::ptr::copy_nonoverlapping(sptr, placeholder[..].as_mut_ptr(), nb);
Simd256u::loadu(placeholder[..].as_ptr())
} else {
#[cfg(any(debug_assertions, miri))]
{
std::ptr::copy_nonoverlapping(sptr, placeholder[..].as_mut_ptr(), nb);
Simd256u::loadu(placeholder[..].as_ptr())
}
#[cfg(not(any(debug_assertions, miri)))]
{
Simd256u::loadu(sptr)
}
}
}
};
Expand Down
38 changes: 20 additions & 18 deletions src/simd/avx512.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,25 +212,27 @@ pub unsafe fn format_string(value: &str, dst: &mut [u8]) -> usize {
// Handle remaining bytes
let mut placeholder: [u8; LANES] = [0; LANES];
while nb > 0 {
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
let v = {
std::ptr::copy_nonoverlapping(sptr, placeholder.as_mut_ptr(), nb);
Simd512u::loadu(placeholder.as_ptr())
};
#[cfg(any(target_os = "linux", target_os = "macos"))]
let v = {
if check_cross_page(sptr, LANES) {
std::ptr::copy_nonoverlapping(sptr, placeholder.as_mut_ptr(), nb);
Simd512u::loadu(placeholder.as_ptr())
} else {
#[cfg(any(debug_assertions, miri))]
{
std::ptr::copy_nonoverlapping(sptr, placeholder.as_mut_ptr(), nb);
Simd512u::loadu(placeholder.as_ptr())
}
#[cfg(not(any(debug_assertions, miri)))]
{
Simd512u::loadu(sptr)
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
{
std::ptr::copy_nonoverlapping(sptr, placeholder[..].as_mut_ptr(), nb);
Simd512u::loadu(placeholder[..].as_ptr())
}
#[cfg(any(target_os = "linux", target_os = "macos"))]
{
if check_cross_page(sptr, LANES) {
std::ptr::copy_nonoverlapping(sptr, placeholder[..].as_mut_ptr(), nb);
Simd512u::loadu(placeholder[..].as_ptr())
} else {
#[cfg(any(debug_assertions, miri))]
{
std::ptr::copy_nonoverlapping(sptr, placeholder[..].as_mut_ptr(), nb);
Simd512u::loadu(placeholder[..].as_ptr())
}
#[cfg(not(any(debug_assertions, miri)))]
{
Simd512u::loadu(sptr)
}
}
}
};
Expand Down
40 changes: 21 additions & 19 deletions src/simd/neon.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,27 +219,29 @@ pub unsafe fn format_string(value: &str, dst: &mut [u8]) -> usize {
}

// Handle remaining bytes
let mut placeholder: [u8; 16] = [0; 16];
let mut placeholder: [u8; LANES] = [0; LANES];
while nb > 0 {
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
let v = {
std::ptr::copy_nonoverlapping(sptr, placeholder.as_mut_ptr(), nb);
Simd128u::loadu(placeholder.as_ptr())
};
#[cfg(any(target_os = "linux", target_os = "macos"))]
let v = {
if check_cross_page(sptr, LANES) {
std::ptr::copy_nonoverlapping(sptr, placeholder.as_mut_ptr(), nb);
Simd128u::loadu(placeholder.as_ptr())
} else {
#[cfg(any(debug_assertions, miri))]
{
std::ptr::copy_nonoverlapping(sptr, placeholder.as_mut_ptr(), nb);
Simd128u::loadu(placeholder.as_ptr())
}
#[cfg(not(any(debug_assertions, miri)))]
{
Simd128u::loadu(sptr)
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
{
std::ptr::copy_nonoverlapping(sptr, placeholder[..].as_mut_ptr(), nb);
Simd128u::loadu(placeholder[..].as_ptr())
}
#[cfg(any(target_os = "linux", target_os = "macos"))]
{
if check_cross_page(sptr, LANES) {
std::ptr::copy_nonoverlapping(sptr, placeholder[..].as_mut_ptr(), nb);
Simd128u::loadu(placeholder[..].as_ptr())
} else {
#[cfg(any(debug_assertions, miri))]
{
std::ptr::copy_nonoverlapping(sptr, placeholder[..].as_mut_ptr(), nb);
Simd128u::loadu(placeholder[..].as_ptr())
}
#[cfg(not(any(debug_assertions, miri)))]
{
Simd128u::loadu(sptr)
}
}
}
};
Expand Down
42 changes: 22 additions & 20 deletions src/simd/sse2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -215,27 +215,29 @@ pub unsafe fn format_string(value: &str, dst: &mut [u8]) -> usize {
}

// Handle remaining bytes
let mut placeholder: [u8; 16] = [0; 16];
let mut placeholder: [u8; LANES] = [0; LANES];
while nb > 0 {
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
let v = {
std::ptr::copy_nonoverlapping(sptr, placeholder.as_mut_ptr(), nb);
Simd128u::loadu(placeholder.as_ptr())
};
#[cfg(any(target_os = "linux", target_os = "macos"))]
let v = {
if check_cross_page(sptr, LANES) {
std::ptr::copy_nonoverlapping(sptr, placeholder.as_mut_ptr(), nb);
Simd128u::loadu(placeholder.as_ptr())
} else {
#[cfg(any(debug_assertions, miri))]
{
std::ptr::copy_nonoverlapping(sptr, placeholder.as_mut_ptr(), nb);
Simd128u::loadu(placeholder.as_ptr())
}
#[cfg(not(any(debug_assertions, miri)))]
{
Simd128u::loadu(sptr)
#[cfg(not(any(target_os = "linux", target_os = "macos")))]
{
std::ptr::copy_nonoverlapping(sptr, placeholder[..].as_mut_ptr(), nb);
Simd128u::loadu(placeholder[..].as_ptr())
}
#[cfg(any(target_os = "linux", target_os = "macos"))]
{
if check_cross_page(sptr, LANES) {
std::ptr::copy_nonoverlapping(sptr, placeholder[..].as_mut_ptr(), nb);
Simd128u::loadu(placeholder[..].as_ptr())
} else {
#[cfg(any(debug_assertions, miri))]
{
std::ptr::copy_nonoverlapping(sptr, placeholder[..].as_mut_ptr(), nb);
Simd128u::loadu(placeholder[..].as_ptr())
}
#[cfg(not(any(debug_assertions, miri)))]
{
Simd128u::loadu(sptr)
}
}
}
};
Expand All @@ -247,7 +249,7 @@ pub unsafe fn format_string(value: &str, dst: &mut [u8]) -> usize {
dptr = dptr.add(nb);
break;
} else {
let cn = mask.trailing_zeros() as usize;
let cn = mask.first_offset();
nb -= cn;
dptr = dptr.add(cn);
sptr = sptr.add(cn);
Expand Down
Loading