Skip to content
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
23f1767
allow taking address to union field
Kivooeo Aug 31, 2025
e1258e7
autodiff: Add basic TypeTree with NoTT flag
KMJ-007 Aug 23, 2025
375e14e
Add TypeTree metadata attachment for autodiff
KMJ-007 Aug 23, 2025
beba6b9
Update TypeTree tests to verify metadata attachment
KMJ-007 Aug 23, 2025
5d3ebc3
Add TypeTree tests for scalar types
KMJ-007 Aug 23, 2025
664e83b
added typetree support for memcpy
KMJ-007 Aug 23, 2025
b8bb2e8
typo: allow EnzymeTypeTreeShiftIndiciesEq
KMJ-007 Aug 27, 2025
d89ee85
enzyme submodule updated
KMJ-007 Aug 27, 2025
54f9376
autodiff: f128 support added for typetree
KMJ-007 Aug 27, 2025
31541fe
autodiff: add TypeTree support for arrays
KMJ-007 Sep 1, 2025
be3617b
autodiff: slice support in typetree
KMJ-007 Sep 1, 2025
7c5fbfb
autodiff: tuple support in typetree
KMJ-007 Sep 1, 2025
574f0b9
autodiff: struct support in typetree
KMJ-007 Sep 1, 2025
4f3f0f4
autodiff: fixed test to be more precise for type tree checking
KMJ-007 Sep 4, 2025
4520926
autodiff: recurion added for typetree
KMJ-007 Sep 11, 2025
3ba5f19
autodiff: typetree recursive depth query from enzyme with fallback
KMJ-007 Sep 12, 2025
97b2292
Allow shared access to `Exclusive<T>` when `T: Sync`
Jules-Bertholet Sep 17, 2025
f1d6e00
Bless UI tests
Jules-Bertholet Sep 21, 2025
c0de794
std::net: update tcp deferaccept delay type to Duration.
devnexen Apr 29, 2025
19d0e72
fix build for android
devnexen Sep 27, 2025
c1259aa
Add LSX accelerated implementation for source file analysis
heiher Aug 28, 2025
5e9cab3
modify ensure_version_or_cargo_install to check existing binary
Shunpoco Sep 28, 2025
322dca8
Rollup merge of #140482 - devnexen:tcp_deferaccept_toduration, r=joboet
matthiaskrgr Sep 28, 2025
6059195
Rollup merge of #141469 - Kivooeo:remove-usnsafegate, r=compiler-errors
matthiaskrgr Sep 28, 2025
c29fb2e
Rollup merge of #144197 - KMJ-007:type-tree, r=ZuseZ4
matthiaskrgr Sep 28, 2025
750e902
Rollup merge of #146675 - Jules-Bertholet:sync-nonexclusive, r=Mark-S…
matthiaskrgr Sep 28, 2025
aa6bd55
Rollup merge of #147113 - heiher:src-analysis-lsx, r=lqd
matthiaskrgr Sep 28, 2025
4eb6b8f
Rollup merge of #147120 - Shunpoco:issue-147105, r=Kobzol
matthiaskrgr Sep 28, 2025
File filter

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 106 additions & 3 deletions compiler/rustc_span/src/analyze_source_file.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,8 @@ cfg_select! {
// use `loadu`, which supports unaligned loading.
let chunk = unsafe { _mm_loadu_si128(chunk.as_ptr() as *const __m128i) };

// For character in the chunk, see if its byte value is < 0, which
// indicates that it's part of a UTF-8 char.
// For each character in the chunk, see if its byte value is < 0,
// which indicates that it's part of a UTF-8 char.
let multibyte_test = _mm_cmplt_epi8(chunk, _mm_set1_epi8(0));
// Create a bit mask from the comparison results.
let multibyte_mask = _mm_movemask_epi8(multibyte_test);
Expand Down Expand Up @@ -132,8 +132,111 @@ cfg_select! {
}
}
}
target_arch = "loongarch64" => {
fn analyze_source_file_dispatch(
src: &str,
lines: &mut Vec<RelativeBytePos>,
multi_byte_chars: &mut Vec<MultiByteChar>,
) {
use std::arch::is_loongarch_feature_detected;

if is_loongarch_feature_detected!("lsx") {
unsafe {
analyze_source_file_lsx(src, lines, multi_byte_chars);
}
} else {
analyze_source_file_generic(
src,
src.len(),
RelativeBytePos::from_u32(0),
lines,
multi_byte_chars,
);
}
}

/// Checks 16 byte chunks of text at a time. If the chunk contains
/// something other than printable ASCII characters and newlines, the
/// function falls back to the generic implementation. Otherwise it uses
/// LSX intrinsics to quickly find all newlines.
#[target_feature(enable = "lsx")]
unsafe fn analyze_source_file_lsx(
src: &str,
lines: &mut Vec<RelativeBytePos>,
multi_byte_chars: &mut Vec<MultiByteChar>,
) {
use std::arch::loongarch64::*;

const CHUNK_SIZE: usize = 16;

let (chunks, tail) = src.as_bytes().as_chunks::<CHUNK_SIZE>();

// This variable keeps track of where we should start decoding a
// chunk. If a multi-byte character spans across chunk boundaries,
// we need to skip that part in the next chunk because we already
// handled it.
let mut intra_chunk_offset = 0;

for (chunk_index, chunk) in chunks.iter().enumerate() {
// All LSX memory instructions support unaligned access, so using
// vld is fine.
let chunk = unsafe { lsx_vld::<0>(chunk.as_ptr() as *const i8) };

// For each character in the chunk, see if its byte value is < 0,
// which indicates that it's part of a UTF-8 char.
let multibyte_mask = lsx_vmskltz_b(chunk);
// Create a bit mask from the comparison results.
let multibyte_mask = lsx_vpickve2gr_w::<0>(multibyte_mask);

// If the bit mask is all zero, we only have ASCII chars here:
if multibyte_mask == 0 {
assert!(intra_chunk_offset == 0);

// Check for newlines in the chunk
let newlines_test = lsx_vseqi_b::<{b'\n' as i32}>(chunk);
let newlines_mask = lsx_vmskltz_b(newlines_test);
let mut newlines_mask = lsx_vpickve2gr_w::<0>(newlines_mask);

let output_offset = RelativeBytePos::from_usize(chunk_index * CHUNK_SIZE + 1);

while newlines_mask != 0 {
let index = newlines_mask.trailing_zeros();

lines.push(RelativeBytePos(index) + output_offset);

// Clear the bit, so we can find the next one.
newlines_mask &= newlines_mask - 1;
}
} else {
// The slow path.
// There are multibyte chars in here, fallback to generic decoding.
let scan_start = chunk_index * CHUNK_SIZE + intra_chunk_offset;
intra_chunk_offset = analyze_source_file_generic(
&src[scan_start..],
CHUNK_SIZE - intra_chunk_offset,
RelativeBytePos::from_usize(scan_start),
lines,
multi_byte_chars,
);
}
}

// There might still be a tail left to analyze
let tail_start = src.len() - tail.len() + intra_chunk_offset;
if tail_start < src.len() {
analyze_source_file_generic(
&src[tail_start..],
src.len() - tail_start,
RelativeBytePos::from_usize(tail_start),
lines,
multi_byte_chars,
);
}
}
}
_ => {
// The target (or compiler version) does not support SSE2 ...
// The target (or compiler version) does not support vector instructions
// our specialized implementations need (x86 SSE2, loongarch64 LSX)...
fn analyze_source_file_dispatch(
src: &str,
lines: &mut Vec<RelativeBytePos>,
Expand Down
1 change: 1 addition & 0 deletions compiler/rustc_span/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

// tidy-alphabetical-start
#![allow(internal_features)]
#![cfg_attr(target_arch = "loongarch64", feature(stdarch_loongarch))]
#![doc(html_root_url = "https://doc.rust-lang.org/nightly/nightly-rustc/")]
#![doc(rust_logo)]
#![feature(array_windows)]
Expand Down