Initial import

This commit is contained in:
Justine Tunney 2020-06-15 07:18:57 -07:00
commit c91b3c5006
14915 changed files with 590219 additions and 0 deletions

View file

@ -0,0 +1,70 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2020 Justine Alexandra Roberts Tunney
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/intrin/packsswb.h"
#include "libc/intrin/packuswb.h"
#include "libc/limits.h"
#include "libc/nexgen32e/kcpuids.h"
#include "libc/str/str.h"
#include "libc/testlib/testlib.h"
const short S[8] = {0, 128, -128, 255, SHRT_MAX, SHRT_MIN, 0, 0};
TEST(packuswb, test) {
unsigned char B[16] = {0};
packuswb(B, S, S);
EXPECT_EQ(0, B[0]);
EXPECT_EQ(128, B[1]);
EXPECT_EQ(0, B[2]);
EXPECT_EQ(255, B[3]);
EXPECT_EQ(255, B[4]);
EXPECT_EQ(0, B[5]);
EXPECT_EQ(0, B[6]);
EXPECT_EQ(0, B[7]);
EXPECT_EQ(0, B[8]);
EXPECT_EQ(128, B[9]);
EXPECT_EQ(0, B[10]);
EXPECT_EQ(255, B[11]);
EXPECT_EQ(255, B[12]);
EXPECT_EQ(0, B[13]);
EXPECT_EQ(0, B[14]);
EXPECT_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);
EXPECT_EQ(0, B[0]);
EXPECT_EQ(127, B[1]);
EXPECT_EQ(-128, B[2]);
EXPECT_EQ(127, B[3]);
EXPECT_EQ(127, B[4]);
EXPECT_EQ(-128, B[5]);
EXPECT_EQ(0, B[6]);
EXPECT_EQ(0, B[7]);
EXPECT_EQ(0, B[8]);
EXPECT_EQ(127, B[9]);
EXPECT_EQ(-128, B[10]);
EXPECT_EQ(127, B[11]);
EXPECT_EQ(127, B[12]);
EXPECT_EQ(-128, B[13]);
EXPECT_EQ(0, B[14]);
EXPECT_EQ(0, B[15]);
}

View file

@ -0,0 +1,55 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2020 Justine Alexandra Roberts Tunney
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/intrin/paddsw.h"
#include "libc/intrin/paddw.h"
#include "libc/limits.h"
#include "libc/testlib/testlib.h"
TEST(paddw, test) {
short A[8] = {7};
short B[8] = {11};
short C[8];
paddw(C, A, B);
EXPECT_EQ(18, C[0]);
}
TEST(paddsw, test) {
short A[8] = {7};
short B[8] = {11};
short C[8];
paddsw(C, A, B);
EXPECT_EQ(18, C[0]);
}
TEST(paddw, testOverflow_wrapsAround) {
short A[8] = {SHRT_MAX, SHRT_MIN};
short B[8] = {1, -1};
paddw(A, A, B);
EXPECT_EQ(SHRT_MIN, A[0]);
EXPECT_EQ(SHRT_MAX, A[1]);
}
TEST(paddsw, testOverflow_saturates) {
short A[8] = {SHRT_MAX, SHRT_MIN};
short B[8] = {1, -1};
paddsw(A, A, B);
EXPECT_EQ(SHRT_MAX, A[0]);
EXPECT_EQ(SHRT_MIN, A[1]);
}

View file

@ -0,0 +1,87 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2020 Justine Alexandra Roberts Tunney
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/intrin/palignr.h"
#include "libc/testlib/testlib.h"
const int A[4] = {1, 2, 3, 4};
const int B[4] = {5, 6, 7, 8};
TEST(palignr, testLeftpad) {
int C[4] = {0};
palignr(C, B, A, 12);
EXPECT_EQ(4, C[0]);
EXPECT_EQ(5, C[1]);
EXPECT_EQ(6, C[2]);
EXPECT_EQ(7, C[3]);
}
TEST(palignr, test0) {
int C[4];
palignr(C, B, A, 0);
EXPECT_EQ(1, C[0]);
EXPECT_EQ(2, C[1]);
EXPECT_EQ(3, C[2]);
EXPECT_EQ(4, C[3]);
}
TEST(palignr, test4) {
int C[4];
palignr(C, B, A, 4);
EXPECT_EQ(2, C[0]);
EXPECT_EQ(3, C[1]);
EXPECT_EQ(4, C[2]);
EXPECT_EQ(5, C[3]);
}
TEST(palignr, test12) {
int C[4];
palignr(C, B, A, 12);
EXPECT_EQ(4, C[0]);
EXPECT_EQ(5, C[1]);
EXPECT_EQ(6, C[2]);
EXPECT_EQ(7, C[3]);
}
TEST(palignr, test16) {
int C[4];
palignr(C, B, A, 16);
EXPECT_EQ(5, C[0]);
EXPECT_EQ(6, C[1]);
EXPECT_EQ(7, C[2]);
EXPECT_EQ(8, C[3]);
}
TEST(palignr, test20) {
int C[4] = {-1, -1, -1, -1};
palignr(C, B, A, 20);
EXPECT_EQ(6, C[0]);
EXPECT_EQ(7, C[1]);
EXPECT_EQ(8, C[2]);
EXPECT_EQ(0, C[3]);
}
TEST(palignr, test32) {
int C[4] = {-1, -1, -1, -1};
palignr(C, B, A, 32);
EXPECT_EQ(0, C[0]);
EXPECT_EQ(0, C[1]);
EXPECT_EQ(0, C[2]);
EXPECT_EQ(0, C[3]);
}

View file

@ -0,0 +1,46 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2020 Justine Alexandra Roberts Tunney
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/intrin/phaddsw.h"
#include "libc/str/str.h"
#include "libc/testlib/testlib.h"
#include "tool/viz/lib/formatstringtable-testlib.h"
/* clang-format off */
FIXTURE(phaddsw, disableHardwareExtensions) {
memset((/*unconst*/ void *)kCpuids, 0, sizeof(kCpuids));
}
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");
}

View file

@ -0,0 +1,48 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2020 Justine Alexandra Roberts Tunney
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/intrin/phaddw.h"
#include "libc/str/str.h"
#include "libc/testlib/testlib.h"
#include "tool/viz/lib/formatstringtable-testlib.h"
/* clang-format off */
FIXTURE(phaddw, disableHardwareExtensions) {
memset((/*unconst*/ void *)kCpuids, 0, sizeof(kCpuids));
}
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");
}

View file

@ -0,0 +1,116 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2020 Justine Alexandra Roberts Tunney
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "dsp/core/q.h"
#include "libc/intrin/pmulhrsw.h"
#include "libc/macros.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) {
memset((/*unconst*/ void *)kCpuids, 0, sizeof(kCpuids));
}
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]);
}
}
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]));
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

@ -0,0 +1,38 @@
/*-*- mode:c;indent-tabs-mode:nil;c-basic-offset:2;tab-width:8;coding:utf-8 -*-│
vi: set net ft=c ts=2 sts=2 sw=2 fenc=utf-8 :vi
Copyright 2020 Justine Alexandra Roberts Tunney
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; version 2 of the License.
This program is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/intrin/psraw.h"
#include "libc/limits.h"
#include "libc/testlib/testlib.h"
TEST(psraw, testPositive) {
short A[8] = {1, 2, SHRT_MAX};
psraw(A, A, 1);
EXPECT_EQ(0, A[0]);
EXPECT_EQ(1, A[1]);
EXPECT_EQ(SHRT_MAX / 2, A[2]);
}
TEST(psraw, testNegative) {
short A[8] = {-1, -2, SHRT_MIN};
psraw(A, A, 1);
EXPECT_EQ(-1, A[0]);
EXPECT_EQ(-1, A[1]);
EXPECT_EQ(SHRT_MIN / 2, A[2]);
}

51
test/libc/intrin/test.mk Normal file
View file

@ -0,0 +1,51 @@
#-*-mode:makefile-gmake;indent-tabs-mode:t;tab-width:8;coding:utf-8-*-┐
#───vi: set et ft=make ts=8 tw=8 fenc=utf-8 :vi───────────────────────┘
PKGS += TEST_LIBC_INTRIN
TEST_LIBC_INTRIN_SRCS := $(wildcard test/libc/intrin/*.c)
TEST_LIBC_INTRIN_SRCS_TEST = $(filter %_test.c,$(TEST_LIBC_INTRIN_SRCS))
TEST_LIBC_INTRIN_COMS = $(TEST_LIBC_INTRIN_OBJS:%.o=%.com)
TEST_LIBC_INTRIN_OBJS = \
$(TEST_LIBC_INTRIN_SRCS:%=o/$(MODE)/%.zip.o) \
$(TEST_LIBC_INTRIN_SRCS:%.c=o/$(MODE)/%.o)
TEST_LIBC_INTRIN_BINS = \
$(TEST_LIBC_INTRIN_COMS) \
$(TEST_LIBC_INTRIN_COMS:%=%.dbg)
TEST_LIBC_INTRIN_TESTS = \
$(TEST_LIBC_INTRIN_SRCS_TEST:%.c=o/$(MODE)/%.com.ok)
TEST_LIBC_INTRIN_CHECKS = \
$(TEST_LIBC_INTRIN_SRCS_TEST:%.c=o/$(MODE)/%.com.runs)
TEST_LIBC_INTRIN_DIRECTDEPS = \
LIBC_INTRIN \
LIBC_NEXGEN32E \
LIBC_STUBS \
LIBC_TINYMATH \
TOOL_VIZ_LIB \
LIBC_TESTLIB
TEST_LIBC_INTRIN_DEPS := \
$(call uniq,$(foreach x,$(TEST_LIBC_INTRIN_DIRECTDEPS),$($(x))))
o/$(MODE)/test/libc/intrin/intrin.pkg: \
$(TEST_LIBC_INTRIN_OBJS) \
$(foreach x,$(TEST_LIBC_INTRIN_DIRECTDEPS),$($(x)_A).pkg)
o/$(MODE)/test/libc/intrin/%.com.dbg: \
$(TEST_LIBC_INTRIN_DEPS) \
o/$(MODE)/test/libc/intrin/%.o \
o/$(MODE)/test/libc/intrin/intrin.pkg \
$(LIBC_TESTMAIN) \
$(CRT) \
$(APE)
@$(APELINK)
.PHONY: o/$(MODE)/test/libc/intrin
o/$(MODE)/test/libc/intrin: \
$(TEST_LIBC_INTRIN_BINS) \
$(TEST_LIBC_INTRIN_CHECKS)