diff --git a/libc/calls/calls.h b/libc/calls/calls.h index 77c9884f7..4b8a1a92f 100644 --- a/libc/calls/calls.h +++ b/libc/calls/calls.h @@ -206,6 +206,7 @@ bool issymlink(const char *); bool32 ischardev(int); char *commandv(const char *, char *, size_t); char *replaceuser(const char *) dontdiscard; +int clone(void *, void *, size_t, int, void *, void *, void *, void *); int gettid(void) libcesque; int makedirs(const char *, unsigned); int memfd_create(const char *, unsigned int); diff --git a/libc/calls/wait4-nt.c b/libc/calls/wait4-nt.c index 9d81af9cc..8ca5a5bdc 100644 --- a/libc/calls/wait4-nt.c +++ b/libc/calls/wait4-nt.c @@ -36,7 +36,6 @@ #include "libc/nt/struct/filetime.h" #include "libc/nt/struct/processmemorycounters.h" #include "libc/nt/synchronization.h" -#include "libc/runtime/ezmap.internal.h" #include "libc/runtime/runtime.h" #include "libc/stdio/lcg.internal.h" #include "libc/str/str.h" diff --git a/libc/elf/getelfstring.c b/libc/elf/getelfstring.c index 89a5ce327..2afa97f69 100644 --- a/libc/elf/getelfstring.c +++ b/libc/elf/getelfstring.c @@ -47,8 +47,7 @@ const char *GetElfString(const Elf64_Ehdr *elf, // validated if (!i) return ""; e = (const char *)elf; if (!strtab) return 0; - if (strtab < e) return 0; - if (strtab >= e + mapsize) return 0; + if (i >= mapsize) return 0; if (strtab + i >= e + mapsize) return 0; if (!memchr(strtab + i, 0, (e + mapsize) - (strtab + i))) return 0; return (const char *)strtab + i; diff --git a/libc/intrin/bitreverse16.c b/libc/intrin/bitreverse.c similarity index 56% rename from libc/intrin/bitreverse16.c rename to libc/intrin/bitreverse.c index ab36cfe2a..ffdc68b03 100644 --- a/libc/intrin/bitreverse16.c +++ b/libc/intrin/bitreverse.c @@ -18,9 +18,35 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/intrin/bits.h" +static const unsigned char kReverseBits[256] = { + 0, 128, 64, 192, 32, 160, 96, 224, 16, 144, 80, 208, 48, 176, 112, 240, + 8, 136, 72, 200, 40, 168, 104, 232, 24, 152, 88, 216, 56, 184, 120, 248, + 4, 132, 68, 196, 36, 164, 100, 228, 20, 148, 84, 212, 52, 180, 116, 244, + 12, 140, 76, 204, 44, 172, 108, 236, 28, 156, 92, 220, 60, 188, 124, 252, + 2, 130, 66, 194, 34, 162, 98, 226, 18, 146, 82, 210, 50, 178, 114, 242, + 10, 138, 74, 202, 42, 170, 106, 234, 26, 154, 90, 218, 58, 186, 122, 250, + 6, 134, 70, 198, 38, 166, 102, 230, 22, 150, 86, 214, 54, 182, 118, 246, + 14, 142, 78, 206, 46, 174, 110, 238, 30, 158, 94, 222, 62, 190, 126, 254, + 1, 129, 65, 193, 33, 161, 97, 225, 17, 145, 81, 209, 49, 177, 113, 241, + 9, 137, 73, 201, 41, 169, 105, 233, 25, 153, 89, 217, 57, 185, 121, 249, + 5, 133, 69, 197, 37, 165, 101, 229, 21, 149, 85, 213, 53, 181, 117, 245, + 13, 141, 77, 205, 45, 173, 109, 237, 29, 157, 93, 221, 61, 189, 125, 253, + 3, 131, 67, 195, 35, 163, 99, 227, 19, 147, 83, 211, 51, 179, 115, 243, + 11, 139, 75, 203, 43, 171, 107, 235, 27, 155, 91, 219, 59, 187, 123, 251, + 7, 135, 71, 199, 39, 167, 103, 231, 23, 151, 87, 215, 55, 183, 119, 247, + 15, 143, 79, 207, 47, 175, 111, 239, 31, 159, 95, 223, 63, 191, 127, 255, +}; + +/** + * Reverses bits in 8-bit word. + */ +int _bitreverse8(int x) { + return kReverseBits[x & 255]; +} + /** * Reverses bits in 16-bit word. */ int _bitreverse16(int x) { - return kReverseBits[0x00FF & x] << 8 | kReverseBits[(0xFF00 & x) >> 8]; + return kReverseBits[x & 255] << 8 | kReverseBits[(0xFF00 & x) >> 8]; } diff --git a/libc/intrin/bitreverse8.c b/libc/intrin/bitreverse8.c deleted file mode 100644 index a66633ce1..000000000 --- a/libc/intrin/bitreverse8.c +++ /dev/null @@ -1,26 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/bits.h" - -/** - * Reverses bits in 8-bit word. - */ -int _bitreverse8(int x) { - return kReverseBits[255 & x]; -} diff --git a/libc/intrin/bits.h b/libc/intrin/bits.h index d810a7355..ff29985aa 100644 --- a/libc/intrin/bits.h +++ b/libc/intrin/bits.h @@ -4,20 +4,13 @@ COSMOPOLITAN_C_START_ #ifdef COSMO -#define CheckUnsigned(x) ((x) / !((typeof(x))(-1) < 0)) - -extern const uint8_t kReverseBits[256]; - -int _bitreverse8(int) libcesque pureconst; -int _bitreverse16(int) libcesque pureconst; -uint32_t _bitreverse32(uint32_t) -libcesque pureconst; -uint64_t _bitreverse64(uint64_t) -libcesque pureconst; -unsigned long _roundup2pow(unsigned long) libcesque pureconst; -unsigned long _roundup2log(unsigned long) libcesque pureconst; -unsigned long _rounddown2pow(unsigned long) libcesque pureconst; -unsigned _bextra(const unsigned *, size_t, char); +int _bitreverse8(int) pureconst; +int _bitreverse16(int) pureconst; +uint32_t _bitreverse32(uint32_t) pureconst; +uint64_t _bitreverse64(uint64_t) pureconst; +unsigned long _roundup2pow(unsigned long) pureconst; +unsigned long _roundup2log(unsigned long) pureconst; +unsigned long _rounddown2pow(unsigned long) pureconst; #define READ16LE(P) \ (__extension__({ \ diff --git a/libc/intrin/dll.c b/libc/intrin/dll.c new file mode 100644 index 000000000..5a60d7d17 --- /dev/null +++ b/libc/intrin/dll.c @@ -0,0 +1,93 @@ +/*-*- 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 2023 Justine Alexandra Roberts Tunney │ +│ │ +│ Permission to use, copy, modify, and/or distribute this software for │ +│ any purpose with or without fee is hereby granted, provided that the │ +│ above copyright notice and this permission notice appear in all copies. │ +│ │ +│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ +│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ +│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ +│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ +│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ +│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ +│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ +│ PERFORMANCE OF THIS SOFTWARE. │ +╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/intrin/dll.h" + +/** + * @fileoverview Doubly Linked List Library + * Based on designs used by Mike Burrows and Linus Torvalds. + */ + +/** + * Makes `succ` and its successors come after `elem`. + * + * It's required that `elem` and `succ` aren't part of the same list. + */ +void dll_splice_after(struct Dll *elem, struct Dll *succ) { + struct Dll *tmp1, *tmp2; + tmp1 = elem->next; + tmp2 = succ->prev; + elem->next = succ; + succ->prev = elem; + tmp2->next = tmp1; + tmp1->prev = tmp2; +} + +/** + * Removes item from doubly-linked list. + * + * @param list is a doubly-linked list, where `!*list` means empty + */ +void dll_remove(struct Dll **list, struct Dll *elem) { + if (*list == elem) { + if ((*list)->prev == *list) { + *list = 0; + } else { + *list = (*list)->prev; + } + } + elem->next->prev = elem->prev; + elem->prev->next = elem->next; + elem->next = elem; + elem->prev = elem; +} + +/** + * Inserts items into list, at the beginning. + * + * The resulting list will start with `elem`, followed by other items in + * `elem`, followed by the items previously in `*list`. + * + * @param list is a doubly-linked list, where `!*list` means empty + * @param elem must not be a member of `list`, or null for no-op + */ +void dll_make_first(struct Dll **list, struct Dll *elem) { + if (elem) { + if (!*list) { + *list = elem->prev; + } else { + dll_splice_after(*list, elem); + } + } +} + +/** + * Inserts items into list, at the end. + * + * The resulting `*list` will end with `elem`, preceded by the other + * items in `elem`, preceded by the items previously in `*list`. + * + * @param list is a doubly-linked list, where `!*list` means empty + * @param elem must not be a member of `list`, or null for no-op + */ +void dll_make_last(struct Dll **list, struct Dll *elem) { + if (elem) { + dll_make_first(list, elem->next); + *list = elem; + } +} diff --git a/libc/intrin/dll.h b/libc/intrin/dll.h new file mode 100644 index 000000000..ae18393a6 --- /dev/null +++ b/libc/intrin/dll.h @@ -0,0 +1,57 @@ +#ifndef COSMOPOLITAN_LIBC_INTRIN_DLL_H_ +#define COSMOPOLITAN_LIBC_INTRIN_DLL_H_ +#ifdef COSMO +#define dll_make_first __dll_make_first +#define dll_make_last __dll_make_last +#define dll_remove __dll_remove +#define dll_splice_after __dll_splice_after +#if !(__ASSEMBLER__ + __LINKER__ + 0) +COSMOPOLITAN_C_START_ + +#define DLL_CONTAINER(t, f, p) ((t *)(((char *)(p)) - offsetof(t, f))) + +struct Dll { + struct Dll *next; + struct Dll *prev; +}; + +static inline void dll_init(struct Dll *e) { + e->next = e; + e->prev = e; +} + +static inline int dll_is_empty(struct Dll *list) { + return !list; +} + +static inline struct Dll *dll_last(struct Dll *list) { + return list; +} + +static inline struct Dll *dll_first(struct Dll *list) { + struct Dll *first = 0; + if (list) first = list->next; + return first; +} + +static inline struct Dll *dll_next(struct Dll *list, struct Dll *e) { + struct Dll *next = 0; + if (e != list) next = e->next; + return next; +} + +static inline struct Dll *dll_prev(struct Dll *list, struct Dll *e) { + struct Dll *prev = 0; + if (e != list->next) prev = e->prev; + return prev; +} + +void dll_remove(struct Dll **, struct Dll *) paramsnonnull() libcesque; +void dll_make_last(struct Dll **, struct Dll *) paramsnonnull((1)) libcesque; +void dll_make_first(struct Dll **, struct Dll *) paramsnonnull((1)) libcesque; +void dll_splice_after(struct Dll *, struct Dll *) paramsnonnull((1)) libcesque; + +COSMOPOLITAN_C_END_ +#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ +#endif /* COSMO */ +#endif /* COSMOPOLITAN_LIBC_INTRIN_DLL_H_ */ diff --git a/libc/intrin/mpsadbw.c b/libc/intrin/mpsadbw.c deleted file mode 100644 index ab0687508..000000000 --- a/libc/intrin/mpsadbw.c +++ /dev/null @@ -1,44 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/mpsadbw.h" -#include "libc/macros.internal.h" -#include "libc/str/str.h" - -/** - * Computes multiple sum of absolute differences. - * - * This appears to be intended for video encoding motion estimation. It - * can be combined with phminposuw. That allows us to search for an int - * overlapping inside 𝑏 that's nearest to an aligned int in 𝑎. - * - * @note goes fast w/ sse4 cf. core c. 2006 cf. bulldozer c. 2011 - * @mayalias - */ -void(mpsadbw)(uint16_t c[8], const uint8_t b[16], const uint8_t a[16], - uint8_t control) { - unsigned i, j; - uint16_t r[8]; - for (i = 0; i < 8; ++i) { - r[i] = 0; - for (j = 0; j < 4; ++j) { - r[i] += ABS(b[(control & 4) + i + j] - a[(control & 3) * 4 + j]); - } - } - __builtin_memcpy(c, r, 16); -} diff --git a/libc/intrin/mpsadbw.h b/libc/intrin/mpsadbw.h deleted file mode 100644 index 9237a55c9..000000000 --- a/libc/intrin/mpsadbw.h +++ /dev/null @@ -1,42 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_MPSADBW_H_ -#define COSMOPOLITAN_LIBC_INTRIN_MPSADBW_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void mpsadbw(uint16_t[8], const uint8_t[16], const uint8_t[16], uint8_t); - -#if defined(__x86_64__) && !defined(__STRICT_ANSI__) -__intrin_xmm_t __mpsadbws(__intrin_xmm_t, __intrin_xmm_t); -#define mpsadbw(C, B, A, I) \ - do { \ - if (__builtin_expect(!IsModeDbg() && X86_NEED(SSE) && X86_HAVE(SSE4_1), \ - 1)) { \ - __intrin_xmm_t *Xmm0 = (void *)(C); \ - const __intrin_xmm_t *Xmm1 = (const __intrin_xmm_t *)(B); \ - const __intrin_xmm_t *Xmm2 = (const __intrin_xmm_t *)(A); \ - if (__builtin_constant_p(I)) { \ - if (!X86_NEED(AVX)) { \ - asm("mpsadbw\t%2,%1,%0" \ - : "=x"(*Xmm0) \ - : "x"(*Xmm2), "i"(I), "0"(*Xmm1)); \ - } else { \ - asm("vmpsadbw\t%3,%2,%1,%0" \ - : "=x"(*Xmm0) \ - : "x"(*Xmm1), "x"(*Xmm2), "i"(I)); \ - } \ - } else { \ - unsigned long Vimm = (I); \ - typeof(__mpsadbws) *Fn; \ - Fn = (typeof(__mpsadbws) *)((uintptr_t)&__mpsadbws + (Vimm & 7) * 8); \ - *Xmm0 = Fn(*Xmm1, *Xmm2); \ - } \ - } else { \ - mpsadbw(C, B, A, I); \ - } \ - } while (0) -#endif - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_MPSADBW_H_ */ diff --git a/libc/intrin/mpsadbws.S b/libc/intrin/mpsadbws.S deleted file mode 100644 index a4383ed12..000000000 --- a/libc/intrin/mpsadbws.S +++ /dev/null @@ -1,34 +0,0 @@ -/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│ -│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/macros.internal.h" - -// Jump table for mpsadbw() with non-constexpr immediate parameter. -// -// @note needs sse4 cf. core c. 2006 cf. bulldozer c. 2011 -// @see mpsadbw() - .balign 8 -__mpsadbws: - i = 0 - .rept 8 - mpsadbw $i,%xmm1,%xmm0 - ret - nop - i = i + 1 - .endr - .endfn __mpsadbws,globl diff --git a/libc/intrin/pabsb.c b/libc/intrin/pabsb.c deleted file mode 100644 index 695c4bcdc..000000000 --- a/libc/intrin/pabsb.c +++ /dev/null @@ -1,34 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/pabsb.h" -#include "libc/macros.internal.h" -#include "libc/str/str.h" - -/** - * Converts signed bytes to absolute values, 𝑎ᵢ ← |𝑏ᵢ|. - * @note goes fast w/ ssse3 (intel c. 2004, amd c. 2011) - */ -void(pabsb)(uint8_t a[16], const int8_t b[16]) { - unsigned i; - uint8_t r[16]; - for (i = 0; i < 16; ++i) { - r[i] = ABS(b[i]); - } - __builtin_memcpy(a, r, 16); -} diff --git a/libc/intrin/pabsb.h b/libc/intrin/pabsb.h deleted file mode 100644 index 81e3cb82e..000000000 --- a/libc/intrin/pabsb.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PABSB_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PABSB_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void pabsb(uint8_t[16], const int8_t[16]); - -#define pabsb(A, B) INTRIN_SSEVEX_X_X_(pabsb, SSSE3, "pabsb", A, B) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PABSB_H_ */ diff --git a/libc/intrin/pabsd.c b/libc/intrin/pabsd.c deleted file mode 100644 index 77f9f6f77..000000000 --- a/libc/intrin/pabsd.c +++ /dev/null @@ -1,34 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/pabsd.h" -#include "libc/macros.internal.h" -#include "libc/str/str.h" - -/** - * Converts shorts to absolute values, 𝑎ᵢ ← |𝑏ᵢ|. - * @note goes fast w/ ssse3 (intel c. 2004, amd c. 2011) - */ -void(pabsd)(uint32_t a[4], const int32_t b[4]) { - unsigned i; - uint32_t r[4]; - for (i = 0; i < 4; ++i) { - r[i] = b[i] >= 0 ? b[i] : -(uint32_t)b[i]; - } - __builtin_memcpy(a, r, 16); -} diff --git a/libc/intrin/pabsd.h b/libc/intrin/pabsd.h deleted file mode 100644 index 5988396dc..000000000 --- a/libc/intrin/pabsd.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PABSD_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PABSD_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void pabsd(uint32_t[4], const int32_t[4]); - -#define pabsd(A, B) INTRIN_SSEVEX_X_X_(pabsd, SSSE3, "pabsd", A, B) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PABSD_H_ */ diff --git a/libc/intrin/pabsw.c b/libc/intrin/pabsw.c deleted file mode 100644 index b028bf0a9..000000000 --- a/libc/intrin/pabsw.c +++ /dev/null @@ -1,34 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/pabsw.h" -#include "libc/macros.internal.h" -#include "libc/str/str.h" - -/** - * Converts shorts to absolute values, 𝑎ᵢ ← |𝑏ᵢ|. - * @note goes fast w/ ssse3 (intel c. 2004, amd c. 2011) - */ -void(pabsw)(uint16_t a[8], const int16_t b[8]) { - unsigned i; - uint16_t r[8]; - for (i = 0; i < 8; ++i) { - r[i] = ABS(b[i]); - } - __builtin_memcpy(a, r, 16); -} diff --git a/libc/intrin/pabsw.h b/libc/intrin/pabsw.h deleted file mode 100644 index f4fd38463..000000000 --- a/libc/intrin/pabsw.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PABSW_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PABSW_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void pabsw(uint16_t[8], const int16_t[8]); - -#define pabsw(A, B) INTRIN_SSEVEX_X_X_(pabsw, SSSE3, "pabsw", A, B) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PABSW_H_ */ diff --git a/libc/intrin/packssdw.c b/libc/intrin/packssdw.c deleted file mode 100644 index 13f2b8ab8..000000000 --- a/libc/intrin/packssdw.c +++ /dev/null @@ -1,31 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/packssdw.h" -#include "libc/limits.h" -#include "libc/macros.internal.h" - -/** - * Casts ints to shorts w/ saturation. - * @mayalias - */ -void(packssdw)(int16_t a[8], const int32_t b[4], const int32_t c[4]) { - unsigned i; - for (i = 0; i < 4; ++i) a[i + 0] = MIN(INT16_MAX, MAX(INT16_MIN, b[i])); - for (i = 0; i < 4; ++i) a[i + 4] = MIN(INT16_MAX, MAX(INT16_MIN, c[i])); -} diff --git a/libc/intrin/packssdw.h b/libc/intrin/packssdw.h deleted file mode 100644 index 4d014984c..000000000 --- a/libc/intrin/packssdw.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PACKSSDW_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PACKSSDW_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void packssdw(int16_t[8], const int32_t[4], const int32_t[4]); - -#define packssdw(A, B, C) \ - INTRIN_SSEVEX_X_X_X_(packssdw, SSE2, "packssdw", INTRIN_NONCOMMUTATIVE, A, \ - B, C) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PACKSSDW_H_ */ diff --git a/libc/intrin/packusdw.c b/libc/intrin/packusdw.c deleted file mode 100644 index 116b09b67..000000000 --- a/libc/intrin/packusdw.c +++ /dev/null @@ -1,34 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/packusdw.h" -#include "libc/limits.h" -#include "libc/macros.internal.h" -#include "libc/str/str.h" - -/** - * Casts ints to shorts w/ saturation. - * @mayalias - */ -void(packusdw)(uint16_t a[8], const int32_t b[4], const int32_t c[4]) { - unsigned i; - uint16_t r[8]; - for (i = 0; i < 4; ++i) r[i + 0] = MIN(UINT16_MAX, MAX(UINT16_MIN, b[i])); - for (i = 0; i < 4; ++i) r[i + 4] = MIN(UINT16_MAX, MAX(UINT16_MIN, c[i])); - __builtin_memcpy(a, r, 16); -} diff --git a/libc/intrin/packusdw.h b/libc/intrin/packusdw.h deleted file mode 100644 index c9847ae87..000000000 --- a/libc/intrin/packusdw.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PACKUSDW_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PACKUSDW_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void packusdw(uint16_t[8], const int32_t[4], const int32_t[4]); - -#define packusdw(A, B, C) \ - INTRIN_SSEVEX_X_X_X_(packusdw, SSE4_1, "packusdw", INTRIN_NONCOMMUTATIVE, A, \ - B, C) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PACKUSDW_H_ */ diff --git a/libc/intrin/paddb.c b/libc/intrin/paddb.c deleted file mode 100644 index 445f329fc..000000000 --- a/libc/intrin/paddb.c +++ /dev/null @@ -1,35 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/paddb.h" -#include "libc/str/str.h" - -/** - * Adds 8-bit integers. - * - * @param 𝑎 [w/o] receives result - * @param 𝑏 [r/o] supplies first input vector - * @param 𝑐 [r/o] supplies second input vector - * @mayalias - */ -void(paddb)(int8_t a[16], const int8_t b[16], const int8_t c[16]) { - unsigned i; - int8_t r[16]; - for (i = 0; i < 16; ++i) r[i] = b[i] + c[i]; - __builtin_memcpy(a, r, 16); -} diff --git a/libc/intrin/paddb.h b/libc/intrin/paddb.h deleted file mode 100644 index 68698e3a2..000000000 --- a/libc/intrin/paddb.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PADDB_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PADDB_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void paddb(int8_t[16], const int8_t[16], const int8_t[16]); - -#define paddb(A, B, C) \ - INTRIN_SSEVEX_X_X_X_(paddb, SSE2, "paddb", INTRIN_COMMUTATIVE, A, B, C) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PADDB_H_ */ diff --git a/libc/intrin/paddd.c b/libc/intrin/paddd.c deleted file mode 100644 index 3bffd0c8f..000000000 --- a/libc/intrin/paddd.c +++ /dev/null @@ -1,37 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/paddd.h" -#include "libc/str/str.h" - -/** - * Adds 32-bit integers. - * - * @param 𝑎 [w/o] receives result - * @param 𝑏 [r/o] supplies first input vector - * @param 𝑐 [r/o] supplies second input vector - * @mayalias - */ -void(paddd)(uint32_t a[4], const uint32_t b[4], const uint32_t c[4]) { - unsigned i; - uint32_t r[4]; - for (i = 0; i < 4; ++i) { - r[i] = b[i] + c[i]; - } - __builtin_memcpy(a, r, 16); -} diff --git a/libc/intrin/paddd.h b/libc/intrin/paddd.h deleted file mode 100644 index 29e936740..000000000 --- a/libc/intrin/paddd.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PADDD_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PADDD_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void paddd(uint32_t[4], const uint32_t[4], const uint32_t[4]); - -#define paddd(A, B, C) \ - INTRIN_SSEVEX_X_X_X_(paddd, SSE2, "paddd", INTRIN_COMMUTATIVE, A, B, C) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PADDD_H_ */ diff --git a/libc/intrin/paddq.c b/libc/intrin/paddq.c deleted file mode 100644 index a9efb5d57..000000000 --- a/libc/intrin/paddq.c +++ /dev/null @@ -1,35 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/paddq.h" -#include "libc/str/str.h" - -/** - * Adds 64-bit integers. - * - * @param 𝑎 [w/o] receives result - * @param 𝑏 [r/o] supplies first input vector - * @param 𝑐 [r/o] supplies second input vector - * @mayalias - */ -void(paddq)(uint64_t a[2], const uint64_t b[2], const uint64_t c[2]) { - unsigned i; - uint64_t r[2]; - for (i = 0; i < 2; ++i) r[i] = b[i] + c[i]; - __builtin_memcpy(a, r, 16); -} diff --git a/libc/intrin/paddq.h b/libc/intrin/paddq.h deleted file mode 100644 index b7dc5635c..000000000 --- a/libc/intrin/paddq.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PADDQ_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PADDQ_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void paddq(uint64_t[2], const uint64_t[2], const uint64_t[2]); - -#define paddq(A, B, C) \ - INTRIN_SSEVEX_X_X_X_(paddq, SSE2, "paddq", INTRIN_COMMUTATIVE, A, B, C) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PADDQ_H_ */ diff --git a/libc/intrin/paddsb.c b/libc/intrin/paddsb.c deleted file mode 100644 index cdec707a6..000000000 --- a/libc/intrin/paddsb.c +++ /dev/null @@ -1,39 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/paddsb.h" -#include "libc/limits.h" -#include "libc/macros.internal.h" -#include "libc/str/str.h" - -/** - * Adds signed 8-bit integers w/ saturation. - * - * @param 𝑎 [w/o] receives result - * @param 𝑏 [r/o] supplies first input vector - * @param 𝑐 [r/o] supplies second input vector - * @mayalias - */ -void(paddsb)(int8_t a[16], const int8_t b[16], const int8_t c[16]) { - unsigned i; - int8_t r[16]; - for (i = 0; i < 16; ++i) { - r[i] = MIN(INT8_MAX, MAX(INT8_MIN, b[i] + c[i])); - } - __builtin_memcpy(a, r, 16); -} diff --git a/libc/intrin/paddsb.h b/libc/intrin/paddsb.h deleted file mode 100644 index 10cabb1a8..000000000 --- a/libc/intrin/paddsb.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PADDSB_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PADDSB_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void paddsb(int8_t[16], const int8_t[16], const int8_t[16]); - -#define paddsb(A, B, C) \ - INTRIN_SSEVEX_X_X_X_(paddsb, SSE2, "paddsb", INTRIN_COMMUTATIVE, A, B, C) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PADDSB_H_ */ diff --git a/libc/intrin/paddsw.c b/libc/intrin/paddsw.c deleted file mode 100644 index 0e597be4e..000000000 --- a/libc/intrin/paddsw.c +++ /dev/null @@ -1,39 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/paddsw.h" -#include "libc/limits.h" -#include "libc/macros.internal.h" -#include "libc/str/str.h" - -/** - * Adds signed 16-bit integers w/ saturation. - * - * @param 𝑎 [w/o] receives result - * @param 𝑏 [r/o] supplies first input vector - * @param 𝑐 [r/o] supplies second input vector - * @mayalias - */ -void(paddsw)(int16_t a[8], const int16_t b[8], const int16_t c[8]) { - unsigned i; - int16_t r[8]; - for (i = 0; i < 8; ++i) { - r[i] = MIN(SHRT_MAX, MAX(SHRT_MIN, b[i] + c[i])); - } - __builtin_memcpy(a, r, 16); -} diff --git a/libc/intrin/paddsw.h b/libc/intrin/paddsw.h deleted file mode 100644 index a500e4364..000000000 --- a/libc/intrin/paddsw.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PADDSW_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PADDSW_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void paddsw(int16_t[8], const int16_t[8], const int16_t[8]); - -#define paddsw(A, B, C) \ - INTRIN_SSEVEX_X_X_X_(paddsw, SSE2, "paddsw", INTRIN_COMMUTATIVE, A, B, C) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PADDSW_H_ */ diff --git a/libc/intrin/paddusb.c b/libc/intrin/paddusb.c deleted file mode 100644 index 790d678ae..000000000 --- a/libc/intrin/paddusb.c +++ /dev/null @@ -1,39 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/paddusb.h" -#include "libc/limits.h" -#include "libc/macros.internal.h" -#include "libc/str/str.h" - -/** - * Adds unsigned 8-bit integers w/ saturation. - * - * @param 𝑎 [w/o] receives result - * @param 𝑏 [r/o] supplies first input vector - * @param 𝑐 [r/o] supplies second input vector - * @mayalias - */ -void(paddusb)(uint8_t a[16], const uint8_t b[16], const uint8_t c[16]) { - unsigned i; - uint8_t r[16]; - for (i = 0; i < 16; ++i) { - r[i] = MIN(UINT8_MAX, b[i] + c[i]); - } - __builtin_memcpy(a, r, 16); -} diff --git a/libc/intrin/paddusb.h b/libc/intrin/paddusb.h deleted file mode 100644 index 8c6b300aa..000000000 --- a/libc/intrin/paddusb.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PADDUSB_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PADDUSB_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void paddusb(uint8_t[16], const uint8_t[16], const uint8_t[16]); - -#define paddusb(A, B, C) \ - INTRIN_SSEVEX_X_X_X_(paddusb, SSE2, "paddusb", INTRIN_COMMUTATIVE, A, B, C) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PADDUSB_H_ */ diff --git a/libc/intrin/paddusw.c b/libc/intrin/paddusw.c deleted file mode 100644 index 46bc976f5..000000000 --- a/libc/intrin/paddusw.c +++ /dev/null @@ -1,39 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/paddusw.h" -#include "libc/limits.h" -#include "libc/macros.internal.h" -#include "libc/str/str.h" - -/** - * Adds unsigned 16-bit integers w/ saturation. - * - * @param 𝑎 [w/o] receives result - * @param 𝑏 [r/o] supplies first input vector - * @param 𝑐 [r/o] supplies second input vector - * @mayalias - */ -void(paddusw)(uint16_t a[8], const uint16_t b[8], const uint16_t c[8]) { - unsigned i; - uint16_t r[8]; - for (i = 0; i < 8; ++i) { - r[i] = MIN(UINT16_MAX, b[i] + c[i]); - } - __builtin_memcpy(a, r, 16); -} diff --git a/libc/intrin/paddusw.h b/libc/intrin/paddusw.h deleted file mode 100644 index 1b47caf71..000000000 --- a/libc/intrin/paddusw.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PADDUSW_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PADDUSW_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void paddusw(uint16_t[8], const uint16_t[8], const uint16_t[8]); - -#define paddusw(A, B, C) \ - INTRIN_SSEVEX_X_X_X_(paddusw, SSE2, "paddusw", INTRIN_COMMUTATIVE, A, B, C) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PADDUSW_H_ */ diff --git a/libc/intrin/pand.c b/libc/intrin/pand.c deleted file mode 100644 index c1e1460fe..000000000 --- a/libc/intrin/pand.c +++ /dev/null @@ -1,34 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/pand.h" - -/** - * Ands 128-bit integers. - * - * @param 𝑎 [w/o] receives result - * @param 𝑏 [r/o] supplies first input vector - * @param 𝑐 [r/o] supplies second input vector - * @mayalias - */ -void(pand)(uint64_t a[2], const uint64_t b[2], const uint64_t c[2]) { - unsigned i; - for (i = 0; i < 2; ++i) { - a[i] = b[i] & c[i]; - } -} diff --git a/libc/intrin/pand.h b/libc/intrin/pand.h deleted file mode 100644 index 0edfee7c7..000000000 --- a/libc/intrin/pand.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PAND_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PAND_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void pand(uint64_t[2], const uint64_t[2], const uint64_t[2]); - -#define pand(A, B, C) \ - INTRIN_SSEVEX_X_X_X_(pand, SSE2, "pand", INTRIN_COMMUTATIVE, A, B, C) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PAND_H_ */ diff --git a/libc/intrin/pavgb.c b/libc/intrin/pavgb.c deleted file mode 100644 index 90a3643db..000000000 --- a/libc/intrin/pavgb.c +++ /dev/null @@ -1,37 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/pavgb.h" -#include "libc/str/str.h" - -/** - * Averages packed 8-bit unsigned integers w/ rounding. - * - * @param 𝑎 [w/o] receives result - * @param 𝑏 [r/o] supplies first input vector - * @param 𝑐 [r/o] supplies second input vector - * @mayalias - */ -void(pavgb)(uint8_t a[16], const uint8_t b[16], const uint8_t c[16]) { - unsigned i; - uint8_t r[16]; - for (i = 0; i < 16; ++i) { - r[i] = (b[i] + c[i] + 1) >> 1; - } - __builtin_memcpy(a, r, 16); -} diff --git a/libc/intrin/pavgb.h b/libc/intrin/pavgb.h deleted file mode 100644 index 8f68e6550..000000000 --- a/libc/intrin/pavgb.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PAVGB_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PAVGB_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void pavgb(uint8_t[16], const uint8_t[16], const uint8_t[16]); - -#define pavgb(A, B, C) \ - INTRIN_SSEVEX_X_X_X_(pavgb, SSE2, "pavgb", INTRIN_COMMUTATIVE, A, B, C) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PAVGB_H_ */ diff --git a/libc/intrin/pavgw.c b/libc/intrin/pavgw.c deleted file mode 100644 index 5cb2536cc..000000000 --- a/libc/intrin/pavgw.c +++ /dev/null @@ -1,37 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/pavgw.h" -#include "libc/str/str.h" - -/** - * Averages packed 16-bit unsigned integers w/ rounding. - * - * @param 𝑎 [w/o] receives result - * @param 𝑏 [r/o] supplies first input vector - * @param 𝑐 [r/o] supplies second input vector - * @mayalias - */ -void(pavgw)(uint16_t a[8], const uint16_t b[8], const uint16_t c[8]) { - unsigned i; - int16_t r[8]; - for (i = 0; i < 8; ++i) { - r[i] = (b[i] + c[i] + 1) >> 1; - } - __builtin_memcpy(a, r, 16); -} diff --git a/libc/intrin/pavgw.h b/libc/intrin/pavgw.h deleted file mode 100644 index d13662e61..000000000 --- a/libc/intrin/pavgw.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PAVGW_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PAVGW_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void pavgw(uint16_t[8], const uint16_t[8], const uint16_t[8]); - -#define pavgw(A, B, C) \ - INTRIN_SSEVEX_X_X_X_(pavgw, SSE2, "pavgw", INTRIN_COMMUTATIVE, A, B, C) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PAVGW_H_ */ diff --git a/libc/intrin/pcmpeqb.c b/libc/intrin/pcmpeqb.c deleted file mode 100644 index a8ddf894c..000000000 --- a/libc/intrin/pcmpeqb.c +++ /dev/null @@ -1,35 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/pcmpeqb.h" -#include "libc/str/str.h" - -/** - * Compares signed 8-bit integers w/ equal to predicate. - * - * @param 𝑎 [w/o] receives result - * @param 𝑏 [r/o] supplies first input vector - * @param 𝑐 [r/o] supplies second input vector - * @mayalias - */ -void(pcmpeqb)(uint8_t a[16], const uint8_t b[16], const uint8_t c[16]) { - unsigned i; - uint8_t r[16]; - for (i = 0; i < 16; ++i) r[i] = -(b[i] == c[i]); - __builtin_memcpy(a, r, 16); -} diff --git a/libc/intrin/pcmpeqb.h b/libc/intrin/pcmpeqb.h deleted file mode 100644 index 1c42f60e7..000000000 --- a/libc/intrin/pcmpeqb.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PCMPEQB_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PCMPEQB_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void pcmpeqb(uint8_t[16], const uint8_t[16], const uint8_t[16]); - -#define pcmpeqb(A, B, C) \ - INTRIN_SSEVEX_X_X_X_(pcmpeqb, SSE2, "pcmpeqb", INTRIN_NONCOMMUTATIVE, A, B, C) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PCMPEQB_H_ */ diff --git a/libc/intrin/pcmpeqd.c b/libc/intrin/pcmpeqd.c deleted file mode 100644 index ed4dcaf5e..000000000 --- a/libc/intrin/pcmpeqd.c +++ /dev/null @@ -1,35 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/pcmpeqd.h" -#include "libc/str/str.h" - -/** - * Compares signed 32-bit integers w/ equal to predicate. - * - * @param 𝑎 [w/o] receives result - * @param 𝑏 [r/o] supplies first input vector - * @param 𝑐 [r/o] supplies second input vector - * @mayalias - */ -void(pcmpeqd)(int32_t a[4], const int32_t b[4], const int32_t c[4]) { - unsigned i; - int32_t r[4]; - for (i = 0; i < 4; ++i) r[i] = -(b[i] == c[i]); - __builtin_memcpy(a, r, 16); -} diff --git a/libc/intrin/pcmpeqd.h b/libc/intrin/pcmpeqd.h deleted file mode 100644 index 87f2bba03..000000000 --- a/libc/intrin/pcmpeqd.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PCMPEQD_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PCMPEQD_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void pcmpeqd(int32_t[4], const int32_t[4], const int32_t[4]); - -#define pcmpeqd(A, B, C) \ - INTRIN_SSEVEX_X_X_X_(pcmpeqd, SSE2, "pcmpeqd", INTRIN_NONCOMMUTATIVE, A, B, C) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PCMPEQD_H_ */ diff --git a/libc/intrin/pcmpeqw.c b/libc/intrin/pcmpeqw.c deleted file mode 100644 index e3a2340cc..000000000 --- a/libc/intrin/pcmpeqw.c +++ /dev/null @@ -1,35 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/pcmpeqw.h" -#include "libc/str/str.h" - -/** - * Compares signed 16-bit integers w/ equal to predicate. - * - * @param 𝑎 [w/o] receives result - * @param 𝑏 [r/o] supplies first input vector - * @param 𝑐 [r/o] supplies second input vector - * @mayalias - */ -void(pcmpeqw)(int16_t a[8], const int16_t b[8], const int16_t c[8]) { - unsigned i; - int16_t r[8]; - for (i = 0; i < 8; ++i) r[i] = -(b[i] == c[i]); - __builtin_memcpy(a, r, 16); -} diff --git a/libc/intrin/pcmpeqw.h b/libc/intrin/pcmpeqw.h deleted file mode 100644 index acd33799c..000000000 --- a/libc/intrin/pcmpeqw.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PCMPEQW_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PCMPEQW_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void pcmpeqw(int16_t[8], const int16_t[8], const int16_t[8]); - -#define pcmpeqw(A, B, C) \ - INTRIN_SSEVEX_X_X_X_(pcmpeqw, SSE2, "pcmpeqw", INTRIN_NONCOMMUTATIVE, A, B, C) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PCMPEQW_H_ */ diff --git a/libc/intrin/pcmpgtd.c b/libc/intrin/pcmpgtd.c deleted file mode 100644 index 5e34bb93b..000000000 --- a/libc/intrin/pcmpgtd.c +++ /dev/null @@ -1,35 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/pcmpgtd.h" -#include "libc/str/str.h" - -/** - * Compares signed 32-bit integers w/ greater than predicate. - * - * @param 𝑎 [w/o] receives result - * @param 𝑏 [r/o] supplies first input vector - * @param 𝑐 [r/o] supplies second input vector - * @mayalias - */ -void(pcmpgtd)(int32_t a[4], const int32_t b[4], const int32_t c[4]) { - unsigned i; - int32_t r[4]; - for (i = 0; i < 4; ++i) r[i] = -(b[i] > c[i]); - __builtin_memcpy(a, r, 16); -} diff --git a/libc/intrin/pcmpgtd.h b/libc/intrin/pcmpgtd.h deleted file mode 100644 index 728824e42..000000000 --- a/libc/intrin/pcmpgtd.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PCMPGTD_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PCMPGTD_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void pcmpgtd(int32_t[4], const int32_t[4], const int32_t[4]); - -#define pcmpgtd(A, B, C) \ - INTRIN_SSEVEX_X_X_X_(pcmpgtd, SSE2, "pcmpgtd", INTRIN_NONCOMMUTATIVE, A, B, C) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PCMPGTD_H_ */ diff --git a/libc/intrin/pdep.c b/libc/intrin/pdep.c deleted file mode 100644 index b49e3429b..000000000 --- a/libc/intrin/pdep.c +++ /dev/null @@ -1,33 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/pdep.h" - -/** - * Parallel bit deposit. - */ -uint64_t(pdep)(uint64_t x, uint64_t mask) { - uint64_t r, b; - for (r = 0, b = 1; mask; mask >>= 1, b <<= 1) { - if (mask & 1) { - if (x & 1) r |= b; - x >>= 1; - } - } - return r; -} diff --git a/libc/intrin/pdep.h b/libc/intrin/pdep.h deleted file mode 100644 index 41472a8e6..000000000 --- a/libc/intrin/pdep.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PDEP_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PDEP_H_ -#include "libc/nexgen32e/x86feature.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -uint64_t pdep(uint64_t, uint64_t) pureconst; - -#define PDEP(NUMBER, BITMASK) \ - ({ \ - typeof(BITMASK) ShuffledBits, Number = (NUMBER); \ - asm("pdep\t%2,%1,%0" : "=r"(ShuffledBits) : "r"(Number), "rm"(BITMASK)); \ - ShuffledBits; \ - }) - -#define pdep(NUMBER, BITMASK) \ - (!X86_HAVE(BMI2) ? pdep(NUMBER, BITMASK) : PDEP(NUMBER, BITMASK)) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PDEP_H_ */ diff --git a/libc/intrin/pext.c b/libc/intrin/pext.c deleted file mode 100644 index ed6cb8c65..000000000 --- a/libc/intrin/pext.c +++ /dev/null @@ -1,33 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/pext.h" - -/** - * Parallel bit extract. - */ -uint64_t(pext)(uint64_t x, uint64_t mask) { - uint64_t r, b; - for (r = 0, b = 1; mask; mask >>= 1, x >>= 1) { - if (mask & 1) { - if (x & 1) r |= b; - b <<= 1; - } - } - return r; -} diff --git a/libc/intrin/pext.h b/libc/intrin/pext.h deleted file mode 100644 index a73322380..000000000 --- a/libc/intrin/pext.h +++ /dev/null @@ -1,20 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PEXT_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PEXT_H_ -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -uint64_t pext(uint64_t, uint64_t) pureconst; - -#define PEXT(NUMBER, BITMASK) \ - ({ \ - typeof(BITMASK) ShuffledBits, Number = (NUMBER); \ - asm("pext\t%2,%1,%0" : "=r"(ShuffledBits) : "r"(Number), "rm"(BITMASK)); \ - ShuffledBits; \ - }) - -#define pext(NUMBER, BITMASK) \ - (!X86_HAVE(BMI2) ? pext(NUMBER, BITMASK) : PEXT(NUMBER, BITMASK)) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PEXT_H_ */ diff --git a/libc/intrin/phaddd.c b/libc/intrin/phaddd.c deleted file mode 100644 index 08bbba240..000000000 --- a/libc/intrin/phaddd.c +++ /dev/null @@ -1,38 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/phaddd.h" -#include "libc/str/str.h" - -/** - * Adds adjacent 32-bit integers. - * - * @param 𝑎 [w/o] receives reduced 𝑏 and 𝑐 concatenated - * @param 𝑏 [r/o] supplies two pairs of ints - * @param 𝑐 [r/o] supplies two pairs of ints - * @note goes fast w/ ssse3 (intel c. 2004, amd c. 2011) - * @mayalias - */ -void(phaddd)(uint32_t a[4], const uint32_t b[4], const uint32_t c[4]) { - int32_t t[4]; - t[0] = b[0] + b[1]; - t[1] = b[2] + b[3]; - t[2] = c[0] + c[1]; - t[3] = c[2] + c[3]; - __builtin_memcpy(a, t, sizeof(t)); -} diff --git a/libc/intrin/phaddd.h b/libc/intrin/phaddd.h deleted file mode 100644 index 7751dd1c6..000000000 --- a/libc/intrin/phaddd.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PHADDD_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PHADDD_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void phaddd(uint32_t[4], const uint32_t[4], const uint32_t[4]); - -#define phaddd(A, B, C) \ - INTRIN_SSEVEX_X_X_X_(phaddd, SSSE3, "phaddd", INTRIN_NONCOMMUTATIVE, A, B, C) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PHADDD_H_ */ diff --git a/libc/intrin/phaddsw.c b/libc/intrin/phaddsw.c deleted file mode 100644 index 40fc4b697..000000000 --- a/libc/intrin/phaddsw.c +++ /dev/null @@ -1,45 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/phaddsw.h" -#include "libc/limits.h" -#include "libc/macros.internal.h" - -/** - * Adds adjacent shorts w/ saturation. - * - * @param 𝑎 [w/o] receives reduced 𝑏 and 𝑐 concatenated - * @param 𝑏 [r/o] supplies four pairs of shorts - * @param 𝑐 [r/o] supplies four pairs of shorts - * @note goes fast w/ ssse3 (intel c. 2004, amd c. 2011) - * @mayalias - */ -void(phaddsw)(int16_t a[8], const int16_t b[8], const int16_t c[8]) { - int i, t[8]; - t[0] = b[0] + b[1]; - t[1] = b[2] + b[3]; - t[2] = b[4] + b[5]; - t[3] = b[6] + b[7]; - t[4] = c[0] + c[1]; - t[5] = c[2] + c[3]; - t[6] = c[4] + c[5]; - t[7] = c[6] + c[7]; - for (i = 0; i < 8; ++i) { - a[i] = MIN(SHRT_MAX, MAX(SHRT_MIN, t[i])); - } -} diff --git a/libc/intrin/phaddsw.h b/libc/intrin/phaddsw.h deleted file mode 100644 index e85db81cb..000000000 --- a/libc/intrin/phaddsw.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PHADDSW_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PHADDSW_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void phaddsw(int16_t[8], const int16_t[8], const int16_t[8]); - -#define phaddsw(A, B, C) \ - INTRIN_SSEVEX_X_X_X_(phaddsw, SSSE3, "phaddsw", INTRIN_NONCOMMUTATIVE, A, B, \ - C) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PHADDSW_H_ */ diff --git a/libc/intrin/phaddw.c b/libc/intrin/phaddw.c deleted file mode 100644 index ee2d7e7a1..000000000 --- a/libc/intrin/phaddw.c +++ /dev/null @@ -1,42 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/phaddw.h" -#include "libc/str/str.h" - -/** - * Adds adjacent 16-bit integers. - * - * @param 𝑎 [w/o] receives reduced 𝑏 and 𝑐 concatenated - * @param 𝑏 [r/o] supplies four pairs of shorts - * @param 𝑐 [r/o] supplies four pairs of shorts - * @note goes fast w/ ssse3 (intel c. 2004, amd c. 2011) - * @mayalias - */ -void(phaddw)(int16_t a[8], const int16_t b[8], const int16_t c[8]) { - int16_t t[8]; - t[0] = b[0] + b[1]; - t[1] = b[2] + b[3]; - t[2] = b[4] + b[5]; - t[3] = b[6] + b[7]; - t[4] = c[0] + c[1]; - t[5] = c[2] + c[3]; - t[6] = c[4] + c[5]; - t[7] = c[6] + c[7]; - __builtin_memcpy(a, t, sizeof(t)); -} diff --git a/libc/intrin/phaddw.h b/libc/intrin/phaddw.h deleted file mode 100644 index efebaef56..000000000 --- a/libc/intrin/phaddw.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PHADDW_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PHADDW_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void phaddw(int16_t[8], const int16_t[8], const int16_t[8]); - -#define phaddw(A, B, C) \ - INTRIN_SSEVEX_X_X_X_(phaddw, SSSE3, "phaddw", INTRIN_NONCOMMUTATIVE, A, B, C) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PHADDW_H_ */ diff --git a/libc/intrin/phsubd.c b/libc/intrin/phsubd.c deleted file mode 100644 index ae86483b2..000000000 --- a/libc/intrin/phsubd.c +++ /dev/null @@ -1,38 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/phsubd.h" -#include "libc/str/str.h" - -/** - * Subtracts adjacent 32-bit integers. - * - * @param 𝑎 [w/o] receives reduced 𝑏 and 𝑐 concatenated - * @param 𝑏 [r/o] supplies two pairs of ints - * @param 𝑐 [r/o] supplies two pairs of ints - * @note goes fast w/ ssse3 - * @mayalias - */ -void(phsubd)(uint32_t a[4], const uint32_t b[4], const uint32_t c[4]) { - uint32_t t[4]; - t[0] = b[0] - b[1]; - t[1] = b[2] - b[3]; - t[2] = c[0] - c[1]; - t[3] = c[2] - c[3]; - __builtin_memcpy(a, t, sizeof(t)); -} diff --git a/libc/intrin/phsubd.h b/libc/intrin/phsubd.h deleted file mode 100644 index a35a2b266..000000000 --- a/libc/intrin/phsubd.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PHSUBD_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PHSUBD_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void phsubd(uint32_t[4], const uint32_t[4], const uint32_t[4]); - -#define phsubd(A, B, C) \ - INTRIN_SSEVEX_X_X_X_(phsubd, SSSE3, "phsubd", INTRIN_NONCOMMUTATIVE, A, B, C) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PHSUBD_H_ */ diff --git a/libc/intrin/phsubsw.c b/libc/intrin/phsubsw.c deleted file mode 100644 index 1e0f04bc5..000000000 --- a/libc/intrin/phsubsw.c +++ /dev/null @@ -1,45 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/phsubsw.h" -#include "libc/limits.h" -#include "libc/macros.internal.h" - -/** - * Subtracts adjacent shorts w/ saturation. - * - * @param 𝑎 [w/o] receives reduced 𝑏 and 𝑐 concatenated - * @param 𝑏 [r/o] supplies four pairs of shorts - * @param 𝑐 [r/o] supplies four pairs of shorts - * @note goes fast w/ ssse3 (intel c. 2004, amd c. 2011) - * @mayalias - */ -void(phsubsw)(int16_t a[8], const int16_t b[8], const int16_t c[8]) { - int i, t[8]; - t[0] = b[0] - b[1]; - t[1] = b[2] - b[3]; - t[2] = b[4] - b[5]; - t[3] = b[6] - b[7]; - t[4] = c[0] - c[1]; - t[5] = c[2] - c[3]; - t[6] = c[4] - c[5]; - t[7] = c[6] - c[7]; - for (i = 0; i < 8; ++i) { - a[i] = MIN(SHRT_MAX, MAX(SHRT_MIN, t[i])); - } -} diff --git a/libc/intrin/phsubsw.h b/libc/intrin/phsubsw.h deleted file mode 100644 index 8c81d7496..000000000 --- a/libc/intrin/phsubsw.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PHSUBSW_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PHSUBSW_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void phsubsw(int16_t[8], const int16_t[8], const int16_t[8]); - -#define phsubsw(A, B, C) \ - INTRIN_SSEVEX_X_X_X_(phsubsw, SSSE3, "phsubsw", INTRIN_NONCOMMUTATIVE, A, B, \ - C) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PHSUBSW_H_ */ diff --git a/libc/intrin/phsubw.c b/libc/intrin/phsubw.c deleted file mode 100644 index 9a03e20e6..000000000 --- a/libc/intrin/phsubw.c +++ /dev/null @@ -1,42 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/phsubw.h" -#include "libc/str/str.h" - -/** - * Subtracts adjacent 16-bit integers. - * - * @param 𝑎 [w/o] receives reduced 𝑏 and 𝑐 concatenated - * @param 𝑏 [r/o] supplies four pairs of shorts - * @param 𝑐 [r/o] supplies four pairs of shorts - * @note goes fast w/ ssse3 (intel c. 2004, amd c. 2011) - * @mayalias - */ -void(phsubw)(int16_t a[8], const int16_t b[8], const int16_t c[8]) { - int16_t t[8]; - t[0] = b[0] - b[1]; - t[1] = b[2] - b[3]; - t[2] = b[4] - b[5]; - t[3] = b[6] - b[7]; - t[4] = c[0] - c[1]; - t[5] = c[2] - c[3]; - t[6] = c[4] - c[5]; - t[7] = c[6] - c[7]; - __builtin_memcpy(a, t, sizeof(t)); -} diff --git a/libc/intrin/phsubw.h b/libc/intrin/phsubw.h deleted file mode 100644 index 0c21fa050..000000000 --- a/libc/intrin/phsubw.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PHSUBW_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PHSUBW_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void phsubw(int16_t[8], const int16_t[8], const int16_t[8]); - -#define phsubw(A, B, C) \ - INTRIN_SSEVEX_X_X_X_(phsubw, SSSE3, "phsubw", INTRIN_NONCOMMUTATIVE, A, B, C) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PHSUBW_H_ */ diff --git a/libc/intrin/pmaddwd.c b/libc/intrin/pmaddwd.c deleted file mode 100644 index 6aad2bce7..000000000 --- a/libc/intrin/pmaddwd.c +++ /dev/null @@ -1,34 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/pmaddwd.h" - -/** - * Multiplies 16-bit signed integers and adds adjacent results. - * - * @param 𝑎 [w/o] receives result - * @param 𝑏 [r/o] supplies first input vector - * @param 𝑐 [r/o] supplies second input vector - * @mayalias - */ -void(pmaddwd)(int32_t a[4], const int16_t b[8], const int16_t c[8]) { - unsigned i; - for (i = 0; i < 4; ++i) { - a[i] = b[i * 2] * c[i * 2] + b[i * 2 + 1] * c[i * 2 + 1]; - } -} diff --git a/libc/intrin/pmaddwd.h b/libc/intrin/pmaddwd.h deleted file mode 100644 index 45ae5dfb7..000000000 --- a/libc/intrin/pmaddwd.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PMADDWD_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PMADDWD_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void pmaddwd(int32_t[4], const int16_t[8], const int16_t[8]); - -#define pmaddwd(A, B, C) \ - INTRIN_SSEVEX_X_X_X_(pmaddwd, SSE2, "pmaddwd", INTRIN_COMMUTATIVE, A, B, C) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PMADDWD_H_ */ diff --git a/libc/intrin/pmaxsw.c b/libc/intrin/pmaxsw.c deleted file mode 100644 index 179fe5adb..000000000 --- a/libc/intrin/pmaxsw.c +++ /dev/null @@ -1,38 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/pmaxsw.h" -#include "libc/macros.internal.h" -#include "libc/str/str.h" - -/** - * Gets maximum of signed 16-bit integers. - * - * @param 𝑎 [w/o] receives result - * @param 𝑏 [r/o] supplies first input vector - * @param 𝑐 [r/o] supplies second input vector - * @mayalias - */ -void(pmaxsw)(int16_t a[8], const int16_t b[8], const int16_t c[8]) { - unsigned i; - int16_t r[8]; - for (i = 0; i < 8; ++i) { - r[i] = MAX(b[i], c[i]); - } - __builtin_memcpy(a, r, 16); -} diff --git a/libc/intrin/pmaxsw.h b/libc/intrin/pmaxsw.h deleted file mode 100644 index 406a607bc..000000000 --- a/libc/intrin/pmaxsw.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PMAXSW_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PMAXSW_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void pmaxsw(int16_t[8], const int16_t[8], const int16_t[8]); - -#define pmaxsw(A, B, C) \ - INTRIN_SSEVEX_X_X_X_(pmaxsw, SSE2, "pmaxsw", INTRIN_COMMUTATIVE, A, B, C) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PMAXSW_H_ */ diff --git a/libc/intrin/pmaxub.c b/libc/intrin/pmaxub.c deleted file mode 100644 index be0041da3..000000000 --- a/libc/intrin/pmaxub.c +++ /dev/null @@ -1,36 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/pmaxub.h" -#include "libc/macros.internal.h" - -/** - * Returns minimum of 8-bit unsigned integers. - * - * @param 𝑎 [w/o] receives result - * @param 𝑏 [r/o] supplies first input vector - * @param 𝑐 [r/o] supplies second input vector - * @mayalias - */ -void(pmaxub)(unsigned char a[16], const unsigned char b[16], - const unsigned char c[16]) { - unsigned i; - for (i = 0; i < 16; ++i) { - a[i] = MAX(b[i], c[i]); - } -} diff --git a/libc/intrin/pmaxub.h b/libc/intrin/pmaxub.h deleted file mode 100644 index 939bbea50..000000000 --- a/libc/intrin/pmaxub.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PMAXUB_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PMAXUB_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void pmaxub(unsigned char[16], const unsigned char[16], - const unsigned char[16]); - -#define pmaxub(A, B, C) \ - INTRIN_SSEVEX_X_X_X_(pmaxub, SSE2, "pmaxub", INTRIN_COMMUTATIVE, A, B, C) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PMAXUB_H_ */ diff --git a/libc/intrin/pminsw.c b/libc/intrin/pminsw.c deleted file mode 100644 index e72cf0424..000000000 --- a/libc/intrin/pminsw.c +++ /dev/null @@ -1,38 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/pminsw.h" -#include "libc/macros.internal.h" -#include "libc/str/str.h" - -/** - * Gets minimum of signed 16-bit integers. - * - * @param 𝑎 [w/o] receives result - * @param 𝑏 [r/o] supplies first input vector - * @param 𝑐 [r/o] supplies second input vector - * @mayalias - */ -void(pminsw)(int16_t a[8], const int16_t b[8], const int16_t c[8]) { - unsigned i; - int16_t r[8]; - for (i = 0; i < 8; ++i) { - r[i] = MIN(b[i], c[i]); - } - __builtin_memcpy(a, r, 16); -} diff --git a/libc/intrin/pminsw.h b/libc/intrin/pminsw.h deleted file mode 100644 index 6675076f8..000000000 --- a/libc/intrin/pminsw.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PMINSW_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PMINSW_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void pminsw(int16_t[8], const int16_t[8], const int16_t[8]); - -#define pminsw(A, B, C) \ - INTRIN_SSEVEX_X_X_X_(pminsw, SSE2, "pminsw", INTRIN_COMMUTATIVE, A, B, C) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PMINSW_H_ */ diff --git a/libc/intrin/pminub.c b/libc/intrin/pminub.c deleted file mode 100644 index 497c25cf5..000000000 --- a/libc/intrin/pminub.c +++ /dev/null @@ -1,36 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/pminub.h" -#include "libc/macros.internal.h" - -/** - * Returns minimum of 8-bit unsigned integers. - * - * @param 𝑎 [w/o] receives result - * @param 𝑏 [r/o] supplies first input vector - * @param 𝑐 [r/o] supplies second input vector - * @mayalias - */ -void(pminub)(unsigned char a[16], const unsigned char b[16], - const unsigned char c[16]) { - unsigned i; - for (i = 0; i < 16; ++i) { - a[i] = MIN(b[i], c[i]); - } -} diff --git a/libc/intrin/pminub.h b/libc/intrin/pminub.h deleted file mode 100644 index 8f7e29d38..000000000 --- a/libc/intrin/pminub.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PMINUB_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PMINUB_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void pminub(unsigned char[16], const unsigned char[16], - const unsigned char[16]); - -#define pminub(A, B, C) \ - INTRIN_SSEVEX_X_X_X_(pminub, SSE2, "pminub", INTRIN_COMMUTATIVE, A, B, C) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PMINUB_H_ */ diff --git a/libc/intrin/pmulhuw.c b/libc/intrin/pmulhuw.c deleted file mode 100644 index ffb529dca..000000000 --- a/libc/intrin/pmulhuw.c +++ /dev/null @@ -1,41 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/pmulhuw.h" -#include "libc/str/str.h" - -/** - * Multiplies 16-bit unsigned integers and stores high word. - * - * @param 𝑎 [w/o] receives result - * @param 𝑏 [r/o] supplies first input vector - * @param 𝑐 [r/o] supplies second input vector - * @mayalias - */ -void(pmulhuw)(uint16_t a[8], const uint16_t b[8], const uint16_t c[8]) { - unsigned i; - uint32_t x; - uint16_t r[8]; - for (i = 0; i < 8; ++i) { - x = b[i]; - x *= c[i]; - x >>= 16; - r[i] = x; - } - __builtin_memcpy(a, r, 16); -} diff --git a/libc/intrin/pmulhuw.h b/libc/intrin/pmulhuw.h deleted file mode 100644 index 341dd20ab..000000000 --- a/libc/intrin/pmulhuw.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PMULHUW_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PMULHUW_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void pmulhuw(uint16_t[8], const uint16_t[8], const uint16_t[8]); - -#define pmulhuw(A, B, C) \ - INTRIN_SSEVEX_X_X_X_(pmulhuw, SSE2, "pmulhuw", INTRIN_COMMUTATIVE, A, B, C) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PMULHUW_H_ */ diff --git a/libc/intrin/pmulhw.c b/libc/intrin/pmulhw.c deleted file mode 100644 index 86f7c2abf..000000000 --- a/libc/intrin/pmulhw.c +++ /dev/null @@ -1,37 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/pmulhw.h" -#include "libc/str/str.h" - -/** - * Multiplies 16-bit signed integers and stores high word. - * - * @param 𝑎 [w/o] receives result - * @param 𝑏 [r/o] supplies first input vector - * @param 𝑐 [r/o] supplies second input vector - * @mayalias - */ -void(pmulhw)(int16_t a[8], const int16_t b[8], const int16_t c[8]) { - unsigned i; - int16_t r[8]; - for (i = 0; i < 8; ++i) { - r[i] = ((b[i] * c[i]) & 0xffff0000) >> 16; - } - __builtin_memcpy(a, r, 16); -} diff --git a/libc/intrin/pmulhw.h b/libc/intrin/pmulhw.h deleted file mode 100644 index ee405a7d3..000000000 --- a/libc/intrin/pmulhw.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PMULHW_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PMULHW_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void pmulhw(int16_t[8], const int16_t[8], const int16_t[8]); - -#define pmulhw(A, B, C) \ - INTRIN_SSEVEX_X_X_X_(pmulhw, SSE2, "pmulhw", INTRIN_COMMUTATIVE, A, B, C) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PMULHW_H_ */ diff --git a/libc/intrin/pmulld.c b/libc/intrin/pmulld.c deleted file mode 100644 index 57fff8780..000000000 --- a/libc/intrin/pmulld.c +++ /dev/null @@ -1,38 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/pmulld.h" -#include "libc/str/str.h" - -/** - * Multiplies 32-bit integers. - * - * @param 𝑎 [w/o] receives result - * @param 𝑏 [r/o] supplies first input vector - * @param 𝑐 [r/o] supplies second input vector - * @see pmuludq() - * @mayalias - */ -void(pmulld)(uint32_t a[4], const uint32_t b[4], const uint32_t c[4]) { - unsigned i; - uint32_t r[4]; - for (i = 0; i < 4; ++i) { - r[i] = b[i] * c[i]; - } - __builtin_memcpy(a, r, 16); -} diff --git a/libc/intrin/pmulld.h b/libc/intrin/pmulld.h deleted file mode 100644 index 74e9563ae..000000000 --- a/libc/intrin/pmulld.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PMULLD_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PMULLD_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void pmulld(uint32_t[4], const uint32_t[4], const uint32_t[4]); - -#define pmulld(A, B, C) \ - INTRIN_SSEVEX_X_X_X_(pmulld, SSE4_1, "pmulld", INTRIN_COMMUTATIVE, A, B, C) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PMULLD_H_ */ diff --git a/libc/intrin/pmullw.c b/libc/intrin/pmullw.c deleted file mode 100644 index 91762a474..000000000 --- a/libc/intrin/pmullw.c +++ /dev/null @@ -1,37 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/pmullw.h" -#include "libc/str/str.h" - -/** - * Multiplies 16-bit signed integers. - * - * @param 𝑎 [w/o] receives result - * @param 𝑏 [r/o] supplies first input vector - * @param 𝑐 [r/o] supplies second input vector - * @mayalias - */ -void(pmullw)(int16_t a[8], const int16_t b[8], const int16_t c[8]) { - unsigned i; - int16_t r[8]; - for (i = 0; i < 8; ++i) { - r[i] = b[i] * c[i]; - } - __builtin_memcpy(a, r, 16); -} diff --git a/libc/intrin/pmullw.h b/libc/intrin/pmullw.h deleted file mode 100644 index 991653a8d..000000000 --- a/libc/intrin/pmullw.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PMULLW_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PMULLW_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void pmullw(int16_t[8], const int16_t[8], const int16_t[8]); - -#define pmullw(A, B, C) \ - INTRIN_SSEVEX_X_X_X_(pmullw, SSE2, "pmullw", INTRIN_COMMUTATIVE, A, B, C) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PMULLW_H_ */ diff --git a/libc/intrin/pmuludq.c b/libc/intrin/pmuludq.c deleted file mode 100644 index 83dc0332e..000000000 --- a/libc/intrin/pmuludq.c +++ /dev/null @@ -1,36 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/pmuludq.h" -#include "libc/str/str.h" - -/** - * Multiplies 32-bit unsigned integers w/ promotion. - * - * @param 𝑎 [w/o] receives result - * @param 𝑏 [r/o] supplies first input vector - * @param 𝑐 [r/o] supplies second input vector - * @see pmulld() - * @mayalias - */ -void(pmuludq)(uint64_t a[2], const uint32_t b[4], const uint32_t c[4]) { - unsigned i; - for (i = 0; i < 2; ++i) { - a[i] = (uint64_t)b[i * 2] * c[i * 2]; - } -} diff --git a/libc/intrin/pmuludq.h b/libc/intrin/pmuludq.h deleted file mode 100644 index 849eeb408..000000000 --- a/libc/intrin/pmuludq.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PMULUDQ_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PMULUDQ_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void pmuludq(uint64_t[2], const uint32_t[4], const uint32_t[4]); - -#define pmuludq(A, B, C) \ - INTRIN_SSEVEX_X_X_X_(pmuludq, SSE2, "pmuludq", INTRIN_COMMUTATIVE, A, B, C) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PMULUDQ_H_ */ diff --git a/libc/intrin/por.c b/libc/intrin/por.c deleted file mode 100644 index f22d5a00c..000000000 --- a/libc/intrin/por.c +++ /dev/null @@ -1,34 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/por.h" - -/** - * Ors 128-bit integers. - * - * @param 𝑎 [w/o] receives result - * @param 𝑏 [r/o] supplies first input vector - * @param 𝑐 [r/o] supplies second input vector - * @mayalias - */ -void(por)(uint64_t a[2], const uint64_t b[2], const uint64_t c[2]) { - unsigned i; - for (i = 0; i < 2; ++i) { - a[i] = b[i] | c[i]; - } -} diff --git a/libc/intrin/por.h b/libc/intrin/por.h deleted file mode 100644 index 62fede4b6..000000000 --- a/libc/intrin/por.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_POR_H_ -#define COSMOPOLITAN_LIBC_INTRIN_POR_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void por(uint64_t[2], const uint64_t[2], const uint64_t[2]); - -#define por(A, B, C) \ - INTRIN_SSEVEX_X_X_X_(por, SSE2, "por", INTRIN_COMMUTATIVE, A, B, C) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_POR_H_ */ diff --git a/libc/intrin/psadbw.c b/libc/intrin/psadbw.c deleted file mode 100644 index 4f77eb8c2..000000000 --- a/libc/intrin/psadbw.c +++ /dev/null @@ -1,36 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/psadbw.h" -#include "libc/macros.internal.h" - -/** - * Computes sum of absolute differences. - * - * @param 𝑎 [w/o] receives sum at first index and rest is zero'd - * @param 𝑏 [r/o] is your first unsigned byte array - * @param 𝑐 [r/o] is your second unsigned byte array - * @mayalias - */ -void(psadbw)(uint64_t a[2], const uint8_t b[16], const uint8_t c[16]) { - unsigned i, x, y; - for (x = i = 0; i < 8; ++i) x += ABS(b[i] - c[i]); - for (y = 0; i < 16; ++i) y += ABS(b[i] - c[i]); - a[0] = x; - a[1] = y; -} diff --git a/libc/intrin/psadbw.h b/libc/intrin/psadbw.h deleted file mode 100644 index 2eb739af5..000000000 --- a/libc/intrin/psadbw.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PSADBW_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PSADBW_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void psadbw(uint64_t[2], const uint8_t[16], const uint8_t[16]); - -#define psadbw(A, B, C) \ - INTRIN_SSEVEX_X_X_X_(psadbw, SSE2, "psadbw", INTRIN_COMMUTATIVE, A, B, C) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PSADBW_H_ */ diff --git a/libc/intrin/pshufb.c b/libc/intrin/pshufb.c deleted file mode 100644 index 1028419d2..000000000 --- a/libc/intrin/pshufb.c +++ /dev/null @@ -1,37 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/pshufb.h" -#include "libc/str/str.h" - -/** - * Shuffles and/or clears 8-bit integers. - * - * @param 𝑎 [w/o] receives result - * @param 𝑏 [r/o] supplies byte vector - * @param 𝑐 [r/o] supplies mask vector - * @note goes fast w/ ssse3 (intel c. 2004, amd c. 2011) - * @note doesn't perfectly emulate mmx - * @mayalias - */ -void(pshufb)(uint8_t a[16], const uint8_t b[16], const uint8_t c[16]) { - unsigned i; - uint8_t r[16]; - for (i = 0; i < 16; ++i) r[i] = (c[i] & 0x80) ? 0 : b[c[i] & 0x0F]; - __builtin_memcpy(a, r, 16); -} diff --git a/libc/intrin/pshufb.h b/libc/intrin/pshufb.h deleted file mode 100644 index 8adefc6ae..000000000 --- a/libc/intrin/pshufb.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PSHUFB_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PSHUFB_H_ -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void pshufb(uint8_t[16], const uint8_t[16], const uint8_t[16]); - -#define pshufb(A, B, C) \ - INTRIN_SSEVEX_X_X_X_(pshufb, SSSE3, "pshufb", INTRIN_NONCOMMUTATIVE, A, B, C) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PSHUFB_H_ */ diff --git a/libc/intrin/pshufd.c b/libc/intrin/pshufd.c deleted file mode 100644 index 993b05e70..000000000 --- a/libc/intrin/pshufd.c +++ /dev/null @@ -1,34 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/pshufd.h" -#include "libc/str/str.h" - -/** - * Shuffles int vector. - * @param 𝑚 needs to be a literal, constexpr, or embedding - * @mayalias - */ -void(pshufd)(int32_t b[4], const int32_t a[4], uint8_t m) { - int32_t t[4]; - t[0] = a[(m & 0b00000011) >> 0]; - t[1] = a[(m & 0b00001100) >> 2]; - t[2] = a[(m & 0b00110000) >> 4]; - t[3] = a[(m & 0b11000000) >> 6]; - __builtin_memcpy(b, t, 16); -} diff --git a/libc/intrin/pshufd.h b/libc/intrin/pshufd.h deleted file mode 100644 index e7dd60dd9..000000000 --- a/libc/intrin/pshufd.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PSHUFD_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PSHUFD_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void pshufd(int32_t[4], const int32_t[4], uint8_t); - -#define pshufd(A, B, I) INTRIN_SSEVEX_X_X_I_(pshufd, SSE2, "pshufd", A, B, I) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PSHUFD_H_ */ diff --git a/libc/intrin/pshufhw.c b/libc/intrin/pshufhw.c deleted file mode 100644 index 2b0ab8cd0..000000000 --- a/libc/intrin/pshufhw.c +++ /dev/null @@ -1,40 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/pshufhw.h" - -/** - * Shuffles lower half of word vector. - * @param 𝑚 needs to be a literal, constexpr, or embedding - * @mayalias - */ -void(pshufhw)(int16_t b[8], const int16_t a[8], uint8_t m) { - int16_t t[4]; - t[0] = a[4 + ((m & 0b00000011) >> 0)]; - t[1] = a[4 + ((m & 0b00001100) >> 2)]; - t[2] = a[4 + ((m & 0b00110000) >> 4)]; - t[3] = a[4 + ((m & 0b11000000) >> 6)]; - b[0] = a[0]; - b[1] = a[1]; - b[2] = a[2]; - b[3] = a[3]; - b[4] = t[0]; - b[5] = t[1]; - b[6] = t[2]; - b[7] = t[3]; -} diff --git a/libc/intrin/pshufhw.h b/libc/intrin/pshufhw.h deleted file mode 100644 index 051c1b6f1..000000000 --- a/libc/intrin/pshufhw.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PSHUFHW_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PSHUFHW_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void pshufhw(int16_t[8], const int16_t[8], uint8_t); - -#define pshufhw(A, B, I) INTRIN_SSEVEX_X_X_I_(pshufhw, SSE2, "pshufhw", A, B, I) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PSHUFHW_H_ */ diff --git a/libc/intrin/pshuflw.c b/libc/intrin/pshuflw.c deleted file mode 100644 index b35cde879..000000000 --- a/libc/intrin/pshuflw.c +++ /dev/null @@ -1,40 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/pshuflw.h" - -/** - * Shuffles lower half of word vector. - * @param 𝑚 needs to be a literal, constexpr, or embedding - * @mayalias - */ -void(pshuflw)(int16_t b[8], const int16_t a[8], uint8_t m) { - int16_t t[4]; - t[0] = a[(m & 0b00000011) >> 0]; - t[1] = a[(m & 0b00001100) >> 2]; - t[2] = a[(m & 0b00110000) >> 4]; - t[3] = a[(m & 0b11000000) >> 6]; - b[0] = t[0]; - b[1] = t[1]; - b[2] = t[2]; - b[3] = t[3]; - b[4] = a[4]; - b[5] = a[5]; - b[6] = a[6]; - b[7] = a[7]; -} diff --git a/libc/intrin/pshuflw.h b/libc/intrin/pshuflw.h deleted file mode 100644 index 1c2457b6e..000000000 --- a/libc/intrin/pshuflw.h +++ /dev/null @@ -1,13 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PSHUFLW_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PSHUFLW_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void pshuflw(int16_t[8], const int16_t[8], uint8_t); - -#define pshuflw(A, B, I) INTRIN_SSEVEX_X_X_I_(pshuflw, SSE2, "pshuflw", A, B, I) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PSHUFLW_H_ */ diff --git a/libc/intrin/pshufw.c b/libc/intrin/pshufw.c deleted file mode 100644 index d85019ab5..000000000 --- a/libc/intrin/pshufw.c +++ /dev/null @@ -1,36 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/pshufw.h" - -/** - * Shuffles mmx vector. - * @param 𝑚 needs to be a literal, constexpr, or embedding - * @mayalias - */ -void(pshufw)(int16_t b[4], const int16_t a[4], uint8_t m) { - int16_t t[4]; - t[0] = a[(m & 0b00000011) >> 0]; - t[1] = a[(m & 0b00001100) >> 2]; - t[2] = a[(m & 0b00110000) >> 4]; - t[3] = a[(m & 0b11000000) >> 6]; - b[0] = t[0]; - b[1] = t[1]; - b[2] = t[2]; - b[3] = t[3]; -} diff --git a/libc/intrin/pshufw.h b/libc/intrin/pshufw.h deleted file mode 100644 index d5c6eb195..000000000 --- a/libc/intrin/pshufw.h +++ /dev/null @@ -1,10 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PSHUFW_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PSHUFW_H_ -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void pshufw(int16_t[4], const int16_t[4], uint8_t); - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PSHUFW_H_ */ diff --git a/libc/intrin/psignb.c b/libc/intrin/psignb.c deleted file mode 100644 index f3c77d087..000000000 --- a/libc/intrin/psignb.c +++ /dev/null @@ -1,37 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/psignb.h" -#include "libc/str/str.h" - -/** - * Conditionally negates or zeroes signed bytes. - * @note goes fast w/ ssse3 (intel c. 2004, amd c. 2011) - */ -void(psignb)(int8_t a[16], const int8_t b[16], const int8_t c[16]) { - unsigned i; - for (i = 0; i < 16; ++i) { - if (!c[i]) { - a[i] = 0; - } else if (c[i] < 0) { - a[i] = -b[i]; - } else { - a[i] = b[i]; - } - } -} diff --git a/libc/intrin/psignb.h b/libc/intrin/psignb.h deleted file mode 100644 index 92f013219..000000000 --- a/libc/intrin/psignb.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PSIGNB_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PSIGNB_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void psignb(int8_t[16], const int8_t[16], const int8_t[16]); - -#define psignb(A, B, C) \ - INTRIN_SSEVEX_X_X_X_(psignb, SSSE3, "psignb", INTRIN_NONCOMMUTATIVE, A, B, C) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PSIGNB_H_ */ diff --git a/libc/intrin/psignd.c b/libc/intrin/psignd.c deleted file mode 100644 index 2ae6e6c35..000000000 --- a/libc/intrin/psignd.c +++ /dev/null @@ -1,37 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/psignd.h" -#include "libc/str/str.h" - -/** - * Conditionally negates or zeroes ints. - * @note goes fast w/ ssse3 (intel c. 2004, amd c. 2011) - */ -void(psignd)(int32_t a[4], const int32_t b[4], const int32_t c[4]) { - unsigned i; - for (i = 0; i < 4; ++i) { - if (!c[i]) { - a[i] = 0; - } else if (c[i] < 0) { - a[i] = -(uint32_t)b[i]; - } else { - a[i] = b[i]; - } - } -} diff --git a/libc/intrin/psignd.h b/libc/intrin/psignd.h deleted file mode 100644 index e22cb12a5..000000000 --- a/libc/intrin/psignd.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PSIGND_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PSIGND_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void psignd(int32_t[4], const int32_t[4], const int32_t[4]); - -#define psignd(A, B, C) \ - INTRIN_SSEVEX_X_X_X_(psignd, SSSE3, "psignd", INTRIN_NONCOMMUTATIVE, A, B, C) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PSIGND_H_ */ diff --git a/libc/intrin/psignw.c b/libc/intrin/psignw.c deleted file mode 100644 index 14a3217aa..000000000 --- a/libc/intrin/psignw.c +++ /dev/null @@ -1,37 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/psignw.h" -#include "libc/str/str.h" - -/** - * Conditionally negates or zeroes shorts. - * @note goes fast w/ ssse3 (intel c. 2004, amd c. 2011) - */ -void(psignw)(int16_t a[8], const int16_t b[8], const int16_t c[8]) { - unsigned i; - for (i = 0; i < 8; ++i) { - if (!c[i]) { - a[i] = 0; - } else if (c[i] < 0) { - a[i] = -b[i]; - } else { - a[i] = b[i]; - } - } -} diff --git a/libc/intrin/psignw.h b/libc/intrin/psignw.h deleted file mode 100644 index ad0dc50b2..000000000 --- a/libc/intrin/psignw.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PSIGNW_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PSIGNW_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void psignw(int16_t[8], const int16_t[8], const int16_t[8]); - -#define psignw(A, B, C) \ - INTRIN_SSEVEX_X_X_X_(psignw, SSSE3, "psignw", INTRIN_NONCOMMUTATIVE, A, B, C) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PSIGNW_H_ */ diff --git a/libc/intrin/pslld.c b/libc/intrin/pslld.c deleted file mode 100644 index 8d9107d27..000000000 --- a/libc/intrin/pslld.c +++ /dev/null @@ -1,37 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/pslld.h" -#include "libc/str/str.h" - -/** - * Multiplies ints by two power. - * - * @note c needs to be a literal, asmconstexpr, or linkconstsym - * @mayalias - */ -void(pslld)(uint32_t a[4], const uint32_t b[4], unsigned char c) { - unsigned i; - if (c <= 31) { - for (i = 0; i < 4; ++i) { - a[i] = b[i] << c; - } - } else { - __builtin_memset(a, 0, 16); - } -} diff --git a/libc/intrin/pslld.h b/libc/intrin/pslld.h deleted file mode 100644 index 845f83266..000000000 --- a/libc/intrin/pslld.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PSLLD_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PSLLD_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void pslld(uint32_t[4], const uint32_t[4], unsigned char); -void pslldv(uint32_t[4], const uint32_t[4], const uint64_t[2]); - -#define pslld(A, B, I) INTRIN_SSEVEX_X_I_(pslld, SSE2, "pslld", A, B, I) -#define pslldv(A, B, C) \ - INTRIN_SSEVEX_X_X_X_(pslldv, SSE2, "pslld", INTRIN_NONCOMMUTATIVE, A, B, C) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PSLLD_H_ */ diff --git a/libc/intrin/pslldq.c b/libc/intrin/pslldq.c deleted file mode 100644 index 6285204ba..000000000 --- a/libc/intrin/pslldq.c +++ /dev/null @@ -1,36 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/pslldq.h" -#include "libc/str/str.h" - -/** - * Shifts vector left by n bytes w/ zero-fill. - * - * @param a is input vector - * @param b receives output - * @mayalias - */ -void(pslldq)(uint8_t b[16], const uint8_t a[16], unsigned long n) { - unsigned i; - uint8_t t[16]; - if (n > 16) n = 16; - for (i = 0; i < n; ++i) t[i] = 0; - for (i = 0; i < 16 - n; ++i) t[n + i] = a[i]; - __builtin_memcpy(b, t, 16); -} diff --git a/libc/intrin/pslldq.h b/libc/intrin/pslldq.h deleted file mode 100644 index d9f2ff479..000000000 --- a/libc/intrin/pslldq.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PSLLDQ_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PSLLDQ_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void pslldq(uint8_t[16], const uint8_t[16], unsigned long); - -#if defined(__x86_64__) && !defined(__STRICT_ANSI__) -__intrin_xmm_t __pslldqs(__intrin_xmm_t); -#define pslldq(B, A, I) \ - do { \ - if (__builtin_expect(!IsModeDbg() && X86_NEED(SSE) && X86_HAVE(SSE2), \ - 1)) { \ - __intrin_xmm_t *Xmm0 = (void *)(B); \ - const __intrin_xmm_t *Xmm1 = (const __intrin_xmm_t *)(A); \ - if (__builtin_constant_p(I)) { \ - if (!X86_NEED(AVX)) { \ - asm("pslldq\t%1,%0" : "=x"(*Xmm0) : "i"(I), "0"(*Xmm1)); \ - } else { \ - asm("vpslldq\t%2,%1,%0" : "=x"(*Xmm0) : "x"(*Xmm1), "i"(I)); \ - } \ - } else { \ - unsigned long Vimm = (I); \ - typeof(__pslldqs) *Fn; \ - if (Vimm > 16) Vimm = 16; \ - Fn = (typeof(__pslldqs) *)((uintptr_t)&__pslldqs + Vimm * 8); \ - *Xmm0 = Fn(*Xmm1); \ - } \ - } else { \ - pslldq(B, A, I); \ - } \ - } while (0) -#endif - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PSLLDQ_H_ */ diff --git a/libc/intrin/pslldqs.S b/libc/intrin/pslldqs.S deleted file mode 100644 index 86e2fd427..000000000 --- a/libc/intrin/pslldqs.S +++ /dev/null @@ -1,93 +0,0 @@ -/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│ -│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/macros.internal.h" - -// Jump table for pslldq() with non-constexpr immediate parameter. - .balign 8 -__pslldqs: - pslldq $0,%xmm0 - ret - nop - nop - pslldq $1,%xmm0 - ret - nop - nop - pslldq $2,%xmm0 - ret - nop - nop - pslldq $3,%xmm0 - ret - nop - nop - pslldq $4,%xmm0 - ret - nop - nop - pslldq $5,%xmm0 - ret - nop - nop - pslldq $6,%xmm0 - ret - nop - nop - pslldq $7,%xmm0 - ret - nop - nop - pslldq $8,%xmm0 - ret - nop - nop - pslldq $9,%xmm0 - ret - nop - nop - pslldq $10,%xmm0 - ret - nop - nop - pslldq $11,%xmm0 - ret - nop - nop - pslldq $12,%xmm0 - ret - nop - nop - pslldq $13,%xmm0 - ret - nop - nop - pslldq $14,%xmm0 - ret - nop - nop - pslldq $15,%xmm0 - ret - nop - nop - pslldq $16,%xmm0 - ret - .if . - __pslldqs != 8 * 17 - 2 - .error "bad assemblage" - .endif - .endfn __pslldqs,globl diff --git a/libc/intrin/pslldv.c b/libc/intrin/pslldv.c deleted file mode 100644 index ff746386a..000000000 --- a/libc/intrin/pslldv.c +++ /dev/null @@ -1,35 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/pslld.h" -#include "libc/str/str.h" - -/** - * Multiplies ints by two power. - * @mayalias - */ -void(pslldv)(uint32_t a[4], const uint32_t b[4], const uint64_t c[2]) { - unsigned i; - if (c[0] <= 31) { - for (i = 0; i < 4; ++i) { - a[i] = b[i] << c[0]; - } - } else { - __builtin_memset(a, 0, 16); - } -} diff --git a/libc/intrin/psllq.c b/libc/intrin/psllq.c deleted file mode 100644 index 63340cf01..000000000 --- a/libc/intrin/psllq.c +++ /dev/null @@ -1,37 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/psllq.h" -#include "libc/str/str.h" - -/** - * Multiplies longs by two power. - * - * @note c needs to be a literal, asmconstexpr, or linkconstsym - * @mayalias - */ -void(psllq)(uint64_t a[2], const uint64_t b[2], unsigned char c) { - unsigned i; - if (c <= 63) { - for (i = 0; i < 2; ++i) { - a[i] = b[i] << c; - } - } else { - __builtin_memset(a, 0, 16); - } -} diff --git a/libc/intrin/psllq.h b/libc/intrin/psllq.h deleted file mode 100644 index 7c04acb0a..000000000 --- a/libc/intrin/psllq.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PSLLQ_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PSLLQ_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void psllq(uint64_t[2], const uint64_t[2], unsigned char); -void psllqv(uint64_t[2], const uint64_t[2], const uint64_t[2]); - -#define psllq(A, B, I) INTRIN_SSEVEX_X_I_(psllq, SSE2, "psllq", A, B, I) -#define psllqv(A, B, C) \ - INTRIN_SSEVEX_X_X_X_(psllqv, SSE2, "psllq", INTRIN_NONCOMMUTATIVE, A, B, C) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PSLLQ_H_ */ diff --git a/libc/intrin/psllqv.c b/libc/intrin/psllqv.c deleted file mode 100644 index 40b8165ce..000000000 --- a/libc/intrin/psllqv.c +++ /dev/null @@ -1,35 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/psllq.h" -#include "libc/str/str.h" - -/** - * Multiplies longs by two power. - * @mayalias - */ -void(psllqv)(uint64_t a[2], const uint64_t b[2], const uint64_t c[2]) { - unsigned i; - if (c[0] <= 63) { - for (i = 0; i < 2; ++i) { - a[i] = b[i] << c[0]; - } - } else { - __builtin_memset(a, 0, 16); - } -} diff --git a/libc/intrin/psllw.c b/libc/intrin/psllw.c deleted file mode 100644 index 380215513..000000000 --- a/libc/intrin/psllw.c +++ /dev/null @@ -1,37 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/psllw.h" -#include "libc/str/str.h" - -/** - * Multiplies shorts by two power. - * - * @note c needs to be a literal, asmconstexpr, or linkconstsym - * @mayalias - */ -void(psllw)(uint16_t a[8], const uint16_t b[8], unsigned char c) { - unsigned i; - if (c <= 15) { - for (i = 0; i < 8; ++i) { - a[i] = b[i] << c; - } - } else { - __builtin_memset(a, 0, 16); - } -} diff --git a/libc/intrin/psllw.h b/libc/intrin/psllw.h deleted file mode 100644 index 0a38ceef5..000000000 --- a/libc/intrin/psllw.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PSLLW_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PSLLW_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void psllw(uint16_t[8], const uint16_t[8], unsigned char); -void psllwv(uint16_t[8], const uint16_t[8], const uint64_t[2]); - -#define psllw(A, B, I) INTRIN_SSEVEX_X_I_(psllw, SSE2, "psllw", A, B, I) -#define psllwv(A, B, C) \ - INTRIN_SSEVEX_X_X_X_(psllwv, SSE2, "psllw", INTRIN_NONCOMMUTATIVE, A, B, C) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PSLLW_H_ */ diff --git a/libc/intrin/psllwv.c b/libc/intrin/psllwv.c deleted file mode 100644 index 5d0b23442..000000000 --- a/libc/intrin/psllwv.c +++ /dev/null @@ -1,36 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/psllw.h" -#include "libc/str/str.h" - -/** - * Multiplies shorts by two power. - * - * @mayalias - */ -void(psllwv)(uint16_t a[8], const uint16_t b[8], const uint64_t c[2]) { - unsigned i; - if (c[0] < 16) { - for (i = 0; i < 8; ++i) { - a[i] = b[i] << c[0]; - } - } else { - __builtin_memset(a, 0, 16); - } -} diff --git a/libc/intrin/psrad.c b/libc/intrin/psrad.c deleted file mode 100644 index 694998048..000000000 --- a/libc/intrin/psrad.c +++ /dev/null @@ -1,34 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/psrad.h" - -/** - * Divides ints by two power. - * - * @note c needs to be a literal, asmconstexpr, or linkconstsym - * @note arithmetic shift right will sign extend negatives - * @mayalias - */ -void(psrad)(int32_t a[4], const int32_t b[4], unsigned char k) { - unsigned i; - if (k > 31) k = 31; - for (i = 0; i < 4; ++i) { - a[i] = b[i] >> k; - } -} diff --git a/libc/intrin/psrad.h b/libc/intrin/psrad.h deleted file mode 100644 index 1a91b00c2..000000000 --- a/libc/intrin/psrad.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PSRAD_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PSRAD_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void psrad(int32_t[4], const int32_t[4], unsigned char); -void psradv(int32_t[4], const int32_t[4], const uint64_t[2]); - -#define psrad(A, B, I) INTRIN_SSEVEX_X_I_(psrad, SSE2, "psrad", A, B, I) -#define psradv(A, B, C) \ - INTRIN_SSEVEX_X_X_X_(psradv, SSE2, "psrad", INTRIN_NONCOMMUTATIVE, A, B, C) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PSRAD_H_ */ diff --git a/libc/intrin/psradv.c b/libc/intrin/psradv.c deleted file mode 100644 index 8506a4ffa..000000000 --- a/libc/intrin/psradv.c +++ /dev/null @@ -1,34 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/psrad.h" - -/** - * Divides shorts by two powers. - * - * @note arithmetic shift right will sign extend negatives - * @mayalias - */ -void(psradv)(int32_t a[4], const int32_t b[4], const uint64_t c[2]) { - unsigned i; - unsigned char k; - k = c[0] > 31 ? 31 : c[0]; - for (i = 0; i < 4; ++i) { - a[i] = b[i] >> k; - } -} diff --git a/libc/intrin/psrld.c b/libc/intrin/psrld.c deleted file mode 100644 index ec9ac8346..000000000 --- a/libc/intrin/psrld.c +++ /dev/null @@ -1,38 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/psrld.h" -#include "libc/str/str.h" - -/** - * Divides unsigned ints by two power. - * - * @note c needs to be a literal, asmconstexpr, or linkconstsym - * @note logical shift does not sign extend negatives - * @mayalias - */ -void(psrld)(uint32_t a[4], const uint32_t b[4], unsigned char c) { - unsigned i; - if (c <= 31) { - for (i = 0; i < 4; ++i) { - a[i] = b[i] >> c; - } - } else { - __builtin_memset(a, 0, 16); - } -} diff --git a/libc/intrin/psrld.h b/libc/intrin/psrld.h deleted file mode 100644 index 9667b8f98..000000000 --- a/libc/intrin/psrld.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PSRLD_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PSRLD_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void psrld(uint32_t[4], const uint32_t[4], unsigned char); -void psrldv(uint32_t[4], const uint32_t[4], const uint64_t[2]); - -#define psrld(A, B, I) INTRIN_SSEVEX_X_I_(psrld, SSE2, "psrld", A, B, I) -#define psrldv(A, B, C) \ - INTRIN_SSEVEX_X_X_X_(psrldv, SSE2, "psrld", INTRIN_NONCOMMUTATIVE, A, B, C) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PSRLD_H_ */ diff --git a/libc/intrin/psrldq.c b/libc/intrin/psrldq.c deleted file mode 100644 index eb69a2fab..000000000 --- a/libc/intrin/psrldq.c +++ /dev/null @@ -1,36 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/psrldq.h" -#include "libc/str/str.h" - -/** - * Shifts vector left by n bytes w/ zero-fill. - * - * @param a is input vector - * @param b receives output - * @mayalias - */ -void(psrldq)(uint8_t b[16], const uint8_t a[16], unsigned long n) { - if (n > 16) { - n = 16; - } else { - __builtin_memcpy(b, a + n, 16 - n); - } - __builtin_memset(b + (16 - n), 0, n); -} diff --git a/libc/intrin/psrldq.h b/libc/intrin/psrldq.h deleted file mode 100644 index 3e0044811..000000000 --- a/libc/intrin/psrldq.h +++ /dev/null @@ -1,38 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PSRLDQ_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PSRLDQ_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void psrldq(uint8_t[16], const uint8_t[16], unsigned long); - -#if defined(__x86_64__) && !defined(__STRICT_ANSI__) -__intrin_xmm_t __psrldqs(__intrin_xmm_t); -#define psrldq(B, A, I) \ - do { \ - if (__builtin_expect(!IsModeDbg() && X86_NEED(SSE) && X86_HAVE(SSE2), \ - 1)) { \ - __intrin_xmm_t *Xmm0 = (void *)(B); \ - const __intrin_xmm_t *Xmm1 = (const __intrin_xmm_t *)(A); \ - if (__builtin_constant_p(I)) { \ - if (!X86_NEED(AVX)) { \ - asm("psrldq\t%1,%0" : "=x"(*Xmm0) : "i"(I), "0"(*Xmm1)); \ - } else { \ - asm("vpsrldq\t%2,%1,%0" : "=x"(*Xmm0) : "x"(*Xmm1), "i"(I)); \ - } \ - } else { \ - unsigned long Vimm = (I); \ - typeof(__psrldqs) *Fn; \ - if (Vimm > 16) Vimm = 16; \ - Fn = (typeof(__psrldqs) *)((uintptr_t)&__psrldqs + Vimm * 8); \ - *Xmm0 = Fn(*Xmm1); \ - } \ - } else { \ - psrldq(B, A, I); \ - } \ - } while (0) -#endif - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PSRLDQ_H_ */ diff --git a/libc/intrin/psrldqs.S b/libc/intrin/psrldqs.S deleted file mode 100644 index 7eb4935ab..000000000 --- a/libc/intrin/psrldqs.S +++ /dev/null @@ -1,93 +0,0 @@ -/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│ -│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/macros.internal.h" - -// Jump table for psrldq() with non-constexpr immediate parameter. - .balign 8 -__psrldqs: - psrldq $0,%xmm0 - ret - nop - nop - psrldq $1,%xmm0 - ret - nop - nop - psrldq $2,%xmm0 - ret - nop - nop - psrldq $3,%xmm0 - ret - nop - nop - psrldq $4,%xmm0 - ret - nop - nop - psrldq $5,%xmm0 - ret - nop - nop - psrldq $6,%xmm0 - ret - nop - nop - psrldq $7,%xmm0 - ret - nop - nop - psrldq $8,%xmm0 - ret - nop - nop - psrldq $9,%xmm0 - ret - nop - nop - psrldq $10,%xmm0 - ret - nop - nop - psrldq $11,%xmm0 - ret - nop - nop - psrldq $12,%xmm0 - ret - nop - nop - psrldq $13,%xmm0 - ret - nop - nop - psrldq $14,%xmm0 - ret - nop - nop - psrldq $15,%xmm0 - ret - nop - nop - psrldq $16,%xmm0 - ret - .if . - __psrldqs != 8 * 17 - 2 - .error "bad assemblage" - .endif - .endfn __psrldqs,globl diff --git a/libc/intrin/psrldv.c b/libc/intrin/psrldv.c deleted file mode 100644 index 7b3dbe0cc..000000000 --- a/libc/intrin/psrldv.c +++ /dev/null @@ -1,37 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/psrld.h" -#include "libc/str/str.h" - -/** - * Divides ints by two power. - * - * @note logical shift does not sign extend negatives - * @mayalias - */ -void(psrldv)(uint32_t a[4], const uint32_t b[4], const uint64_t c[2]) { - unsigned i; - if (c[0] <= 31) { - for (i = 0; i < 4; ++i) { - a[i] = b[i] >> c[0]; - } - } else { - __builtin_memset(a, 0, 16); - } -} diff --git a/libc/intrin/psrlq.c b/libc/intrin/psrlq.c deleted file mode 100644 index 37613a768..000000000 --- a/libc/intrin/psrlq.c +++ /dev/null @@ -1,38 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/psrlq.h" -#include "libc/str/str.h" - -/** - * Divides unsigned longs by two power. - * - * @note c needs to be a literal, asmconstexpr, or linkconstsym - * @note logical shift does not sign extend negatives - * @mayalias - */ -void(psrlq)(uint64_t a[2], const uint64_t b[2], unsigned char c) { - unsigned i; - if (c <= 63) { - for (i = 0; i < 2; ++i) { - a[i] = b[i] >> c; - } - } else { - __builtin_memset(a, 0, 16); - } -} diff --git a/libc/intrin/psrlq.h b/libc/intrin/psrlq.h deleted file mode 100644 index 96abe9c4d..000000000 --- a/libc/intrin/psrlq.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PSRLQ_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PSRLQ_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void psrlq(uint64_t[2], const uint64_t[2], unsigned char); -void psrlqv(uint64_t[2], const uint64_t[2], const uint64_t[2]); - -#define psrlq(A, B, I) INTRIN_SSEVEX_X_I_(psrlq, SSE2, "psrlq", A, B, I) -#define psrlqv(A, B, C) \ - INTRIN_SSEVEX_X_X_X_(psrlqv, SSE2, "psrlq", INTRIN_NONCOMMUTATIVE, A, B, C) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PSRLQ_H_ */ diff --git a/libc/intrin/psrlqv.c b/libc/intrin/psrlqv.c deleted file mode 100644 index 8ba6f4765..000000000 --- a/libc/intrin/psrlqv.c +++ /dev/null @@ -1,37 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/psrlq.h" -#include "libc/str/str.h" - -/** - * Divides unsigned longs by two power. - * - * @note logical shift does not sign extend negatives - * @mayalias - */ -void(psrlqv)(uint64_t a[2], const uint64_t b[2], const uint64_t c[2]) { - unsigned i; - if (c[0] <= 63) { - for (i = 0; i < 2; ++i) { - a[i] = b[i] >> c[0]; - } - } else { - __builtin_memset(a, 0, 16); - } -} diff --git a/libc/intrin/psrlw.c b/libc/intrin/psrlw.c deleted file mode 100644 index cfc5bc0d1..000000000 --- a/libc/intrin/psrlw.c +++ /dev/null @@ -1,38 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/psrlw.h" -#include "libc/str/str.h" - -/** - * Divides unsigned shorts by two power. - * - * @note c needs to be a literal, asmconstexpr, or linkconstsym - * @note logical shift does not sign extend negatives - * @mayalias - */ -void(psrlw)(uint16_t a[8], const uint16_t b[8], unsigned char c) { - unsigned i; - if (c < 16) { - for (i = 0; i < 8; ++i) { - a[i] = b[i] >> c; - } - } else { - __builtin_memset(a, 0, 16); - } -} diff --git a/libc/intrin/psrlw.h b/libc/intrin/psrlw.h deleted file mode 100644 index 25dee7f9c..000000000 --- a/libc/intrin/psrlw.h +++ /dev/null @@ -1,16 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PSRLW_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PSRLW_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void psrlw(uint16_t[8], const uint16_t[8], unsigned char); -void psrlwv(uint16_t[8], const uint16_t[8], const uint64_t[2]); - -#define psrlw(A, B, I) INTRIN_SSEVEX_X_I_(psrlw, SSE2, "psrlw", A, B, I) -#define psrlwv(A, B, C) \ - INTRIN_SSEVEX_X_X_X_(psrlwv, SSE2, "psrlw", INTRIN_NONCOMMUTATIVE, A, B, C) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PSRLW_H_ */ diff --git a/libc/intrin/psrlwv.c b/libc/intrin/psrlwv.c deleted file mode 100644 index cf11f2d87..000000000 --- a/libc/intrin/psrlwv.c +++ /dev/null @@ -1,37 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/psrlw.h" -#include "libc/str/str.h" - -/** - * Divides unsigned shorts by two power. - * - * @note logical shift does not sign extend negatives - * @mayalias - */ -void(psrlwv)(uint16_t a[8], const uint16_t b[8], const uint64_t c[2]) { - unsigned i; - if (c[0] < 16) { - for (i = 0; i < 8; ++i) { - a[i] = b[i] >> c[0]; - } - } else { - __builtin_memset(a, 0, 16); - } -} diff --git a/libc/intrin/psubb.c b/libc/intrin/psubb.c deleted file mode 100644 index 0f17872d9..000000000 --- a/libc/intrin/psubb.c +++ /dev/null @@ -1,37 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/psubb.h" -#include "libc/str/str.h" - -/** - * Subtracts 8-bit integers. - * - * @param 𝑎 [w/o] receives result - * @param 𝑏 [r/o] supplies first input vector - * @param 𝑐 [r/o] supplies second input vector - * @mayalias - */ -void(psubb)(uint8_t a[16], const uint8_t b[16], const uint8_t c[16]) { - unsigned i; - uint8_t r[16]; - for (i = 0; i < 16; ++i) { - r[i] = b[i] - c[i]; - } - __builtin_memcpy(a, r, 16); -} diff --git a/libc/intrin/psubb.h b/libc/intrin/psubb.h deleted file mode 100644 index 37b04263a..000000000 --- a/libc/intrin/psubb.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PSUBB_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PSUBB_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void psubb(uint8_t[16], const uint8_t[16], const uint8_t[16]); - -#define psubb(A, B, C) \ - INTRIN_SSEVEX_X_X_X_(psubb, SSE2, "psubb", INTRIN_NONCOMMUTATIVE, A, B, C) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PSUBB_H_ */ diff --git a/libc/intrin/psubd.c b/libc/intrin/psubd.c deleted file mode 100644 index b21bd6f4b..000000000 --- a/libc/intrin/psubd.c +++ /dev/null @@ -1,37 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/psubd.h" -#include "libc/str/str.h" - -/** - * Subtracts 32-bit integers. - * - * @param 𝑎 [w/o] receives result - * @param 𝑏 [r/o] supplies first input vector - * @param 𝑐 [r/o] supplies second input vector - * @mayalias - */ -void(psubd)(uint32_t a[4], const uint32_t b[4], const uint32_t c[4]) { - unsigned i; - uint32_t r[4]; - for (i = 0; i < 4; ++i) { - r[i] = b[i] - c[i]; - } - __builtin_memcpy(a, r, 16); -} diff --git a/libc/intrin/psubd.h b/libc/intrin/psubd.h deleted file mode 100644 index 4aa30b9ce..000000000 --- a/libc/intrin/psubd.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PSUBD_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PSUBD_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void psubd(uint32_t[4], const uint32_t[4], const uint32_t[4]); - -#define psubd(A, B, C) \ - INTRIN_SSEVEX_X_X_X_(psubd, SSE2, "psubd", INTRIN_NONCOMMUTATIVE, A, B, C) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PSUBD_H_ */ diff --git a/libc/intrin/psubq.c b/libc/intrin/psubq.c deleted file mode 100644 index 44efe9853..000000000 --- a/libc/intrin/psubq.c +++ /dev/null @@ -1,37 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/psubq.h" -#include "libc/str/str.h" - -/** - * Subtracts 64-bit integers. - * - * @param 𝑎 [w/o] receives result - * @param 𝑏 [r/o] supplies first input vector - * @param 𝑐 [r/o] supplies second input vector - * @mayalias - */ -void(psubq)(uint64_t a[2], const uint64_t b[2], const uint64_t c[2]) { - unsigned i; - uint64_t r[2]; - for (i = 0; i < 2; ++i) { - r[i] = b[i] - c[i]; - } - __builtin_memcpy(a, r, 16); -} diff --git a/libc/intrin/psubq.h b/libc/intrin/psubq.h deleted file mode 100644 index 9b4a5d3b9..000000000 --- a/libc/intrin/psubq.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PSUBQ_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PSUBQ_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void psubq(uint64_t[2], const uint64_t[2], const uint64_t[2]); - -#define psubq(A, B, C) \ - INTRIN_SSEVEX_X_X_X_(psubq, SSE2, "psubq", INTRIN_NONCOMMUTATIVE, A, B, C) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PSUBQ_H_ */ diff --git a/libc/intrin/psubsb.c b/libc/intrin/psubsb.c deleted file mode 100644 index e7e7d3049..000000000 --- a/libc/intrin/psubsb.c +++ /dev/null @@ -1,37 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/psubsb.h" -#include "libc/limits.h" -#include "libc/macros.internal.h" -#include "libc/str/str.h" - -/** - * Subtracts signed 8-bit integers w/ saturation. - * - * @param 𝑎 [w/o] receives result - * @param 𝑏 [r/o] supplies first input vector - * @param 𝑐 [r/o] supplies second input vector - * @mayalias - */ -void(psubsb)(int8_t a[16], const int8_t b[16], const int8_t c[16]) { - unsigned i; - int8_t r[16]; - for (i = 0; i < 16; ++i) r[i] = MIN(INT8_MAX, MAX(INT8_MIN, b[i] - c[i])); - __builtin_memcpy(a, r, 16); -} diff --git a/libc/intrin/psubsb.h b/libc/intrin/psubsb.h deleted file mode 100644 index 4e263c0d9..000000000 --- a/libc/intrin/psubsb.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PSUBSB_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PSUBSB_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void psubsb(int8_t[16], const int8_t[16], const int8_t[16]); - -#define psubsb(A, B, C) \ - INTRIN_SSEVEX_X_X_X_(psubsb, SSE2, "psubsb", INTRIN_NONCOMMUTATIVE, A, B, C) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PSUBSB_H_ */ diff --git a/libc/intrin/psubsw.c b/libc/intrin/psubsw.c deleted file mode 100644 index 119c07026..000000000 --- a/libc/intrin/psubsw.c +++ /dev/null @@ -1,37 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/psubsw.h" -#include "libc/limits.h" -#include "libc/macros.internal.h" -#include "libc/str/str.h" - -/** - * Subtracts signed 16-bit integers w/ saturation. - * - * @param 𝑎 [w/o] receives result - * @param 𝑏 [r/o] supplies first input vector - * @param 𝑐 [r/o] supplies second input vector - * @mayalias - */ -void(psubsw)(int16_t a[8], const int16_t b[8], const int16_t c[8]) { - unsigned i; - int16_t r[8]; - for (i = 0; i < 8; ++i) r[i] = MIN(INT16_MAX, MAX(INT16_MIN, b[i] - c[i])); - __builtin_memcpy(a, r, 16); -} diff --git a/libc/intrin/psubsw.h b/libc/intrin/psubsw.h deleted file mode 100644 index a6994ac37..000000000 --- a/libc/intrin/psubsw.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PSUBSW_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PSUBSW_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void psubsw(int16_t[8], const int16_t[8], const int16_t[8]); - -#define psubsw(A, B, C) \ - INTRIN_SSEVEX_X_X_X_(psubsw, SSE2, "psubsw", INTRIN_NONCOMMUTATIVE, A, B, C) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PSUBSW_H_ */ diff --git a/libc/intrin/psubusb.c b/libc/intrin/psubusb.c deleted file mode 100644 index 817f75c5b..000000000 --- a/libc/intrin/psubusb.c +++ /dev/null @@ -1,39 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/psubusb.h" -#include "libc/limits.h" -#include "libc/macros.internal.h" -#include "libc/str/str.h" - -/** - * Subtracts unsigned 8-bit integers w/ saturation. - * - * @param 𝑎 [w/o] receives result - * @param 𝑏 [r/o] supplies first input vector - * @param 𝑐 [r/o] supplies second input vector - * @mayalias - */ -void(psubusb)(uint8_t a[16], const uint8_t b[16], const uint8_t c[16]) { - unsigned i; - uint8_t r[16]; - for (i = 0; i < 16; ++i) { - r[i] = MIN(UINT8_MAX, MAX(UINT8_MIN, b[i] - c[i])); - } - __builtin_memcpy(a, r, 16); -} diff --git a/libc/intrin/psubusb.h b/libc/intrin/psubusb.h deleted file mode 100644 index b93050cd3..000000000 --- a/libc/intrin/psubusb.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PSUBUSB_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PSUBUSB_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void psubusb(uint8_t[16], const uint8_t[16], const uint8_t[16]); - -#define psubusb(A, B, C) \ - INTRIN_SSEVEX_X_X_X_(psubusb, SSE2, "psubusb", INTRIN_NONCOMMUTATIVE, A, B, C) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PSUBUSB_H_ */ diff --git a/libc/intrin/psubusw.c b/libc/intrin/psubusw.c deleted file mode 100644 index ebe25a3df..000000000 --- a/libc/intrin/psubusw.c +++ /dev/null @@ -1,39 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/psubusw.h" -#include "libc/limits.h" -#include "libc/macros.internal.h" -#include "libc/str/str.h" - -/** - * Subtracts unsigned 16-bit integers w/ saturation. - * - * @param 𝑎 [w/o] receives result - * @param 𝑏 [r/o] supplies first input vector - * @param 𝑐 [r/o] supplies second input vector - * @mayalias - */ -void(psubusw)(uint16_t a[8], const uint16_t b[8], const uint16_t c[8]) { - unsigned i; - uint16_t r[8]; - for (i = 0; i < 8; ++i) { - r[i] = MIN(UINT16_MAX, MAX(UINT16_MIN, b[i] - c[i])); - } - __builtin_memcpy(a, r, 16); -} diff --git a/libc/intrin/psubusw.h b/libc/intrin/psubusw.h deleted file mode 100644 index 2a96ba9ed..000000000 --- a/libc/intrin/psubusw.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PSUBUSW_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PSUBUSW_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void psubusw(uint16_t[8], const uint16_t[8], const uint16_t[8]); - -#define psubusw(A, B, C) \ - INTRIN_SSEVEX_X_X_X_(psubusw, SSE2, "psubusw", INTRIN_NONCOMMUTATIVE, A, B, C) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PSUBUSW_H_ */ diff --git a/libc/intrin/psubw.c b/libc/intrin/psubw.c deleted file mode 100644 index bdb0edb0c..000000000 --- a/libc/intrin/psubw.c +++ /dev/null @@ -1,37 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/psubw.h" -#include "libc/str/str.h" - -/** - * Subtracts 16-bit integers. - * - * @param 𝑎 [w/o] receives result - * @param 𝑏 [r/o] supplies first input vector - * @param 𝑐 [r/o] supplies second input vector - * @mayalias - */ -void(psubw)(int16_t a[8], const int16_t b[8], const int16_t c[8]) { - unsigned i; - int16_t r[8]; - for (i = 0; i < 8; ++i) { - r[i] = b[i] - c[i]; - } - __builtin_memcpy(a, r, 16); -} diff --git a/libc/intrin/psubw.h b/libc/intrin/psubw.h deleted file mode 100644 index 09043ea56..000000000 --- a/libc/intrin/psubw.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PSUBW_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PSUBW_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void psubw(int16_t[8], const int16_t[8], const int16_t[8]); - -#define psubw(A, B, C) \ - INTRIN_SSEVEX_X_X_X_(psubw, SSE2, "psubw", INTRIN_NONCOMMUTATIVE, A, B, C) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PSUBW_H_ */ diff --git a/libc/intrin/punpckhdq.c b/libc/intrin/punpckhdq.c deleted file mode 100644 index 2a5f1cd72..000000000 --- a/libc/intrin/punpckhdq.c +++ /dev/null @@ -1,42 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/punpckhdq.h" - -/** - * Interleaves high doublewords. - * - * 0 1 2 3 - * B aaaa bbbb CCCC DDDD - * C eeee ffff GGGG HHHH - * └┬─┘ └─┬┘ - * ┌────┘ │ - * ┌─────┴─┐ ┌──────┴┐ - * → A CCCC GGGG DDDD HHHH - * - * @param 𝑎 [w/o] receives reduced 𝑏 and 𝑐 interleaved - * @param 𝑏 [r/o] supplies four doublewords - * @param 𝑐 [r/o] supplies four doublewords - * @mayalias - */ -void(punpckhdq)(uint32_t a[4], const uint32_t b[4], const uint32_t c[4]) { - a[0] = b[2]; - a[1] = c[2]; - a[2] = b[3]; - a[3] = c[3]; -} diff --git a/libc/intrin/punpckhdq.h b/libc/intrin/punpckhdq.h deleted file mode 100644 index b25165852..000000000 --- a/libc/intrin/punpckhdq.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PUNPCKHDQ_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PUNPCKHDQ_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void punpckhdq(uint32_t[4], const uint32_t[4], const uint32_t[4]); - -#define punpckhdq(A, B, C) \ - INTRIN_SSEVEX_X_X_X_(punpckhdq, SSE2, "punpckhdq", INTRIN_NONCOMMUTATIVE, A, \ - B, C) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PUNPCKHDQ_H_ */ diff --git a/libc/intrin/punpckhqdq.c b/libc/intrin/punpckhqdq.c deleted file mode 100644 index ce3c5164c..000000000 --- a/libc/intrin/punpckhqdq.c +++ /dev/null @@ -1,32 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/punpckhqdq.h" - -/** - * Interleaves high quadwords. - * - * @param 𝑎 [w/o] receives reduced 𝑏 and 𝑐 interleaved - * @param 𝑏 [r/o] supplies two quadwords - * @param 𝑐 [r/o] supplies two quadwords - * @mayalias - */ -void(punpckhqdq)(uint64_t a[2], const uint64_t b[2], const uint64_t c[2]) { - a[0] = b[1]; - a[1] = c[1]; -} diff --git a/libc/intrin/punpckhqdq.h b/libc/intrin/punpckhqdq.h deleted file mode 100644 index ced06c5f7..000000000 --- a/libc/intrin/punpckhqdq.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PUNPCKHQDQ_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PUNPCKHQDQ_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void punpckhqdq(uint64_t[2], const uint64_t[2], const uint64_t[2]); - -#define punpckhqdq(A, B, C) \ - INTRIN_SSEVEX_X_X_X_(punpckhqdq, SSE2, "punpckhqdq", INTRIN_NONCOMMUTATIVE, \ - A, B, C) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PUNPCKHQDQ_H_ */ diff --git a/libc/intrin/punpckldq.c b/libc/intrin/punpckldq.c deleted file mode 100644 index 6640c227d..000000000 --- a/libc/intrin/punpckldq.c +++ /dev/null @@ -1,42 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/punpckldq.h" - -/** - * Interleaves low doublewords. - * - * 0 1 2 3 - * B AAAA BBBB cccc dddd - * C EEEE FFFF gggg hhhh - * └┬─┘ └─┬┘ - * │ └───┐ - * ┌┴──────┐ ┌┴──────┐ - * → A AAAA EEEE BBBB FFFF - * - * @param 𝑎 [w/o] receives reduced 𝑏 and 𝑐 interleaved - * @param 𝑏 [r/o] supplies four doublewords - * @param 𝑐 [r/o] supplies four doublewords - * @mayalias - */ -void(punpckldq)(uint32_t a[4], const uint32_t b[4], const uint32_t c[4]) { - a[3] = c[1]; - a[2] = b[1]; - a[1] = c[0]; - a[0] = b[0]; -} diff --git a/libc/intrin/punpckldq.h b/libc/intrin/punpckldq.h deleted file mode 100644 index b52d61322..000000000 --- a/libc/intrin/punpckldq.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PUNPCKLDQ_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PUNPCKLDQ_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void punpckldq(uint32_t[4], const uint32_t[4], const uint32_t[4]); - -#define punpckldq(A, B, C) \ - INTRIN_SSEVEX_X_X_X_(punpckldq, SSE2, "punpckldq", INTRIN_NONCOMMUTATIVE, A, \ - B, C) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PUNPCKLDQ_H_ */ diff --git a/libc/intrin/punpcklqdq.c b/libc/intrin/punpcklqdq.c deleted file mode 100644 index 549130eab..000000000 --- a/libc/intrin/punpcklqdq.c +++ /dev/null @@ -1,32 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/punpcklqdq.h" - -/** - * Interleaves low quadwords. - * - * @param 𝑎 [w/o] receives reduced 𝑏 and 𝑐 interleaved - * @param 𝑏 [r/o] supplies two quadwords - * @param 𝑐 [r/o] supplies two quadwords - * @mayalias - */ -void(punpcklqdq)(uint64_t a[2], const uint64_t b[2], const uint64_t c[2]) { - a[1] = c[0]; - a[0] = b[0]; -} diff --git a/libc/intrin/punpcklqdq.h b/libc/intrin/punpcklqdq.h deleted file mode 100644 index fc0f88f90..000000000 --- a/libc/intrin/punpcklqdq.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PUNPCKLQDQ_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PUNPCKLQDQ_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void punpcklqdq(uint64_t[2], const uint64_t[2], const uint64_t[2]); - -#define punpcklqdq(A, B, C) \ - INTRIN_SSEVEX_X_X_X_(punpcklqdq, SSE2, "punpcklqdq", INTRIN_NONCOMMUTATIVE, \ - A, B, C) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PUNPCKLQDQ_H_ */ diff --git a/libc/intrin/pxor.c b/libc/intrin/pxor.c deleted file mode 100644 index 3b797e433..000000000 --- a/libc/intrin/pxor.c +++ /dev/null @@ -1,34 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/pxor.h" - -/** - * Xors 128-bit integers. - * - * @param 𝑎 [w/o] receives result - * @param 𝑏 [r/o] supplies first input vector - * @param 𝑐 [r/o] supplies second input vector - * @mayalias - */ -void(pxor)(uint64_t a[2], const uint64_t b[2], const uint64_t c[2]) { - unsigned i; - for (i = 0; i < 2; ++i) { - a[i] = b[i] ^ c[i]; - } -} diff --git a/libc/intrin/pxor.h b/libc/intrin/pxor.h deleted file mode 100644 index aee0120cd..000000000 --- a/libc/intrin/pxor.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_PXOR_H_ -#define COSMOPOLITAN_LIBC_INTRIN_PXOR_H_ -#include "libc/intrin/macros.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void pxor(uint64_t[2], const uint64_t[2], const uint64_t[2]); - -#define pxor(A, B, C) \ - INTRIN_SSEVEX_X_X_X_(pxor, SSE2, "pxor", INTRIN_COMMUTATIVE, A, B, C) - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_PXOR_H_ */ diff --git a/libc/intrin/shufpd.c b/libc/intrin/shufpd.c deleted file mode 100644 index d327c28ed..000000000 --- a/libc/intrin/shufpd.c +++ /dev/null @@ -1,32 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/shufpd.h" -#include "libc/str/str.h" - -/** - * Shuffles double vector. - * @param 𝑚 needs to be a literal, constexpr, or embedding - * @mayalias - */ -void(shufpd)(double c[2], const double b[2], const double a[2], uint8_t m) { - double t[2]; - t[0] = b[(m & 0b0000001) >> 0]; - t[1] = a[(m & 0b0000010) >> 1]; - __builtin_memcpy(c, t, 16); -} diff --git a/libc/intrin/shufpd.h b/libc/intrin/shufpd.h deleted file mode 100644 index 140704c69..000000000 --- a/libc/intrin/shufpd.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_SHUFPD_H_ -#define COSMOPOLITAN_LIBC_INTRIN_SHUFPD_H_ -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void shufpd(double[2], const double[2], const double[2], uint8_t); - -#if !defined(__STRICT_ANSI__) && !defined(__chibicc__) -typedef double shufpd_t _Vector_size(16) forcealign(16) mayalias; -shufpd_t shufpdjt(shufpd_t, shufpd_t); -#define shufpd(C, B, A, I) \ - do { \ - if (__builtin_expect(X86_NEED(SSE) && X86_HAVE(SSSE3), 1)) { \ - shufpd_t *Xmm0 = (void *)(C); \ - const shufpd_t *Xmm1 = (const shufpd_t *)(B); \ - const shufpd_t *Xmm2 = (const shufpd_t *)(A); \ - if (__builtin_constant_p(I)) { \ - if (!X86_NEED(AVX)) { \ - asm("shufpd\t%2,%1,%0" \ - : "=x"(*Xmm0) \ - : "x"(*Xmm2), "i"(I), "0"(*Xmm1)); \ - } else { \ - asm("vshufpd\t%3,%2,%1,%0" \ - : "=x"(*Xmm0) \ - : "x"(*Xmm1), "x"(*Xmm2), "i"(I)); \ - } \ - } else { \ - uint8_t Vimm = (I); \ - typeof(shufpdjt) *Fn; \ - Fn = (typeof(shufpdjt) *)((uintptr_t)&shufpdjt + Vimm * 8); \ - *Xmm0 = Fn(*Xmm1, *Xmm2); \ - } \ - } else { \ - shufpd(C, B, A, I); \ - } \ - } while (0) -#endif - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_SHUFPD_H_ */ diff --git a/libc/intrin/shufpdjt.S b/libc/intrin/shufpdjt.S deleted file mode 100644 index 9cde9ef82..000000000 --- a/libc/intrin/shufpdjt.S +++ /dev/null @@ -1,30 +0,0 @@ -/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│ -│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2023 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/macros.internal.h" - - .balign 8 -shufpdjt: - i=0 - .rept 256 - shufpd $i,%xmm1,%xmm0 - ret - .balign 8 - i=i+1 - .endr - .endfn shufpdjt,globl diff --git a/libc/intrin/shufps.c b/libc/intrin/shufps.c deleted file mode 100644 index a4a9ee3d2..000000000 --- a/libc/intrin/shufps.c +++ /dev/null @@ -1,34 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/shufps.h" -#include "libc/str/str.h" - -/** - * Shuffles float vector. - * @param 𝑚 needs to be a literal, constexpr, or embedding - * @mayalias - */ -void(shufps)(float c[4], const float b[4], const float a[4], uint8_t m) { - float t[4]; - t[0] = b[(m & 0b00000011) >> 0]; - t[1] = b[(m & 0b00001100) >> 2]; - t[2] = a[(m & 0b00110000) >> 4]; - t[3] = a[(m & 0b11000000) >> 6]; - __builtin_memcpy(c, t, 16); -} diff --git a/libc/intrin/shufps.h b/libc/intrin/shufps.h deleted file mode 100644 index ef8b576cf..000000000 --- a/libc/intrin/shufps.h +++ /dev/null @@ -1,41 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_INTRIN_SHUFPS_H_ -#define COSMOPOLITAN_LIBC_INTRIN_SHUFPS_H_ -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -void shufps(float[4], const float[4], const float[4], uint8_t); - -#if !defined(__STRICT_ANSI__) && !defined(__chibicc__) -typedef float shufps_t _Vector_size(16) forcealign(16) mayalias; -shufps_t shufpsjt(shufps_t, shufps_t); -#define shufps(C, B, A, I) \ - do { \ - if (__builtin_expect(X86_NEED(SSE) && X86_HAVE(SSSE3), 1)) { \ - shufps_t *Xmm0 = (void *)(C); \ - const shufps_t *Xmm1 = (const shufps_t *)(B); \ - const shufps_t *Xmm2 = (const shufps_t *)(A); \ - if (__builtin_constant_p(I)) { \ - if (!X86_NEED(AVX)) { \ - asm("shufps\t%2,%1,%0" \ - : "=x"(*Xmm0) \ - : "x"(*Xmm2), "i"(I), "0"(*Xmm1)); \ - } else { \ - asm("vshufps\t%3,%2,%1,%0" \ - : "=x"(*Xmm0) \ - : "x"(*Xmm1), "x"(*Xmm2), "i"(I)); \ - } \ - } else { \ - uint8_t Vimm = (I); \ - typeof(shufpsjt) *Fn; \ - Fn = (typeof(shufpsjt) *)((uintptr_t)&shufpsjt + Vimm * 8); \ - *Xmm0 = Fn(*Xmm1, *Xmm2); \ - } \ - } else { \ - shufps(C, B, A, I); \ - } \ - } while (0) -#endif - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_INTRIN_SHUFPS_H_ */ diff --git a/libc/intrin/shufpsjt.S b/libc/intrin/shufpsjt.S deleted file mode 100644 index 1b074437f..000000000 --- a/libc/intrin/shufpsjt.S +++ /dev/null @@ -1,30 +0,0 @@ -/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│ -│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2023 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/macros.internal.h" - - .balign 8 -shufpsjt: - i=0 - .rept 256 - shufps $i,%xmm1,%xmm0 - ret - .balign 8 - i=i+1 - .endr - .endfn shufpsjt,globl diff --git a/libc/isystem/cosmo.h b/libc/isystem/cosmo.h index 18db08f76..b136fc1b5 100644 --- a/libc/isystem/cosmo.h +++ b/libc/isystem/cosmo.h @@ -35,6 +35,7 @@ #include "libc/fmt/leb128.h" #include "libc/intrin/bsf.h" #include "libc/intrin/bsr.h" +#include "libc/intrin/dll.h" #include "libc/intrin/kprintf.h" #include "libc/intrin/likely.h" #include "libc/intrin/tpenc.h" diff --git a/libc/log/showcrashreports.c b/libc/log/showcrashreports.c index 44965d08a..d17a2ce6d 100644 --- a/libc/log/showcrashreports.c +++ b/libc/log/showcrashreports.c @@ -159,6 +159,4 @@ void ShowCrashReports(void) { InstallCrashHandler(SIGBUS, __got_sigbus, ef); // misalign, mmap i/o failed InstallCrashHandler(SIGURG, __got_sigurg, ef); // placeholder GetSymbolTable(); - void __wipe(uintptr_t); - return __wipe(0); } diff --git a/libc/mem/balloc.c b/libc/mem/balloc.c deleted file mode 100644 index 9017963fb..000000000 --- a/libc/mem/balloc.c +++ /dev/null @@ -1,37 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/mem/mem.h" -#include "libc/runtime/buffer.internal.h" - -/* TODO(jart): delete */ - -/** - * Allocates page-guarded buffer. - * - * @param b is metadata object owned by caller, initialized to zero for - * first call; subsequent calls will resize - * @param a is alignment requirement in bytes, e.g. 1,2,4,8,16,... - * @param n is buffer size in bytes - * @return b->p - * @see ralloc() - * @deprecated - */ -void *balloc(struct GuardedBuffer *b, unsigned a, size_t n) { - return (b->p = memalign(a, n)); -} diff --git a/libc/mem/bfree.c b/libc/mem/bfree.c deleted file mode 100644 index e16a7e950..000000000 --- a/libc/mem/bfree.c +++ /dev/null @@ -1,30 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/assert.h" -#include "libc/calls/calls.h" -#include "libc/mem/mem.h" -#include "libc/runtime/buffer.internal.h" - -/** - * Frees memory return by balloc(). - * @deprecated - */ -void bfree(struct GuardedBuffer *b) { - free(b->p); -} diff --git a/libc/nexgen32e/kreversebits.S b/libc/nexgen32e/kreversebits.S deleted file mode 100644 index 41e85fc3e..000000000 --- a/libc/nexgen32e/kreversebits.S +++ /dev/null @@ -1,88 +0,0 @@ -/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│ -│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/macros.internal.h" - - .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 diff --git a/libc/runtime/__stack_chk_fail.c b/libc/runtime/__stack_chk_fail.c deleted file mode 100644 index 3bdd04a7a..000000000 --- a/libc/runtime/__stack_chk_fail.c +++ /dev/null @@ -1,19 +0,0 @@ -/*-*- 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 2023 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/runtime/runtime.h" diff --git a/libc/runtime/buffer.internal.h b/libc/runtime/buffer.internal.h deleted file mode 100644 index 929d2050a..000000000 --- a/libc/runtime/buffer.internal.h +++ /dev/null @@ -1,15 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_RUNTIME_BUFFER_INTERNAL_H_ -#define COSMOPOLITAN_LIBC_RUNTIME_BUFFER_INTERNAL_H_ -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -struct GuardedBuffer { - void *p; -}; - -void *balloc(struct GuardedBuffer *, unsigned, size_t); -void bfree(struct GuardedBuffer *); - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_RUNTIME_BUFFER_INTERNAL_H_ */ diff --git a/libc/runtime/clone.c b/libc/runtime/clone.c index c699051ce..f5305f192 100644 --- a/libc/runtime/clone.c +++ b/libc/runtime/clone.c @@ -34,7 +34,6 @@ #include "libc/nt/synchronization.h" #include "libc/nt/thread.h" #include "libc/nt/thunk/msabi.h" -#include "libc/runtime/clone.internal.h" #include "libc/runtime/internal.h" #include "libc/runtime/runtime.h" #include "libc/runtime/syslib.internal.h" diff --git a/libc/runtime/clone.internal.h b/libc/runtime/clone.internal.h deleted file mode 100644 index 89f4b826a..000000000 --- a/libc/runtime/clone.internal.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_RUNTIME_CLONE_INTERNAL_H_ -#define COSMOPOLITAN_LIBC_RUNTIME_CLONE_INTERNAL_H_ -#include "libc/atomic.h" -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -int clone(void *, void *, size_t, int, void *, void *, void *, void *); - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_RUNTIME_CLONE_INTERNAL_H_ */ diff --git a/libc/runtime/cocmd.c b/libc/runtime/cocmd.c index abd9e2219..40398a416 100644 --- a/libc/runtime/cocmd.c +++ b/libc/runtime/cocmd.c @@ -72,7 +72,6 @@ static int exitstatus; static char *envs[500]; static char *args[3000]; static const char *prog; -static char errbuf[512]; static char argbuf[ARG_MAX]; static bool unsupported[256]; @@ -80,35 +79,12 @@ static ssize_t Write(int fd, const char *s) { return write(fd, s, strlen(s)); } -static void Log(const char *s, ...) { - va_list va; - va_start(va, s); - errbuf[0] = 0; - do { - strlcat(errbuf, s, sizeof(errbuf)); - } while ((s = va_arg(va, const char *))); - strlcat(errbuf, "\n", sizeof(errbuf)); - Write(2, errbuf); - va_end(va); -} - -static wontreturn void Wexit(int rc, const char *s, ...) { - va_list va; - va_start(va, s); - errbuf[0] = 0; - do { - strlcat(errbuf, s, sizeof(errbuf)); - } while ((s = va_arg(va, const char *))); - Write(2, errbuf); - va_end(va); - _Exit(rc); -} - static wontreturn void UnsupportedSyntax(unsigned char c) { char ibuf[13], cbuf[2] = {c}; FormatOctal32(ibuf, c, true); - Wexit(4, prog, ": unsupported syntax '", cbuf, "' (", ibuf, "): ", cmd, "\n", - 0); + tinyprint(2, prog, ": unsupported syntax '", cbuf, "' (", ibuf, "): ", cmd, + "\n", 0); + _Exit(4); } static wontreturn void SysExit(int rc, const char *call, const char *thing) { @@ -119,7 +95,8 @@ static wontreturn void SysExit(int rc, const char *call, const char *thing) { FormatInt32(ibuf, err); estr = _strerdoc(err); if (!estr) estr = "EUNKNOWN"; - Wexit(rc, thing, ": ", call, "() failed: ", estr, " (", ibuf, ")\n", 0); + tinyprint(2, thing, ": ", call, "() failed: ", estr, " (", ibuf, ")\n", 0); + _Exit(rc); } static void Open(const char *path, int fd, int flags) { @@ -132,7 +109,10 @@ static void Open(const char *path, int fd, int flags) { static wontreturn void Exec(void) { _unassert(args[0][0]); - if (!n) Wexit(5, prog, ": error: too few args\n", 0); + if (!n) { + tinyprint(2, prog, ": error: too few args\n", 0); + _Exit(5); + } execvpe(args[0], args, envs); SysExit(127, "execve", args[0]); } @@ -255,11 +235,11 @@ static int Cd(void) { if (!chdir(s)) { return 0; } else { - Log("chdir: ", s, ": ", _strerdoc(errno), NULL); + tinyprint(2, "chdir: ", s, ": ", _strerdoc(errno), NULL); return 1; } } else { - Log("chdir: missing argument", NULL); + tinyprint(2, "chdir: missing argument", NULL); return 1; } } @@ -270,7 +250,7 @@ static int Mkdir(void) { if (n >= 3 && !strcmp(args[1], "-p")) ++i, f = makedirs; for (; i < n; ++i) { if (f(args[i], 0755)) { - Log("mkdir: ", args[i], ": ", _strerdoc(errno), NULL); + tinyprint(2, "mkdir: ", args[i], ": ", _strerdoc(errno), NULL); return errno; } } @@ -287,7 +267,7 @@ static int Kill(void) { } for (; i < n; ++i) { if (kill(atoi(args[i]), sig)) { - Log("kill: ", args[i], ": ", _strerdoc(errno), NULL); + tinyprint(2, "kill: ", args[i], ": ", _strerdoc(errno), NULL); rc = 1; } } @@ -345,7 +325,7 @@ static int Rm(void) { if (n > 1 && args[1][0] != '-') { for (i = 1; i < n; ++i) { if (unlink(args[i])) { - Log("rm: ", args[i], ": ", _strerdoc(errno), NULL); + tinyprint(2, "rm: ", args[i], ": ", _strerdoc(errno), NULL); return 1; } } @@ -360,7 +340,7 @@ static int Rmdir(void) { if (n > 1 && args[1][0] != '-') { for (i = 1; i < n; ++i) { if (rmdir(args[i])) { - Log("rmdir: ", args[i], ": ", _strerdoc(errno), NULL); + tinyprint(2, "rmdir: ", args[i], ": ", _strerdoc(errno), NULL); return 1; } } @@ -375,7 +355,7 @@ static int Touch(void) { if (n > 1 && args[1][0] != '-') { for (i = 1; i < n; ++i) { if (touch(args[i], 0644)) { - Log("touch: ", args[i], ": ", _strerdoc(errno), NULL); + tinyprint(2, "touch: ", args[i], ": ", _strerdoc(errno), NULL); return 1; } } @@ -614,7 +594,8 @@ static char *Tokenize(void) { break; UnterminatedString: - Wexit(6, "cmd: error: unterminated string\n", 0); + tinyprint(2, "cmd: error: unterminated string\n", 0); + _Exit(6); case STATE_QUOTED_VAR: if (!*p) goto UnterminatedString; @@ -661,7 +642,8 @@ static const char *GetRedirectArg(const char *prog, const char *arg, int n) { } else if ((arg = Tokenize())) { return arg; } else { - Wexit(14, prog, ": error: redirect missing path\n", 0); + tinyprint(2, prog, ": error: redirect missing path\n", 0); + _Exit(14); } } @@ -693,16 +675,19 @@ int _cocmd(int argc, char **argv, char **envp) { } if (argc != 3) { - Wexit(10, prog, ": error: wrong number of args\n", 0); + tinyprint(2, prog, ": error: wrong number of args\n", 0); + _Exit(10); } if (strcmp(argv[1], "-c")) { - Wexit(11, prog, ": error: argv[1] should -c\n", 0); + tinyprint(2, prog, ": error: argv[1] should -c\n", 0); + _Exit(11); } p = cmd = argv[2]; if (strlen(cmd) >= ARG_MAX) { - Wexit(12, prog, ": error: cmd too long: ", cmd, "\n", 0); + tinyprint(2, prog, ": error: cmd too long: ", cmd, "\n", 0); + _Exit(12); } // copy environment variables @@ -747,7 +732,8 @@ int _cocmd(int argc, char **argv, char **envp) { args[n++] = globTheBuilder.gl_pathv[globCount]; } } else if (globrc != GLOB_NOMATCH) { - Wexit(16, prog, ": error: with glob\n", 0); + tinyprint(2, prog, ": error: with glob\n", 0); + _Exit(16); } globFlags |= GLOB_APPEND; } @@ -757,7 +743,8 @@ int _cocmd(int argc, char **argv, char **envp) { args[n] = 0; } } else { - Wexit(13, prog, ": error: too many args\n", 0); + tinyprint(2, prog, ": error: too many args\n", 0); + _Exit(13); } } diff --git a/libc/runtime/cosmo2.c b/libc/runtime/cosmo2.c index c5353ce99..e6585faa5 100644 --- a/libc/runtime/cosmo2.c +++ b/libc/runtime/cosmo2.c @@ -38,7 +38,6 @@ * @fileoverview Cosmopolitan C Runtime, Second Edition */ -void __wipe(uintptr_t) _Hide; int main(int, char **, char **) __attribute__((__weak__)); typedef int init_f(int argc, char **argv, char **envp, unsigned long *auxv); @@ -169,7 +168,6 @@ textstartup void cosmo(long *sp, struct Syslib *m1) { #endif // run program - if (!IsTiny()) __wipe(0); exit(main(argc, argv, envp)); } diff --git a/libc/runtime/enable_tls.c b/libc/runtime/enable_tls.c index 1569f1bc6..743704399 100644 --- a/libc/runtime/enable_tls.c +++ b/libc/runtime/enable_tls.c @@ -24,6 +24,7 @@ #include "libc/intrin/asan.internal.h" #include "libc/intrin/asancodes.h" #include "libc/intrin/atomic.h" +#include "libc/intrin/dll.h" #include "libc/intrin/weaken.h" #include "libc/macros.internal.h" #include "libc/runtime/internal.h" @@ -38,7 +39,7 @@ extern unsigned char __tls_mov_nt_rax[]; extern unsigned char __tls_add_nt_rax[]; -nsync_dll_list_ _pthread_list; +struct Dll *_pthread_list; pthread_spinlock_t _pthread_lock; static struct PosixThread _pthread_main; _Alignas(TLS_ALIGNMENT) static char __static_tls[6016]; @@ -205,7 +206,6 @@ textstartup void __enable_tls(void) { _pthread_main.flags = PT_STATIC; _pthread_main.list.prev = _pthread_main.list.next = // _pthread_list = VEIL("r", &_pthread_main.list); - _pthread_main.list.container = &_pthread_main; atomic_store_explicit(&_pthread_main.ptid, tid, memory_order_relaxed); // copy in initialized data section diff --git a/libc/runtime/ezmap.c b/libc/runtime/ezmap.c deleted file mode 100644 index 66a1f5228..000000000 --- a/libc/runtime/ezmap.c +++ /dev/null @@ -1,58 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/calls.h" -#include "libc/intrin/safemacros.internal.h" -#include "libc/limits.h" -#include "libc/log/libfatal.internal.h" -#include "libc/runtime/ezmap.internal.h" -#include "libc/runtime/runtime.h" -#include "libc/sysv/consts/map.h" -#include "libc/sysv/consts/o.h" -#include "libc/sysv/consts/prot.h" - -// TODO(jart): DELETE - -_Hide int MapFileRead(const char *filename, struct MappedFile *mf) { - mf->addr = MAP_FAILED; - if ((mf->fd = open(filename, O_RDONLY)) != -1 && - (mf->size = lseek(mf->fd, 0, SEEK_END)) < INT_MAX && - (mf->addr = mf->size ? mmap(NULL, mf->size, PROT_READ, - MAP_PRIVATE | MAP_POPULATE, mf->fd, 0) - : NULL) != MAP_FAILED) { - return 0; - } else { - UnmapFile(mf); - return -1; - } -} - -_Hide int UnmapFile(struct MappedFile *mf) { - int rc; - rc = 0; - if (mf->addr && mf->addr != MAP_FAILED) { - rc |= munmap(mf->addr, mf->size); - mf->addr = MAP_FAILED; - } - if (mf->fd != -1) { - rc |= close(mf->fd); - mf->fd = -1; - } - mf->size = 0; - return rc; -} diff --git a/libc/runtime/ezmap.internal.h b/libc/runtime/ezmap.internal.h deleted file mode 100644 index 6d4745c52..000000000 --- a/libc/runtime/ezmap.internal.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef COSMOPOLITAN_LIBC_RUNTIME_EZMAP_INTERNAL_H_ -#define COSMOPOLITAN_LIBC_RUNTIME_EZMAP_INTERNAL_H_ -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -struct MappedFile { - int fd; - void *addr; - size_t size; -}; - -int MapFileRead(const char *, struct MappedFile *) _Hide; -int UnmapFile(struct MappedFile *) _Hide; - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* COSMOPOLITAN_LIBC_RUNTIME_EZMAP_INTERNAL_H_ */ diff --git a/libc/runtime/internal.h b/libc/runtime/internal.h index 1d80792a0..c7873ce63 100644 --- a/libc/runtime/internal.h +++ b/libc/runtime/internal.h @@ -3,7 +3,6 @@ #ifndef __STRICT_ANSI__ #include "libc/dce.h" #include "libc/elf/struct/ehdr.h" -#include "libc/runtime/ezmap.internal.h" #include "libc/runtime/runtime.h" #define STACK_CEIL 0x700000000000ul @@ -40,7 +39,6 @@ void __asan_init(int, char **, char **, intptr_t *) _Hide; void _jmpstack(void *, void *, ...) _Hide wontreturn; long _setstack(void *, void *, ...) _Hide; int GetDosArgv(const char16_t *, char *, size_t, char **, size_t); -Elf64_Ehdr *MapElfRead(const char *, struct MappedFile *) _Hide; int GetDosEnviron(const char16_t *, char *, size_t, char **, size_t); bool __intercept_flag(int *, char *[], const char *); int sys_mprotect_nt(void *, size_t, int) _Hide; diff --git a/libc/runtime/mapelfread.c b/libc/runtime/mapelfread.c deleted file mode 100644 index 6c2eb7557..000000000 --- a/libc/runtime/mapelfread.c +++ /dev/null @@ -1,31 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/elf/def.h" -#include "libc/elf/elf.h" -#include "libc/runtime/ezmap.internal.h" -#include "libc/runtime/internal.h" - -_Hide Elf64_Ehdr *MapElfRead(const char *filename, struct MappedFile *mf) { - if (MapFileRead(filename, mf) != -1 && IsElf64Binary(mf->addr, mf->size)) { - return mf->addr; - } else { - UnmapFile(mf); - return NULL; - } -} diff --git a/libc/runtime/peekall.S b/libc/runtime/peekall.S deleted file mode 100644 index 8e1a56c2e..000000000 --- a/libc/runtime/peekall.S +++ /dev/null @@ -1,45 +0,0 @@ -/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│ -│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "ape/relocations.h" -#include "libc/macros.internal.h" - -// Loads all pages from program image into memory. -_peekall: - .leafprologue - ezlea __executable_start,si - ezlea _etext,cx - add $0x1000,%rsi -0: xor (%rsi),%eax - add $PAGESIZE,%rsi - cmp %rcx,%rsi - jb 0b - ezlea _etext,si - ezlea _end,cx - add $0x1000,%rsi -0: incq (%rsi) - decq (%rsi) - add $PAGESIZE,%rsi - cmp %rcx,%rsi - jb 0b - .leafepilogue - .endfn _peekall,globl - - .weak __executable_start - .weak _etext - .weak _end diff --git a/libc/runtime/runtime.h b/libc/runtime/runtime.h index 6294960c8..46d1a68ae 100644 --- a/libc/runtime/runtime.h +++ b/libc/runtime/runtime.h @@ -122,7 +122,6 @@ void _weakfree(void *); void *_mapanon(size_t) attributeallocsize((1)) mallocesque; void *_mapshared(size_t) attributeallocsize((1)) mallocesque; void __oom_hook(size_t); -void _peekall(void); bool _isheap(void *); /* portability */ int NtGetVersion(void) pureconst; diff --git a/libc/runtime/setstack.S b/libc/runtime/setstack.S deleted file mode 100644 index fd2ae7a2f..000000000 --- a/libc/runtime/setstack.S +++ /dev/null @@ -1,45 +0,0 @@ -/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│ -│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/macros.internal.h" - -// Switches stack. -// -// @param rdi is new rsp, passed as malloc(size) + size -// @param rsi is function to call in new stack space -// @param rdx,rcx,r8,r9 get passed as args to rsi -// @return rax and happens on original stack -_setstack: - push %rbp - mov %rsp,%rbp - push %rbx - mov %rsp,%rbx - mov %rdi,%rsp - push 16(%rbx) - push 8(%rbx) - mov %rsi,%rax - mov %rdx,%rdi - mov %rcx,%rsi - mov %r8,%rdx - mov %r9,%rcx - call *%rax - mov %rbx,%rsp - pop %rbx - pop %rbp - ret - .endfn _setstack,globl,hidden diff --git a/libc/intrin/stackchkfail.c b/libc/runtime/stackchkfail.c similarity index 93% rename from libc/intrin/stackchkfail.c rename to libc/runtime/stackchkfail.c index 300c24830..75a9fad59 100644 --- a/libc/intrin/stackchkfail.c +++ b/libc/runtime/stackchkfail.c @@ -16,10 +16,11 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/kprintf.h" +#include "libc/calls/calls.h" +#include "libc/runtime/internal.h" #include "libc/runtime/runtime.h" __attribute__((__weak__)) void __stack_chk_fail(void) { - kprintf("%s: stack smashed\n", program_invocation_name); + tinyprint(2, program_invocation_name, ": stack smashed\n", NULL); __builtin_trap(); } diff --git a/libc/intrin/stackchkfaillocal.c b/libc/runtime/stackchkfaillocal.c similarity index 100% rename from libc/intrin/stackchkfaillocal.c rename to libc/runtime/stackchkfaillocal.c diff --git a/libc/runtime/wipe.S b/libc/runtime/wipe.S deleted file mode 100644 index 1ceae8414..000000000 --- a/libc/runtime/wipe.S +++ /dev/null @@ -1,84 +0,0 @@ -/*-*- mode:unix-assembly; indent-tabs-mode:t; tab-width:8; coding:utf-8 -*-│ -│vi: set et ft=asm ts=8 tw=8 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2023 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/nexgen32e/x86feature.h" -#include "libc/macros.internal.h" - -// Zeroes as many registers as possible. -// -// Each caller should declare an appropriate prototype. -// -// @param is return value -// @return is copied from parameter -__wipe: -#ifdef __x86_64__ - mov %rdi,%rax - xor %edi,%edi - xor %esi,%esi - xor %edx,%edx - xor %ecx,%ecx - xor %r8d,%r8d - xor %r9d,%r9d - xor %r10d,%r10d - xor %r11d,%r11d - testb X86_HAVE(AVX)+kCpuids(%rip) - jz .Lsse - vpxor %xmm0,%xmm0,%xmm0 - vpxor %xmm1,%xmm1,%xmm1 - vpxor %xmm2,%xmm2,%xmm2 - vpxor %xmm3,%xmm3,%xmm3 - vpxor %xmm4,%xmm4,%xmm4 - vpxor %xmm5,%xmm5,%xmm5 - vpxor %xmm6,%xmm6,%xmm6 - vpxor %xmm7,%xmm7,%xmm7 - ret -.Lsse: xorps %xmm0,%xmm0 - xorps %xmm1,%xmm1 - xorps %xmm2,%xmm2 - xorps %xmm3,%xmm3 - xorps %xmm4,%xmm4 - xorps %xmm5,%xmm5 - xorps %xmm6,%xmm6 - xorps %xmm7,%xmm7 - ret -#elif defined(__aarch64__) - mov x1,#0 - mov x2,#0 - mov x3,#0 - mov x4,#0 - mov x5,#0 - mov x6,#0 - mov x7,#0 - mov x9,#0 - mov x10,#0 - mov x11,#0 - mov x12,#0 - mov x13,#0 - mov x14,#0 - mov x15,#0 - movi v0.16b,#0 - movi v1.16b,#0 - movi v2.16b,#0 - movi v3.16b,#0 - movi v4.16b,#0 - movi v5.16b,#0 - movi v6.16b,#0 - movi v7.16b,#0 - ret -#endif - .endfn __wipe,globl,hidden diff --git a/libc/str/strnwidth.c b/libc/str/strnwidth.c index af0757892..ce855d176 100644 --- a/libc/str/strnwidth.c +++ b/libc/str/strnwidth.c @@ -19,7 +19,6 @@ #include "libc/intrin/bsf.h" #include "libc/intrin/pcmpgtb.h" #include "libc/intrin/pmovmskb.h" -#include "libc/intrin/psubb.h" #include "libc/macros.internal.h" #include "libc/str/str.h" #include "libc/str/thompike.h" diff --git a/libc/str/tprecode16to8.c b/libc/str/tprecode16to8.c index 6ab104c63..b48d53e98 100644 --- a/libc/str/tprecode16to8.c +++ b/libc/str/tprecode16to8.c @@ -31,15 +31,15 @@ static const int16_t kDel16[8] = {127, 127, 127, 127, 127, 127, 127, 127}; static noasan axdx_t tprecode16to8_sse2(char *dst, size_t dstsize, const char16_t *src, axdx_t r) { int16_t v1[8], v2[8], v3[8], vz[8]; - __builtin_memset(vz, 0, 16); + memset(vz, 0, 16); while (r.ax + 8 < dstsize) { - __builtin_memcpy(v1, src + r.dx, 16); + memcpy(v1, src + r.dx, 16); pcmpgtw(v2, v1, vz); pcmpgtw(v3, v1, kDel16); pandn((void *)v2, (void *)v3, (void *)v2); if (pmovmskb((void *)v2) != 0xFFFF) break; packsswb((void *)v1, v1, v1); - __builtin_memcpy(dst + r.ax, v1, 8); + memcpy(dst + r.ax, v1, 8); r.ax += 8; r.dx += 8; } diff --git a/libc/str/tprecode8to16.c b/libc/str/tprecode8to16.c index 4e4aacf74..a4f6bc9c1 100644 --- a/libc/str/tprecode8to16.c +++ b/libc/str/tprecode8to16.c @@ -28,15 +28,15 @@ static inline noasan axdx_t tprecode8to16_sse2(char16_t *dst, size_t dstsize, const char *src, axdx_t r) { uint8_t v1[16], v2[16], vz[16]; - __builtin_memset(vz, 0, 16); + memset(vz, 0, 16); while (r.ax + 16 < dstsize) { - __builtin_memcpy(v1, src + r.dx, 16); + memcpy(v1, src + r.dx, 16); pcmpgtb((int8_t *)v2, (int8_t *)v1, (int8_t *)vz); if (pmovmskb(v2) != 0xFFFF) break; punpcklbw(v2, v1, vz); punpckhbw(v1, v1, vz); - __builtin_memcpy(dst + r.ax + 0, v2, 16); - __builtin_memcpy(dst + r.ax + 8, v1, 16); + memcpy(dst + r.ax + 0, v2, 16); + memcpy(dst + r.ax + 8, v1, 16); r.ax += 16; r.dx += 16; } diff --git a/libc/thread/posixthread.internal.h b/libc/thread/posixthread.internal.h index 778a3648a..29ae16a8f 100644 --- a/libc/thread/posixthread.internal.h +++ b/libc/thread/posixthread.internal.h @@ -2,10 +2,10 @@ #define COSMOPOLITAN_LIBC_THREAD_POSIXTHREAD_INTERNAL_H_ #include "libc/calls/struct/sched_param.h" #include "libc/calls/struct/sigset.h" +#include "libc/intrin/dll.h" #include "libc/runtime/runtime.h" #include "libc/thread/thread.h" #include "libc/thread/tls.h" -#include "third_party/nsync/dll.h" #define PT_OWNSTACK 1 #define PT_STATIC 2 @@ -64,26 +64,28 @@ enum PosixThreadStatus { kPosixThreadZombie, }; +#define POSIXTHREAD_CONTAINER(e) DLL_CONTAINER(struct PosixThread, list, e) + struct PosixThread { int flags; // 0x00: see PT_* constants _Atomic(int) cancelled; // 0x04: thread has bad beliefs _Atomic(enum PosixThreadStatus) status; - _Atomic(int) ptid; // transitions 0 → tid - void *(*start)(void *); // creation callback - void *arg; // start's parameter - void *rc; // start's return value - char *altstack; // thread sigaltstack - char *tls; // bottom of tls allocation - struct CosmoTib *tib; // middle of tls allocation - nsync_dll_element_ list; // list of threads - jmp_buf exiter; // for pthread_exit + _Atomic(int) ptid; // transitions 0 → tid + void *(*start)(void *); // creation callback + void *arg; // start's parameter + void *rc; // start's return value + char *altstack; // thread sigaltstack + char *tls; // bottom of tls allocation + struct CosmoTib *tib; // middle of tls allocation + struct Dll list; // list of threads + jmp_buf exiter; // for pthread_exit pthread_attr_t attr; struct _pthread_cleanup_buffer *cleanup; }; typedef void (*atfork_f)(void); -extern nsync_dll_list_ _pthread_list; +extern struct Dll *_pthread_list; extern pthread_spinlock_t _pthread_lock; extern _Atomic(pthread_key_dtor) _pthread_key_dtor[PTHREAD_KEYS_MAX] _Hide; diff --git a/libc/thread/pthread_atfork.c b/libc/thread/pthread_atfork.c index 7b94ff7c2..fa8d0d1e8 100644 --- a/libc/thread/pthread_atfork.c +++ b/libc/thread/pthread_atfork.c @@ -20,6 +20,7 @@ #include "libc/calls/state.internal.h" #include "libc/errno.h" #include "libc/intrin/atomic.h" +#include "libc/intrin/dll.h" #include "libc/intrin/kmalloc.h" #include "libc/mem/mem.h" #include "libc/runtime/memtrack.internal.h" @@ -37,10 +38,10 @@ static struct AtForks { } _atforks; static void _pthread_purge(void) { - nsync_dll_element_ *e; - while ((e = nsync_dll_first_(_pthread_list))) { - _pthread_list = nsync_dll_remove_(_pthread_list, e); - _pthread_free(e->container); + struct Dll *e; + while ((e = dll_first(_pthread_list))) { + dll_remove(&_pthread_list, e); + _pthread_free(POSIXTHREAD_CONTAINER(e)); } } @@ -97,9 +98,9 @@ void _pthread_onfork_child(void) { // delete other threads that existed before forking // this must come after onfork, since it calls free - _pthread_list = nsync_dll_remove_(_pthread_list, &pt->list); + dll_remove(&_pthread_list, &pt->list); _pthread_purge(); - _pthread_list = nsync_dll_make_first_in_list_(_pthread_list, &pt->list); + dll_make_first(&_pthread_list, &pt->list); } int _pthread_atfork(atfork_f prepare, atfork_f parent, atfork_f child) { diff --git a/libc/thread/pthread_create.c b/libc/thread/pthread_create.c index c9ea50aa6..4c65ed264 100644 --- a/libc/thread/pthread_create.c +++ b/libc/thread/pthread_create.c @@ -26,10 +26,10 @@ #include "libc/intrin/asan.internal.h" #include "libc/intrin/atomic.h" #include "libc/intrin/bits.h" +#include "libc/intrin/dll.h" #include "libc/log/internal.h" #include "libc/macros.internal.h" #include "libc/mem/mem.h" -#include "libc/runtime/clone.internal.h" #include "libc/runtime/runtime.h" #include "libc/runtime/stack.h" #include "libc/str/str.h" @@ -43,7 +43,6 @@ #include "libc/thread/thread.h" #include "libc/thread/tls.h" #include "libc/thread/wait0.internal.h" -#include "third_party/nsync/dll.h" STATIC_YOINK("nsync_mu_lock"); STATIC_YOINK("nsync_mu_unlock"); @@ -246,9 +245,9 @@ static errno_t pthread_create_impl(pthread_t *thread, // add thread to global list // we add it to the end since zombies go at the beginning - nsync_dll_init_(&pt->list, pt); + dll_init(&pt->list); pthread_spin_lock(&_pthread_lock); - _pthread_list = nsync_dll_make_last_in_list_(_pthread_list, &pt->list); + dll_make_last(&_pthread_list, &pt->list); pthread_spin_unlock(&_pthread_lock); // launch PosixThread(pt) in new thread @@ -260,7 +259,7 @@ static errno_t pthread_create_impl(pthread_t *thread, CLONE_CHILD_CLEARTID, pt, &pt->ptid, __adj_tls(pt->tib), &pt->tib->tib_tid))) { pthread_spin_lock(&_pthread_lock); - _pthread_list = nsync_dll_remove_(_pthread_list, &pt->list); + dll_remove(&_pthread_list, &pt->list); pthread_spin_unlock(&_pthread_lock); _pthread_free(pt); return rc; diff --git a/libc/thread/pthread_decimate_np.c b/libc/thread/pthread_decimate_np.c index dcfa297d6..74fb77d12 100644 --- a/libc/thread/pthread_decimate_np.c +++ b/libc/thread/pthread_decimate_np.c @@ -17,29 +17,28 @@ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/intrin/atomic.h" +#include "libc/intrin/dll.h" #include "libc/runtime/runtime.h" #include "libc/thread/posixthread.internal.h" #include "libc/thread/thread.h" #include "libc/thread/tls.h" -#include "third_party/nsync/dll.h" /** * Releases memory of detached threads that have terminated. */ void pthread_decimate_np(void) { - nsync_dll_element_ *e; + struct Dll *e; struct PosixThread *pt; enum PosixThreadStatus status; StartOver: pthread_spin_lock(&_pthread_lock); - for (e = nsync_dll_first_(_pthread_list); e; - e = nsync_dll_next_(_pthread_list, e)) { - pt = (struct PosixThread *)e->container; + for (e = dll_first(_pthread_list); e; e = dll_next(_pthread_list, e)) { + pt = POSIXTHREAD_CONTAINER(e); if (pt->tib == __get_tls()) continue; status = atomic_load_explicit(&pt->status, memory_order_acquire); if (status != kPosixThreadZombie) break; if (!atomic_load_explicit(&pt->tib->tib_tid, memory_order_acquire)) { - _pthread_list = nsync_dll_remove_(_pthread_list, e); + dll_remove(&_pthread_list, e); pthread_spin_unlock(&_pthread_lock); _pthread_free(pt); goto StartOver; diff --git a/libc/thread/pthread_detach.c b/libc/thread/pthread_detach.c index f031d37d6..384d05d63 100644 --- a/libc/thread/pthread_detach.c +++ b/libc/thread/pthread_detach.c @@ -25,7 +25,6 @@ #include "libc/thread/posixthread.internal.h" #include "libc/thread/spawn.h" #include "libc/thread/thread.h" -#include "third_party/nsync/dll.h" /** * Asks POSIX thread to free itself automatically upon termination. diff --git a/libc/thread/pthread_exit.c b/libc/thread/pthread_exit.c index 6d99e80cb..aae41e711 100644 --- a/libc/thread/pthread_exit.c +++ b/libc/thread/pthread_exit.c @@ -29,7 +29,6 @@ #include "libc/thread/posixthread.internal.h" #include "libc/thread/thread.h" #include "libc/thread/tls.h" -#include "third_party/nsync/dll.h" #include "third_party/nsync/futex.internal.h" static void CleanupThread(struct PosixThread *pt) { diff --git a/libc/thread/pthread_print_np.c b/libc/thread/pthread_print_np.c deleted file mode 100644 index 27becd6f2..000000000 --- a/libc/thread/pthread_print_np.c +++ /dev/null @@ -1,91 +0,0 @@ -/*-*- 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 2022 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/blockcancel.internal.h" -#include "libc/calls/calls.h" -#include "libc/intrin/kprintf.h" -#include "libc/runtime/runtime.h" -#include "libc/str/str.h" -#include "libc/thread/posixthread.internal.h" -#include "libc/thread/thread.h" -#include "third_party/nsync/dll.h" - -#define N 2048 -#define M 15 - -#define append(f, ...) o += f(buf + o, N - o, __VA_ARGS__) - -static const char *DescribeStatus(enum PosixThreadStatus status) { - switch (status) { - case kPosixThreadJoinable: - return "JOINAB"; - case kPosixThreadDetached: - return "DETACH"; - case kPosixThreadTerminated: - return "TERMIN"; - case kPosixThreadZombie: - return "ZOMBIE"; - default: - __builtin_unreachable(); - } -} - -static const char *DescribeFlags(char buf[M], struct PosixThread *pt) { - char *p = buf; - if (pt->cancelled) *p++ = '*'; - if (pt->flags & PT_EXITING) *p++ = 'X'; - if (pt->flags & PT_STATIC) *p++ = 'S'; - if (pt->flags & PT_OWNSTACK) *p++ = 'O'; - if (pt->flags & PT_ASYNC) *p++ = 'A'; - if (pt->flags & PT_MASKED) *p++ = 'M'; - if (pt->flags & PT_OPENBSD_KLUDGE) *p++ = 'K'; - if (pt->flags & PT_INCANCEL) *p++ = '?'; - if (pt->flags & PT_NOCANCEL) *p++ = '!'; - *p = 0; - return buf; -} - -int pthread_print_np(int fd, const char *fmt, ...) { - va_list va; - int rc, o = 0; - nsync_dll_element_ *e; - struct PosixThread *pt; - char buf[N], flagbuf[M]; - pthread_spin_lock(&_pthread_lock); - if (fmt) { - va_start(va, fmt); - append(kvsnprintf, fmt, va); - va_end(va); - append(ksnprintf, "\n"); - } - append(ksnprintf, "%6s %6s %6s %6s %s\n", "ptid", "tid", "status", "flags", - "start"); - for (e = nsync_dll_first_(_pthread_list); e; - e = nsync_dll_next_(_pthread_list, e)) { - pt = (struct PosixThread *)e->container; - append(ksnprintf, "%-6d %-6d %6s %6s %t\n", pt->ptid, pt->tib->tib_tid, - DescribeStatus(pt->status), DescribeFlags(flagbuf, pt), pt->start); - } - pthread_spin_unlock(&_pthread_lock); - BLOCK_CANCELLATIONS; - strace_enabled(-1); - rc = write(fd, buf, strlen(buf)); - strace_enabled(+1); - ALLOW_CANCELLATIONS; - return rc; -} diff --git a/libc/thread/pthread_timedjoin_np.c b/libc/thread/pthread_timedjoin_np.c index 9de4d800e..1d6e37573 100644 --- a/libc/thread/pthread_timedjoin_np.c +++ b/libc/thread/pthread_timedjoin_np.c @@ -20,6 +20,7 @@ #include "libc/calls/struct/timespec.h" #include "libc/errno.h" #include "libc/intrin/atomic.h" +#include "libc/intrin/dll.h" #include "libc/thread/posixthread.internal.h" #include "libc/thread/thread2.h" #include "libc/thread/tls.h" @@ -60,7 +61,7 @@ errno_t pthread_timedjoin_np(pthread_t thread, void **value_ptr, _unassert(status == kPosixThreadJoinable || status == kPosixThreadTerminated); if (!(rc = _wait0(&pt->tib->tib_tid, abstime))) { pthread_spin_lock(&_pthread_lock); - _pthread_list = nsync_dll_remove_(_pthread_list, &pt->list); + dll_remove(&_pthread_list, &pt->list); pthread_spin_unlock(&_pthread_lock); if (value_ptr) { *value_ptr = pt->rc; diff --git a/libc/thread/pthread_zombify.c b/libc/thread/pthread_zombify.c index 5ec91ec6c..521e8ae91 100644 --- a/libc/thread/pthread_zombify.c +++ b/libc/thread/pthread_zombify.c @@ -16,13 +16,13 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/intrin/dll.h" #include "libc/thread/posixthread.internal.h" #include "libc/thread/thread.h" -#include "third_party/nsync/dll.h" void _pthread_zombify(struct PosixThread *pt) { pthread_spin_lock(&_pthread_lock); - _pthread_list = nsync_dll_remove_(_pthread_list, &pt->list); - _pthread_list = nsync_dll_make_first_in_list_(_pthread_list, &pt->list); + dll_remove(&_pthread_list, &pt->list); + dll_make_first(&_pthread_list, &pt->list); pthread_spin_unlock(&_pthread_lock); } diff --git a/libc/thread/spawn.c b/libc/thread/spawn.c index 0b4f30387..97d463065 100644 --- a/libc/thread/spawn.c +++ b/libc/thread/spawn.c @@ -22,7 +22,6 @@ #include "libc/errno.h" #include "libc/macros.internal.h" #include "libc/mem/mem.h" -#include "libc/runtime/clone.internal.h" #include "libc/runtime/internal.h" #include "libc/runtime/runtime.h" #include "libc/runtime/stack.h" diff --git a/libc/thread/thread.h b/libc/thread/thread.h index 654b3f700..c13a84655 100644 --- a/libc/thread/thread.h +++ b/libc/thread/thread.h @@ -170,7 +170,6 @@ int pthread_mutexattr_setpshared(pthread_mutexattr_t *, int) paramsnonnull(); int pthread_mutexattr_settype(pthread_mutexattr_t *, int) paramsnonnull(); int pthread_once(pthread_once_t *, void (*)(void)) paramsnonnull(); int pthread_orphan_np(void); -int pthread_print_np(int, const char *, ...); int pthread_rwlock_destroy(pthread_rwlock_t *) paramsnonnull(); int pthread_rwlock_init(pthread_rwlock_t *, const pthread_rwlockattr_t *) paramsnonnull((1)); int pthread_rwlock_rdlock(pthread_rwlock_t *) paramsnonnull(); diff --git a/libc/time/localtime.c b/libc/time/localtime.c index ebe97b2a3..8d6709afc 100644 --- a/libc/time/localtime.c +++ b/libc/time/localtime.c @@ -529,7 +529,7 @@ localtime_tzloadbody_(char const *name, struct state *sp, bool doextend, sp->chars[i] = *p++; /* Ensure '\0'-terminated, and make it safe to call ttunspecified later. */ - memset(&sp->chars[i], 0, CHARS_EXTRA); + bzero(&sp->chars[i], CHARS_EXTRA); /* Read leap seconds, discarding those out of time_t range. */ leapcnt = 0; diff --git a/libc/vga/tty.greg.c b/libc/vga/tty.greg.c index 30c1d907f..953d735af 100644 --- a/libc/vga/tty.greg.c +++ b/libc/vga/tty.greg.c @@ -166,7 +166,7 @@ void _StartTty(struct Tty *tty, unsigned char type, unsigned short yp, void *fb, unsigned init_flags) { unsigned short yn, xn, xs = xp * sizeof(TtyCanvasColor); struct DirectMap dm; - memset(tty, 0, sizeof(struct Tty)); + bzero(tty, sizeof(struct Tty)); SetYp(tty, yp); SetXp(tty, xp); SetXsFb(tty, xsfb); diff --git a/test/dsp/core/sad16x8n_test.c b/test/dsp/core/sad16x8n_test.c deleted file mode 100644 index 28620e729..000000000 --- a/test/dsp/core/sad16x8n_test.c +++ /dev/null @@ -1,107 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "dsp/core/core.h" -#include "dsp/mpeg/mpeg.h" -#include "libc/limits.h" -#include "libc/log/check.h" -#include "libc/nexgen32e/x86feature.h" -#include "libc/runtime/buffer.internal.h" -#include "libc/stdio/rand.h" -#include "libc/testlib/ezbench.h" -#include "libc/testlib/testlib.h" - -void addsw_pure(size_t n, short x[n][8], const short y[n][8]) { - size_t i, j; - for (i = 0; i < n; ++i) { - for (j = 0; j < 8; ++j) { - x[i][j] = MIN(MAX(x[i][j] + y[i][j], INT16_MIN), INT16_MAX); - } - } -} - -short *pcm1; -short *pcm2; -struct GuardedBuffer b1, b2; - -TEST(sad16x8n, test) { - CHECK_NOTNULL((pcm1 = balloc(&b1, 32, 128 * 2))); - CHECK_NOTNULL((pcm2 = balloc(&b2, 32, 128 * 2))); - pcm1[0] = 0; - pcm2[0] = 0; - pcm1[1] = 23; - pcm2[1] = 10; - pcm1[2] = 23; - pcm2[2] = -10; - pcm1[3] = 23; - pcm2[3] = -46; - pcm1[120 + 0] = 0; - pcm2[120 + 0] = 0; - pcm1[120 + 1] = 23; - pcm2[120 + 1] = 10; - pcm1[120 + 2] = 23; - pcm2[120 + 2] = -10; - pcm1[120 + 3] = 23; - pcm2[120 + 3] = -46; - sad16x8n(128 / 8, (void *)pcm1, (void *)pcm2); - EXPECT_EQ(0, pcm1[0]); - EXPECT_EQ(33, pcm1[1]); - EXPECT_EQ(13, pcm1[2]); - EXPECT_EQ(-23, pcm1[3]); - EXPECT_EQ(0, pcm1[120 + 0]); - EXPECT_EQ(33, pcm1[120 + 1]); - EXPECT_EQ(13, pcm1[120 + 2]); - EXPECT_EQ(-23, pcm1[120 + 3]); - bfree(&b1); - bfree(&b2); -} - -////////////////////////////////////////////////////////////////////// -// audio frame mixing latency: ~60ns (sse2 10x faster than pure) -// -// 1f ~= 14ms (cd quality) -// (1.0 / 41000) * (1.0 / 2) * (1152 / 1.0) -// -// 1f ~= 845µs (dolby truehd) -// (1.0 / 192000) * (1.0 / 7.1) * (1152 / 1.0) -// -// @note plm frame always has exactly 1152 floats - -void randomizeaudio(void) { - size_t i; - for (i = 0; i < PLM_AUDIO_SAMPLES_PER_FRAME; ++i) { - pcm1[i] = (rand() - INT_MAX / 2) % INT16_MAX; - pcm2[i] = (rand() - INT_MAX / 2) % INT16_MAX; - } -} - -void sad16x8n_sse2(void) { - sad16x8n(PLM_AUDIO_SAMPLES_PER_FRAME / 8, (void *)pcm1, (void *)pcm2); -} -void sad16x8n_pure(void) { - addsw_pure(PLM_AUDIO_SAMPLES_PER_FRAME / 8, (void *)pcm1, (void *)pcm2); -} - -BENCH(sad16x8n, audioframe) { - CHECK_NOTNULL((pcm1 = balloc(&b1, 32, PLM_AUDIO_SAMPLES_PER_FRAME * 2))); - CHECK_NOTNULL((pcm2 = balloc(&b2, 32, PLM_AUDIO_SAMPLES_PER_FRAME * 2))); - EZBENCH(randomizeaudio(), sad16x8n_pure()); - EZBENCH(randomizeaudio(), sad16x8n_sse2()); - bfree(&b1); - bfree(&b2); -} diff --git a/test/dsp/core/scalevolume_test.c b/test/dsp/core/scalevolume_test.c index d4172fe03..ff2cec049 100644 --- a/test/dsp/core/scalevolume_test.c +++ b/test/dsp/core/scalevolume_test.c @@ -22,7 +22,6 @@ #include "libc/log/check.h" #include "libc/macros.internal.h" #include "libc/nexgen32e/x86feature.h" -#include "libc/runtime/buffer.internal.h" #include "libc/stdio/rand.h" #include "libc/testlib/ezbench.h" #include "libc/testlib/testlib.h" diff --git a/test/libc/intrin/bextra_test.c b/test/libc/intrin/bextra_test.c deleted file mode 100644 index 284ae2fd6..000000000 --- a/test/libc/intrin/bextra_test.c +++ /dev/null @@ -1,115 +0,0 @@ -/*-*- 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 2021 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/calls/calls.h" -#include "libc/intrin/bits.h" -#include "libc/testlib/ezbench.h" -#include "libc/testlib/testlib.h" - -void SetUpOnce(void) { - ASSERT_SYS(0, 0, pledge("stdio rpath", 0)); -} - -unsigned P[] = { - // 33333222222222111111111000000000 - 0b000011000000010000000001000000000, // - // 76666666665555555554444444443333 - 0b010000001100000001010000001000000, // - 0b000101000000100100000100000000011, // - 0b010000001101000001100000001011000, // - 0b000100010000100000000011110000011, // - 0b010100001010000001001100001001000, // - 0b000011000000010111000010110000010, // - 0b011000000110110000110100000110010, // - 0b000001111100001111000001110100001, // - 0b000011000100010000100001000100000, // - 0b010001001100001001010001001000001, // - 0b010101000010100100010100000010011, // - 0b010000101101000101100000101011000, // - 0b001100010001100000001011110001011, // - 0b010100011010000011001100011001000, // - 0b000111000000110111000110110000110, // - 0b011000001110110001110100001110010, // - 0b000011111100011111000011110100011, // - 0b000011001000010001000001001000000, // - 0b010010001100010001010010001000010, // - 0b000101000100100100100100000100011, // - 0b010001001101001001100001001011001, // - 0b010100010010100000010011110010011, // - 0b010100101010000101001100101001000, // - 0b001011000001010111001010110001010, // - 0b011000010110110010110100010110010, // - 0b000101111100101111000101110100101, // - 0b000011001100010001100001001100000, // - 0b010011001100011001010011001000011, // - 0b010101000110100100110100000110011, // - 0b010001101101001101100001101011001, // - 0b011100010011100000011011110011011, // - 0b010100111010000111001100111001000, // - 0b001111000001110111001110110001110, // - 0b011000011110110011110100011110010, // - 0b000111111100111111000111110100111, // - 0b000011010000010010000001010000000, // - 0b010100001100100001010100001000100, // - 0b000101001000100101000100001000011, // - 0b010010001101010001100010001011010, // - 0b000100010100100000100011110100011, // - 0b010101001010001001001101001001001, // - 0b010011000010010111010010110010010, // - 0b011000100110110100110100100110010, // - 0b001001111101001111001001110101001, // - 0b000011010100010010100001010100000, // - 0b010101001100101001010101001000101, // - 0b010101001010100101010100001010011, // - 0b010010101101010101100010101011010, // - 0b001100010101100000101011110101011, // - 0b010101011010001011001101011001001, // - 0b010111000010110111010110110010110, // - 0b011000101110110101110100101110010, // - 0b001011111101011111001011110101011, // - 0b000011011000010011000001011000000, // - 0b010110001100110001010110001000110, // - 0b000101001100100101100100001100011, // - 0b010011001101011001100011001011011, // - 0b010100010110100000110011110110011, // - 0b010101101010001101001101101001001, // - 0b011011000011010111011010110011010, // - 0b011000110110110110110100110110010, // - 0b001101111101101111001101110101101, // - 0b000011011100010011100001011100000, // - 0b010111001100111001010111001000111, // - 0b010101001110100101110100001110011, // - 0b010011101101011101100011101011011, // - 0b011100010111100000111011110111011, // - 0b010101111010001111001101111001001, // - 0b011111000011110111011110110011110, // - 0b011000111110110111110100111110010, // - 0b001111111101111111001111110101111, // - 0b000000000000000000000000100000000, // -}; - -TEST(bextra, 9bit) { - int i; - for (i = 4; i < 257; ++i) { - ASSERT_EQ(i, _bextra(P, i, 9)); - } -} - -BENCH(bextra, bench) { - EZBENCH2("bextra 1/31", donothing, _bextra(P, 1, 31)); -} diff --git a/test/libc/intrin/division_test.c b/test/libc/intrin/division_test.c deleted file mode 100644 index edde45cd7..000000000 --- a/test/libc/intrin/division_test.c +++ /dev/null @@ -1,43 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/bits.h" -#include "libc/testlib/ezbench.h" -#include "libc/testlib/testlib.h" - -#define L(x) ((int64_t)(x)) -#define S(x) ((int128_t)(x)) -#define U(x) ((uint128_t)(x)) - -TEST(division, testUnsigned) { - volatile uint128_t x; - x = U(1000000000123123123); - EXPECT_EQ(U(20769187431582143), (U(1125899906842624) << 64) / x); - x = U(42); - EXPECT_EQ((U(26807140639110) << 64) | U(1756832768924719201), - (U(1125899906842624) << 64) / x); -} - -TEST(division, testSigned) { - volatile int128_t x; - x = S(1000000000123123123); - EXPECT_EQ(S(20769187431582143), (S(1125899906842624) << 64) / x); - x = S(42); - EXPECT_EQ(S(26807140639110) << 64 | S(1756832768924719201), - (S(1125899906842624) << 64) / x); -} diff --git a/test/libc/intrin/integralarithmetic_test.c b/test/libc/intrin/integralarithmetic_test.c deleted file mode 100644 index 18161b7f2..000000000 --- a/test/libc/intrin/integralarithmetic_test.c +++ /dev/null @@ -1,52 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/bits.h" -#include "libc/calls/calls.h" -#include "libc/limits.h" -#include "libc/macros.internal.h" -#include "libc/testlib/testlib.h" - -#define ROR(w, k) (CheckUnsigned(w) >> (k) | (w) << (sizeof(w) * 8 - (k))) -#define ROL(w, k) ((w) << (k) | CheckUnsigned(w) >> (sizeof(w) * 8 - (k))) - -void SetUpOnce(void) { - ASSERT_SYS(0, 0, pledge("stdio", 0)); -} - -TEST(TwosComplementBane, LiteralsThatAreLiterallyTheSameNumber) { - EXPECT_EQ(4, sizeof(INT_MIN)); - EXPECT_EQ(8, sizeof(-2147483648)); - EXPECT_TRUE(TYPE_SIGNED(-2147483648)); - EXPECT_FALSE(TYPE_SIGNED(0x80000000)); - EXPECT_FALSE(TYPE_SIGNED(-0x80000000)); -} - -TEST(RotateRight, Test) { - EXPECT_EQ(0x41122334u, ROR(0x11223344u, 4)); - EXPECT_EQ(0x44112233u, ROR(0x11223344u, 8)); - EXPECT_EQ(0x34411223u, ROR(0x11223344u, 12)); - EXPECT_EQ(0x33441122u, ROR(0x11223344u, 16)); -} - -TEST(RotateLeft, Test) { - EXPECT_EQ(0x12233441u, ROL(0x11223344u, 4)); - EXPECT_EQ(0x22334411u, ROL(0x11223344u, 8)); - EXPECT_EQ(0x23344112u, ROL(0x11223344u, 12)); - EXPECT_EQ(0x33441122u, ROL(0x11223344u, 16)); -} diff --git a/test/libc/intrin/intrin_test.c b/test/libc/intrin/intrin_test.c deleted file mode 100644 index 48fdd0c2f..000000000 --- a/test/libc/intrin/intrin_test.c +++ /dev/null @@ -1,2182 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/mpsadbw.h" -#include "libc/intrin/pabsb.h" -#include "libc/intrin/pabsd.h" -#include "libc/intrin/pabsw.h" -#include "libc/intrin/packssdw.h" -#include "libc/intrin/packsswb.h" -#include "libc/intrin/packusdw.h" -#include "libc/intrin/packuswb.h" -#include "libc/intrin/paddb.h" -#include "libc/intrin/paddd.h" -#include "libc/intrin/paddq.h" -#include "libc/intrin/paddsb.h" -#include "libc/intrin/paddsw.h" -#include "libc/intrin/paddusb.h" -#include "libc/intrin/paddusw.h" -#include "libc/intrin/paddw.h" -#include "libc/intrin/palignr.h" -#include "libc/intrin/pand.h" -#include "libc/intrin/pandn.h" -#include "libc/intrin/pavgb.h" -#include "libc/intrin/pavgw.h" -#include "libc/intrin/pcmpeqb.h" -#include "libc/intrin/pcmpeqd.h" -#include "libc/intrin/pcmpeqw.h" -#include "libc/intrin/pcmpgtb.h" -#include "libc/intrin/pcmpgtd.h" -#include "libc/intrin/pcmpgtw.h" -#include "libc/intrin/pdep.h" -#include "libc/intrin/pext.h" -#include "libc/intrin/phaddd.h" -#include "libc/intrin/phaddsw.h" -#include "libc/intrin/phaddw.h" -#include "libc/intrin/phsubd.h" -#include "libc/intrin/phsubsw.h" -#include "libc/intrin/phsubw.h" -#include "libc/intrin/pmaddubsw.h" -#include "libc/intrin/pmaddwd.h" -#include "libc/intrin/pmaxsw.h" -#include "libc/intrin/pmaxub.h" -#include "libc/intrin/pminsw.h" -#include "libc/intrin/pminub.h" -#include "libc/intrin/pmulhrsw.h" -#include "libc/intrin/pmulhuw.h" -#include "libc/intrin/pmulhw.h" -#include "libc/intrin/pmulld.h" -#include "libc/intrin/pmullw.h" -#include "libc/intrin/pmuludq.h" -#include "libc/intrin/por.h" -#include "libc/intrin/psadbw.h" -#include "libc/intrin/pshufb.h" -#include "libc/intrin/pshufd.h" -#include "libc/intrin/pshufhw.h" -#include "libc/intrin/pshuflw.h" -#include "libc/intrin/pshufw.h" -#include "libc/intrin/psignb.h" -#include "libc/intrin/psignd.h" -#include "libc/intrin/psignw.h" -#include "libc/intrin/pslld.h" -#include "libc/intrin/pslldq.h" -#include "libc/intrin/psllq.h" -#include "libc/intrin/psllw.h" -#include "libc/intrin/psrad.h" -#include "libc/intrin/psraw.h" -#include "libc/intrin/psrld.h" -#include "libc/intrin/psrldq.h" -#include "libc/intrin/psrlq.h" -#include "libc/intrin/psrlw.h" -#include "libc/intrin/psubb.h" -#include "libc/intrin/psubd.h" -#include "libc/intrin/psubq.h" -#include "libc/intrin/psubsb.h" -#include "libc/intrin/psubsw.h" -#include "libc/intrin/psubusb.h" -#include "libc/intrin/psubusw.h" -#include "libc/intrin/psubw.h" -#include "libc/intrin/punpckhbw.h" -#include "libc/intrin/punpckhdq.h" -#include "libc/intrin/punpckhqdq.h" -#include "libc/intrin/punpckhwd.h" -#include "libc/intrin/punpcklbw.h" -#include "libc/intrin/punpckldq.h" -#include "libc/intrin/punpcklqdq.h" -#include "libc/intrin/punpcklwd.h" -#include "libc/intrin/pxor.h" -#include "libc/intrin/shufpd.h" -#include "libc/intrin/shufps.h" -#include "libc/limits.h" -#include "libc/log/check.h" -#include "libc/mem/gc.internal.h" -#include "libc/nexgen32e/kcpuids.h" -#include "libc/stdio/lcg.internal.h" -#include "libc/stdio/rand.h" -#include "libc/stdio/stdio.h" -#include "libc/str/str.h" -#include "libc/testlib/ezbench.h" -#include "libc/testlib/testlib.h" -#include "libc/x/x.h" -#include "tool/viz/lib/formatstringtable-testlib.h" - -uint64_t g_rando = 1; - -forceinline uint64_t Rando(void) { - return KnuthLinearCongruentialGenerator(&g_rando) >> 32 << 32 | - KnuthLinearCongruentialGenerator(&g_rando) >> 32; -} - -dontinline void RngSet(void *mem, size_t size) { - uint64_t coin; - DCHECK(size % 8 == 0); - for (size >>= 3; size--;) { - coin = Rando(); - memcpy((char *)mem + size * 8, &coin, 8); - } -} - -FIXTURE(intrin, disableHardwareExtensions) { -#ifdef __x86_64__ - memset((/*unconst*/ void *)kCpuids, 0, sizeof(kCpuids)); -#endif -} - -TEST(punpcklwd, test) { - uint16_t a[8] = {1, 02, 03, 04, 05, 06, 07, 8}; - uint16_t b[8] = {9, 10, 11, 12, 13, 14, 15, 16}; - uint16_t c[8]; - punpcklwd(c, a, b); - ASSERT_EQ(1, c[0]); - ASSERT_EQ(9, c[1]); - ASSERT_EQ(2, c[2]); - ASSERT_EQ(10, c[3]); - ASSERT_EQ(3, c[4]); - ASSERT_EQ(11, c[5]); - ASSERT_EQ(4, c[6]); - ASSERT_EQ(12, c[7]); -} - -TEST(punpcklwd, pure) { - uint16_t a[8] = {1, 02, 03, 04, 05, 06, 07, 8}; - uint16_t b[8] = {9, 10, 11, 12, 13, 14, 15, 16}; - uint16_t c[8]; - punpcklwd(c, a, b); - ASSERT_EQ(1, c[0]); - ASSERT_EQ(9, c[1]); - ASSERT_EQ(2, c[2]); - ASSERT_EQ(10, c[3]); - ASSERT_EQ(3, c[4]); - ASSERT_EQ(11, c[5]); - ASSERT_EQ(4, c[6]); - ASSERT_EQ(12, c[7]); -} - -TEST(punpcklwd, 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}; - punpcklwd(a, a, b); - ASSERT_EQ(1, a[0]); - ASSERT_EQ(9, a[1]); - ASSERT_EQ(2, a[2]); - ASSERT_EQ(10, a[3]); - ASSERT_EQ(3, a[4]); - ASSERT_EQ(11, a[5]); - ASSERT_EQ(4, a[6]); - ASSERT_EQ(12, a[7]); -} - -TEST(punpcklwd, 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}; - (punpcklwd)(a, a, b); - ASSERT_EQ(1, a[0]); - ASSERT_EQ(9, a[1]); - ASSERT_EQ(2, a[2]); - ASSERT_EQ(10, a[3]); - ASSERT_EQ(3, a[4]); - ASSERT_EQ(11, a[5]); - ASSERT_EQ(4, a[6]); - ASSERT_EQ(12, a[7]); -} - -TEST(punpcklwd, 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}; - punpcklwd(b, a, b); - ASSERT_EQ(1, b[0]); - ASSERT_EQ(9, b[1]); - ASSERT_EQ(2, b[2]); - ASSERT_EQ(10, b[3]); - ASSERT_EQ(3, b[4]); - ASSERT_EQ(11, b[5]); - ASSERT_EQ(4, b[6]); - ASSERT_EQ(12, b[7]); -} - -TEST(punpcklwd, 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}; - (punpcklwd)(b, a, b); - ASSERT_EQ(1, b[0]); - ASSERT_EQ(9, b[1]); - ASSERT_EQ(2, b[2]); - ASSERT_EQ(10, b[3]); - ASSERT_EQ(3, b[4]); - ASSERT_EQ(11, b[5]); - ASSERT_EQ(4, b[6]); - ASSERT_EQ(12, b[7]); -} - -TEST(punpcklqdq, test) { - uint64_t a[2] = {1, 2}; - uint64_t b[2] = {3, 4}; - uint64_t c[2]; - punpcklqdq(c, a, b); - ASSERT_EQ(1, c[0]); - ASSERT_EQ(3, c[1]); -} - -TEST(punpcklqdq, pure) { - uint64_t a[2] = {1, 2}; - uint64_t b[2] = {3, 4}; - uint64_t c[2]; - (punpcklqdq)(c, a, b); - ASSERT_EQ(1, c[0]); - ASSERT_EQ(3, c[1]); -} - -TEST(punpcklqdq, testAlias) { - uint64_t a[2] = {1, 2}; - uint64_t b[2] = {3, 4}; - punpcklqdq(a, a, b); - ASSERT_EQ(1, a[0]); - ASSERT_EQ(3, a[1]); -} - -TEST(punpcklqdq, pureAlias) { - uint64_t a[2] = {1, 2}; - uint64_t b[2] = {3, 4}; - (punpcklqdq)(a, a, b); - ASSERT_EQ(1, a[0]); - ASSERT_EQ(3, a[1]); -} - -TEST(punpckldq, test) { - uint32_t a[4] = {1, 2, 3, 4}; - uint32_t b[4] = {5, 6, 7, 8}; - uint32_t c[4]; - punpckldq(c, a, b); - ASSERT_EQ(1, c[0]); - ASSERT_EQ(5, c[1]); - ASSERT_EQ(2, c[2]); - ASSERT_EQ(6, c[3]); -} - -TEST(punpckldq, pure) { - uint32_t a[4] = {1, 2, 3, 4}; - uint32_t b[4] = {5, 6, 7, 8}; - uint32_t c[4]; - punpckldq(c, a, b); - ASSERT_EQ(1, c[0]); - ASSERT_EQ(5, c[1]); - ASSERT_EQ(2, c[2]); - ASSERT_EQ(6, c[3]); -} - -TEST(punpckldq, testAlias) { - uint32_t a[4] = {1, 2, 3, 4}; - uint32_t b[4] = {5, 6, 7, 8}; - punpckldq(a, a, b); - ASSERT_EQ(1, a[0]); - ASSERT_EQ(5, a[1]); - ASSERT_EQ(2, a[2]); - ASSERT_EQ(6, a[3]); -} - -TEST(punpckldq, pureAlias) { - uint32_t a[4] = {1, 2, 3, 4}; - uint32_t b[4] = {5, 6, 7, 8}; - (punpckldq)(a, a, b); - ASSERT_EQ(1, a[0]); - ASSERT_EQ(5, a[1]); - ASSERT_EQ(2, a[2]); - ASSERT_EQ(6, a[3]); -} - -TEST(punpckldq, testAlias2) { - uint32_t a[4] = {1, 2, 3, 4}; - uint32_t b[4] = {5, 6, 7, 8}; - punpckldq(b, a, b); - ASSERT_EQ(1, b[0]); - ASSERT_EQ(5, b[1]); - ASSERT_EQ(2, b[2]); - ASSERT_EQ(6, b[3]); -} - -TEST(punpckldq, pureAlias2) { - uint32_t a[4] = {1, 2, 3, 4}; - uint32_t b[4] = {5, 6, 7, 8}; - (punpckldq)(b, a, b); - ASSERT_EQ(1, b[0]); - ASSERT_EQ(5, b[1]); - ASSERT_EQ(2, b[2]); - ASSERT_EQ(6, b[3]); -} - -TEST(punpcklqdq, fuzz) { - int i, j; - uint64_t x[2], y[2], a[2], b[2]; - for (i = 0; i < 100; ++i) { - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - punpcklqdq(a, x, y); - (punpcklqdq)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(punpckldq, fuzz) { - int i, j; - uint32_t x[4], y[4], a[4], b[4]; - for (i = 0; i < 100; ++i) { - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - punpckldq(a, x, y); - (punpckldq)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(punpcklbw, fuzz) { - int i, j; - uint8_t x[16], y[16], a[16], b[16]; - for (i = 0; i < 100; ++i) { - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - punpcklbw(a, x, y); - (punpcklbw)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(punpckhwd, test) { - uint16_t a[8] = {1, 02, 03, 04, 05, 06, 07, 8}; - uint16_t b[8] = {9, 10, 11, 12, 13, 14, 15, 16}; - uint16_t c[8]; - punpckhwd(c, a, b); - 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) { - uint16_t a[8] = {1, 02, 03, 04, 05, 06, 07, 8}; - uint16_t b[8] = {9, 10, 11, 12, 13, 14, 15, 16}; - uint16_t c[8]; - punpckhwd(c, a, b); - 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); - 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); - 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); - 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); - 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) { - uint64_t a[2] = {1, 2}; - uint64_t b[2] = {3, 4}; - uint64_t c[2]; - punpckhqdq(c, a, b); - EXPECT_EQ(2, c[0]); - EXPECT_EQ(4, c[1]); -} - -TEST(punpckhqdq, pure) { - uint64_t a[2] = {1, 2}; - uint64_t b[2] = {3, 4}; - uint64_t c[2]; - (punpckhqdq)(c, a, b); - 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); - 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); - EXPECT_EQ(2, a[0]); - EXPECT_EQ(4, a[1]); -} - -TEST(punpckhdq, test) { - uint32_t a[4] = {1, 2, 3, 4}; - uint32_t b[4] = {5, 6, 7, 8}; - uint32_t c[4]; - punpckhdq(c, a, b); - EXPECT_EQ(3, c[0]); - EXPECT_EQ(7, c[1]); - EXPECT_EQ(4, c[2]); - EXPECT_EQ(8, c[3]); -} - -TEST(punpckhdq, pure) { - uint32_t a[4] = {1, 2, 3, 4}; - uint32_t b[4] = {5, 6, 7, 8}; - uint32_t c[4]; - punpckhdq(c, a, b); - 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); - 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); - 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); - 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); - EXPECT_EQ(3, b[0]); - EXPECT_EQ(7, b[1]); - EXPECT_EQ(4, b[2]); - EXPECT_EQ(8, b[3]); -} - -TEST(punpckhwd, fuzz) { - int i, j; - uint16_t x[8], y[8], a[8], b[8]; - for (i = 0; i < 100; ++i) { - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - punpckhwd(a, x, y); - (punpckhwd)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(punpckhqdq, fuzz) { - int i, j; - uint64_t x[2], y[2], a[2], b[2]; - for (i = 0; i < 100; ++i) { - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - punpckhqdq(a, x, y); - (punpckhqdq)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(punpckhdq, fuzz) { - int i, j; - uint32_t x[4], y[4], a[4], b[4]; - for (i = 0; i < 100; ++i) { - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - punpckhdq(a, x, y); - (punpckhdq)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(punpckhbw, fuzz) { - int i, j; - uint8_t x[16], y[16], a[16], b[16]; - for (i = 0; i < 100; ++i) { - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - punpckhbw(a, x, y); - (punpckhbw)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(psubq, fuzz) { - int i, j; - uint64_t x[2], y[2], a[2], b[2]; - for (i = 0; i < 100; ++i) { - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - psubq(a, x, y); - (psubq)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(psrawv, testSmallShift) { - int16_t A[8] = {-1, -2, SHRT_MIN, 2}; - uint64_t B[2] = {1}; - psrawv(A, A, B); - ASSERT_EQ(-1, A[0]); - ASSERT_EQ(-1, A[1]); - ASSERT_EQ(-16384, A[2]); - ASSERT_EQ(1, A[3]); - ASSERT_EQ(0, A[4]); -} - -TEST(psraw, testSmallShift) { - int16_t A[8] = {-1, -2, SHRT_MIN, 2}; - psraw(A, A, 1); - ASSERT_EQ(-1, A[0]); - ASSERT_EQ(-1, A[1]); - ASSERT_EQ(-16384, A[2]); - ASSERT_EQ(1, A[3]); - ASSERT_EQ(0, A[4]); -} - -TEST(psraw, pureSmallShift) { - int16_t A[8] = {-1, -2, SHRT_MIN, 2}; - (psraw)(A, A, 1); - ASSERT_EQ(-1, A[0]); - ASSERT_EQ(-1, A[1]); - ASSERT_EQ(-16384, A[2]); - ASSERT_EQ(1, A[3]); - ASSERT_EQ(0, A[4]); -} - -TEST(psraw, testBigShift_saturatesCount) { - int16_t A[8] = {-1, -2, SHRT_MIN, 2}; - psraw(A, A, 77); - ASSERT_EQ(-1, A[0]); - ASSERT_EQ(-1, A[1]); - ASSERT_EQ(-1, A[2]); - ASSERT_EQ(0, A[3]); - ASSERT_EQ(0, A[4]); -} - -TEST(psraw, pureBigShift_saturatesCount) { - int16_t A[8] = {-1, -2, SHRT_MIN, 2}; - (psraw)(A, A, 77); - ASSERT_EQ(-1, A[0]); - ASSERT_EQ(-1, A[1]); - ASSERT_EQ(-1, A[2]); - ASSERT_EQ(0, A[3]); - ASSERT_EQ(0, A[4]); -} - -TEST(psradv, testSmallShift) { - int32_t A[8] = {-1, -2, INT32_MIN, 2}; - uint64_t B[2] = {1}; - psradv(A, A, B); - ASSERT_EQ(-1, A[0]); - ASSERT_EQ(-1, A[1]); - ASSERT_EQ(-1073741824, A[2]); - ASSERT_EQ(1, A[3]); - ASSERT_EQ(0, A[4]); -} - -TEST(psradv, test) { - int i, j; - int32_t x[4], a[4], b[4]; - uint64_t y[2]; - for (i = 0; i < 100; ++i) { - RngSet(x, sizeof(x)); - for (j = 0; j < 2; ++j) { - y[j] = Rando() % 70; - } - psradv(a, x, y); - (psradv)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(psrad, testSmallShift) { - int32_t A[4] = {-1, -2, INT32_MIN, 2}; - psrad(A, A, 1); - ASSERT_EQ(-1, A[0]); - ASSERT_EQ(-1, A[1]); - ASSERT_EQ(-1073741824, A[2]); - ASSERT_EQ(1, A[3]); -} - -TEST(psrad, pureSmallShift) { - int32_t A[4] = {-1, -2, INT32_MIN, 2}; - (psrad)(A, A, 1); - ASSERT_EQ(-1, A[0]); - ASSERT_EQ(-1, A[1]); - ASSERT_EQ(-1073741824, A[2]); - ASSERT_EQ(1, A[3]); -} - -TEST(psrad, testBigShift_saturatesCount) { - int32_t A[4] = {-1, -2, INT32_MIN, 2}; - psrad(A, A, 77); - ASSERT_EQ(-1, A[0]); - ASSERT_EQ(-1, A[1]); - ASSERT_EQ(-1, A[2]); - ASSERT_EQ(0, A[3]); -} - -TEST(psrad, pureBigShift_saturatesCount) { - int32_t A[4] = {-1, -2, INT32_MIN, 2}; - (psrad)(A, A, 77); - ASSERT_EQ(-1, A[0]); - ASSERT_EQ(-1, A[1]); - ASSERT_EQ(-1, A[2]); - ASSERT_EQ(0, A[3]); -} - -TEST(psllwv, test) { - int i, j; - uint16_t x[8], a[8], b[8]; - uint64_t y[2]; - for (i = 0; i < 32; ++i) { - RngSet(x, sizeof(x)); - for (j = 0; j < 2; ++j) { - y[j] = Rando() % 300; - } - psllwv(a, x, y); - (psllwv)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(psllw, testSmallShift) { - uint16_t A[8] = {0, 1, 0xffff, 2}; - psllw(A, A, 1); - ASSERT_EQ(0, A[0]); - ASSERT_EQ(2, A[1]); - ASSERT_EQ(0xfffe, A[2]); - ASSERT_EQ(4, A[3]); -} - -TEST(psllwv, testSmallShift) { - uint16_t A[8] = {0, 1, 0xffff, 2}; - uint64_t B[2] = {1}; - psllwv(A, A, B); - ASSERT_EQ(0, A[0]); - ASSERT_EQ(2, A[1]); - ASSERT_EQ(0xfffe, A[2]); - ASSERT_EQ(4, A[3]); -} - -TEST(pslldv, test) { - int i, j; - uint32_t x[4], a[4], b[4]; - uint64_t y[2]; - for (i = 0; i < 32; ++i) { - RngSet(x, sizeof(x)); - for (j = 0; j < 2; ++j) { - y[j] = Rando() % 300; - } - pslldv(a, x, y); - (pslldv)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(pslld, testSmallShift) { - uint32_t A[8] = {0, 1, 0xffffffff, 2}; - pslld(A, A, 1); - ASSERT_EQ(0, A[0]); - ASSERT_EQ(2, A[1]); - ASSERT_EQ(0xfffffffe, A[2]); - ASSERT_EQ(4, A[3]); -} - -TEST(pslldv, testSmallShift) { - uint32_t A[8] = {0, 1, 0xffffffff, 2}; - uint64_t B[2] = {1}; - pslldv(A, A, B); - ASSERT_EQ(0, A[0]); - ASSERT_EQ(2, A[1]); - ASSERT_EQ(0xfffffffe, A[2]); - ASSERT_EQ(4, A[3]); -} - -TEST(pmulhuw, test) { - uint16_t x[8] = {0, 0xffff, 0x0000, 0x0001, 0x8000}; - uint16_t y[8] = {0, 0xffff, 0xffff, 0xffff, 0x8000}; - uint16_t z[8]; - pmulhuw(z, x, y); - ASSERT_EQ(0x0000 /*0000*/, z[0]); - ASSERT_EQ(0xfffe /*0001*/, z[1]); - ASSERT_EQ(0x0000 /*0000*/, z[2]); - ASSERT_EQ(0x0000 /*ffff*/, z[3]); - ASSERT_EQ(0x4000 /*0000*/, z[4]); -} - -TEST(pmulhuw, pure) { - uint16_t x[8] = {0, 0xffff, 0x0000, 0x0001, 0x8000}; - uint16_t y[8] = {0, 0xffff, 0xffff, 0xffff, 0x8000}; - uint16_t z[8]; - (pmulhuw)(z, x, y); - ASSERT_EQ(0x0000 /*0000*/, z[0]); - ASSERT_EQ(0xfffe /*0001*/, z[1]); - ASSERT_EQ(0x0000 /*0000*/, z[2]); - ASSERT_EQ(0x0000 /*ffff*/, z[3]); - ASSERT_EQ(0x4000 /*0000*/, z[4]); -} - -TEST(pmulhuw, fuzz) { - int i, j; - uint16_t x[8], y[8], a[8], b[8]; - for (i = 0; i < 100; ++i) { - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - pmulhuw(a, x, y); - (pmulhuw)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - pmulhuw(a, (void *)a, y); - (pmulhuw)(b, (void *)b, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(pmulhw, fuzz) { - int i, j; - int16_t x[8], y[8], a[8], b[8]; - for (i = 0; i < 1000; ++i) { - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - pmulhw(a, x, y); - (pmulhw)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - pmulhw(a, (void *)a, y); - (pmulhw)(b, (void *)b, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(pmullw, fuzz) { - int i, j; - int16_t x[8], y[8], a[8], b[8]; - for (i = 0; i < 1000; ++i) { - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - pmullw(a, x, y); - (pmullw)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - pmullw(a, (void *)a, y); - (pmullw)(b, (void *)b, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(pmulld, fuzz) { - int i, j; - uint32_t x[4], y[4], a[4], b[4]; - for (i = 0; i < 1000; ++i) { - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - pmulld(a, x, y); - (pmulld)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - pmulld(a, (void *)a, y); - (pmulld)(b, (void *)b, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(pmuludq, fuzz) { - int i, j; - uint32_t x[4], y[4]; - uint64_t a[2], b[2]; - for (i = 0; i < 1000; ++i) { - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - pmuludq(a, x, y); - (pmuludq)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - pmuludq(a, (void *)a, y); - (pmuludq)(b, (void *)b, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(pmaddwd, fuzz) { - int i, j; - int16_t x[8], y[8]; - int32_t a[4], b[4]; - for (i = 0; i < 1000; ++i) { - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - pmaddwd(a, x, y); - (pmaddwd)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - pmaddwd(a, (void *)a, y); - (pmaddwd)(b, (void *)b, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(phaddw, fuzz) { - int i, j; - int16_t x[8], y[8]; - int16_t a[8], b[8]; - for (i = 0; i < 1000; ++i) { - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - phaddw(a, x, y); - (phaddw)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - phaddw(a, (void *)a, y); - (phaddw)(b, (void *)b, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(phaddd, fuzz) { - int i, j; - uint32_t x[4], y[4]; - uint32_t a[4], b[4]; - for (i = 0; i < 1000; ++i) { - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - phaddd(a, x, y); - (phaddd)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - phaddd(a, (void *)a, y); - (phaddd)(b, (void *)b, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(phsubw, fuzz) { - int i, j; - int16_t x[8], y[8]; - int16_t a[8], b[8]; - for (i = 0; i < 1000; ++i) { - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - phsubw(a, x, y); - (phsubw)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - phsubw(a, (void *)a, y); - (phsubw)(b, (void *)b, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(phsubd, fuzz) { - int i, j; - uint32_t x[4], y[4]; - uint32_t a[4], b[4]; - for (i = 0; i < 1000; ++i) { - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - phsubd(a, x, y); - (phsubd)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - phsubd(a, (void *)a, y); - (phsubd)(b, (void *)b, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(psubd, fuzz) { - int i, j; - uint32_t x[4], y[4]; - uint32_t a[4], b[4]; - for (i = 0; i < 1000; ++i) { - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - psubd(a, x, y); - (psubd)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - psubd(a, (void *)a, y); - (psubd)(b, (void *)b, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(phaddsw, fuzz) { - int i, j; - int16_t x[8], y[8]; - int16_t a[8], b[8]; - for (i = 0; i < 1000; ++i) { - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - phaddsw(a, x, y); - (phaddsw)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - phaddsw(a, (void *)a, y); - (phaddsw)(b, (void *)b, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(phsubsw, fuzz) { - int i, j; - int16_t x[8], y[8]; - int16_t a[8], b[8]; - for (i = 0; i < 1000; ++i) { - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - phsubsw(a, x, y); - (phsubsw)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - phsubsw(a, (void *)a, y); - (phsubsw)(b, (void *)b, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(phaddw, testOverflow_wrapsAround) { - short M[2][8] = { - {0x7fff, 0, 0x7fff, 1, 13004, -30425, 20777, -16389}, - {-28040, 13318, -1336, -24798, -13876, 3599, -7346, -23575}, - }; - phaddw(M[0], M[0], M[1]); - EXPECT_SHRTMATRIXEQ(2, 8, M, "\n\ - 32767 -32768 -17421 4388 -14722 -26134 -10277 -30921\n\ --28040 13318 -1336 -24798 -13876 3599 -7346 -23575"); -} - -TEST(phaddw, testAliasing_isOk) { - short M[1][8] = { - {0, 1, 2, 3, 4, 5, 6, 7}, - }; - phaddw(M[0], M[0], M[0]); - EXPECT_SHRTMATRIXEQ(1, 8, M, "\n\ - 1 5 9 13 1 5 9 13"); -} - -TEST(phaddsw, testOverflow_saturates) { - short M[2][8] = { - {0x7fff, 0, 0x7fff, 1, 0x7fff, 0x7fff, 20777, -16389}, - {-28040, 13318, -1336, -24798, -13876, 3599, -7346, -23575}, - }; - phaddsw(M[0], M[0], M[1]); - EXPECT_SHRTMATRIXEQ(2, 8, M, "\n\ - 32767 32767 32767 4388 -14722 -26134 -10277 -30921\n\ --28040 13318 -1336 -24798 -13876 3599 -7346 -23575"); -} - -TEST(phaddsw, testAliasing_isOk) { - short M[1][8] = {{0, 1, 2, 3, 4, 5, 6, 7}}; - phaddsw(M[0], M[0], M[0]); - EXPECT_SHRTMATRIXEQ(1, 8, M, "\n\ - 1 5 9 13 1 5 9 13"); -} - -TEST(pcmpgtb, test) { - int i, j; - int8_t x[16], y[16], a[16], b[16]; - for (i = 0; i < 100; ++i) { - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - static int count; - pcmpgtb(a, x, y); - (pcmpgtb)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(pcmpeqb, test) { - int i, j; - uint8_t x[16], y[16], a[16], b[16]; - for (i = 0; i < 100; ++i) { - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - pcmpeqb(a, x, y); - (pcmpeqb)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(pcmpeqd, test) { - int i, j; - int32_t x[4], y[4], a[4], b[4]; - for (i = 0; i < 100; ++i) { - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - pcmpeqd(a, x, y); - (pcmpeqd)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(pcmpgtd, test) { - int i, j; - int32_t x[4], y[4], a[4], b[4]; - for (i = 0; i < 100; ++i) { - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - pcmpgtd(a, x, y); - (pcmpgtd)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(pcmpeqw, test) { - int i, j; - int16_t x[8], y[8], a[8], b[8]; - for (i = 0; i < 100; ++i) { - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - pcmpeqw(a, x, y); - (pcmpeqw)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(pcmpgtw, test) { - int i, j; - int16_t x[8], y[8], a[8], b[8]; - for (i = 0; i < 100; ++i) { - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - pcmpgtw(a, x, y); - (pcmpgtw)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(por, fuzz) { - int i, j; - uint64_t x[2], y[2], a[2], b[2]; - for (i = 0; i < 100; ++i) { - for (j = 0; j < 2; ++j) x[j] = Rando(); - for (j = 0; j < 2; ++j) y[j] = Rando(); - por(a, x, y); - (por)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - por(a, (void *)a, y); - (por)(b, (void *)b, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(pxor, fuzz) { - int i, j; - uint64_t x[2], y[2], a[2], b[2]; - for (i = 0; i < 100; ++i) { - for (j = 0; j < 2; ++j) x[j] = Rando(); - for (j = 0; j < 2; ++j) y[j] = Rando(); - pxor(a, x, y); - (pxor)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - pxor(a, (void *)a, y); - (pxor)(b, (void *)b, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(pand, fuzz) { - int i, j; - uint64_t x[2], y[2], a[2], b[2]; - for (i = 0; i < 100; ++i) { - for (j = 0; j < 2; ++j) x[j] = Rando(); - for (j = 0; j < 2; ++j) y[j] = Rando(); - pand(a, x, y); - (pand)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - pand(a, (void *)a, y); - (pand)(b, (void *)b, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(pandn, fuzz) { - int i, j; - uint64_t x[2], y[2], a[2], b[2]; - for (i = 0; i < 100; ++i) { - for (j = 0; j < 2; ++j) x[j] = Rando(); - for (j = 0; j < 2; ++j) y[j] = Rando(); - pandn(a, x, y); - (pandn)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - pandn(a, (void *)a, y); - (pandn)(b, (void *)b, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(paddq, fuzz) { - int i, j; - uint64_t x[2], y[2], a[2], b[2]; - for (i = 0; i < 100; ++i) { - for (j = 0; j < 2; ++j) x[j] = Rando(); - for (j = 0; j < 2; ++j) y[j] = Rando(); - paddq(a, x, y); - (paddq)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - paddq(a, (void *)a, y); - (paddq)(b, (void *)b, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(pavgb, fuzz) { - int i, j; - uint8_t x[16], y[16], a[16], b[16]; - for (i = 0; i < 100; ++i) { - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - pavgb(a, x, y); - (pavgb)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - pavgb(a, (void *)a, y); - (pavgb)(b, (void *)b, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(pavgw, fuzz) { - int i, j; - uint16_t x[8], y[8], a[8], b[8]; - for (i = 0; i < 100; ++i) { - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - pavgw(a, x, y); - (pavgw)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - pavgw(a, (void *)a, y); - (pavgw)(b, (void *)b, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(punpcklwd, fuzz) { - int i, j; - uint16_t x[8], y[8], a[8], b[8]; - for (i = 0; i < 100; ++i) { - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - punpcklwd(a, x, y); - (punpcklwd)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - punpcklwd(a, a, y); - (punpcklwd)(b, b, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - punpcklwd(a, y, a); - (punpcklwd)(b, y, b); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(pminub, fuzz) { - int i, j; - uint8_t x[16], y[16], a[16], b[16]; - for (i = 0; i < 100; ++i) { - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - pminub(a, x, y); - (pminub)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - pminub(a, (void *)a, y); - (pminub)(b, (void *)b, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(pminsw, fuzz) { - int i, j; - int16_t x[8], y[8], a[8], b[8]; - for (i = 0; i < 100; ++i) { - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - pminsw(a, x, y); - (pminsw)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - pminsw(a, (void *)a, y); - (pminsw)(b, (void *)b, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(pmaxub, fuzz) { - int i, j; - uint8_t x[16], y[16], a[16], b[16]; - for (i = 0; i < 100; ++i) { - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - pmaxub(a, x, y); - (pmaxub)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - pmaxub(a, (void *)a, y); - (pmaxub)(b, (void *)b, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(pmaxsw, fuzz) { - int i, j; - int16_t x[8], y[8], a[8], b[8]; - for (i = 0; i < 100; ++i) { - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - pmaxsw(a, x, y); - (pmaxsw)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - pmaxsw(a, (void *)a, y); - (pmaxsw)(b, (void *)b, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(paddw, test) { - int16_t A[8] = {7}; - int16_t B[8] = {11}; - int16_t C[8]; - paddw(C, A, B); - ASSERT_EQ(18, C[0]); -} - -TEST(paddw, testOverflow_wrapsAround) { - int16_t A[8] = {SHRT_MAX, SHRT_MIN}; - int16_t B[8] = {1, -1}; - paddw(A, A, B); - ASSERT_EQ(SHRT_MIN, A[0]); - ASSERT_EQ(SHRT_MAX, A[1]); -} - -TEST(paddw, fuzz) { - int i, j; - int16_t x[8], y[8], a[8], b[8]; - for (i = 0; i < 100; ++i) { - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - paddw(a, x, y); - (paddw)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - paddw(a, (void *)a, y); - (paddw)(b, (void *)b, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(paddsw, test) { - int16_t A[8] = {7}; - int16_t B[8] = {11}; - int16_t C[8]; - paddsw(C, A, B); - ASSERT_EQ(18, C[0]); -} - -TEST(paddsw, testOverflow_saturates) { - int16_t A[8] = {SHRT_MAX, SHRT_MIN}; - int16_t B[8] = {1, -1}; - paddsw(A, A, B); - ASSERT_EQ(SHRT_MAX, A[0]); - ASSERT_EQ(SHRT_MIN, A[1]); -} - -TEST(paddusw, fuzz) { - int i, j; - uint16_t x[8], y[8], a[8], b[8]; - for (i = 0; i < 100; ++i) { - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - paddusw(a, x, y); - (paddusw)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - paddusw(a, (void *)a, y); - (paddusw)(b, (void *)b, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(psubb, fuzz) { - int i, j; - uint8_t x[16], y[16], a[16], b[16]; - for (i = 0; i < 100; ++i) { - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - psubb(a, x, y); - (psubb)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - psubb(a, (void *)a, y); - (psubb)(b, (void *)b, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(psubw, fuzz) { - int i, j; - int16_t x[8], y[8], a[8], b[8]; - for (i = 0; i < 100; ++i) { - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - psubw(a, x, y); - (psubw)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - psubw(a, (void *)a, y); - (psubw)(b, (void *)b, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(psubusw, fuzz) { - int i, j; - uint16_t x[8], y[8], a[8], b[8]; - for (i = 0; i < 100; ++i) { - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - psubusw(a, x, y); - (psubusw)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - psubusw(a, (void *)a, y); - (psubusw)(b, (void *)b, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(paddusb, fuzz) { - int i, j; - uint8_t x[16], y[16], a[16], b[16]; - for (i = 0; i < 100; ++i) { - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - paddusb(a, x, y); - (paddusb)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - paddusb(a, (void *)a, y); - (paddusb)(b, (void *)b, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(psubusb, fuzz) { - int i, j; - uint8_t x[16], y[16], a[16], b[16]; - for (i = 0; i < 100; ++i) { - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - psubusb(a, x, y); - (psubusb)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - psubusb(a, (void *)a, y); - (psubusb)(b, (void *)b, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(pabsb, fuzz) { - int i, j; - int8_t x[16]; - uint8_t a[16], b[16]; - for (i = 0; i < 100; ++i) { - RngSet(x, sizeof(x)); - pabsb(a, x); - (pabsb)(b, x); - ASSERT_EQ(0, memcmp(a, b, 16), "%d\n\t%#.16hhs\n\t%#.16hhs\n\t%#.16hhs", i, - x, a, b); - } -} - -TEST(pabsw, fuzz) { - int i, j; - int16_t x[8]; - uint16_t a[8], b[8]; - for (i = 0; i < 100; ++i) { - RngSet(x, sizeof(x)); - pabsw(a, x); - (pabsw)(b, x); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(pabsd, fuzz) { - int i, j; - int32_t x[4]; - uint32_t a[4], b[4]; - x[0] = INT_MIN; - pabsd((uint32_t *)x, x); - EXPECT_EQ(INT_MIN, x[0]); - x[0] = INT_MIN; - (pabsd)((uint32_t *)x, x); - EXPECT_EQ(INT_MIN, x[0]); - for (i = 0; i < 100; ++i) { - RngSet(x, sizeof(x)); - pabsd(a, x); - (pabsd)(b, x); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(psignb, fuzz) { - int i, j; - int8_t x[16], y[16], a[16], b[16]; - for (i = 0; i < 100; ++i) { - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - psignb(a, x, y); - (psignb)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - psignb(a, (void *)a, y); - (psignb)(b, (void *)b, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(psignw, fuzz) { - int i, j; - int16_t x[8], y[8], a[8], b[8]; - for (i = 0; i < 100; ++i) { - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - psignw(a, x, y); - (psignw)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - psignw(a, (void *)a, y); - (psignw)(b, (void *)b, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(psignd, fuzz) { - int i, j; - int32_t x[4], y[4], a[4], b[4]; - for (i = 0; i < 100; ++i) { - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - psignd(a, x, y); - (psignd)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - psignd(a, (void *)a, y); - (psignd)(b, (void *)b, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(psignd, testBane) { - int32_t x[4] = {INT_MIN, INT_MIN, INT_MIN, INT_MIN}; - int32_t y[4] = {0, 1, -1, INT_MIN}; - psignd(x, x, y); - EXPECT_EQ(0, x[0]); - EXPECT_EQ(INT_MIN, x[1]); - EXPECT_EQ(INT_MIN, x[2]); - EXPECT_EQ(INT_MIN, x[3]); -} - -TEST(paddb, fuzz) { - int i, j; - int8_t x[16], y[16], a[16], b[16]; - for (i = 0; i < 100; ++i) { - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - paddb(a, x, y); - (paddb)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - paddb(a, (void *)a, y); - (paddb)(b, (void *)b, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(paddsb, fuzz) { - int i, j; - int8_t x[16], y[16], a[16], b[16]; - for (i = 0; i < 100; ++i) { - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - paddsb(a, x, y); - (paddsb)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - paddsb(a, (void *)a, y); - (paddsb)(b, (void *)b, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(paddsw, fuzz) { - int i, j; - int16_t x[8], y[8], a[8], b[8]; - for (i = 0; i < 100; ++i) { - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - paddsw(a, x, y); - (paddsw)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - paddsw(a, (void *)a, y); - (paddsw)(b, (void *)b, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(psubsb, fuzz) { - int i, j; - int8_t x[16], y[16], a[16], b[16]; - for (i = 0; i < 100; ++i) { - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - psubsb(a, x, y); - (psubsb)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - psubsb(a, (void *)a, y); - (psubsb)(b, (void *)b, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(psubsw, fuzz) { - int i, j; - int16_t x[8], y[8], a[8], b[8]; - for (i = 0; i < 100; ++i) { - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - psubsw(a, x, y); - (psubsw)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - psubsw(a, (void *)a, y); - (psubsw)(b, (void *)b, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(paddd, fuzz) { - int i, j; - uint32_t x[4], y[4], a[4], b[4]; - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - x[0] = 0x7fffffff; - y[0] = 0x7fffffff; - (paddd)(b, x, y); - for (i = 0; i < 100; ++i) { - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - paddd(a, x, y); - (paddd)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - paddd(a, (void *)a, y); - (paddd)(b, (void *)b, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(pshufb, fuzz) { - int i, j; - uint8_t x[16], y[16], a[16], b[16]; - for (i = 0; i < 100; ++i) { - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - pshufb(a, x, y); - (pshufb)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - pshufb(a, (void *)a, y); - (pshufb)(b, (void *)b, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(pshufd, fuzz) { - int i, j; - int32_t x[4], a[4], b[4]; - for (i = 0; i < 100; ++i) { - for (j = 0; j < 4; ++j) x[j] = Rando(); -#define T(IMM) \ - pshufd(a, x, IMM); \ - (pshufd)(b, x, IMM); \ - ASSERT_EQ(0, memcmp(a, b, 16)); \ - pshufd(a, (void *)a, IMM); \ - (pshufd)(b, (void *)b, IMM); \ - ASSERT_EQ(0, memcmp(a, b, 16)) - T(0b00000011); - T(0b00000110); - T(0b00001100); - T(0b00011000); - T(0b00110000); - T(0b01100000); - T(0b11000000); - T(0b10000000); -#undef T - } -} - -TEST(pshuflw, fuzz) { - int i, j; - int16_t x[8], a[8], b[8]; - for (i = 0; i < 100; ++i) { - for (j = 0; j < 8; ++j) x[j] = Rando(); -#define T(IMM) \ - pshuflw(a, x, IMM); \ - (pshuflw)(b, x, IMM); \ - ASSERT_EQ(0, memcmp(a, b, 16)); \ - pshuflw(a, (void *)a, IMM); \ - (pshuflw)(b, (void *)b, IMM); \ - ASSERT_EQ(0, memcmp(a, b, 16)) - T(0b00000011); - T(0b00000110); - T(0b00001100); - T(0b00011000); - T(0b00110000); - T(0b01100000); - T(0b11000000); - T(0b10000000); -#undef T - } -} - -TEST(pshufhw, fuzz) { - int i, j; - int16_t x[8], a[8], b[8]; - for (i = 0; i < 100; ++i) { - for (j = 0; j < 8; ++j) x[j] = Rando(); -#define T(IMM) \ - pshufhw(a, x, IMM); \ - (pshufhw)(b, x, IMM); \ - ASSERT_EQ(0, memcmp(a, b, 16)); \ - pshufhw(a, (void *)a, IMM); \ - (pshufhw)(b, (void *)b, IMM); \ - ASSERT_EQ(0, memcmp(a, b, 16)) - T(0b00000011); - T(0b00000110); - T(0b00001100); - T(0b00011000); - T(0b00110000); - T(0b01100000); - T(0b11000000); - T(0b10000000); -#undef T - } -} - -TEST(packuswb, test) { - const short S[8] = {0, 128, -128, 255, SHRT_MAX, SHRT_MIN, 0, 0}; - unsigned char B[16] = {0}; - packuswb(B, S, S); - ASSERT_EQ(0, B[0]); - ASSERT_EQ(128, B[1]); - ASSERT_EQ(0, B[2]); - ASSERT_EQ(255, B[3]); - ASSERT_EQ(255, B[4]); - ASSERT_EQ(0, B[5]); - ASSERT_EQ(0, B[6]); - ASSERT_EQ(0, B[7]); - ASSERT_EQ(0, B[8]); - ASSERT_EQ(128, B[9]); - ASSERT_EQ(0, B[10]); - ASSERT_EQ(255, B[11]); - ASSERT_EQ(255, B[12]); - ASSERT_EQ(0, B[13]); - ASSERT_EQ(0, B[14]); - ASSERT_EQ(0, B[15]); -} - -TEST(packsswb, test) { - const short S[8] = {0, 128, -128, 255, SHRT_MAX, SHRT_MIN, 0, 0}; - signed char B[16] = {0}; - packsswb(B, S, S); - ASSERT_EQ(0, B[0]); - ASSERT_EQ(127, B[1]); - ASSERT_EQ(-128, B[2]); - ASSERT_EQ(127, B[3]); - ASSERT_EQ(127, B[4]); - ASSERT_EQ(-128, B[5]); - ASSERT_EQ(0, B[6]); - ASSERT_EQ(0, B[7]); - ASSERT_EQ(0, B[8]); - ASSERT_EQ(127, B[9]); - ASSERT_EQ(-128, B[10]); - ASSERT_EQ(127, B[11]); - ASSERT_EQ(127, B[12]); - ASSERT_EQ(-128, B[13]); - ASSERT_EQ(0, B[14]); - ASSERT_EQ(0, B[15]); -} - -TEST(packssdw, testAlias) { - int i, j; - union { - int16_t out[8]; - int32_t in1[4]; - } u; - int16_t a[8], b[8]; - int32_t x[4], y[4]; - for (i = 0; i < 100; ++i) { - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - memcpy(u.in1, x, sizeof(x)); - packssdw(u.out, u.in1, y); - memcpy(a, u.out, sizeof(u.out)); - memcpy(u.in1, x, sizeof(x)); - (packssdw)(u.out, u.in1, y); - memcpy(b, u.out, sizeof(u.out)); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(packusdw, test) { - int i, j; - int32_t x[4], y[4]; - uint16_t a[8], b[8]; - for (i = 0; i < 100; ++i) { - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - packusdw(a, x, y); - (packusdw)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(packuswb, fuzz) { - int i, j; - int16_t x[8], y[8]; - uint8_t a[16], b[16]; - for (i = 0; i < 100; ++i) { - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - packuswb(a, x, y); - (packuswb)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - packuswb(a, x, x); - (packuswb)(b, x, x); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(packssdw, test) { - int i, j; - int32_t x[4], y[4]; - int16_t a[8], b[8]; - for (i = 0; i < 100; ++i) { - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - packssdw(a, x, y); - (packssdw)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(psllwv, fuzz) { - int i, j; - uint64_t y[2]; - uint16_t x[8], a[8], b[8]; - for (i = 0; i < 100; ++i) { - for (j = 0; j < 8; ++j) x[j] = Rando(); - for (j = 0; j < 2; ++j) y[j] = Rando() % 64; - psllwv(a, x, y); - (psllwv)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - psllwv(a, (void *)a, y); - (psllwv)(b, (void *)b, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(pslldv, fuzz) { - int i, j; - uint64_t y[2]; - uint32_t x[4], a[4], b[4]; - for (i = 0; i < 100; ++i) { - for (j = 0; j < 4; ++j) x[j] = Rando(); - for (j = 0; j < 2; ++j) y[j] = Rando() % 64; - pslldv(a, x, y); - (pslldv)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - pslldv(a, (void *)a, y); - (pslldv)(b, (void *)b, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(psllqv, fuzz) { - int i, j; - uint64_t y[2]; - uint64_t x[2], a[2], b[2]; - for (i = 0; i < 100; ++i) { - for (j = 0; j < 2; ++j) x[j] = Rando(); - for (j = 0; j < 2; ++j) y[j] = Rando() % 64; - psllqv(a, x, y); - (psllqv)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - psllqv(a, (void *)a, y); - (psllqv)(b, (void *)b, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(psrlwv, fuzz) { - int i, j; - uint64_t y[2]; - uint16_t x[8], a[8], b[8]; - for (i = 0; i < 100; ++i) { - for (j = 0; j < 8; ++j) x[j] = Rando(); - for (j = 0; j < 2; ++j) y[j] = Rando() % 64; - psrlwv(a, x, y); - (psrlwv)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - psrlwv(a, (void *)a, y); - (psrlwv)(b, (void *)b, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(psrldv, fuzz) { - int i, j; - uint64_t y[2]; - uint32_t x[4], a[4], b[4]; - for (i = 0; i < 100; ++i) { - for (j = 0; j < 4; ++j) x[j] = Rando(); - for (j = 0; j < 2; ++j) y[j] = Rando() % 64; - psrldv(a, x, y); - (psrldv)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - psrldv(a, (void *)a, y); - (psrldv)(b, (void *)b, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(psrlqv, fuzz) { - int i, j; - uint64_t y[2]; - uint64_t x[2], a[2], b[2]; - for (i = 0; i < 100; ++i) { - for (j = 0; j < 2; ++j) x[j] = Rando(); - for (j = 0; j < 2; ++j) y[j] = Rando() % 64; - psrlqv(a, x, y); - (psrlqv)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - psrlqv(a, (void *)a, y); - (psrlqv)(b, (void *)b, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(psrawv, fuzz) { - int i, j; - uint64_t y[2]; - int16_t x[8], a[8], b[8]; - for (i = 0; i < 100; ++i) { - for (j = 0; j < 8; ++j) x[j] = Rando(); - for (j = 0; j < 2; ++j) y[j] = Rando() % 64; - psrawv(a, x, y); - (psrawv)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - psrawv(a, (void *)a, y); - (psrawv)(b, (void *)b, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(psradv, fuzz) { - int i, j; - uint64_t y[2]; - int32_t x[4], a[4], b[4]; - for (i = 0; i < 100; ++i) { - for (j = 0; j < 4; ++j) x[j] = Rando(); - for (j = 0; j < 2; ++j) y[j] = Rando() % 64; - psradv(a, x, y); - (psradv)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - psradv(a, (void *)a, y); - (psradv)(b, (void *)b, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -// // TODO(jart): Fix me. on low power cpus. -// TEST(psrldq, fuzz) { -// int i, n; -// uint8_t x[16], a[16], b[16]; -// for (i = 0; i < 100; ++i) { -// memset(a, -1, sizeof(a)); -// memset(b, -1, sizeof(b)); -// RngSet(x, sizeof(x)); -// n = Rando() % 20; -// psrldq(a, x, n); -// (psrldq)(b, x, n); -// ASSERT_EQ(0, memcmp(a, b, 16), "%d\n\t%#.16hhs\n\t%#.16hhs\n\t%#.16hhs", -// n, x, a, b); -// n = Rando() % 20; -// psrldq(a, a, n); -// (psrldq)(b, b, n); -// ASSERT_EQ(0, memcmp(a, b, 16), "%d\n\t%#.16hhs\n\t%#.16hhs\n\t%#.16hhs", -// n, x, a, b); -// } -// } - -TEST(pslldq, fuzz) { - int i, n; - uint8_t x[16], a[16], b[16]; - for (i = 0; i < 100; ++i) { - memset(a, -1, sizeof(a)); - memset(b, -1, sizeof(b)); - RngSet(x, sizeof(x)); - n = Rando() % 20; - pslldq(a, x, n); - (pslldq)(b, x, n); - ASSERT_EQ(0, memcmp(a, b, 16), "%d\n\t%#.16hhs\n\t%#.16hhs\n\t%#.16hhs", n, - x, a, b); - n = Rando() % 20; - pslldq(a, a, n); - (pslldq)(b, b, n); - ASSERT_EQ(0, memcmp(a, b, 16), "%d\n\t%#.16hhs\n\t%#.16hhs\n\t%#.16hhs", n, - x, a, b); - } -} - -TEST(psadbw, test) { - int i, j; - uint64_t a[2], b[2]; - uint8_t x[16], y[16]; - for (i = 0; i < 100; ++i) { - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - psadbw(a, x, y); - (psadbw)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(pmulhrsw, fuzz) { - int i, j; - int16_t x[8], y[8], a[8], b[8]; - for (i = 0; i < 1000; ++i) { - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - pmulhrsw(a, x, y); - (pmulhrsw)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - pmulhrsw(a, (void *)a, y); - (pmulhrsw)(b, (void *)b, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(mpsadbw, fuzz) { - int i, j; - uint16_t a[8], b[8]; - uint8_t x[16], y[16]; - for (i = 0; i < 100; ++i) { - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - for (j = 0; j < 8; ++j) { - mpsadbw(a, x, y, j); - (mpsadbw)(b, x, y, j); - ASSERT_EQ(0, memcmp(a, b, 16), "%d %d", i, j); - } - } -} - -TEST(pmaddubsw, fuzz) { - int i, j; - int8_t y[16]; - uint8_t x[16]; - int16_t a[8], b[8]; - for (i = 0; i < 1000; ++i) { - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - pmaddubsw(a, x, y); - (pmaddubsw)(b, x, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - pmaddubsw(a, (void *)a, y); - (pmaddubsw)(b, (void *)b, y); - ASSERT_EQ(0, memcmp(a, b, 16)); - } -} - -TEST(pshufw, fuzz) { - int i, j; - uint8_t y; - int16_t x[4], a[4], b[4]; - for (i = 0; i < 100; ++i) { - for (j = 0; j < 4; ++j) x[j] = Rando(); - pshufw(a, x, 0b10111111); - (pshufw)(b, x, 0b10111111); - ASSERT_EQ(0, memcmp(a, b, 8)); - pshufw(a, (void *)a, 0b10111111); - (pshufw)(b, (void *)b, 0b10111111); - ASSERT_EQ(0, memcmp(a, b, 8)); - pshufw(a, x, 0b00001000); - (pshufw)(b, x, 0b00001000); - ASSERT_EQ(0, memcmp(a, b, 8)); - pshufw(a, x, 0b00010001); - (pshufw)(b, x, 0b00010001); - ASSERT_EQ(0, memcmp(a, b, 8)); - pshufw(a, x, 0b01110100); - (pshufw)(b, x, 0b01110100); - ASSERT_EQ(0, memcmp(a, b, 8)); - pshufw(a, x, 0b01101101); - (pshufw)(b, x, 0b01101101); - ASSERT_EQ(0, memcmp(a, b, 8)); - pshufw(a, x, 0b10011011); - (pshufw)(b, x, 0b10011011); - ASSERT_EQ(0, memcmp(a, b, 8)); - pshufw(a, x, 0b10111000); - (pshufw)(b, x, 0b10111000); - ASSERT_EQ(0, memcmp(a, b, 8)); - pshufw(a, x, 0b11000111); - (pshufw)(b, x, 0b11000111); - ASSERT_EQ(0, memcmp(a, b, 8)); - } -} - -TEST(pcmpeqw, test2) { - int16_t kNumbers16[] = {0, 1, 2, 123, 0xffff, 0xfffe, 0x8000, 0x8001, 0x8080}; - int i, j, k; - int16_t a[8], b[8], x[8], y[8]; - for (i = 0; i < ARRAYLEN(kNumbers16); ++i) { - for (j = 0; j < ARRAYLEN(kNumbers16); ++j) { - for (k = 0; k < 8; ++k) { - x[k] = kNumbers16[(i + k) % ARRAYLEN(kNumbers16)]; - y[k] = kNumbers16[(j + k) % ARRAYLEN(kNumbers16)]; - } - pcmpeqw(a, x, y); - (pcmpeqw)(b, x, y); - EXPECT_EQ(0, memcmp(a, b, 16)); - } - } -} - -TEST(pdep, fuzz) { - int i; - uint64_t x, y; - for (i = 0; i < 1000; ++i) { - x = _rand64(); - y = _rand64(); - ASSERT_EQ(pdep(x, y), (pdep)(x, y)); - } -} - -TEST(pext, fuzz) { - int i; - uint64_t x, y; - for (i = 0; i < 1000; ++i) { - x = _rand64(); - y = _rand64(); - ASSERT_EQ(pext(x, y), (pext)(x, y)); - } -} - -TEST(palignr, fuzz) { - int i, imm; - int8_t x[16], y[16], a[16], b[16]; - for (i = 0; i < 50; ++i) { - for (imm = 0; imm < 32; ++imm) { - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - memcpy(a, x, 16); - memcpy(b, y, 16); - palignr(a, a, b, imm); - (palignr)(x, x, y, imm); - ASSERT_EQ(0, memcmp(a, x, 16)); - ASSERT_EQ(0, memcmp(b, y, 16)); - } - } -} - -TEST(shufps, fuzz) { - int i, imm; - char x[16], y[16], a[16], b[16]; - for (i = 0; i < 20; ++i) { - for (imm = 0; imm < 256; ++imm) { - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - memcpy(a, x, 16); - memcpy(b, y, 16); - shufps((void *)a, (void *)a, (void *)b, imm); - (shufps)((void *)x, (void *)x, (void *)y, imm); - ASSERT_EQ(0, memcmp(a, x, 16)); - ASSERT_EQ(0, memcmp(b, y, 16)); - } - } -} - -TEST(shufpd, fuzz) { - int i, imm; - char x[16], y[16], a[16], b[16]; - for (i = 0; i < 20; ++i) { - for (imm = 0; imm < 256; ++imm) { - RngSet(x, sizeof(x)); - RngSet(y, sizeof(y)); - memcpy(a, x, 16); - memcpy(b, y, 16); - shufpd((void *)a, (void *)a, (void *)b, imm); - (shufpd)((void *)x, (void *)x, (void *)y, imm); - ASSERT_EQ(0, memcmp(a, x, 16), - "imm=%d\n\t" - "a=%.*hhs\n\t" - "x=%.*hhs", - imm, 16, a, 16, x); - ASSERT_EQ(0, memcmp(b, y, 16), "imm=%d", imm); - } - } -} diff --git a/test/libc/intrin/lock_test.c b/test/libc/intrin/lock_test.c index f388b25df..45188ccb4 100644 --- a/test/libc/intrin/lock_test.c +++ b/test/libc/intrin/lock_test.c @@ -25,7 +25,6 @@ #include "libc/intrin/atomic.h" #include "libc/intrin/kprintf.h" #include "libc/intrin/weaken.h" -#include "libc/runtime/clone.internal.h" #include "libc/runtime/internal.h" #include "libc/runtime/runtime.h" #include "libc/runtime/stack.h" diff --git a/test/libc/intrin/palignr_test.c b/test/libc/intrin/palignr_test.c deleted file mode 100644 index b7ddce936..000000000 --- a/test/libc/intrin/palignr_test.c +++ /dev/null @@ -1,221 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/palignr.h" -#include "libc/stdio/rand.h" -#include "libc/testlib/ezbench.h" -#include "libc/testlib/testlib.h" - -TEST(palignr, testLeftpad) { - const int A[4] = {1, 2, 3, 4}; - const int B[4] = {5, 6, 7, 8}; - int C[4] = {0}; - palignr(C, B, A, 12); - ASSERT_EQ(4, C[0]); - ASSERT_EQ(5, C[1]); - ASSERT_EQ(6, C[2]); - ASSERT_EQ(7, C[3]); -} - -TEST(palignr, testLeftpad_variableImmediate) { - const int A[4] = {1, 2, 3, 4}; - const int B[4] = {5, 6, 7, 8}; - int C[4] = {0}; - palignr(C, B, A, VEIL("r", 12)); - ASSERT_EQ(4, C[0]); - ASSERT_EQ(5, C[1]); - ASSERT_EQ(6, C[2]); - ASSERT_EQ(7, C[3]); -} - -TEST(palignr, test0) { - const int A[4] = {1, 2, 3, 4}; - const int B[4] = {5, 6, 7, 8}; - int C[4]; - palignr(C, B, A, 0); - ASSERT_EQ(1, C[0]); - ASSERT_EQ(2, C[1]); - ASSERT_EQ(3, C[2]); - ASSERT_EQ(4, C[3]); -} - -TEST(palignr, test4) { - const int A[4] = {1, 2, 3, 4}; - const int B[4] = {5, 6, 7, 8}; - int C[4]; - palignr(C, B, A, 4); - ASSERT_EQ(2, C[0]); - ASSERT_EQ(3, C[1]); - ASSERT_EQ(4, C[2]); - ASSERT_EQ(5, C[3]); -} - -TEST(palignr, test12) { - const int A[4] = {1, 2, 3, 4}; - const int B[4] = {5, 6, 7, 8}; - int C[4]; - palignr(C, B, A, 12); - ASSERT_EQ(4, C[0]); - ASSERT_EQ(5, C[1]); - ASSERT_EQ(6, C[2]); - ASSERT_EQ(7, C[3]); -} - -TEST(palignr, test16) { - const int A[4] = {1, 2, 3, 4}; - const int B[4] = {5, 6, 7, 8}; - int C[4]; - palignr(C, B, A, 16); - ASSERT_EQ(5, C[0]); - ASSERT_EQ(6, C[1]); - ASSERT_EQ(7, C[2]); - ASSERT_EQ(8, C[3]); -} - -TEST(palignr, test20) { - const int A[4] = {1, 2, 3, 4}; - const int B[4] = {5, 6, 7, 8}; - int C[4] = {-1, -1, -1, -1}; - palignr(C, B, A, 20); - ASSERT_EQ(6, C[0]); - ASSERT_EQ(7, C[1]); - ASSERT_EQ(8, C[2]); - ASSERT_EQ(0, C[3]); -} - -TEST(palignrc, testLeftpad) { - const int A[4] = {1, 2, 3, 4}; - const int B[4] = {5, 6, 7, 8}; - int C[4] = {0}; - (palignr)(C, B, A, 12); - ASSERT_EQ(4, C[0]); - ASSERT_EQ(5, C[1]); - ASSERT_EQ(6, C[2]); - ASSERT_EQ(7, C[3]); -} - -TEST(palignrc, testLeftpad_variableImmediate) { - const int A[4] = {1, 2, 3, 4}; - const int B[4] = {5, 6, 7, 8}; - int C[4] = {0}; - (palignr)(C, B, A, VEIL("r", 12)); - ASSERT_EQ(4, C[0]); - ASSERT_EQ(5, C[1]); - ASSERT_EQ(6, C[2]); - ASSERT_EQ(7, C[3]); -} - -TEST(palignrc, test0) { - const int A[4] = {1, 2, 3, 4}; - const int B[4] = {5, 6, 7, 8}; - int C[4]; - (palignr)(C, B, A, 0); - ASSERT_EQ(1, C[0]); - ASSERT_EQ(2, C[1]); - ASSERT_EQ(3, C[2]); - ASSERT_EQ(4, C[3]); -} - -TEST(palignrc, test4) { - const int A[4] = {1, 2, 3, 4}; - const int B[4] = {5, 6, 7, 8}; - int C[4]; - (palignr)(C, B, A, 4); - ASSERT_EQ(2, C[0]); - ASSERT_EQ(3, C[1]); - ASSERT_EQ(4, C[2]); - ASSERT_EQ(5, C[3]); -} - -TEST(palignrc, test12) { - const int A[4] = {1, 2, 3, 4}; - const int B[4] = {5, 6, 7, 8}; - int C[4]; - (palignr)(C, B, A, 12); - ASSERT_EQ(4, C[0]); - ASSERT_EQ(5, C[1]); - ASSERT_EQ(6, C[2]); - ASSERT_EQ(7, C[3]); -} - -TEST(palignrc, test16) { - const int A[4] = {1, 2, 3, 4}; - const int B[4] = {5, 6, 7, 8}; - int C[4]; - (palignr)(C, B, A, 16); - ASSERT_EQ(5, C[0]); - ASSERT_EQ(6, C[1]); - ASSERT_EQ(7, C[2]); - ASSERT_EQ(8, C[3]); -} - -TEST(palignrc, test20) { - const int A[4] = {1, 2, 3, 4}; - const int B[4] = {5, 6, 7, 8}; - int C[4] = {-1, -1, -1, -1}; - (palignr)(C, B, A, 20); - ASSERT_EQ(6, C[0]); - ASSERT_EQ(7, C[1]); - ASSERT_EQ(8, C[2]); - ASSERT_EQ(0, C[3]); -} - -TEST(palignr, test32orHigher_clearsOutput) { - const int A[4] = {1, 2, 3, 4}; - const int B[4] = {5, 6, 7, 8}; - int C[4] = {-1, -1, -1, -1}; - palignr(C, B, A, 32); - ASSERT_EQ(0, C[0]); - ASSERT_EQ(0, C[1]); - ASSERT_EQ(0, C[2]); - ASSERT_EQ(0, C[3]); - C[0] = 43; - palignr(C, B, A, 123); - ASSERT_EQ(0, C[0]); - ASSERT_EQ(0, C[1]); - ASSERT_EQ(0, C[2]); - ASSERT_EQ(0, C[3]); -} - -TEST(palignrv, test32orHigher_clearsOutput) { - const int A[4] = {1, 2, 3, 4}; - const int B[4] = {5, 6, 7, 8}; - int C[4] = {-1, -1, -1, -1}; - palignr(C, B, A, VEIL("r", 32)); - ASSERT_EQ(0, C[0]); - ASSERT_EQ(0, C[1]); - ASSERT_EQ(0, C[2]); - ASSERT_EQ(0, C[3]); - C[0] = 43; - palignr(C, B, A, VEIL("r", 123)); - ASSERT_EQ(0, C[0]); - ASSERT_EQ(0, C[1]); - ASSERT_EQ(0, C[2]); - ASSERT_EQ(0, C[3]); -} - -TEST(palignrc, test32orHigher_clearsOutput) { - const int A[4] = {1, 2, 3, 4}; - const int B[4] = {5, 6, 7, 8}; - int C[4] = {-1, -1, -1, -1}; - (palignr)(C, B, A, 32); - ASSERT_EQ(0, C[0]); - ASSERT_EQ(0, C[1]); - ASSERT_EQ(0, C[2]); - ASSERT_EQ(0, C[3]); -} diff --git a/test/libc/intrin/pmulhrsw_test.c b/test/libc/intrin/pmulhrsw_test.c deleted file mode 100644 index 1cd8a60a2..000000000 --- a/test/libc/intrin/pmulhrsw_test.c +++ /dev/null @@ -1,134 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/pmulhrsw.h" -#include "dsp/core/q.h" -#include "libc/log/check.h" -#include "libc/macros.internal.h" -#include "libc/str/str.h" -#include "libc/testlib/testlib.h" -#include "tool/viz/lib/formatstringtable-testlib.h" - -#define ACCURACY powf(10, -4) - -#define FOR8(STMT) \ - for (y = 0; y < 8; ++y) { \ - STMT; \ - } - -#define FOR88(STMT) \ - for (y = 0; y < 8; ++y) { \ - for (x = 0; x < 8; ++x) { \ - STMT; \ - } \ - } - -FIXTURE(pmulhrsw, disableHardwareExtensions) { -#ifdef __x86_64__ - memset((/*unconst*/ void *)kCpuids, 0, sizeof(kCpuids)); -#endif -} - -TEST(pmulhrsw, testLimits) { - int i; - short A[8], B[8]; - const short kPmulhrswTorture[][3] = { - {SHRT_MIN, SHRT_MIN, SHRT_MIN}, - {SHRT_MIN, -1, 1}, - {SHRT_MIN, 0, 0}, - {SHRT_MIN, 1, -1}, - {-1, SHRT_MIN, 1}, - {-1, -1, 0}, - {-1, 0, 0}, - {-1, 1, 0}, - {-1, SHRT_MAX, -1}, - {0, SHRT_MIN, 0}, - {0, -1, 0}, - {0, 0, 0}, - {0, 1, 0}, - {0, SHRT_MAX, 0}, - {1, SHRT_MIN, -1}, - {1, -1, 0}, - {1, 0, 0}, - {1, 1, 0}, - {1, SHRT_MAX, 1}, - {SHRT_MAX, -1, -1}, - {SHRT_MAX, 0, 0}, - {SHRT_MAX, 1, 1}, - }; - memset(A, 0, sizeof(A)); - memset(B, 0, sizeof(B)); - for (i = 0; i < ARRAYLEN(kPmulhrswTorture); ++i) { - A[0] = kPmulhrswTorture[i][0]; - B[0] = kPmulhrswTorture[i][1]; - pmulhrsw(A, A, B); - EXPECT_EQ(kPmulhrswTorture[i][2], A[0], "pmulhrsw(%hd,%hd)→%hd", - kPmulhrswTorture[i][0], kPmulhrswTorture[i][1], A[0]); - } - for (i = 0; i < ARRAYLEN(kPmulhrswTorture); ++i) { - A[0] = kPmulhrswTorture[i][0]; - B[0] = kPmulhrswTorture[i][1]; - (pmulhrsw)(A, A, B); - EXPECT_EQ(kPmulhrswTorture[i][2], A[0], "pmulhrsw(%hd,%hd)→%hd", - kPmulhrswTorture[i][0], kPmulhrswTorture[i][1], A[0]); - } -} - -TEST(pmulhrsw, testFakeFloat) { - int y, x; - float R[8][8]; - float Q[8][8]; - short QQ[8][8]; - short QD[8][8]; - short QM[8][8]; - float D[8][8] = /* clang-format off */ { - {.929142, .147545, .17061, .765948, .874296, .925816, .073955, .10664}, - {.986743, .311924, .550892, .789301, .873408, .743376, .434021, .143184}, - {.405694, .080979, .894841, .625169, .465688, .877854, .97371, .264295}, - {.781549, .20985, .599735, .943491, .059135, .045806, .770352, .081862}, - {.584684, .701568, .022328, .177048, .412809, .185355, .992654, .252167}, - {.327565, .693878, .722431, .84546, .060729, .383725, .589365, .435534}, - {.942854, .62579, .177928, .809653, .143087, .624792, .851914, .072192}, - {.750157, .968502, .270052, .087784, .406716, .510766, .959699, .416836}, - }; - float M[8][8] = { - {.009407, .882863, .000511, .565419, .69844, .035758, .817049, .249922}, - {.072144, .703228, .479622, .121608, .288279, .55492, .387912, .140278}, - {.047205, .748263, .683692, .805669, .137764, .858753, .787804, .059591}, - {.682286, .787778, .503573, .473795, .437378, .573171, .135995, .341236}, - {.588849, .723929, .624155, .710336, .480396, .462433, .865392, .071378}, - {.598636, .575209, .758356, .518674, .043861, .542574, .355843, .02014}, - {.359636, .95607, .698256, .492859, .149454, .795121, .790219, .357014}, - {.401603, .928426, .416429, .11747, .643411, .907285, .074102, .411959}, - } /* clang-format on */; - FOR88(QD[y][x] = F2Q(15, D[y][x])); - FOR88(QM[y][x] = F2Q(15, M[y][x])); - /* for (y = 0; y < 8; ++y) { */ - /* for (x = 0; x < 8; ++x) { */ - /* CHECK_NE(8, x); */ - /* CHECK_NE(8, y); */ - /* QM[y][x] = F2Q(15, M[y][x]); */ - /* CHECK_NE(8, x); */ - /* CHECK_NE(8, y); */ - /* } */ - /* } */ - FOR8(pmulhrsw(QQ[y], QD[y], QM[y])); - FOR88(Q[y][x] = Q2F(15, QQ[y][x])); - FOR88(R[y][x] = D[y][x] * M[y][x]); - FOR88(EXPECT_TRUE(ACCURACY > Q[y][x] - R[y][x])); -} diff --git a/test/libc/intrin/pshuf_test.c b/test/libc/intrin/pshuf_test.c deleted file mode 100644 index de707e056..000000000 --- a/test/libc/intrin/pshuf_test.c +++ /dev/null @@ -1,161 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│ -│vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2020 Justine Alexandra Roberts Tunney │ -│ │ -│ Permission to use, copy, modify, and/or distribute this software for │ -│ any purpose with or without fee is hereby granted, provided that the │ -│ above copyright notice and this permission notice appear in all copies. │ -│ │ -│ THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL │ -│ WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED │ -│ WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE │ -│ AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL │ -│ DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR │ -│ PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER │ -│ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ -│ PERFORMANCE OF THIS SOFTWARE. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/pshufd.h" -#include "libc/intrin/pshufhw.h" -#include "libc/intrin/pshuflw.h" -#include "libc/stdio/rand.h" -#include "libc/str/str.h" -#include "libc/testlib/testlib.h" - -#define T(f, m) \ - f(a, x, m); \ - (f)(b, x, m); \ - EXPECT_EQ(0, memcmp(a, b, 16)) - -TEST(pshuflw, test) { - int i, j; - int16_t x[8], a[8], b[8]; - for (i = 0; i < 10; ++i) { - for (j = 0; j < 8; ++j) x[j] = rand(); - T(pshuflw, 0b00000000); - T(pshuflw, 0b00000001); - T(pshuflw, 0b00000011); - T(pshuflw, 0b00001100); - T(pshuflw, 0b00001101); - T(pshuflw, 0b00001111); - T(pshuflw, 0b00110000); - T(pshuflw, 0b00110001); - T(pshuflw, 0b00110011); - T(pshuflw, 0b00111100); - T(pshuflw, 0b00111101); - T(pshuflw, 0b00111111); - T(pshuflw, 0b01000000); - T(pshuflw, 0b01000001); - T(pshuflw, 0b01000011); - T(pshuflw, 0b01001100); - T(pshuflw, 0b01001101); - T(pshuflw, 0b01001111); - T(pshuflw, 0b01110000); - T(pshuflw, 0b01110001); - T(pshuflw, 0b01110011); - T(pshuflw, 0b01111100); - T(pshuflw, 0b01111101); - T(pshuflw, 0b01111111); - T(pshuflw, 0b11000000); - T(pshuflw, 0b11000001); - T(pshuflw, 0b11000011); - T(pshuflw, 0b11001100); - T(pshuflw, 0b11001101); - T(pshuflw, 0b11001111); - T(pshuflw, 0b11110000); - T(pshuflw, 0b11110001); - T(pshuflw, 0b11110011); - T(pshuflw, 0b11111100); - T(pshuflw, 0b11111101); - T(pshuflw, 0b11111111); - } -} - -TEST(pshufhw, test) { - int i, j; - int16_t x[8], a[8], b[8]; - for (i = 0; i < 10; ++i) { - for (j = 0; j < 8; ++j) x[j] = rand(); - T(pshufhw, 0b00000000); - T(pshufhw, 0b00000001); - T(pshufhw, 0b00000011); - T(pshufhw, 0b00001100); - T(pshufhw, 0b00001101); - T(pshufhw, 0b00001111); - T(pshufhw, 0b00110000); - T(pshufhw, 0b00110001); - T(pshufhw, 0b00110011); - T(pshufhw, 0b00111100); - T(pshufhw, 0b00111101); - T(pshufhw, 0b00111111); - T(pshufhw, 0b01000000); - T(pshufhw, 0b01000001); - T(pshufhw, 0b01000011); - T(pshufhw, 0b01001100); - T(pshufhw, 0b01001101); - T(pshufhw, 0b01001111); - T(pshufhw, 0b01110000); - T(pshufhw, 0b01110001); - T(pshufhw, 0b01110011); - T(pshufhw, 0b01111100); - T(pshufhw, 0b01111101); - T(pshufhw, 0b01111111); - T(pshufhw, 0b11000000); - T(pshufhw, 0b11000001); - T(pshufhw, 0b11000011); - T(pshufhw, 0b11001100); - T(pshufhw, 0b11001101); - T(pshufhw, 0b11001111); - T(pshufhw, 0b11110000); - T(pshufhw, 0b11110001); - T(pshufhw, 0b11110011); - T(pshufhw, 0b11111100); - T(pshufhw, 0b11111101); - T(pshufhw, 0b11111111); - } -} - -TEST(pshufd, test) { - int i, j; - int32_t x[4], a[4], b[4]; - for (i = 0; i < 10; ++i) { - for (j = 0; j < 4; ++j) x[j] = rand(); - T(pshufd, 0b00000000); - T(pshufd, 0b00000001); - T(pshufd, 0b00000011); - T(pshufd, 0b00001100); - T(pshufd, 0b00001101); - T(pshufd, 0b00001111); - T(pshufd, 0b00110000); - T(pshufd, 0b00110001); - T(pshufd, 0b00110011); - T(pshufd, 0b00111100); - T(pshufd, 0b00111101); - T(pshufd, 0b00111111); - T(pshufd, 0b01000000); - T(pshufd, 0b01000001); - T(pshufd, 0b01000011); - T(pshufd, 0b01001100); - T(pshufd, 0b01001101); - T(pshufd, 0b01001111); - T(pshufd, 0b01110000); - T(pshufd, 0b01110001); - T(pshufd, 0b01110011); - T(pshufd, 0b01111100); - T(pshufd, 0b01111101); - T(pshufd, 0b01111111); - T(pshufd, 0b11000000); - T(pshufd, 0b11000001); - T(pshufd, 0b11000011); - T(pshufd, 0b11001100); - T(pshufd, 0b11001101); - T(pshufd, 0b11001111); - T(pshufd, 0b11110000); - T(pshufd, 0b11110001); - T(pshufd, 0b11110011); - T(pshufd, 0b11111100); - T(pshufd, 0b11111101); - T(pshufd, 0b11111111); - } -} diff --git a/test/libc/nexgen32e/lz4decode_test.c b/test/libc/nexgen32e/lz4decode_test.c index 87c405067..66a107327 100644 --- a/test/libc/nexgen32e/lz4decode_test.c +++ b/test/libc/nexgen32e/lz4decode_test.c @@ -16,16 +16,17 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/safemacros.internal.h" #include "libc/calls/calls.h" +#include "libc/intrin/safemacros.internal.h" #include "libc/log/check.h" +#include "libc/mem/gc.internal.h" #include "libc/mem/mem.h" #include "libc/nexgen32e/kompressor.h" #include "libc/nexgen32e/lz4.h" -#include "libc/runtime/ezmap.internal.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" #include "libc/testlib/testlib.h" +#include "libc/x/x.h" TEST(lz4, decompress_emptyStringWithoutChecksum) { /* lz4 -9 --content-size --no-frame-crc /tmp/empty - | hexdump -C */ @@ -72,25 +73,22 @@ TEST(lz4, decompress_runLengthDecode) { TEST(lz4, zoneFileGmt) { if (!fileexists("usr/share/zoneinfo.dict.lz4")) return; - struct MappedFile dict, gmt; - CHECK_NE(-1, MapFileRead("usr/share/zoneinfo.dict.lz4", &dict)); - CHECK_NE(-1, MapFileRead("usr/share/zoneinfo/GMT.lz4", &gmt)); + char *dict = gc(xslurp("usr/share/zoneinfo.dict.lz4", 0)); + char *gmt = gc(xslurp("usr/share/zoneinfo/GMT.lz4", 0)); size_t mapsize, gmtsize; char *mapping, *gmtdata; - lz4decode((gmtdata = lz4decode( - (mapping = _mapanon( - (mapsize = roundup( - LZ4_FRAME_BLOCKCONTENTSIZE(lz4check(dict.addr)) + - (gmtsize = LZ4_FRAME_BLOCKCONTENTSIZE( - lz4check(gmt.addr))), - FRAMESIZE)))), - dict.addr)), - gmt.addr); + lz4decode( + (gmtdata = lz4decode( + (mapping = _mapanon( + (mapsize = roundup( + LZ4_FRAME_BLOCKCONTENTSIZE(lz4check(dict)) + + (gmtsize = LZ4_FRAME_BLOCKCONTENTSIZE(lz4check(gmt))), + FRAMESIZE)))), + dict)), + gmt); ASSERT_BINEQ( u"TZif2                  ☺   ☺           ☺   ♦      GMT   TZif2   " u"               ☺   ☺       ☺   ☺   ♦°              GMT   ◙GMT0◙", gmtdata); munmap(mapping, mapsize); - UnmapFile(&dict); - UnmapFile(&gmt); } diff --git a/test/libc/thread/pthread_detach_test.c b/test/libc/thread/pthread_detach_test.c index baba21df9..28bd61f2a 100644 --- a/test/libc/thread/pthread_detach_test.c +++ b/test/libc/thread/pthread_detach_test.c @@ -25,7 +25,6 @@ #include "libc/testlib/testlib.h" #include "libc/thread/posixthread.internal.h" #include "libc/thread/thread.h" -#include "third_party/nsync/dll.h" void OnUsr1(int sig, struct siginfo *si, void *vctx) { struct ucontext *ctx = vctx; diff --git a/third_party/nsync/README.cosmo b/third_party/nsync/README.cosmo index c327a93f0..fc280d7ca 100644 --- a/third_party/nsync/README.cosmo +++ b/third_party/nsync/README.cosmo @@ -19,3 +19,5 @@ LOCAL CHANGES - nsync_mu_semaphore uses Cosmopolitan Futexes - block pthread cancellations in nsync_mu_lock_slow_ - support posix thread cancellations in nsync_cv_wait + - timespec api was so good that it's now part of libc + - linked list api was so good that it's now part of libc diff --git a/third_party/nsync/common.c b/third_party/nsync/common.c index 4845e8512..88c69db3d 100644 --- a/third_party/nsync/common.c +++ b/third_party/nsync/common.c @@ -15,6 +15,7 @@ │ See the License for the specific language governing permissions and │ │ limitations under the License. │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/intrin/dll.h" #include "libc/intrin/kmalloc.h" #include "libc/mem/mem.h" #include "libc/runtime/runtime.h" @@ -23,7 +24,6 @@ #include "third_party/nsync/atomic.h" #include "third_party/nsync/atomic.internal.h" #include "third_party/nsync/common.internal.h" -#include "third_party/nsync/dll.h" #include "third_party/nsync/mu_semaphore.h" #include "third_party/nsync/races.internal.h" #include "third_party/nsync/wait_s.internal.h" @@ -122,23 +122,24 @@ uint32_t nsync_spin_test_and_set_ (nsync_atomic_uint32_ *w, uint32_t test, /* ====================================================================================== */ -struct nsync_waiter_s *nsync_dll_nsync_waiter_ (nsync_dll_element_ *e) { - struct nsync_waiter_s *nw = (struct nsync_waiter_s *) e->container; +struct nsync_waiter_s *nsync_dll_nsync_waiter_ (struct Dll *e) { + struct nsync_waiter_s *nw = DLL_CONTAINER(struct nsync_waiter_s, q, e); ASSERT (nw->tag == NSYNC_WAITER_TAG); ASSERT (e == &nw->q); return (nw); } -waiter *nsync_dll_waiter_ (nsync_dll_element_ *e) { + +waiter *nsync_dll_waiter_ (struct Dll *e) { struct nsync_waiter_s *nw = DLL_NSYNC_WAITER (e); - waiter *w = CONTAINER (waiter, nw, nw); + waiter *w = DLL_CONTAINER (waiter, nw, nw); ASSERT ((nw->flags & NSYNC_WAITER_FLAG_MUCV) != 0); ASSERT (w->tag == WAITER_TAG); ASSERT (e == &w->nw.q); return (w); } -waiter *nsync_dll_waiter_samecond_ (nsync_dll_element_ *e) { - waiter *w = (waiter *) e->container; +waiter *nsync_dll_waiter_samecond_ (struct Dll *e) { + waiter *w = DLL_CONTAINER (struct waiter_s, same_condition, e); ASSERT (w->tag == WAITER_TAG); ASSERT (e == &w->same_condition); return (w); @@ -146,7 +147,7 @@ waiter *nsync_dll_waiter_samecond_ (nsync_dll_element_ *e) { /* -------------------------------- */ -static nsync_dll_list_ free_waiters = NULL; +static struct Dll *free_waiters = NULL; /* free_waiters points to a doubly-linked list of free waiter structs. */ static nsync_atomic_uint32_ free_waiters_mu; /* spinlock; protects free_waiters */ @@ -165,7 +166,7 @@ static void waiter_destroy (void *v) { ASSERT ((w->flags & (WAITER_RESERVED|WAITER_IN_USE)) == WAITER_RESERVED); w->flags &= ~WAITER_RESERVED; nsync_spin_test_and_set_ (&free_waiters_mu, 1, 1, 0); - free_waiters = nsync_dll_make_first_in_list_ (free_waiters, &w->nw.q); + dll_make_first (&free_waiters, &w->nw.q); ATM_STORE_REL (&free_waiters_mu, 0); /* release store */ IGNORE_RACES_END (); } @@ -173,7 +174,7 @@ static void waiter_destroy (void *v) { /* Return a pointer to an unused waiter struct. Ensures that the enclosed timer is stopped and its channel drained. */ waiter *nsync_waiter_new_ (void) { - nsync_dll_element_ *q; + struct Dll *q; waiter *tw; waiter *w; tw = waiter_for_thread; @@ -181,9 +182,9 @@ waiter *nsync_waiter_new_ (void) { if (w == NULL || (w->flags & (WAITER_RESERVED|WAITER_IN_USE)) != WAITER_RESERVED) { w = NULL; nsync_spin_test_and_set_ (&free_waiters_mu, 1, 1, 0); - q = nsync_dll_first_ (free_waiters); + q = dll_first (free_waiters); if (q != NULL) { /* If free list is non-empty, dequeue an item. */ - free_waiters = nsync_dll_remove_ (free_waiters, q); + dll_remove (&free_waiters, q); w = DLL_WAITER (q); } ATM_STORE_REL (&free_waiters_mu, 0); /* release store */ @@ -193,11 +194,11 @@ waiter *nsync_waiter_new_ (void) { w->nw.tag = NSYNC_WAITER_TAG; nsync_mu_semaphore_init (&w->sem); w->nw.sem = &w->sem; - nsync_dll_init_ (&w->nw.q, &w->nw); + dll_init (&w->nw.q); NSYNC_ATOMIC_UINT32_STORE_ (&w->nw.waiting, 0); w->nw.flags = NSYNC_WAITER_FLAG_MUCV; ATM_STORE (&w->remove_count, 0); - nsync_dll_init_ (&w->same_condition, w); + dll_init (&w->same_condition); w->flags = 0; } if (tw == NULL) { @@ -216,7 +217,7 @@ void nsync_waiter_free_ (waiter *w) { w->flags &= ~WAITER_IN_USE; if ((w->flags & WAITER_RESERVED) == 0) { nsync_spin_test_and_set_ (&free_waiters_mu, 1, 1, 0); - free_waiters = nsync_dll_make_first_in_list_ (free_waiters, &w->nw.q); + dll_make_first (&free_waiters, &w->nw.q); ATM_STORE_REL (&free_waiters_mu, 0); /* release store */ } } diff --git a/third_party/nsync/common.internal.h b/third_party/nsync/common.internal.h index fba32eb4f..113a9b909 100644 --- a/third_party/nsync/common.internal.h +++ b/third_party/nsync/common.internal.h @@ -1,10 +1,10 @@ #ifndef NSYNC_COMMON_H_ #define NSYNC_COMMON_H_ #include "libc/assert.h" +#include "libc/intrin/dll.h" #include "third_party/nsync/atomic.h" #include "third_party/nsync/atomic.internal.h" #include "third_party/nsync/cv.h" -#include "third_party/nsync/dll.h" #include "third_party/nsync/mu.h" #include "third_party/nsync/mu_semaphore.h" #include "third_party/nsync/note.h" @@ -101,9 +101,9 @@ void nsync_panic_(const char *s); #define MU_ALL_FALSE \ ((uint32_t)(1 << 7)) /* all waiter conditions are false \ */ -#define MU_RLOCK \ - ((uint32_t)( \ - 1 << 8)) /* low-order bit of reader count, which uses rest of word */ +#define MU_RLOCK \ + ((uint32_t)(1 << 8)) /* low-order bit of reader count, which uses rest of \ + word */ /* The constants below are derived from those above. */ #define MU_RLOCK_FIELD \ @@ -202,7 +202,7 @@ struct wait_condition_s { Remove *w from the relevant queue then: ATM_STORE_REL (&w.waiting, 0); nsync_mu_semaphore_v (&w.sem); */ -typedef struct { +typedef struct waiter_s { uint32_t tag; /* debug DLL_NSYNC_WAITER, DLL_WAITER, DLL_WAITER_SAMECOND */ int flags; /* see WAITER_* bits below */ nsync_semaphore sem; /* Thread waits on this semaphore. */ @@ -212,7 +212,7 @@ typedef struct { *l_type; /* Lock type of the mu, or nil if not associated with a mu. */ nsync_atomic_uint32_ remove_count; /* count of removals from queue */ struct wait_condition_s cond; /* A condition on which to acquire a mu. */ - nsync_dll_element_ same_condition; /* Links neighbours in nw.q with same + struct Dll same_condition; /* Links neighbours in nw.q with same non-nil condition. */ } waiter; static const uint32_t WAITER_TAG = 0x0590239f; @@ -222,28 +222,27 @@ static const uint32_t NSYNC_WAITER_TAG = 0x726d2ba9; 0x1 /* waiter reserved by a thread, even when not in use */ #define WAITER_IN_USE 0x2 /* waiter in use by a thread */ -#define CONTAINER(t_, f_, p_) ((t_ *)(((char *)(p_)) - offsetof(t_, f_))) - #define ASSERT(x) _npassert(x) -/* Return a pointer to the nsync_waiter_s containing nsync_dll_element_ *e. */ +/* Return a pointer to the nsync_waiter_s containing struct Dll *e. */ #define DLL_NSYNC_WAITER(e) \ (NSYNC_DEBUG ? nsync_dll_nsync_waiter_(e) \ - : ((struct nsync_waiter_s *)((e)->container))) -struct nsync_waiter_s *nsync_dll_nsync_waiter_(nsync_dll_element_ *e); + : DLL_CONTAINER(struct nsync_waiter_s, q, e)) +struct nsync_waiter_s *nsync_dll_nsync_waiter_(struct Dll *e); /* Return a pointer to the waiter struct that *e is embedded in, where *e is an * nw.q field. */ #define DLL_WAITER(e) \ (NSYNC_DEBUG ? nsync_dll_waiter_(e) \ - : CONTAINER(waiter, nw, DLL_NSYNC_WAITER(e))) -waiter *nsync_dll_waiter_(nsync_dll_element_ *e); + : DLL_CONTAINER(waiter, nw, DLL_NSYNC_WAITER(e))) +waiter *nsync_dll_waiter_(struct Dll *e); /* Return a pointer to the waiter struct that *e is embedded in, where *e is a same_condition field. */ -#define DLL_WAITER_SAMECOND(e) \ - (NSYNC_DEBUG ? nsync_dll_waiter_samecond_(e) : ((waiter *)((e)->container))) -waiter *nsync_dll_waiter_samecond_(nsync_dll_element_ *e); +#define DLL_WAITER_SAMECOND(e) \ + (NSYNC_DEBUG ? nsync_dll_waiter_samecond_(e) \ + : DLL_CONTAINER(struct waiter_s, same_condition, e)) +waiter *nsync_dll_waiter_samecond_(struct Dll *e); /* Return a pointer to an unused waiter struct. Ensures that the enclosed timer is stopped and its channel drained. */ @@ -257,8 +256,7 @@ void nsync_waiter_free_(waiter *w); /* The internals of an nync_note. See internal/note.c for details of locking discipline. */ struct nsync_note_s_ { - nsync_dll_element_ - parent_child_link; /* parent's children, under parent->note_mu */ + struct Dll parent_child_link; /* parent's children, under parent->note_mu */ int expiry_time_valid; /* whether expiry_time is valid; r/o after init */ nsync_time expiry_time; /* expiry time, if expiry_time_valid != 0; r/o after init */ @@ -267,8 +265,8 @@ struct nsync_note_s_ { uint32_t disconnecting; /* non-zero => node is being disconnected */ nsync_atomic_uint32_ notified; /* non-zero if the note has been notified */ struct nsync_note_s_ *parent; /* points to parent, if any */ - nsync_dll_element_ *children; /* list of children */ - nsync_dll_element_ *waiters; /* list of waiters */ + struct Dll *children; /* list of children */ + struct Dll *waiters; /* list of waiters */ }; /* ---------- */ @@ -276,10 +274,8 @@ struct nsync_note_s_ { void nsync_mu_lock_slow_(nsync_mu *mu, waiter *w, uint32_t clear, lock_type *l_type); void nsync_mu_unlock_slow_(nsync_mu *mu, lock_type *l_type); -nsync_dll_list_ nsync_remove_from_mu_queue_(nsync_dll_list_ mu_queue, - nsync_dll_element_ *e); -void nsync_maybe_merge_conditions_(nsync_dll_element_ *p, - nsync_dll_element_ *n); +struct Dll *nsync_remove_from_mu_queue_(struct Dll *mu_queue, struct Dll *e); +void nsync_maybe_merge_conditions_(struct Dll *p, struct Dll *n); nsync_time nsync_note_notified_deadline_(nsync_note n); int nsync_sem_wait_with_cancel_(waiter *w, nsync_time abs_deadline, nsync_note cancel_note); diff --git a/third_party/nsync/counter.h b/third_party/nsync/counter.h index 7828553e9..6441f9a39 100644 --- a/third_party/nsync/counter.h +++ b/third_party/nsync/counter.h @@ -5,8 +5,6 @@ #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ -struct nsync_dll_element_s_; - /* An nsync_counter represents an unsigned integer that can count up and down, and wake waiters when zero. */ typedef struct nsync_counter_s_ *nsync_counter; diff --git a/third_party/nsync/cv.h b/third_party/nsync/cv.h index d7456cbde..c3646e3d5 100644 --- a/third_party/nsync/cv.h +++ b/third_party/nsync/cv.h @@ -1,5 +1,6 @@ #ifndef NSYNC_CV_H_ #define NSYNC_CV_H_ +#include "libc/intrin/dll.h" #include "third_party/nsync/mu.h" #include "third_party/nsync/time.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) @@ -8,7 +9,6 @@ COSMOPOLITAN_C_START_ #define NSYNC_CV_INIT \ { NSYNC_ATOMIC_UINT32_INIT_, 0 } -struct nsync_dll_element_s_; struct nsync_note_s_; /* An nsync_cv is a condition variable in the style of Mesa, Java, @@ -92,7 +92,7 @@ typedef struct nsync_cv_s_ { /* see bits below */ nsync_atomic_uint32_ word; /* points to tail of list of waiters; under mu. */ - struct nsync_dll_element_s_ *waiters; + struct Dll *waiters; } nsync_cv; /* An nsync_cv should be zeroed to initialize, which can be accomplished diff --git a/third_party/nsync/dll.c b/third_party/nsync/dll.c deleted file mode 100644 index d5ff5e555..000000000 --- a/third_party/nsync/dll.c +++ /dev/null @@ -1,143 +0,0 @@ -/*-*- mode:c;indent-tabs-mode:t;c-basic-offset:8;tab-width:8;coding:utf-8 -*-│ -│vi: set et ft=c ts=8 tw=8 fenc=utf-8 :vi│ -╞══════════════════════════════════════════════════════════════════════════════╡ -│ Copyright 2016 Google Inc. │ -│ │ -│ Licensed under the Apache License, Version 2.0 (the "License"); │ -│ you may not use this file except in compliance with the License. │ -│ You may obtain a copy of the License at │ -│ │ -│ http://www.apache.org/licenses/LICENSE-2.0 │ -│ │ -│ Unless required by applicable law or agreed to in writing, software │ -│ distributed under the License is distributed on an "AS IS" BASIS, │ -│ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. │ -│ See the License for the specific language governing permissions and │ -│ limitations under the License. │ -╚─────────────────────────────────────────────────────────────────────────────*/ -#include "third_party/nsync/dll.h" - -asm(".ident\t\"\\n\\n\ -*NSYNC (Apache 2.0)\\n\ -Copyright 2016 Google, Inc.\\n\ -https://github.com/google/nsync\""); -// clang-format off - -/* Initialize *e. */ -void nsync_dll_init_ (nsync_dll_element_ *e, void *container) { - e->next = e; - e->prev = e; - e->container = container; -} - -/* Return whether list is empty. */ -int nsync_dll_is_empty_ (nsync_dll_list_ list) { - return (list == NULL); -} - -/* Remove *e from list, and returns the new list. */ -nsync_dll_list_ nsync_dll_remove_ (nsync_dll_list_ list, nsync_dll_element_ *e) { - if (list == e) { /* removing tail of list */ - if (list->prev == list) { - list = NULL; /* removing only element of list */ - } else { - list = list->prev; - } - } - e->next->prev = e->prev; - e->prev->next = e->next; - e->next = e; - e->prev = e; - return (list); -} - -/* Cause element *n and its successors to come after element *p. - Requires n and p are non-NULL and do not point at elements of the same list. - - Unlike the other operations in this API, this operation acts on - two circular lists of elements, rather than on a "head" location that points - to such a circular list. - - If the two lists are p->p_2nd->p_mid->p_last->p and n->n_2nd->n_mid->n_last->n, - then after nsync_dll_splice_after_ (p, n), the p list would be: - p->n->n_2nd->n_mid->n_last->p_2nd->p_mid->p_last->p. */ -void nsync_dll_splice_after_ (nsync_dll_element_ *p, nsync_dll_element_ *n) { - nsync_dll_element_ *p_2nd = p->next; - nsync_dll_element_ *n_last = n->prev; - p->next = n; /* n follows p */ - n->prev = p; - n_last->next = p_2nd; /* remainder of p-list follows last of n-list */ - p_2nd->prev = n_last; -} - -/* Make element *e the first element of list, and return - the list. The resulting list will have *e as its first element, followed by - any elements in the same list as *e, followed by the elements that were - previously in list. Requires that *e not be in list. If e==NULL, list is - returned unchanged. - - Suppose the e list is e->e_2nd->e_mid->e_last->e. - Recall that a head "list" points to the last element of its list. - If list is initially null, then the outcome is: - result = e_last->e->e_2nd->e_mid->e_last - If list is initially list->list_last->list_1st->list_mid->list_last, - then the outcome is: - result = list_last->e->e_2nd->e_mid->e_last->list_1st->list_mid->list_last - */ -nsync_dll_list_ nsync_dll_make_first_in_list_ (nsync_dll_list_ list, nsync_dll_element_ *e) { - if (e != NULL) { - if (list == NULL) { - list = e->prev; /*e->prev is e_last*/ - } else { - nsync_dll_splice_after_ (list, e); - } - } - return (list); -} - -/* Make element *e the last element of list, and return - the list. The resulting list will have *e as its last element, preceded by - any elements in the same list as *e, preceded by the elements that were - previously in list. Requires that *e not be in list. If e==NULL, list is - returned unchanged. */ -nsync_dll_list_ nsync_dll_make_last_in_list_ (nsync_dll_list_ list, nsync_dll_element_ *e) { - if (e != NULL) { - nsync_dll_make_first_in_list_ (list, e->next); - list = e; - } - return (list); -} - -/* Return a pointer to the first element of list, or NULL if list is empty. */ -nsync_dll_element_ *nsync_dll_first_ (nsync_dll_list_ list) { - nsync_dll_element_ *first = NULL; - if (list != NULL) { - first = list->next; - } - return (first); -} - -/* Return a pointer to the last element of list, or NULL if list is empty. */ -nsync_dll_element_ *nsync_dll_last_ (nsync_dll_list_ list) { - return (list); -} - -/* Return a pointer to the next element of list following *e, - or NULL if there is no such element. */ -nsync_dll_element_ *nsync_dll_next_ (nsync_dll_list_ list, nsync_dll_element_ *e) { - nsync_dll_element_ *next = NULL; - if (e != list) { - next = e->next; - } - return (next); -} - -/* Return a pointer to the previous element of list following *e, - or NULL if there is no such element. */ -nsync_dll_element_ *nsync_dll_prev_ (nsync_dll_list_ list, nsync_dll_element_ *e) { - nsync_dll_element_ *prev = NULL; - if (e != list->next) { - prev = e->prev; - } - return (prev); -} diff --git a/third_party/nsync/dll.h b/third_party/nsync/dll.h deleted file mode 100644 index a1345d386..000000000 --- a/third_party/nsync/dll.h +++ /dev/null @@ -1,69 +0,0 @@ -#ifndef NSYNC_DLL_H_ -#define NSYNC_DLL_H_ -#if !(__ASSEMBLER__ + __LINKER__ + 0) -COSMOPOLITAN_C_START_ - -/* A nsync_dll_element_ represents an element of a doubly-linked list of - waiters. */ -typedef struct nsync_dll_element_s_ { - struct nsync_dll_element_s_ *next; - struct nsync_dll_element_s_ *prev; - /* points to the struct this nsync_dll struct is embedded in. */ - void *container; -} nsync_dll_element_; - -/* A nsync_dll_list_ represents a list of nsync_dll_elements_. */ -typedef nsync_dll_element_ *nsync_dll_list_; /* last elem of circular list; nil - => empty; first is x.next. */ - -/* Initialize *e. */ -void nsync_dll_init_(nsync_dll_element_ *e, void *container); - -/* Return whether list is empty. */ -int nsync_dll_is_empty_(nsync_dll_list_ list); - -/* Remove *e from list, and returns the new list. */ -nsync_dll_list_ nsync_dll_remove_(nsync_dll_list_ list, nsync_dll_element_ *e); - -/* Cause element *n and its successors to come after element *p. - Requires n and p are non-NULL and do not point at elements of the - same list. */ -void nsync_dll_splice_after_(nsync_dll_element_ *p, nsync_dll_element_ *n); - -/* Make element *e the first element of list, and return the list. The - resulting list will have *e as its first element, followed by any - elements in the same list as *e, followed by the elements that were - previously in list. Requires that *e not be in list. If e==NULL, list - is returned unchanged. */ -nsync_dll_list_ nsync_dll_make_first_in_list_(nsync_dll_list_ list, - nsync_dll_element_ *e); - -/* Make element *e the last element of list, and return the list. The - resulting list will have *e as its last element, preceded by any - elements in the same list as *e, preceded by the elements that were - previously in list. Requires that *e not be in list. If e==NULL, list - is returned unchanged. */ -nsync_dll_list_ nsync_dll_make_last_in_list_(nsync_dll_list_ list, - nsync_dll_element_ *e); - -/* Return a pointer to the first element of list, or NULL if list is - * empty. */ -nsync_dll_element_ *nsync_dll_first_(nsync_dll_list_ list); - -/* Return a pointer to the last element of list, or NULL if list is - * empty. */ -nsync_dll_element_ *nsync_dll_last_(nsync_dll_list_ list); - -/* Return a pointer to the next element of list following *e, or NULL if - there is no such element. */ -nsync_dll_element_ *nsync_dll_next_(nsync_dll_list_ list, - nsync_dll_element_ *e); - -/* Return a pointer to the previous element of list following *e, or - NULL if there is no such element. */ -nsync_dll_element_ *nsync_dll_prev_(nsync_dll_list_ list, - nsync_dll_element_ *e); - -COSMOPOLITAN_C_END_ -#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ -#endif /* NSYNC_DLL_H_ */ diff --git a/third_party/nsync/mem/array.c b/third_party/nsync/mem/array.c index b115b6d72..1d16b5a11 100644 --- a/third_party/nsync/mem/array.c +++ b/third_party/nsync/mem/array.c @@ -39,7 +39,7 @@ void a_ensure_ (void *v, int delta, int sz) { } else { na = realloc (a->a_, nmax*sz); } - memset (omax *sz + (char *)na, 0, (nmax - omax) * sz); + bzero (omax *sz + (char *)na, (nmax - omax) * sz); a->a_ = (void **) na; a->h_.max_ = nmax; } diff --git a/third_party/nsync/mem/nsync_counter.c b/third_party/nsync/mem/nsync_counter.c index dddc67ec4..68fa3ac07 100644 --- a/third_party/nsync/mem/nsync_counter.c +++ b/third_party/nsync/mem/nsync_counter.c @@ -15,13 +15,13 @@ │ See the License for the specific language governing permissions and │ │ limitations under the License. │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/intrin/dll.h" #include "libc/mem/mem.h" #include "libc/str/str.h" #include "third_party/nsync/atomic.h" #include "third_party/nsync/atomic.internal.h" #include "third_party/nsync/common.internal.h" #include "third_party/nsync/counter.h" -#include "third_party/nsync/dll.h" #include "third_party/nsync/mu_semaphore.h" #include "third_party/nsync/races.internal.h" #include "third_party/nsync/wait_s.internal.h" @@ -38,13 +38,13 @@ struct nsync_counter_s_ { nsync_atomic_uint32_ waited; /* wait has been called */ nsync_mu counter_mu; /* protects fields below except reads of "value" */ nsync_atomic_uint32_ value; /* value of counter */ - struct nsync_dll_element_s_ *waiters; /* list of waiters */ + struct Dll *waiters; /* list of waiters */ }; nsync_counter nsync_counter_new (uint32_t value) { nsync_counter c = (nsync_counter) malloc (sizeof (*c)); if (c != NULL) { - memset ((void *) c, 0, sizeof (*c)); + bzero ((void *) c, sizeof (*c)); ATM_STORE (&c->value, value); } return (c); @@ -52,7 +52,7 @@ nsync_counter nsync_counter_new (uint32_t value) { void nsync_counter_free (nsync_counter c) { nsync_mu_lock (&c->counter_mu); - ASSERT (nsync_dll_is_empty_ (c->waiters)); + ASSERT (dll_is_empty (c->waiters)); nsync_mu_unlock (&c->counter_mu); free (c); } @@ -77,10 +77,10 @@ uint32_t nsync_counter_add (nsync_counter c, int32_t delta) { ASSERT (value < value - delta); /* Crash on overflow. */ } if (value == 0) { - nsync_dll_element_ *p; - while ((p = nsync_dll_first_ (c->waiters)) != NULL) { + struct Dll *p; + while ((p = dll_first (c->waiters)) != NULL) { struct nsync_waiter_s *nw = DLL_NSYNC_WAITER (p); - c->waiters = nsync_dll_remove_ (c->waiters, p); + dll_remove (&c->waiters, p); ATM_STORE_REL (&nw->waiting, 0); nsync_mu_semaphore_v (nw->sem); } @@ -127,7 +127,7 @@ static int counter_enqueue (void *v, struct nsync_waiter_s *nw) { nsync_mu_lock (&c->counter_mu); value = ATM_LOAD_ACQ (&c->value); if (value != 0) { - c->waiters = nsync_dll_make_last_in_list_ (c->waiters, &nw->q); + dll_make_last (&c->waiters, &nw->q); ATM_STORE (&nw->waiting, 1); } else { ATM_STORE (&nw->waiting, 0); @@ -142,7 +142,7 @@ static int counter_dequeue (void *v, struct nsync_waiter_s *nw) { nsync_mu_lock (&c->counter_mu); value = ATM_LOAD_ACQ (&c->value); if (ATM_LOAD_ACQ (&nw->waiting) != 0) { - c->waiters = nsync_dll_remove_ (c->waiters, &nw->q); + dll_remove (&c->waiters, &nw->q); ATM_STORE (&nw->waiting, 0); } nsync_mu_unlock (&c->counter_mu); diff --git a/third_party/nsync/mem/nsync_cv.c b/third_party/nsync/mem/nsync_cv.c index 806e712e5..fab7ac716 100644 --- a/third_party/nsync/mem/nsync_cv.c +++ b/third_party/nsync/mem/nsync_cv.c @@ -16,12 +16,12 @@ │ limitations under the License. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/cp.internal.h" +#include "libc/intrin/dll.h" #include "libc/str/str.h" #include "libc/thread/thread.h" #include "third_party/nsync/atomic.internal.h" #include "third_party/nsync/common.internal.h" #include "third_party/nsync/cv.h" -#include "third_party/nsync/dll.h" #include "third_party/nsync/races.internal.h" #include "third_party/nsync/wait_s.internal.h" #include "third_party/nsync/waiter.h" @@ -38,7 +38,7 @@ https://github.com/google/nsync\""); /* Initialize *cv. */ void nsync_cv_init (nsync_cv *cv) { - memset ((void *) cv, 0, sizeof (*cv)); + bzero ((void *) cv, sizeof (*cv)); } /* Wake the cv waiters in the circular list pointed to by @@ -46,10 +46,10 @@ void nsync_cv_init (nsync_cv *cv) { nsync_mu, the "wakeup" may consist of transferring the waiters to the nsync_mu's queue. Requires that every waiter is associated with the same mutex. all_readers indicates whether all the waiters on the list are readers. */ -static void wake_waiters (nsync_dll_list_ to_wake_list, int all_readers) { - nsync_dll_element_ *p = NULL; - nsync_dll_element_ *next = NULL; - nsync_dll_element_ *first_waiter = nsync_dll_first_ (to_wake_list); +static void wake_waiters (struct Dll *to_wake_list, int all_readers) { + struct Dll *p = NULL; + struct Dll *next = NULL; + struct Dll *first_waiter = dll_first (to_wake_list); struct nsync_waiter_s *first_nw = DLL_NSYNC_WAITER (first_waiter); waiter *first_w = NULL; nsync_mu *pmu = NULL; @@ -71,7 +71,7 @@ static void wake_waiters (nsync_dll_list_ to_wake_list, int all_readers) { */ uint32_t old_mu_word = ATM_LOAD (&pmu->word); int first_cant_acquire = ((old_mu_word & first_w->l_type->zero_to_acquire) != 0); - next = nsync_dll_next_ (to_wake_list, first_waiter); + next = dll_next (to_wake_list, first_waiter); if ((old_mu_word&MU_ANY_LOCK) != 0 && (old_mu_word&MU_SPINLOCK) == 0 && (first_cant_acquire || (next != NULL && !all_readers)) && @@ -88,8 +88,8 @@ static void wake_waiters (nsync_dll_list_ to_wake_list, int all_readers) { int woke_areader = 0; /* Transfer the first waiter iff it can't acquire *pmu. */ if (first_cant_acquire) { - to_wake_list = nsync_dll_remove_ (to_wake_list, first_waiter); - pmu->waiters = nsync_dll_make_last_in_list_ (pmu->waiters, first_waiter); + dll_remove (&to_wake_list, first_waiter); + dll_make_last (&pmu->waiters, first_waiter); /* tell nsync_cv_wait_with_deadline() that we moved the waiter to *pmu's queue. */ first_w->cv_mu = NULL; @@ -107,7 +107,7 @@ static void wake_waiters (nsync_dll_list_ to_wake_list, int all_readers) { if ((p_nw->flags & NSYNC_WAITER_FLAG_MUCV) != 0) { p_w = DLL_WAITER (p); } - next = nsync_dll_next_ (to_wake_list, p); + next = dll_next (to_wake_list, p); p_is_writer = (p_w != NULL && DLL_WAITER (p)->l_type == nsync_writer_type_); /* We transfer this element if any of: @@ -117,8 +117,8 @@ static void wake_waiters (nsync_dll_list_ to_wake_list, int all_readers) { if (p_w == NULL) { /* wake non-native waiter */ } else if (first_cant_acquire || first_is_writer || p_is_writer) { - to_wake_list = nsync_dll_remove_ (to_wake_list, p); - pmu->waiters = nsync_dll_make_last_in_list_ (pmu->waiters, p); + dll_remove (&to_wake_list, p); + dll_make_last (&pmu->waiters, p); /* tell nsync_cv_wait_with_deadline() that we moved the waiter to *pmu's queue. */ @@ -147,10 +147,10 @@ static void wake_waiters (nsync_dll_list_ to_wake_list, int all_readers) { } /* Wake any waiters we didn't manage to enqueue on the mu. */ - for (p = nsync_dll_first_ (to_wake_list); p != NULL; p = next) { + for (p = dll_first (to_wake_list); p != NULL; p = next) { struct nsync_waiter_s *p_nw = DLL_NSYNC_WAITER (p); - next = nsync_dll_next_ (to_wake_list, p); - to_wake_list = nsync_dll_remove_ (to_wake_list, p); + next = dll_next (to_wake_list, p); + dll_remove (&to_wake_list, p); /* Wake the waiter. */ ATM_STORE_REL (&p_nw->waiting, 0); /* release store */ nsync_mu_semaphore_v (p_nw->sem); @@ -239,7 +239,7 @@ int nsync_cv_wait_with_deadline_generic (nsync_cv *pcv, void *pmu, /* acquire spinlock, set non-empty */ old_word = nsync_spin_test_and_set_ (&pcv->word, CV_SPINLOCK, CV_SPINLOCK|CV_NON_EMPTY, 0); - pcv->waiters = nsync_dll_make_last_in_list_ (pcv->waiters, &w->nw.q); + dll_make_last (&pcv->waiters, &w->nw.q); remove_count = ATM_LOAD (&w->remove_count); /* Release the spin lock. */ ATM_STORE_REL (&pcv->word, old_word|CV_NON_EMPTY); /* release store */ @@ -277,12 +277,11 @@ int nsync_cv_wait_with_deadline_generic (nsync_cv *pcv, void *pmu, queue, and declare a timeout/cancellation. */ outcome = sem_outcome; - pcv->waiters = nsync_dll_remove_ (pcv->waiters, - &w->nw.q); + dll_remove (&pcv->waiters, &w->nw.q); do { old_value = ATM_LOAD (&w->remove_count); } while (!ATM_CAS (&w->remove_count, old_value, old_value+1)); - if (nsync_dll_is_empty_ (pcv->waiters)) { + if (dll_is_empty (pcv->waiters)) { old_word &= ~(CV_NON_EMPTY); } ATM_STORE_REL (&w->nw.waiting, 0); /* release store */ @@ -328,27 +327,26 @@ int nsync_cv_wait_with_deadline_generic (nsync_cv *pcv, void *pmu, void nsync_cv_signal (nsync_cv *pcv) { IGNORE_RACES_START (); if ((ATM_LOAD_ACQ (&pcv->word) & CV_NON_EMPTY) != 0) { /* acquire load */ - nsync_dll_list_ to_wake_list = NULL; /* waiters that we will wake */ + struct Dll *to_wake_list = NULL; /* waiters that we will wake */ int all_readers = 0; /* acquire spinlock */ uint32_t old_word = nsync_spin_test_and_set_ (&pcv->word, CV_SPINLOCK, CV_SPINLOCK, 0); - if (!nsync_dll_is_empty_ (pcv->waiters)) { + if (!dll_is_empty (pcv->waiters)) { /* Point to first waiter that enqueued itself, and detach it from all others. */ struct nsync_waiter_s *first_nw; - nsync_dll_element_ *first = nsync_dll_first_ (pcv->waiters); - pcv->waiters = nsync_dll_remove_ (pcv->waiters, first); + struct Dll *first = dll_first (pcv->waiters); + dll_remove (&pcv->waiters, first); first_nw = DLL_NSYNC_WAITER (first); if ((first_nw->flags & NSYNC_WAITER_FLAG_MUCV) != 0) { uint32_t old_value; do { - old_value = - ATM_LOAD (&DLL_WAITER (first)->remove_count); + old_value = ATM_LOAD (&DLL_WAITER (first)->remove_count); } while (!ATM_CAS (&DLL_WAITER (first)->remove_count, old_value, old_value+1)); } - to_wake_list = nsync_dll_make_last_in_list_ (to_wake_list, first); + dll_make_last (&to_wake_list, first); if ((first_nw->flags & NSYNC_WAITER_FLAG_MUCV) != 0 && DLL_WAITER (first)->l_type == nsync_reader_type_) { int woke_writer; @@ -363,14 +361,14 @@ void nsync_cv_signal (nsync_cv *pcv) { the condition; the client is expecting only one writer to be able make use of the wakeup, or he would have called nsync_cv_broadcast(). */ - nsync_dll_element_ *p = NULL; - nsync_dll_element_ *next = NULL; + struct Dll *p = NULL; + struct Dll *next = NULL; all_readers = 1; woke_writer = 0; - for (p = nsync_dll_first_ (pcv->waiters); p != NULL; p = next) { + for (p = dll_first (pcv->waiters); p != NULL; p = next) { struct nsync_waiter_s *p_nw = DLL_NSYNC_WAITER (p); int should_wake; - next = nsync_dll_next_ (pcv->waiters, p); + next = dll_next (pcv->waiters, p); should_wake = 0; if ((p_nw->flags & NSYNC_WAITER_FLAG_MUCV) != 0 && DLL_WAITER (p)->l_type == nsync_reader_type_) { @@ -381,7 +379,7 @@ void nsync_cv_signal (nsync_cv *pcv) { should_wake = 1; } if (should_wake) { - pcv->waiters = nsync_dll_remove_ (pcv->waiters, p); + dll_remove (&pcv->waiters, p); if ((p_nw->flags & NSYNC_WAITER_FLAG_MUCV) != 0) { uint32_t old_value; do { @@ -390,18 +388,17 @@ void nsync_cv_signal (nsync_cv *pcv) { } while (!ATM_CAS (&DLL_WAITER (p)->remove_count, old_value, old_value+1)); } - to_wake_list = nsync_dll_make_last_in_list_ ( - to_wake_list, p); + dll_make_last (&to_wake_list, p); } } } - if (nsync_dll_is_empty_ (pcv->waiters)) { + if (dll_is_empty (pcv->waiters)) { old_word &= ~(CV_NON_EMPTY); } } /* Release spinlock. */ ATM_STORE_REL (&pcv->word, old_word); /* release store */ - if (!nsync_dll_is_empty_ (to_wake_list)) { + if (!dll_is_empty (to_wake_list)) { wake_waiters (to_wake_list, all_readers); } } @@ -412,22 +409,22 @@ void nsync_cv_signal (nsync_cv *pcv) { void nsync_cv_broadcast (nsync_cv *pcv) { IGNORE_RACES_START (); if ((ATM_LOAD_ACQ (&pcv->word) & CV_NON_EMPTY) != 0) { /* acquire load */ - nsync_dll_element_ *p; - nsync_dll_element_ *next; + struct Dll *p; + struct Dll *next; int all_readers; - nsync_dll_list_ to_wake_list = NULL; /* waiters that we will wake */ + struct Dll *to_wake_list = NULL; /* waiters that we will wake */ /* acquire spinlock */ nsync_spin_test_and_set_ (&pcv->word, CV_SPINLOCK, CV_SPINLOCK, 0); p = NULL; next = NULL; all_readers = 1; /* Wake entire waiter list, which we leave empty. */ - for (p = nsync_dll_first_ (pcv->waiters); p != NULL; p = next) { + for (p = dll_first (pcv->waiters); p != NULL; p = next) { struct nsync_waiter_s *p_nw = DLL_NSYNC_WAITER (p); - next = nsync_dll_next_ (pcv->waiters, p); + next = dll_next (pcv->waiters, p); all_readers = all_readers && (p_nw->flags & NSYNC_WAITER_FLAG_MUCV) != 0 && (DLL_WAITER (p)->l_type == nsync_reader_type_); - pcv->waiters = nsync_dll_remove_ (pcv->waiters, p); + dll_remove (&pcv->waiters, p); if ((p_nw->flags & NSYNC_WAITER_FLAG_MUCV) != 0) { uint32_t old_value; do { @@ -435,11 +432,11 @@ void nsync_cv_broadcast (nsync_cv *pcv) { } while (!ATM_CAS (&DLL_WAITER (p)->remove_count, old_value, old_value+1)); } - to_wake_list = nsync_dll_make_last_in_list_ (to_wake_list, p); + dll_make_last (&to_wake_list, p); } /* Release spinlock and mark queue empty. */ ATM_STORE_REL (&pcv->word, 0); /* release store */ - if (!nsync_dll_is_empty_ (to_wake_list)) { /* Wake them. */ + if (!dll_is_empty (to_wake_list)) { /* Wake them. */ wake_waiters (to_wake_list, all_readers); } } @@ -477,7 +474,7 @@ static int cv_enqueue (void *v, struct nsync_waiter_s *nw) { nsync_cv *pcv = (nsync_cv *) v; /* acquire spinlock */ uint32_t old_word = nsync_spin_test_and_set_ (&pcv->word, CV_SPINLOCK, CV_SPINLOCK, 0); - pcv->waiters = nsync_dll_make_last_in_list_ (pcv->waiters, &nw->q); + dll_make_last (&pcv->waiters, &nw->q); ATM_STORE (&nw->waiting, 1); /* Release spinlock. */ ATM_STORE_REL (&pcv->word, old_word | CV_NON_EMPTY); /* release store */ @@ -490,11 +487,11 @@ static int cv_dequeue (void *v, struct nsync_waiter_s *nw) { /* acquire spinlock */ uint32_t old_word = nsync_spin_test_and_set_ (&pcv->word, CV_SPINLOCK, CV_SPINLOCK, 0); if (ATM_LOAD_ACQ (&nw->waiting) != 0) { - pcv->waiters = nsync_dll_remove_ (pcv->waiters, &nw->q); + dll_remove (&pcv->waiters, &nw->q); ATM_STORE (&nw->waiting, 0); was_queued = 1; } - if (nsync_dll_is_empty_ (pcv->waiters)) { + if (dll_is_empty (pcv->waiters)) { old_word &= ~(CV_NON_EMPTY); } /* Release spinlock. */ diff --git a/third_party/nsync/mem/nsync_debug.c b/third_party/nsync/mem/nsync_debug.c index abfeb73ba..e0269196b 100644 --- a/third_party/nsync/mem/nsync_debug.c +++ b/third_party/nsync/mem/nsync_debug.c @@ -15,9 +15,9 @@ │ See the License for the specific language governing permissions and │ │ limitations under the License. │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/intrin/dll.h" #include "third_party/nsync/atomic.h" #include "third_party/nsync/common.internal.h" -#include "third_party/nsync/dll.h" #include "third_party/nsync/mu_semaphore.h" #include "third_party/nsync/races.internal.h" #include "third_party/nsync/wait_s.internal.h" @@ -142,9 +142,9 @@ static void emit_word (struct emit_buf *b, const struct bit_name *name, uint32_t } /* Emit the waiter queue *q to *b. */ -static void emit_waiters (struct emit_buf *b, nsync_dll_list_ list) { - nsync_dll_element_ *p = nsync_dll_first_ (list); - nsync_dll_element_ *next; +static void emit_waiters (struct emit_buf *b, struct Dll *list) { + struct Dll *p = dll_first (list); + struct Dll *next; if (p != NULL) { emit_print (b, "\nwaiters =\n"); } @@ -157,7 +157,7 @@ static void emit_waiters (struct emit_buf *b, nsync_dll_list_ list) { emit_print (b, "bad WAITER_TAG %i", (uintptr_t) w->tag); } else { - next = nsync_dll_next_ (list, p); + next = dll_next (list, p); if (nw->tag != NSYNC_WAITER_TAG) { emit_print (b, " bad WAITER_TAG %i", (uintptr_t) nw->tag); diff --git a/third_party/nsync/mem/nsync_mu_wait.c b/third_party/nsync/mem/nsync_mu_wait.c index 693839fbe..4f03138b8 100644 --- a/third_party/nsync/mem/nsync_mu_wait.c +++ b/third_party/nsync/mem/nsync_mu_wait.c @@ -16,9 +16,9 @@ │ limitations under the License. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/blockcancel.internal.h" +#include "libc/intrin/dll.h" #include "third_party/nsync/atomic.h" #include "third_party/nsync/common.internal.h" -#include "third_party/nsync/dll.h" #include "third_party/nsync/mu_semaphore.h" #include "third_party/nsync/races.internal.h" #include "third_party/nsync/wait_s.internal.h" @@ -203,18 +203,16 @@ int nsync_mu_wait_with_deadline (nsync_mu *mu, had_waiters = ((old_word & (MU_DESIG_WAKER | MU_WAITING)) == MU_WAITING); /* Queue the waiter. */ if (first_wait) { - nsync_maybe_merge_conditions_ (nsync_dll_last_ (mu->waiters), + nsync_maybe_merge_conditions_ (dll_last (mu->waiters), &w->nw.q); /* first wait goes to end of queue */ - mu->waiters = nsync_dll_make_last_in_list_ (mu->waiters, - &w->nw.q); + dll_make_last (&mu->waiters, &w->nw.q); first_wait = 0; } else { nsync_maybe_merge_conditions_ (&w->nw.q, - nsync_dll_first_ (mu->waiters)); + dll_first (mu->waiters)); /* subsequent waits go to front of queue */ - mu->waiters = nsync_dll_make_first_in_list_ (mu->waiters, - &w->nw.q); + dll_make_first (&mu->waiters, &w->nw.q); } /* Release spinlock and *mu. */ do { diff --git a/third_party/nsync/mem/nsync_note.c b/third_party/nsync/mem/nsync_note.c index f13b0a582..aa0b9ee0f 100644 --- a/third_party/nsync/mem/nsync_note.c +++ b/third_party/nsync/mem/nsync_note.c @@ -15,11 +15,11 @@ │ See the License for the specific language governing permissions and │ │ limitations under the License. │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/intrin/dll.h" #include "libc/mem/mem.h" #include "libc/str/str.h" #include "third_party/nsync/atomic.h" #include "third_party/nsync/common.internal.h" -#include "third_party/nsync/dll.h" #include "third_party/nsync/mu_semaphore.h" #include "third_party/nsync/mu_wait.h" #include "third_party/nsync/races.internal.h" @@ -64,12 +64,12 @@ static void set_expiry_time (nsync_note n, nsync_time t) { n->expiry_time_valid = 1; } -/* Return a pointer to the note containing nsync_dll_element_ *e. */ -#define DLL_NOTE(e) ((nsync_note)((e)->container)) +/* Return a pointer to the note containing struct Dll *e. */ +#define DLL_NOTE(e) DLL_CONTAINER(struct nsync_note_s_, parent_child_link, e) /* Return whether n->children is empty. Assumes n->note_mu held. */ static int no_children (const void *v) { - return (nsync_dll_is_empty_ (((nsync_note)v)->children)); + return (dll_is_empty (((nsync_note)v)->children)); } #define WAIT_FOR_NO_CHILDREN(pred_, n_) nsync_mu_wait (&(n_)->note_mu, &pred_, (n_), NULL) @@ -91,18 +91,18 @@ static void note_notify_child (nsync_note n, nsync_note parent) { nsync_time t; t = NOTIFIED_TIME (n); if (nsync_time_cmp (t, nsync_time_zero) > 0) { - nsync_dll_element_ *p; - nsync_dll_element_ *next; + struct Dll *p; + struct Dll *next; ATM_STORE_REL (&n->notified, 1); - while ((p = nsync_dll_first_ (n->waiters)) != NULL) { + while ((p = dll_first (n->waiters)) != NULL) { struct nsync_waiter_s *nw = DLL_NSYNC_WAITER (p); - n->waiters = nsync_dll_remove_ (n->waiters, p); + dll_remove (&n->waiters, p); ATM_STORE_REL (&nw->waiting, 0); nsync_mu_semaphore_v (nw->sem); } - for (p = nsync_dll_first_ (n->children); p != NULL; p = next) { + for (p = dll_first (n->children); p != NULL; p = next) { nsync_note child = DLL_NOTE (p); - next = nsync_dll_next_ (n->children, p); + next = dll_next (n->children, p); nsync_mu_lock (&child->note_mu); if (child->disconnecting == 0) { note_notify_child (child, n); @@ -111,8 +111,7 @@ static void note_notify_child (nsync_note n, nsync_note parent) { } WAIT_FOR_NO_CHILDREN (no_children, n); if (parent != NULL) { - parent->children = nsync_dll_remove_ (parent->children, - &n->parent_child_link); + dll_remove (&parent->children, &n->parent_child_link); WAKEUP_NO_CHILDREN (parent); n->parent = NULL; } @@ -178,8 +177,8 @@ nsync_note nsync_note_new (nsync_note parent, nsync_time abs_deadline) { nsync_note n = (nsync_note) malloc (sizeof (*n)); if (n != NULL) { - memset ((void *) n, 0, sizeof (*n)); - nsync_dll_init_ (&n->parent_child_link, n); + bzero (n, sizeof (*n)); + dll_init (&n->parent_child_link); set_expiry_time (n, abs_deadline); if (!nsync_note_is_notified (n) && parent != NULL) { nsync_time parent_time; @@ -190,8 +189,8 @@ nsync_note nsync_note_new (nsync_note parent, } if (nsync_time_cmp (parent_time, nsync_time_zero) > 0) { n->parent = parent; - parent->children = nsync_dll_make_last_in_list_ (parent->children, - &n->parent_child_link); + dll_make_last (&parent->children, + &n->parent_child_link); } nsync_mu_unlock (&parent->note_mu); } @@ -201,28 +200,27 @@ nsync_note nsync_note_new (nsync_note parent, void nsync_note_free (nsync_note n) { nsync_note parent; - nsync_dll_element_ *p; - nsync_dll_element_ *next; + struct Dll *p; + struct Dll *next; nsync_mu_lock (&n->note_mu); n->disconnecting++; - ASSERT (nsync_dll_is_empty_ (n->waiters)); + ASSERT (dll_is_empty (n->waiters)); parent = n->parent; if (parent != NULL && !nsync_mu_trylock (&parent->note_mu)) { nsync_mu_unlock (&n->note_mu); nsync_mu_lock (&parent->note_mu); nsync_mu_lock (&n->note_mu); } - for (p = nsync_dll_first_ (n->children); p != NULL; p = next) { + for (p = dll_first (n->children); p != NULL; p = next) { nsync_note child = DLL_NOTE (p); - next = nsync_dll_next_ (n->children, p); + next = dll_next (n->children, p); nsync_mu_lock (&child->note_mu); if (child->disconnecting == 0) { - n->children = nsync_dll_remove_ (n->children, - &child->parent_child_link); + dll_remove (&n->children, &child->parent_child_link); if (parent != NULL) { child->parent = parent; - parent->children = nsync_dll_make_last_in_list_ ( - parent->children, &child->parent_child_link); + dll_make_last (&parent->children, + &child->parent_child_link); } else { child->parent = NULL; } @@ -231,8 +229,7 @@ void nsync_note_free (nsync_note n) { } WAIT_FOR_NO_CHILDREN (no_children, n); if (parent != NULL) { - parent->children = nsync_dll_remove_ (parent->children, - &n->parent_child_link); + dll_remove (&parent->children, &n->parent_child_link); WAKEUP_NO_CHILDREN (parent); n->parent = NULL; nsync_mu_unlock (&parent->note_mu); @@ -273,7 +270,7 @@ static int note_enqueue (void *v, struct nsync_waiter_s *nw) { nsync_mu_lock (&n->note_mu); ntime = NOTIFIED_TIME (n); if (nsync_time_cmp (ntime, nsync_time_zero) > 0) { - n->waiters = nsync_dll_make_last_in_list_ (n->waiters, &nw->q); + dll_make_last (&n->waiters, &nw->q); ATM_STORE (&nw->waiting, 1); waiting = 1; } else { @@ -292,7 +289,7 @@ static int note_dequeue (void *v, struct nsync_waiter_s *nw) { nsync_mu_lock (&n->note_mu); ntime = NOTIFIED_TIME (n); if (nsync_time_cmp (ntime, nsync_time_zero) > 0) { - n->waiters = nsync_dll_remove_ (n->waiters, &nw->q); + dll_remove (&n->waiters, &nw->q); ATM_STORE (&nw->waiting, 0); was_queued = 1; } diff --git a/third_party/nsync/mem/nsync_once.c b/third_party/nsync/mem/nsync_once.c index 381f443c9..3c0d20ef7 100644 --- a/third_party/nsync/mem/nsync_once.c +++ b/third_party/nsync/mem/nsync_once.c @@ -18,7 +18,6 @@ #include "third_party/nsync/atomic.h" #include "third_party/nsync/atomic.internal.h" #include "third_party/nsync/common.internal.h" -#include "third_party/nsync/dll.h" #include "third_party/nsync/mu_semaphore.h" #include "third_party/nsync/once.h" #include "third_party/nsync/races.internal.h" diff --git a/third_party/nsync/mem/nsync_sem_wait.c b/third_party/nsync/mem/nsync_sem_wait.c index 112bf793b..60ad9f3de 100644 --- a/third_party/nsync/mem/nsync_sem_wait.c +++ b/third_party/nsync/mem/nsync_sem_wait.c @@ -16,11 +16,11 @@ │ limitations under the License. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/errno.h" +#include "libc/intrin/dll.h" #include "libc/runtime/runtime.h" #include "third_party/nsync/atomic.h" #include "third_party/nsync/atomic.internal.h" #include "third_party/nsync/common.internal.h" -#include "third_party/nsync/dll.h" #include "third_party/nsync/mu_semaphore.h" #include "third_party/nsync/wait_s.internal.h" @@ -47,7 +47,7 @@ int nsync_sem_wait_with_cancel_ (waiter *w, nsync_time abs_deadline, struct nsync_waiter_s nw; nw.tag = NSYNC_WAITER_TAG; nw.sem = &w->sem; - nsync_dll_init_ (&nw.q, &nw); + dll_init (&nw.q); ATM_STORE (&nw.waiting, 1); nw.flags = 0; nsync_mu_lock (&cancel_note->note_mu); @@ -55,8 +55,7 @@ int nsync_sem_wait_with_cancel_ (waiter *w, nsync_time abs_deadline, if (nsync_time_cmp (cancel_time, nsync_time_zero) > 0) { nsync_time local_abs_deadline; int deadline_is_nearer = 0; - cancel_note->waiters = nsync_dll_make_last_in_list_ ( - cancel_note->waiters, &nw.q); + dll_make_last (&cancel_note->waiters, &nw.q); local_abs_deadline = cancel_time; if (nsync_time_cmp (abs_deadline, cancel_time) < 0) { local_abs_deadline = abs_deadline; @@ -73,8 +72,7 @@ int nsync_sem_wait_with_cancel_ (waiter *w, nsync_time abs_deadline, cancel_time = NOTIFIED_TIME (cancel_note); if (nsync_time_cmp (cancel_time, nsync_time_zero) > 0) { - cancel_note->waiters = nsync_dll_remove_ ( - cancel_note->waiters, &nw.q); + dll_remove (&cancel_note->waiters, &nw.q); } } nsync_mu_unlock (&cancel_note->note_mu); diff --git a/third_party/nsync/mem/nsync_wait.c b/third_party/nsync/mem/nsync_wait.c index 71cffaece..e33fe815d 100644 --- a/third_party/nsync/mem/nsync_wait.c +++ b/third_party/nsync/mem/nsync_wait.c @@ -20,7 +20,6 @@ #include "third_party/nsync/atomic.h" #include "third_party/nsync/atomic.internal.h" #include "third_party/nsync/common.internal.h" -#include "third_party/nsync/dll.h" #include "third_party/nsync/mu_semaphore.h" #include "third_party/nsync/races.internal.h" #include "third_party/nsync/wait_s.internal.h" @@ -58,7 +57,7 @@ int nsync_wait_n (void *mu, void (*lock) (void *), void (*unlock) (void *), for (i = 0; i != count && enqueued; i++) { nw[i].tag = NSYNC_WAITER_TAG; nw[i].sem = &w->sem; - nsync_dll_init_ (&nw[i].q, &nw[i]); + dll_init (&nw[i].q); ATM_STORE (&nw[i].waiting, 0); nw[i].flags = 0; enqueued = (*waitable[i]->funcs->enqueue) (waitable[i]->v, &nw[i]); diff --git a/third_party/nsync/mu.c b/third_party/nsync/mu.c index 28fd8d7a8..4b8db1103 100644 --- a/third_party/nsync/mu.c +++ b/third_party/nsync/mu.c @@ -16,10 +16,10 @@ │ limitations under the License. │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/calls/blockcancel.internal.h" +#include "libc/intrin/dll.h" #include "libc/str/str.h" #include "third_party/nsync/atomic.h" #include "third_party/nsync/common.internal.h" -#include "third_party/nsync/dll.h" #include "third_party/nsync/mu_semaphore.h" #include "third_party/nsync/races.internal.h" #include "third_party/nsync/wait_s.internal.h" @@ -32,7 +32,7 @@ https://github.com/google/nsync\""); /* Initialize *mu. */ void nsync_mu_init (nsync_mu *mu) { - memset ((void *) mu, 0, sizeof (*mu)); + bzero ((void *) mu, sizeof (*mu)); } /* Release the mutex spinlock. */ @@ -88,12 +88,10 @@ void nsync_mu_lock_slow_ (nsync_mu *mu, waiter *w, uint32_t clear, lock_type *l_ ATM_STORE (&w->nw.waiting, 1); if (wait_count == 0) { /* first wait goes to end of queue */ - mu->waiters = nsync_dll_make_last_in_list_ (mu->waiters, - &w->nw.q); + dll_make_last (&mu->waiters, &w->nw.q); } else { /* subsequent waits go to front of queue */ - mu->waiters = nsync_dll_make_first_in_list_ (mu->waiters, - &w->nw.q); + dll_make_first (&mu->waiters, &w->nw.q); } /* Release spinlock. Cannot use a store here, because @@ -202,32 +200,32 @@ void nsync_mu_rlock (nsync_mu *mu) { /* Invoke the condition associated with *p, which is an element of a "waiter" list. */ -static int condition_true (nsync_dll_element_ *p) { +static int condition_true (struct Dll *p) { return ((*DLL_WAITER (p)->cond.f) (DLL_WAITER (p)->cond.v)); } /* If *p is an element of waiter_list (a list of "waiter" structs(, return a pointer to the next element of the list that has a different condition. */ -static nsync_dll_element_ *skip_past_same_condition ( - nsync_dll_list_ waiter_list, nsync_dll_element_ *p) { - nsync_dll_element_ *next; - nsync_dll_element_ *last_with_same_condition = +static struct Dll *skip_past_same_condition ( + struct Dll *waiter_list, struct Dll *p) { + struct Dll *next; + struct Dll *last_with_same_condition = &DLL_WAITER_SAMECOND (DLL_WAITER (p)->same_condition.prev)->nw.q; if (last_with_same_condition != p && last_with_same_condition != p->prev) { /* First in set with same condition, so skip to end. */ - next = nsync_dll_next_ (waiter_list, last_with_same_condition); + next = dll_next (waiter_list, last_with_same_condition); } else { - next = nsync_dll_next_ (waiter_list, p); + next = dll_next (waiter_list, p); } return (next); } /* Merge the same_condition lists of *p and *n if they have the same non-NULL condition. */ -void nsync_maybe_merge_conditions_ (nsync_dll_element_ *p, nsync_dll_element_ *n) { +void nsync_maybe_merge_conditions_ (struct Dll *p, struct Dll *n) { if (p != NULL && n != NULL && WAIT_CONDITION_EQ (&DLL_WAITER (p)->cond, &DLL_WAITER (n)->cond)) { - nsync_dll_splice_after_ (&DLL_WAITER (p)->same_condition, + dll_splice_after (&DLL_WAITER (p)->same_condition, &DLL_WAITER (n)->same_condition); } } @@ -235,19 +233,19 @@ void nsync_maybe_merge_conditions_ (nsync_dll_element_ *p, nsync_dll_element_ *n /* Remove element *e from nsync_mu waiter queue mu_queue, fixing up the same_condition list by merging the lists on either side if possible. Also increment the waiter's remove_count. */ -nsync_dll_list_ nsync_remove_from_mu_queue_ (nsync_dll_list_ mu_queue, nsync_dll_element_ *e) { +struct Dll *nsync_remove_from_mu_queue_ (struct Dll *mu_queue, struct Dll *e) { /* Record previous and next elements in the original queue. */ - nsync_dll_element_ *prev = e->prev; - nsync_dll_element_ *next = e->next; + struct Dll *prev = e->prev; + struct Dll *next = e->next; uint32_t old_value; /* Remove. */ - mu_queue = nsync_dll_remove_ (mu_queue, e); + dll_remove (&mu_queue, e); do { old_value = ATM_LOAD (&DLL_WAITER (e)->remove_count); } while (!ATM_CAS (&DLL_WAITER (e)->remove_count, old_value, old_value+1)); - if (!nsync_dll_is_empty_ (mu_queue)) { + if (!dll_is_empty (mu_queue)) { /* Fix up same_condition. */ - nsync_dll_element_ *e_same_condition = &DLL_WAITER (e)->same_condition; + struct Dll *e_same_condition = &DLL_WAITER (e)->same_condition; if (e_same_condition->next != e_same_condition) { /* *e is linked to a same_condition neighbour---just remove it. */ @@ -255,7 +253,7 @@ nsync_dll_list_ nsync_remove_from_mu_queue_ (nsync_dll_list_ mu_queue, nsync_dll e_same_condition->prev->next = e_same_condition->next; e_same_condition->next = e_same_condition; e_same_condition->prev = e_same_condition; - } else if (prev != nsync_dll_last_ (mu_queue)) { + } else if (prev != dll_last (mu_queue)) { /* Merge the new neighbours together if we can. */ nsync_maybe_merge_conditions_ (prev, next); } @@ -301,7 +299,7 @@ void nsync_mu_unlock_slow_ (nsync_mu *mu, lock_type *l_type) { } else if ((old_word&MU_SPINLOCK) == 0 && ATM_CAS_ACQ (&mu->word, old_word, (old_word-early_release_mu)|MU_SPINLOCK|MU_DESIG_WAKER)) { - nsync_dll_list_ wake; + struct Dll *wake; lock_type *wake_type; uint32_t clear_on_release; uint32_t set_on_release; @@ -311,8 +309,8 @@ void nsync_mu_unlock_slow_ (nsync_mu *mu, lock_type *l_type) { there are conditions to check, the mutex itself is still held. */ - nsync_dll_element_ *p = NULL; - nsync_dll_element_ *next = NULL; + struct Dll *p = NULL; + struct Dll *next = NULL; /* Swap the entire mu->waiters list into the local "new_waiters" list. This gives us exclusive access @@ -321,8 +319,8 @@ void nsync_mu_unlock_slow_ (nsync_mu *mu, lock_type *l_type) { will grab more new waiters that arrived while we were checking conditions, and terminates only if no new waiters arrive in one loop iteration. */ - nsync_dll_list_ waiters = NULL; - nsync_dll_list_ new_waiters = mu->waiters; + struct Dll *waiters = NULL; + struct Dll *new_waiters = mu->waiters; mu->waiters = NULL; /* Remove a waiter from the queue, if possible. */ @@ -330,8 +328,8 @@ void nsync_mu_unlock_slow_ (nsync_mu *mu, lock_type *l_type) { wake_type = NULL; /* type of waiter(s) on wake, or NULL if wake is empty. */ clear_on_release = MU_SPINLOCK; set_on_release = MU_ALL_FALSE; - while (!nsync_dll_is_empty_ (new_waiters)) { /* some new waiters to consider */ - p = nsync_dll_first_ (new_waiters); + while (!dll_is_empty (new_waiters)) { /* some new waiters to consider */ + p = dll_first (new_waiters); if (testing_conditions) { /* Should we continue to test conditions? */ if (wake_type == nsync_writer_type_) { @@ -357,12 +355,12 @@ void nsync_mu_unlock_slow_ (nsync_mu *mu, lock_type *l_type) { } /* Process the new waiters picked up in this iteration of the - "while (!nsync_dll_is_empty_ (new_waiters))" loop, + "while (!dll_is_empty (new_waiters))" loop, and stop looking when we run out of waiters, or we find a writer to wake up. */ while (p != NULL && wake_type != nsync_writer_type_) { int p_has_condition; - next = nsync_dll_next_ (new_waiters, p); + next = dll_next (new_waiters, p); p_has_condition = (DLL_WAITER (p)->cond.f != NULL); if (p_has_condition && !testing_conditions) { nsync_panic_ ("checking a waiter condition " @@ -377,7 +375,7 @@ void nsync_mu_unlock_slow_ (nsync_mu *mu, lock_type *l_type) { /* Wake this thread. */ new_waiters = nsync_remove_from_mu_queue_ ( new_waiters, p); - wake = nsync_dll_make_last_in_list_ (wake, p); + dll_make_last (&wake, p); wake_type = DLL_WAITER (p)->l_type; } else { /* Failing to wake a writer @@ -403,10 +401,9 @@ void nsync_mu_unlock_slow_ (nsync_mu *mu, lock_type *l_type) { } /* add the new_waiters to the last of the waiters. */ - nsync_maybe_merge_conditions_ (nsync_dll_last_ (waiters), - nsync_dll_first_ (new_waiters)); - waiters = nsync_dll_make_last_in_list_ (waiters, - nsync_dll_last_ (new_waiters)); + nsync_maybe_merge_conditions_ (dll_last (waiters), + dll_first (new_waiters)); + dll_make_last (&waiters, dll_last (new_waiters)); /* Pick up the next set of new waiters. */ new_waiters = mu->waiters; mu->waiters = NULL; @@ -415,7 +412,7 @@ void nsync_mu_unlock_slow_ (nsync_mu *mu, lock_type *l_type) { /* Return the local waiter list to *mu. */ mu->waiters = waiters; - if (nsync_dll_is_empty_ (wake)) { + if (dll_is_empty (wake)) { /* not waking a waiter => no designated waker */ clear_on_release |= MU_DESIG_WAKER; } @@ -425,7 +422,7 @@ void nsync_mu_unlock_slow_ (nsync_mu *mu, lock_type *l_type) { clear_on_release |= MU_ALL_FALSE; } - if (nsync_dll_is_empty_ (mu->waiters)) { + if (dll_is_empty (mu->waiters)) { /* no waiters left */ clear_on_release |= MU_WAITING | MU_WRITER_WAITING | MU_CONDITION | MU_ALL_FALSE; @@ -443,9 +440,9 @@ void nsync_mu_unlock_slow_ (nsync_mu *mu, lock_type *l_type) { old_word = ATM_LOAD (&mu->word); } /* Wake the waiters. */ - for (p = nsync_dll_first_ (wake); p != NULL; p = next) { - next = nsync_dll_next_ (wake, p); - wake = nsync_dll_remove_ (wake, p); + for (p = dll_first (wake); p != NULL; p = next) { + next = dll_next (wake, p); + dll_remove (&wake, p); ATM_STORE_REL (&DLL_NSYNC_WAITER (p)->waiting, 0); nsync_mu_semaphore_v (&DLL_WAITER (p)->sem); } diff --git a/third_party/nsync/mu.h b/third_party/nsync/mu.h index 600fc8770..ed16eb4dd 100644 --- a/third_party/nsync/mu.h +++ b/third_party/nsync/mu.h @@ -1,11 +1,10 @@ #ifndef NSYNC_MU_H_ #define NSYNC_MU_H_ +#include "libc/intrin/dll.h" #include "third_party/nsync/atomic.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ -struct nsync_dll_element_s_; - /* An nsync_mu is a lock. If initialized to zero, it's valid and unlocked. An nsync_mu can be "free", held by a single thread (aka fiber, @@ -49,9 +48,9 @@ struct nsync_dll_element_s_; */ typedef struct nsync_mu_s_ { - nsync_atomic_uint32_ word; /* internal use only */ - int _zero; /* c pthread_mutex_t */ - struct nsync_dll_element_s_ *waiters; /* internal use only */ + nsync_atomic_uint32_ word; /* internal use only */ + int _zero; /* c pthread_mutex_t */ + struct Dll *waiters; /* internal use only */ } nsync_mu; /* An nsync_mu should be zeroed to initialize, which can be accomplished diff --git a/third_party/nsync/mu_semaphore_futex.c b/third_party/nsync/mu_semaphore_futex.c index 23d67267a..2a3c69b6e 100644 --- a/third_party/nsync/mu_semaphore_futex.c +++ b/third_party/nsync/mu_semaphore_futex.c @@ -88,7 +88,7 @@ errno_t nsync_mu_semaphore_p_with_deadline_futex (nsync_semaphore *s, nsync_time struct timespec ts_buf; const struct timespec *ts = NULL; if (nsync_time_cmp (abs_deadline, nsync_time_no_deadline) != 0) { - memset (&ts_buf, 0, sizeof (ts_buf)); + bzero (&ts_buf, sizeof (ts_buf)); ts_buf.tv_sec = NSYNC_TIME_SEC (abs_deadline); ts_buf.tv_nsec = NSYNC_TIME_NSEC (abs_deadline); ts = &ts_buf; diff --git a/third_party/nsync/mu_semaphore_gcd.c b/third_party/nsync/mu_semaphore_gcd.c index cc8a4413e..364b0682d 100644 --- a/third_party/nsync/mu_semaphore_gcd.c +++ b/third_party/nsync/mu_semaphore_gcd.c @@ -82,7 +82,7 @@ errno_t nsync_mu_semaphore_p_with_deadline_gcd (nsync_semaphore *s, DISPATCH_TIME_FOREVER); } else { struct timespec ts; - memset (&ts, 0, sizeof (ts)); + bzero (&ts, sizeof (ts)); ts.tv_sec = NSYNC_TIME_SEC (abs_deadline); ts.tv_nsec = NSYNC_TIME_NSEC (abs_deadline); if (dispatch_semaphore_wait (*(dispatch_semaphore_t *)s, diff --git a/third_party/nsync/nsync.mk b/third_party/nsync/nsync.mk index ccb17bff2..dc9374dec 100644 --- a/third_party/nsync/nsync.mk +++ b/third_party/nsync/nsync.mk @@ -48,7 +48,7 @@ $(THIRD_PARTY_NSYNC_A).pkg: \ $(THIRD_PARTY_NSYNC_A_OBJS) \ $(foreach x,$(THIRD_PARTY_NSYNC_A_DIRECTDEPS),$($(x)_A).pkg) -$(THIRD_PARTY_NSYNC_A_OBJS): private \ +#$(THIRD_PARTY_NSYNC_A_OBJS): private \ CCFLAGS += \ -ffunction-sections \ -fdata-sections diff --git a/third_party/nsync/testing/cv_mu_timeout_stress_test_.c b/third_party/nsync/testing/cv_mu_timeout_stress_test_.c index 5da2e88b8..9b28a3abd 100644 --- a/third_party/nsync/testing/cv_mu_timeout_stress_test_.c +++ b/third_party/nsync/testing/cv_mu_timeout_stress_test_.c @@ -499,7 +499,7 @@ static void test_cv_timeout_stress (testing t) { nsync_time deadline; deadline = nsync_time_add (nsync_time_now (), nsync_time_ms (5000)); do { - memset ((void *) &s, 0, sizeof (s)); + bzero ((void *) &s, sizeof (s)); s.loop_count = loop_count; s.cv_threads_per_value = 4; s.cv_reader_threads_per_value = 2; @@ -519,7 +519,7 @@ static void test_mu_timeout_stress (testing t) { nsync_time deadline; deadline = nsync_time_add (nsync_time_now (), nsync_time_ms (5000)); do { - memset ((void *) &s, 0, sizeof (s)); + bzero ((void *) &s, sizeof (s)); s.loop_count = loop_count; s.cv_threads_per_value = 0; s.cv_reader_threads_per_value = 0; @@ -539,7 +539,7 @@ static void test_mu_cv_timeout_stress (testing t) { nsync_time deadline; deadline = nsync_time_add (nsync_time_now (), nsync_time_ms (5000)); do { - memset ((void *) &s, 0, sizeof (s)); + bzero ((void *) &s, sizeof (s)); s.loop_count = loop_count; s.cv_threads_per_value = 4; s.cv_reader_threads_per_value = 1; diff --git a/third_party/nsync/testing/cv_test.c b/third_party/nsync/testing/cv_test.c index 7a06d71ca..01c042d9a 100644 --- a/third_party/nsync/testing/cv_test.c +++ b/third_party/nsync/testing/cv_test.c @@ -15,12 +15,12 @@ │ See the License for the specific language governing permissions and │ │ limitations under the License. │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "third_party/nsync/cv.h" #include "libc/errno.h" #include "libc/fmt/fmt.h" #include "libc/mem/mem.h" #include "libc/runtime/runtime.h" #include "libc/str/str.h" -#include "third_party/nsync/cv.h" #include "third_party/nsync/debug.h" #include "third_party/nsync/mu.h" #include "third_party/nsync/mu_wait.h" @@ -51,7 +51,7 @@ static cv_queue *cv_queue_new (int limit) { cv_queue *q; int size = offsetof (struct cv_queue_s, data) + sizeof (q->data[0]) * limit; q = (cv_queue *) malloc (size); - memset ((void *) q, 0, size); + bzero ((void *) q, size); q->limit = limit; return (q); } @@ -481,7 +481,7 @@ static void test_cv_debug (testing t) { int buflen; struct debug_state xs; struct debug_state *s = &xs; - memset ((void *) s, 0, sizeof (*s)); + bzero ((void *) s, sizeof (*s)); /* Use nsync_*_debugger to check that they work. */ tmp = nsync_mu_debugger (&s->mu); @@ -708,7 +708,7 @@ static void test_cv_transfer (testing t) { TEST_LOG (t, ("transfer waiters %d wakeup_type %d cv_writers %d ccs_reader %d\n", waiters, wakeup_type, cv_writers, ccs_reader)); } - memset ((void *) cvt, 0, sizeof (*cvt)); + bzero ((void *) cvt, sizeof (*cvt)); /* Start the waiter threads that use condition variables. */ for (i = 0; i < waiters-1; i++) { diff --git a/third_party/nsync/testing/cv_wait_example_test.c b/third_party/nsync/testing/cv_wait_example_test.c index 8b21471f6..0682e9fe3 100644 --- a/third_party/nsync/testing/cv_wait_example_test.c +++ b/third_party/nsync/testing/cv_wait_example_test.c @@ -149,8 +149,8 @@ static void example_cv_wait (testing t) { "five\n" "timeout 1s\n"; - memset ((void *) &q, 0, sizeof (q)); - memset (&output, 0, sizeof (output)); + bzero ((void *) &q, sizeof (q)); + bzero (&output, sizeof (output)); closure_fork (closure_add_and_wait_cv (&add_and_wait_cv, &q, nsync_time_ms (500), NELEM (input), input)); diff --git a/third_party/nsync/testing/dll_test.c b/third_party/nsync/testing/dll_test.c index 226f1f3b2..425825a5a 100644 --- a/third_party/nsync/testing/dll_test.c +++ b/third_party/nsync/testing/dll_test.c @@ -15,11 +15,12 @@ │ See the License for the specific language governing permissions and │ │ limitations under the License. │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "libc/intrin/dll.h" #include "libc/fmt/fmt.h" +#include "libc/intrin/dll.h" #include "libc/mem/mem.h" #include "libc/str/str.h" #include "third_party/nsync/array.internal.h" -#include "third_party/nsync/dll.h" #include "third_party/nsync/testing/smprintf.h" #include "third_party/nsync/testing/testing.h" // clang-format off @@ -80,25 +81,25 @@ static char *a_string (const a_int *a) { /* A list item for use in the tests below */ struct list_item_s { - nsync_dll_element_ e; + struct Dll e; int i; }; -/* Return a pointer to the struct list_item_s containing nsync_dll_element_ *e_. */ -#define LIST_ITEM(e_) ((struct list_item_s *) ((e_)->container)) +/* Return a pointer to the struct list_item_s containing struct Dll *e_. */ +#define LIST_ITEM(e_) DLL_CONTAINER(struct list_item_s, e, e_) /* Check that list l contains elements containing the values in expected, by scanning both forwards and backwards through the list. Also - verify that nsync_dll_first_() and nsync_dll_last_() return the first and last element - found during those iterations, and that nsync_dll_is_empty_() yields the right value. */ -static void verify_list (testing t, const char *label, nsync_dll_list_ l, + verify that dll_first() and dll_last() return the first and last element + found during those iterations, and that dll_is_empty() yields the right value. */ +static void verify_list (testing t, const char *label, struct Dll *l, const a_int *expected, const char *file, int line) { - nsync_dll_element_ *first; - nsync_dll_element_ *last = NULL; - nsync_dll_element_ *p; + struct Dll *first; + struct Dll *last = NULL; + struct Dll *p; int i = 0; char *expected_str = a_string (expected); - for (p = nsync_dll_first_ (l); p != NULL; p = nsync_dll_next_ (l, p)) { + for (p = dll_first (l); p != NULL; p = dll_next (l, p)) { if (A (expected, i) != LIST_ITEM (p)->i) { TEST_ERROR (t, ("%s:%d; %s:expected=%s: expected %d as " "value %d in list, but found %d\n", @@ -108,10 +109,10 @@ static void verify_list (testing t, const char *label, nsync_dll_list_ l, last = p; i++; } - if (last != nsync_dll_last_ (l)) { + if (last != dll_last (l)) { TEST_ERROR (t, ("%s:%d: %s:expected=%s: expected %p as " "last item in list, but found %p\n", - file, line, label, expected_str, last, nsync_dll_last_ (l))); + file, line, label, expected_str, last, dll_last (l))); } if (i != A_LEN (expected)) { TEST_ERROR (t, ("%s:%d: %s:expected=%s: expected %d items in " @@ -120,7 +121,7 @@ static void verify_list (testing t, const char *label, nsync_dll_list_ l, } first = NULL; - for (p = nsync_dll_last_ (l); p != NULL; p = nsync_dll_prev_ (l, p)) { + for (p = dll_last (l); p != NULL; p = dll_prev (l, p)) { i--; if (A (expected, i) != LIST_ITEM (p)->i) { TEST_ERROR (t, ("%s:%d: %s:expected=%s: expected %d as " @@ -130,10 +131,10 @@ static void verify_list (testing t, const char *label, nsync_dll_list_ l, } first = p; } - if (first != nsync_dll_first_ (l)) { + if (first != dll_first (l)) { TEST_ERROR (t, ("%s:%d: %s:expected=%s: expected %p as " "first item in list, but found %p\n", - file, line, label, expected_str, first, nsync_dll_last_ (l))); + file, line, label, expected_str, first, dll_last (l))); } if (i != 0) { TEST_ERROR (t, ("%s:%d: %s:expected=%s: expected %d items " @@ -142,43 +143,43 @@ static void verify_list (testing t, const char *label, nsync_dll_list_ l, A_LEN (expected), A_LEN (expected)-i)); } - if ((A_LEN (expected) == 0) != nsync_dll_is_empty_ (l)) { - TEST_ERROR (t, ("%s:%d: %s:expected=%s: expected nsync_dll_is_empty_() " + if ((A_LEN (expected) == 0) != dll_is_empty (l)) { + TEST_ERROR (t, ("%s:%d: %s:expected=%s: expected dll_is_empty() " "to yield %d but got %d\n", file, line, label, expected_str, - (A_LEN (expected) == 0), nsync_dll_is_empty_ (l))); + (A_LEN (expected) == 0), dll_is_empty (l))); } free (expected_str); } /* Return a new list containing the count integers from start to start+count-1 by appending successive elements to the list. - This exercises nsync_dll_make_last_in_list_() using singleton elements. */ -static nsync_dll_list_ make_list (int start, int count) { - nsync_dll_list_ l = NULL; + This exercises dll_make_last() using singleton elements. */ +static struct Dll *make_list (int start, int count) { + struct Dll *l = NULL; int i; for (i = start; i != start+count; i++) { struct list_item_s *item = (struct list_item_s *) malloc (sizeof (*item)); - nsync_dll_init_ (&item->e, item); + dll_init (&item->e); item->i = i; - l = nsync_dll_make_last_in_list_ (l, &item->e); + dll_make_last (&l, &item->e); } return (l); } /* Return a new list containing the count integers from start to start+count-1 by prefixing the list with elements, starting with the last. - It exercises nsync_dll_make_first_in_list_() using singleton elements. */ -static nsync_dll_list_ make_rlist (int start, int count) { - nsync_dll_list_ l = NULL; + It exercises dll_make_first() using singleton elements. */ +static struct Dll *make_rlist (int start, int count) { + struct Dll *l = NULL; int i; for (i = start + count - 1; i != start-1; i--) { struct list_item_s *item = (struct list_item_s *) malloc (sizeof (*item)); - nsync_dll_init_ (&item->e, item); + dll_init (&item->e); item->i = i; - l = nsync_dll_make_first_in_list_ (l, &item->e); + dll_make_first (&l, &item->e); } return (l); } @@ -190,16 +191,16 @@ static void test_dll (testing t) { a_int expected; struct list_item_s *item; - nsync_dll_list_ empty = NULL; - nsync_dll_list_ list = NULL; + struct Dll *empty = NULL; + struct Dll *list = NULL; - nsync_dll_list_ x10 = NULL; - nsync_dll_list_ x20 = NULL; - nsync_dll_list_ x30 = NULL; - nsync_dll_list_ x40 = NULL; - nsync_dll_list_ x50 = NULL; + struct Dll *x10 = NULL; + struct Dll *x20 = NULL; + struct Dll *x30 = NULL; + struct Dll *x40 = NULL; + struct Dll *x50 = NULL; - memset (&expected, 0, sizeof (expected)); + bzero (&expected, sizeof (expected)); /* All lists are initially empty. */ verify_list (t, "empty (0)", empty, &a_int_empty, __FILE__, __LINE__); @@ -223,61 +224,60 @@ static void test_dll (testing t) { verify_list (t, "x50", x50, a_set (&expected, 50, 51, 52, -1), __FILE__, __LINE__); /* Check that adding nothing to an empty list leaves it empty. */ - list = nsync_dll_make_first_in_list_ (list, NULL); + dll_make_first (&list, NULL); verify_list (t, "list(1)", list, &a_int_empty, __FILE__, __LINE__); - list = nsync_dll_make_first_in_list_ (list, nsync_dll_first_ (empty)); + dll_make_first (&list, dll_first (empty)); verify_list (t, "list(2)", list, &a_int_empty, __FILE__, __LINE__); - list = nsync_dll_make_first_in_list_ (list, nsync_dll_last_ (empty)); + dll_make_first (&list, dll_last (empty)); verify_list (t, "list(3)", list, &a_int_empty, __FILE__, __LINE__); /* Prefix an empty list with some elements. */ - list = nsync_dll_make_first_in_list_ (list, nsync_dll_first_ (x10)); + dll_make_first (&list, dll_first (x10)); verify_list (t, "list(4)", list, a_set (&expected, 10, 11, 12, -1), __FILE__, __LINE__); /* Check that adding nothing no a non-empty list leaves it unchanged. */ - list = nsync_dll_make_first_in_list_ (list, NULL); + dll_make_first (&list, NULL); verify_list (t, "list(5)", list, a_set (&expected, 10, 11, 12, -1), __FILE__, __LINE__); - list = nsync_dll_make_first_in_list_ (list, nsync_dll_first_ (empty)); + dll_make_first (&list, dll_first (empty)); verify_list (t, "list(6)", list, a_set (&expected, 10, 11, 12, -1), __FILE__, __LINE__); - list = nsync_dll_make_first_in_list_ (list, nsync_dll_last_ (empty)); + dll_make_first (&list, dll_last (empty)); verify_list (t, "list(7)", list, a_set (&expected, 10, 11, 12, -1), __FILE__, __LINE__); /* Check prefixing the list with some elements. */ - list = nsync_dll_make_first_in_list_ (list, nsync_dll_first_ (x20)); + dll_make_first (&list, dll_first (x20)); verify_list (t, "list(8)", list, a_set (&expected, 20, 21, 22, 10, 11, 12, -1), __FILE__, __LINE__); /* Check appending elements to list. */ - list = nsync_dll_make_last_in_list_ (list, nsync_dll_last_ (x30)); + dll_make_last (&list, dll_last (x30)); verify_list (t, "list(9)", list, a_set (&expected, 20, 21, 22, 10, 11, 12, 30, 31, 32, -1), __FILE__, __LINE__); /* Remove the first element. */ - item = (struct list_item_s *) nsync_dll_first_ (list)->container; - list = nsync_dll_remove_ (list, &item->e); + item = (struct list_item_s *) LIST_ITEM (dll_first (list)); + dll_remove (&list, &item->e); verify_list (t, "list(10)", list, a_set (&expected, 21, 22, 10, 11, 12, 30, 31, 32, -1), __FILE__, __LINE__); free (item); /* Remove the last element. */ - item = (struct list_item_s *) nsync_dll_last_ (list)->container; - list = nsync_dll_remove_ (list, &item->e); + item = (struct list_item_s *) LIST_ITEM (dll_last (list)); + dll_remove (&list, &item->e); verify_list (t, "list(11)", list, a_set (&expected, 21, 22, 10, 11, 12, 30, 31, -1), __FILE__, __LINE__); free (item); /* Remove the third element. */ - item = (struct list_item_s *) nsync_dll_next_ (list, - nsync_dll_next_ (list, nsync_dll_first_ (list)))->container; - list = nsync_dll_remove_ (list, &item->e); + item = LIST_ITEM (dll_next (list, dll_next (list, dll_first (list)))); + dll_remove (&list, &item->e); verify_list (t, "list(12)", list, a_set (&expected, 21, 22, 11, 12, 30, 31, -1), __FILE__, __LINE__); @@ -285,10 +285,10 @@ static void test_dll (testing t) { /* Remove all elements. */ a_set (&expected, 21, 22, 11, 12, 30, 31, -1); - for (i = 0; !nsync_dll_is_empty_ (list); i++) { + for (i = 0; !dll_is_empty (list); i++) { char buf[32]; - item = (struct list_item_s *) nsync_dll_first_ (list)->container; - list = nsync_dll_remove_ (list, &item->e); + item = LIST_ITEM (dll_first (list)); + dll_remove (&list, &item->e); a_remove_first (&expected); snprintf (buf, sizeof (buf), "list(13.%d)", i); verify_list (t, buf, list, &expected, __FILE__, __LINE__); @@ -297,22 +297,22 @@ static void test_dll (testing t) { verify_list (t, "list(14)", list, &a_int_empty, __FILE__, __LINE__); /* Append some elements to an empty list. */ - list = nsync_dll_make_last_in_list_ (list, nsync_dll_last_ (x40)); + dll_make_last (&list, dll_last (x40)); verify_list (t, "list(15)", list, a_set (&expected, 40, 41, 42, -1), __FILE__, __LINE__); - /* Use nsync_dll_splice_after_() to put {50, 51, 52} just after 41, which is + /* Use dll_splice_after() to put {50, 51, 52} just after 41, which is next (first (list)). */ - nsync_dll_splice_after_ (nsync_dll_next_ (list, nsync_dll_first_ (list)), nsync_dll_first_ (x50)); + dll_splice_after (dll_next (list, dll_first (list)), dll_first (x50)); verify_list (t, "list(16)", list, a_set (&expected, 40, 41, 50, 51, 52, 42, -1), __FILE__, __LINE__); A_FREE (&expected); - while (!nsync_dll_is_empty_ (list)) { - item = (struct list_item_s *) nsync_dll_first_ (list)->container; - list = nsync_dll_remove_ (list, &item->e); + while (!dll_is_empty (list)) { + item = LIST_ITEM (dll_first (list)); + dll_remove (&list, &item->e); free (item); } } diff --git a/third_party/nsync/testing/mu_starvation_test.c b/third_party/nsync/testing/mu_starvation_test.c index 100897379..15ed904d6 100644 --- a/third_party/nsync/testing/mu_starvation_test.c +++ b/third_party/nsync/testing/mu_starvation_test.c @@ -41,7 +41,7 @@ typedef struct starve_data_s { /* initialize *sd */ static void starve_data_init (starve_data *sd, int threads) { - memset ((void *) sd, 0, sizeof (*sd)); + bzero ((void *) sd, sizeof (*sd)); sd->not_yet_started = threads; sd->not_yet_done = threads; sd->start = nsync_time_now (); diff --git a/third_party/nsync/testing/mu_test.c b/third_party/nsync/testing/mu_test.c index d3b644f76..bd2150d60 100644 --- a/third_party/nsync/testing/mu_test.c +++ b/third_party/nsync/testing/mu_test.c @@ -15,11 +15,11 @@ │ See the License for the specific language governing permissions and │ │ limitations under the License. │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "third_party/nsync/mu.h" #include "libc/calls/calls.h" #include "libc/str/str.h" #include "libc/thread/thread.h" #include "third_party/nsync/cv.h" -#include "third_party/nsync/mu.h" #include "third_party/nsync/mu_wait.h" #include "third_party/nsync/testing/closure.h" #include "third_party/nsync/testing/smprintf.h" @@ -116,7 +116,7 @@ static void test_mu_nthread (testing t) { do { int i; test_data td; - memset ((void *) &td, 0, sizeof (td)); + bzero ((void *) &td, sizeof (td)); td.t = t; td.n_threads = 5; td.loop_count = loop_count; @@ -155,7 +155,7 @@ static void test_mutex_nthread (testing t) { do { int i; test_data td; - memset ((void *) &td, 0, sizeof (td)); + bzero ((void *) &td, sizeof (td)); td.t = t; td.n_threads = 5; td.loop_count = loop_count; @@ -196,7 +196,7 @@ static void test_rwmutex_nthread (testing t) { do { int i; test_data td; - memset ((void *) &td, 0, sizeof (td)); + bzero ((void *) &td, sizeof (td)); td.t = t; td.n_threads = 5; td.loop_count = loop_count; @@ -249,7 +249,7 @@ static void test_try_mu_nthread (testing t) { do { int i; test_data td; - memset ((void *) &td, 0, sizeof (td)); + bzero ((void *) &td, sizeof (td)); td.t = t; td.n_threads = 5; td.loop_count = loop_count; @@ -281,7 +281,7 @@ typedef struct counter_s { /* Return a counter with initial value "initial". */ static counter *counter_new (int initial) { counter *c = (counter *) malloc (sizeof (*c)); - memset ((void *) c, 0, sizeof (*c)); + bzero ((void *) c, sizeof (*c)); c->value = initial; return (c); } @@ -1023,7 +1023,7 @@ static void contended_state_run_test (contended_state *cs, testing t, nsync_mu locks, with small critical sections. */ static void benchmark_mu_contended (testing t) { contended_state cs; - memset ((void *) &cs, 0, sizeof (cs)); + bzero ((void *) &cs, sizeof (cs)); contended_state_run_test (&cs, t, &cs.mu, (void (*) (void*))&nsync_mu_lock, (void (*) (void*))&nsync_mu_unlock); } @@ -1032,7 +1032,7 @@ static void benchmark_mu_contended (testing t) { pthread_mutex_t locks, with small critical sections. */ static void benchmark_mutex_contended (testing t) { contended_state cs; - memset ((void *) &cs, 0, sizeof (cs)); + bzero ((void *) &cs, sizeof (cs)); pthread_mutex_init (&cs.mutex, NULL); contended_state_run_test (&cs, t, &cs.mutex, &void_pthread_mutex_lock, &void_pthread_mutex_unlock); @@ -1043,7 +1043,7 @@ static void benchmark_mutex_contended (testing t) { pthread_rwlock_t locks, with small critical sections. */ static void benchmark_wmutex_contended (testing t) { contended_state cs; - memset ((void *) &cs, 0, sizeof (cs)); + bzero ((void *) &cs, sizeof (cs)); pthread_rwlock_init (&cs.rwmutex, NULL); contended_state_run_test (&cs, t, &cs.rwmutex, &void_pthread_rwlock_wrlock, &void_pthread_rwlock_unlock); diff --git a/third_party/nsync/testing/mu_wait_example_test.c b/third_party/nsync/testing/mu_wait_example_test.c index 1b2cef437..8052ca041 100644 --- a/third_party/nsync/testing/mu_wait_example_test.c +++ b/third_party/nsync/testing/mu_wait_example_test.c @@ -148,8 +148,8 @@ static void example_mu_wait (testing t) { "five\n" "timeout 1s\n"; - memset ((void *) &q, 0, sizeof (q)); - memset (&output, 0, sizeof (output)); + bzero ((void *) &q, sizeof (q)); + bzero (&output, sizeof (output)); closure_fork (closure_add_and_wait_mu (&add_and_wait_mu, &q, nsync_time_ms (500), NELEM (input), input)); diff --git a/third_party/nsync/testing/mu_wait_test.c b/third_party/nsync/testing/mu_wait_test.c index a3fab948e..a0703f038 100644 --- a/third_party/nsync/testing/mu_wait_test.c +++ b/third_party/nsync/testing/mu_wait_test.c @@ -15,10 +15,10 @@ │ See the License for the specific language governing permissions and │ │ limitations under the License. │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "third_party/nsync/mu_wait.h" #include "libc/errno.h" #include "libc/str/str.h" #include "third_party/nsync/mu.h" -#include "third_party/nsync/mu_wait.h" #include "third_party/nsync/note.h" #include "third_party/nsync/testing/closure.h" #include "third_party/nsync/testing/smprintf.h" @@ -44,7 +44,7 @@ static mu_queue *mu_queue_new (int limit) { mu_queue *q; int size = offsetof (struct mu_queue_s, data) + sizeof (q->data[0]) * limit; q = (mu_queue *) malloc (size); - memset ((void *) q, 0, size); + bzero ((void *) q, size); q->limit = limit; return (q); } diff --git a/third_party/nsync/testing/once_test.c b/third_party/nsync/testing/once_test.c index 5de2e8b57..f1fcf1afd 100644 --- a/third_party/nsync/testing/once_test.c +++ b/third_party/nsync/testing/once_test.c @@ -15,11 +15,11 @@ │ See the License for the specific language governing permissions and │ │ limitations under the License. │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "third_party/nsync/once.h" #include "libc/str/str.h" #include "libc/thread/thread.h" #include "third_party/nsync/counter.h" #include "third_party/nsync/mu.h" -#include "third_party/nsync/once.h" #include "third_party/nsync/testing/closure.h" #include "third_party/nsync/testing/smprintf.h" #include "third_party/nsync/testing/testing.h" @@ -99,7 +99,7 @@ static void test_once_run (testing t) { for (i = 0; i != 250; i++) { struct once_test_s *s = (struct once_test_s *) malloc (sizeof (*s)); - memset ((void *) s, 0, sizeof (*s)); + bzero ((void *) s, sizeof (*s)); s->counter = 0; s->done = nsync_counter_new (N); s->t = t; diff --git a/third_party/nsync/testing/pingpong_test.c b/third_party/nsync/testing/pingpong_test.c index dfd6d77ed..f5f8efa32 100644 --- a/third_party/nsync/testing/pingpong_test.c +++ b/third_party/nsync/testing/pingpong_test.c @@ -53,7 +53,7 @@ typedef struct ping_pong_s { } ping_pong; static void ping_pong_init (ping_pong *pp, int limit) { - memset ((void *) pp, 0, sizeof (*pp)); + bzero ((void *) pp, sizeof (*pp)); pthread_mutex_init (&pp->mutex, NULL); pthread_rwlock_init (&pp->rwmutex, NULL); pthread_cond_init (&pp->cond[0], NULL); diff --git a/third_party/nsync/testing/testing.c b/third_party/nsync/testing/testing.c index 0243af185..cdb27cf39 100644 --- a/third_party/nsync/testing/testing.c +++ b/third_party/nsync/testing/testing.c @@ -15,6 +15,7 @@ │ See the License for the specific language governing permissions and │ │ limitations under the License. │ ╚─────────────────────────────────────────────────────────────────────────────*/ +#include "third_party/nsync/testing/testing.h" #include "libc/calls/calls.h" #include "libc/fmt/conv.h" #include "libc/limits.h" @@ -25,14 +26,12 @@ #include "libc/str/str.h" #include "third_party/nsync/atomic.internal.h" #include "third_party/nsync/common.internal.h" -#include "third_party/nsync/dll.h" #include "third_party/nsync/mu.h" #include "third_party/nsync/mu_wait.h" #include "third_party/nsync/races.internal.h" #include "third_party/nsync/testing/atm_log.h" #include "third_party/nsync/testing/closure.h" #include "third_party/nsync/testing/smprintf.h" -#include "third_party/nsync/testing/testing.h" #include "third_party/nsync/testing/time_extra.h" // clang-format off @@ -55,7 +54,7 @@ struct testing_base_s { nsync_mu testing_mu; /* protects fields below */ int is_uniprocessor; /* whether the system is a uniprocessor */ - nsync_dll_list_ children; /* list of testing_s structs whose base is this testing_base_s */ + struct Dll *children; /* list of testing_s structs whose base is this testing_base_s */ int child_count; /* count of testing_s structs whose base is this testing_base_s */ int exit_status; /* final exit status */ }; @@ -70,7 +69,7 @@ struct testing_s { nsync_time stop_time; /* when the timer was stopped; for benchmarks */ void (*f) (testing); /* test function to run */ const char *name; /* name of test */ - nsync_dll_element_ siblings; /* part of list of siblings */ + struct Dll siblings; /* part of list of siblings */ }; /* Output the header for benchmarks. */ @@ -147,7 +146,7 @@ testing_base testing_new (int argc, char *argv[], int flags) { int argn; testing_base tb = (testing_base)malloc (sizeof (*tb)); ShowCrashReports (); - memset ((void *) tb, 0, sizeof (*tb)); + bzero ((void *) tb, sizeof (*tb)); tb->flags = flags; tb->fp = stderr; tb->argc = argc; @@ -224,7 +223,7 @@ static void finish_run (testing t) { if (tb->exit_status < t->test_status) { tb->exit_status = t->test_status; } - tb->children = nsync_dll_remove_ (tb->children, &t->siblings); + dll_remove (&tb->children, &t->siblings); tb->child_count--; nsync_mu_unlock (&tb->testing_mu); free (t); @@ -358,8 +357,8 @@ void testing_run_ (testing_base tb, void (*f) (testing t), const char *name, int (tb->include_pat == NULL || match (tb->include_pat, name)) && (tb->exclude_pat == NULL || !match (tb->exclude_pat, name))) { testing t = (testing) malloc (sizeof (*t)); - memset ((void *) t, 0, sizeof (*t)); - nsync_dll_init_ (&t->siblings, t); + bzero ((void *) t, sizeof (*t)); + dll_init (&t->siblings); t->base = tb; t->f = f; t->name = name; @@ -378,7 +377,7 @@ void testing_run_ (testing_base tb, void (*f) (testing t), const char *name, int nsync_mu_lock (&tb->testing_mu); nsync_mu_wait (&tb->testing_mu, &spare_thread, tb, NULL); tb->child_count++; - tb->children = nsync_dll_make_last_in_list_ (tb->children, &t->siblings); + dll_make_last (&tb->children, &t->siblings); nsync_mu_unlock (&tb->testing_mu); closure_fork (closure_testing (&run_test, t)); } else { @@ -394,7 +393,7 @@ void testing_run_ (testing_base tb, void (*f) (testing t), const char *name, int nsync_mu_lock (&tb->testing_mu); nsync_mu_wait (&tb->testing_mu, &spare_thread, tb, NULL); tb->child_count++; - tb->children = nsync_dll_make_last_in_list_ (tb->children, &t->siblings); + dll_make_last (&tb->children, &t->siblings); nsync_mu_unlock (&tb->testing_mu); closure_fork (closure_testing (&run_benchmark, t)); } diff --git a/third_party/nsync/testing/wait_test.c b/third_party/nsync/testing/wait_test.c index 92e749052..720725dc0 100644 --- a/third_party/nsync/testing/wait_test.c +++ b/third_party/nsync/testing/wait_test.c @@ -60,8 +60,8 @@ static void test_wait_n (testing t) { nsync_time deadline; a_waitable aw; a_pwaitable apw; - memset (&aw, 0, sizeof (aw)); - memset (&apw, 0, sizeof (apw)); + bzero (&aw, sizeof (aw)); + bzero (&apw, sizeof (apw)); now = nsync_time_now (); deadline = nsync_time_add (now, nsync_time_ms (100)); for (j = A_LEN (&aw); A_LEN (&aw) < j+ncounter;) { diff --git a/third_party/nsync/wait_s.internal.h b/third_party/nsync/wait_s.internal.h index ee84040c0..f07c380d7 100644 --- a/third_party/nsync/wait_s.internal.h +++ b/third_party/nsync/wait_s.internal.h @@ -1,7 +1,7 @@ #ifndef COSMOPOLITAN_LIBC_THREAD_WAIT_INTERNAL_H_ #define COSMOPOLITAN_LIBC_THREAD_WAIT_INTERNAL_H_ +#include "libc/intrin/dll.h" #include "third_party/nsync/atomic.h" -#include "third_party/nsync/dll.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ @@ -13,7 +13,7 @@ COSMOPOLITAN_C_START_ struct nsync_waiter_s { uint32_t tag; /* used for debugging */ uint32_t flags; /* see below */ - nsync_dll_element_ q; /* used to link children of parent */ + struct Dll q; /* used to link children of parent */ nsync_atomic_uint32_ waiting; /* non-zero <=> the waiter is waiting */ struct nsync_semaphore_s_ *sem; /* *sem will be Ved when waiter is woken */ }; diff --git a/libc/intrin/bextra.c b/third_party/python/Modules/bextra.c similarity index 91% rename from libc/intrin/bextra.c rename to third_party/python/Modules/bextra.c index 3922daa65..0ec925528 100644 --- a/libc/intrin/bextra.c +++ b/third_party/python/Modules/bextra.c @@ -1,7 +1,7 @@ /*-*- 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 2021 Justine Alexandra Roberts Tunney │ +│ Copyright 2023 Justine Alexandra Roberts Tunney │ │ │ │ Permission to use, copy, modify, and/or distribute this software for │ │ any purpose with or without fee is hereby granted, provided that the │ @@ -16,12 +16,9 @@ │ TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR │ │ PERFORMANCE OF THIS SOFTWARE. │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/bits.h" +#include "third_party/python/Modules/bextra.h" -/** - * Extracts bit field from array. - */ -unsigned _bextra(const unsigned *p, size_t i, char b) { +unsigned BitFieldExtract(const unsigned *p, size_t i, char b) { unsigned k, r, w; w = sizeof(unsigned) * CHAR_BIT; if (b) { diff --git a/third_party/python/Modules/bextra.h b/third_party/python/Modules/bextra.h new file mode 100644 index 000000000..decc57be5 --- /dev/null +++ b/third_party/python/Modules/bextra.h @@ -0,0 +1,10 @@ +#ifndef COSMOPOLITAN_THIRD_PARTY_PYTHON_MODULES_BEXTRA_H_ +#define COSMOPOLITAN_THIRD_PARTY_PYTHON_MODULES_BEXTRA_H_ +#if !(__ASSEMBLER__ + __LINKER__ + 0) +COSMOPOLITAN_C_START_ + +unsigned BitFieldExtract(const unsigned *, size_t, char); + +COSMOPOLITAN_C_END_ +#endif /* !(__ASSEMBLER__ + __LINKER__ + 0) */ +#endif /* COSMOPOLITAN_THIRD_PARTY_PYTHON_MODULES_BEXTRA_H_ */ diff --git a/third_party/python/Modules/unicodedata.c b/third_party/python/Modules/unicodedata.c index af241fd24..279c7d273 100644 --- a/third_party/python/Modules/unicodedata.c +++ b/third_party/python/Modules/unicodedata.c @@ -7,7 +7,6 @@ #define PY_SSIZE_T_CLEAN #include "third_party/python/Modules/unicodedata.h" #include "libc/fmt/fmt.h" -#include "libc/intrin/bits.h" #include "libc/nexgen32e/kompressor.h" #include "third_party/python/Include/floatobject.h" #include "third_party/python/Include/import.h" @@ -21,6 +20,7 @@ #include "third_party/python/Include/structmember.h" #include "third_party/python/Include/ucnhash.h" #include "third_party/python/Include/yoink.h" +#include "third_party/python/Modules/bextra.h" #include "third_party/python/Modules/unicodedata_unidata.h" /* clang-format off */ @@ -405,7 +405,7 @@ unicodedata_UCD_decomposition_impl(PyObject *self, int chr) /* high byte is number of hex bytes (usually one or two), low byte is prefix code (from*/ - count = _bextra(_PyUnicode_Decomp, index, _PyUnicode_DecompBits) >> 8; + count = BitFieldExtract(_PyUnicode_Decomp, index, _PyUnicode_DecompBits) >> 8; /* XXX: could allocate the PyString up front instead (strlen(prefix) + 5 * count + 1 bytes) */ @@ -413,7 +413,7 @@ unicodedata_UCD_decomposition_impl(PyObject *self, int chr) /* Based on how index is calculated above and _PyUnicode_Decomp is generated from Tools/unicode/makeunicodedata.py, it should not be possible to overflow _PyUnicode_DecompPrefix. */ - prefix_index = _bextra(_PyUnicode_Decomp, index, _PyUnicode_DecompBits) & 255; + prefix_index = BitFieldExtract(_PyUnicode_Decomp, index, _PyUnicode_DecompBits) & 255; assert(prefix_index < Py_ARRAY_LENGTH(_PyUnicode_DecompPrefix)); /* copy prefix */ @@ -425,8 +425,8 @@ unicodedata_UCD_decomposition_impl(PyObject *self, int chr) decomp[i++] = ' '; assert(i < sizeof(decomp)); PyOS_snprintf(decomp + i, sizeof(decomp) - i, "%04X", - _bextra(_PyUnicode_Decomp, ++index, - _PyUnicode_DecompBits)); + BitFieldExtract(_PyUnicode_Decomp, ++index, + _PyUnicode_DecompBits)); i += strlen(decomp + i); } return PyUnicode_FromStringAndSize(decomp, i); diff --git a/third_party/python/Modules/unicodedata_getcode.c b/third_party/python/Modules/unicodedata_getcode.c index d6fcebe4e..d5ab2c74d 100644 --- a/third_party/python/Modules/unicodedata_getcode.c +++ b/third_party/python/Modules/unicodedata_getcode.c @@ -5,11 +5,11 @@ │ https://docs.python.org/3/license.html │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/fmt/fmt.h" -#include "libc/intrin/bits.h" #include "third_party/python/Include/pyctype.h" #include "third_party/python/Include/pyerrors.h" #include "third_party/python/Include/pymacro.h" #include "third_party/python/Include/pymem.h" +#include "third_party/python/Modules/bextra.h" #include "third_party/python/Modules/unicodedata.h" #include "third_party/python/Modules/unicodedata_unidata.h" /* clang-format off */ @@ -174,7 +174,7 @@ _PyUnicode_GetCode(PyObject *self, const char *name, int namelen, Py_UCS4 *code, details */ h = (unsigned int)_gethash(name, namelen, _PyUnicode_CodeMagic); i = ~h & mask; - v = _bextra(_PyUnicode_CodeHash, i, _PyUnicode_CodeHashBits); + v = BitFieldExtract(_PyUnicode_CodeHash, i, _PyUnicode_CodeHashBits); if (!v) return 0; if (_cmpname(self, v, name, namelen)) @@ -184,7 +184,7 @@ _PyUnicode_GetCode(PyObject *self, const char *name, int namelen, Py_UCS4 *code, incr = mask; for (;;) { i = (i + incr) & mask; - v = _bextra(_PyUnicode_CodeHash, i, _PyUnicode_CodeHashBits); + v = BitFieldExtract(_PyUnicode_CodeHash, i, _PyUnicode_CodeHashBits); if (!v) return 0; if (_cmpname(self, v, name, namelen)) @@ -247,10 +247,10 @@ _PyUnicode_GetUcName(PyObject *self, Py_UCS4 code, char *buffer, int buflen, } /* get offset into phrasebook */ offset = _PyUnicode_PhrasebookOffset1[(code>>_PyUnicode_PhrasebookShift)]; - offset = _bextra(_PyUnicode_PhrasebookOffset2, - (offset << _PyUnicode_PhrasebookShift) + - (code & ((1 << _PyUnicode_PhrasebookShift) - 1)), - _PyUnicode_PhrasebookOffset2Bits); + offset = BitFieldExtract(_PyUnicode_PhrasebookOffset2, + (offset << _PyUnicode_PhrasebookShift) + + (code & ((1 << _PyUnicode_PhrasebookShift) - 1)), + _PyUnicode_PhrasebookOffset2Bits); if (!offset) return 0; i = 0; @@ -271,8 +271,8 @@ _PyUnicode_GetUcName(PyObject *self, Py_UCS4 code, char *buffer, int buflen, word has bit 7 set. the last word in a string ends with 0x80 */ w = (_PyUnicode_Lexicon + - _bextra(_PyUnicode_LexiconOffset, word, - _PyUnicode_LexiconOffsetBits)); + BitFieldExtract(_PyUnicode_LexiconOffset, word, + _PyUnicode_LexiconOffsetBits)); while (*w < 128) { if (i >= buflen) return 0; /* buffer overflow */ diff --git a/third_party/python/Modules/unicodedata_getdecomprecord.c b/third_party/python/Modules/unicodedata_getdecomprecord.c index 8e8ba1a47..773138006 100644 --- a/third_party/python/Modules/unicodedata_getdecomprecord.c +++ b/third_party/python/Modules/unicodedata_getdecomprecord.c @@ -5,6 +5,7 @@ │ https://docs.python.org/3/license.html │ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "libc/intrin/bits.h" +#include "third_party/python/Modules/bextra.h" #include "third_party/python/Modules/unicodedata.h" #include "third_party/python/Modules/unicodedata_unidata.h" /* clang-format off */ @@ -31,7 +32,7 @@ _PyUnicode_GetDecompRecord(PyObject *self, } /* high byte is number of hex bytes (usually one or two), low byte is prefix code (from*/ - decomp = _bextra(_PyUnicode_Decomp, *index, _PyUnicode_DecompBits); + decomp = BitFieldExtract(_PyUnicode_Decomp, *index, _PyUnicode_DecompBits); *count = decomp >> 8; *prefix = decomp & 255; (*index)++; diff --git a/third_party/python/Modules/unicodedata_nfcnfkc.c b/third_party/python/Modules/unicodedata_nfcnfkc.c index 5ccebd16d..ecf158717 100644 --- a/third_party/python/Modules/unicodedata_nfcnfkc.c +++ b/third_party/python/Modules/unicodedata_nfcnfkc.c @@ -4,10 +4,10 @@ │ Python 3 │ │ https://docs.python.org/3/license.html │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/bits.h" #include "libc/intrin/likely.h" #include "third_party/python/Include/pyerrors.h" #include "third_party/python/Include/pymem.h" +#include "third_party/python/Modules/bextra.h" #include "third_party/python/Modules/unicodedata.h" #include "third_party/python/Modules/unicodedata_unidata.h" /* clang-format off */ @@ -115,10 +115,10 @@ _PyUnicode_NfcNfkc(PyObject *self, PyObject *input, int k) } index = f * UNIDATA_TOTAL_LAST + l; index1 = _PyUnicode_CompIndex[index >> _PyUnicode_CompShift]; - code = _bextra(_PyUnicode_CompData, - (index1 << _PyUnicode_CompShift)+ - (index & ((1 << _PyUnicode_CompShift) - 1)), - _PyUnicode_CompDataBits); + code = BitFieldExtract(_PyUnicode_CompData, + (index1 << _PyUnicode_CompShift)+ + (index & ((1 << _PyUnicode_CompShift) - 1)), + _PyUnicode_CompDataBits); if (code == 0) goto not_combinable; /* Replace the original character. */ diff --git a/third_party/python/Modules/unicodedata_nfdnfkd.c b/third_party/python/Modules/unicodedata_nfdnfkd.c index 03db44c83..88d7726ff 100644 --- a/third_party/python/Modules/unicodedata_nfdnfkd.c +++ b/third_party/python/Modules/unicodedata_nfdnfkd.c @@ -4,9 +4,9 @@ │ Python 3 │ │ https://docs.python.org/3/license.html │ ╚─────────────────────────────────────────────────────────────────────────────*/ -#include "libc/intrin/bits.h" #include "third_party/python/Include/pyerrors.h" #include "third_party/python/Include/pymem.h" +#include "third_party/python/Modules/bextra.h" #include "third_party/python/Modules/unicodedata.h" #include "third_party/python/Modules/unicodedata_unidata.h" /* clang-format off */ @@ -97,9 +97,9 @@ _PyUnicode_NfdNfkd(PyObject *self, PyObject *input, int k) /* Copy decomposition onto the stack, in reverse order. */ while(count) { - code = _bextra(_PyUnicode_Decomp, - index + (--count), - _PyUnicode_DecompBits); + code = BitFieldExtract(_PyUnicode_Decomp, + index + (--count), + _PyUnicode_DecompBits); stack[stackptr++] = code; } } diff --git a/third_party/python/python.mk b/third_party/python/python.mk index e143bf93d..216996f33 100644 --- a/third_party/python/python.mk +++ b/third_party/python/python.mk @@ -156,6 +156,7 @@ THIRD_PARTY_PYTHON_HDRS = \ third_party/python/Include/unicodeobject.h \ third_party/python/Include/warnings.h \ third_party/python/Include/weakrefobject.h \ + third_party/python/Modules/bextra.h \ third_party/python/Modules/unicodedata.h \ third_party/python/Modules/unicodedata_unidata.h \ third_party/python/Modules/_decimal/docstrings.h \ @@ -417,6 +418,7 @@ THIRD_PARTY_PYTHON_STAGE1_A_SRCS = \ third_party/python/Python/sysmodule.c \ third_party/python/Python/thread.c \ third_party/python/Python/traceback.c \ + third_party/python/Modules/bextra.c \ third_party/python/Modules/unicodedata_3.2.0.c \ third_party/python/Modules/unicodedata_bidirectionalnames.c \ third_party/python/Modules/unicodedata_categorynames.c \ diff --git a/third_party/stb/stb_image.c b/third_party/stb/stb_image.c index 3c1759d5e..0f330ea99 100644 --- a/third_party/stb/stb_image.c +++ b/third_party/stb/stb_image.c @@ -50,7 +50,7 @@ http://nothings.org/stb\""); #define idct_block_kernel stbi__idct_block #endif -#define ROL(w, k) ((w) << (k) | CheckUnsigned(w) >> (sizeof(w) * 8 - (k))) +#define ROL(w, k) ((w) << (k) | (w) >> (sizeof(w) * CHAR_BIT - (k))) #ifndef STBI_REALLOC_SIZED #define STBI_REALLOC_SIZED(p, oldsz, newsz) realloc(p, newsz) diff --git a/tool/build/lz4toasm.c b/tool/build/lz4toasm.c index 62f2b62cd..58c6fca5e 100644 --- a/tool/build/lz4toasm.c +++ b/tool/build/lz4toasm.c @@ -26,7 +26,6 @@ #include "libc/mem/mem.h" #include "libc/nexgen32e/kompressor.h" #include "libc/nexgen32e/lz4.h" -#include "libc/runtime/ezmap.internal.h" #include "libc/runtime/runtime.h" #include "libc/stdio/stdio.h" #include "libc/str/str.h" diff --git a/tool/build/mkdeps.c b/tool/build/mkdeps.c index f10227743..323fe2298 100644 --- a/tool/build/mkdeps.c +++ b/tool/build/mkdeps.c @@ -36,7 +36,6 @@ #include "libc/mem/gc.internal.h" #include "libc/mem/mem.h" #include "libc/nexgen32e/crc32.h" -#include "libc/runtime/ezmap.internal.h" #include "libc/runtime/runtime.h" #include "libc/runtime/stack.h" #include "libc/stdio/append.h" diff --git a/tool/viz/lib/boxblur.c b/tool/viz/lib/boxblur.c index 18cb889c5..eb5036a78 100644 --- a/tool/viz/lib/boxblur.c +++ b/tool/viz/lib/boxblur.c @@ -25,5 +25,5 @@ void boxblur(struct Graphic *g) { {+1.0, +1.0, +1.0}, {+1.0, +1.0, +1.0}, }; - convolve(g->yn, g->xn, g->b.p, 3, kBoxBlurKernel, 9.0, 0); + convolve(g->yn, g->xn, g->b, 3, kBoxBlurKernel, 9.0, 0); } diff --git a/tool/viz/lib/convolve.h b/tool/viz/lib/convolve.h index cd67f6be3..3c55a5b8e 100644 --- a/tool/viz/lib/convolve.h +++ b/tool/viz/lib/convolve.h @@ -1,6 +1,7 @@ #ifndef COSMOPOLITAN_TOOL_VIZ_LIB_CONVOLVE_H_ #define COSMOPOLITAN_TOOL_VIZ_LIB_CONVOLVE_H_ #include "dsp/tty/quant.h" +#include "libc/mem/mem.h" #include "libc/str/str.h" #include "tool/viz/lib/graphic.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) @@ -24,7 +25,7 @@ forceinline void convolve(unsigned yn, unsigned xn, ttyrgb_m128 img[yn][xn], } bzero(&g, sizeof(g)); resizegraphic(&g, yn, xn); - tmp = g.b.p; + tmp = g.b; for (y = 0; y < yn - KW; ++y) { for (x = 0; x < xn - KW; ++x) { bzero(&p, sizeof(p)); @@ -37,7 +38,7 @@ forceinline void convolve(unsigned yn, unsigned xn, ttyrgb_m128 img[yn][xn], } } memcpy(img, tmp, yn * xn * sizeof(img[0][0])); - bfree(&g.b); + free(g.b); } COSMOPOLITAN_C_END_ diff --git a/tool/viz/lib/emboss.c b/tool/viz/lib/emboss.c index 1667f48e2..2f6f21df3 100644 --- a/tool/viz/lib/emboss.c +++ b/tool/viz/lib/emboss.c @@ -26,5 +26,5 @@ void emboss(struct Graphic *g) { {-1.0, +1.0, +1.0}, {+0.0, +1.0, +2.0}, }; - convolve(g->yn, g->xn, g->b.p, 3, kEmbossKernel, 1, 0); + convolve(g->yn, g->xn, g->b, 3, kEmbossKernel, 1, 0); } diff --git a/tool/viz/lib/getxtermcodes.c b/tool/viz/lib/getxtermcodes.c index 3241c396f..19aa90f54 100644 --- a/tool/viz/lib/getxtermcodes.c +++ b/tool/viz/lib/getxtermcodes.c @@ -22,7 +22,7 @@ void getxtermcodes(struct TtyRgb *p, const struct Graphic *g) { unsigned y, x; - unsigned char(*img)[3][g->yn][g->xn] = g->b.p; + unsigned char(*img)[3][g->yn][g->xn] = g->b; for (y = 0; y < g->yn; ++y) { for (x = 0; x < g->xn; ++x) { *p++ = rgb2tty((*img)[0][y][x], (*img)[1][y][x], (*img)[2][y][x]); diff --git a/tool/viz/lib/graphic.h b/tool/viz/lib/graphic.h index 5e67094a5..832f82097 100644 --- a/tool/viz/lib/graphic.h +++ b/tool/viz/lib/graphic.h @@ -1,13 +1,12 @@ #ifndef COSMOPOLITAN_TOOL_VIZ_LIB_GRAPHIC_H_ #define COSMOPOLITAN_TOOL_VIZ_LIB_GRAPHIC_H_ #include "dsp/tty/quant.h" -#include "libc/runtime/buffer.internal.h" #if !(__ASSEMBLER__ + __LINKER__ + 0) COSMOPOLITAN_C_START_ struct Graphic { union { - struct GuardedBuffer b; + void *b; char *bytes; float (*lum)[2][8]; float (*rgba)[2][2]; diff --git a/tool/viz/lib/resizegraphic.c b/tool/viz/lib/resizegraphic.c index 483eba161..bcdd443eb 100644 --- a/tool/viz/lib/resizegraphic.c +++ b/tool/viz/lib/resizegraphic.c @@ -18,19 +18,14 @@ ╚─────────────────────────────────────────────────────────────────────────────*/ #include "dsp/tty/quant.h" #include "libc/assert.h" -#include "libc/runtime/buffer.internal.h" +#include "libc/mem/mem.h" #include "tool/viz/lib/graphic.h" -/** - * Allocates graphic. - * - * @param g should be zero initialized before first call - * @note bfree(g->b) needs to be called later - */ +// TODO(jart): DELETE + struct Graphic *resizegraphic(struct Graphic *g, size_t yn, size_t xn) { - /* assert(xn % 2 == 0); */ /* todo: ughhh this whole thing is wrong */ yn &= ~1; - balloc(&g->b, 64, yn * xn * sizeof(ttyrgb_m128) + /* wut */ PAGESIZE); + g->b = pvalloc(yn * xn * sizeof(ttyrgb_m128)); g->yn = yn; g->xn = xn; return g; diff --git a/tool/viz/lib/sobel.c b/tool/viz/lib/sobel.c index 4a5c15451..ff20997b6 100644 --- a/tool/viz/lib/sobel.c +++ b/tool/viz/lib/sobel.c @@ -69,7 +69,7 @@ void sobel(struct Graphic* g) { FLIP(BROADCAST(-2), BROADCAST(+0), BROADCAST(+2)), FLIP(BROADCAST(-1), BROADCAST(+0), BROADCAST(+1))); if (g->yn >= 3 && g->xn >= 3) { - ConvolveGradient(g->yn, g->xn, g->b.p, 3, &kSobelEmbossKernelY, + ConvolveGradient(g->yn, g->xn, g->b, 3, &kSobelEmbossKernelY, &kSobelEmbossKernelX); } } diff --git a/tool/viz/lib/vizlib.mk b/tool/viz/lib/vizlib.mk index 4cf71eeeb..2478aa29a 100644 --- a/tool/viz/lib/vizlib.mk +++ b/tool/viz/lib/vizlib.mk @@ -66,8 +66,7 @@ o/$(MODE)/tool/viz/lib/dither.o \ o/$(MODE)/tool/viz/lib/emboss.o \ o/$(MODE)/tool/viz/lib/getxtermcodes.o \ o/$(MODE)/tool/viz/lib/lingamma.o \ -o/$(MODE)/tool/viz/lib/perlin3.o \ -o/$(MODE)/tool/viz/lib/resizegraphic.o: private \ +o/$(MODE)/tool/viz/lib/perlin3.o: private \ CFLAGS += \ -DSTACK_FRAME_UNLIMITED \ $(MATHEMATICAL) diff --git a/tool/viz/printvideo.c b/tool/viz/printvideo.c index 977eba360..0af0cd4e2 100644 --- a/tool/viz/printvideo.c +++ b/tool/viz/printvideo.c @@ -56,7 +56,6 @@ #include "libc/nexgen32e/x86feature.h" #include "libc/nt/console.h" #include "libc/nt/runtime.h" -#include "libc/runtime/buffer.internal.h" #include "libc/runtime/runtime.h" #include "libc/sock/sock.h" #include "libc/sock/struct/pollfd.h" @@ -173,7 +172,7 @@ mode.\n\ #define BALLOC(B, A, N, NAME) \ ({ \ INFOF("balloc/%s %,zu bytes", NAME, N); \ - balloc(B, A, N); \ + *(B) = pvalloc(N); \ }) #define TIMEIT(OUT_NANOS, FORM) \ @@ -207,7 +206,7 @@ struct NamedVector { struct VtFrame { size_t i, n; union { - struct GuardedBuffer b; + void *b; char *bytes; }; }; @@ -266,6 +265,7 @@ static bool emboss_, sobel_; static volatile int playpid_; static struct winsize wsize_; static float hue_, sat_, lit_; +static void *xtcodes_, *audio_; static struct FrameBuffer fb0_; static unsigned chans_, srate_; static volatile bool ignoresigs_; @@ -277,7 +277,6 @@ static openspeaker_f tryspeakerfns_[4]; static int primaries_, lighting_, swing_; static uint64_t t1, t2, t3, t4, t5, t6, t8; static const char *sox_, *ffplay_, *patharg_; -static struct GuardedBuffer xtcodes_, audio_; static struct VtFrame vtframe_[2], *f1_, *f2_; static struct Graphic graphic_[2], *g1_, *g2_; static bool yes_, stats_, dither_, ttymode_, istango_; @@ -614,7 +613,7 @@ static char *StartRender(char *vt) { static void EndRender(char *vt) { vt += sprintf(vt, "\e[0m"); - f2_->n = (intptr_t)vt - (intptr_t)f2_->b.p; + f2_->n = (intptr_t)vt - (intptr_t)f2_->b; f2_->i = 0; } @@ -692,7 +691,7 @@ static void RenderIt(void) { struct TtyRgb bg, fg; yn = g2_->yn; xn = g2_->xn; - vt = f2_->b.p; + vt = f2_->b; p = StartRender(vt); if (TTYQUANT()->alg == kTtyQuantTrue) { bg = (struct TtyRgb){0, 0, 0, 0}; @@ -708,7 +707,7 @@ static void RenderIt(void) { fg = (struct TtyRgb){0xff, 0xff, 0xff, 231}; p = stpcpy(p, "\e[48;5;16;38;5;231m"); } - p = ttyraster(p, xtcodes_.p, yn, xn, bg, fg); + p = ttyraster(p, xtcodes_, yn, xn, bg, fg); if (ttymode_ && stats_) { bpc = bpf = p - vt; bpc /= wsize_.ws_row * wsize_.ws_col; @@ -759,7 +758,7 @@ static void RasterIt(void) { once = true; } WriteToFrameBuffer(fb0_.vscreen.yres_virtual, fb0_.vscreen.xres_virtual, buf, - g2_->yn, g2_->xn, g2_->b.p, fb0_.vscreen.yres, + g2_->yn, g2_->xn, g2_->b, fb0_.vscreen.yres, fb0_.vscreen.xres); memcpy(fb0_.map, buf, fb0_.size); } @@ -776,7 +775,7 @@ static void TranscodeVideo(plm_frame_t *pf) { if (pf1_) pary_ = 1.; if (pf2_) pary_ = (266 / 64.) * (900 / 1600.); pary_ *= plm_get_pixel_aspect_ratio(plm_); - YCbCr2RgbScale(g2_->yn, g2_->xn, g2_->b.p, pf->y.height, pf->y.width, + YCbCr2RgbScale(g2_->yn, g2_->xn, g2_->b, pf->y.height, pf->y.width, (void *)pf->y.data, pf->cr.height, pf->cr.width, (void *)pf->cb.data, (void *)pf->cr.data, pf->y.height, pf->y.width, pf->cr.height, pf->cr.width, pf->height, @@ -791,7 +790,7 @@ static void TranscodeVideo(plm_frame_t *pf) { boxblur(g2_); break; case kBlurGaussian: - gaussian(g2_->yn, g2_->xn, g2_->b.p); + gaussian(g2_->yn, g2_->xn, g2_->b); break; default: break; @@ -800,16 +799,16 @@ static void TranscodeVideo(plm_frame_t *pf) { if (emboss_) emboss(g2_); switch (sharp_) { case kSharpSharp: - sharpen(3, g2_->yn, g2_->xn, g2_->b.p, g2_->yn, g2_->xn); + sharpen(3, g2_->yn, g2_->xn, g2_->b, g2_->yn, g2_->xn); break; case kSharpUnsharp: - unsharp(3, g2_->yn, g2_->xn, g2_->b.p, g2_->yn, g2_->xn); + unsharp(3, g2_->yn, g2_->xn, g2_->b, g2_->yn, g2_->xn); break; default: break; } if (dither_ && TTYQUANT()->alg != kTtyQuantTrue) { - dither(g2_->yn, g2_->xn, g2_->b.p, g2_->yn, g2_->xn); + dither(g2_->yn, g2_->xn, g2_->b, g2_->yn, g2_->xn); } }); @@ -817,7 +816,7 @@ static void TranscodeVideo(plm_frame_t *pf) { t3 = 0; TIMEIT(t4, RasterIt()); } else { - TIMEIT(t3, getxtermcodes(xtcodes_.p, g2_)); + TIMEIT(t3, getxtermcodes(xtcodes_, g2_)); TIMEIT(t4, RenderIt()); } @@ -1401,19 +1400,16 @@ static void OnExit(void) { ttyidentclear(&ti_); close(infd_), infd_ = -1; close(outfd_), outfd_ = -1; - bfree(&graphic_[0].b); - bfree(&graphic_[1].b); - bfree(&vtframe_[0].b); - bfree(&vtframe_[1].b); - bfree(&xtcodes_); - bfree(&audio_); + free(graphic_[0].b); + free(graphic_[1].b); + free(vtframe_[0].b); + free(vtframe_[1].b); + free(xtcodes_); + free(audio_); CloseSpeaker(); } static void MakeLatencyLittleLessBad(void) { -#ifdef __x86_64__ - _peekall(); -#endif LOGIFNEG1(sys_mlockall(MCL_CURRENT)); LOGIFNEG1(nice(-5)); }