Re: Obvious one-liner - Use 3DNOW on MK8

Denis Vlasenko
2004-08-23T22:47:31Z

[-- Attachment #1: Type: text/plain, Size: 288 bytes --]

These are test programs.

copy_load.c:

for(i = 0; i < N; i++)
mem[i*SIZE+1] = 'b'; /* force copy */
strchr(mem, 'c') == mem+N*SIZE-1 || printf("BUG\n"); /* read all */

This forces page copying, and then touches every byte.
--
vda

[-- Attachment #2: copy_load.c --]
[-- Type: text/x-csrc, Size: 889 bytes --]

#include <stdlib.h>
#include <unistd.h>
#include <sys/mman.h>

#define N (256/4)
#define SIZE 4096

int main()
{
int i,k;
unsigned char *mem = mmap(0, N*SIZE, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
if(mem == MAP_FAILED)
perror("mmap");
memset(mem, 'a', N*SIZE); /* force page clearing */
mem[N*SIZE-1]='c';
//for(i = 0; i < N; i++) mem[i*SIZE] = i; /* force page clearing */

for(k = 0; k < 5000; k++) {
int pid;
pid = fork();
if(pid == 0) {
/* child */
for(i = 0; i < N; i++)
mem[i*SIZE+1] = 'b'; /* force copy */
//printf("copy complete\n");
strchr(mem, 'c') == mem+N*SIZE-1 || printf("BUG\n"); /* read all */
exit(0);
} else if(pid == -1) {
perror("fork");
} else {
/* parent */
waitpid(pid, NULL, 0);
}
}
munmap(mem, N*SIZE);
}

[-- Attachment #3: zero_load.c --]
[-- Type: text/x-csrc, Size: 594 bytes --]

#include <stdlib.h>
#include <unistd.h>
#include <sys/mman.h>

#define N (320/4)
#define SIZE 4096

int dummy;

int main()
{
int k;
for(k = 0; k < 20000; k++) {
int i = 0;
int pid;
unsigned char *mem,*p;
mem = mmap(0, N*SIZE, PROT_READ|PROT_WRITE,
MAP_PRIVATE|MAP_ANONYMOUS, 0, 0);
if(mem == MAP_FAILED)
perror("mmap");
for(i = 0; i < N; i++) mem[i*SIZE] = i; /* force page allocation and clearing */
//memset(mem, 'a', N*SIZE); /* force page clearing */
p = mem;
while(p != mem+N*SIZE) { i += *p; p+=32; } /* use data */
dummy = i;
munmap(mem, N*SIZE);
}
}