blob: 1b404f56144105f0919de7b658d253b8f889b56b (
plain)
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
|
/***********************************************************************/
/* */
/* Objective Caml */
/* */
/* Xavier Leroy, projet Cristal, INRIA Rocquencourt */
/* */
/* Copyright 1996 Institut National de Recherche en Informatique et */
/* Automatique. Distributed only by permission. */
/* */
/***********************************************************************/
/* $Id$ */
/* Swap byte-order in 16-bit, 32-bit and 64-bit words */
#ifndef _reverse_
#define _reverse_
#define Reverse_short(s) { \
char * _p; \
int _a; \
_p = (char *) (s); \
_a = _p[0]; \
_p[0] = _p[1]; \
_p[1] = _a; \
}
#define Reverse_int32(w) { \
char * _p; \
int _a; \
_p = (char *) (w); \
_a = _p[0]; \
_p[0] = _p[3]; \
_p[3] = _a; \
_a = _p[1]; \
_p[1] = _p[2]; \
_p[2] = _a; \
}
#define Reverse_int64(d) { \
char * _p; \
int _a; \
_p = (char *) (d); \
_a = _p[0]; \
_p[0] = _p[7]; \
_p[7] = _a; \
_a = _p[1]; \
_p[1] = _p[6]; \
_p[6] = _a; \
_a = _p[2]; \
_p[2] = _p[5]; \
_p[5] = _a; \
_a = _p[3]; \
_p[3] = _p[4]; \
_p[4] = _a; \
}
#ifdef SIXTYFOUR
#define Reverse_word Reverse_int64
#else
#define Reverse_word Reverse_int32
#endif
#define Reverse_double Reverse_int64
#endif /* _reverse_ */
|