summaryrefslogtreecommitdiff
path: root/tests/assembly
diff options
context:
space:
mode:
authorScott McMurray <scottmcm@users.noreply.github.com>2023-05-05 02:29:40 -0700
committerScott McMurray <scottmcm@users.noreply.github.com>2023-05-06 22:56:43 -0700
commitc8c5a587ac637aa1521c17c631fe0070aa1dc994 (patch)
tree4794d57ec969965ce27f9000eb986f47745f0bbb /tests/assembly
parent1cfcf71e0428b5fa314b8e82aae2ef5858e8a79a (diff)
downloadrust-c8c5a587ac637aa1521c17c631fe0070aa1dc994.tar.gz
Tune the `is_ascii` implementation used for short slices
Diffstat (limited to 'tests/assembly')
-rw-r--r--tests/assembly/slice-is_ascii.rs35
1 files changed, 35 insertions, 0 deletions
diff --git a/tests/assembly/slice-is_ascii.rs b/tests/assembly/slice-is_ascii.rs
new file mode 100644
index 00000000000..b3e1fee15a7
--- /dev/null
+++ b/tests/assembly/slice-is_ascii.rs
@@ -0,0 +1,35 @@
+// revisions: WIN LIN
+// [WIN] only-windows
+// [LIN] only-linux
+// assembly-output: emit-asm
+// compile-flags: --crate-type=lib -O -C llvm-args=-x86-asm-syntax=intel
+// min-llvm-version: 14
+// only-x86_64
+// ignore-sgx
+// ignore-debug
+
+#![feature(str_internals)]
+
+// CHECK-LABEL: is_ascii_simple_demo:
+#[no_mangle]
+pub fn is_ascii_simple_demo(bytes: &[u8]) -> bool {
+ // Linux (System V): pointer is rdi; length is rsi
+ // Windows: pointer is rcx; length is rdx.
+
+ // CHECK-NOT: mov
+ // CHECK-NOT: test
+ // CHECK-NOT: cmp
+
+ // CHECK: .[[LOOPHEAD:.+]]:
+ // CHECK-NEXT: mov [[TEMP:.+]], [[LEN:rsi|rdx]]
+ // CHECK-NEXT: sub [[LEN]], 1
+ // CHECK-NEXT: jb .[[LOOPEXIT:.+]]
+ // CHECK-NEXT: cmp byte ptr [{{rdi|rcx}} + [[TEMP]] - 1], 0
+ // CHECK-NEXT: jns .[[LOOPHEAD]]
+
+ // CHECK-NEXT: .[[LOOPEXIT]]:
+ // CHECK-NEXT: test [[TEMP]], [[TEMP]]
+ // CHECK-NEXT: sete al
+ // CHECK-NEXT: ret
+ core::slice::is_ascii_simple(bytes)
+}