Justine Tunney 2 years ago
parent
commit
5aabacb361
  1. 2
      dsp/tty/tty.h
  2. 4
      dsp/tty/ttyraw.c
  3. 2
      dsp/tty/write.c
  4. 4
      examples/hello2.c
  5. 83
      libc/fmt/unbing.c
  6. 9
      libc/integral/c.inc
  7. 29
      libc/log/log.h
  8. 4
      libc/log/vflogf.c
  9. 24
      libc/nexgen32e/bsf.c
  10. 7
      libc/nexgen32e/bsf.h
  11. 24
      libc/nexgen32e/bsfl.c
  12. 24
      libc/nexgen32e/bsfll.c
  13. 24
      libc/nexgen32e/bsr.c
  14. 11
      libc/nexgen32e/bsr.h
  15. 24
      libc/nexgen32e/bsrl.c
  16. 24
      libc/nexgen32e/bsrll.c
  17. 0
      libc/nexgen32e/djbsort-avx2.S
  18. 4
      libc/nexgen32e/djbsort.c
  19. 8
      libc/nexgen32e/gc.S
  20. 0
      libc/nexgen32e/insertionsort.greg.c
  21. 2
      libc/nexgen32e/kcpuids.S
  22. 16
      libc/nexgen32e/x86feature.h
  23. 5
      libc/runtime/construct.S
  24. 9
      libc/runtime/cxaatexit.c
  25. 2
      libc/runtime/mmap.c
  26. 1
      libc/runtime/runtime.mk
  27. 5
      libc/runtime/spawn.S
  28. 7
      libc/str/str.h
  29. 8
      libc/str/thompike.h
  30. 2
      libc/sysv/consts.sh
  31. 5
      libc/tinymath/fpclassify.S
  32. 5
      libc/tinymath/fpclassifyf.S
  33. 5
      libc/tinymath/fpclassifyl.S
  34. 4
      libc/tinymath/scalbn.S
  35. 4
      libc/tinymath/scalbnf.S
  36. 3
      libc/tinymath/scalbnl.S
  37. 2
      test/libc/fmt/test.mk
  38. 160
      test/libc/intrin/intrin_test.c
  39. 1
      test/libc/runtime/test.mk
  40. 18
      test/tool/build/lib/bitscan_test.c
  41. 48
      test/tool/build/lib/divmul_test.c
  42. 17
      test/tool/build/lib/modrm_test.c
  43. 2
      third_party/compiler_rt/divmodti4.c
  44. 7
      third_party/xed/x86.h
  45. 8
      third_party/xed/x86ild.greg.c
  46. 2
      tool/build/emucrt/emucrt.S
  47. 2
      tool/build/emucrt/emucrt.lds
  48. 2
      tool/build/emucrt/emucrt.mk
  49. 541
      tool/build/emulator.c
  50. 6
      tool/build/lib/alu.h
  51. 14
      tool/build/lib/bitscan.c
  52. 6
      tool/build/lib/bitscan.h
  53. 8
      tool/build/lib/breakpoint.c
  54. 3
      tool/build/lib/breakpoint.h
  55. 10
      tool/build/lib/buffer.c
  56. 1
      tool/build/lib/buildlib.mk
  57. 204
      tool/build/lib/cvt.c
  58. 2
      tool/build/lib/cvt.h
  59. 1
      tool/build/lib/dis.c
  60. 130
      tool/build/lib/disarg.c
  61. 63
      tool/build/lib/disinst.c
  62. 218
      tool/build/lib/disspec.c
  63. 107
      tool/build/lib/divmul.c
  64. 20
      tool/build/lib/divmul.h
  65. 55
      tool/build/lib/fds.c
  66. 27
      tool/build/lib/fds.h
  67. 100
      tool/build/lib/fpu.c
  68. 29
      tool/build/lib/fpu.h
  69. 0
      tool/build/lib/init.c
  70. 29
      tool/build/lib/ioports.c
  71. 1839
      tool/build/lib/machine.c
  72. 2
      tool/build/lib/machine.h
  73. 214
      tool/build/lib/modrm.c
  74. 136
      tool/build/lib/modrm.h
  75. 512
      tool/build/lib/pty.c
  76. 50
      tool/build/lib/pty.h
  77. 24
      tool/build/lib/reset.c
  78. 42
      tool/build/lib/sse.c
  79. 6
      tool/build/lib/sse.h
  80. 22
      tool/build/lib/stack.c
  81. 5
      tool/build/lib/stack.h
  82. 38
      tool/build/lib/string.c
  83. 6
      tool/build/lib/string.h
  84. 129
      tool/build/lib/syscall.c
  85. 2
      tool/build/lib/syscall.h
  86. 65
      tool/build/lib/time.c
  87. 11
      tool/build/lib/time.h
  88. 1
      tool/build/tinyemu.c
  89. 1
      tool/emacs/cosmo-c-keywords.el
  90. 41
      tool/viz/lib/ansitrinsics.h
  91. 12
      tool/viz/lib/scale.h
  92. 1
      tool/viz/lib/ycbcr2rgb3.c
  93. 1
      tool/viz/magikarp.c
  94. 23
      tool/viz/printimage.c

2
dsp/tty/tty.h

@ -39,7 +39,7 @@ int ttyrestorecursor(int); @@ -39,7 +39,7 @@ int ttyrestorecursor(int);
int ttyenablealtbuf(int);
int ttydisablealtbuf(int);
int ttysend(int, const char *);
int ttywrite(int, const void *, size_t);
ssize_t ttywrite(int, const void *, size_t);
int ttysendtitle(int, const char *, const struct TtyIdent *);
int ttyident(struct TtyIdent *, int, int);
void ttyidentclear(struct TtyIdent *);

4
dsp/tty/ttyraw.c

@ -101,7 +101,9 @@ static relegated void ttyraw_onsig(int sig, struct siginfo *info, @@ -101,7 +101,9 @@ static relegated void ttyraw_onsig(int sig, struct siginfo *info,
if (g_ttyraw.sigs[i] == sig) {
if (g_ttyraw.next[i] != SIG_IGN) {
if (g_ttyraw.next[i] != SIG_DFL) {
g_ttyraw.next[i](sig, info, ctx);
if (g_ttyraw.next[i]) {
g_ttyraw.next[i](sig, info, ctx);
}
} else if (sig != SIGCONT) {
_Exit(128 + sig);
}

2
dsp/tty/write.c

@ -35,7 +35,7 @@ @@ -35,7 +35,7 @@
*
* @return 0 on success, or -1 w/ errno
*/
int ttywrite(int fd, const void *data, size_t size) {
ssize_t ttywrite(int fd, const void *data, size_t size) {
char *p;
ssize_t rc;
size_t wrote, n;

4
examples/hello2.c

@ -7,11 +7,11 @@ @@ -7,11 +7,11 @@
http://creativecommons.org/publicdomain/zero/1.0/ │
*/
#endif
#include "libc/str/str.h"
#include "libc/calls/calls.h"
#include "libc/str/str.h"
#include "libc/sysv/consts/fileno.h"
#define kMessage "hello world\r\n"
#define kMessage "hello \e[1mworld\e[0m\r\n"
int main() {
/*

83
libc/fmt/unbing.c

@ -18,42 +18,36 @@ @@ -18,42 +18,36 @@
02110-1301 USA
*/
#include "libc/alg/alg.h"
#include "libc/fmt/bing.h"
#include "libc/log/log.h"
#include "libc/macros.h"
#include "libc/nexgen32e/nexgen32e.h"
#include "libc/str/str.h"
#define ALTCOUNT 21
static const struct Cp437Multimappings {
unsigned char b[ALTCOUNT];
char16_t c[ALTCOUNT];
} kCp437iMultimappings = {
#define ALT(I, C, B) .c[I] = C, .b[I] = B
ALT(0, u'\n', '\n'),
ALT(1, u'\r', '\r'),
ALT(2, u'?', '?'), /* TRIGRAPH */
ALT(3, u'\'', '\''), /* CHARACTER LITERAL */
ALT(4, u'\"', '\"'), /* STRING LITERAL */
ALT(5, u'\\', '\\'), /* ESCAPE LITERAL */
ALT(6, u'', '\0'), /* EMPTY SET */
ALT(7, u'', '\0'), /* SYMBOL FOR NULL [sic] */
ALT(7, 0x20A7, 0x9E), /* PESETA SIGN */
ALT(8, u'Π' /* 03A0: GREEK CAPITAL LETTER PI */, 0xE3),
ALT(9, u'' /* 220F: N-ARY PRODUCT */, 0xE3),
ALT(10, u'' /* 2211: N-ARY SUMMATION */, 0xE4),
ALT(11, u'µ' /* 03BC: MICRO SIGN */, 0xE6),
ALT(12, u'' /* 2126: OHM SIGN */, 0xEA),
ALT(13, u'' /* 2202: PARTIAL DIFFERENTIAL */, 0xEB),
ALT(14, u'ε' /* 03D5: PHI SMALL (CLOSED FORM) */, 0xED),
ALT(15, u'ϕ' /* 03D5: PHI SMALL (CLOSED FORM) */, 0xED),
ALT(16, u'' /* 2208: ELEMENT-OF SIGN */, 0xED),
ALT(17, u'' /* 220A: SMALL ELEMENT OF */, 0xEE),
ALT(18, u'' /* 03B5: ELEMENT-OF SIGN */, 0xEE),
ALT(19, u'β' /* 03B2: GREEK SMALL BETA */, 0xE1),
ALT(20, u'ſ' /* 017F: LATIN SMALL LETTER LONG S */, 0xF4),
#undef ALT
static const int kCp437iMultimappings[] = {
u'\n' << 8 | '\n', // NEWLINE
u'\r' << 8 | '\r', // CARRIAGE RETURN
u'?' << 8 | '?', // TRIGRAPH
u'\'' << 8 | '\'', // CHARACTER LITERAL
u'\"' << 8 | '\"', // STRING LITERAL
u'\\' << 8 | '\\', // ESCAPE LITERAL
u'' << 8 | '\0', // EMPTY SET
u'' << 8 | '\0', // SYMBOL FOR NULL [sic]
0x20A7 << 8 | 0x9E, // PESETA SIGN
u'Π' << 8 | 0xE3, // GREEK CAPITAL LETTER PI
u'' << 8 | 0xE3, // N-ARY PRODUCT
u'' << 8 | 0xE4, // N-ARY SUMMATION
u'µ' << 8 | 0xE6, // MICRO SIGN
u'' << 8 | 0xEA, // OHM SIGN
u'' << 8 | 0xEB, // PARTIAL DIFFERENTIAL
u'ϕ' << 8 | 0xED, // PHI SMALL (CLOSED FORM)
u'ε' << 8 | 0xEE, // LATIN SMALL LETTER EPSILON
u'' << 8 | 0xEE, // SMALL ELEMENT OF
u'' << 8 | 0xEE, // ELEMENT-OF SIGN
u'β' << 8 | 0xE1, // GREEK SMALL BETA
u'ſ' << 8 | 0xF4, // LATIN SMALL LETTER LONG S
};
static int g_cp437i[256 + ARRAYLEN(kCp437iMultimappings)];
/**
* Turns CP437 unicode glyph into its binary representation.
*
@ -62,15 +56,24 @@ static const struct Cp437Multimappings { @@ -62,15 +56,24 @@ static const struct Cp437Multimappings {
* @see bing()
*/
int unbing(int c) {
int i;
for (i = 0; i < 256; ++i) {
if (c == kCp437[i]) {
return i;
}
int i, m, l, r;
static bool once;
if (!once) {
for (i = 0; i < 256; ++i) g_cp437i[i] = kCp437[i] << 8 | i;
memcpy(g_cp437i + 256, kCp437iMultimappings, sizeof(kCp437iMultimappings));
insertionsort(ARRAYLEN(g_cp437i), g_cp437i);
once = true;
}
for (i = 0; i < ALTCOUNT; ++i) {
if (c == kCp437iMultimappings.c[i]) {
return kCp437iMultimappings.b[i];
l = 0;
r = ARRAYLEN(g_cp437i) - 1;
while (l <= r) {
m = (l + r) >> 1;
if ((g_cp437i[m] >> 8) < c) {
l = m + 1;
} else if ((g_cp437i[m] >> 8) > c) {
r = m - 1;
} else {
return g_cp437i[m] & 0xff;
}
}
return -1;

9
libc/integral/c.inc

@ -318,6 +318,15 @@ typedef uint64_t uintmax_t; @@ -318,6 +318,15 @@ typedef uint64_t uintmax_t;
#endif
#endif
#ifndef noclone
#if !defined(__STRICT_ANSI__) && \
(__has_attribute(__noclone__) || __GNUC__ * 100 + __GNUC_MINOR__ >= 405)
#define noclone __attribute__((__noclone__))
#else
#define noclone
#endif
#endif
/**
* Makes function behave as much like macro as possible, meaning:
*

29
libc/log/log.h

@ -5,11 +5,12 @@ @@ -5,11 +5,12 @@
cosmopolitan § liblog
*/
#define kLogFatal 0u
#define kLogError 1u
#define kLogWarn 2u
#define kLogInfo 3u
#define kLogDebug 4u
#define kLogFatal 0u
#define kLogError 1u
#define kLogWarn 2u
#define kLogInfo 3u
#define kLogVerbose 4u
#define kLogDebug 5u
/**
* Log level for compile-time DCE.
@ -20,7 +21,7 @@ @@ -20,7 +21,7 @@
/* #elif IsTiny() */
/* #define LOGGABLELEVEL kLogInfo */
#else
#define LOGGABLELEVEL kLogInfo
#define LOGGABLELEVEL kLogVerbose
#endif
#endif
@ -149,6 +150,13 @@ extern unsigned g_loglevel; /* log level for runtime check */ @@ -149,6 +150,13 @@ extern unsigned g_loglevel; /* log level for runtime check */
} \
} while (0)
#define VERBOSEF(FMT, ...) \
do { \
if (LOGGABLE(kLogVerbose)) { \
fverbosef(kLogVerbose, __FILE__, __LINE__, NULL, FMT, ##__VA_ARGS__); \
} \
} while (0)
#define VDEBUGF(FMT, VA) \
do { \
if (LOGGABLE(kLogDebug)) { \
@ -163,6 +171,13 @@ extern unsigned g_loglevel; /* log level for runtime check */ @@ -163,6 +171,13 @@ extern unsigned g_loglevel; /* log level for runtime check */
} \
} while (0)
#define VFVERBOSEF(F, FMT, VA) \
do { \
if (LOGGABLE(kLogVerbose)) { \
vfverbosef(kLogVerbose, __FILE__, __LINE__, F, FMT, VA); \
} \
} while (0)
#define VFDEBUGF(F, FMT, VA) \
do { \
if (LOGGABLE(kLogDebug)) { \
@ -203,6 +218,8 @@ void __logerrno(const char *, int, const char *) relegated; @@ -203,6 +218,8 @@ void __logerrno(const char *, int, const char *) relegated;
#define ATTRV paramsnonnull((5, 6))
void flogf(ARGS, ...) ATTR libcesque;
void vflogf(ARGS, va_list) ATTRV libcesque;
void fverbosef(ARGS, ...) asm("flogf") ATTR relegated libcesque;
void vfverbosef(ARGS, va_list) asm("vflogf") ATTRV relegated libcesque;
void fdebugf(ARGS, ...) asm("flogf") ATTR relegated libcesque;
void vfdebugf(ARGS, va_list) asm("vflogf") ATTRV relegated libcesque;
void ffatalf(ARGS, ...) asm("flogf") ATTR relegated noreturn libcesque;

4
libc/log/vflogf.c

@ -76,7 +76,6 @@ void vflogf_onfail(FILE *f) { @@ -76,7 +76,6 @@ void vflogf_onfail(FILE *f) {
void(vflogf)(unsigned level, const char *file, int line, FILE *f,
const char *fmt, va_list va) {
static struct timespec ts;
bool flush;
struct tm tm;
long double t2;
const char *prog;
@ -95,12 +94,10 @@ void(vflogf)(unsigned level, const char *file, int line, FILE *f, @@ -95,12 +94,10 @@ void(vflogf)(unsigned level, const char *file, int line, FILE *f,
timebufp = timebuf;
zonebufp = zonebuf;
dots = nsec;
flush = true;
} else {
timebufp = "---------------";
zonebufp = "---";
dots = nsec - ts.tv_nsec;
flush = true;
}
ts.tv_sec = secs;
ts.tv_nsec = nsec;
@ -113,7 +110,6 @@ void(vflogf)(unsigned level, const char *file, int line, FILE *f, @@ -113,7 +110,6 @@ void(vflogf)(unsigned level, const char *file, int line, FILE *f,
(vfprintf)(f, fmt, va);
va_end(va);
fputc('\n', f);
if (flush) fflush(f);
if (level == kLogFatal) {
startfatal(file, line);
fprintf(stderr, "fatal error see logfile\n");

24
libc/nexgen32e/bsf.c

@ -0,0 +1,24 @@ @@ -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);
}

7
libc/nexgen32e/bsf.h

@ -17,12 +17,15 @@ COSMOPOLITAN_C_START_ @@ -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

@ -0,0 +1,24 @@ @@ -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

@ -0,0 +1,24 @@ @@ -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

@ -0,0 +1,24 @@ @@ -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);
}

11
libc/nexgen32e/bsr.h

@ -17,11 +17,14 @@ COSMOPOLITAN_C_START_ @@ -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

@ -0,0 +1,24 @@ @@ -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

@ -0,0 +1,24 @@ @@ -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);
}

0
libc/alg/djbsort-avx2.S → libc/nexgen32e/djbsort-avx2.S

4
libc/alg/djbsort.c → libc/nexgen32e/djbsort.c

@ -24,9 +24,9 @@ @@ -24,9 +24,9 @@
void djbsort$avx2(int32_t *, long);
/**
* D.J. Bernstein's fast integer sorting algorithm.
* D.J. Bernstein's outrageously fast integer sorting algorithm.
*/
void djbsort(size_t n, int32_t *a) {
void djbsort(size_t n, int32_t a[n]) {
if (X86_HAVE(AVX2)) {
djbsort$avx2(a, n);
} else {

8
libc/nexgen32e/gc.S

@ -49,11 +49,11 @@ CollectGarbage: @@ -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

0
libc/str/insertionsort.greg.c → libc/nexgen32e/insertionsort.greg.c

2
libc/nexgen32e/kcpuids.S

@ -70,7 +70,7 @@ kCpuids:.long 0,0,0,0 # EAX=0 (Basic Processor Info) @@ -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)

16
libc/nexgen32e/x86feature.h

@ -17,8 +17,8 @@ @@ -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 @@ @@ -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_ */

5
libc/runtime/construct.S

@ -23,6 +23,11 @@ @@ -23,6 +23,11 @@
.source __FILE__
/ Calls global initialization functions.
/
/ @param r12 is argc
/ @param r13 is argv
/ @param r14 is environ
/ @param r15 is auxv
_construct:
push %rbp
mov %rsp,%rbp

9
libc/runtime/cxaatexit.c

@ -43,8 +43,8 @@ static struct CxaAtexitBlocks { @@ -43,8 +43,8 @@ static struct CxaAtexitBlocks {
*
* Destructors are called in reverse order. They won't be called if the
* program aborts or _exit() is called. Invocations of this function are
* usually generated by the C++ compiler. Behavior is limitless if you
* choose to link calloc() and free().
* usually generated by the C++ compiler. Behavior is limitless if some
* other module has linked calloc().
*
* @param fp is void(*)(T)
* @param arg is passed to callback
@ -78,8 +78,11 @@ int __cxa_atexit(void *fp, void *arg, void *pred) { @@ -78,8 +78,11 @@ int __cxa_atexit(void *fp, void *arg, void *pred) {
/**
* Triggers global destructors.
*
* They're called in LIFO order. If a destructor adds more destructors,
* then those destructors will be called immediately following, before
* iteration continues.
*
* @param pred can be null to match all
* @note reentrant emptor
*/
void __cxa_finalize(void *pred) {
unsigned i;

2
libc/runtime/mmap.c

@ -129,7 +129,7 @@ void *mmap(void *addr, size_t size, int prot, int flags, int fd, int64_t off) { @@ -129,7 +129,7 @@ void *mmap(void *addr, size_t size, int prot, int flags, int fd, int64_t off) {
if (!CANONICAL(addr)) return VIP(einval());
if (!(!!(flags & MAP_ANONYMOUS) ^ (fd != -1))) return VIP(einval());
if (!(!!(flags & MAP_PRIVATE) ^ !!(flags & MAP_SHARED))) return VIP(einval());
if (!(IsWindows() && fd != -1)) size = ROUNDUP(size, FRAMESIZE);
if (fd != -1) size = ROUNDUP(size, FRAMESIZE);
if (flags & MAP_FIXED) {
if (UntrackMemoryIntervals(addr, size) == -1) {
return MAP_FAILED;

1
libc/runtime/runtime.mk

@ -37,6 +37,7 @@ LIBC_RUNTIME_A_DIRECTDEPS = \ @@ -37,6 +37,7 @@ LIBC_RUNTIME_A_DIRECTDEPS = \
LIBC_BITS \
LIBC_CALLS \
LIBC_CONV \
LIBC_TINYMATH \
LIBC_ELF \
LIBC_FMT \
LIBC_NEXGEN32E \

5
libc/runtime/spawn.S

@ -22,6 +22,11 @@ @@ -22,6 +22,11 @@
#include "libc/macros.h"
/ Self-bootstraps process upon existence before calling main.
/
/ @param r12 is argc
/ @param r13 is argv
/ @param r14 is environ
/ @param r15 is auxv
_spawn: push %rbp
mov %rsp,%rbp

7
libc/str/str.h

@ -64,9 +64,10 @@ void *isnotplaintext(const void *, size_t) nothrow nocallback nosideeffect; @@ -64,9 +64,10 @@ void *isnotplaintext(const void *, size_t) nothrow nocallback nosideeffect;
3 Continuations follow */
#define INVALID_CODEPOINT 0xfffd
#define UTF16_MASK 0b1111110000000000
#define UTF16_MOAR 0b1101100000000000 /* 0xD800..0xDBFF */
#define UTF16_CONT 0b1101110000000000 /* 0xDC00..0xDBFF */
#define UTF16_MASK 0b1111110000000000
#define UTF16_MOAR 0b1101100000000000 /* 0xD800..0xDBFF */
#define UTF16_CONT 0b1101110000000000 /* 0xDC00..0xDBFF */
unsigned getutf16(const char16_t *, wint_t *);
int pututf16(char16_t *, size_t, wint_t, bool);

8
libc/str/thompike.h

@ -0,0 +1,8 @@ @@ -0,0 +1,8 @@
#ifndef COSMOPOLITAN_LIBC_STR_THOMPIKE_H_
#define COSMOPOLITAN_LIBC_STR_THOMPIKE_H_
#include "libc/nexgen32e/bsr.h"
#define ThomPikeCont(x) ((x & 0b11000000) == 0b10000000)
#define ThomPikeByte(x) (x & (((1 << (x < 252 ? bsr(~x & 0xff) : 1)) - 1) | 3))
#endif /* COSMOPOLITAN_LIBC_STR_THOMPIKE_H_ */

2
libc/sysv/consts.sh

@ -2611,7 +2611,7 @@ syscon ioctl FIONREAD 0x541b 0x4004667f 0x4004667f 0x4004667f 0x4004667f @@ -2611,7 +2611,7 @@ syscon ioctl FIONREAD 0x541b 0x4004667f 0x4004667f 0x4004667f 0x4004667f
#syscon ioctl FIONWRITE 0x0 0x0 0x40046677 0x0 -1 # [FreeBSD Generalization] bytes queued in FD's output buffer (same as TIOCOUTQ for TTY FDs; see also SO_SNDBUF)
#syscon ioctl FIONSPACE 0x0 0x0 0x40046676 0x0 -1 # [FreeBSD Generalization] capacity of FD's output buffer, e.g. equivalent to TIOCGSERIAL w/ UART
syscon ioctl TIOCINQ 0x541b 0x4004667f 0x4004667f 0x4004667f 0x4004667f # [Linuxism] same as FIONREAD
syscon ioctl TIOCOUTQ 0x5411 0x40047473 0x40047473 0x40047473 -1 # bytes queued in TTY's output buffer
#syscon ioctl TIOCOUTQ 0x5411 0x40047473 0x40047473 0x40047473 -1 # bytes queued in TTY's output buffer
syscon misc FANOTIFY_METADATA_VERSION 3 0 0 0 0
syscon misc FAPPEND 0x0400 8 8 8 0 # bsd consensus

5
libc/tinymath/fpclassify.S

@ -21,7 +21,7 @@ @@ -21,7 +21,7 @@
#include "libc/macros.h"
.source __FILE__
__fpclassify:
tinymath_fpclassify:
.leafprologue
movd %xmm0,%rax
movd %xmm0,%rdx
@ -41,4 +41,5 @@ __fpclassify: @@ -41,4 +41,5 @@ __fpclassify:
sal $12,%rdx
sete %al
1: .leafepilogue
.endfn __fpclassify,globl
.endfn tinymath_fpclassify,globl
.alias tinymath_fpclassify,__fpclassify

5
libc/tinymath/fpclassifyf.S

@ -21,7 +21,7 @@ @@ -21,7 +21,7 @@
#include "libc/macros.h"
.source __FILE__
__fpclassifyf:
tinymath_fpclassifyf:
.leafprologue
movd %xmm0,%edx
movd %xmm0,%eax
@ -42,4 +42,5 @@ __fpclassifyf: @@ -42,4 +42,5 @@ __fpclassifyf:
sete %al
movzbl %al,%eax
1: .leafepilogue
.endfn __fpclassifyf,globl
.endfn tinymath_fpclassifyf,globl
.alias tinymath_fpclassifyf,__fpclassifyf

5
libc/tinymath/fpclassifyl.S

@ -21,7 +21,7 @@ @@ -21,7 +21,7 @@
#include "libc/macros.h"
.source __FILE__
__fpclassifyl:
tinymath_fpclassifyl:
push %rbp
mov %rsp,%rbp
mov 24(%rbp),%rax
@ -50,4 +50,5 @@ __fpclassifyl: @@ -50,4 +50,5 @@ __fpclassifyl:
and $FP_NORMAL,%eax
1: pop %rbp
ret
.endfn __fpclassifyl,globl
.endfn tinymath_fpclassifyl,globl
.alias tinymath_fpclassifyl,__fpclassifyl

4
libc/tinymath/scalbn.S

@ -20,6 +20,10 @@ @@ -20,6 +20,10 @@
#include "libc/macros.h"
.source __FILE__
/ Returns 𝑥 × 2ʸ.
/
/ @param 𝑥 is double passed in %xmm0
/ @param 𝑦 is exponent via %edi
tinymath_scalbn:
push %rbp
mov %rsp,%rbp

4
libc/tinymath/scalbnf.S

@ -20,6 +20,10 @@ @@ -20,6 +20,10 @@
#include "libc/macros.h"
.source __FILE__
/ Returns 𝑥 × 2ʸ.
/
/ @param 𝑥 is float passed in %xmm0
/ @param 𝑦 is exponent via %edi
tinymath_scalbnf:
push %rbp
mov %rsp,%rbp

3
libc/tinymath/scalbnl.S

@ -20,11 +20,10 @@ @@ -20,11 +20,10 @@
#include "libc/macros.h"
.source __FILE__
/ Returns 𝑥 × 𝑟ʸ where 𝑟 is radix of hardware architecture.
/ Returns 𝑥 × 2ʸ.
/
/ @param 𝑥 is long double passed on stack
/ @param 𝑦 is exponent via %edi
/ @see FLT_RADIX
tinymath_scalbnl:
push %rbp
mov %rsp,%rbp

2
test/libc/fmt/test.mk

@ -19,12 +19,14 @@ TEST_LIBC_FMT_CHECKS = \ @@ -19,12 +19,14 @@ TEST_LIBC_FMT_CHECKS = \
$(TEST_LIBC_FMT_SRCS_TEST:%.c=o/$(MODE)/%.com.runs)
TEST_LIBC_FMT_DIRECTDEPS = \
LIBC_ALG \
LIBC_CALLS_HEFTY \
LIBC_CONV \
LIBC_FMT \
LIBC_MEM \
LIBC_NEXGEN32E \
LIBC_RUNTIME \
LIBC_STDIO \
LIBC_STR \
LIBC_STUBS \
LIBC_SYSV \

160
test/libc/intrin/intrin_test.c

@ -355,14 +355,14 @@ TEST(punpckhwd, test) { @@ -355,14 +355,14 @@ TEST(punpckhwd, test) {
uint16_t b[8] = {9, 10, 11, 12, 13, 14, 15, 16};
uint16_t c[8];
punpckhwd(c, a, b);
ASSERT_EQ(5, c[0]);
ASSERT_EQ(13, c[1]);
ASSERT_EQ(6, c[2]);
ASSERT_EQ(14, c[3]);
ASSERT_EQ(7, c[4]);
ASSERT_EQ(15, c[5]);
ASSERT_EQ(8, c[6]);
ASSERT_EQ(16, c[7]);
EXPECT_EQ(5, c[0]);
EXPECT_EQ(13, c[1]);
EXPECT_EQ(6, c[2]);
EXPECT_EQ(14, c[3]);
EXPECT_EQ(7, c[4]);
EXPECT_EQ(15, c[5]);
EXPECT_EQ(8, c[6]);
EXPECT_EQ(16, c[7]);
}
TEST(punpckhwd, pure) {
@ -370,70 +370,70 @@ TEST(punpckhwd, pure) { @@ -370,70 +370,70 @@ TEST(punpckhwd, pure) {
uint16_t b[8] = {9, 10, 11, 12, 13, 14, 15, 16};
uint16_t c[8];
punpckhwd(c, a, b);
ASSERT_EQ(5, c[0]);
ASSERT_EQ(13, c[1]);
ASSERT_EQ(6, c[2]);
ASSERT_EQ(14, c[3]);
ASSERT_EQ(7, c[4]);
ASSERT_EQ(15, c[5]);
ASSERT_EQ(8, c[6]);
ASSERT_EQ(16, c[7]);
EXPECT_EQ(5, c[0]);
EXPECT_EQ(13, c[1]);
EXPECT_EQ(6, c[2]);
EXPECT_EQ(14, c[3]);
EXPECT_EQ(7, c[4]);
EXPECT_EQ(15, c[5]);
EXPECT_EQ(8, c[6]);
EXPECT_EQ(16, c[7]);
}
TEST(punpckhwd, testAlias) {
uint16_t a[8] = {1, 02, 03, 04, 05, 06, 07, 8};
uint16_t b[8] = {9, 10, 11, 12, 13, 14, 15, 16};
punpckhwd(a, a, b);
ASSERT_EQ(5, a[0]);
ASSERT_EQ(13, a[1]);
ASSERT_EQ(6, a[2]);
ASSERT_EQ(14, a[3]);
ASSERT_EQ(7, a[4]);
ASSERT_EQ(15, a[5]);
ASSERT_EQ(8, a[6]);
ASSERT_EQ(16, a[7]);
EXPECT_EQ(5, a[0]);
EXPECT_EQ(13, a[1]);
EXPECT_EQ(6, a[2]);
EXPECT_EQ(14, a[3]);
EXPECT_EQ(7, a[4]);
EXPECT_EQ(15, a[5]);
EXPECT_EQ(8, a[6]);
EXPECT_EQ(16, a[7]);
}
TEST(punpckhwd, pureAlias) {
uint16_t a[8] = {1, 02, 03, 04, 05, 06, 07, 8};
uint16_t b[8] = {9, 10, 11, 12, 13, 14, 15, 16};
(punpckhwd)(a, a, b);
ASSERT_EQ(5, a[0]);
ASSERT_EQ(13, a[1]);
ASSERT_EQ(6, a[2]);
ASSERT_EQ(14, a[3]);
ASSERT_EQ(7, a[4]);
ASSERT_EQ(15, a[5]);
ASSERT_EQ(8, a[6]);
ASSERT_EQ(16, a[7]);
EXPECT_EQ(5, a[0]);
EXPECT_EQ(13, a[1]);
EXPECT_EQ(6, a[2]);
EXPECT_EQ(14, a[3]);
EXPECT_EQ(7, a[4]);
EXPECT_EQ(15, a[5]);
EXPECT_EQ(8, a[6]);
EXPECT_EQ(16, a[7]);
}
TEST(punpckhwd, testAlias2) {
uint16_t a[8] = {1, 02, 03, 04, 05, 06, 07, 8};
uint16_t b[8] = {9, 10, 11, 12, 13, 14, 15, 16};
punpckhwd(b, a, b);
ASSERT_EQ(5, b[0]);
ASSERT_EQ(13, b[1]);
ASSERT_EQ(6, b[2]);
ASSERT_EQ(14, b[3]);
ASSERT_EQ(7, b[4]);
ASSERT_EQ(15, b[5]);
ASSERT_EQ(8, b[6]);
ASSERT_EQ(16, b[7]);
EXPECT_EQ(5, b[0]);
EXPECT_EQ(13, b[1]);
EXPECT_EQ(6, b[2]);
EXPECT_EQ(14, b[3]);
EXPECT_EQ(7, b[4]);
EXPECT_EQ(15, b[5]);
EXPECT_EQ(8, b[6]);
EXPECT_EQ(16, b[7]);
}
TEST(punpckhwd, pureAlias2) {
uint16_t a[8] = {1, 02, 03, 04, 05, 06, 07, 8};
uint16_t b[8] = {9, 10, 11, 12, 13, 14, 15, 16};
(punpckhwd)(b, a, b);
ASSERT_EQ(5, b[0]);
ASSERT_EQ(13, b[1]);
ASSERT_EQ(6, b[2]);
ASSERT_EQ(14, b[3]);
ASSERT_EQ(7, b[4]);
ASSERT_EQ(15, b[5]);
ASSERT_EQ(8, b[6]);
ASSERT_EQ(16, b[7]);
EXPECT_EQ(5, b[0]);
EXPECT_EQ(13, b[1]);
EXPECT_EQ(6, b[2]);
EXPECT_EQ(14, b[3]);
EXPECT_EQ(7, b[4]);
EXPECT_EQ(15, b[5]);
EXPECT_EQ(8, b[6]);
EXPECT_EQ(16, b[7]);
}
TEST(punpckhqdq, test) {
@ -441,8 +441,8 @@ TEST(punpckhqdq, test) { @@ -441,8 +441,8 @@ TEST(punpckhqdq, test) {
uint64_t b[2] = {3, 4};
uint64_t c[2];
punpckhqdq(c, a, b);
ASSERT_EQ(2, c[0]);
ASSERT_EQ(4, c[1]);
EXPECT_EQ(2, c[0]);
EXPECT_EQ(4, c[1]);
}
TEST(punpckhqdq, pure) {
@ -450,24 +450,24 @@ TEST(punpckhqdq, pure) { @@ -450,24 +450,24 @@ TEST(punpckhqdq, pure) {
uint64_t b[2] = {3, 4};
uint64_t c[2];
(punpckhqdq)(c, a, b);
ASSERT_EQ(2, c[0]);
ASSERT_EQ(4, c[1]);
EXPECT_EQ(2, c[0]);
EXPECT_EQ(4, c[1]);
}
TEST(punpckhqdq, testAlias) {
uint64_t a[2] = {1, 2};
uint64_t b[2] = {3, 4};
punpckhqdq(a, a, b);
ASSERT_EQ(2, a[0]);
ASSERT_EQ(4, a[1]);
EXPECT_EQ(2, a[0]);
EXPECT_EQ(4, a[1]);
}
TEST(punpckhqdq, pureAlias) {
uint64_t a[2] = {1, 2};
uint64_t b[2] = {3, 4};
(punpckhqdq)(a, a, b);
ASSERT_EQ(2, a[0]);
ASSERT_EQ(4, a[1]);
EXPECT_EQ(2, a[0]);
EXPECT_EQ(4, a[1]);
}
TEST(punpckhdq, test) {
@ -475,10 +475,10 @@ TEST(punpckhdq, test) { @@ -475,10 +475,10 @@ TEST(punpckhdq, test) {
uint32_t b[4] = {5, 6, 7, 8};
uint32_t c[4];
punpckhdq(c, a, b);
ASSERT_EQ(3, c[0]);
ASSERT_EQ(7, c[1]);
ASSERT_EQ(4, c[2]);
ASSERT_EQ(8, c[3]);
EXPECT_EQ(3, c[0]);
EXPECT_EQ(7, c[1]);
EXPECT_EQ(4, c[2]);
EXPECT_EQ(8, c[3]);
}
TEST(punpckhdq, pure) {
@ -486,50 +486,50 @@ TEST(punpckhdq, pure) { @@ -486,50 +486,50 @@ TEST(punpckhdq, pure) {
uint32_t b[4] = {5, 6, 7, 8};
uint32_t c[4];
punpckhdq(c, a, b);
ASSERT_EQ(3, c[0]);
ASSERT_EQ(7, c[1]);
ASSERT_EQ(4, c[2]);
ASSERT_EQ(8, c[3]);
EXPECT_EQ(3, c[0]);
EXPECT_EQ(7, c[1]);
EXPECT_EQ(4, c[2]);
EXPECT_EQ(8, c[3]);
}
TEST(punpckhdq, testAlias) {
uint32_t a[4] = {1, 2, 3, 4};
uint32_t b[4] = {5, 6, 7, 8};
punpckhdq(a, a, b);
ASSERT_EQ(3, a[0]);
ASSERT_EQ(7, a[1]);
ASSERT_EQ(4, a[2]);
ASSERT_EQ(8, a[3]);
EXPECT_EQ(3, a[0]);
EXPECT_EQ(7, a[1]);
EXPECT_EQ(4, a[2]);
EXPECT_EQ(8, a[3]);
}
TEST(punpckhdq, pureAlias) {
uint32_t a[4] = {1, 2, 3, 4};
uint32_t b[4] = {5, 6, 7, 8};
(punpckhdq)(a, a, b);
ASSERT_EQ(3, a[0]);
ASSERT_EQ(7, a[1]);
ASSERT_EQ(4, a[2]);
ASSERT_EQ(8, a[3]);
EXPECT_EQ(3, a[0]);
EXPECT_EQ(7, a[1]);
EXPECT_EQ(4, a[2]);
EXPECT_EQ(8, a[3]);
}
TEST(punpckhdq, testAlias2) {
uint32_t a[4] = {1, 2, 3, 4};
uint32_t b[4] = {5, 6, 7, 8};
punpckhdq(b, a, b);
ASSERT_EQ(3, b[0]);
ASSERT_EQ(7, b[1]);
ASSERT_EQ(4, b[2]);
ASSERT_EQ(8, b[3]);
EXPECT_EQ(3, b[0]);
EXPECT_EQ(7, b[1]);
EXPECT_EQ(4, b[2]);
EXPECT_EQ(8, b[3]);
}
TEST(punpckhdq, pureAlias2) {
uint32_t a[4] = {1, 2, 3, 4};
uint32_t b[4] = {5, 6, 7, 8};
(punpckhdq)(b, a, b);
ASSERT_EQ(3, b[0]);
ASSERT_EQ(7, b[1]);
ASSERT_EQ(4, b[2]);
ASSERT_EQ(8, b[3]);
EXPECT_EQ(3, b[0]);
EXPECT_EQ(7, b[1]);
EXPECT_EQ(4, b[2]);
EXPECT_EQ(8, b[3]);
}
TEST(punpckhwd, fuzz) {

1
test/libc/runtime/test.mk

@ -29,6 +29,7 @@ TEST_LIBC_RUNTIME_DIRECTDEPS = \ @@ -29,6 +29,7 @@ TEST_LIBC_RUNTIME_DIRECTDEPS = \
LIBC_CALLS_HEFTY \
LIBC_FMT \
LIBC_MEM \
LIBC_TINYMATH \
LIBC_NEXGEN32E \
LIBC_RAND \
LIBC_RUNTIME \

18
test/tool/build/lib/bitscan_test.c

@ -36,10 +36,9 @@ void SetUp(void) { @@ -36,10 +36,9 @@ void SetUp(void) {
TEST(bsr64, test) {
bool zf;
uint64_t i, w, x, a, b;
m->xedd->op.rde = REXW;
for (i = 0; i < ARRAYLEN(kNumbers); ++i) {
x = kNumbers[i];
a = AluBsr(m, 0, x);
a = AluBsr(m, REXW, 0, x);
asm("bsrq\t%2,%0" : "=r"(b), "=@ccz"(zf) : "r"(x));
ASSERT_EQ(zf, GetFlag(m->flags, FLAGS_ZF));
if (!zf) ASSERT_EQ(a, b);
@ -49,10 +48,9 @@ TEST(bsr64, test) { @@ -49,10 +48,9 @@ TEST(bsr64, test) {
TEST(bsr32, test) {
bool zf;
uint32_t i, w, x, a, b;
m->xedd->op.rde = 0;
for (i = 0; i < ARRAYLEN(kNumbers); ++i) {
x = kNumbers[i];
a = AluBsr(m, 0, x);
a = AluBsr(m, 0, 0, x);
asm("bsrl\t%2,%0" : "=r"(b), "=@ccz"(zf) : "r"(x));
ASSERT_EQ(zf, GetFlag(m->flags, FLAGS_ZF));
if (!zf) ASSERT_EQ(a, b);
@ -62,10 +60,9 @@ TEST(bsr32, test) { @@ -62,10 +60,9 @@ TEST(bsr32, test) {
TEST(bsr16, test) {
bool zf;
uint16_t i, w, x, a, b;
m->xedd->op.rde = OSZ;
for (i = 0; i < ARRAYLEN(kNumbers); ++i) {
x = kNumbers[i];
a = AluBsr(m, 0, x);
a = AluBsr(m, OSZ, 0, x);
asm("bsrw\t%2,%0" : "=r"(b), "=@ccz"(zf) : "r"(x));
ASSERT_EQ(zf, GetFlag(m->flags, FLAGS_ZF));
if (!zf) ASSERT_EQ(a, b);
@ -75,10 +72,9 @@ TEST(bsr16, test) { @@ -75,10 +72,9 @@ TEST(bsr16, test) {
TEST(bsf64, test) {
bool zf;
uint64_t i, w, x, a, b;
m->xedd->op.rde = REXW;
for (i = 0; i < ARRAYLEN(kNumbers); ++i) {
x = kNumbers[i];
a = AluBsf(m, 0, x);
a = AluBsf(m, REXW, 0, x);
asm("bsfq\t%2,%0" : "=r"(b), "=@ccz"(zf) : "r"(x));
ASSERT_EQ(zf, GetFlag(m->flags, FLAGS_ZF));
if (!zf) ASSERT_EQ(a, b);
@ -88,10 +84,9 @@ TEST(bsf64, test) { @@ -88,10 +84,9 @@ TEST(bsf64, test) {
TEST(bsf32, test) {
bool zf;
uint32_t i, w, x, a, b;
m->xedd->op.rde = 0;
for (i = 0; i < ARRAYLEN(kNumbers); ++i) {
x = kNumbers[i];
a = AluBsf(m, 0, x);
a = AluBsf(m, 0, 0, x);
asm("bsfl\t%2,%0" : "=r"(b), "=@ccz"(zf) : "r"(x));
ASSERT_EQ(zf, GetFlag(m->flags, FLAGS_ZF));
if (!zf) ASSERT_EQ(a, b);
@ -101,10 +96,9 @@ TEST(bsf32, test) { @@ -101,10 +96,9 @@ TEST(bsf32, test) {
TEST(bsf16, test) {
bool zf;
uint16_t i, w, x, a, b;
m->xedd->op.rde = OSZ;
for (i = 0; i < ARRAYLEN(kNumbers); ++i) {
x = kNumbers[i];
a = AluBsf(m, 0, x);
a = AluBsf(m, OSZ, 0, x);
asm("bsfw\t%2,%0" : "=r"(b), "=@ccz"(zf) : "r"(x));
ASSERT_EQ(zf, GetFlag(m->flags, FLAGS_ZF));
if (!zf) ASSERT_EQ(a, b, "%#lx", x);

48
test/tool/build/lib/divmul_test.c

@ -62,12 +62,11 @@ TEST(imul8, test) { @@ -62,12 +62,11 @@ TEST(imul8, test) {