mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-06 11:18:30 +00:00
Add MODE=optlinux build mode (#141)
This commit is contained in:
parent
226aaf3547
commit
67b5200a0b
111 changed files with 934 additions and 854 deletions
|
@ -42,11 +42,6 @@ $(LIBC_NEXGEN32E_A).pkg: \
|
|||
$(LIBC_NEXGEN32E_A_OBJS) \
|
||||
$(foreach x,$(LIBC_NEXGEN32E_A_DIRECTDEPS),$($(x)_A).pkg)
|
||||
|
||||
o/$(MODE)/libc/nexgen32e/tinystrlen.ncabi.o \
|
||||
o/$(MODE)/libc/nexgen32e/tinystrncmp.ncabi.o: \
|
||||
OVERRIDE_CFLAGS += \
|
||||
-Os
|
||||
|
||||
o/$(MODE)/libc/nexgen32e/errno.o: \
|
||||
OVERRIDE_CFLAGS += \
|
||||
$(NO_MAGIC) \
|
||||
|
|
|
@ -95,32 +95,6 @@ strnlen16_s:
|
|||
.leafepilogue
|
||||
.endfn strnlen16_s,globl
|
||||
|
||||
// Returns length of NUL-terminated char16_t string.
|
||||
//
|
||||
// @param rdi is non-null NUL-terminated char16_t string pointer
|
||||
// @return rax is the number of shorts, excluding the NUL
|
||||
// @asyncsignalsafe
|
||||
strlen16:
|
||||
or $-1,%rsi
|
||||
// fallthrough
|
||||
.endfn strlen16,globl
|
||||
|
||||
// Returns length of NUL-terminated memory, with limit.
|
||||
//
|
||||
// @param rdi is non-null memory
|
||||
// @param rsi is the maximum number of shorts to consider
|
||||
// @return rax is the number of shorts, excluding the NUL
|
||||
// @asyncsignalsafe
|
||||
strnlen16:
|
||||
.leafprologue
|
||||
.profilable
|
||||
or $-1,%r10
|
||||
0: xor %edx,%edx
|
||||
xor %r11d,%r11d
|
||||
mov %rdi,%r8
|
||||
// fallthrough
|
||||
.endfn strnlen16,globl
|
||||
|
||||
// Swiss Army Knife of string char16_t scanning.
|
||||
// Sixteen fast functions in one.
|
||||
//
|
||||
|
|
|
@ -79,7 +79,8 @@ wcslen: or $-1,%rsi
|
|||
// @param rsi is the maximum number of chars to consider
|
||||
// @return rax is the number of chars, excluding the NUL
|
||||
// @asyncsignalsafe
|
||||
wcsnlen:.leafprologue
|
||||
wcsnlen:
|
||||
.leafprologue
|
||||
.profilable
|
||||
or $-1,%r10
|
||||
0: xor %edx,%edx
|
||||
|
|
|
@ -1,36 +0,0 @@
|
|||
/*-*- 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.internal.h"
|
||||
|
||||
// 8-bit strlen that's tiny and near optimal if data's tiny.
|
||||
//
|
||||
// @param RDI is char *s
|
||||
// @param EAX is unsigned length
|
||||
// @see libc/nexgen32e/strsak.S
|
||||
tinystrlen:
|
||||
.leafprologue
|
||||
.profilable
|
||||
xor %eax,%eax
|
||||
1: cmpb $0,(%rdi,%rax)
|
||||
jz 2f
|
||||
inc %eax
|
||||
jmp 1b
|
||||
2: .leafepilogue
|
||||
.endfn tinystrlen,globl
|
||||
.source __FILE__
|
|
@ -1,55 +0,0 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_NEXGEN32E_TINYSTRLEN_H_
|
||||
#define COSMOPOLITAN_LIBC_NEXGEN32E_TINYSTRLEN_H_
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
#if !defined(__GNUC__) || defined(__STRICT_ANSI__)
|
||||
|
||||
int tinystrlen(const char *);
|
||||
int tinystrnlen(const char *, size_t);
|
||||
int tinystrlen16(const char16_t *);
|
||||
int tinystrnlen16(const char16_t *, size_t);
|
||||
int tinywcslen(const wchar_t *);
|
||||
int tinywcsnlen(const wchar_t *, size_t);
|
||||
|
||||
#else
|
||||
|
||||
forceinline int tinystrlen(const char *s) {
|
||||
unsigned ax;
|
||||
asm("call\ttinystrlen" : "=a"(ax) : "D"(s), "m"(*(char(*)[PAGESIZE])s));
|
||||
return ax;
|
||||
}
|
||||
|
||||
forceinline int tinystrnlen(const char *s, size_t n) {
|
||||
unsigned ax;
|
||||
asm("call\ttinystrnlen" : "=a"(ax) : "D"(s), "S"(n), "m"(*(char(*)[n])s));
|
||||
return ax;
|
||||
}
|
||||
|
||||
forceinline int tinystrlen16(const char16_t *s) {
|
||||
unsigned ax;
|
||||
asm("call\ttinystrlen16" : "=a"(ax) : "D"(s), "m"(*(char16_t(*)[PAGESIZE])s));
|
||||
return ax;
|
||||
}
|
||||
|
||||
forceinline int tinystrnlen16(const char16_t *s, size_t n) {
|
||||
unsigned ax;
|
||||
asm("call\ttinystrnlen16"
|
||||
: "=a"(ax)
|
||||
: "D"(s), "S"(n), "m"(*(char16_t(*)[n])s));
|
||||
return ax;
|
||||
}
|
||||
|
||||
forceinline int tinywcslen(const wchar_t *s) {
|
||||
unsigned ax;
|
||||
asm("call\ttinywcslen" : "=a"(ax) : "D"(s), "m"(*(wchar_t(*)[PAGESIZE])s));
|
||||
return ax;
|
||||
}
|
||||
|
||||
forceinline int tinywcsnlen(const wchar_t *s, size_t n) {
|
||||
unsigned ax;
|
||||
asm("call\ttinywcsnlen" : "=a"(ax) : "D"(s), "S"(n), "m"(*(wchar_t(*)[n])s));
|
||||
return ax;
|
||||
}
|
||||
|
||||
#endif
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_NEXGEN32E_TINYSTRLEN_H_ */
|
|
@ -1,36 +0,0 @@
|
|||
/*-*- 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.internal.h"
|
||||
|
||||
// 16-bit strlen that's tiny and near optimal if data's tiny.
|
||||
//
|
||||
// @param RDI is char16_t *s
|
||||
// @param EAX is unsigned length
|
||||
// @see libc/nexgen32e/strsak16.S
|
||||
tinystrlen16:
|
||||
.leafprologue
|
||||
.profilable
|
||||
xor %eax,%eax
|
||||
1: cmpw $0,(%rdi,%rax,2)
|
||||
jz 2f
|
||||
inc %eax
|
||||
jmp 1b
|
||||
2: .leafepilogue
|
||||
.endfn tinystrlen16,globl
|
||||
.source __FILE__
|
|
@ -1,55 +0,0 @@
|
|||
/*-*- 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.internal.h"
|
||||
|
||||
// Compares strings w/ limit & no-clobber greg abi.
|
||||
//
|
||||
// @param %rdi is first string
|
||||
// @param %rsi is second string
|
||||
// @param %rdx is max length
|
||||
// @return <0, 0, or >0 depending on comparison
|
||||
// @clob flags only
|
||||
// @asyncsignalsafe
|
||||
tinystrncmp:
|
||||
.leafprologue
|
||||
push %rbx
|
||||
push %rcx
|
||||
xor %eax,%eax
|
||||
xor %ebx,%ebx
|
||||
xor %ecx,%ecx
|
||||
test %edx,%edx
|
||||
jz 2f
|
||||
cmp %rdi,%rsi
|
||||
je 2f
|
||||
0: cmp %edx,%ecx
|
||||
jae 1f
|
||||
movzbl (%rdi,%rcx,1),%eax
|
||||
movzbl (%rsi,%rcx,1),%ebx
|
||||
test %al,%al
|
||||
jz 1f
|
||||
cmp %bl,%al
|
||||
jne 1f
|
||||
inc %ecx
|
||||
jmp 0b
|
||||
1: sub %ebx,%eax
|
||||
2: pop %rcx
|
||||
pop %rbx
|
||||
.leafepilogue
|
||||
.endfn tinystrncmp,globl
|
||||
.source __FILE__
|
|
@ -1,39 +0,0 @@
|
|||
/*-*- 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.internal.h"
|
||||
|
||||
// 8-bit strnlen that's tiny and near optimal if data's tiny.
|
||||
//
|
||||
// @param RDI is char *s
|
||||
// @param RSI is size_t n
|
||||
// @param EAX is unsigned length
|
||||
// @see libc/nexgen32e/strsak.S
|
||||
tinystrnlen:
|
||||
.leafprologue
|
||||
.profilable
|
||||
xor %eax,%eax
|
||||
1: cmp %esi,%eax
|
||||
jae 2f
|
||||
cmpb $0,(%rdi,%rax)
|
||||
jz 2f
|
||||
inc %eax
|
||||
jmp 1b
|
||||
2: .leafepilogue
|
||||
.endfn tinystrnlen,globl
|
||||
.source __FILE__
|
|
@ -1,39 +0,0 @@
|
|||
/*-*- 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.internal.h"
|
||||
|
||||
// 16-bit strnlen that's tiny and near optimal if data's tiny.
|
||||
//
|
||||
// @param RDI is char16_t *s
|
||||
// @param RSI is size_t n
|
||||
// @param EAX is unsigned length
|
||||
// @see libc/nexgen32e/strsak16.S
|
||||
tinystrnlen16:
|
||||
.leafprologue
|
||||
.profilable
|
||||
xor %eax,%eax
|
||||
1: cmp %esi,%eax
|
||||
jae 2f
|
||||
cmpw $0,(%rdi,%rax,2)
|
||||
jz 2f
|
||||
inc %eax
|
||||
jmp 1b
|
||||
2: .leafepilogue
|
||||
.endfn tinystrnlen16,globl
|
||||
.source __FILE__
|
Loading…
Add table
Add a link
Reference in a new issue