mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-02 17:28:30 +00:00
Initial import
This commit is contained in:
commit
c91b3c5006
14915 changed files with 590219 additions and 0 deletions
39
libc/nexgen32e/atomicislockfree.S
Normal file
39
libc/nexgen32e/atomicislockfree.S
Normal file
|
@ -0,0 +1,39 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
/ Returns true if architecture guarantees atomicity.
|
||||
/
|
||||
/ @param rdi is byte width of type
|
||||
/ @param rsi is optional pointer for alignment check
|
||||
/ @see Intel's Six Thousand Page Manual V.3A §8.2.3.1
|
||||
__atomic_is_lock_free:
|
||||
.leafprologue
|
||||
.profilable
|
||||
xor %ecx,%ecx
|
||||
pushpop 1,%rax
|
||||
cmp $7,%rdi
|
||||
cmova %ecx,%eax
|
||||
dec %edi
|
||||
and %edi,%esi
|
||||
cmovnz %ecx,%eax
|
||||
.leafepilogue
|
||||
.endfn __atomic_is_lock_free,globl,hidden
|
||||
.yoink __FILE__
|
33
libc/nexgen32e/bcmp.S
Normal file
33
libc/nexgen32e/bcmp.S
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
/ Compares memory.
|
||||
/
|
||||
/ This API was thought to be nearly extinct until recent versions
|
||||
/ of Clang (c. 2019) started generating synthetic calls to it.
|
||||
/
|
||||
/ @param edi first string
|
||||
/ @param esi second string
|
||||
/ @param edx byte size
|
||||
/ @return 0 if equal or nonzero
|
||||
bcmp: jmp *hook$memcmp(%rip)
|
||||
.endfn bcmp,globl
|
||||
.yoink __FILE__
|
32
libc/nexgen32e/bcopy.S
Normal file
32
libc/nexgen32e/bcopy.S
Normal file
|
@ -0,0 +1,32 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
/ Copies memory.
|
||||
/
|
||||
/ DEST and SRC may overlap.
|
||||
/
|
||||
/ @param rdi is dest
|
||||
/ @param rsi is src
|
||||
/ @param rdx is number of bytes
|
||||
bcopy: jmp memmove
|
||||
.endfn bcopy,globl
|
||||
.yoink __FILE__
|
||||
.yoink __FILE__
|
59
libc/nexgen32e/bench.h
Normal file
59
libc/nexgen32e/bench.h
Normal file
|
@ -0,0 +1,59 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_NEXGEN32E_BENCH_H_
|
||||
#define COSMOPOLITAN_LIBC_NEXGEN32E_BENCH_H_
|
||||
#include "libc/nexgen32e/rdtsc.h"
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
|
||||
/**
|
||||
* @fileoverview NexGen32e Microbenchmarking.
|
||||
*
|
||||
* @see X86_HAVE(INVTSC)
|
||||
* @see libc/testlib/bench.h
|
||||
*/
|
||||
|
||||
#define __startbench() \
|
||||
({ \
|
||||
uint64_t Ticks; \
|
||||
asm volatile("lfence\n\t" \
|
||||
"push\t%%rbx\n\t" \
|
||||
"cpuid\n\t" \
|
||||
"pop\t%%rbx\n\t" \
|
||||
"rdtsc\n\t" \
|
||||
"shl\t%2,%%rdx\n\t" \
|
||||
"or\t%%rdx,%0" \
|
||||
: "=a"(Ticks) \
|
||||
: "0"(0), "J"(32) \
|
||||
: "rcx", "rdx", "memory", "cc"); \
|
||||
Ticks; \
|
||||
})
|
||||
|
||||
#define __endbench() \
|
||||
({ \
|
||||
uint64_t Ticks; \
|
||||
asm volatile("rdtscp\n\t" \
|
||||
"shl\t%1,%%rdx\n\t" \
|
||||
"or\t%%rdx,%%rax\n\t" \
|
||||
"mov\t%%rax,%0\n\t" \
|
||||
"xor\t%%eax,%%eax\n\t" \
|
||||
"push\t%%rbx\n\t" \
|
||||
"cpuid\n\t" \
|
||||
"pop\t%%rbx" \
|
||||
: "=r"(Ticks) \
|
||||
: "J"(32) \
|
||||
: "rax", "rcx", "rdx", "memory", "cc"); \
|
||||
Ticks; \
|
||||
})
|
||||
|
||||
#define __startbench_m() mfence_lfence_rdtsc_lfence()
|
||||
#define __endbench_m() __startbench_m()
|
||||
#define __marker() asm("nop")
|
||||
#define __ordered() asm volatile("" ::: "memory")
|
||||
#define __fakeread(X) asm volatile("" : /* no outputs */ : "g"(X))
|
||||
#define __fakereadwrite(X) \
|
||||
({ \
|
||||
autotype(X) Res = (X); \
|
||||
asm volatile("" : "=g"(Res) : "0"(X)); \
|
||||
Res; \
|
||||
})
|
||||
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_NEXGEN32E_BENCH_H_ */
|
43
libc/nexgen32e/bsf.S
Normal file
43
libc/nexgen32e/bsf.S
Normal file
|
@ -0,0 +1,43 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
/ Finds lowest set bit in 𝑥.
|
||||
/
|
||||
/ @param edi is 32-bit unsigned 𝑥 value
|
||||
/ @return eax in range [0,32) or undefined if 𝑥 is 0
|
||||
/ @see also treasure trove of nearly identical functions
|
||||
/
|
||||
/ uint32 𝑥 bsf(𝑥) tzcnt(𝑥) ffs(𝑥) bsr(𝑥) lzcnt(𝑥)
|
||||
/ 0x00000000 wut 32 0 wut 32
|
||||
/ 0x00000001 0 0 1 0 31
|
||||
/ 0x80000001 0 0 1 31 0
|
||||
/ 0x80000000 31 31 32 31 0
|
||||
/ 0x00000010 4 4 5 4 27
|
||||
/ 0x08000010 4 4 5 27 4
|
||||
/ 0x08000000 27 27 28 27 4
|
||||
/ 0xffffffff 0 0 1 31 0
|
||||
/
|
||||
bsf: .leafprologue
|
||||
.profilable
|
||||
bsf %edi,%eax
|
||||
.leafepilogue
|
||||
.endfn bsf,globl
|
||||
.yoink __FILE__
|
21
libc/nexgen32e/bsf.h
Normal file
21
libc/nexgen32e/bsf.h
Normal file
|
@ -0,0 +1,21 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_NEXGEN32E_BSF_H_
|
||||
#define COSMOPOLITAN_LIBC_NEXGEN32E_BSF_H_
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
unsigned bsf(unsigned) libcesque pureconst;
|
||||
unsigned bsfl(unsigned long) libcesque pureconst;
|
||||
unsigned bsfmax(uintmax_t) libcesque pureconst;
|
||||
|
||||
#define bsf(X) \
|
||||
({ \
|
||||
unsigned Res; \
|
||||
typeof(X) Word; \
|
||||
asm("bsf\t%1,%0" : "=r,r"(Word) : "r,m"(X)); \
|
||||
Res = Word; \
|
||||
Res; \
|
||||
})
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_NEXGEN32E_BSF_H_ */
|
44
libc/nexgen32e/bsfl.S
Normal file
44
libc/nexgen32e/bsfl.S
Normal file
|
@ -0,0 +1,44 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
/ Finds lowest set bit in 𝑥.
|
||||
/
|
||||
/ @param rdi is 64-bit unsigned 𝑥 value
|
||||
/ @return eax number in range [0,64) or undefined if 𝑥 is 0
|
||||
/ @see also treasure trove of nearly identical functions
|
||||
/
|
||||
/ uint32 𝑥 bsf(𝑥) tzcnt(𝑥) ffs(𝑥) bsr(𝑥) lzcnt(𝑥)
|
||||
/ 0x00000000 wut 32 0 wut 32
|
||||
/ 0x00000001 0 0 1 0 31
|
||||
/ 0x80000001 0 0 1 31 0
|
||||
/ 0x80000000 31 31 32 31 0
|
||||
/ 0x00000010 4 4 5 4 27
|
||||
/ 0x08000010 4 4 5 27 4
|
||||
/ 0x08000000 27 27 28 27 4
|
||||
/ 0xffffffff 0 0 1 31 0
|
||||
/
|
||||
bsfl: .leafprologue
|
||||
.profilable
|
||||
bsf %rdi,%rax
|
||||
.leafepilogue
|
||||
.endfn bsfl,globl
|
||||
.alias bsfl,bsfll
|
||||
.yoink __FILE__
|
43
libc/nexgen32e/bsr.S
Normal file
43
libc/nexgen32e/bsr.S
Normal file
|
@ -0,0 +1,43 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
/ Returns binary logarithm of integer 𝑥.
|
||||
/
|
||||
/ @param edi is 32-bit unsigned 𝑥 value
|
||||
/ @return eax number in range [0,32) or undefined if 𝑥 is 0
|
||||
/ @see also treasure trove of nearly identical functions
|
||||
/
|
||||
/ uint32 𝑥 bsf(𝑥) tzcnt(𝑥) ffs(𝑥) bsr(𝑥) lzcnt(𝑥)
|
||||
/ 0x00000000 wut 32 0 wut 32
|
||||
/ 0x00000001 0 0 1 0 31
|
||||
/ 0x80000001 0 0 1 31 0
|
||||
/ 0x80000000 31 31 32 31 0
|
||||
/ 0x00000010 4 4 5 4 27
|
||||
/ 0x08000010 4 4 5 27 4
|
||||
/ 0x08000000 27 27 28 27 4
|
||||
/ 0xffffffff 0 0 1 31 0
|
||||
/
|
||||
bsr: .leafprologue
|
||||
.profilable
|
||||
bsr %edi,%eax
|
||||
.leafepilogue
|
||||
.endfn bsr,globl
|
||||
.yoink __FILE__
|
29
libc/nexgen32e/bsr.h
Normal file
29
libc/nexgen32e/bsr.h
Normal file
|
@ -0,0 +1,29 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_NEXGEN32E_BSR_H_
|
||||
#define COSMOPOLITAN_LIBC_NEXGEN32E_BSR_H_
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
unsigned bsr(unsigned) libcesque pureconst;
|
||||
unsigned bsrl(unsigned long) libcesque pureconst;
|
||||
unsigned bsrmax(uintmax_t) libcesque pureconst;
|
||||
|
||||
#ifdef __GNUC__
|
||||
#define bsr(X) \
|
||||
({ \
|
||||
unsigned Word; \
|
||||
asm("bsrl\t%1,%0" : "=r,r"(Word) : "r,m"(X)); \
|
||||
Word; \
|
||||
})
|
||||
#define bsrl(X) \
|
||||
({ \
|
||||
unsigned Res; \
|
||||
unsigned long Word; \
|
||||
asm("bsrq\t%1,%0" : "=r,r"(Word) : "r,m"(X)); \
|
||||
Res = Word; \
|
||||
Res; \
|
||||
})
|
||||
#endif
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_NEXGEN32E_BSR_H_ */
|
44
libc/nexgen32e/bsrl.S
Normal file
44
libc/nexgen32e/bsrl.S
Normal file
|
@ -0,0 +1,44 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
/ Returns binary logarithm of integer 𝑥.
|
||||
/
|
||||
/ @param rdi is 32-bit unsigned 𝑥 value
|
||||
/ @return eax number in range [0,64) or undefined if 𝑥 is 0
|
||||
/ @see also treasure trove of nearly identical functions
|
||||
/
|
||||
/ uint32 𝑥 bsf(𝑥) tzcnt(𝑥) ffs(𝑥) bsr(𝑥) lzcnt(𝑥)
|
||||
/ 0x00000000 wut 32 0 wut 32
|
||||
/ 0x00000001 0 0 1 0 31
|
||||
/ 0x80000001 0 0 1 31 0
|
||||
/ 0x80000000 31 31 32 31 0
|
||||
/ 0x00000010 4 4 5 4 27
|
||||
/ 0x08000010 4 4 5 27 4
|
||||
/ 0x08000000 27 27 28 27 4
|
||||
/ 0xffffffff 0 0 1 31 0
|
||||
/
|
||||
bsrl: .leafprologue
|
||||
.profilable
|
||||
bsr %rdi,%rax
|
||||
.leafepilogue
|
||||
.endfn bsrl,globl
|
||||
.alias bsrl,bsrll
|
||||
.yoink __FILE__
|
47
libc/nexgen32e/bsrmax.S
Normal file
47
libc/nexgen32e/bsrmax.S
Normal file
|
@ -0,0 +1,47 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
/ Returns binary logarithm of integer 𝑥.
|
||||
/
|
||||
/ @param rsi:rdi is 128-bit unsigned 𝑥 value
|
||||
/ @return eax number in range [0,128) or undef if 𝑥 is 0
|
||||
/ @see also treasure trove of nearly identical functions
|
||||
/
|
||||
/ uint32 𝑥 bsf(𝑥) tzcnt(𝑥) ffs(𝑥) bsr(𝑥) lzcnt(𝑥)
|
||||
/ 0x00000000 wut 32 0 wut 32
|
||||
/ 0x00000001 0 0 1 0 31
|
||||
/ 0x80000001 0 0 1 31 0
|
||||
/ 0x80000000 31 31 32 31 0
|
||||
/ 0x00000010 4 4 5 4 27
|
||||
/ 0x08000010 4 4 5 27 4
|
||||
/ 0x08000000 27 27 28 27 4
|
||||
/ 0xffffffff 0 0 1 31 0
|
||||
/
|
||||
bsrmax: .leafprologue
|
||||
.profilable
|
||||
bsr %rsi,%rax
|
||||
jnz 2f
|
||||
bsr %rdi,%rax
|
||||
1: .leafepilogue
|
||||
2: add $64,%eax
|
||||
jmp 1b
|
||||
.endfn bsrmax,globl
|
||||
.yoink __FILE__
|
35
libc/nexgen32e/bzero.S
Normal file
35
libc/nexgen32e/bzero.S
Normal file
|
@ -0,0 +1,35 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
/ Sets memory to zero.
|
||||
/
|
||||
/ C code should always favor memset(), since that's the one we've
|
||||
/ prototyped with the best optimizations. This definition is used
|
||||
/ by old code and sometimes code generators, as a thunk.
|
||||
/
|
||||
/ @param rdi is dest
|
||||
/ @param rsi is the number of bytes to set
|
||||
/ @see memset(), explicit_bzero()
|
||||
bzero: mov %rsi,%rdx
|
||||
xor %esi,%esi
|
||||
jmp _memset
|
||||
.endfn bzero,globl
|
||||
.yoink __FILE__
|
16
libc/nexgen32e/cachesize.h
Normal file
16
libc/nexgen32e/cachesize.h
Normal file
|
@ -0,0 +1,16 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_NEXGEN32E_CACHESIZE_H_
|
||||
#define COSMOPOLITAN_LIBC_NEXGEN32E_CACHESIZE_H_
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
enum CpuCacheType {
|
||||
kCpuCacheTypeData = 1,
|
||||
kCpuCacheTypeInstruction,
|
||||
kCpuCacheTypeUnified,
|
||||
};
|
||||
|
||||
unsigned getcachesize(enum CpuCacheType, int);
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_NEXGEN32E_CACHESIZE_H_ */
|
133
libc/nexgen32e/cescapec.S
Normal file
133
libc/nexgen32e/cescapec.S
Normal file
|
@ -0,0 +1,133 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "ape/relocations.h"
|
||||
#include "libc/macros.h"
|
||||
|
||||
/ Escapes byte for string literal.
|
||||
/
|
||||
/ This turns stuff like (char)0xFF into \0377. The returned
|
||||
/ string is word-encoded, e.g. '\\'|'0'<<010|'3'<<020|etc.
|
||||
/
|
||||
/ @see libc/nexgen32e/cescapec.c
|
||||
cescapec:
|
||||
lea -7(%rdi),%ecx
|
||||
cmp $85,%cl
|
||||
ja 1f
|
||||
mov $'\\,%eax
|
||||
movzbl %cl,%ecx
|
||||
jmp *cescapectab(,%rcx,8)
|
||||
.Lanchorpoint:
|
||||
.LBEL: mov $'a,%ah
|
||||
ret
|
||||
.LBS: mov $'b,%ah
|
||||
ret
|
||||
.LHT: mov $'t,%ah
|
||||
ret
|
||||
.LLF: or $'n<<010|'\\<<020|'\n<<030,%eax
|
||||
ret
|
||||
.LVT: mov $'v,%ah
|
||||
ret
|
||||
.LFF: mov $'f,%ah
|
||||
ret
|
||||
.LCR: mov $'r,%ah
|
||||
ret
|
||||
.LDQ: mov $'\",%ah
|
||||
ret
|
||||
.LSQ: mov $'\',%ah
|
||||
ret
|
||||
.LBSL: mov $'\\,%ah
|
||||
ret
|
||||
#ifdef __STRICT_ANSI__
|
||||
.LQM: mov $'?,%ah
|
||||
ret
|
||||
.LESC:
|
||||
#elif defined(__GNUC__)
|
||||
.LESC: mov $'e,%ah
|
||||
ret
|
||||
.LQM:
|
||||
#endif
|
||||
1: movzbl %dil,%eax
|
||||
cmp $127,%eax
|
||||
ja 2f
|
||||
ezlea kCtype,cx
|
||||
testb $16,(%rcx,%rax)
|
||||
jne 3f
|
||||
2: and $-64,%eax
|
||||
mov %edi,%ecx
|
||||
and $56,%ecx
|
||||
shl $13,%ecx
|
||||
and $7,%edi
|
||||
shl $24,%edi
|
||||
or %ecx,%edi
|
||||
lea (%rdi,%rax,4),%eax
|
||||
add $'0<<030|'0<<020|'0<<010|'\\,%eax
|
||||
3: ret
|
||||
.endfn cescapec,globl
|
||||
|
||||
.initro 300,_init_cescapec
|
||||
cescapectab.ro:
|
||||
.byte 1,.LBEL-.Lanchorpoint
|
||||
.byte 1,.LBS-.Lanchorpoint
|
||||
.byte 1,.LHT-.Lanchorpoint
|
||||
.byte 1,.LLF-.Lanchorpoint
|
||||
.byte 1,.LVT-.Lanchorpoint
|
||||
.byte 1,.LFF-.Lanchorpoint
|
||||
.byte 1,.LCR-.Lanchorpoint
|
||||
.byte 0x1b-'\r-1,1b-.Lanchorpoint
|
||||
.byte 1,.LESC-.Lanchorpoint
|
||||
.byte '\"-0x1b-1,1b-.Lanchorpoint
|
||||
.byte 1,.LDQ-.Lanchorpoint
|
||||
.byte '\'-'\"-1,1b-.Lanchorpoint
|
||||
.byte 1,.LSQ-.Lanchorpoint
|
||||
.byte '?-'\'-1,1b-.Lanchorpoint
|
||||
.byte 1,.LQM-.Lanchorpoint
|
||||
.byte '\\-'?-1,1b-.Lanchorpoint
|
||||
.byte 1,.LBSL-.Lanchorpoint
|
||||
.equ .Lcescapectab.ro.size,.-cescapectab.ro
|
||||
.org 8 - .Lcescapectab.ro.size % 8 + .
|
||||
.endobj cescapectab.ro,globl,hidden
|
||||
.previous
|
||||
|
||||
.initbss 300,_init_cescapec
|
||||
cescapectab:
|
||||
.rept '\\-7+1
|
||||
.quad 0
|
||||
.endr
|
||||
.endobj cescapectab
|
||||
.previous
|
||||
|
||||
.init.start 300,_init_cescapec
|
||||
ezlea .Lanchorpoint,dx
|
||||
mov $.Lcescapectab.ro.size/2,%ch
|
||||
0: xor %eax,%eax
|
||||
lodsb
|
||||
mov %al,%cl
|
||||
lodsb
|
||||
add %rdx,%rax
|
||||
1: stosq
|
||||
dec %cl
|
||||
jnz 1b
|
||||
dec %ch
|
||||
jnz 0b
|
||||
.if .Lcescapectab.ro.size % 8
|
||||
add $(8-.Lcescapectab.ro.size%8),%rsi
|
||||
.endif
|
||||
.init.end 300,_init_cescapec
|
||||
.yoink __FILE__
|
35
libc/nexgen32e/clamp1.S
Normal file
35
libc/nexgen32e/clamp1.S
Normal file
|
@ -0,0 +1,35 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
clamp1: .leafprologue
|
||||
minps .Lmax(%rip),%xmm0
|
||||
maxps .Lmin(%rip),%xmm0
|
||||
.leafepilogue
|
||||
.endfn clamp1,globl,hidden
|
||||
|
||||
.rodata.cst16
|
||||
.Lmin: .rept 4
|
||||
.float 0
|
||||
.endr
|
||||
.Lmax: .rept 4
|
||||
.float 0.99609375
|
||||
.endr
|
||||
.yoink __FILE__
|
43
libc/nexgen32e/cmpsb.S
Normal file
43
libc/nexgen32e/cmpsb.S
Normal file
|
@ -0,0 +1,43 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
/ Compares 8-bit signed integers.
|
||||
/
|
||||
/ @param rdi points to left integer
|
||||
/ @param rsi points to right integer
|
||||
/ @return <0, 0, or >0 based on comparison
|
||||
.align 16
|
||||
cmpsb: .leafprologue
|
||||
.profilable
|
||||
xor %eax,%eax
|
||||
cmpsb
|
||||
cmovl .Lone(%rip),%eax
|
||||
cmovg .Lneg1(%rip),%eax
|
||||
.leafepilogue
|
||||
.endfn cmpsb,globl
|
||||
|
||||
.rodata.cst4
|
||||
.Lone: .long 1
|
||||
.endobj .Lone
|
||||
.Lneg1: .long -1
|
||||
.endobj .Lneg1
|
||||
.previous
|
||||
.yoink __FILE__
|
43
libc/nexgen32e/cmpsl.S
Normal file
43
libc/nexgen32e/cmpsl.S
Normal file
|
@ -0,0 +1,43 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
/ Compares 32-bit signed integers.
|
||||
/
|
||||
/ @param rdi points to left integer
|
||||
/ @param rsi points to right integer
|
||||
/ @return <0, 0, or >0 based on comparison
|
||||
.align 16
|
||||
cmpsl: .leafprologue
|
||||
.profilable
|
||||
xor %eax,%eax
|
||||
cmpsl
|
||||
cmovl .Lone(%rip),%eax
|
||||
cmovg .Lneg1(%rip),%eax
|
||||
.leafepilogue
|
||||
.endfn cmpsl,globl
|
||||
|
||||
.rodata.cst4
|
||||
.Lone: .long 1
|
||||
.endobj .Lone
|
||||
.Lneg1: .long -1
|
||||
.endobj .Lneg1
|
||||
.previous
|
||||
.yoink __FILE__
|
43
libc/nexgen32e/cmpsq.S
Normal file
43
libc/nexgen32e/cmpsq.S
Normal file
|
@ -0,0 +1,43 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
/ Compares 64-bit signed integers.
|
||||
/
|
||||
/ @param rdi points to left integer
|
||||
/ @param rsi points to right integer
|
||||
/ @return <0, 0, or >0 based on comparison
|
||||
.align 16
|
||||
cmpsq: .leafprologue
|
||||
.profilable
|
||||
xor %eax,%eax
|
||||
cmpsq
|
||||
cmovl .Lone(%rip),%eax
|
||||
cmovg .Lneg1(%rip),%eax
|
||||
.leafepilogue
|
||||
.endfn cmpsq,globl
|
||||
|
||||
.rodata.cst4
|
||||
.Lone: .long 1
|
||||
.endobj .Lone
|
||||
.Lneg1: .long -1
|
||||
.endobj .Lneg1
|
||||
.previous
|
||||
.yoink __FILE__
|
43
libc/nexgen32e/cmpsw.S
Normal file
43
libc/nexgen32e/cmpsw.S
Normal file
|
@ -0,0 +1,43 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
/ Compares 16-bit signed integers.
|
||||
/
|
||||
/ @param rdi points to left integer
|
||||
/ @param rsi points to right integer
|
||||
/ @return <0, 0, or >0 based on comparison
|
||||
.align 16
|
||||
cmpsw: .leafprologue
|
||||
.profilable
|
||||
xor %eax,%eax
|
||||
cmpsw
|
||||
cmovl .Lone(%rip),%eax
|
||||
cmovg .Lneg1(%rip),%eax
|
||||
.leafepilogue
|
||||
.endfn cmpsw,globl
|
||||
|
||||
.rodata.cst4
|
||||
.Lone: .long 1
|
||||
.endobj .Lone
|
||||
.Lneg1: .long -1
|
||||
.endobj .Lneg1
|
||||
.previous
|
||||
.yoink __FILE__
|
43
libc/nexgen32e/cmpub.S
Normal file
43
libc/nexgen32e/cmpub.S
Normal file
|
@ -0,0 +1,43 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
/ Compares 8-bit unsigned integers.
|
||||
/
|
||||
/ @param rdi points to left integer
|
||||
/ @param rsi points to right integer
|
||||
/ @return <0, 0, or >0 based on comparison
|
||||
.align 16
|
||||
cmpub: .leafprologue
|
||||
.profilable
|
||||
xor %eax,%eax
|
||||
cmpsb
|
||||
cmovb .Lone(%rip),%eax
|
||||
cmova .Lneg1(%rip),%eax
|
||||
.leafepilogue
|
||||
.endfn cmpub,globl
|
||||
|
||||
.rodata.cst4
|
||||
.Lone: .long 1
|
||||
.endobj .Lone
|
||||
.Lneg1: .long -1
|
||||
.endobj .Lneg1
|
||||
.previous
|
||||
.yoink __FILE__
|
43
libc/nexgen32e/cmpul.S
Normal file
43
libc/nexgen32e/cmpul.S
Normal file
|
@ -0,0 +1,43 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
/ Compares 32-bit unsigned integers.
|
||||
/
|
||||
/ @param rdi points to left integer
|
||||
/ @param rsi points to right integer
|
||||
/ @return <0, 0, or >0 based on comparison
|
||||
.align 16
|
||||
cmpul: .leafprologue
|
||||
.profilable
|
||||
xor %eax,%eax
|
||||
cmpsl
|
||||
cmovb .Lone(%rip),%eax
|
||||
cmova .Lneg1(%rip),%eax
|
||||
.leafepilogue
|
||||
.endfn cmpul,globl
|
||||
|
||||
.rodata.cst4
|
||||
.Lone: .long 1
|
||||
.endobj .Lone
|
||||
.Lneg1: .long -1
|
||||
.endobj .Lneg1
|
||||
.previous
|
||||
.yoink __FILE__
|
43
libc/nexgen32e/cmpuq.S
Normal file
43
libc/nexgen32e/cmpuq.S
Normal file
|
@ -0,0 +1,43 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
/ Compares 64-bit unsigned integers.
|
||||
/
|
||||
/ @param rdi points to left integer
|
||||
/ @param rsi points to right integer
|
||||
/ @return <0, 0, or >0 based on comparison
|
||||
.align 16
|
||||
cmpuq: .leafprologue
|
||||
.profilable
|
||||
xor %eax,%eax
|
||||
cmpsq
|
||||
cmovb .Lone(%rip),%eax
|
||||
cmova .Lneg1(%rip),%eax
|
||||
.leafepilogue
|
||||
.endfn cmpuq,globl
|
||||
|
||||
.rodata.cst4
|
||||
.Lone: .long 1
|
||||
.endobj .Lone
|
||||
.Lneg1: .long -1
|
||||
.endobj .Lneg1
|
||||
.previous
|
||||
.yoink __FILE__
|
43
libc/nexgen32e/cmpuw.S
Normal file
43
libc/nexgen32e/cmpuw.S
Normal file
|
@ -0,0 +1,43 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
/ Compares 16-bit unsigned integers.
|
||||
/
|
||||
/ @param rdi points to left integer
|
||||
/ @param rsi points to right integer
|
||||
/ @return <0, 0, or >0 based on comparison
|
||||
.align 16
|
||||
cmpuw: .leafprologue
|
||||
.profilable
|
||||
xor %eax,%eax
|
||||
cmpsw
|
||||
cmovb .Lone(%rip),%eax
|
||||
cmova .Lneg1(%rip),%eax
|
||||
.leafepilogue
|
||||
.endfn cmpuw,globl
|
||||
|
||||
.rodata.cst4
|
||||
.Lone: .long 1
|
||||
.endobj .Lone
|
||||
.Lneg1: .long -1
|
||||
.endobj .Lneg1
|
||||
.previous
|
||||
.yoink __FILE__
|
51
libc/nexgen32e/cpuid4.h
Normal file
51
libc/nexgen32e/cpuid4.h
Normal file
|
@ -0,0 +1,51 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_NEXGEN32E_CPUID4_H_
|
||||
#define COSMOPOLITAN_LIBC_NEXGEN32E_CPUID4_H_
|
||||
#include "libc/nexgen32e/kcpuids.h"
|
||||
|
||||
#define CPUID4_KEY (eax & 0xff)
|
||||
#define CPUID4_CACHE_TYPE (((eax & 0x0000001fu) >> 000) + 0)
|
||||
#define CPUID4_CACHE_LEVEL (((eax & 0x000000e0u) >> 005) + 0)
|
||||
#define CPUID4_IS_FULLY_ASSOCIATIVE (!!(eax & (1u << 9)))
|
||||
#define CPUID4_IS_SELF_INITIALIZING_LEVEL (!!(eax & (1u << 8)))
|
||||
#define CPUID4_MAX_THREADS_SHARING_CACHE (((eax & 0x03ffc000u) >> 016) + 1)
|
||||
#define CPUID4_MAX_CORES_IN_PHYSICAL_CPU (((eax & 0xfc000000u) >> 032) + 1)
|
||||
#define CPUID4_SYSTEM_COHERENCY_LINE_SIZE (((Ebx & 0x00000fffu) >> 000) + 1)
|
||||
#define CPUID4_PHYSICAL_LINE_PARTITIONS (((Ebx & 0x003ff000u) >> 014) + 1)
|
||||
#define CPUID4_WAYS_OF_ASSOCIATIVITY (((Ebx & 0xffc00000u) >> 026) + 1)
|
||||
#define CPUID4_NUMBER_OF_SETS (Ecx + 1u)
|
||||
#define CPUID4_WBINVD_INVD_BEHAVIOR (!!(Edx & (1u << 0)))
|
||||
#define CPUID4_INCLUSIVE_OF_LOWER_LEVELS (!!(Edx & (1u << 1)))
|
||||
#define CPUID4_COMPLEX_INDEXING (!!(Edx & (1u << 2)))
|
||||
#define CPUID4_CACHE_SIZE_IN_BYTES \
|
||||
(CPUID4_WAYS_OF_ASSOCIATIVITY * CPUID4_PHYSICAL_LINE_PARTITIONS * \
|
||||
CPUID4_SYSTEM_COHERENCY_LINE_SIZE * CPUID4_NUMBER_OF_SETS)
|
||||
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
#define CPUID4_ITERATE(I, FORM) \
|
||||
do { \
|
||||
uint32_t eax, Ebx, Ecx, Edx; \
|
||||
if (KCPUIDS(0H, EAX) >= 4) { \
|
||||
for (I = 0;; ++I) { \
|
||||
asm("push\t%%rbx\n\t" \
|
||||
"cpuid\n\t" \
|
||||
"mov\t%%ebx,%1\n\t" \
|
||||
"pop\t%%rbx" \
|
||||
: "=a"(eax), "=rm"(Ebx), "=c"(Ecx), "=d"(Edx) \
|
||||
: "0"(4), "2"(I)); \
|
||||
(void)Ebx; \
|
||||
(void)Ecx; \
|
||||
(void)Edx; \
|
||||
if (CPUID4_CACHE_TYPE) { \
|
||||
FORM; \
|
||||
} else { \
|
||||
break; \
|
||||
} \
|
||||
} \
|
||||
} \
|
||||
} while (0)
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_NEXGEN32E_CPUID4_H_ */
|
263
libc/nexgen32e/crc32-pclmul.S
Normal file
263
libc/nexgen32e/crc32-pclmul.S
Normal file
|
@ -0,0 +1,263 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
/ Computes Phil Katz CRC-32 w/ carryless multiply isa.
|
||||
/
|
||||
/ This is support code that's abstracted by crc32_z().
|
||||
/
|
||||
/ @param edi is initial value
|
||||
/ @param rsi points to buffer
|
||||
/ @param rdx is bytes in buffer that's >=64 and %16==0
|
||||
/ @return eax is crc32
|
||||
/ @note needs Westmere (c.2010) or Bulldozer (c.2011)
|
||||
/ @see “Fast CRC Computation for Generic Polynomials Using
|
||||
/ PCLMULQDQ Instruction” V. Gopal, E. Ozturk, et al.,
|
||||
/ 2009, intel.ly/2ySEwL0
|
||||
crc32$pclmul:
|
||||
.leafprologue
|
||||
.profilable
|
||||
movdqu (%rsi),%xmm7
|
||||
movd %edi,%xmm1
|
||||
movdqu 16(%rsi),%xmm9
|
||||
movdqu 32(%rsi),%xmm4
|
||||
movdqu 48(%rsi),%xmm0
|
||||
lea -64(%rdx),%rdi
|
||||
lea 64(%rsi),%rcx
|
||||
pxor %xmm7,%xmm1
|
||||
movdqa .Lk1k2(%rip),%xmm8
|
||||
cmp $63,%rdi
|
||||
jbe 2f
|
||||
lea -128(%rdx),%rdi
|
||||
mov %rdi,%rdx
|
||||
shr $6,%rdx
|
||||
lea 2(%rdx),%rax
|
||||
sal $6,%rax
|
||||
add %rax,%rsi
|
||||
mov %rcx,%rax
|
||||
3: add $64,%rax
|
||||
movdqa %xmm1,%xmm7
|
||||
movdqa %xmm4,%xmm5
|
||||
movdqa %xmm0,%xmm3
|
||||
movdqa %xmm9,%xmm6
|
||||
movdqa %xmm9,%xmm2
|
||||
movdqu -48(%rax),%xmm9
|
||||
pclmullqlqdq %xmm8,%xmm7
|
||||
pclmullqlqdq %xmm8,%xmm6
|
||||
pclmullqlqdq %xmm8,%xmm5
|
||||
pclmulhqhqdq %xmm8,%xmm1
|
||||
pclmulhqhqdq %xmm8,%xmm2
|
||||
pclmulhqhqdq %xmm8,%xmm4
|
||||
pxor %xmm7,%xmm1
|
||||
movdqu -64(%rax),%xmm7
|
||||
pxor %xmm6,%xmm2
|
||||
pxor %xmm5,%xmm4
|
||||
movdqu -32(%rax),%xmm6
|
||||
movdqu -16(%rax),%xmm5
|
||||
pclmullqlqdq %xmm8,%xmm3
|
||||
pclmulhqhqdq %xmm8,%xmm0
|
||||
pxor %xmm7,%xmm1
|
||||
pxor %xmm3,%xmm0
|
||||
pxor %xmm2,%xmm9
|
||||
pxor %xmm6,%xmm4
|
||||
pxor %xmm5,%xmm0
|
||||
cmp %rsi,%rax
|
||||
jne 3b
|
||||
lea 1(%rdx),%rax
|
||||
sal $6,%rdx
|
||||
sal $6,%rax
|
||||
sub %rdx,%rdi
|
||||
add %rax,%rcx
|
||||
2: movdqa .Lk3k4(%rip),%xmm3
|
||||
movdqa %xmm1,%xmm2
|
||||
movdqa %xmm1,%xmm5
|
||||
pclmulhqhqdq %xmm3,%xmm2
|
||||
pclmullqlqdq %xmm3,%xmm5
|
||||
pxor %xmm9,%xmm2
|
||||
pxor %xmm5,%xmm2
|
||||
movdqa %xmm2,%xmm5
|
||||
pclmulhqhqdq %xmm3,%xmm2
|
||||
movdqa %xmm2,%xmm1
|
||||
pclmullqlqdq %xmm3,%xmm5
|
||||
pxor %xmm4,%xmm1
|
||||
pxor %xmm5,%xmm1
|
||||
movdqa %xmm1,%xmm2
|
||||
pclmulhqhqdq %xmm3,%xmm1
|
||||
pclmullqlqdq %xmm3,%xmm2
|
||||
pxor %xmm1,%xmm0
|
||||
pxor %xmm2,%xmm0
|
||||
cmp $15,%rdi
|
||||
jbe 4f
|
||||
sub $16,%rdi
|
||||
mov %rcx,%rax
|
||||
and $-16,%rdi
|
||||
lea 16(%rcx,%rdi),%rdx
|
||||
5: movdqa %xmm0,%xmm1
|
||||
movdqu (%rax),%xmm6
|
||||
pclmulhqhqdq %xmm3,%xmm0
|
||||
add $16,%rax
|
||||
pclmullqlqdq %xmm3,%xmm1
|
||||
pxor %xmm1,%xmm0
|
||||
pxor %xmm6,%xmm0
|
||||
cmp %rax,%rdx
|
||||
jne 5b
|
||||
4: movdqa %xmm0,%xmm1
|
||||
movdqa .Lboop(%rip),%xmm2
|
||||
psrldq $8,%xmm0
|
||||
pclmullqhqdq %xmm3,%xmm1
|
||||
movdqa .Lpoly(%rip),%xmm3
|
||||
pxor %xmm1,%xmm0
|
||||
movdqa %xmm0,%xmm1
|
||||
pand %xmm2,%xmm0
|
||||
pclmullqlqdq .Lk5k0(%rip),%xmm0
|
||||
psrldq $4,%xmm1
|
||||
pxor %xmm0,%xmm1
|
||||
movdqa %xmm1,%xmm0
|
||||
pand %xmm2,%xmm0
|
||||
pclmullqhqdq %xmm3,%xmm0
|
||||
pand %xmm2,%xmm0
|
||||
pclmullqlqdq %xmm3,%xmm0
|
||||
pxor %xmm1,%xmm0
|
||||
pextrd $1,%xmm0,%eax
|
||||
.leafepilogue
|
||||
.endfn crc32$pclmul,globl,hidden
|
||||
|
||||
/ Definitions of the bit-reflected domain constants k1,k2,k3, etc.
|
||||
/ and the CRC32+Barrett polynomials given at the end of the paper.
|
||||
.rodata.cst16
|
||||
.Lk1k2: .quad 0x0000000154442bd4
|
||||
.quad 0x00000001c6e41596
|
||||
.endobj .Lk1k2
|
||||
.Lk3k4: .quad 0x00000001751997d0
|
||||
.quad 0x00000000ccaa009e
|
||||
.endobj .Lk3k4
|
||||
.Lk5k0: .quad 0x0000000163cd6124
|
||||
.quad 0x0000000000000000
|
||||
.endobj .Lk5k0
|
||||
.Lboop: .quad 0x00000000ffffffff
|
||||
.quad 0x00000000ffffffff
|
||||
.endobj .Lboop
|
||||
.Lpoly: .quad 0x00000001db710641
|
||||
.quad 0x00000001f7011641
|
||||
.endobj .Lpoly
|
||||
.previous
|
||||
|
||||
/* crc32() w/ pclmul for #c per n where c ≈ 0.293ns
|
||||
N x1 x8 x64 mBps
|
||||
------------------------------------------------------------
|
||||
1 4437.000 42.375 38.141 85
|
||||
1 45.000 39.375 38.234 85
|
||||
2 31.500 25.312 23.102 141
|
||||
3 25.667 19.792 17.911 181
|
||||
4 21.250 16.219 15.035 216
|
||||
7 18.429 12.946 11.712 277
|
||||
8 16.125 12.578 10.998 296
|
||||
15 12.867 9.925 9.161 355
|
||||
16 12.438 9.836 9.114 357
|
||||
31 11.194 8.528 8.149 399
|
||||
32 10.781 8.418 8.098 401
|
||||
63 9.063 7.780 7.647 425
|
||||
64 3.109 1.604 1.414 2299
|
||||
127 2.260 1.824 1.729 1880
|
||||
128 1.305 0.860 0.806 4033
|
||||
255 1.290 1.001 0.948 3428
|
||||
256 0.574 0.491 0.476 6822
|
||||
511 0.773 0.571 0.546 5956
|
||||
512 0.354 0.320 0.306 10613
|
||||
1023 0.425 0.365 0.347 9375
|
||||
1024 0.237 0.229 0.231 14097
|
||||
2047 0.278 0.251 0.246 13236
|
||||
2048 0.187 0.187 0.188 17306
|
||||
4095 0.229 0.200 0.194 16761
|
||||
4096 0.162 0.170 0.167 19438
|
||||
8191 0.182 0.173 0.178 18266
|
||||
8192 0.162 0.155 0.158 20560
|
||||
16383 0.156 0.162 0.154 21136
|
||||
16384 0.156 0.156 0.148 22005
|
||||
32767 0.163 0.149 0.149 21768
|
||||
32768 0.150 0.146 0.145 22491
|
||||
65535 0.158 0.141 0.141 23102
|
||||
65536 0.149 0.140 0.138 23478
|
||||
131071 0.150 0.145 0.141 23011
|
||||
131072 0.148 0.141 0.148 21892
|
||||
262143 0.151 0.148 0.147 22136
|
||||
262144 0.149 0.146 0.146 22298
|
||||
524287 0.150 0.149 0.149 21832
|
||||
524288 0.148 0.148 0.147 22043
|
||||
1048575 0.148 0.158 0.163 19913
|
||||
1048576 0.156 0.179 0.153 21186
|
||||
2097151 0.153 0.149 0.148 21979
|
||||
2097152 0.147 0.148 0.147 22040
|
||||
4194303 0.148 0.148 0.151 21482
|
||||
4194304 0.148 0.148 0.147 22061
|
||||
8388607 0.185 0.183 0.185 17536
|
||||
8388608 0.193 0.180 0.183 17769
|
||||
|
||||
crc32() w/ 10+ year old cpus for #c per n where c ≈ 0.293ns
|
||||
N x1 x8 x64 mBps
|
||||
------------------------------------------------------------
|
||||
1 4447.000 43.625 37.641 86
|
||||
1 41.000 37.125 37.609 86
|
||||
2 31.500 26.562 22.477 145
|
||||
3 25.000 20.125 17.422 187
|
||||
4 21.250 16.594 15.230 213
|
||||
7 16.714 13.089 11.717 277
|
||||
8 16.875 12.609 11.174 291
|
||||
15 12.733 9.958 9.339 348
|
||||
16 12.438 9.852 9.208 353
|
||||
31 10.935 8.617 8.164 398
|
||||
32 10.906 8.496 8.155 399
|
||||
63 9.095 7.819 7.692 423
|
||||
64 9.172 7.807 7.692 423
|
||||
127 8.165 7.531 7.438 437
|
||||
128 8.133 7.503 7.437 437
|
||||
255 7.714 7.329 7.293 446
|
||||
256 7.723 7.348 7.293 446
|
||||
511 7.434 7.253 7.223 450
|
||||
512 7.412 7.237 7.218 450
|
||||
1023 7.274 7.214 7.201 451
|
||||
1024 7.292 7.203 7.189 452
|
||||
2047 7.232 7.185 7.178 453
|
||||
2048 7.239 7.189 7.186 452
|
||||
4095 7.189 7.175 7.172 453
|
||||
4096 7.192 7.173 7.172 453
|
||||
8191 7.187 7.173 7.172 453
|
||||
8192 7.183 7.174 7.181 453
|
||||
16383 7.175 7.170 7.169 453
|
||||
16384 7.176 7.169 7.169 453
|
||||
32767 7.169 7.182 7.170 453
|
||||
32768 7.173 7.172 7.172 453
|
||||
65535 7.170 7.170 7.171 453
|
||||
65536 7.172 7.171 7.204 451
|
||||
131071 7.170 7.354 7.260 448
|
||||
131072 7.172 7.172 7.182 453
|
||||
262143 7.037 7.178 7.182 453
|
||||
262144 7.169 7.343 7.205 451
|
||||
524287 7.438 7.170 7.206 451
|
||||
524288 7.169 7.164 7.209 451
|
||||
1048575 6.995 7.119 7.158 454
|
||||
1048576 7.168 7.110 7.157 454
|
||||
2097151 7.057 7.058 7.065 460
|
||||
2097152 6.977 7.047 7.089 458
|
||||
4194303 7.017 7.504 7.030 462
|
||||
4194304 7.025 7.059 7.030 462
|
||||
8388607 7.082 6.980 6.997 464
|
||||
8388608 7.051 6.985 6.999 464 */
|
||||
.yoink __FILE__
|
30
libc/nexgen32e/crc32.S
Normal file
30
libc/nexgen32e/crc32.S
Normal file
|
@ -0,0 +1,30 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
/ Computes Phil Katz CRC-32 used by zip/zlib/gzip/etc.
|
||||
/
|
||||
/ @param edi is init crc32 value
|
||||
/ @param rsi is nullable pointer to data
|
||||
/ @param edx is int size per zlib interface
|
||||
crc32: movslq %edx,%rdx
|
||||
jmp crc32_z
|
||||
.endfn crc32,globl
|
||||
.yoink __FILE__
|
79
libc/nexgen32e/crc32c-pure.c
Normal file
79
libc/nexgen32e/crc32c-pure.c
Normal file
|
@ -0,0 +1,79 @@
|
|||
/*-*- 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/str/internal.h"
|
||||
|
||||
/**
|
||||
* Computes Castagnoli CRC-32 on old computers.
|
||||
*/
|
||||
uint32_t crc32c$pure(uint32_t init, const void *data, size_t size) {
|
||||
extern const uint32_t kCrc32cTab[256];
|
||||
const unsigned char *p = data;
|
||||
uint32_t h = init ^ 0xffffffff;
|
||||
unsigned i;
|
||||
for (i = 0; i < size; i++) {
|
||||
h = h >> 8 ^ kCrc32cTab[(h & 0xff) ^ p[i]];
|
||||
}
|
||||
return h ^ 0xffffffff;
|
||||
}
|
||||
|
||||
/*
|
||||
bench_crc32c$pure for #c per n where c ≈ 0.293ns
|
||||
N x1 x8 x64 mBps
|
||||
------------------------------------------------------------
|
||||
1 4305.000 91.375 44.203 74
|
||||
1 75.000 55.875 44.703 73
|
||||
2 46.500 35.188 24.617 132
|
||||
3 40.333 26.625 19.193 169
|
||||
4 32.250 19.969 16.215 200
|
||||
7 18.429 15.089 12.033 270
|
||||
8 20.625 13.547 11.607 280
|
||||
15 15.667 10.775 9.589 339
|
||||
16 17.562 10.695 9.419 345
|
||||
31 12.226 8.891 8.317 391
|
||||
32 13.219 8.480 8.078 402
|
||||
63 9.571 8.065 7.731 420
|
||||
64 9.672 7.955 7.633 426
|
||||
127 8.433 7.548 7.329 443
|
||||
128 8.492 7.528 7.352 442
|
||||
255 7.557 7.366 7.239 449
|
||||
256 7.699 7.342 7.305 445
|
||||
511 7.376 7.243 7.223 450
|
||||
512 7.408 7.233 7.225 450
|
||||
1023 7.188 7.192 7.098 458
|
||||
1024 7.171 7.194 7.097 458
|
||||
2047 7.130 7.172 7.085 459
|
||||
2048 7.117 7.170 7.169 453
|
||||
4095 7.063 7.076 7.085 459
|
||||
4096 7.078 7.161 7.081 459
|
||||
8191 7.041 7.095 7.055 461
|
||||
8192 7.051 7.098 7.087 459
|
||||
16383 7.039 7.114 7.067 460
|
||||
16384 6.876 6.931 7.133 456
|
||||
32767 7.055 7.108 7.290 446
|
||||
32768 6.868 6.887 6.974 466
|
||||
65535 6.984 6.885 6.967 467
|
||||
65536 6.877 6.924 10.994 296
|
||||
131071 7.166 7.141 7.011 464
|
||||
131072 6.853 6.971 7.694 422
|
||||
262143 6.853 7.213 7.406 439
|
||||
262144 6.852 6.968 7.290 446
|
||||
524287 7.398 7.389 7.166 454
|
||||
524288 6.851 7.094 7.159 454
|
||||
*/
|
96
libc/nexgen32e/crc32c-sse42.c
Normal file
96
libc/nexgen32e/crc32c-sse42.c
Normal file
|
@ -0,0 +1,96 @@
|
|||
/*-*- 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/str/internal.h"
|
||||
|
||||
/**
|
||||
* Hashes data with hardware acceleration at 10GBps.
|
||||
* @note needs Nehalem+ c. 2008 or Bulldozer+ c. 2011
|
||||
*/
|
||||
uint32_t crc32c$sse42(uint32_t init, const void *data, size_t size) {
|
||||
const unsigned char *p = (const unsigned char *)data;
|
||||
const unsigned char *pe = (const unsigned char *)data + size;
|
||||
uint32_t h = init ^ 0xffffffff;
|
||||
if (size >= 16 + 8) {
|
||||
while ((uintptr_t)p & 7) asm("crc32b\t%1,%0" : "+r"(h) : "rm"(*p++));
|
||||
uint64_t hl = h;
|
||||
while (p < pe - 16ul) {
|
||||
asm("crc32q\t%1,%0" : "+r"(hl) : "rm"(*(const uint64_t *)p));
|
||||
p += 8;
|
||||
asm("crc32q\t%1,%0" : "+r"(hl) : "rm"(*(const uint64_t *)p));
|
||||
p += 8;
|
||||
}
|
||||
h = (uint32_t)hl;
|
||||
}
|
||||
while (p < pe) asm("crc32b\t%1,%0" : "+r"(h) : "rm"(*p++));
|
||||
return h ^ 0xffffffff;
|
||||
}
|
||||
|
||||
/*
|
||||
bench_crc32c$sse42 for #c per n where c ≈ 0.293ns
|
||||
N x1 x8 x64 mBps
|
||||
------------------------------------------------------------
|
||||
1 877.000 43.375 40.359 81
|
||||
1 45.000 39.625 40.484 80
|
||||
2 34.500 27.562 20.461 159
|
||||
3 23.000 16.708 14.245 228
|
||||
4 18.250 13.094 11.449 284
|
||||
7 10.429 8.339 8.185 397
|
||||
8 42.125 8.734 6.850 475
|
||||
15 9.400 5.375 4.884 665
|
||||
16 7.312 5.070 4.882 666
|
||||
31 5.258 2.923 2.680 1213
|
||||
32 3.969 2.676 2.562 1269
|
||||
63 3.095 1.581 1.428 2276
|
||||
64 2.234 1.623 1.478 2199
|
||||
127 1.205 0.901 0.900 3610
|
||||
128 1.164 0.960 0.915 3552
|
||||
255 0.922 0.651 0.618 5260
|
||||
256 0.715 0.650 0.609 5341
|
||||
511 0.558 0.482 0.477 6819
|
||||
512 0.529 0.475 0.469 6932
|
||||
1023 0.425 0.400 0.396 8204
|
||||
1024 0.417 0.392 0.388 8383
|
||||
2047 0.367 0.355 0.353 9199
|
||||
2048 0.374 0.366 0.364 8929
|
||||
4095 0.351 0.338 0.337 9644
|
||||
4096 0.353 0.338 0.338 9624
|
||||
8191 0.335 0.338 0.337 9641
|
||||
8192 0.335 0.329 0.329 9870
|
||||
16383 0.336 0.325 0.325 10011
|
||||
16384 0.336 0.326 0.375 8666
|
||||
32767 0.329 0.323 0.323 10070
|
||||
32768 0.327 0.324 0.323 10062
|
||||
65535 0.322 0.322 0.322 10103
|
||||
65536 0.321 0.322 0.322 10102
|
||||
131071 0.322 0.321 0.321 10125
|
||||
131072 0.321 0.321 0.321 10124
|
||||
262143 0.322 0.321 0.335 9699
|
||||
262144 0.321 0.321 0.321 10134
|
||||
524287 0.321 0.321 0.499 6516
|
||||
524288 0.321 0.321 0.339 9575
|
||||
1048575 0.322 0.321 0.322 10095
|
||||
1048576 0.320 1.001 0.323 10048
|
||||
2097151 0.325 0.321 0.322 10086
|
||||
2097152 0.330 0.320 0.323 10076
|
||||
4194303 0.331 0.322 0.321 10128
|
||||
4194304 0.332 0.321 0.325 10004
|
||||
8388607 0.334 0.332 0.331 9829
|
||||
8388608 0.334 0.329 0.327 9934
|
||||
*/
|
46
libc/nexgen32e/crc32c.S
Normal file
46
libc/nexgen32e/crc32c.S
Normal file
|
@ -0,0 +1,46 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/dce.h"
|
||||
#include "libc/macros.h"
|
||||
#include "libc/nexgen32e/x86feature.h"
|
||||
#include "libc/notice.inc"
|
||||
|
||||
/ Computes 32-bit Castagnoli Cyclic Redundancy Check.
|
||||
/
|
||||
/ @param edi is the initial hash value (0 is fine)
|
||||
/ @param rsi points to the data
|
||||
/ @param rdx is the byte size of data
|
||||
/ @return eax is the new hash value
|
||||
/ @note Used by ISCSI, TensorFlow, etc.
|
||||
.initbss 300,_init_crc32c
|
||||
crc32c: .quad 0
|
||||
.endobj crc32c,globl
|
||||
.previous
|
||||
|
||||
.init.start 300,_init_crc32c
|
||||
ezlea crc32c$pure,ax
|
||||
#if !IsTiny()
|
||||
ezlea crc32c$sse42,cx
|
||||
testb X86_HAVE(SSE4_2)+kCpuids(%rip)
|
||||
cmovnz %rcx,%rax
|
||||
#endif
|
||||
stosq
|
||||
.init.end 300,_init_crc32c
|
||||
.yoink __FILE__
|
72
libc/nexgen32e/crc32init.S
Normal file
72
libc/nexgen32e/crc32init.S
Normal file
|
@ -0,0 +1,72 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
.text.startup
|
||||
|
||||
/ Generates lookup table for computing CRC-32 byte-by-byte.
|
||||
/
|
||||
/ void crc32init(uint32_t table[256], uint32_t polynomial) {
|
||||
/ uint32_t d, i, r;
|
||||
/ for (d = 0; d < 256; ++d) {
|
||||
/ r = d;
|
||||
/ for (i = 0; i < 8; ++i) {
|
||||
/ r = r >> 1 ^ (r & 1 ? polynomial : 0);
|
||||
/ }
|
||||
/ table[d] = r;
|
||||
/ }
|
||||
/ }
|
||||
/
|
||||
/ @param rdi is pointer to uint32_t[256] array
|
||||
/ @param esi 32-bit binary polynomial config
|
||||
/ @note imposes ~300ns one-time cost
|
||||
crc32init:
|
||||
push %rbp
|
||||
mov %rsp,%rbp
|
||||
.profilable
|
||||
lea 256*4(%rdi),%rdx
|
||||
movd %esi,%xmm0
|
||||
pshufd $0,%xmm0,%xmm0 # (uint32_t[]){esi,esi,esi,esi} → %xmm0
|
||||
pushpop 4,%rax
|
||||
movd %eax,%xmm2 # (int[]){4,4,4,4} → %xmm2
|
||||
pshufd $0,%xmm2,%xmm2
|
||||
0: sub $4,%rsp # (int[]){0,1,2,3} → %xmm1
|
||||
dec %eax
|
||||
mov %eax,(%rsp)
|
||||
jnz 0b
|
||||
movups (%rsp),%xmm1
|
||||
1: mov $8,%ecx
|
||||
movdqa %xmm1,%xmm3
|
||||
2: movdqa %xmm3,%xmm4
|
||||
psrld $1,%xmm4
|
||||
pslld $31,%xmm3
|
||||
psrad $31,%xmm3
|
||||
pand %xmm0,%xmm3
|
||||
pxor %xmm4,%xmm3
|
||||
movdqa %xmm3,%xmm4
|
||||
loop 2b
|
||||
movdqu %xmm3,(%rdi)
|
||||
add $16,%rdi
|
||||
paddd %xmm2,%xmm1
|
||||
cmp %rdx,%rdi
|
||||
jb 1b
|
||||
leave
|
||||
ret
|
||||
.endfn crc32init,globl
|
||||
.yoink __FILE__
|
48
libc/nexgen32e/crc32z.c
Normal file
48
libc/nexgen32e/crc32z.c
Normal file
|
@ -0,0 +1,48 @@
|
|||
/*-*- 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/safemacros.h"
|
||||
#include "libc/nexgen32e/x86feature.h"
|
||||
#include "libc/str/internal.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
/**
|
||||
* Computes Phil Katz CRC-32 used by zip/zlib/gzip/etc.
|
||||
*/
|
||||
uint32_t crc32_z(uint32_t h, const void *data, size_t size) {
|
||||
const unsigned char *p, *pe;
|
||||
size_t skip;
|
||||
if (data) {
|
||||
h ^= 0xffffffff;
|
||||
if (size >= 64 && X86_HAVE(PCLMUL)) {
|
||||
h = crc32$pclmul(h, data, size); /* 51x faster */
|
||||
skip = rounddown(size, 16);
|
||||
} else {
|
||||
skip = 0;
|
||||
}
|
||||
p = (const unsigned char *)data + skip;
|
||||
pe = (const unsigned char *)data + size;
|
||||
while (p < pe) {
|
||||
h = h >> 8 ^ kCrc32Tab[(h & 0xff) ^ *p++];
|
||||
}
|
||||
return h ^ 0xffffffff;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
101
libc/nexgen32e/ctype.S
Normal file
101
libc/nexgen32e/ctype.S
Normal file
|
@ -0,0 +1,101 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
/ Returns nonzero if %dil ∈ [ \t\v\r\n].
|
||||
/
|
||||
/ @param edi is character to test (treated as uint8_t)
|
||||
/ @return nonzero if character matches, otherwise 0
|
||||
isspace:push $1
|
||||
jmp ctypep
|
||||
.endfn isspace,globl
|
||||
|
||||
/ Returns nonzero if %dil ∈ [A-Za-z].
|
||||
/
|
||||
/ @param edi is character to test (treated as uint8_t)
|
||||
/ @return nonzero if character matches, otherwise 0
|
||||
isalpha:push $2
|
||||
jmp ctypep
|
||||
.endfn isalpha,globl
|
||||
|
||||
/ Returns nonzero if %dil ∈ [0-9].
|
||||
/
|
||||
/ @param edi is character to test (treated as uint8_t)
|
||||
/ @return nonzero if character matches, otherwise 0
|
||||
isdigit:push $4
|
||||
jmp ctypep
|
||||
.endfn isdigit,globl
|
||||
|
||||
/ Returns nonzero if %dil ∈ [0-9A-Za-z].
|
||||
/
|
||||
/ @param edi is character to test (treated as uint8_t)
|
||||
/ @return nonzero if character matches, otherwise 0
|
||||
isalnum:push $6
|
||||
jmp ctypep
|
||||
.endfn isalnum,globl
|
||||
|
||||
/ Returns nonzero if %dil ∈ [0-9A-fa-f].
|
||||
/
|
||||
/ @param edi is character to test (treated as uint8_t)
|
||||
/ @return nonzero if character matches, otherwise 0
|
||||
isxdigit:push $8
|
||||
jmp ctypep
|
||||
.endfn isxdigit,globl
|
||||
|
||||
/ Returns nonzero if %dil ∈ [ -~] a.k.a. [\x20-\x7e].
|
||||
/
|
||||
/ @param edi is character to test (treated as uint8_t)
|
||||
/ @return nonzero if character matches, otherwise 0
|
||||
isprint:push $16
|
||||
jmp ctypep
|
||||
.endfn isprint,globl
|
||||
|
||||
/ Returns nonzero if %dil ∈ [a-z]
|
||||
/
|
||||
/ @param edi is character to test (treated as uint8_t)
|
||||
/ @return nonzero if character matches, otherwise 0
|
||||
islower:push $32
|
||||
jmp ctypep
|
||||
.endfn islower,globl
|
||||
|
||||
/ Returns nonzero if %dil ∈ [A-Z]
|
||||
/
|
||||
/ @param edi is character to test (treated as uint8_t)
|
||||
/ @return nonzero if character matches, otherwise 0
|
||||
isupper:push $64
|
||||
jmp ctypep
|
||||
.endfn isupper,globl
|
||||
|
||||
/ Returns nonzero if %dil ∈ [ \t]
|
||||
/
|
||||
/ @param edi is character to test (treated as uint8_t)
|
||||
/ @return nonzero if character matches, otherwise 0
|
||||
isblank:push $-128
|
||||
/ fallthrough
|
||||
.endfn isblank,globl
|
||||
|
||||
ctypep: pop %rsi
|
||||
movzbl %dil,%edi
|
||||
ezlea kCtype,cx
|
||||
movzbl (%rcx,%rdi),%eax
|
||||
and %esi,%eax
|
||||
ret
|
||||
.endfn ctypep
|
||||
.yoink __FILE__
|
119
libc/nexgen32e/div10.greg.S
Normal file
119
libc/nexgen32e/div10.greg.S
Normal file
|
@ -0,0 +1,119 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
/ Performs 128-bit div+mod by 10 without using div or mod.
|
||||
/
|
||||
/ If we didn't have this one-off function, our palandprintf()
|
||||
/ implementation would cause nearly everything to need a soft
|
||||
/ math library. It also somehow goes faster than 64-bit IDIV.
|
||||
/
|
||||
/ @param rdi:rsi is the number
|
||||
/ @param rdx points to where remainder goes
|
||||
/ @return rax:rdx is result of division
|
||||
/ @see “Division by Invariant Integers using Multiplication”
|
||||
/ @see llog10() and div10int64() is a tiny bit faster
|
||||
div10: .leafprologue
|
||||
.profilable
|
||||
push %rbx
|
||||
mov %rdx,%r8
|
||||
test %rsi,%rsi
|
||||
je 1f
|
||||
bsr %rsi,%r10
|
||||
xor $63,%r10d
|
||||
mov $125,%r9d
|
||||
sub %r10d,%r9d
|
||||
cmp $64,%r9d
|
||||
jne 6f
|
||||
xor %eax,%eax
|
||||
xor %r11d,%r11d
|
||||
jmp 9f
|
||||
1: test %r8,%r8
|
||||
je 3f
|
||||
movabs $0xcccccccccccccccd,%rcx
|
||||
mov %rdi,%rax
|
||||
mul %rcx
|
||||
shr $3,%rdx
|
||||
add %edx,%edx
|
||||
lea (%rdx,%rdx,4),%eax
|
||||
mov %edi,%ecx
|
||||
sub %eax,%ecx
|
||||
mov %ecx,(%r8)
|
||||
3: movabs $0xcccccccccccccccd,%rcx
|
||||
mov %rdi,%rax
|
||||
mul %rcx
|
||||
mov %rdx,%rax
|
||||
shr $3,%rax
|
||||
xor %edi,%edi
|
||||
jmp 14f
|
||||
6: mov %r9d,%ecx
|
||||
neg %cl
|
||||
cmp $62,%r10d
|
||||
jb 8f
|
||||
mov %rdi,%rdx
|
||||
shl %cl,%rdx
|
||||
mov %rsi,%rax
|
||||
mov %r9d,%ecx
|
||||
shr %cl,%rax
|
||||
shrd %cl,%rsi,%rdi
|
||||
xor %r11d,%r11d
|
||||
mov %rdi,%rsi
|
||||
mov %rdx,%rdi
|
||||
jmp 9f
|
||||
8: mov %rdi,%r11
|
||||
shl %cl,%r11
|
||||
mov %rsi,%rax
|
||||
shl %cl,%rax
|
||||
mov %r9d,%ecx
|
||||
shr %cl,%rdi
|
||||
or %rax,%rdi
|
||||
shr %cl,%rsi
|
||||
xor %eax,%eax
|
||||
9: add $-125,%r10d
|
||||
xor %ecx,%ecx
|
||||
mov $9,%r9d
|
||||
10: shld $1,%rsi,%rax
|
||||
shld $1,%rdi,%rsi
|
||||
shld $1,%r11,%rdi
|
||||
mov %r11,%rdx
|
||||
add %r11,%rdx
|
||||
mov %rcx,%r11
|
||||
or %rdx,%r11
|
||||
cmp %rsi,%r9
|
||||
mov $0,%ebx
|
||||
sbb %rax,%rbx
|
||||
sar $63,%rbx
|
||||
mov %ebx,%ecx
|
||||
and $1,%ecx
|
||||
and $10,%ebx
|
||||
sub %rbx,%rsi
|
||||
sbb $0,%rax
|
||||
inc %r10d
|
||||
jne 10b
|
||||
test %r8,%r8
|
||||
je 13f
|
||||
mov %esi,(%r8)
|
||||
13: lea (%rcx,%r11,2),%rax
|
||||
shld $1,%rdx,%rdi
|
||||
14: mov %rdi,%rdx
|
||||
pop %rbx
|
||||
.leafepilogue
|
||||
.endfn div10,globl,hidden
|
||||
.yoink __FILE__
|
32
libc/nexgen32e/div1000000000int64.greg.S
Normal file
32
libc/nexgen32e/div1000000000int64.greg.S
Normal file
|
@ -0,0 +1,32 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
/ Divides 64-bit integer by 1,000,000,000.
|
||||
/
|
||||
/ @param rdi is number to divide
|
||||
/ @return truncated numerator
|
||||
div1000000000int64:
|
||||
mov $0x1a,%cl
|
||||
movabs $0x112e0be826d694b3,%rdx
|
||||
jmp tinydivsi
|
||||
.globl tinydivsi
|
||||
.endfn div1000000000int64,globl
|
||||
.yoink __FILE__
|
31
libc/nexgen32e/div1000000int64.greg.S
Normal file
31
libc/nexgen32e/div1000000int64.greg.S
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
/ Divides 64-bit integer by 1,000,000.
|
||||
/
|
||||
/ @param rdi is number to divide
|
||||
/ @return truncated numerator
|
||||
div1000000int64:
|
||||
mov $0x12,%cl
|
||||
movabs $0x431bde82d7b634db,%rdx
|
||||
jmp tinydivsi
|
||||
.endfn div1000000int64,globl
|
||||
.yoink __FILE__
|
31
libc/nexgen32e/div1000int64.greg.S
Normal file
31
libc/nexgen32e/div1000int64.greg.S
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
/ Divides 64-bit integer by 1,000.
|
||||
/
|
||||
/ @param rdi is number to divide
|
||||
/ @return truncated numerator
|
||||
div1000int64:
|
||||
mov $0x7,%cl
|
||||
movabs $0x20c49ba5e353f7cf,%rdx
|
||||
jmp tinydivsi
|
||||
.endfn div1000int64,globl
|
||||
.yoink __FILE__
|
31
libc/nexgen32e/div10int64.greg.S
Normal file
31
libc/nexgen32e/div10int64.greg.S
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
/ Divides 64-bit integer by 10.
|
||||
/
|
||||
/ @param rdi is number to divide
|
||||
/ @return truncated numerator
|
||||
div10int64:
|
||||
mov $0x2,%cl
|
||||
movabs $0x6666666666666667,%rdx
|
||||
jmp tinydivsi
|
||||
.endfn div10int64,globl
|
||||
.yoink __FILE__
|
1
libc/nexgen32e/doc/README.txt
Normal file
1
libc/nexgen32e/doc/README.txt
Normal file
|
@ -0,0 +1 @@
|
|||
These files aren't intended to be compiled.
|
56
libc/nexgen32e/doc/cescapec.c
Normal file
56
libc/nexgen32e/doc/cescapec.c
Normal file
|
@ -0,0 +1,56 @@
|
|||
/*-*- 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/str/internal.h"
|
||||
|
||||
unsigned cescapec(int c) {
|
||||
unsigned char ch = c;
|
||||
switch (ch) {
|
||||
case '\a':
|
||||
return '\\' | 'a' << 8;
|
||||
case '\b':
|
||||
return '\\' | 'b' << 8;
|
||||
case '\v':
|
||||
return '\\' | 'v' << 8;
|
||||
case '\f':
|
||||
return '\\' | 'f' << 8;
|
||||
case '\?':
|
||||
return '\\' | '?' << 8;
|
||||
case '\n':
|
||||
return '\\' | 'n' << 8;
|
||||
case '\r':
|
||||
return '\\' | 'r' << 8;
|
||||
case '\t':
|
||||
return '\\' | 't' << 8;
|
||||
case '\"':
|
||||
return '\\' | '"' << 8;
|
||||
case '\'':
|
||||
return '\\' | '\'' << 8;
|
||||
case '\\':
|
||||
return '\\' | '\\' << 8;
|
||||
default: {
|
||||
if (ch >= 0x80 || !isprint(ch)) {
|
||||
return '\\' | (ch / 64 + '0') << 8 | (ch % 64 / 8 + '0') << 16 |
|
||||
(ch % 8 + '0') << 24;
|
||||
} else {
|
||||
return ch;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
57
libc/nexgen32e/doc/memrchr.c
Normal file
57
libc/nexgen32e/doc/memrchr.c
Normal file
|
@ -0,0 +1,57 @@
|
|||
/*-*- 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/dce.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
#define N 32
|
||||
typedef uint8_t uint8_v _Vector_size(N);
|
||||
|
||||
/**
|
||||
* Searches for last instance of character in memory region.
|
||||
*
|
||||
* @param s is binary data to search
|
||||
* @param c is treated as unsigned char
|
||||
* @param n is byte length of s
|
||||
* @return address of last c in s, or NULL if not found
|
||||
*/
|
||||
void *memrchr(const void *s, int c, size_t n) {
|
||||
unsigned char ch = (unsigned char)c;
|
||||
const unsigned char *p = (const unsigned char *)s;
|
||||
if (n >= 32 && CheckAvx2()) {
|
||||
uint8_v cv;
|
||||
__builtin_memset(&cv, ch, sizeof(cv));
|
||||
do {
|
||||
uint32_t skip;
|
||||
uint8_v sv, tv;
|
||||
memcpy(&sv, s + n - N, N);
|
||||
asm("vpcmpeqb\t%2,%3,%1\n\t"
|
||||
"vpmovmskb\t%1,%0\n\t"
|
||||
"lzcnt\t%0,%0"
|
||||
: "=r"(skip), "=x"(tv)
|
||||
: "x"(sv), "x"(cv));
|
||||
n -= skip;
|
||||
if (skip != 32) break;
|
||||
} while (n >= 32);
|
||||
}
|
||||
while (n--) {
|
||||
if (p[n] == ch) return (/* unconst */ void *)&p[n];
|
||||
}
|
||||
return NULL;
|
||||
}
|
62
libc/nexgen32e/doc/strcmp-avx2.c
Normal file
62
libc/nexgen32e/doc/strcmp-avx2.c
Normal file
|
@ -0,0 +1,62 @@
|
|||
/*-*- 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/bits.h"
|
||||
#include "libc/str/internal.h"
|
||||
|
||||
#define kVectorSize 32 /* x86+avx2 is 256-bit cpu */
|
||||
|
||||
typedef uint8_t uint8_v _Vector_size(kVectorSize);
|
||||
typedef uint32_t vbitmask_t;
|
||||
|
||||
/**
|
||||
* Returns how many bytes the utf16 string would be as utf8.
|
||||
*/
|
||||
int strcmp$avx2(const char *s1, const char *s2) {
|
||||
if (s1 == s2) return 0;
|
||||
const unsigned char *p1 = (const unsigned char *)s1;
|
||||
const unsigned char *p2 = (const unsigned char *)s2;
|
||||
size_t i = -kVectorSize;
|
||||
vLoop:
|
||||
i += kVectorSize;
|
||||
bLoop:
|
||||
if (!IsPointerDangerous(p1 + i) && !IsPointerDangerous(p2 + i)) {
|
||||
unsigned char zf;
|
||||
vbitmask_t r1;
|
||||
uint8_v v1, v2;
|
||||
const uint8_v kZero = {0};
|
||||
asm(ZFLAG("vmovdqu\t%5,%2\n\t" /* move because gcc problematic */
|
||||
"vpcmpeqb\t%4,%2,%1\n\t" /* check for equality in p1 and p2 */
|
||||
"vpcmpeqb\t%6,%2,%2\n\t" /* check for nul in p1 */
|
||||
"vpandn\t%7,%1,%2\n\t" /* most complicated bitwise not ever */
|
||||
"vpor\t%2,%1,%1\n\t" /* check for nul in p2 */
|
||||
"pmovmskb\t%1,%3\n\t" /* turn 256 bits into 32 bits */
|
||||
"bsf\t%3,%3") /* find stop byte */
|
||||
: ZF(zf), "=x"(v1), "=x"(v2), "=r"(r1)
|
||||
: "m"(*(const uint8_v *)(p1 + i)), "m"(*(const uint8_v *)(p2 + i)),
|
||||
"x"(kZero), "m"(kVectorSize));
|
||||
if (zf) goto vLoop;
|
||||
return p1[i + r1] - p2[i + r1];
|
||||
} else {
|
||||
i += 1;
|
||||
int c;
|
||||
if (!(c = p1[i - 1] - p2[i - 1]) && p1[i - 1] + p1[i - 1] != 0) goto bLoop;
|
||||
return c;
|
||||
}
|
||||
}
|
33
libc/nexgen32e/environ.S
Normal file
33
libc/nexgen32e/environ.S
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
#include "libc/notice.inc"
|
||||
|
||||
/ Environment variable pointer list.
|
||||
.bss
|
||||
.align 8
|
||||
environ:.quad 0
|
||||
.endobj environ,globl
|
||||
.previous
|
||||
|
||||
.init.start 300,_init_environ
|
||||
mov %r14,environ(%rip)
|
||||
.init.end 300,_init_environ
|
||||
.yoink __FILE__
|
50
libc/nexgen32e/explicit_bzero.S
Normal file
50
libc/nexgen32e/explicit_bzero.S
Normal file
|
@ -0,0 +1,50 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
/ Sets memory to zero w/ accompanying non-optimizing macro.
|
||||
/
|
||||
/ This is intended for security-conscious applications. This
|
||||
/ implementation also hoses every register the abi allows. A
|
||||
/ concomitant prototype (str.h) countermands compiler magic.
|
||||
/
|
||||
/ @param rdi is dest
|
||||
/ @param rsi is the number of bytes to set
|
||||
explicit_bzero:
|
||||
.leafprologue
|
||||
mov %rsi,%rcx
|
||||
xor %eax,%eax
|
||||
rep stosb
|
||||
xor %edx,%edx
|
||||
xor %edi,%edi
|
||||
xor %esi,%esi
|
||||
xor %r8,%r8
|
||||
xor %r9,%r9
|
||||
xor %r10,%r10
|
||||
xor %r11,%r11
|
||||
xorps %xmm0,%xmm0
|
||||
xorps %xmm1,%xmm1
|
||||
xorps %xmm2,%xmm2
|
||||
xorps %xmm3,%xmm3
|
||||
xorps %xmm4,%xmm4
|
||||
xorps %xmm5,%xmm5
|
||||
.leafepilogue
|
||||
.endfn explicit_bzero,globl
|
||||
.yoink __FILE__
|
47
libc/nexgen32e/ffs.S
Normal file
47
libc/nexgen32e/ffs.S
Normal file
|
@ -0,0 +1,47 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
/ Finds lowest set bit in word.
|
||||
/
|
||||
/ @param edi is the input number
|
||||
/ @return number in range [1,32] or 0 if no bits set
|
||||
/ @see also treasure trove of nearly identical functions
|
||||
/
|
||||
/ uint32 𝑥 bsf(𝑥) tzcnt(𝑥) ffs(𝑥) bsr(𝑥) lzcnt(𝑥)
|
||||
/ 0x00000000 wut 32 0 wut 32
|
||||
/ 0x00000001 0 0 1 0 31
|
||||
/ 0x80000001 0 0 1 31 0
|
||||
/ 0x80000000 31 31 32 31 0
|
||||
/ 0x00000010 4 4 5 4 27
|
||||
/ 0x08000010 4 4 5 27 4
|
||||
/ 0x08000000 27 27 28 27 4
|
||||
/ 0xffffffff 0 0 1 31 0
|
||||
/
|
||||
/ @asyncsignalsafe
|
||||
ffs: .leafprologue
|
||||
.profilable
|
||||
bsf %edi,%eax
|
||||
or $-1,%edx
|
||||
cmovz %edx,%eax
|
||||
inc %eax
|
||||
.leafepilogue
|
||||
.endfn ffs,globl
|
||||
.yoink __FILE__
|
48
libc/nexgen32e/ffsl.S
Normal file
48
libc/nexgen32e/ffsl.S
Normal file
|
@ -0,0 +1,48 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
/ Finds lowest set bit in word.
|
||||
/
|
||||
/ @param rdi is the input number
|
||||
/ @return number in range [1,64] or 0 if no bits set
|
||||
/ @see also treasure trove of nearly identical functions
|
||||
/
|
||||
/ uint32 𝑥 bsf(𝑥) tzcnt(𝑥) ffs(𝑥) bsr(𝑥) lzcnt(𝑥)
|
||||
/ 0x00000000 wut 32 0 wut 32
|
||||
/ 0x00000001 0 0 1 0 31
|
||||
/ 0x80000001 0 0 1 31 0
|
||||
/ 0x80000000 31 31 32 31 0
|
||||
/ 0x00000010 4 4 5 4 27
|
||||
/ 0x08000010 4 4 5 27 4
|
||||
/ 0x08000000 27 27 28 27 4
|
||||
/ 0xffffffff 0 0 1 31 0
|
||||
/
|
||||
/ @asyncsignalsafe
|
||||
ffsl: .leafprologue
|
||||
.profilable
|
||||
bsf %rdi,%rax
|
||||
or $-1,%edx
|
||||
cmovz %edx,%eax
|
||||
inc %eax
|
||||
.leafepilogue
|
||||
.endfn ffsl,globl
|
||||
.alias ffsl,ffsll
|
||||
.yoink __FILE__
|
29
libc/nexgen32e/fpu.h
Normal file
29
libc/nexgen32e/fpu.h
Normal file
|
@ -0,0 +1,29 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_NEXGEN32E_FPU_H_
|
||||
#define COSMOPOLITAN_LIBC_NEXGEN32E_FPU_H_
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
|
||||
/**
|
||||
* Saves FPU state.
|
||||
* @see X86_HAVE(FXSR)
|
||||
*/
|
||||
#define FXSAVE(STATE) \
|
||||
asm volatile("fxsave\t%0" \
|
||||
: "=m"(STATE) \
|
||||
: /* x87/sse */ \
|
||||
: "memory")
|
||||
|
||||
/**
|
||||
* Restores FPU state.
|
||||
* @see X86_HAVE(FXSR)
|
||||
*/
|
||||
#define FXRSTOR(STATE) \
|
||||
asm volatile("fxrstor\t%0" \
|
||||
: /* x87/sse */ \
|
||||
: "m"(STATE) \
|
||||
: "xmm0", "xmm1", "xmm2", "xmm3", "xmm4", "xmm5", "xmm6", \
|
||||
"xmm7", "xmm8", "xmm9", "xmm10", "xmm11", "xmm12", "xmm13", \
|
||||
"xmm14", "xmm15", "st", "st(1)", "st(2)", "st(3)", "st(4)", \
|
||||
"st(5)", "st(6)", "st(7)", "memory", "fpsr", "fpcr")
|
||||
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_NEXGEN32E_FPU_H_ */
|
32
libc/nexgen32e/g_argv.S
Normal file
32
libc/nexgen32e/g_argv.S
Normal file
|
@ -0,0 +1,32 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
#include "libc/notice.inc"
|
||||
|
||||
.initbss 300,_init_g_argv
|
||||
g_argv: .quad 0
|
||||
.endobj g_argv,globl,hidden
|
||||
.previous
|
||||
|
||||
.init.start 300,_init_g_argv
|
||||
mov %r13,%rax
|
||||
stosq
|
||||
.init.end 300,_init_g_argv
|
||||
.yoink __FILE__
|
31
libc/nexgen32e/g_auxv.S
Normal file
31
libc/nexgen32e/g_auxv.S
Normal file
|
@ -0,0 +1,31 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
.initbss 300,_init_g_auxv
|
||||
g_auxv: .quad 0
|
||||
.endobj g_auxv,globl,hidden
|
||||
.previous
|
||||
|
||||
.init.start 300,_init_g_auxv
|
||||
mov %r15,%rax
|
||||
stosq
|
||||
.init.end 300,_init_g_auxv
|
||||
.yoink __FILE__
|
23
libc/nexgen32e/g_runstate.S
Normal file
23
libc/nexgen32e/g_runstate.S
Normal file
|
@ -0,0 +1,23 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
.comm g_runstate,4
|
||||
.yoink __FILE__
|
91
libc/nexgen32e/gc.S
Normal file
91
libc/nexgen32e/gc.S
Normal file
|
@ -0,0 +1,91 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/notice.inc"
|
||||
#define INITIAL_CAPACITY 4
|
||||
|
||||
/ Invokes deferred function calls.
|
||||
/
|
||||
/ This offers behavior similar to std::unique_ptr. Functions
|
||||
/ overwrite their return addresses jumping here, and pushing
|
||||
/ exactly one entry on the shadow stack below. Functions may
|
||||
/ repeat that process multiple times, in which case the body
|
||||
/ of this gadget loops and unwinds as a natural consequence.
|
||||
/
|
||||
/ @param rax,rdx,xmm0,xmm1,st0,st1 is return value
|
||||
/ @see test/libc/runtime/gc_test.c
|
||||
/ <LIMBO>
|
||||
__gc: decq __garbage(%rip)
|
||||
mov __garbage(%rip),%r8
|
||||
mov __garbage+16(%rip),%r9
|
||||
js 9f
|
||||
shl $5,%r8
|
||||
lea (%r9,%r8),%r8
|
||||
mov 8(%r8),%r9
|
||||
mov 16(%r8),%rdi
|
||||
push 24(%r8)
|
||||
/ </LIMBO>
|
||||
push %rbp
|
||||
mov %rsp,%rbp
|
||||
sub $0x40,%rsp
|
||||
push %rax
|
||||
push %rdx
|
||||
fstpl -0x40(%rbp)
|
||||
fstpl -0x30(%rbp)
|
||||
movaps %xmm0,-0x20(%rbp)
|
||||
movaps %xmm1,-0x10(%rbp)
|
||||
call *%r9
|
||||
movaps -0x10(%rbp),%xmm1
|
||||
movaps -0x20(%rbp),%xmm0
|
||||
fldl -0x30(%rbp)
|
||||
fldl -0x40(%rbp)
|
||||
pop %rdx
|
||||
pop %rax
|
||||
leave
|
||||
ret
|
||||
9: call abort
|
||||
.endfn __gc,globl,hidden
|
||||
|
||||
.bss
|
||||
.align 8
|
||||
__garbage:
|
||||
.quad 0 # garbage.i
|
||||
.quad 0 # garbage.n
|
||||
.quad 0 # garbage.p
|
||||
.rept INITIAL_CAPACITY
|
||||
.quad 0 # garbage.p[𝑖].frame
|
||||
.quad 0 # garbage.p[𝑖].fn
|
||||
.quad 0 # garbage.p[𝑖].arg
|
||||
.quad 0 # garbage.p[𝑖].ret
|
||||
.endr
|
||||
.endobj __garbage,globl,hidden
|
||||
.previous
|
||||
|
||||
.init.start 100,_init_garbage
|
||||
push %rdi
|
||||
ezlea __garbage+8,di
|
||||
pushpop INITIAL_CAPACITY,%rax
|
||||
stosq
|
||||
lea 8(%rdi),%rax
|
||||
stosq
|
||||
pop %rdi
|
||||
.init.end 100,_init_garbage
|
||||
.yoink __FILE__
|
24
libc/nexgen32e/gc.h
Normal file
24
libc/nexgen32e/gc.h
Normal file
|
@ -0,0 +1,24 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_NEXGEN32E_GC_H_
|
||||
#define COSMOPOLITAN_LIBC_NEXGEN32E_GC_H_
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
struct StackFrame;
|
||||
|
||||
struct Garbages {
|
||||
size_t i, n;
|
||||
struct Garbage {
|
||||
struct StackFrame *frame;
|
||||
intptr_t fn;
|
||||
intptr_t arg;
|
||||
intptr_t ret;
|
||||
} * p;
|
||||
};
|
||||
|
||||
hidden extern struct Garbages __garbage;
|
||||
|
||||
int64_t __gc(void) hidden;
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_NEXGEN32E_GC_H_ */
|
62
libc/nexgen32e/gclongjmp.S
Normal file
62
libc/nexgen32e/gclongjmp.S
Normal file
|
@ -0,0 +1,62 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
/ Jumps up stack to previous setjmp() invocation.
|
||||
/
|
||||
/ This is the same as longjmp() but also unwinds the stack to free
|
||||
/ memory, etc. that was registered using gc() or defer(). If GC
|
||||
/ isn't linked, this behaves the same as longjmp().
|
||||
/
|
||||
/ @param rdi points to the jmp_buf which must be the same stack
|
||||
/ @param esi is returned by setjmp() invocation (coerced nonzero)
|
||||
/ @assume system five nexgen32e abi conformant
|
||||
/ @see examples/ctrlc.c
|
||||
/ @noreturn
|
||||
gclongjmp:
|
||||
.leafprologue
|
||||
.profilable
|
||||
.weak __garbage
|
||||
lea __garbage(%rip),%r12
|
||||
test %r12,%r12
|
||||
jnz .L.unwind.destructors
|
||||
0: jmp longjmp
|
||||
.L.unwind.destructors:
|
||||
push %rdi
|
||||
push %rsi
|
||||
mov (%r12),%r13 # garbage.i
|
||||
mov 16(%r12),%r14 # garbage.p
|
||||
mov (%rdi),%r15 # jmp_buf[0] is new %rsp
|
||||
shl $5,%r13
|
||||
1: test %r13,%r13
|
||||
jz 2f
|
||||
sub $32,%r13
|
||||
cmp (%r14,%r13),%r15
|
||||
ja 2f
|
||||
mov 8(%r14,%r13),%rax # garbage.p[𝑖].fn
|
||||
mov 16(%r14,%r13),%rdi # garbage.p[𝑖].arg
|
||||
call *%rax
|
||||
decq (%r12)
|
||||
jmp 1b
|
||||
2: pop %rsi
|
||||
pop %rdi
|
||||
jmp 0b
|
||||
.endfn gclongjmp,globl
|
||||
.yoink __FILE__
|
58
libc/nexgen32e/getcachesize.c
Normal file
58
libc/nexgen32e/getcachesize.c
Normal file
|
@ -0,0 +1,58 @@
|
|||
/*-*- 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/assert.h"
|
||||
#include "libc/bits/bits.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/nexgen32e/cachesize.h"
|
||||
#include "libc/nexgen32e/cpuid4.h"
|
||||
|
||||
static unsigned getcachesize$cpuid4(int type, int level) {
|
||||
unsigned i, k;
|
||||
static int once;
|
||||
static unsigned char kCacheKey[8];
|
||||
static unsigned kCacheSize[8];
|
||||
if (!once) {
|
||||
CPUID4_ITERATE(i, {
|
||||
kCacheKey[i] = CPUID4_KEY;
|
||||
kCacheSize[i] = CPUID4_CACHE_SIZE_IN_BYTES;
|
||||
});
|
||||
once = 1;
|
||||
}
|
||||
k = ((level & 7) << 5) | (type & 31);
|
||||
for (i = 0; i < 8; ++i) {
|
||||
if (kCacheKey[i] == k) {
|
||||
return kCacheSize[i];
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns CPU cache size.
|
||||
*
|
||||
* @param type 1=data, 2=instruction, 3=unified
|
||||
* @param level starts at 1
|
||||
* @return size in bytes, or 0 if unknown
|
||||
*/
|
||||
unsigned getcachesize(enum CpuCacheType type, int level) {
|
||||
assert(1 <= type && type <= 3);
|
||||
assert(level >= 1);
|
||||
return getcachesize$cpuid4(type, level);
|
||||
}
|
39
libc/nexgen32e/getx86processormodel.c
Normal file
39
libc/nexgen32e/getx86processormodel.c
Normal file
|
@ -0,0 +1,39 @@
|
|||
/*-*- 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/alg/bisect.h"
|
||||
#include "libc/nexgen32e/x86info.h"
|
||||
|
||||
static int CmpX86ProcModelKey(const struct X86ProcessorModel *a,
|
||||
const struct X86ProcessorModel *b) {
|
||||
return a->key > b->key ? 1 : a->key < b->key ? -1 : 0;
|
||||
}
|
||||
|
||||
/**
|
||||
* Identifies microarchitecture of host processor.
|
||||
*
|
||||
* @param key can be kX86ProcessorModelKey for host info
|
||||
* @see https://en.wikichip.org/wiki/intel/cpuid
|
||||
* @see https://a4lg.com/tech/x86/database/x86-families-and-models.en.html
|
||||
*/
|
||||
const struct X86ProcessorModel *getx86processormodel(short key) {
|
||||
return bisect(&(struct X86ProcessorModel){key}, kX86ProcessorModels,
|
||||
kX86ProcessorModelCount, sizeof(struct X86ProcessorModel),
|
||||
(void *)CmpX86ProcModelKey, NULL);
|
||||
}
|
36
libc/nexgen32e/hascharacter.h
Normal file
36
libc/nexgen32e/hascharacter.h
Normal file
|
@ -0,0 +1,36 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_NEXGEN32E_HASCHARACTER_H_
|
||||
#define COSMOPOLITAN_LIBC_NEXGEN32E_HASCHARACTER_H_
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
|
||||
forceinline bool HasCharacter(char c, const char *s) {
|
||||
unsigned i;
|
||||
for (i = 0; s[i]; ++i) {
|
||||
if (s[i] == c) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
forceinline bool HasCharacter16(char16_t c, const char16_t *s) {
|
||||
unsigned i;
|
||||
for (i = 0; s[i]; ++i) {
|
||||
if (s[i] == c) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
forceinline bool HasCharacterWide(wchar_t c, const wchar_t *s) {
|
||||
unsigned i;
|
||||
for (i = 0; s[i]; ++i) {
|
||||
if (s[i] == c) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_NEXGEN32E_HASCHARACTER_H_ */
|
33
libc/nexgen32e/hextoint.S
Normal file
33
libc/nexgen32e/hextoint.S
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
hextoint:
|
||||
.leafprologue
|
||||
.profilable
|
||||
mov %edi,%eax
|
||||
sar $6,%eax
|
||||
and $1,%eax
|
||||
lea (%rax,%rax,8),%eax
|
||||
add %edi,%eax
|
||||
and $15,%eax
|
||||
.leafepilogue
|
||||
.endfn hextoint,globl
|
||||
.yoink __FILE__
|
29
libc/nexgen32e/identity.S
Normal file
29
libc/nexgen32e/identity.S
Normal file
|
@ -0,0 +1,29 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
#include "libc/notice.inc"
|
||||
|
||||
/ The identity() function.
|
||||
/ @return first argument
|
||||
identity:
|
||||
mov %rdi,%rax
|
||||
ret
|
||||
.endfn identity,globl
|
||||
.yoink __FILE__
|
41
libc/nexgen32e/imapxlatab.S
Normal file
41
libc/nexgen32e/imapxlatab.S
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
.text.startup
|
||||
.align 8
|
||||
|
||||
/ Identity maps 256-byte translation table.
|
||||
/
|
||||
/ @param char (*rdi)[256]
|
||||
/ @speed 90mBps
|
||||
/ @mode long
|
||||
imapxlatab:
|
||||
.leafprologue
|
||||
.profilable
|
||||
pushpop 32,%rcx
|
||||
mov $0x0706050403020100,%rax
|
||||
mov $0x0808080808080808,%rdx
|
||||
.align 8
|
||||
1: stosq
|
||||
add %rdx,%rax
|
||||
loop 1b
|
||||
.leafepilogue
|
||||
.endfn imapxlatab,globl,hidden
|
||||
.yoink __FILE__
|
39
libc/nexgen32e/insertionsort.greg.c
Normal file
39
libc/nexgen32e/insertionsort.greg.c
Normal file
|
@ -0,0 +1,39 @@
|
|||
/*-*- 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/log/log.h"
|
||||
#include "libc/nexgen32e/nexgen32e.h"
|
||||
|
||||
/**
|
||||
* Sorts array of signed 32-bit integers.
|
||||
* @see djbsort()
|
||||
*/
|
||||
textreal void insertionsort(size_t n, int32_t a[n]) {
|
||||
int t;
|
||||
unsigned i, j;
|
||||
for (i = 1; i < n; ++i) {
|
||||
j = i;
|
||||
t = a[i];
|
||||
while (j > 0 && t < a[j - 1]) {
|
||||
a[j] = a[j - 1];
|
||||
--j;
|
||||
}
|
||||
a[j] = t;
|
||||
}
|
||||
}
|
35
libc/nexgen32e/iscntrl.S
Normal file
35
libc/nexgen32e/iscntrl.S
Normal file
|
@ -0,0 +1,35 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
iscntrl:.leafprologue
|
||||
.profilable
|
||||
xor %eax,%eax
|
||||
cmp $255,%edi
|
||||
ja 1f
|
||||
movslq %edi,%rdi
|
||||
ezlea kCtype,cx
|
||||
mov (%rcx,%rdi),%al
|
||||
shr $4,%al
|
||||
xor $1,%eax
|
||||
and $1,%eax
|
||||
1: .leafepilogue
|
||||
.endfn iscntrl,globl
|
||||
.yoink __FILE__
|
38
libc/nexgen32e/isgraph.S
Normal file
38
libc/nexgen32e/isgraph.S
Normal file
|
@ -0,0 +1,38 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
isgraph:.leafprologue
|
||||
.profilable
|
||||
xor %eax,%eax
|
||||
cmp $255,%edi
|
||||
ja 1f
|
||||
movslq %edi,%rax
|
||||
ezlea kCtype,cx
|
||||
mov (%rcx,%rax),%al
|
||||
shr $4,%al
|
||||
mov %eax,%edx
|
||||
xor %eax,%eax
|
||||
cmp $32,%edi
|
||||
setne %al
|
||||
and %edx,%eax
|
||||
1: .leafepilogue
|
||||
.endfn isgraph,globl
|
||||
.yoink __FILE__
|
41
libc/nexgen32e/ispunct.S
Normal file
41
libc/nexgen32e/ispunct.S
Normal file
|
@ -0,0 +1,41 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
/ Checks for printable characters that aren't space / alnum.
|
||||
/
|
||||
/ @param edi is character to test (treated as uint8_t)
|
||||
/ @return nonzero if character matches, otherwise 0
|
||||
ispunct:.leafprologue
|
||||
.profilable
|
||||
xor %eax,%eax
|
||||
cmp $255,%edi
|
||||
ja 1f
|
||||
movslq %edi,%rdi
|
||||
ezlea kCtype,cx
|
||||
mov (%rcx,%rdi),%dl
|
||||
test $16,%dl
|
||||
je 1f
|
||||
xor %eax,%eax
|
||||
and $7,%dl
|
||||
sete %al
|
||||
1: .leafepilogue
|
||||
.endfn ispunct,globl
|
||||
.yoink __FILE__
|
33
libc/nexgen32e/iswalnum.S
Normal file
33
libc/nexgen32e/iswalnum.S
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
iswalnum:
|
||||
.leafprologue
|
||||
.profilable
|
||||
movslq %edi,%rax
|
||||
cmpl $127,%eax
|
||||
ja 1f
|
||||
ezlea kCtype,cx
|
||||
movb (%rcx,%rax),%al
|
||||
andl $6,%eax
|
||||
1: .leafepilogue
|
||||
.endfn iswalnum,globl
|
||||
.yoink __FILE__
|
34
libc/nexgen32e/iswalpha.S
Normal file
34
libc/nexgen32e/iswalpha.S
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
iswalpha:
|
||||
.leafprologue
|
||||
.profilable
|
||||
movslq %edi,%rax
|
||||
cmpl $127,%eax
|
||||
ja 1f
|
||||
ezlea kCtype,cx
|
||||
movb (%rcx,%rax),%al
|
||||
andl $2,%eax
|
||||
movzbl %al,%eax
|
||||
1: .leafepilogue
|
||||
.endfn iswalpha,globl
|
||||
.yoink __FILE__
|
34
libc/nexgen32e/iswblank.S
Normal file
34
libc/nexgen32e/iswblank.S
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
iswblank:
|
||||
.leafprologue
|
||||
.profilable
|
||||
movslq %edi,%rax
|
||||
cmpl $127,%eax
|
||||
ja 1f
|
||||
ezlea kCtype,cx
|
||||
movb (%rcx,%rax),%al
|
||||
andl $-128,%eax
|
||||
movzbl %al,%eax
|
||||
1: .leafepilogue
|
||||
.endfn iswblank,globl
|
||||
.yoink __FILE__
|
35
libc/nexgen32e/iswcntrl.S
Normal file
35
libc/nexgen32e/iswcntrl.S
Normal file
|
@ -0,0 +1,35 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
iswcntrl:
|
||||
.leafprologue
|
||||
.profilable
|
||||
movslq %edi,%rax
|
||||
cmp $127,%eax
|
||||
ja 1f
|
||||
ezlea kCtype,cx
|
||||
mov (%rcx,%rax),%al
|
||||
shr $4,%al
|
||||
xor $1,%eax
|
||||
and $1,%eax
|
||||
1: .leafepilogue
|
||||
.endfn iswcntrl,globl
|
||||
.yoink __FILE__
|
34
libc/nexgen32e/iswdigit.S
Normal file
34
libc/nexgen32e/iswdigit.S
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
iswdigit:
|
||||
.leafprologue
|
||||
.profilable
|
||||
movl %edi,%eax
|
||||
cmpl $127,%edi
|
||||
ja 1f
|
||||
subl $48,%eax
|
||||
cmpl $9,%eax
|
||||
setbe %al
|
||||
movzbl %al,%eax
|
||||
1: .leafepilogue
|
||||
.endfn iswdigit,globl
|
||||
.yoink __FILE__
|
38
libc/nexgen32e/iswgraph.S
Normal file
38
libc/nexgen32e/iswgraph.S
Normal file
|
@ -0,0 +1,38 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
iswgraph:
|
||||
.leafprologue
|
||||
.profilable
|
||||
movl %edi,%eax
|
||||
cmpl $127,%edi
|
||||
ja 1f
|
||||
movslq %edi,%rdx
|
||||
ezlea kCtype,cx
|
||||
movb (%rcx,%rdx),%dl
|
||||
shrb $4,%dl
|
||||
cmpl $32,%edi
|
||||
setne %al
|
||||
movzbl %al,%eax
|
||||
andl %edx,%eax
|
||||
1: .leafepilogue
|
||||
.endfn iswgraph,globl
|
||||
.yoink __FILE__
|
34
libc/nexgen32e/iswlower.S
Normal file
34
libc/nexgen32e/iswlower.S
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
iswlower:
|
||||
.leafprologue
|
||||
.profilable
|
||||
movslq %edi,%rax
|
||||
cmpl $127,%eax
|
||||
ja 1f
|
||||
ezlea kCtype,cx
|
||||
movb (%rcx,%rax),%al
|
||||
andl $32,%eax
|
||||
movzbl %al,%eax
|
||||
1: .leafepilogue
|
||||
.endfn iswlower,globl
|
||||
.yoink __FILE__
|
35
libc/nexgen32e/iswprint.S
Normal file
35
libc/nexgen32e/iswprint.S
Normal file
|
@ -0,0 +1,35 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
iswprint:
|
||||
.leafprologue
|
||||
.profilable
|
||||
movl $1,%eax
|
||||
cmpl $127,%edi
|
||||
ja 1f
|
||||
movslq %edi,%rdi
|
||||
ezlea kCtype,cx
|
||||
movb (%rcx,%rdi),%al
|
||||
shrb $4,%al
|
||||
andl $1,%eax
|
||||
1: .leafepilogue
|
||||
.endfn iswprint,globl
|
||||
.yoink __FILE__
|
39
libc/nexgen32e/iswpunct.S
Normal file
39
libc/nexgen32e/iswpunct.S
Normal file
|
@ -0,0 +1,39 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
iswpunct:
|
||||
.leafprologue
|
||||
.profilable
|
||||
mov $1,%eax
|
||||
cmp $127,%edi
|
||||
ja 1f
|
||||
movslq %edi,%rdi
|
||||
ezlea kCtype,cx
|
||||
mov (%rcx,%rdi),%dl
|
||||
xor %eax,%eax
|
||||
test $16,%dl
|
||||
je 1f
|
||||
xor %eax,%eax
|
||||
and $7,%dl
|
||||
sete %al
|
||||
1: .leafepilogue
|
||||
.endfn iswpunct,globl
|
||||
.yoink __FILE__
|
33
libc/nexgen32e/iswspace.S
Normal file
33
libc/nexgen32e/iswspace.S
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
iswspace:
|
||||
.leafprologue
|
||||
.profilable
|
||||
movslq %edi,%rax
|
||||
cmpl $127,%eax
|
||||
ja 1f
|
||||
ezlea kCtype,cx
|
||||
movb (%rcx,%rax),%al
|
||||
andl $1,%eax
|
||||
1: .leafepilogue
|
||||
.endfn iswspace,globl
|
||||
.yoink __FILE__
|
34
libc/nexgen32e/iswupper.S
Normal file
34
libc/nexgen32e/iswupper.S
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
iswupper:
|
||||
.leafprologue
|
||||
.profilable
|
||||
movslq %edi,%rax
|
||||
cmpl $127,%eax
|
||||
ja 1f
|
||||
ezlea kCtype,cx
|
||||
movb (%rcx,%rax),%al
|
||||
andl $64,%eax
|
||||
movzbl %al,%eax
|
||||
1: .leafepilogue
|
||||
.endfn iswupper,globl
|
||||
.yoink __FILE__
|
34
libc/nexgen32e/iswxdigit.S
Normal file
34
libc/nexgen32e/iswxdigit.S
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
iswxdigit:
|
||||
.leafprologue
|
||||
.profilable
|
||||
movslq %edi,%rax
|
||||
cmpl $127,%eax
|
||||
ja 1f
|
||||
ezlea kCtype,cx
|
||||
movb (%rcx,%rax),%al
|
||||
andl $8,%eax
|
||||
movzbl %al,%eax
|
||||
1: .leafepilogue
|
||||
.endfn iswxdigit,globl
|
||||
.yoink __FILE__
|
47
libc/nexgen32e/kbase36.S
Normal file
47
libc/nexgen32e/kbase36.S
Normal file
|
@ -0,0 +1,47 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
/ Base 36 Decoder Table.
|
||||
/
|
||||
/ This supports uppercase and lowercase. For encoding, the string
|
||||
/ 0123456789abcdefghijklmnopqrstuvwxyz can be used, which linkers
|
||||
/ are able to deduplicate.
|
||||
.initbss 300,_init_kBase36
|
||||
kBase36:.zero 256
|
||||
.endobj kBase36,globl,hidden
|
||||
.previous
|
||||
|
||||
.init.start 300,_init_kBase36
|
||||
add $'0,%rdi
|
||||
xor %eax,%eax
|
||||
pushpop 10,%rcx
|
||||
0: inc %eax
|
||||
stosb
|
||||
loop 0b
|
||||
add $'A-1-'9,%rdi
|
||||
pushpop 'Z+1-'A,%rcx
|
||||
0: inc %eax
|
||||
mov %al,0x20(%rdi)
|
||||
stosb
|
||||
loop 0b
|
||||
add $255-'Z,%rdi
|
||||
.init.end 300,_init_kBase36
|
||||
.yoink __FILE__
|
96
libc/nexgen32e/kcp437.S
Normal file
96
libc/nexgen32e/kcp437.S
Normal file
|
@ -0,0 +1,96 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
.rodata
|
||||
.align 16
|
||||
|
||||
/ ibm cp437 unicode table w/ string literal safety
|
||||
/
|
||||
/ ░▄██▒▄█ ▐██ ░░░ ▀▀████▒▀█▄
|
||||
/ ▐███▓██░ ██▌ ▀████▄■█▄
|
||||
/ ▐█▓███▀█░██▀ ░ ░▀█████▓▄
|
||||
/ ▐█▓██▀▄█▒██▀ ▄▄░ ▄▄▄ ░░░ ░▀████▒▄
|
||||
/ ▐████▀▄█■█▀ ▀▀ ░█████░
|
||||
/ ▐█▓█▀████▀ ░ ▐▓███▒
|
||||
/ █░███▀▀ ░░░ ▄█ ░░░ █████
|
||||
/ ▐█▓█░▀▀ ░░▄█▄▄▄▄▄ ▀▄ ▌▄▄▄░▄▄▄▄▄ ▐████░
|
||||
/ ▐███▌ ▄▀█████████▄ ▌▐▄████████▄ ▐▓███░
|
||||
/ ▐███░░░▀▄█▀▄▄████▄▀░ ▐████████▒ ▀ ░███░
|
||||
/ ░████░ ▓▀ ▄███████▀▌ ▀▄■████▀▀█▀ ██▀█
|
||||
/ ▓███░ ░▄▀▀░░░ ▀ ░░▌ ▄▀▀▄░░▀░▄▀▄ ▐██▀▄
|
||||
/ ░███░ ▄▓▓▄▄░▀▀█▀█ ▌░░ ▀█▀█▀▀ ▐██▀
|
||||
/ █▀▄▐██ ▀░░ ▄▀ ▐ █ ▀ ▄▄▄░ ░▀▄█▄▀█
|
||||
/ ▌▄ █▓ ▒ ░ █▄█▄▀▄▄▄███▄▀▄ ░░ ░ ▀ █▌
|
||||
/ █▌▄░▌ ░░░▄▀█▀███████▄▀▄▀▄▀▀▄▄▄ █▀█░▐
|
||||
/ ██▄ ░░░▄█▄▀██▄█■██████▄█▄█▄■▀█░ ▐░▐
|
||||
/ ▀██░ ░▄██████████████████▄█▄█ ░█ ░ ▄▀
|
||||
/ ▀▓█▄▓░░ ▒█▀█████████████████████▒ ██▀
|
||||
/ ▀███ ▓▒ ██████████████▀▀▀▀█▄▀ ░▄█▒
|
||||
/ ▀███ ▀█▄▀▄█████▀▀ ▓▓▓▄░ ▐ ░▄██
|
||||
/ ▀██ ▄███████▄████████▀░░ ░▄██
|
||||
/ ▄██▀▀▄ █▄▀▄██▒▒███████████▀▀▀▄░ ░███░
|
||||
/ ▄██▀▄▄░░▀▐▄████▄ █████▀▄░░█▀▄▀░░ ▄██░
|
||||
/ █████▄▄▄███▀░█▌██▄▀▀█████▄▄░░░▄▄███▀██▄ ▄▀▀▀▄▄
|
||||
/ ▀██████▀■▄█▄▄ ░▀███████████████▓▓░░▄██▀▄████▄▄▀▄
|
||||
/
|
||||
/ █▀█ █ █▀█ █▀█ █▄▀ ▐▀█▀▌█▀█ █▀█ █▄ █ ▀█▀ █▀█ █▀▀
|
||||
/ █▀▄ █ █ █ █ █ ▀▄ █ █▀▄ █ █ █ ▀█ █ █ ▀▀█
|
||||
/ █▄█ █▄▌█▄█ █▄█ █ █ █ █ █ █▄█ █ █ ▄█▄ █▄█ █▄█
|
||||
/
|
||||
/ THERE WILL BE BLOCKS march 01 2017
|
||||
/
|
||||
/ @see libc/str/str.h
|
||||
/ @see kCp437i[]
|
||||
kCp437:
|
||||
.short 0x00a0,0x263a,0x263b,0x2665,0x2666,0x2663,0x2660,0x2022 #00: ☺☻♥♦♣♠•
|
||||
.short 0x25d8,0x25cb,0x25d9,0x2642,0x2640,0x266a,0x266b,0x263c #08:◘○◙♂♀♪♫☼
|
||||
.short 0x25ba,0x25c4,0x2195,0x203c,0x00b6,0x00a7,0x25ac,0x21a8 #10:►◄↕‼¶§▬↨
|
||||
.short 0x2191,0x2193,0x2192,0x2190,0x221f,0x2194,0x25b2,0x25bc #18:↑↓→←∟↔▲▼
|
||||
.short 0x0020,0x0021,0x201c,0x0023,0x0024,0x0025,0x0026,0x2018 #20: !“#$%&‘
|
||||
.short 0x0028,0x0029,0x002a,0x002b,0x002c,0x002d,0x002e,0x002f #28:()*+,-./
|
||||
.short 0x0030,0x0031,0x0032,0x0033,0x0034,0x0035,0x0036,0x0037 #30:01234567
|
||||
.short 0x0038,0x0039,0x003a,0x003b,0x003c,0x003d,0x003e,0x2047 #38:89:;<=>⁇
|
||||
.short 0x0040,0x0041,0x0042,0x0043,0x0044,0x0045,0x0046,0x0047 #40:@ABCDEFG
|
||||
.short 0x0048,0x0049,0x004a,0x004b,0x004c,0x004d,0x004e,0x004f #48:HIJKLMNO
|
||||
.short 0x0050,0x0051,0x0052,0x0053,0x0054,0x0055,0x0056,0x0057 #50:PQRSTUVW
|
||||
.short 0x0058,0x0059,0x005a,0x005b,0x2572,0x005d,0x005e,0x005f #58:XYZ[╲]^_
|
||||
.short 0x0060,0x0061,0x0062,0x0063,0x0064,0x0065,0x0066,0x0067 #60:`abcdefg
|
||||
.short 0x0068,0x0069,0x006a,0x006b,0x006c,0x006d,0x006e,0x006f #68:hijklmno
|
||||
.short 0x0070,0x0071,0x0072,0x0073,0x0074,0x0075,0x0076,0x0077 #70:pqrstuvw
|
||||
.short 0x0078,0x0079,0x007a,0x007b,0x007c,0x007d,0x007e,0x2302 #78:xyz{|}~⌂
|
||||
.short 0x00c7,0x00fc,0x00e9,0x00e2,0x00e4,0x00e0,0x00e5,0x00e7 #80:Çüéâäàåç
|
||||
.short 0x00ea,0x00eb,0x00e8,0x00ef,0x00ee,0x00ec,0x00c4,0x00c5 #88:êëèïîìÄÅ
|
||||
.short 0x00c9,0x00e6,0x00c6,0x00f4,0x00f6,0x00f2,0x00fb,0x00f9 #90:ÉæÆôöòûù
|
||||
.short 0x00ff,0x00d6,0x00dc,0x00a2,0x00a3,0x00a5,0x20ac,0x0192 #98:ÿÖÜ¢£¥€ƒ
|
||||
.short 0x00e1,0x00ed,0x00f3,0x00fa,0x00f1,0x00d1,0x00aa,0x00ba #a0:áíóúñѪº
|
||||
.short 0x00bf,0x2310,0x00ac,0x00bd,0x00bc,0x00a1,0x00ab,0x00bb #a8:¿⌐¬½¼¡«»
|
||||
.short 0x2591,0x2592,0x2593,0x2502,0x2524,0x2561,0x2562,0x2556 #b0:░▒▓│┤╡╢╖
|
||||
.short 0x2555,0x2563,0x2551,0x2557,0x255d,0x255c,0x255b,0x2510 #b8:╕╣║╗╝╜╛┐
|
||||
.short 0x2514,0x2534,0x252c,0x251c,0x2500,0x253c,0x255e,0x255f #c0:└┴┬├─┼╞╟
|
||||
.short 0x255a,0x2554,0x2569,0x2566,0x2560,0x2550,0x256c,0x2567 #c8:╚╔╩╦╠═╬╧
|
||||
.short 0x2568,0x2564,0x2565,0x2559,0x2558,0x2552,0x2553,0x256b #d0:╨╤╥╙╘╒╓╫
|
||||
.short 0x256a,0x2518,0x250c,0x2588,0x2584,0x258c,0x2590,0x2580 #d8:╪┘┌█▄▌▐▀
|
||||
.short 0x03b1,0x00df,0x0393,0x03c0,0x03a3,0x03c3,0x03bc,0x03c4 #e0:αßΓπΣσμτ
|
||||
.short 0x03a6,0x0398,0x03a9,0x03b4,0x221e,0x03c6,0x03b5,0x2229 #e8:ΦΘΩδ∞φε∩
|
||||
.short 0x2261,0x00b1,0x2265,0x2264,0x2320,0x2321,0x00f7,0x2248 #f0:≡±≥≤⌠⌡÷≈
|
||||
.short 0x00b0,0x2219,0x00b7,0x221a,0x207f,0x00b2,0x25a0,0x03bb #f8:°∙·√ⁿ²■λ
|
||||
.endobj kCp437,globl
|
||||
.previous
|
||||
.yoink __FILE__
|
88
libc/nexgen32e/kcpuids.S
Normal file
88
libc/nexgen32e/kcpuids.S
Normal file
|
@ -0,0 +1,88 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "ape/lib/pc.h"
|
||||
#include "libc/dce.h"
|
||||
#include "libc/macros.h"
|
||||
#include "libc/nexgen32e/kcpuids.h"
|
||||
#include "libc/nexgen32e/x86feature.h"
|
||||
|
||||
/ Globally precomputed CPUID.
|
||||
/
|
||||
/ This module lets us check CPUID in 0.06ns rather than 51.00ns.
|
||||
/ If every piece of native software linked this module, then the
|
||||
/ world would be a much better place; since all the alternatives
|
||||
/ are quite toilsome.
|
||||
/
|
||||
/ @see www.felixcloutier.com/x86/cpuid
|
||||
.initbss 201,_init_kCpuids
|
||||
kCpuids:.long 0,0,0,0 # EAX=0 (Basic Processor Info)
|
||||
.long 0,0,0,0 # EAX=1 (Processor Info)
|
||||
.long 0,0,0,0 # EAX=2
|
||||
.long 0,0,0,0 # EAX=7 (Extended Features)
|
||||
.long 0,0,0,0 # EAX=0x80000001 (NexGen32e)
|
||||
.long 0,0,0,0 # EAX=0x80000007 (APM)
|
||||
.long 0,0,0,0 # EAX=16h (CPU Frequency)
|
||||
.endobj kCpuids,globl
|
||||
.previous
|
||||
|
||||
.init.start 201,_init_kCpuids
|
||||
push %rbx
|
||||
push $0
|
||||
push $0x16
|
||||
push $0xffffffff80000007
|
||||
push $0xffffffff80000001
|
||||
push $7
|
||||
push $2
|
||||
push $1
|
||||
mov %rdi,%r8
|
||||
xor %eax,%eax
|
||||
1: xor %ecx,%ecx
|
||||
cpuid
|
||||
stosl
|
||||
xchg %eax,%ebx
|
||||
stosl
|
||||
xchg %eax,%ecx
|
||||
stosl
|
||||
xchg %eax,%edx
|
||||
stosl
|
||||
2: pop %rax
|
||||
test %eax,%eax # EAX = stacklist->pop()
|
||||
jz 3f # EAX ≠ 0 (EOL sentinel)
|
||||
cmp KCPUIDS(0H,EAX)(%r8),%eax # EAX ≤ CPUID.0 max leaf
|
||||
jle 1b # CPUID too new to probe
|
||||
add $4*4,%rdi
|
||||
jmp 2b
|
||||
3: nop
|
||||
#if 0 && !X86_NEED(AVX2)
|
||||
testb X86_HAVE(AVX)(%r8)
|
||||
jz 5f
|
||||
testb X86_HAVE(OSXSAVE)(%r8)
|
||||
jz 4f
|
||||
xor %ecx,%ecx
|
||||
xgetbv
|
||||
and $XCR0_SSE|XCR0_AVX,%eax
|
||||
cmp $XCR0_SSE|XCR0_AVX,%eax
|
||||
je 5f
|
||||
4: btr $X86_BIT(AVX),X86_WORD(AVX)(%r8)
|
||||
btr $X86_BIT(AVX2),X86_WORD(AVX2)(%r8)
|
||||
#endif
|
||||
5: pop %rbx
|
||||
.init.end 201,_init_kCpuids
|
||||
.yoink __FILE__
|
43
libc/nexgen32e/kcpuids.h
Normal file
43
libc/nexgen32e/kcpuids.h
Normal file
|
@ -0,0 +1,43 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_NEXGEN32E_KCPUIDS_H_
|
||||
#define COSMOPOLITAN_LIBC_NEXGEN32E_KCPUIDS_H_
|
||||
|
||||
#define KCPUIDS_0H 0
|
||||
#define KCPUIDS_1H 1
|
||||
#define KCPUIDS_2H 2
|
||||
#define KCPUIDS_7H 3
|
||||
#define KCPUIDS_80000001H 4
|
||||
#define KCPUIDS_80000007H 5
|
||||
#define KCPUIDS_16H 6
|
||||
#define _KCPUIDS_LEN 7
|
||||
#define KCPUIDS_6H -1 /* TBD: Thermal and Power Management */
|
||||
#define KCPUIDS_DH -1 /* TBD: Extended state features */
|
||||
#define KCPUIDS_80000008H -1 /* TBD: AMD Miscellaneous */
|
||||
#define KCPUIDS_8000000AH -1 /* TBD: AMD SVM */
|
||||
|
||||
#define KCPUIDS_EAX 0
|
||||
#define KCPUIDS_EBX 1
|
||||
#define KCPUIDS_ECX 2
|
||||
#define KCPUIDS_EDX 3
|
||||
|
||||
#define KCPUIDS(LEAF, REG) _KCPUIDS(LEAF, REG)
|
||||
#ifdef __ASSEMBLER__
|
||||
#define _KCPUIDS(LEAF, REG) KCPUIDS_##LEAF * 16 + KCPUIDS_##REG * 4
|
||||
#else
|
||||
#define _KCPUIDS(LEAF, REG) kCpuids[KCPUIDS_##LEAF][KCPUIDS_##REG]
|
||||
#endif
|
||||
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
/**
|
||||
* Globally precomputed x86 CPUID values.
|
||||
*
|
||||
* @note Referencing Is Initialization (RII)
|
||||
* @note Protected with PIRO
|
||||
* @see X86_HAVE()
|
||||
*/
|
||||
extern const unsigned kCpuids[_KCPUIDS_LEN][4];
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_NEXGEN32E_KCPUIDS_H_ */
|
42
libc/nexgen32e/kcrc32ctab.S
Normal file
42
libc/nexgen32e/kcrc32ctab.S
Normal file
|
@ -0,0 +1,42 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
/ Castagnoli CRC32 ISCSI Polynomial
|
||||
/ x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1
|
||||
/ 0b00011110110111000110111101000001
|
||||
/ bitreverse32(0x1edc6f41)
|
||||
#define ISCSI_POLYNOMIAL 0x82f63b78
|
||||
|
||||
.initbss 300,_init_kCrc32cTab
|
||||
kCrc32cTab:
|
||||
.rept 256
|
||||
.long 0
|
||||
.endr
|
||||
.endobj kCrc32cTab,globl,hidden
|
||||
.previous
|
||||
|
||||
.init.start 300,_init_kCrc32cTab
|
||||
push %rsi
|
||||
mov $ISCSI_POLYNOMIAL,%esi
|
||||
call crc32init
|
||||
pop %rsi
|
||||
.init.end 300,_init_kCrc32cTab
|
||||
.yoink __FILE__
|
42
libc/nexgen32e/kcrc32tab.S
Normal file
42
libc/nexgen32e/kcrc32tab.S
Normal file
|
@ -0,0 +1,42 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
/ Phil Katz CRC-32 Polynomial
|
||||
/ x^32+x^26+x^23+x^22+x^16+x^12+x^11+x^10+x^8+x^7+x^5+x^4+x^2+x+1
|
||||
/ 0b100000100110000010001110110110111
|
||||
/ bitreverse32(0x104c11db7)
|
||||
#define kZipCrc32Polynomial 0xedb88320
|
||||
|
||||
.initbss 300,_init_kCrc32Tab
|
||||
kCrc32Tab:
|
||||
.rept 256
|
||||
.long 0
|
||||
.endr
|
||||
.endobj kCrc32Tab,globl,hidden
|
||||
.previous
|
||||
|
||||
.init.start 300,_init_kCrc32Tab
|
||||
push %rsi
|
||||
mov $kZipCrc32Polynomial,%esi
|
||||
call crc32init
|
||||
pop %rsi
|
||||
.init.end 300,_init_kCrc32Tab
|
||||
.yoink __FILE__
|
63
libc/nexgen32e/kctype.S
Normal file
63
libc/nexgen32e/kctype.S
Normal file
|
@ -0,0 +1,63 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
#include "libc/notice.inc"
|
||||
|
||||
.initbss 300,_init_kCtype
|
||||
kCtype: .rept 256
|
||||
.byte 0
|
||||
.endr
|
||||
.endobj kCtype,globl,hidden
|
||||
.previous
|
||||
|
||||
.initro 300,_init_kCtype
|
||||
.LkCtype.rodata:
|
||||
/ ┌─isblank
|
||||
/ │┌─isupper
|
||||
/ ││┌─islower
|
||||
/ │││┌─isprint
|
||||
/ ││││┌─isxdigit
|
||||
/ │││││┌─isdigit
|
||||
/ ││││││┌─isalpha
|
||||
/ │││││││┌─isspace
|
||||
/ ││││││││
|
||||
.byte 9, 0b00000000 # 00─08 ∅─◘
|
||||
.byte 1, 0b10000001 # 09─09 ○
|
||||
.byte 4, 0b00000001 # 0a─0d ◙─♪
|
||||
.byte 18, 0b00000000 # 0e─1f ♫─▼
|
||||
.byte 1, 0b10010001 # 20─20
|
||||
.byte 15, 0b00010000 # 21─2f !─/
|
||||
.byte 10, 0b00011100 # 30─39 0─9
|
||||
.byte 7, 0b00010000 # 3a─40 :─@
|
||||
.byte 6, 0b01011010 # 41─46 A─F
|
||||
.byte 20, 0b01010010 # 47─5a G─Z
|
||||
.byte 6, 0b00010000 # 5b─60 [─`
|
||||
.byte 6, 0b00111010 # 61─66 a─f
|
||||
.byte 20, 0b00110010 # 67─7a g─z
|
||||
.byte 4, 0b00010000 # 7b─7e {─~
|
||||
.byte 129, 0b00000000 # 7f─ff ⌂─λ
|
||||
.endobj .LkCtype.rodata # 32b ─ 13%
|
||||
.byte 0,0 # terminatr
|
||||
.previous
|
||||
|
||||
.init.start 300,_init_kCtype
|
||||
call rldecode
|
||||
.init.end 300,_init_kCtype
|
||||
.yoink __FILE__
|
33
libc/nexgen32e/knobs.c
Normal file
33
libc/nexgen32e/knobs.c
Normal file
|
@ -0,0 +1,33 @@
|
|||
/*-*- 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "tool/viz/lib/knobs.h"
|
||||
|
||||
bool pf1_;
|
||||
bool pf2_;
|
||||
bool pf3_;
|
||||
bool pf4_;
|
||||
bool pf5_;
|
||||
bool pf6_;
|
||||
bool pf7_;
|
||||
bool pf8_;
|
||||
bool pf9_;
|
||||
bool pf10_;
|
||||
bool pf11_;
|
||||
bool pf12_;
|
23
libc/nexgen32e/kompressor.h
Normal file
23
libc/nexgen32e/kompressor.h
Normal file
|
@ -0,0 +1,23 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_KOMPRESSOR_KOMPRESSOR_H_
|
||||
#define COSMOPOLITAN_LIBC_KOMPRESSOR_KOMPRESSOR_H_
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
#if 0
|
||||
/*───────────────────────────────────────────────────────────────────────────│─╗
|
||||
│ cosmopolitan § standard library » compression ─╬─│┼
|
||||
╚────────────────────────────────────────────────────────────────────────────│*/
|
||||
#endif
|
||||
|
||||
struct RlDecode {
|
||||
uint8_t repititions;
|
||||
uint8_t byte;
|
||||
};
|
||||
|
||||
void rldecode(void *dest, const struct RlDecode *) hidden;
|
||||
const uint8_t *lz4check(const void *data) hidden;
|
||||
void *lz4cpy(void *dest, const void *blockdata, size_t blocksize) hidden;
|
||||
void *lz4decode(void *dest, const void *src) hidden;
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_KOMPRESSOR_KOMPRESSOR_H_ */
|
90
libc/nexgen32e/kreversebits.S
Normal file
90
libc/nexgen32e/kreversebits.S
Normal file
|
@ -0,0 +1,90 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
.rodata
|
||||
kReverseBits:
|
||||
.byte 0b00000000,0b10000000,0b01000000,0b11000000
|
||||
.byte 0b00100000,0b10100000,0b01100000,0b11100000
|
||||
.byte 0b00010000,0b10010000,0b01010000,0b11010000
|
||||
.byte 0b00110000,0b10110000,0b01110000,0b11110000
|
||||
.byte 0b00001000,0b10001000,0b01001000,0b11001000
|
||||
.byte 0b00101000,0b10101000,0b01101000,0b11101000
|
||||
.byte 0b00011000,0b10011000,0b01011000,0b11011000
|
||||
.byte 0b00111000,0b10111000,0b01111000,0b11111000
|
||||
.byte 0b00000100,0b10000100,0b01000100,0b11000100
|
||||
.byte 0b00100100,0b10100100,0b01100100,0b11100100
|
||||
.byte 0b00010100,0b10010100,0b01010100,0b11010100
|
||||
.byte 0b00110100,0b10110100,0b01110100,0b11110100
|
||||
.byte 0b00001100,0b10001100,0b01001100,0b11001100
|
||||
.byte 0b00101100,0b10101100,0b01101100,0b11101100
|
||||
.byte 0b00011100,0b10011100,0b01011100,0b11011100
|
||||
.byte 0b00111100,0b10111100,0b01111100,0b11111100
|
||||
.byte 0b00000010,0b10000010,0b01000010,0b11000010
|
||||
.byte 0b00100010,0b10100010,0b01100010,0b11100010
|
||||
.byte 0b00010010,0b10010010,0b01010010,0b11010010
|
||||
.byte 0b00110010,0b10110010,0b01110010,0b11110010
|
||||
.byte 0b00001010,0b10001010,0b01001010,0b11001010
|
||||
.byte 0b00101010,0b10101010,0b01101010,0b11101010
|
||||
.byte 0b00011010,0b10011010,0b01011010,0b11011010
|
||||
.byte 0b00111010,0b10111010,0b01111010,0b11111010
|
||||
.byte 0b00000110,0b10000110,0b01000110,0b11000110
|
||||
.byte 0b00100110,0b10100110,0b01100110,0b11100110
|
||||
.byte 0b00010110,0b10010110,0b01010110,0b11010110
|
||||
.byte 0b00110110,0b10110110,0b01110110,0b11110110
|
||||
.byte 0b00001110,0b10001110,0b01001110,0b11001110
|
||||
.byte 0b00101110,0b10101110,0b01101110,0b11101110
|
||||
.byte 0b00011110,0b10011110,0b01011110,0b11011110
|
||||
.byte 0b00111110,0b10111110,0b01111110,0b11111110
|
||||
.byte 0b00000001,0b10000001,0b01000001,0b11000001
|
||||
.byte 0b00100001,0b10100001,0b01100001,0b11100001
|
||||
.byte 0b00010001,0b10010001,0b01010001,0b11010001
|
||||
.byte 0b00110001,0b10110001,0b01110001,0b11110001
|
||||
.byte 0b00001001,0b10001001,0b01001001,0b11001001
|
||||
.byte 0b00101001,0b10101001,0b01101001,0b11101001
|
||||
.byte 0b00011001,0b10011001,0b01011001,0b11011001
|
||||
.byte 0b00111001,0b10111001,0b01111001,0b11111001
|
||||
.byte 0b00000101,0b10000101,0b01000101,0b11000101
|
||||
.byte 0b00100101,0b10100101,0b01100101,0b11100101
|
||||
.byte 0b00010101,0b10010101,0b01010101,0b11010101
|
||||
.byte 0b00110101,0b10110101,0b01110101,0b11110101
|
||||
.byte 0b00001101,0b10001101,0b01001101,0b11001101
|
||||
.byte 0b00101101,0b10101101,0b01101101,0b11101101
|
||||
.byte 0b00011101,0b10011101,0b01011101,0b11011101
|
||||
.byte 0b00111101,0b10111101,0b01111101,0b11111101
|
||||
.byte 0b00000011,0b10000011,0b01000011,0b11000011
|
||||
.byte 0b00100011,0b10100011,0b01100011,0b11100011
|
||||
.byte 0b00010011,0b10010011,0b01010011,0b11010011
|
||||
.byte 0b00110011,0b10110011,0b01110011,0b11110011
|
||||
.byte 0b00001011,0b10001011,0b01001011,0b11001011
|
||||
.byte 0b00101011,0b10101011,0b01101011,0b11101011
|
||||
.byte 0b00011011,0b10011011,0b01011011,0b11011011
|
||||
.byte 0b00111011,0b10111011,0b01111011,0b11111011
|
||||
.byte 0b00000111,0b10000111,0b01000111,0b11000111
|
||||
.byte 0b00100111,0b10100111,0b01100111,0b11100111
|
||||
.byte 0b00010111,0b10010111,0b01010111,0b11010111
|
||||
.byte 0b00110111,0b10110111,0b01110111,0b11110111
|
||||
.byte 0b00001111,0b10001111,0b01001111,0b11001111
|
||||
.byte 0b00101111,0b10101111,0b01101111,0b11101111
|
||||
.byte 0b00011111,0b10011111,0b01011111,0b11011111
|
||||
.byte 0b00111111,0b10111111,0b01111111,0b11111111
|
||||
.endobj kReverseBits,globl
|
||||
.previous
|
||||
.yoink __FILE__
|
33
libc/nexgen32e/ksha256tab.S
Normal file
33
libc/nexgen32e/ksha256tab.S
Normal file
|
@ -0,0 +1,33 @@
|
|||
#if 0
|
||||
/*─────────────────────────────────────────────────────────────────╗
|
||||
│ To the extent possible under law, Justine Tunney has waived │
|
||||
│ all copyright and related or neighboring rights to this file, │
|
||||
│ as it is written in the following disclaimers: │
|
||||
│ • http://unlicense.org/ │
|
||||
│ • http://creativecommons.org/publicdomain/zero/1.0/ │
|
||||
╚─────────────────────────────────────────────────────────────────*/
|
||||
#endif
|
||||
#include "libc/macros.h"
|
||||
|
||||
.rodata.cst16
|
||||
.align 16
|
||||
kSha256Tab:
|
||||
.long 0x428a2f98,0x71374491,0xb5c0fbcf,0xe9b5dba5
|
||||
.long 0x3956c25b,0x59f111f1,0x923f82a4,0xab1c5ed5
|
||||
.long 0xd807aa98,0x12835b01,0x243185be,0x550c7dc3
|
||||
.long 0x72be5d74,0x80deb1fe,0x9bdc06a7,0xc19bf174
|
||||
.long 0xe49b69c1,0xefbe4786,0x0fc19dc6,0x240ca1cc
|
||||
.long 0x2de92c6f,0x4a7484aa,0x5cb0a9dc,0x76f988da
|
||||
.long 0x983e5152,0xa831c66d,0xb00327c8,0xbf597fc7
|
||||
.long 0xc6e00bf3,0xd5a79147,0x06ca6351,0x14292967
|
||||
.long 0x27b70a85,0x2e1b2138,0x4d2c6dfc,0x53380d13
|
||||
.long 0x650a7354,0x766a0abb,0x81c2c92e,0x92722c85
|
||||
.long 0xa2bfe8a1,0xa81a664b,0xc24b8b70,0xc76c51a3
|
||||
.long 0xd192e819,0xd6990624,0xf40e3585,0x106aa070
|
||||
.long 0x19a4c116,0x1e376c08,0x2748774c,0x34b0bcb5
|
||||
.long 0x391c0cb3,0x4ed8aa4a,0x5b9cca4f,0x682e6ff3
|
||||
.long 0x748f82ee,0x78a5636f,0x84c87814,0x8cc70208
|
||||
.long 0x90befffa,0xa4506ceb,0xbef9a3f7,0xc67178f2
|
||||
.endobj kSha256Tab,globl,hidden
|
||||
.previous
|
||||
.yoink __FILE__
|
39
libc/nexgen32e/ksigsetempty.S
Normal file
39
libc/nexgen32e/ksigsetempty.S
Normal file
|
@ -0,0 +1,39 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
/ Signal mask constant w/ no signal bits set.
|
||||
/
|
||||
/ @see kSigsetFull,sigemptyset(),sigprocmask(),sigaction()
|
||||
.initbss 300,_init_kSigsetEmpty
|
||||
kSigsetEmpty:
|
||||
.rept NSIG / 64
|
||||
.quad 0
|
||||
.endr
|
||||
.if NSIG % 64
|
||||
.error "bad signal max"
|
||||
.endif
|
||||
.endobj kSigsetEmpty,globl
|
||||
.previous
|
||||
|
||||
.init.start 300,_init_kSigsetEmpty
|
||||
add $NSIG/8,%rdi
|
||||
.init.end 300,_init_kSigsetEmpty
|
||||
.yoink __FILE__
|
42
libc/nexgen32e/ksigsetfull.S
Normal file
42
libc/nexgen32e/ksigsetfull.S
Normal file
|
@ -0,0 +1,42 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
/ Signal mask constant w/ every signal bit set.
|
||||
/
|
||||
/ @see kSigsetEmpty,sigemptyset(),sigprocmask(),sigaction()
|
||||
.initbss 300,_init_kSigsetFull
|
||||
kSigsetFull:
|
||||
.rept NSIG / 64
|
||||
.quad 0
|
||||
.endr
|
||||
.if NSIG % 64
|
||||
.error "bad signal max"
|
||||
.endif
|
||||
.endobj kSigsetFull,globl
|
||||
.previous
|
||||
|
||||
.init.start 300,_init_kSigsetFull
|
||||
or $-1,%rax
|
||||
.rept NSIG / 64
|
||||
stosq
|
||||
.endr
|
||||
.init.end 300,_init_kSigsetFull
|
||||
.yoink __FILE__
|
37
libc/nexgen32e/kstarttsc.S
Normal file
37
libc/nexgen32e/kstarttsc.S
Normal file
|
@ -0,0 +1,37 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
/ Stores CPU Timestamp Counter at startup.
|
||||
/ It can be useful as an added source of seeding information.
|
||||
/ @note rdtsc is a 25 cycle instruction
|
||||
.initbss 200,_init_kStartTsc
|
||||
kStartTsc:
|
||||
.quad 0
|
||||
.endobj kStartTsc,globl
|
||||
.previous
|
||||
|
||||
.init.start 200,_init_kStartTsc
|
||||
rdtsc
|
||||
stosl
|
||||
xchg %edx,%eax
|
||||
stosl
|
||||
.init.end 200,_init_kStartTsc
|
||||
.yoink __FILE__
|
61
libc/nexgen32e/ktolower.S
Normal file
61
libc/nexgen32e/ktolower.S
Normal file
|
@ -0,0 +1,61 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
/ ASCII uppercase → lowercase translation tables.
|
||||
/
|
||||
/ char kToLower[256];
|
||||
/ char16_t kToLower16[256];
|
||||
/
|
||||
/ @note kToLower16 saves 128kb; CMOVcc can't even 8-bit
|
||||
.initbss 300,_init_kToLower
|
||||
kToLower:
|
||||
.rept 256
|
||||
.byte 0
|
||||
.endr
|
||||
.endobj kToLower,globl,hidden
|
||||
kToLower16:
|
||||
.rept 256
|
||||
.short 0
|
||||
.endr
|
||||
.endobj kToLower16,globl,hidden
|
||||
.previous
|
||||
|
||||
.init.start 300,_init_kToLower
|
||||
push %rdi
|
||||
call imapxlatab
|
||||
xchg %rsi,(%rsp)
|
||||
xor %ecx,%ecx
|
||||
0: inc %ecx
|
||||
addb $0x20,'A-1(%rsi,%rcx)
|
||||
cmp $'Z-'A,%ecx
|
||||
jne 0b
|
||||
xor %eax,%eax
|
||||
mov $256,%ecx
|
||||
0: lodsb
|
||||
stosw
|
||||
loop 0b
|
||||
pop %rsi
|
||||
.init.end 300,_init_kToLower
|
||||
|
||||
.type gperf_downcase,@object
|
||||
.globl gperf_downcase
|
||||
gperf_downcase = kToLower
|
||||
.yoink __FILE__
|
35
libc/nexgen32e/ktoupper.S
Normal file
35
libc/nexgen32e/ktoupper.S
Normal file
|
@ -0,0 +1,35 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
.initbss 300,_init_kToUpper
|
||||
kToUpper:
|
||||
.zero 256
|
||||
.endobj kToUpper,globl,hidden
|
||||
.previous
|
||||
|
||||
.init.start 300,_init_kToUpper
|
||||
lea 'a(%rdi),%r8
|
||||
call imapxlatab
|
||||
pushpop 'z-'a,%rcx
|
||||
0: subb $0x20,(%r8,%rcx)
|
||||
loop 0b
|
||||
.init.end 300,_init_kToUpper
|
||||
.yoink __FILE__
|
83
libc/nexgen32e/kx86processormodels.c
Normal file
83
libc/nexgen32e/kx86processormodels.c
Normal file
|
@ -0,0 +1,83 @@
|
|||
/*-*- 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/bits.h"
|
||||
#include "libc/macros.h"
|
||||
#include "libc/nexgen32e/x86info.h"
|
||||
|
||||
const struct X86ProcessorModel kX86ProcessorModels[] = {
|
||||
/* <SORTED> */
|
||||
{0x060F, X86_MARCH_CORE2, X86_GRADE_CLIENT},
|
||||
{0x0616, X86_MARCH_CORE2, X86_GRADE_MOBILE},
|
||||
{0x0617, X86_MARCH_CORE2, X86_GRADE_SERVER},
|
||||
{0x061A, X86_MARCH_NEHALEM, X86_GRADE_DENSITY},
|
||||
{0x061C, X86_MARCH_BONNELL, X86_GRADE_APPLIANCE},
|
||||
{0x061D, X86_MARCH_CORE2, X86_GRADE_SERVER},
|
||||
{0x061E, X86_MARCH_NEHALEM, X86_GRADE_CLIENT},
|
||||
{0x061F, X86_MARCH_NEHALEM, X86_GRADE_DESKTOP},
|
||||
{0x0625, X86_MARCH_WESTMERE, X86_GRADE_CLIENT},
|
||||
{0x0626, X86_MARCH_BONNELL, X86_GRADE_TABLET},
|
||||
{0x0627, X86_MARCH_SALTWELL, X86_GRADE_TABLET},
|
||||
{0x062A, X86_MARCH_SANDYBRIDGE, X86_GRADE_CLIENT},
|
||||
{0x062C, X86_MARCH_WESTMERE, X86_GRADE_DENSITY},
|
||||
{0x062D, X86_MARCH_SANDYBRIDGE, X86_GRADE_SERVER},
|
||||
{0x062E, X86_MARCH_NEHALEM, X86_GRADE_SERVER},
|
||||
{0x062F, X86_MARCH_WESTMERE, X86_GRADE_SERVER},
|
||||
{0x0635, X86_MARCH_SALTWELL, X86_GRADE_TABLET},
|
||||
{0x0636, X86_MARCH_SALTWELL, X86_GRADE_APPLIANCE},
|
||||
{0x0637, X86_MARCH_SILVERMONT, X86_GRADE_APPLIANCE},
|
||||
{0x063A, X86_MARCH_IVYBRIDGE, X86_GRADE_CLIENT},
|
||||
{0x063C, X86_MARCH_HASWELL, X86_GRADE_CLIENT},
|
||||
{0x063D, X86_MARCH_BROADWELL, X86_GRADE_CLIENT},
|
||||
{0x063E, X86_MARCH_IVYBRIDGE, X86_GRADE_SERVER},
|
||||
{0x063F, X86_MARCH_HASWELL, X86_GRADE_SERVER},
|
||||
{0x0645, X86_MARCH_HASWELL, X86_GRADE_MOBILE},
|
||||
{0x0646, X86_MARCH_HASWELL, X86_GRADE_DESKTOP},
|
||||
{0x0647, X86_MARCH_BROADWELL, X86_GRADE_DESKTOP},
|
||||
{0x064A, X86_MARCH_SILVERMONT, X86_GRADE_TABLET},
|
||||
{0x064C, X86_MARCH_AIRMONT, X86_GRADE_APPLIANCE},
|
||||
{0x064D, X86_MARCH_SILVERMONT, X86_GRADE_DENSITY},
|
||||
{0x064E, X86_MARCH_SKYLAKE, X86_GRADE_MOBILE},
|
||||
{0x064F, X86_MARCH_BROADWELL, X86_GRADE_SERVER},
|
||||
{0x0655, X86_MARCH_SKYLAKE, X86_GRADE_SERVER},
|
||||
{0x0656, X86_MARCH_BROADWELL, X86_GRADE_DENSITY},
|
||||
{0x0657, X86_MARCH_KNIGHTSLANDING, X86_GRADE_SCIENCE},
|
||||
{0x065A, X86_MARCH_AIRMONT, X86_GRADE_TABLET},
|
||||
{0x065C, X86_MARCH_GOLDMONT, X86_GRADE_APPLIANCE},
|
||||
{0x065E, X86_MARCH_SKYLAKE, X86_GRADE_CLIENT},
|
||||
{0x065F, X86_MARCH_GOLDMONT, X86_GRADE_DENSITY},
|
||||
{0x0666, X86_MARCH_CANNONLAKE, X86_GRADE_MOBILE},
|
||||
{0x066A, X86_MARCH_ICELAKE, X86_GRADE_SERVER},
|
||||
{0x066C, X86_MARCH_ICELAKE, X86_GRADE_DENSITY},
|
||||
{0x0675, X86_MARCH_AIRMONT, X86_GRADE_APPLIANCE},
|
||||
{0x067A, X86_MARCH_GOLDMONTPLUS, X86_GRADE_APPLIANCE},
|
||||
{0x067D, X86_MARCH_ICELAKE, X86_GRADE_CLIENT},
|
||||
{0x067E, X86_MARCH_ICELAKE, X86_GRADE_MOBILE},
|
||||
{0x0685, X86_MARCH_KNIGHTSMILL, X86_GRADE_SCIENCE},
|
||||
{0x0686, X86_MARCH_TREMONT, X86_GRADE_APPLIANCE},
|
||||
{0x068C, X86_MARCH_TIGERLAKE, X86_GRADE_MOBILE},
|
||||
{0x068D, X86_MARCH_TIGERLAKE, X86_GRADE_CLIENT},
|
||||
{0x068E, X86_MARCH_KABYLAKE, X86_GRADE_MOBILE},
|
||||
{0x0696, X86_MARCH_TREMONT, X86_GRADE_APPLIANCE},
|
||||
{0x069D, X86_MARCH_ICELAKE, X86_GRADE_SCIENCE},
|
||||
{0x069E, X86_MARCH_KABYLAKE, X86_GRADE_CLIENT},
|
||||
/* </SORTED> */
|
||||
};
|
||||
|
||||
const size_t kX86ProcessorModelCount = ARRAYLEN(kX86ProcessorModels);
|
67
libc/nexgen32e/llog10.S
Normal file
67
libc/nexgen32e/llog10.S
Normal file
|
@ -0,0 +1,67 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
/ Fast log₁₀ when 𝑥 is an integer.
|
||||
/
|
||||
/ @param rdi is uint64 𝑥
|
||||
/ @domain 0<𝑥<2⁶⁴ ∧ 𝑥∊ℤ
|
||||
llog10: .leafprologue
|
||||
.profilable
|
||||
bsr %rdi,%rax
|
||||
jz 3f
|
||||
lea llog10data(%rip),%rdx
|
||||
movsbl 1(%rdx,%rax),%eax
|
||||
cmp 2f-1f(%rdx,%rax,8),%rdi
|
||||
sbb $0,%al
|
||||
jmp 4f
|
||||
3: xor %eax,%eax # domain error
|
||||
4: .leafepilogue
|
||||
.endfn llog10,globl
|
||||
|
||||
.rodata
|
||||
llog10data:
|
||||
1: .byte 0, 0, 0, 0, 1, 1, 1, 2, 2, 2, 3, 3, 3, 3, 4, 4
|
||||
.byte 4, 5, 5, 5, 6, 6, 6, 6, 7, 7, 7, 8, 8, 8, 9, 9
|
||||
.byte 9, 9,10,10,10,11,11,11,12,12,12,12,13,13,13,14
|
||||
.byte 14,14,15,15,15,15,16,16,16,17,17,17,18,18,18,18
|
||||
.byte 19,19,19
|
||||
.align 8
|
||||
2: .quad 0
|
||||
.quad 10
|
||||
.quad 100
|
||||
.quad 1000
|
||||
.quad 10000
|
||||
.quad 100000
|
||||
.quad 1000000
|
||||
.quad 10000000
|
||||
.quad 100000000
|
||||
.quad 1000000000
|
||||
.quad 10000000000
|
||||
.quad 100000000000
|
||||
.quad 1000000000000
|
||||
.quad 10000000000000
|
||||
.quad 100000000000000
|
||||
.quad 1000000000000000
|
||||
.quad 10000000000000000
|
||||
.quad 100000000000000000
|
||||
.endobj llog10data
|
||||
.previous
|
||||
.yoink __FILE__
|
46
libc/nexgen32e/loadxmm.S
Normal file
46
libc/nexgen32e/loadxmm.S
Normal file
|
@ -0,0 +1,46 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
.privileged
|
||||
|
||||
/ Loads XMM registers from buffer.
|
||||
/
|
||||
/ @param %rdi points to &(aligned(16) uint8_t[256])[128]
|
||||
/ @note modern cpus have out-of-order execution engines
|
||||
loadxmm:.leafprologue
|
||||
movaps -0x80(%rdi),%xmm0
|
||||
movaps -0x70(%rdi),%xmm1
|
||||
movaps -0x60(%rdi),%xmm2
|
||||
movaps -0x50(%rdi),%xmm3
|
||||
movaps -0x40(%rdi),%xmm4
|
||||
movaps -0x30(%rdi),%xmm5
|
||||
movaps -0x20(%rdi),%xmm6
|
||||
movaps -0x10(%rdi),%xmm7
|
||||
movaps 0x00(%rdi),%xmm8
|
||||
movaps 0x10(%rdi),%xmm9
|
||||
movaps 0x20(%rdi),%xmm10
|
||||
movaps 0x30(%rdi),%xmm11
|
||||
movaps 0x40(%rdi),%xmm12
|
||||
movaps 0x50(%rdi),%xmm13
|
||||
movaps 0x60(%rdi),%xmm14
|
||||
movaps 0x70(%rdi),%xmm15
|
||||
.leafepilogue
|
||||
.endfn loadxmm,globl,hidden
|
||||
.yoink __FILE__
|
79
libc/nexgen32e/lolendian.S
Normal file
79
libc/nexgen32e/lolendian.S
Normal file
|
@ -0,0 +1,79 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
/ @fileoverview Byte-order conversion functions.
|
||||
/
|
||||
/ Endianness is deceptively complicated to the uninitiated. Many
|
||||
/ helpers have been written by our top minds to address perceived
|
||||
/ difficulties. These ones got through standardization processes.
|
||||
/ To protect their legacy, all 19 functions have been implemented
|
||||
/ in just 17 bytes.
|
||||
/
|
||||
/ @asyncsignalsafe
|
||||
/ @see read32le(), read32be(), etc.
|
||||
|
||||
bswap_64:
|
||||
htobe64:
|
||||
htole64:
|
||||
be64toh:
|
||||
le64toh:mov %rdi,%rax
|
||||
bswap %rax
|
||||
ret
|
||||
.endfn le64toh,globl
|
||||
.endfn be64toh,globl
|
||||
.endfn htole64,globl
|
||||
.endfn htobe64,globl
|
||||
.endfn bswap_64,globl
|
||||
|
||||
bswap_32:
|
||||
htobe32:
|
||||
htole32:
|
||||
be32toh:
|
||||
le32toh:
|
||||
ntohl:
|
||||
htonl: mov %edi,%eax
|
||||
bswap %eax
|
||||
ret
|
||||
.endfn htonl,globl
|
||||
.endfn htole32,globl
|
||||
.endfn le32toh,globl
|
||||
.endfn be32toh,globl
|
||||
.endfn htobe32,globl
|
||||
.endfn ntohl,globl
|
||||
.endfn bswap_32,globl
|
||||
|
||||
bswap_16:
|
||||
htobe16:
|
||||
htole16:
|
||||
be16toh:
|
||||
le16toh:
|
||||
ntohs:
|
||||
htons: movzwl %di,%eax
|
||||
xchg %al,%ah
|
||||
ret
|
||||
.endfn htobe16,globl
|
||||
.endfn htons,globl
|
||||
.endfn le16toh,globl
|
||||
.endfn be16toh,globl
|
||||
.endfn htole16,globl
|
||||
.endfn ntohs,globl
|
||||
.endfn bswap_16,globl
|
||||
.yoink __FILE__
|
44
libc/nexgen32e/longjmp.S
Normal file
44
libc/nexgen32e/longjmp.S
Normal file
|
@ -0,0 +1,44 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
.privileged
|
||||
|
||||
/ Loads previously saved processor state.
|
||||
/
|
||||
/ @param rdi points to the jmp_buf
|
||||
/ @param esi is returned by setjmp() invocation (coerced nonzero)
|
||||
/ @noreturn
|
||||
/ @assume system five nexgen32e abi conformant
|
||||
/ @note code built w/ microsoft abi compiler can't call this
|
||||
/ @see gclongjmp() unwinds gc() destructors
|
||||
longjmp:mov %esi,%eax
|
||||
test %eax,%eax
|
||||
jnz 1f
|
||||
inc %eax
|
||||
1: mov (%rdi),%rsp
|
||||
mov 8(%rdi),%rbx
|
||||
mov 16(%rdi),%rbp
|
||||
mov 24(%rdi),%r12
|
||||
mov 32(%rdi),%r13
|
||||
mov 40(%rdi),%r14
|
||||
mov 48(%rdi),%r15
|
||||
jmp *56(%rdi)
|
||||
.endfn longjmp,globl
|
||||
.yoink __FILE__
|
78
libc/nexgen32e/lz4.h
Normal file
78
libc/nexgen32e/lz4.h
Normal file
|
@ -0,0 +1,78 @@
|
|||
#ifndef COSMOPOLITAN_LIBC_LZ4_H_
|
||||
#define COSMOPOLITAN_LIBC_LZ4_H_
|
||||
#include "libc/bits/bits.h"
|
||||
#if 0
|
||||
/*───────────────────────────────────────────────────────────────────────────│─╗
|
||||
│ cosmopolitan § lz4 ─╬─│┼
|
||||
╚────────────────────────────────────────────────────────────────────────────│─╝
|
||||
LZ4 is a framing format for REP MOVSB designed by Yann Collet.
|
||||
|
||||
@see https://github.com/lz4/lz4/blob/master/doc/lz4_Frame_format.md
|
||||
@see https://github.com/lz4/lz4/blob/master/doc/lz4_Block_format.md
|
||||
@see http://ticki.github.io/blog/how-lz4-works/ */
|
||||
#endif
|
||||
|
||||
#define LZ4_EOF 0
|
||||
#define LZ4_VERSION 1
|
||||
#define LZ4_MAGICNUMBER 0x184D2204
|
||||
#define LZ4_SKIPPABLE0 0x184D2A50
|
||||
#define LZ4_SKIPPABLEMASK 0xFFFFFFF0
|
||||
#define LZ4_MAXHEADERSIZE (MAGICNUMBER_SIZE + 2 + 8 + 4 + 1)
|
||||
#define LZ4_BLOCKMAXSIZE_64KB 4
|
||||
#define LZ4_BLOCKMAXSIZE_256KB 5
|
||||
#define LZ4_BLOCKMAXSIZE_1MB 6
|
||||
#define LZ4_BLOCKMAXSIZE_4MB 7
|
||||
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
#if 0
|
||||
/*───────────────────────────────────────────────────────────────────────────│─╗
|
||||
│ cosmopolitan § lz4 » frames ─╬─│┼
|
||||
╚────────────────────────────────────────────────────────────────────────────│*/
|
||||
#endif
|
||||
|
||||
#define LZ4_MAGIC(FRAME) read32le(FRAME)
|
||||
#define LZ4_FRAME_VERSION(FRAME) ((_LZ4_FRAME_FLG(FRAME) >> 6) & 0b11)
|
||||
#define LZ4_FRAME_BLOCKINDEPENDENCE(FRAME) ((_LZ4_FRAME_FLG(FRAME) >> 5) & 1)
|
||||
#define LZ4_FRAME_BLOCKCHECKSUMFLAG(FRAME) ((_LZ4_FRAME_FLG(FRAME) >> 4) & 1)
|
||||
#define LZ4_FRAME_BLOCKCONTENTSIZEFLAG(FRAME) ((_LZ4_FRAME_FLG(FRAME) >> 3) & 1)
|
||||
#define LZ4_FRAME_BLOCKCONTENTCHECKSUMFLAG(FRAME) \
|
||||
((_LZ4_FRAME_FLG(FRAME) >> 2) & 1)
|
||||
#define LZ4_FRAME_DICTIONARYIDFLAG(FRAME) ((_LZ4_FRAME_FLG(FRAME) >> 0) & 1)
|
||||
#define LZ4_FRAME_BLOCKMAXSIZE(FRAME) ((_LZ4_FRAME_BD(FRAME) >> 4) & 0b111)
|
||||
#define LZ4_FRAME_RESERVED1(FRAME) ((_LZ4_FRAME_FLG(FRAME) >> 1) & 1)
|
||||
#define LZ4_FRAME_RESERVED2(FRAME) ((_LZ4_FRAME_BD(FRAME) >> 7) & 1)
|
||||
#define LZ4_FRAME_RESERVED3(FRAME) ((_LZ4_FRAME_BD(FRAME) >> 0) & 0b1111)
|
||||
#define LZ4_FRAME_BLOCKCONTENTSIZE(FRAME) \
|
||||
(LZ4_FRAME_BLOCKCONTENTSIZEFLAG(FRAME) ? read64le((FRAME) + 4 + 1 + 1) : 0)
|
||||
#define LZ4_FRAME_DICTIONARYID(FRAME) \
|
||||
(LZ4_FRAME_DICTIONARYIDFLAG(FRAME) \
|
||||
? read32le(((FRAME) + 4 + 1 + 1 + \
|
||||
8 * LZ4_FRAME_BLOCKCONTENTSIZEFLAG(FRAME))) \
|
||||
: 0)
|
||||
#define LZ4_FRAME_HEADERCHECKSUM(FRAME) \
|
||||
(*((FRAME) + 4 + 1 + 1 + 8 * LZ4_FRAME_BLOCKCONTENTSIZEFLAG(FRAME) + \
|
||||
4 * LZ4_FRAME_DICTIONARYIDFLAG(FRAME)))
|
||||
#define LZ4_FRAME_HEADERSIZE(FRAME) \
|
||||
(4 + 1 + 1 + 8 * LZ4_FRAME_BLOCKCONTENTSIZEFLAG(FRAME) + \
|
||||
4 * LZ4_FRAME_DICTIONARYIDFLAG(FRAME) + 1)
|
||||
#define _LZ4_FRAME_FLG(FRAME) (*((FRAME) + 4))
|
||||
#define _LZ4_FRAME_BD(FRAME) (*((FRAME) + 5))
|
||||
|
||||
#if 0
|
||||
/*───────────────────────────────────────────────────────────────────────────│─╗
|
||||
│ cosmopolitan § lz4 » blocks ─╬─│┼
|
||||
╚────────────────────────────────────────────────────────────────────────────│*/
|
||||
#endif
|
||||
|
||||
#define LZ4_BLOCK_DATA(block) (block + sizeof(uint32_t))
|
||||
#define LZ4_BLOCK_DATASIZE(block) (read32le(block) & 0x7fffffff)
|
||||
#define LZ4_BLOCK_ISEOF(block) (read32le(block) == LZ4_EOF)
|
||||
#define LZ4_BLOCK_ISCOMPRESSED(block) ((read32le(block) & 0x80000000) == 0)
|
||||
#define LZ4_BLOCK_SIZE(frame, block) \
|
||||
(sizeof(uint32_t) + LZ4_BLOCK_DATASIZE(block) + \
|
||||
(LZ4_FRAME_BLOCKCHECKSUMFLAG(frame) ? sizeof(uint8_t) : 0))
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_LZ4_H_ */
|
34
libc/nexgen32e/lz4check.c
Normal file
34
libc/nexgen32e/lz4check.c
Normal file
|
@ -0,0 +1,34 @@
|
|||
/*-*- 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/nexgen32e/kompressor.h"
|
||||
#include "libc/nexgen32e/lz4.h"
|
||||
|
||||
const unsigned char *lz4check(const void *data) {
|
||||
const unsigned char *frame = data;
|
||||
if (LZ4_MAGIC(frame) == LZ4_MAGICNUMBER && LZ4_FRAME_VERSION(frame) == 1 &&
|
||||
LZ4_FRAME_BLOCKINDEPENDENCE(frame) == true &&
|
||||
LZ4_FRAME_BLOCKCONTENTSIZEFLAG(frame) == true &&
|
||||
LZ4_FRAME_RESERVED1(frame) == 0 && LZ4_FRAME_RESERVED2(frame) == 0 &&
|
||||
LZ4_FRAME_RESERVED3(frame) == 0) {
|
||||
return frame;
|
||||
} else {
|
||||
return NULL;
|
||||
}
|
||||
}
|
61
libc/nexgen32e/lz4cpy.c
Normal file
61
libc/nexgen32e/lz4cpy.c
Normal file
|
@ -0,0 +1,61 @@
|
|||
/*-*- 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/bits/bits.h"
|
||||
#include "libc/bits/pushpop.h"
|
||||
#include "libc/intrin/repmovsb.h"
|
||||
#include "libc/nexgen32e/kompressor.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
/**
|
||||
* Decompresses LZ4 block.
|
||||
*
|
||||
* This is a 103 byte implementation of the LZ4 algorithm. Please note
|
||||
* LZ4 files are comprised of multiple frames, which may be decoded
|
||||
* together using the wrapper function lz4decode().
|
||||
*
|
||||
* @see rldecode() for a 16-byte decompressor
|
||||
*/
|
||||
textstartup void *lz4cpy(void *dest, const void *blockdata, size_t blocksize) {
|
||||
unsigned char *op, *ip, *ipe, *match;
|
||||
unsigned token, length, fifteen, offset, matchlen;
|
||||
for (op = dest, ip = blockdata, ipe = ip + blocksize;;) {
|
||||
token = *ip++;
|
||||
length = token >> 4;
|
||||
fifteen = pushpop(15);
|
||||
if (length == fifteen) {
|
||||
do {
|
||||
length += *ip;
|
||||
} while (*ip++ == 255);
|
||||
}
|
||||
repmovsb(&op, &ip, length);
|
||||
if (ip >= ipe) break;
|
||||
offset = read16le(ip);
|
||||
matchlen = token & fifteen;
|
||||
ip += 2;
|
||||
if (matchlen == fifteen) {
|
||||
do {
|
||||
matchlen += *ip;
|
||||
} while (*ip++ == 255);
|
||||
}
|
||||
match = op - offset;
|
||||
repmovsb(&op, &match, (matchlen += 4));
|
||||
}
|
||||
return op;
|
||||
}
|
50
libc/nexgen32e/lz4decode.c
Normal file
50
libc/nexgen32e/lz4decode.c
Normal file
|
@ -0,0 +1,50 @@
|
|||
/*-*- 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/nexgen32e/kompressor.h"
|
||||
#include "libc/nexgen32e/lz4.h"
|
||||
#include "libc/str/str.h"
|
||||
|
||||
/**
|
||||
* Decompresses LZ4 file.
|
||||
*
|
||||
* We assume (1) the file is mmap()'d or was copied into into memory
|
||||
* beforehand; and (2) folks handling untrustworthy data shall place
|
||||
* 64kb of guard pages on the ends of each buffer, see mapanon(). We
|
||||
* don't intend to support XXHASH; we recommend folks needing checks
|
||||
* against data corruption consider crc32c(), or gzip since it's the
|
||||
* best at file recovery. Dictionaries are supported; by convention,
|
||||
* they are passed in the ≤64kb bytes preceding src.
|
||||
*
|
||||
* @return pointer to end of decoded data, similar to mempcpy()
|
||||
* @see mapanon(), lz4check()
|
||||
*/
|
||||
void *lz4decode(void *dest, const void *src) {
|
||||
const unsigned char *frame, *block;
|
||||
frame = (const unsigned char *)src;
|
||||
for (block = frame + LZ4_FRAME_HEADERSIZE(frame); !LZ4_BLOCK_ISEOF(block);
|
||||
block += LZ4_BLOCK_SIZE(frame, block)) {
|
||||
if (LZ4_BLOCK_ISCOMPRESSED(block)) {
|
||||
dest = lz4cpy(dest, LZ4_BLOCK_DATA(block), LZ4_BLOCK_DATASIZE(block));
|
||||
} else {
|
||||
dest = mempcpy(dest, LZ4_BLOCK_DATA(block), LZ4_BLOCK_DATASIZE(block));
|
||||
}
|
||||
}
|
||||
return dest;
|
||||
}
|
47
libc/nexgen32e/lzcnt.S
Normal file
47
libc/nexgen32e/lzcnt.S
Normal file
|
@ -0,0 +1,47 @@
|
|||
/*-*- mode:asm; 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 │
|
||||
│ │
|
||||
│ This program is free software; you can redistribute it and/or modify │
|
||||
│ it under the terms of the GNU General Public License as published by │
|
||||
│ the Free Software Foundation; version 2 of the License. │
|
||||
│ │
|
||||
│ This program is distributed in the hope that it will be useful, but │
|
||||
│ WITHOUT ANY WARRANTY; without even the implied warranty of │
|
||||
│ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU │
|
||||
│ General Public License for more details. │
|
||||
│ │
|
||||
│ You should have received a copy of the GNU General Public License │
|
||||
│ along with this program; if not, write to the Free Software │
|
||||
│ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA │
|
||||
│ 02110-1301 USA │
|
||||
╚─────────────────────────────────────────────────────────────────────────────*/
|
||||
#include "libc/macros.h"
|
||||
|
||||
/ Finds leading bits in 𝑥.
|
||||
/
|
||||
/ @param edi is 32-bit unsigned 𝑥 value
|
||||
/ @return eax number in range [0,32) or 32 if 𝑥 is 0
|
||||
/ @see also treasure trove of nearly identical functions
|
||||
/
|
||||
/ uint32 𝑥 bsf(𝑥) tzcnt(𝑥) ffs(𝑥) bsr(𝑥) lzcnt(𝑥)
|
||||
/ 0x00000000 wut 32 0 wut 32
|
||||
/ 0x00000001 0 0 1 0 31
|
||||
/ 0x80000001 0 0 1 31 0
|
||||
/ 0x80000000 31 31 32 31 0
|
||||
/ 0x00000010 4 4 5 4 27
|
||||
/ 0x08000010 4 4 5 27 4
|
||||
/ 0x08000000 27 27 28 27 4
|
||||
/ 0xffffffff 0 0 1 31 0
|
||||
/
|
||||
lzcnt: .leafprologue
|
||||
.profilable
|
||||
mov $31,%eax
|
||||
mov $-1,%edx
|
||||
bsr %edi,%ecx
|
||||
cmovz %edx,%ecx
|
||||
sub %ecx,%eax
|
||||
.leafepilogue
|
||||
.endfn lzcnt,globl
|
||||
.yoink __FILE__
|
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue