Add chibicc

This program popped up on Hacker News recently. It's the only modern
compiler I've ever seen that doesn't have dependencies and is easily
modified. So I added all of the missing GNU extensions I like to use
which means it might be possible soon to build on non-Linux and have
third party not vendor gcc binaries.
This commit is contained in:
Justine Tunney 2020-12-05 12:20:41 -08:00
parent e44a0cf6f8
commit 8da931a7f6
298 changed files with 19493 additions and 11950 deletions

View file

@ -1,88 +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 "dsp/core/core.h"
#include "libc/math.h"
#include "libc/stdio/stdio.h"
#include "libc/str/str.h"
#include "libc/testlib/ezbench.h"
#include "libc/testlib/testlib.h"
#include "libc/time/time.h"
#include "tool/viz/lib/formatstringtable-testlib.h"
TEST(dct, test) {
float M[8][8] /* clang-format off */ = {
{.509804, .513725, .094118, .219608, .027451, .294118, .172549, .658824},
{.019608, .070588, .196078, .015686, .172549, .458824, .713725, .294118},
{.380392, .341176, .235294, .737255, .741176, .968627, .607843, .12549},
{.560784, .843137, .639216, .929412, .756863, .113725, .643137, .435294},
{.878431, .576471, .737255, .356863, .8, .878431, .682353, .866667},
{.780392, .070588, .866667, .607843, .792157, .47451, .427451, .043137},
{.133333, .976471, .698039, .662745, .035294, .207843, .831373, .627451},
{.313725, .580392, .858824, .631373, .784314, .972549, .27451, .94902},
} /* clang-format on */;
dctjpeg(M);
EXPECT_FLTMATRIXEQ(5, rint, 8, 8, M, "\n\
32.86666 -1.46274 -1.4456 -.43895 -1.17255 .19084 .05736 .01672\n\
-9.41551 -2.72135 3.7228 5.47448 .74604 .91144 -1.22542 -.41829\n\
-6.32875 -4.21755 4.42546 -3.86307 -1.93691 -2.1173 1.00377 -1.0752\n\
-2.58232 3.67887 5.65331 -.25753 .89732 1.09837 .93163 .61133\n\
4.23922 1.36747 3.29469 -1.63407 2.78039 -3.0021 .7602 -.21367\n\
-.11643 3.93022 .80678 -3.70514 .13347 .54381 -2.15087 -.52343\n\
.64248 1.19093 -2.94494 2.66037 1.6624 .04414 .99807 .00514\n\
.61622 -.76318 .75918 .41939 -.38075 -.30623 .09867 -.19237");
}
/* TEST(dct, test2) { */
/* float M[8][8] /\* clang-format off *\/ = { */
/* {.5,.5,.5,.5,.5,.5,.5,.5}, */
/* {.5,.5,.5,.5,.5,.5,.5,.5}, */
/* {.5,.5,.5,.5,.5,.5,.5,.5}, */
/* {.5,.5,.5,.5,.5,.5,.5,.5}, */
/* {.5,.5,.5,.5,.5,.5,.5,.5}, */
/* {.5,.5,.5,.5,.5,.5,.5,.5}, */
/* {.5,.5,.5,.5,.5,.5,.5,.5}, */
/* {.5,.5,.5,.5,.5,.5,.5,.5}, */
/* } /\* clang-format on *\/; */
/* dctjpeg(M); */
/* EXPECT_FLTMATRIXEQ(5, rint, 8, 8, M, "\n\ */
/* 32.86666 -1.46274 -1.4456 -.43895 -1.17255 .19084 .05736 .01672\n\ */
/* -9.41551 -2.72135 3.7228 5.47448 .74604 .91144 -1.22542 -.41829\n\ */
/* -6.32875 -4.21755 4.42546 -3.86307 -1.93691 -2.1173 1.00377 -1.0752\n\ */
/* -2.58232 3.67887 5.65331 -.25753 .89732 1.09837 .93163 .61133\n\ */
/* 4.23922 1.36747 3.29469 -1.63407 2.78039 -3.0021 .7602 -.21367\n\ */
/* -.11643 3.93022 .80678 -3.70514 .13347 .54381 -2.15087 -.52343\n\ */
/* .64248 1.19093 -2.94494 2.66037 1.6624 .04414 .99807 .00514\n\ */
/* .61622 -.76318 .75918 .41939 -.38075 -.30623 .09867 -.19237"); */
/* } */
BENCH(dct, bench) {
float M[8][8] /* clang-format off */ = {
{.101961, .486275, .082353, .082353, .937255, .321569, .14902, .270588},
{.384314, .062745, .152941, .003922, .921569, .015686, .247059, 0},
{.760784, .023529, .411765, .443137, .862745, .85098, .435294, .631373},
{.309804, .141176, .54902, .984314, .478431, .6, .364706, .643137},
{.780392, .811765, .458824, .964706, .439216, .941176, .321569, .313725},
{.596078, .207843, .133333, .345098, .278431, .192157, .52549, .627451},
{.952941, .090196, .290196, .717647, .686275, .713725, .54902, .411765},
{.109804, .121569, .403922, .27451, .470588, .007843, .168627, .105882},
} /* clang-format on */;
void *data = tgc(tmalloc(sizeof(M)));
EZBENCH2("dct", memcpy(data, M, sizeof(M)), EXPROPRIATE(dctjpeg(data)));
}

View file

@ -29,18 +29,18 @@ TEST(GetChromaticAdaptationMatrix, testSuperiorIlluminationBannedInCalifornia) {
double M[3][3];
GetChromaticAdaptationMatrix(M, kIlluminantD65, kIlluminantA);
EXPECT_DBLMATRIXEQ(5, rint, 3, 3, M, "\n\
1.21646 .11099 -.15493\n\
.15333 .91523 -.056\n\
-.02395 .0359 .31475");
1.2165 .11099 -.15493\n\
.15333 .91523 -.055995\n\
-.023947 .035898 .31475");
}
TEST(GetChromaticAdaptationMatrix, testD65ToD50_soWeCanCieLab) {
double M[3][3];
GetChromaticAdaptationMatrix(M, kIlluminantD65, kIlluminantD50);
EXPECT_DBLMATRIXEQ(6, rint, 3, 3, M, "\n\
1.047811 .022887 -.050127\n\
.029542 .990484 -.017049\n\
-.009234 .015044 .752132");
1.04781 .0228866 -.050127\n\
.0295424 .990484 -.0170491\n\
-.00923449 .0150436 .752132");
}
BENCH(GetChromaticAdaptationMatrix, bench) {

View file

@ -28,9 +28,9 @@ TEST(inv3, test) {
double M[3][3];
inv3(M, kBradford, det3(kBradford));
EXPECT_DBLMATRIXEQ(7, rint, 3, 3, M, "\n\
.9869929 -.1470543 .1599627\n\
.4323053 .5183603 .0492912\n\
-.0085287 .0400428 .9684867");
.9869929 -.1470543 .1599627\n\
.4323053 .5183603 .04929123\n\
-.008528665 .04004282 .9684867");
}
BENCH(inv3, bench) {

View file

@ -31,7 +31,7 @@ unsigned windex$k8(short *, size_t) hidden;
unsigned windex$avx2(short *, size_t) hidden;
unsigned windex$sse4(short *, size_t) hidden;
const short kW[64] aligned(32) = {
const short kW[64] forcealign(32) = {
8281, 3883, 1365, 1786, 9006, 3681, 5563, 8013, 5787, 9063, 2923,
3564, 6122, 32, 1436, 0741, 7957, 9219, 1320, 2083, 1904, 8905,
2465, 9122, 9563, 1290, 4474, 3988, 9920, 8325, 1088, 2915, 33,
@ -40,13 +40,13 @@ const short kW[64] aligned(32) = {
1730, 2041, 7707, 5096, 6876, 1324, 1242, 5283, 0x7fff,
};
const short kW2[32] aligned(32) = {
const short kW2[32] forcealign(32) = {
8281, 1, 1365, 1786, 9006, 3681, 5563, 8013, 5787, 9063, 2923,
3564, 6122, 32, 1436, 0741, 7957, 9219, 1320, 2083, 1904, 8905,
2465, 9122, 9563, 1290, 4474, 3988, 9920, 8325, 1088, 2915,
};
const short kW3[64] aligned(32) = {
const short kW3[64] forcealign(32) = {
8281, 0x7fff, 1365, 1786, 9006, 3681, 5563, 8013, 5787, 9063, 2923,
3564, 6122, 32, 1436, 0741, 7957, 9219, 1320, 2083, 1904, 8905,
2465, 9122, 9563, 1290, 4474, 3988, 9920, 8325, 1088, 2915, 33,
@ -64,7 +64,7 @@ const short kW3[64] aligned(32) = {
})
TEST(windex, testRealWorldPicks) {
const short kPicks[96] aligned(32) = {
const short kPicks[96] forcealign(32) = {
103, 85, 145, 146, 121, 103, 145, 187, 146, 189,
121, 103, 139, 121, 63, 105, 105, 147, 60, 103,
103, 146, 121, 103, 139, 121, 139, 121, 157, 139,