Add x86_64-linux-gnu emulator

I wanted a tiny scriptable meltdown proof way to run userspace programs
and visualize how program execution impacts memory. It helps to explain
how things like Actually Portable Executable works. It can show you how
the GCC generated code is going about manipulating matrices and more. I
didn't feel fully comfortable with Qemu and Bochs because I'm not smart
enough to understand them. I wanted something like gVisor but with much
stronger levels of assurances. I wanted a single binary that'll run, on
all major operating systems with an embedded GPL barrier ZIP filesystem
that is tiny enough to transpile to JavaScript and run in browsers too.

https://justine.storage.googleapis.com/emulator625.mp4
This commit is contained in:
Justine Tunney 2020-08-25 04:23:25 -07:00
parent 467504308a
commit f4f4caab0e
1052 changed files with 65667 additions and 7825 deletions

File diff suppressed because it is too large Load diff

View file

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

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

@ -17,71 +17,216 @@
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA
*/
#include "libc/bits/progn.h"
#include "libc/intrin/palignr.h"
#include "libc/rand/rand.h"
#include "libc/testlib/ezbench.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) {
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);
EXPECT_EQ(4, C[0]);
EXPECT_EQ(5, C[1]);
EXPECT_EQ(6, C[2]);
EXPECT_EQ(7, C[3]);
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);
EXPECT_EQ(1, C[0]);
EXPECT_EQ(2, C[1]);
EXPECT_EQ(3, C[2]);
EXPECT_EQ(4, C[3]);
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);
EXPECT_EQ(2, C[0]);
EXPECT_EQ(3, C[1]);
EXPECT_EQ(4, C[2]);
EXPECT_EQ(5, C[3]);
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);
EXPECT_EQ(4, C[0]);
EXPECT_EQ(5, C[1]);
EXPECT_EQ(6, C[2]);
EXPECT_EQ(7, C[3]);
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);
EXPECT_EQ(5, C[0]);
EXPECT_EQ(6, C[1]);
EXPECT_EQ(7, C[2]);
EXPECT_EQ(8, C[3]);
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);
EXPECT_EQ(6, C[0]);
EXPECT_EQ(7, C[1]);
EXPECT_EQ(8, C[2]);
EXPECT_EQ(0, C[3]);
ASSERT_EQ(6, C[0]);
ASSERT_EQ(7, C[1]);
ASSERT_EQ(8, C[2]);
ASSERT_EQ(0, C[3]);
}
TEST(palignr, test32) {
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);
EXPECT_EQ(0, C[0]);
EXPECT_EQ(0, C[1]);
EXPECT_EQ(0, C[2]);
EXPECT_EQ(0, C[3]);
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]);
}
BENCH(palignr, bench) {
volatile __intrin_xmm_t A;
volatile __intrin_xmm_t B;
EZBENCH2("palignr const 𝑖", donothing, PROGN(palignr(&A, &A, &B, 7)));
EZBENCH2("palignr var 𝑖", donothing,
PROGN(palignr(&A, &A, &B, VEIL("r", 7))));
EZBENCH2("palignr ansi", donothing, PROGN((palignr)(&A, &A, &B, 7)));
}

View file

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

@ -1,48 +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
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,162 @@
/*-*- 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/pshufd.h"
#include "libc/intrin/pshufhw.h"
#include "libc/intrin/pshuflw.h"
#include "libc/rand/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

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

View file

@ -5,12 +5,14 @@ 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_COMS = \
$(TEST_LIBC_INTRIN_SRCS:%.c=o/$(MODE)/%.com)
TEST_LIBC_INTRIN_BINS = \
$(TEST_LIBC_INTRIN_COMS) \
$(TEST_LIBC_INTRIN_COMS:%=%.dbg)
@ -22,12 +24,17 @@ TEST_LIBC_INTRIN_CHECKS = \
$(TEST_LIBC_INTRIN_SRCS_TEST:%.c=o/$(MODE)/%.com.runs)
TEST_LIBC_INTRIN_DIRECTDEPS = \
LIBC_FMT \
LIBC_INTRIN \
LIBC_NEXGEN32E \
LIBC_RAND \
LIBC_LOG \
LIBC_STUBS \
LIBC_TESTLIB \
LIBC_TINYMATH \
TOOL_VIZ_LIB \
LIBC_TESTLIB
LIBC_RUNTIME \
LIBC_X \
TOOL_VIZ_LIB
TEST_LIBC_INTRIN_DEPS := \
$(call uniq,$(foreach x,$(TEST_LIBC_INTRIN_DIRECTDEPS),$($(x))))