mirror of
https://github.com/jart/cosmopolitan.git
synced 2025-07-29 14:00:29 +00:00
Add pseudoteletypewriter to emulator
https://justine.storage.googleapis.com/emulator628.mp4
This commit is contained in:
parent
e86cff8ba0
commit
5aabacb361
94 changed files with 3245 additions and 2179 deletions
24
libc/nexgen32e/bsf.c
Normal file
24
libc/nexgen32e/bsf.c
Normal file
|
@ -0,0 +1,24 @@
|
|||
/*-*- 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/bsf.h"
|
||||
|
||||
int(bsf)(int x) {
|
||||
return bsf(x);
|
||||
}
|
|
@ -17,12 +17,15 @@ COSMOPOLITAN_C_START_
|
|||
* 0xffffffff 0 0 1 31 0
|
||||
*/
|
||||
|
||||
int bsf(int);
|
||||
int bsfl(long);
|
||||
int bsfll(long long);
|
||||
int bsfmax(uintmax_t);
|
||||
|
||||
#define bsf(u) __builtin_ctz(u)
|
||||
#define bsfl(u) __builtin_ctzl(u)
|
||||
#define bsfll(u) __builtin_ctzll(u)
|
||||
|
||||
unsigned bsfmax(uintmax_t);
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_NEXGEN32E_BSF_H_ */
|
||||
|
|
24
libc/nexgen32e/bsfl.c
Normal file
24
libc/nexgen32e/bsfl.c
Normal file
|
@ -0,0 +1,24 @@
|
|||
/*-*- 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/bsf.h"
|
||||
|
||||
int(bsfl)(long x) {
|
||||
return bsfl(x);
|
||||
}
|
24
libc/nexgen32e/bsfll.c
Normal file
24
libc/nexgen32e/bsfll.c
Normal file
|
@ -0,0 +1,24 @@
|
|||
/*-*- 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/bsf.h"
|
||||
|
||||
int(bsfll)(long long x) {
|
||||
return bsfll(x);
|
||||
}
|
24
libc/nexgen32e/bsr.c
Normal file
24
libc/nexgen32e/bsr.c
Normal file
|
@ -0,0 +1,24 @@
|
|||
/*-*- 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/bsr.h"
|
||||
|
||||
int(bsr)(int x) {
|
||||
return bsr(x);
|
||||
}
|
|
@ -17,11 +17,14 @@ COSMOPOLITAN_C_START_
|
|||
* 0xffffffff 0 0 1 31 0
|
||||
*/
|
||||
|
||||
#define bsr(u) ((sizeof(unsigned) * 8 - 1) ^ __builtin_clz(u))
|
||||
#define bsrl(u) ((sizeof(unsigned long) * 8 - 1) ^ __builtin_clzl(u))
|
||||
#define bsrll(u) ((sizeof(unsigned long long) * 8 - 1) ^ __builtin_clzll(u))
|
||||
int bsr(int);
|
||||
int bsrl(long);
|
||||
int bsrll(long long);
|
||||
int bsrmax(uintmax_t);
|
||||
|
||||
unsigned bsrmax(uintmax_t);
|
||||
#define bsr(u) ((sizeof(int) * 8 - 1) ^ __builtin_clz(u))
|
||||
#define bsrl(u) ((sizeof(long) * 8 - 1) ^ __builtin_clzl(u))
|
||||
#define bsrll(u) ((sizeof(long long) * 8 - 1) ^ __builtin_clzll(u))
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
|
|
24
libc/nexgen32e/bsrl.c
Normal file
24
libc/nexgen32e/bsrl.c
Normal file
|
@ -0,0 +1,24 @@
|
|||
/*-*- 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/bsr.h"
|
||||
|
||||
int(bsrl)(long x) {
|
||||
return bsrl(x);
|
||||
}
|
24
libc/nexgen32e/bsrll.c
Normal file
24
libc/nexgen32e/bsrll.c
Normal file
|
@ -0,0 +1,24 @@
|
|||
/*-*- 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/bsr.h"
|
||||
|
||||
int(bsrll)(long long x) {
|
||||
return bsrll(x);
|
||||
}
|
2327
libc/nexgen32e/djbsort-avx2.S
Normal file
2327
libc/nexgen32e/djbsort-avx2.S
Normal file
File diff suppressed because it is too large
Load diff
35
libc/nexgen32e/djbsort.c
Normal file
35
libc/nexgen32e/djbsort.c
Normal file
|
@ -0,0 +1,35 @@
|
|||
/*-*- 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/alg.h"
|
||||
#include "libc/nexgen32e/nexgen32e.h"
|
||||
#include "libc/nexgen32e/x86feature.h"
|
||||
|
||||
void djbsort$avx2(int32_t *, long);
|
||||
|
||||
/**
|
||||
* D.J. Bernstein's outrageously fast integer sorting algorithm.
|
||||
*/
|
||||
void djbsort(size_t n, int32_t a[n]) {
|
||||
if (X86_HAVE(AVX2)) {
|
||||
djbsort$avx2(a, n);
|
||||
} else {
|
||||
insertionsort(n, a);
|
||||
}
|
||||
}
|
|
@ -49,11 +49,11 @@ CollectGarbage:
|
|||
sub $0x20,%rsp
|
||||
push %rax
|
||||
push %rdx
|
||||
movaps %xmm0,-0x20(%rbp)
|
||||
movaps %xmm1,-0x10(%rbp)
|
||||
movdqa %xmm0,-0x20(%rbp)
|
||||
movdqa %xmm1,-0x10(%rbp)
|
||||
call *%r9
|
||||
movaps -0x10(%rbp),%xmm1
|
||||
movaps -0x20(%rbp),%xmm0
|
||||
movdqa -0x10(%rbp),%xmm1
|
||||
movdqa -0x20(%rbp),%xmm0
|
||||
pop %rdx
|
||||
pop %rax
|
||||
leave
|
||||
|
|
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;
|
||||
}
|
||||
}
|
|
@ -70,7 +70,7 @@ kCpuids:.long 0,0,0,0 # EAX=0 (Basic Processor Info)
|
|||
add $4*4,%rdi
|
||||
jmp 2b
|
||||
3: nop
|
||||
#if 0 && !X86_NEED(AVX2)
|
||||
#if !X86_NEED(AVX2)
|
||||
testb X86_HAVE(AVX)(%r8)
|
||||
jz 5f
|
||||
testb X86_HAVE(OSXSAVE)(%r8)
|
||||
|
|
|
@ -17,8 +17,8 @@
|
|||
#define X86_AES 1H, ECX, 25, _X86_CC_AES, _ /* westmere c. 2010 */
|
||||
#define X86_APIC 1H, EDX, 9, 0, _
|
||||
#define X86_ARCH_CAPABILITIES 7H, EDX, 29, 0, _
|
||||
#define X86_AVX 1H, ECX, 28, _X86_CC_AVX, AVX /* sandybridge c. 2012 */
|
||||
#define X86_AVX2 7H, EBX, 5, _X86_CC_AVX2, AVX /* haswell c. 2013 */
|
||||
#define X86_AVX 1H, ECX, 28, _X86_CC_AVX, _ /* sandybridge c. 2012 */
|
||||
#define X86_AVX2 7H, EBX, 5, _X86_CC_AVX2, _ /* haswell c. 2013 */
|
||||
#define X86_AVX512BW 7H, EBX, 30, 0, _
|
||||
#define X86_AVX512CD 7H, EBX, 28, 0, _
|
||||
#define X86_AVX512DQ 7H, EBX, 17, 0, _
|
||||
|
@ -246,17 +246,5 @@
|
|||
#endif
|
||||
|
||||
#define _X86_HOOK__(X) X
|
||||
#define _X86_HOOK_AVX(X) \
|
||||
({ \
|
||||
YOINK(_init_enableavx); \
|
||||
X; \
|
||||
})
|
||||
|
||||
#if !(__ASSEMBLER__ + __LINKER__ + 0)
|
||||
COSMOPOLITAN_C_START_
|
||||
|
||||
int _init_enableavx(void) pureconst;
|
||||
|
||||
COSMOPOLITAN_C_END_
|
||||
#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */
|
||||
#endif /* COSMOPOLITAN_LIBC_NEXGEN32E_X86FEATURE_H_ */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue