mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-26 20:40:28 +00:00
Replace .pushsection directives (#30)
This commit is contained in:
parent
28316891e9
commit
04f1d89f84
16 changed files with 171 additions and 10422 deletions
|
@ -1,5 +1,23 @@
|
|||
#include "libc/nexgen32e/x86feature.h"
|
||||
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
||||
│vi: set et ft=asm ts=8 sw=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"
|
||||
#include "libc/nexgen32e/x86feature.h"
|
||||
|
||||
/ Broadcast byte literal to vector, e.g.
|
||||
/
|
||||
|
|
73
libc/nexgen32e/strcspn.S
Normal file
73
libc/nexgen32e/strcspn.S
Normal file
|
@ -0,0 +1,73 @@
|
|||
/*-*- 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.
|
||||
/ a.k.a. Return index of first byte that's in charset.
|
||||
/
|
||||
/ @param rdi is string
|
||||
/ @param rsi is reject nul-terminated character set
|
||||
/ @see strspn(), strtok_r()
|
||||
/ @asyncsignalsafe
|
||||
strcspn:
|
||||
push %rbp
|
||||
mov %rsp,%rbp
|
||||
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
|
|
@ -2,18 +2,18 @@
|
|||
#define COSMOPOLITAN_LIBC_NEXGEN32E_TRAMPOLINE_H_
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
|
||||
#define TRAMPOLINE(FUNCTION, THUNK) \
|
||||
({ \
|
||||
typeof(FUNCTION) *Tramp; \
|
||||
asm(".pushsection .text.trampoline\n" \
|
||||
"183:\n\t" \
|
||||
"mov\t%1,%%eax\n\t" \
|
||||
"jmp\t" #THUNK "\n\t" \
|
||||
".popsection\n\t" \
|
||||
"mov\t$183b,%k0" \
|
||||
: "=r"(Tramp) \
|
||||
: "i"(FUNCTION)); \
|
||||
Tramp; \
|
||||
#define TRAMPOLINE(FUNCTION, THUNK) \
|
||||
({ \
|
||||
typeof(FUNCTION) *Tramp; \
|
||||
asm(".section .text.trampoline\n" \
|
||||
"183:\n\t" \
|
||||
"mov\t%1,%%eax\n\t" \
|
||||
"jmp\t" #THUNK "\n\t" \
|
||||
".previous\n\t" \
|
||||
"mov\t$183b,%k0" \
|
||||
: "=r"(Tramp) \
|
||||
: "i"(FUNCTION)); \
|
||||
Tramp; \
|
||||
})
|
||||
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue