]> rtime.felk.cvut.cz Git - l4.git/blob - l4/pkg/ocaml/contrib/config/auto-aux/align.c
update
[l4.git] / l4 / pkg / ocaml / contrib / config / auto-aux / align.c
1 /***********************************************************************/
2 /*                                                                     */
3 /*                           Objective Caml                            */
4 /*                                                                     */
5 /*            Xavier Leroy, projet Cristal, INRIA Rocquencourt         */
6 /*                                                                     */
7 /*  Copyright 1996 Institut National de Recherche en Informatique et   */
8 /*  en Automatique.  All rights reserved.  This file is distributed    */
9 /*  under the terms of the GNU Library General Public License, with    */
10 /*  the special exception on linking described in file ../../LICENSE.  */
11 /*                                                                     */
12 /***********************************************************************/
13
14 /* $Id: align.c 4144 2001-12-07 13:41:02Z xleroy $ */
15
16 #include <stdio.h>
17 #include <signal.h>
18 #include <setjmp.h>
19
20 long foo;
21
22 void access16(short int *p)
23 {
24   foo = *p;
25 }
26
27 void access32(long int *p)
28 {
29   foo = *p;
30 }
31
32 jmp_buf failure;
33
34 void sig_handler(int dummy)
35 {
36   longjmp(failure, 1);
37 }
38
39 int test(void (*fct) (/* ??? */), char *p)
40 {
41   int res;
42
43   signal(SIGSEGV, sig_handler);
44   signal(SIGBUS, sig_handler);
45   if(setjmp(failure) == 0) {
46     fct(p);
47     res = 0;
48   } else {
49     res = 1;
50   }
51   signal(SIGSEGV, SIG_DFL);
52   signal(SIGBUS, SIG_DFL);
53   return res;
54 }
55
56 jmp_buf timer;
57
58 void alarm_handler(int dummy)
59 {
60   longjmp(timer, 1);
61 }
62
63 void use(int n)
64 {
65   return;
66 }
67
68 int speedtest(char *p)
69 {
70   int * q;
71   volatile int total;
72   int i;
73   volatile int sum;
74
75   signal(SIGALRM, alarm_handler);
76   sum = 0;
77   if (setjmp(timer) == 0) {
78     alarm(1);
79     total = 0;
80     while(1) {
81       for (q = (int *) p, i = 1000; i > 0; q++, i--)
82         sum += *q;
83       total++;
84     }
85   }
86   use(sum);
87   signal(SIGALRM, SIG_DFL);
88   return total;
89 }
90
91 main(void)
92 {
93   long n[1001];
94   int speed_aligned, speed_unaligned;
95
96   if (test(access16, (char *) n + 1)) exit(1);
97   if (test(access32, (char *) n + 1)) exit(1);
98   if (test(access32, (char *) n + 2)) exit(1);
99   speed_aligned = speedtest((char *) n);
100   speed_unaligned = speedtest((char *) n + 1);
101   if (speed_aligned >= 3 * speed_unaligned) exit(1);
102   exit(0);
103 }