mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-05-24 06:12:27 +00:00
Replace .pushsection directives (#30)
This commit is contained in:
parent
28316891e9
commit
04f1d89f84
16 changed files with 171 additions and 10422 deletions
|
@ -85,10 +85,10 @@ idata.iat.\name:
|
||||||
*/.section .piro.data.sort.iat.2.\name\().3,"awG",\name,comdat
|
*/.section .piro.data.sort.iat.2.\name\().3,"awG",\name,comdat
|
||||||
.quad 0
|
.quad 0
|
||||||
.previous
|
.previous
|
||||||
.pushsection .rodata.str1.1,"aSM",@progbits,1
|
.section .rodata.str1.1,"aSM",@progbits,1
|
||||||
.Lidata.str.\name:
|
.Lidata.str.\name:
|
||||||
.asciz "\name\().dll"
|
.asciz "\name\().dll"
|
||||||
.popsection
|
.previous
|
||||||
.endm
|
.endm
|
||||||
|
|
||||||
/* clang-format on */
|
/* clang-format on */
|
||||||
|
|
|
@ -170,7 +170,7 @@ static unsigned char pixels_[3][DYN][DXN];
|
||||||
static unsigned char palette_[3][64][512][3];
|
static unsigned char palette_[3][64][512][3];
|
||||||
static int joy_current_[2], joy_next_[2], joypos_[2];
|
static int joy_current_[2], joy_next_[2], joypos_[2];
|
||||||
|
|
||||||
static int keyframes_ = 20;
|
static int keyframes_ = 10;
|
||||||
static enum TtyBlocksSelection blocks_ = kTtyBlocksUnicode;
|
static enum TtyBlocksSelection blocks_ = kTtyBlocksUnicode;
|
||||||
static enum TtyQuantizationAlgorithm quant_ = kTtyQuantTrue;
|
static enum TtyQuantizationAlgorithm quant_ = kTtyQuantTrue;
|
||||||
|
|
||||||
|
|
|
@ -8,9 +8,9 @@
|
||||||
* Teleports code fragment inside _init().
|
* Teleports code fragment inside _init().
|
||||||
*/
|
*/
|
||||||
#define INITIALIZER(PRI, NAME, CODE) \
|
#define INITIALIZER(PRI, NAME, CODE) \
|
||||||
asm(".pushsection .init." #PRI "." #NAME ",\"ax\",@progbits\n\t" \
|
asm(".section .init." #PRI "." #NAME ",\"ax\",@progbits\n\t" \
|
||||||
"call\t" #NAME "\n\t" \
|
"call\t" #NAME "\n\t" \
|
||||||
".popsection"); \
|
".previous"); \
|
||||||
textstartup optimizesize void NAME(char *rdi, const char *rsi) { \
|
textstartup optimizesize void NAME(char *rdi, const char *rsi) { \
|
||||||
CODE; \
|
CODE; \
|
||||||
asm volatile("" : /* no outputs */ : "D"(rdi), "S"(rsi)); \
|
asm volatile("" : /* no outputs */ : "D"(rdi), "S"(rsi)); \
|
||||||
|
|
|
@ -65,7 +65,7 @@
|
||||||
#else
|
#else
|
||||||
#define PFLINK(FMT) FMT
|
#define PFLINK(FMT) FMT
|
||||||
#define SFLINK(FMT) FMT
|
#define SFLINK(FMT) FMT
|
||||||
asm(".pushsection .yoink\n\t"
|
asm(".section .yoink\n\t"
|
||||||
"nop\tntoa(%rip)\n\t"
|
"nop\tntoa(%rip)\n\t"
|
||||||
"nop\tftoa(%rip)\n\t"
|
"nop\tftoa(%rip)\n\t"
|
||||||
"nop\tkCp437(%rip)\n\t"
|
"nop\tkCp437(%rip)\n\t"
|
||||||
|
@ -77,7 +77,7 @@ asm(".pushsection .yoink\n\t"
|
||||||
"nop\tcalloc(%rip)\n\t"
|
"nop\tcalloc(%rip)\n\t"
|
||||||
"nop\tfree_s(%rip)\n\t"
|
"nop\tfree_s(%rip)\n\t"
|
||||||
"nop\t__grow(%rip)\n\t"
|
"nop\t__grow(%rip)\n\t"
|
||||||
".popsection");
|
".previous");
|
||||||
#endif /* __STRICT_ANSI__ */
|
#endif /* __STRICT_ANSI__ */
|
||||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||||
#endif /* COSMOPOLITAN_LIBC_FMT_PFLINK_H_ */
|
#endif /* COSMOPOLITAN_LIBC_FMT_PFLINK_H_ */
|
||||||
|
|
|
@ -776,15 +776,15 @@ typedef uint64_t uintmax_t;
|
||||||
do { \
|
do { \
|
||||||
_Static_assert(!__builtin_types_compatible_p(typeof(SYMBOL), char[]), \
|
_Static_assert(!__builtin_types_compatible_p(typeof(SYMBOL), char[]), \
|
||||||
"Please YOINK(symbol), not YOINK(\"symbol\")"); \
|
"Please YOINK(symbol), not YOINK(\"symbol\")"); \
|
||||||
asm(".pushsection .yoink\n\t" \
|
asm(".section .yoink\n\t" \
|
||||||
"nop\t%a0\n\t" \
|
"nop\t%a0\n\t" \
|
||||||
".popsection" \
|
".previous" \
|
||||||
: /* no outputs */ \
|
: /* no outputs */ \
|
||||||
: "X"(SYMBOL)); \
|
: "X"(SYMBOL)); \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
#define STATIC_YOINK(SYMBOLSTR) \
|
#define STATIC_YOINK(SYMBOLSTR) \
|
||||||
asm(".pushsection .yoink\n\tnopl\t\"" SYMBOLSTR "\"\n\t.popsection")
|
asm(".section .yoink\n\tnopl\t\"" SYMBOLSTR "\"\n\t.previous")
|
||||||
|
|
||||||
#if !defined(IM_FEELING_NAUGHTY) && !defined(__STRICT_ANSI__)
|
#if !defined(IM_FEELING_NAUGHTY) && !defined(__STRICT_ANSI__)
|
||||||
#define STATIC_YOINK_SOURCE(PATH) STATIC_YOINK(PATH)
|
#define STATIC_YOINK_SOURCE(PATH) STATIC_YOINK(PATH)
|
||||||
|
|
|
@ -16,21 +16,9 @@
|
||||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/bits/weaken.h"
|
|
||||||
#include "libc/calls/internal.h"
|
|
||||||
#include "libc/dce.h"
|
#include "libc/dce.h"
|
||||||
#include "libc/log/log.h"
|
|
||||||
#include "libc/nt/console.h"
|
|
||||||
#include "libc/nt/enum/consolemodeflags.h"
|
|
||||||
#include "libc/nt/enum/filetype.h"
|
|
||||||
#include "libc/nt/enum/version.h"
|
|
||||||
#include "libc/nt/files.h"
|
|
||||||
#include "libc/nt/pedef.internal.h"
|
|
||||||
#include "libc/nt/runtime.h"
|
|
||||||
#include "libc/nt/struct/teb.h"
|
|
||||||
#include "libc/runtime/runtime.h"
|
#include "libc/runtime/runtime.h"
|
||||||
#include "libc/str/str.h"
|
#include "libc/str/str.h"
|
||||||
#include "libc/sysv/consts/fileno.h"
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Returns true if ANSI terminal colors are appropriate.
|
* Returns true if ANSI terminal colors are appropriate.
|
||||||
|
|
|
@ -129,9 +129,9 @@
|
||||||
.byte 0x0f,0x1f,0x44,0x00,0x00
|
.byte 0x0f,0x1f,0x44,0x00,0x00
|
||||||
#endif
|
#endif
|
||||||
#if defined(__MRECORD_MCOUNT__) && !defined(__MFENTRY__)
|
#if defined(__MRECORD_MCOUNT__) && !defined(__MFENTRY__)
|
||||||
.pushsection __mcount_loc,"a",@progbits
|
.section __mcount_loc,"a",@progbits
|
||||||
.quad 1382b
|
.quad 1382b
|
||||||
.popsection
|
.previous
|
||||||
#endif
|
#endif
|
||||||
#endif
|
#endif
|
||||||
.endm
|
.endm
|
||||||
|
@ -139,10 +139,10 @@
|
||||||
/ Pushes RVA on stack of linktime mergeable string literal.
|
/ Pushes RVA on stack of linktime mergeable string literal.
|
||||||
/ @see popstr
|
/ @see popstr
|
||||||
.macro pushstr text
|
.macro pushstr text
|
||||||
.pushsection .rodata.str1.1,"aSM",@progbits,1
|
.section .rodata.str1.1,"aSM",@progbits,1
|
||||||
.Lstr\@: .asciz "\text"
|
.Lstr\@: .asciz "\text"
|
||||||
.endobj .Lstr\@
|
.endobj .Lstr\@
|
||||||
.popsection
|
.previous
|
||||||
push $.Lstr\@ - IMAGE_BASE_VIRTUAL
|
push $.Lstr\@ - IMAGE_BASE_VIRTUAL
|
||||||
.endm
|
.endm
|
||||||
|
|
||||||
|
@ -155,12 +155,12 @@
|
||||||
|
|
||||||
/ Loads address of linktime mergeable string literal into register.
|
/ Loads address of linktime mergeable string literal into register.
|
||||||
.macro getstr text:req reg64:req reg32 regsz64 regsz32 bias=0
|
.macro getstr text:req reg64:req reg32 regsz64 regsz32 bias=0
|
||||||
.pushsection .rodata.str1.1,"aSM",@progbits,1
|
.section .rodata.str1.1,"aSM",@progbits,1
|
||||||
.type .Lstr\@,@object
|
.type .Lstr\@,@object
|
||||||
.Lstr\@: .asciz "\text"
|
.Lstr\@: .asciz "\text"
|
||||||
.Lstr\@.size = .-.Lstr\@ - 1
|
.Lstr\@.size = .-.Lstr\@ - 1
|
||||||
.size .Lstr\@,.-.Lstr\@
|
.size .Lstr\@,.-.Lstr\@
|
||||||
.popsection
|
.previous
|
||||||
plea .Lstr\@,\reg64,\reg32
|
plea .Lstr\@,\reg64,\reg32
|
||||||
.ifnb \regsz64
|
.ifnb \regsz64
|
||||||
#ifdef __OPTIMIZE_SIZE__
|
#ifdef __OPTIMIZE_SIZE__
|
||||||
|
@ -178,12 +178,12 @@
|
||||||
/ TODO(jart): delete
|
/ TODO(jart): delete
|
||||||
/ Loads address of linktime mergeable string literal into register.
|
/ Loads address of linktime mergeable string literal into register.
|
||||||
.macro loadstr text:req reg:req regsz bias=0
|
.macro loadstr text:req reg:req regsz bias=0
|
||||||
.pushsection .rodata.str1.1,"aSM",@progbits,1
|
.section .rodata.str1.1,"aSM",@progbits,1
|
||||||
.type .Lstr\@,@object
|
.type .Lstr\@,@object
|
||||||
.Lstr\@: .asciz "\text"
|
.Lstr\@: .asciz "\text"
|
||||||
.Lstr\@.size = .-.Lstr\@ - 1
|
.Lstr\@.size = .-.Lstr\@ - 1
|
||||||
.size .Lstr\@,.-.Lstr\@
|
.size .Lstr\@,.-.Lstr\@
|
||||||
.popsection
|
.previous
|
||||||
ezlea .Lstr\@,\reg
|
ezlea .Lstr\@,\reg
|
||||||
.ifnb \regsz
|
.ifnb \regsz
|
||||||
#ifdef __OPTIMIZE_SIZE__
|
#ifdef __OPTIMIZE_SIZE__
|
||||||
|
|
|
@ -253,25 +253,25 @@
|
||||||
.macro .hookable
|
.macro .hookable
|
||||||
/ nopl 0x00(%rax,%rax,1)
|
/ nopl 0x00(%rax,%rax,1)
|
||||||
83457: .byte 0x0f,0x1f,0x44,0x00,0x00
|
83457: .byte 0x0f,0x1f,0x44,0x00,0x00
|
||||||
.pushsection __mcount_loc,"a",@progbits
|
.section __mcount_loc,"a",@progbits
|
||||||
.quad 83457b
|
.quad 83457b
|
||||||
.popsection
|
.previous
|
||||||
.endm
|
.endm
|
||||||
|
|
||||||
/ Puts initialized data in uninitialized data section.
|
/ Puts initialized data in uninitialized data section.
|
||||||
.macro .bsdata name:req expr:req bnd vis
|
.macro .bsdata name:req expr:req bnd vis
|
||||||
.pushsection .initbss.300._init_\name,"aw",@nobits
|
.section .initbss.300._init_\name,"aw",@nobits
|
||||||
\name: .quad 0
|
\name: .quad 0
|
||||||
.endobj \name,\bnd,\vis
|
.endobj \name,\bnd,\vis
|
||||||
.popsection
|
.previous
|
||||||
.pushsection .initro.300._init_\name,"a",@progbits
|
.section .initro.300._init_\name,"a",@progbits
|
||||||
.quad \expr
|
.quad \expr
|
||||||
.popsection
|
.previous
|
||||||
.pushsection .init.300._init_\name,"ax",@progbits
|
.section .init.300._init_\name,"ax",@progbits
|
||||||
_init_\name:
|
_init_\name:
|
||||||
movsq
|
movsq
|
||||||
.endfn _init_\name
|
.endfn _init_\name
|
||||||
.popsection
|
.previous
|
||||||
.endm
|
.endm
|
||||||
|
|
||||||
/ ICE Breakpoint.
|
/ ICE Breakpoint.
|
||||||
|
@ -304,14 +304,14 @@ _init_\name:
|
||||||
/ In order for this technique to work with --gc-sections, another
|
/ In order for this technique to work with --gc-sections, another
|
||||||
/ module somewhere might want to weakly reference whats yoinked.
|
/ module somewhere might want to weakly reference whats yoinked.
|
||||||
.macro yoink symbol:req
|
.macro yoink symbol:req
|
||||||
.pushsection .yoink
|
.section .yoink
|
||||||
nop "\symbol"
|
nop "\symbol"
|
||||||
.popsection
|
.previous
|
||||||
.endm
|
.endm
|
||||||
.macro .yoink symbol:req
|
.macro .yoink symbol:req
|
||||||
.pushsection .yoink
|
.section .yoink
|
||||||
nop "\symbol"
|
nop "\symbol"
|
||||||
.popsection
|
.previous
|
||||||
.endm
|
.endm
|
||||||
|
|
||||||
/ Calls Windows function.
|
/ Calls Windows function.
|
||||||
|
|
|
@ -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/macros.h"
|
||||||
|
#include "libc/nexgen32e/x86feature.h"
|
||||||
|
|
||||||
/ Broadcast byte literal to vector, e.g.
|
/ Broadcast byte literal to vector, e.g.
|
||||||
/
|
/
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│
|
||||||
│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│
|
│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│
|
||||||
╞══════════════════════════════════════════════════════════════════════════════╡
|
╞══════════════════════════════════════════════════════════════════════════════╡
|
||||||
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
│ Copyright 2020 Justine Alexandra Roberts Tunney │
|
||||||
│ │
|
│ │
|
||||||
|
@ -16,23 +16,58 @@
|
||||||
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │
|
||||||
│ PERFORMANCE OF THIS SOFTWARE. │
|
│ PERFORMANCE OF THIS SOFTWARE. │
|
||||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||||
#include "libc/nexgen32e/hascharacter.internal.h"
|
#include "libc/macros.h"
|
||||||
#include "libc/str/str.h"
|
|
||||||
|
|
||||||
/**
|
/ Returns prefix length, consisting of chars not in reject.
|
||||||
* Returns prefix length, consisting of chars not in reject.
|
/ a.k.a. Return index of first byte that's in charset.
|
||||||
* a.k.a. Return index of first byte that's in charset.
|
/
|
||||||
*
|
/ @param rdi is string
|
||||||
* @param reject is nul-terminated character set
|
/ @param rsi is reject nul-terminated character set
|
||||||
* @see strspn(), strtok_r()
|
/ @see strspn(), strtok_r()
|
||||||
* @asyncsignalsafe
|
/ @asyncsignalsafe
|
||||||
*/
|
strcspn:
|
||||||
size_t strcspn(const char *s, const char *reject) {
|
push %rbp
|
||||||
size_t i;
|
mov %rsp,%rbp
|
||||||
for (i = 0; s[i]; ++i) {
|
sub $16,%rsp
|
||||||
if (HasCharacter(s[i], reject)) {
|
push %rdi
|
||||||
break;
|
mov %rsi,%rdi
|
||||||
}
|
call strlen
|
||||||
}
|
pop %rdi
|
||||||
return i;
|
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
|
|
@ -5,11 +5,11 @@
|
||||||
#define TRAMPOLINE(FUNCTION, THUNK) \
|
#define TRAMPOLINE(FUNCTION, THUNK) \
|
||||||
({ \
|
({ \
|
||||||
typeof(FUNCTION) *Tramp; \
|
typeof(FUNCTION) *Tramp; \
|
||||||
asm(".pushsection .text.trampoline\n" \
|
asm(".section .text.trampoline\n" \
|
||||||
"183:\n\t" \
|
"183:\n\t" \
|
||||||
"mov\t%1,%%eax\n\t" \
|
"mov\t%1,%%eax\n\t" \
|
||||||
"jmp\t" #THUNK "\n\t" \
|
"jmp\t" #THUNK "\n\t" \
|
||||||
".popsection\n\t" \
|
".previous\n\t" \
|
||||||
"mov\t$183b,%k0" \
|
"mov\t$183b,%k0" \
|
||||||
: "=r"(Tramp) \
|
: "=r"(Tramp) \
|
||||||
: "i"(FUNCTION)); \
|
: "i"(FUNCTION)); \
|
||||||
|
|
10342
libc/nt/hog.py
10342
libc/nt/hog.py
File diff suppressed because it is too large
Load diff
49
test/libc/nexgen32e/strcspn_test.c
Normal file
49
test/libc/nexgen32e/strcspn_test.c
Normal file
|
@ -0,0 +1,49 @@
|
||||||
|
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
|
||||||
|
│vi: set net ft=c ts=2 sts=2 sw=2 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/str/str.h"
|
||||||
|
#include "libc/testlib/ezbench.h"
|
||||||
|
#include "libc/testlib/testlib.h"
|
||||||
|
|
||||||
|
TEST(strcspn, test) {
|
||||||
|
EXPECT_EQ(0, strcspn("abcdefg", "ae"));
|
||||||
|
EXPECT_EQ(0, strcspn("abcdefg", "aeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"));
|
||||||
|
EXPECT_EQ(4, strcspn("abcdefg", "ze"));
|
||||||
|
EXPECT_EQ(4, strcspn("abcdefg", "zeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"));
|
||||||
|
EXPECT_EQ(5, strcspn("abcdfzg", "ze"));
|
||||||
|
EXPECT_EQ(5, strcspn("abcdfzg", "zeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"));
|
||||||
|
EXPECT_EQ(7, strcspn("abcdEfg", "ze"));
|
||||||
|
EXPECT_EQ(7, strcspn("abcdEfg", "zeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeeee"));
|
||||||
|
EXPECT_EQ(31, strcspn("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOp", "abcdefghijklmnp"));
|
||||||
|
EXPECT_EQ(31, strcspn("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOp",
|
||||||
|
"abcdefghijklmnpabcdefghijklmnp"));
|
||||||
|
}
|
||||||
|
|
||||||
|
BENCH(strcspn, bench) {
|
||||||
|
EZBENCH2("strcspn", donothing,
|
||||||
|
EXPROPRIATE(
|
||||||
|
strcspn("pABCDEFGHIJKLMNOPABCDEFGHIJKLMNO", "abcdefghijklmnp")));
|
||||||
|
EZBENCH2("strcspn", donothing,
|
||||||
|
EXPROPRIATE(
|
||||||
|
strcspn("ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOp", "abcdefghijklmnp")));
|
||||||
|
EZBENCH2(
|
||||||
|
"strcspn", donothing,
|
||||||
|
EXPROPRIATE(strcspn(
|
||||||
|
"ABCDEFGHIJKLMNOPABCDEFGHIJKLMNOABCDEFGHIJKLMNOPABCDEFGHIJKLMNOp",
|
||||||
|
"abcdefghijklmnp")));
|
||||||
|
}
|
|
@ -24,6 +24,7 @@ o/$(MODE)/test/libc/release/smoke.com: \
|
||||||
-fno-pie \
|
-fno-pie \
|
||||||
-nostdlib \
|
-nostdlib \
|
||||||
-nostdinc \
|
-nostdinc \
|
||||||
|
-mno-red-zone \
|
||||||
-Wl,--gc-sections \
|
-Wl,--gc-sections \
|
||||||
-Wl,--oformat=binary \
|
-Wl,--oformat=binary \
|
||||||
-Wl,-z,max-page-size=0x1000 \
|
-Wl,-z,max-page-size=0x1000 \
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
asm(".pushsection .start,\"ax\",@progbits\n\t"
|
asm(".section .start,\"ax\",@progbits\n\t"
|
||||||
".globl\t_start\n"
|
".globl\t_start\n"
|
||||||
"_start:\n\t"
|
"_start:\n\t"
|
||||||
"jmp\t1f\n1:\t"
|
"jmp\t1f\n1:\t"
|
||||||
"call\tmain\n\t"
|
"call\tmain\n\t"
|
||||||
"nop\n\t"
|
"nop\n\t"
|
||||||
".popsection");
|
".previous");
|
||||||
|
|
|
@ -23,9 +23,9 @@
|
||||||
.Lrows = 0 # w/ 2 cols
|
.Lrows = 0 # w/ 2 cols
|
||||||
|
|
||||||
.macro .tab sym:req str
|
.macro .tab sym:req str
|
||||||
.pushsection .rodata.str1.1,"aSM",@progbits,1
|
.section .rodata.str1.1,"aSM",@progbits,1
|
||||||
.L\@: .asciz "\str"
|
.L\@: .asciz "\str"
|
||||||
.popsection
|
.previous
|
||||||
.long RVA(\sym)
|
.long RVA(\sym)
|
||||||
.long RVA(.L\@)
|
.long RVA(.L\@)
|
||||||
.Lrows = .Lrows + 1
|
.Lrows = .Lrows + 1
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue