mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-01-31 19:43:32 +00:00
e75ffde09e
You can now build Cosmopolitan with Clang: make -j8 MODE=llvm o/llvm/examples/hello.com The assembler and linker code is now friendly to LLVM too. So it's not needed to configure Clang to use binutils under the hood. If you love LLVM then you can now use pure LLVM.
63 lines
2.7 KiB
ArmAsm
63 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/nexgen32e/x86feature.h"
|
|
#include "libc/dce.h"
|
|
#include "libc/macros.h"
|
|
|
|
// Searches for last instance of wchar_t in memory region.
|
|
//
|
|
// @param rdi points to data to search
|
|
// @param esi is treated as int32_t (officially wchar_t)
|
|
// @param rdx is short count in rdi
|
|
// @return rax is address of last %esi in %rdi, or NULL
|
|
// @note AVX2 requires Haswell (2014+) or Excavator (2015+)
|
|
wmemrchr:
|
|
.leafprologue
|
|
.profilable
|
|
#if !IsTiny()
|
|
cmp $8,%rdx
|
|
jb 5f
|
|
testb X86_HAVE(AVX2)+kCpuids(%rip)
|
|
jz 5f
|
|
vmovd %esi,%xmm0
|
|
vpbroadcastd %xmm0,%ymm0
|
|
3: vmovdqu -32(%rdi,%rdx,4),%ymm1
|
|
vpcmpeqd %ymm1,%ymm0,%ymm1
|
|
vpmovmskb %ymm1,%eax
|
|
lzcnt %eax,%eax
|
|
shr %eax
|
|
mov %eax,%ecx
|
|
sub %rcx,%rdx
|
|
cmp $8,%eax
|
|
jne 5f
|
|
cmp $7,%rdx
|
|
ja 3b
|
|
vzeroupper
|
|
#endif
|
|
5: xor %eax,%eax
|
|
mov %rdx,%rcx
|
|
6: sub $1,%rcx
|
|
jb 9f
|
|
cmp %esi,-4(%rdi,%rdx,4)
|
|
mov %rcx,%rdx
|
|
jne 6b
|
|
lea (%rdi,%rcx,4),%rax
|
|
9: .leafepilogue
|
|
.endfn wmemrchr,globl
|
|
.source __FILE__
|