1960
|
1 /* |
|
2 |
2847
|
3 Copyright (C) 1996, 1997 John W. Eaton |
1960
|
4 |
|
5 This file is part of Octave. |
|
6 |
|
7 Octave is free software; you can redistribute it and/or modify it |
|
8 under the terms of the GNU General Public License as published by the |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
11 |
|
12 Octave is distributed in the hope that it will be useful, but WITHOUT |
|
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
15 for more details. |
|
16 |
|
17 You should have received a copy of the GNU General Public License |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #if !defined (octave_byte_swap_h) |
|
24 #define octave_byte_swap_h 1 |
|
25 |
3215
|
26 // XXX FIXME XXX -- not sure these volatile qualifiers are really |
|
27 // needed or appropriate here. |
|
28 |
1960
|
29 static inline void |
3215
|
30 swap_bytes (volatile void *ptr, unsigned int i, unsigned int j) |
1960
|
31 { |
3215
|
32 volatile char *t = static_cast<volatile char *> (ptr); |
3145
|
33 |
1960
|
34 char tmp = t[i]; |
|
35 t[i] = t[j]; |
|
36 t[j] = tmp; |
|
37 } |
|
38 |
|
39 static inline void |
3215
|
40 swap_2_bytes (volatile void *ptr) |
1960
|
41 { |
3215
|
42 volatile char *t = static_cast<volatile char *> (ptr); |
3145
|
43 |
1960
|
44 swap_bytes (t, 0, 1); |
|
45 } |
|
46 |
|
47 static inline void |
3215
|
48 swap_4_bytes (volatile void *ptr) |
1960
|
49 { |
3215
|
50 volatile char *t = static_cast<volatile char *> (ptr); |
3145
|
51 |
1960
|
52 swap_bytes (t, 0, 3); |
|
53 swap_bytes (t, 1, 2); |
|
54 } |
|
55 |
|
56 static inline void |
3215
|
57 swap_8_bytes (volatile void *ptr) |
1960
|
58 { |
3215
|
59 volatile char *t = static_cast<volatile char *> (ptr); |
3145
|
60 |
1960
|
61 swap_bytes (t, 0, 7); |
|
62 swap_bytes (t, 1, 6); |
|
63 swap_bytes (t, 2, 5); |
|
64 swap_bytes (t, 3, 4); |
|
65 } |
|
66 |
|
67 static inline void |
3215
|
68 swap_2_bytes (volatile void *ptr, int len) |
1960
|
69 { |
3215
|
70 volatile char *t = static_cast<volatile char *> (ptr); |
3145
|
71 |
1960
|
72 for (int i = 0; i < len; i++) |
|
73 { |
3145
|
74 swap_2_bytes (t); |
|
75 t += 2; |
1960
|
76 } |
|
77 } |
|
78 |
|
79 static inline void |
3215
|
80 swap_4_bytes (volatile void *ptr, int len) |
1960
|
81 { |
3215
|
82 volatile char *t = static_cast<volatile char *> (ptr); |
3145
|
83 |
1960
|
84 for (int i = 0; i < len; i++) |
|
85 { |
3145
|
86 swap_4_bytes (t); |
|
87 t += 4; |
1960
|
88 } |
|
89 } |
|
90 |
|
91 static inline void |
3215
|
92 swap_8_bytes (volatile void *ptr, int len) |
1960
|
93 { |
3215
|
94 volatile char *t = static_cast<volatile char *> (ptr); |
3145
|
95 |
1960
|
96 for (int i = 0; i < len; i++) |
|
97 { |
3145
|
98 swap_8_bytes (t); |
|
99 t += 8; |
1960
|
100 } |
|
101 } |
|
102 |
|
103 #endif |
|
104 |
|
105 /* |
|
106 ;;; Local Variables: *** |
|
107 ;;; mode: C++ *** |
|
108 ;;; End: *** |
|
109 */ |