1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
|
/***********************************************************************/
/* */
/* Objective Caml */
/* */
/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */
/* */
/* Copyright 1996 Institut National de Recherche en Informatique et */
/* Automatique. Distributed only by permission. */
/* */
/***********************************************************************/
/* $Id$ */
#include <stdio.h>
#include <signal.h>
#include <setjmp.h>
long foo;
void access16(p)
short * p;
{
foo = *p;
}
void access32(p)
long * p;
{
foo = *p;
}
jmp_buf failure;
void sig_handler(dummy)
int dummy;
{
longjmp(failure, 1);
}
int test(fct, p)
void (*fct)();
char * p;
{
int res;
signal(SIGSEGV, sig_handler);
signal(SIGBUS, sig_handler);
if(setjmp(failure) == 0) {
fct(p);
res = 0;
} else {
res = 1;
}
signal(SIGSEGV, SIG_DFL);
signal(SIGBUS, SIG_DFL);
return res;
}
jmp_buf timer;
void alarm_handler(dummy)
int dummy;
{
longjmp(timer, 1);
}
void use(n)
int n;
{
return;
}
int speedtest(p)
char * p;
{
int * q;
volatile int total;
int i;
volatile int sum;
signal(SIGALRM, alarm_handler);
sum = 0;
if (setjmp(timer) == 0) {
alarm(1);
total = 0;
while(1) {
for (q = (int *) p, i = 1000; i > 0; q++, i--)
sum += *q;
total++;
}
}
use(sum);
signal(SIGALRM, SIG_DFL);
return total;
}
main()
{
long n[1001];
int speed_aligned, speed_unaligned;
if (test(access16, (char *) n + 1)) exit(1);
if (test(access32, (char *) n + 1)) exit(1);
if (test(access32, (char *) n + 2)) exit(1);
speed_aligned = speedtest((char *) n);
speed_unaligned = speedtest((char *) n + 1);
if (speed_aligned >= 3 * speed_unaligned) exit(1);
exit(0);
}
|