Merging in 2.0.2.
This commit is contained in:
@@ -35,17 +35,14 @@
|
||||
* 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.
|
||||
@@ -57,61 +54,6 @@
|
||||
* 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)
|
||||
@@ -131,7 +73,6 @@ sort(int *arr, int size)
|
||||
j = pivot;
|
||||
k = 0;
|
||||
while (i<pivot && j<size) {
|
||||
progress();
|
||||
if (arr[i] < arr[j]) {
|
||||
tmp[k++] = arr[i++];
|
||||
}
|
||||
@@ -140,15 +81,13 @@ sort(int *arr, int size)
|
||||
}
|
||||
}
|
||||
while (i<pivot) {
|
||||
progress();
|
||||
tmp[k++] = arr[i++];
|
||||
}
|
||||
while (j<size) {
|
||||
progress();
|
||||
tmp[k++] = arr[j++];
|
||||
}
|
||||
|
||||
local_memcpy(arr, tmp, size*sizeof(int));
|
||||
memcpy(arr, tmp, size*sizeof(int));
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
@@ -177,15 +116,13 @@ 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]);
|
||||
}
|
||||
}
|
||||
success(TEST161_SUCCESS, SECRET, "/testbin/sort");
|
||||
warnx("Passed.");
|
||||
}
|
||||
|
||||
int
|
||||
|
Reference in New Issue
Block a user