clang-format

This commit is contained in:
2024-09-10 13:03:02 -04:00
parent 53c617d779
commit d66450e427
381 changed files with 28864 additions and 34170 deletions

View File

@@ -40,46 +40,40 @@
/*
* comparison functions for qsort
*/
static
int
uintcmp(const void *av, const void *bv)
{
unsigned a = *(const unsigned *)av;
unsigned b = *(const unsigned *)bv;
static int uintcmp(const void *av, const void *bv) {
unsigned a = *(const unsigned *)av;
unsigned b = *(const unsigned *)bv;
if (a < b) {
return -1;
}
if (a > b) {
return 1;
}
return 0;
if (a < b) {
return -1;
}
if (a > b) {
return 1;
}
return 0;
}
static
int
altcmp(const void *av, const void *bv)
{
unsigned a = *(const unsigned *)av;
unsigned b = *(const unsigned *)bv;
unsigned ax = (a & 0xffff0000) >> 16;
unsigned ay = a & 0xffff;
unsigned bx = (b & 0xffff0000) >> 16;
unsigned by = b & 0xffff;
static int altcmp(const void *av, const void *bv) {
unsigned a = *(const unsigned *)av;
unsigned b = *(const unsigned *)bv;
unsigned ax = (a & 0xffff0000) >> 16;
unsigned ay = a & 0xffff;
unsigned bx = (b & 0xffff0000) >> 16;
unsigned by = b & 0xffff;
if (ax < bx) {
return 1;
}
if (ax > bx) {
return -1;
}
if (ay < by) {
return -1;
}
if (ay > by) {
return 1;
}
return 0;
if (ax < bx) {
return 1;
}
if (ax > bx) {
return -1;
}
if (ay < by) {
return -1;
}
if (ay > by) {
return 1;
}
return 0;
}
#if 0
@@ -104,35 +98,29 @@ shuffle(unsigned *p, unsigned n)
/*
* Compute first differences.
*/
static
void
diffs(unsigned *p, unsigned n)
{
unsigned p0;
unsigned i;
static void diffs(unsigned *p, unsigned n) {
unsigned p0;
unsigned i;
p0 = p[0];
p0 = p[0];
for (i=0; i<n-1; i++) {
p[i] = p[i] - p[i+1];
}
p[n-1] = p[n-1] - p0;
for (i = 0; i < n - 1; i++) {
p[i] = p[i] - p[i + 1];
}
p[n - 1] = p[n - 1] - p0;
}
/*
* Take the sum.
*/
static
unsigned
sum(const unsigned *p, unsigned n)
{
unsigned t, i;
static unsigned sum(const unsigned *p, unsigned n) {
unsigned t, i;
t = 0;
for (i=0; i<n; i++) {
t += p[i];
}
return t;
t = 0;
for (i = 0; i < n; i++) {
t += p[i];
}
return t;
}
/*
@@ -140,66 +128,64 @@ sum(const unsigned *p, unsigned n)
*
* Note that this won't work until you have a VM system.
*/
void
grind(unsigned groupid, unsigned id)
{
unsigned *p;
unsigned i, n, s;
void grind(unsigned groupid, unsigned id) {
unsigned *p;
unsigned i, n, s;
(void)groupid;
(void)groupid;
waitstart();
waitstart();
/* each grind task uses 768K */
n = (768*1024) / sizeof(*p);
p = malloc(n * sizeof(*p));
if (p == NULL) {
if (errno == ENOSYS) {
/*
* If we don't have sbrk, just bail out with
* "success" instead of failing the whole
* workload.
*/
errx(0, "grind: sbrk/malloc not implemented");
}
err(1, "malloc");
}
/* each grind task uses 768K */
n = (768 * 1024) / sizeof(*p);
p = malloc(n * sizeof(*p));
if (p == NULL) {
if (errno == ENOSYS) {
/*
* If we don't have sbrk, just bail out with
* "success" instead of failing the whole
* workload.
*/
errx(0, "grind: sbrk/malloc not implemented");
}
err(1, "malloc");
}
/* First, get some random integers. */
warnx("grind %u: seeding", id);
srandom(1753);
for (i=0; i<n; i++) {
p[i] = random();
}
/* First, get some random integers. */
warnx("grind %u: seeding", id);
srandom(1753);
for (i = 0; i < n; i++) {
p[i] = random();
}
/* Now sort them. */
warnx("grind %u: sorting", id);
qsort(p, n, sizeof(p[0]), uintcmp);
/* Now sort them. */
warnx("grind %u: sorting", id);
qsort(p, n, sizeof(p[0]), uintcmp);
/* Sort by a different comparison. */
warnx("grind %u: sorting alternately", id);
qsort(p, n, sizeof(p[0]), altcmp);
/* Sort by a different comparison. */
warnx("grind %u: sorting alternately", id);
qsort(p, n, sizeof(p[0]), altcmp);
/* Take the sum. */
warnx("grind %u: summing", id);
s = sum(p, n);
warnx("grind %u: sum is %u (should be %u)", id, s, RIGHT);
if (s != RIGHT) {
errx(1, "grind %u FAILED", id);
}
/* Take the sum. */
warnx("grind %u: summing", id);
s = sum(p, n);
warnx("grind %u: sum is %u (should be %u)", id, s, RIGHT);
if (s != RIGHT) {
errx(1, "grind %u FAILED", id);
}
/* Take first differences. */
warnx("grind %u: first differences", id);
diffs(p, n);
/* Take first differences. */
warnx("grind %u: first differences", id);
diffs(p, n);
/* Sort. */
warnx("grind %u: sorting", id);
qsort(p, n, sizeof(p[0]), uintcmp);
/* Sort. */
warnx("grind %u: sorting", id);
qsort(p, n, sizeof(p[0]), uintcmp);
warnx("grind %u: summing", id);
s = sum(p, n);
warnx("grind %u: sum is %u (should be 0)", id, s);
if (s != 0) {
errx(1, "grind %u FAILED", id);
}
warnx("grind %u: summing", id);
s = sum(p, n);
warnx("grind %u: sum is %u (should be 0)", id, s);
if (s != 0) {
errx(1, "grind %u FAILED", id);
}
}