Skip to content

Commit adc9c1f

Browse files
authored
Provide a non-sse version for x86_64.
1 parent 43bec16 commit adc9c1f

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

compiler-builtins/src/mem/x86_64.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,7 @@ pub unsafe fn compare_bytes(a: *const u8, b: *const u8, n: usize) -> i32 {
173173
c16(a.cast(), b.cast(), n)
174174
}
175175

176+
#[cfg(target_feature="sse2")]
176177
#[inline(always)]
177178
pub unsafe fn c_string_length(s: *const core::ffi::c_char) -> usize {
178179
let mut n: usize;
@@ -256,6 +257,19 @@ pub unsafe fn c_string_length(s: *const core::ffi::c_char) -> usize {
256257
n
257258
}
258259

260+
// Provided for scenarios like kernel development, where SSE might not
261+
// be available.
262+
#[cfg(not(target_feature="sse2"))]
263+
#[inline(always)]
264+
pub unsafe fn c_string_length(mut s: *const core::ffi::c_char) -> usize {
265+
let mut n = 0;
266+
while *s != 0 {
267+
n += 1;
268+
s = s.add(1);
269+
}
270+
n
271+
}
272+
259273
/// Determine optimal parameters for a `rep` instruction.
260274
fn rep_param(dest: *mut u8, mut count: usize) -> (usize, usize, usize) {
261275
// Unaligned writes are still slow on modern processors, so align the destination address.

0 commit comments

Comments
 (0)