cosmopolitan/libc/nexgen32e/strcspn.S
Justine Tunney 45b72485ad Fix XNU / FreeBSD / OpenBSD / RHEL5 / NT bugs
For the first time ever, all tests in this codebase now pass, when
run automatically on macos, freebsd, openbsd, rhel5, rhel7, alpine
and windows via the network using the runit and runitd build tools

- Fix vfork exec path etc.
- Add XNU opendir() support
- Add OpenBSD opendir() support
- Add Linux history to syscalls.sh
- Use copy_file_range on FreeBSD 13+
- Fix system calls with 7+ arguments
- Fix Windows with greater than 16 FDs
- Fix RUNIT.COM and RUNITD.COM flakiness
- Fix OpenBSD munmap() when files are mapped
- Fix long double so it's actually long on Windows
- Fix OpenBSD truncate() and ftruncate() thunk typo
- Let Windows fcntl() be used on socket files descriptors
- Fix Windows fstat() which had an accidental printf statement
- Fix RHEL5 CLOCK_MONOTONIC by not aliasing to CLOCK_MONOTONIC_RAW

This is wonderful. I never could have dreamed it would be possible
to get it working so well on so many platforms with tiny binaries.

Fixes #31
Fixes #25
Fixes #14
2021-01-25 18:31:17 -08:00

74 lines
2.7 KiB
ArmAsm

/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi
Copyright 2020 Justine Alexandra Roberts Tunney
Permission to use, copy, modify, and/or distribute this software for
any purpose with or without fee is hereby granted, provided that the
above copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL
WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE
AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL
DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR
PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
PERFORMANCE OF THIS SOFTWARE.
*/
#include "libc/macros.h"
/ Returns prefix length, consisting of chars not in reject.
/
/ @param rdi is string
/ @param rsi is reject nul-terminated character set
/ @return rax is index of first byte in charset
/ @see strspn(), strtok_r()
/ @asyncsignalsafe
strcspn:
push %rbp
mov %rsp,%rbp
.profilable
sub $16,%rsp
push %rdi
mov %rsi,%rdi
call strlen
pop %rdi
cmp $15,%rax
ja 4f
push %rdi
mov %rax,%rdx
pxor %xmm0,%xmm0
lea -16(%rbp),%rdi
movdqa %xmm0,(%rdi)
call MemCpy
movdqa (%rdi),%xmm1
pop %rdi
or $-1,%rax
0: inc %rax
movzbl (%rdi,%rax),%ecx
movd %ecx,%xmm0
punpcklbw %xmm0,%xmm0
punpcklwd %xmm0,%xmm0
pshufd $0,%xmm0,%xmm0
pcmpeqb %xmm1,%xmm0
pmovmskb %xmm0,%ecx
test %ecx,%ecx
jz 0b
9: leave
ret
1: cmp %ch,%cl
je 9b
inc %edx
2: mov (%rsi,%rdx),%ch
test %ch,%ch
jne 1b
inc %rax
3: mov (%rdi,%rax),%cl
test %cl,%cl
je 9b
xor %edx,%edx
jmp 2b
4: xor %eax,%eax
jmp 3b
.endfn strcspn,globl