about summary refs log tree commit diff
path: root/library/stdarch/examples/hex.rs
diff options
context:
space:
mode:
authorgnzlbg <gnzlbg@users.noreply.github.com>2018-03-22 17:09:01 +0100
committerAlex Crichton <alex@alexcrichton.com>2018-03-22 11:09:01 -0500
commit56d9a42a2fd623edce8e9bb0a07255e5f3494c2a (patch)
tree70daf737746fcc2c8e8a90017723f8b251bfdfc0 /library/stdarch/examples/hex.rs
parentdb819cb9320d55afc34085f7ea2b16f39e715cf4 (diff)
downloadrust-56d9a42a2fd623edce8e9bb0a07255e5f3494c2a.tar.gz
rust-56d9a42a2fd623edce8e9bb0a07255e5f3494c2a.zip
add tests for endian-dependent behavior (#394)
* add tests for endian-dependent behavior

* format
Diffstat (limited to 'library/stdarch/examples/hex.rs')
-rw-r--r--library/stdarch/examples/hex.rs22
1 files changed, 17 insertions, 5 deletions
diff --git a/library/stdarch/examples/hex.rs b/library/stdarch/examples/hex.rs
index b24b9a83f12..85b160d661f 100644
--- a/library/stdarch/examples/hex.rs
+++ b/library/stdarch/examples/hex.rs
@@ -115,7 +115,9 @@ unsafe fn hex_encode_avx2<'a>(
     let i = i as usize;
     let _ = hex_encode_sse41(src, &mut dst[i * 2..]);
 
-    Ok(str::from_utf8_unchecked(&dst[..src.len() * 2 + i * 2]))
+    Ok(str::from_utf8_unchecked(
+        &dst[..src.len() * 2 + i * 2],
+    ))
 }
 
 // copied from https://github.com/Matherunner/bin2hex-sse/blob/master/base16_sse4.cpp
@@ -155,7 +157,10 @@ unsafe fn hex_encode_sse41<'a>(
         let res2 = _mm_unpackhi_epi8(masked2, masked1);
 
         _mm_storeu_si128(dst.as_mut_ptr().offset(i * 2) as *mut _, res1);
-        _mm_storeu_si128(dst.as_mut_ptr().offset(i * 2 + 16) as *mut _, res2);
+        _mm_storeu_si128(
+            dst.as_mut_ptr().offset(i * 2 + 16) as *mut _,
+            res2,
+        );
         src = &src[16..];
         i += 16;
     }
@@ -163,7 +168,9 @@ unsafe fn hex_encode_sse41<'a>(
     let i = i as usize;
     let _ = hex_encode_fallback(src, &mut dst[i * 2..]);
 
-    Ok(str::from_utf8_unchecked(&dst[..src.len() * 2 + i * 2]))
+    Ok(str::from_utf8_unchecked(
+        &dst[..src.len() * 2 + i * 2],
+    ))
 }
 
 fn hex_encode_fallback<'a>(
@@ -192,7 +199,10 @@ mod tests {
     fn test(input: &[u8], output: &str) {
         let tmp = || vec![0; input.len() * 2];
 
-        assert_eq!(hex_encode_fallback(input, &mut tmp()).unwrap(), output);
+        assert_eq!(
+            hex_encode_fallback(input, &mut tmp()).unwrap(),
+            output
+        );
         assert_eq!(hex_encode(input, &mut tmp()).unwrap(), output);
 
         #[cfg(any(target_arch = "x86", target_arch = "x86_64"))]
@@ -229,7 +239,9 @@ mod tests {
     fn odd() {
         test(
             &[0; 313],
-            &iter::repeat('0').take(313 * 2).collect::<String>(),
+            &iter::repeat('0')
+                .take(313 * 2)
+                .collect::<String>(),
         );
     }