Revert "Merging in 1.0.2."

This reverts commit 50cf3276e7.
This commit is contained in:
Geoffrey Challen
2017-01-09 22:52:13 -05:00
parent 50cf3276e7
commit e318e3171e
118 changed files with 3158 additions and 1350 deletions

View File

@@ -35,14 +35,17 @@
* Once the virtual memory assignment is complete, your system
* should survive this.
*/
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <err.h>
#include <test161/test161.h>
/* Larger than physical memory */
#define SIZE (144*1024)
#define PROGRESS_INTERVAL 8000
#define NEWLINE_FREQ 100
/*
* Quicksort.
@@ -54,6 +57,61 @@
* Also, quicksort has somewhat more interesting memory usage patterns.
*/
static unsigned iters;
static inline
void
progress() {
TEST161_LPROGRESS_N(iters, PROGRESS_INTERVAL);
if (iters > 0 && (iters % (PROGRESS_INTERVAL * NEWLINE_FREQ)) == 0) {
printf("\n");
}
++iters;
}
static void *
local_memcpy(void *dst, const void *src, size_t len)
{
size_t i;
/*
* memcpy does not support overlapping buffers, so always do it
* forwards. (Don't change this without adjusting memmove.)
*
* For speedy copying, optimize the common case where both pointers
* and the length are word-aligned, and copy word-at-a-time instead
* of byte-at-a-time. Otherwise, copy by bytes.
*
* The alignment logic below should be portable. We rely on
* the compiler to be reasonably intelligent about optimizing
* the divides and modulos out. Fortunately, it is.
*/
if ((uintptr_t)dst % sizeof(long) == 0 &&
(uintptr_t)src % sizeof(long) == 0 &&
len % sizeof(long) == 0) {
long *d = dst;
const long *s = src;
for (i=0; i<len/sizeof(long); i++) {
progress();
d[i] = s[i];
}
}
else {
char *d = dst;
const char *s = src;
for (i=0; i<len; i++) {
progress();
d[i] = s[i];
}
}
return dst;
}
static
void
sort(int *arr, int size)
@@ -73,6 +131,7 @@ sort(int *arr, int size)
j = pivot;
k = 0;
while (i<pivot && j<size) {
progress();
if (arr[i] < arr[j]) {
tmp[k++] = arr[i++];
}
@@ -81,13 +140,15 @@ sort(int *arr, int size)
}
}
while (i<pivot) {
progress();
tmp[k++] = arr[i++];
}
while (j<size) {
progress();
tmp[k++] = arr[j++];
}
memcpy(arr, tmp, size*sizeof(int));
local_memcpy(arr, tmp, size*sizeof(int));
}
////////////////////////////////////////////////////////////
@@ -116,13 +177,15 @@ check(void)
{
int i;
printf("\nChecking...");
for (i=0; i<SIZE-1; i++) {
TEST161_LPROGRESS_N(i, PROGRESS_INTERVAL);
if (A[i] > A[i+1]) {
errx(1, "Failed: A[%d] is %d, A[%d] is %d",
i, A[i], i+1, A[i+1]);
}
}
warnx("Passed.");
success(TEST161_SUCCESS, SECRET, "/testbin/sort");
}
int