Clean up more code

The *NSYNC linked list API is good enough that it deserves to be part of
the C libray, so this change writes an improved version of it which uses
that offsetof() trick from the Linux Kernel. We vendor all of the *NSYNC
tests in third_party which helped confirm the needed refactoring is safe

This change also deletes more old code that didn't pan out. My goal here
is to work towards a vision where the Cosmopolitan core libraries become
less experimental and more focused on curation. This better reflects the
current level of quality we've managed to achieve.
This commit is contained in:
Justine Tunney 2023-07-06 06:57:28 -07:00
parent 88612a2cd7
commit 0a24b4fc3c
No known key found for this signature in database
GPG key ID: BE714B4575D6E328
268 changed files with 632 additions and 8688 deletions

View file

@ -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));
}

View file

@ -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);
}

View file

@ -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));
}

File diff suppressed because it is too large Load diff

View file

@ -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"

View file

@ -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]);
}

View file

@ -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]));
}

View file

@ -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);
}
}

View file

@ -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);
}

View file

@ -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;