annotate liboctave/byte-swap.h @ 6469:a848b846cb3a ss-2-9-10

[project @ 2007-03-27 18:42:11 by jwe]
author jwe
date Tue, 27 Mar 2007 18:42:11 +0000
parents ace8d8d26933
children 93c65f2a5668
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1960
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
1 /*
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
2
2847
8b262e771614 [project @ 1997-03-27 16:18:26 by jwe]
jwe
parents: 1993
diff changeset
3 Copyright (C) 1996, 1997 John W. Eaton
1960
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
4
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
5 This file is part of Octave.
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
6
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
7 Octave is free software; you can redistribute it and/or modify it
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
8 under the terms of the GNU General Public License as published by the
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
9 Free Software Foundation; either version 2, or (at your option) any
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
10 later version.
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
11
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
12 Octave is distributed in the hope that it will be useful, but WITHOUT
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
15 for more details.
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
16
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
17 You should have received a copy of the GNU General Public License
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
18 along with Octave; see the file COPYING. If not, write to the Free
5307
4c8a2e4e0717 [project @ 2005-04-26 19:24:27 by jwe]
jwe
parents: 4944
diff changeset
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
4c8a2e4e0717 [project @ 2005-04-26 19:24:27 by jwe]
jwe
parents: 4944
diff changeset
20 02110-1301, USA.
1960
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
21
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
22 */
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
23
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
24 #if !defined (octave_byte_swap_h)
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
25 #define octave_byte_swap_h 1
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
26
5775
ace8d8d26933 [project @ 2006-04-24 19:13:06 by jwe]
jwe
parents: 5307
diff changeset
27 // FIXME -- not sure these volatile qualifiers are really
3215
bc3fdfe311a3 [project @ 1998-11-10 14:06:21 by jwe]
jwe
parents: 3145
diff changeset
28 // needed or appropriate here.
bc3fdfe311a3 [project @ 1998-11-10 14:06:21 by jwe]
jwe
parents: 3145
diff changeset
29
1960
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
30 static inline void
3215
bc3fdfe311a3 [project @ 1998-11-10 14:06:21 by jwe]
jwe
parents: 3145
diff changeset
31 swap_bytes (volatile void *ptr, unsigned int i, unsigned int j)
1960
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
32 {
3215
bc3fdfe311a3 [project @ 1998-11-10 14:06:21 by jwe]
jwe
parents: 3145
diff changeset
33 volatile char *t = static_cast<volatile char *> (ptr);
3145
0d640dc625c7 [project @ 1998-02-05 08:44:59 by jwe]
jwe
parents: 2847
diff changeset
34
1960
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
35 char tmp = t[i];
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
36 t[i] = t[j];
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
37 t[j] = tmp;
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
38 }
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
39
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
40 template <int n>
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
41 void
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
42 swap_bytes (volatile void *ptr)
1960
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
43 {
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
44 for (size_t i = 0; i < n/2; i++)
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
45 swap_bytes (ptr, i, n-1-i);
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
46 }
3145
0d640dc625c7 [project @ 1998-02-05 08:44:59 by jwe]
jwe
parents: 2847
diff changeset
47
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
48 template <>
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
49 inline void
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
50 swap_bytes <1> (volatile void *)
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
51 {
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
52 }
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
53
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
54 template <>
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
55 inline void
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
56 swap_bytes <2> (volatile void *ptr)
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
57 {
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
58 swap_bytes (ptr, 0, 1);
1960
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
59 }
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
60
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
61 template <>
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
62 inline void
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
63 swap_bytes <4> (volatile void *ptr)
1960
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
64 {
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
65 swap_bytes (ptr, 0, 3);
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
66 swap_bytes (ptr, 1, 2);
1960
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
67 }
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
68
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
69 template <>
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
70 inline void
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
71 swap_bytes <8> (volatile void *ptr)
1960
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
72 {
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
73 swap_bytes (ptr, 0, 7);
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
74 swap_bytes (ptr, 1, 6);
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
75 swap_bytes (ptr, 2, 5);
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
76 swap_bytes (ptr, 3, 4);
1960
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
77 }
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
78
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
79 template <int n>
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
80 void
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
81 swap_bytes (volatile void *ptr, int len)
1960
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
82 {
3215
bc3fdfe311a3 [project @ 1998-11-10 14:06:21 by jwe]
jwe
parents: 3145
diff changeset
83 volatile char *t = static_cast<volatile char *> (ptr);
3145
0d640dc625c7 [project @ 1998-02-05 08:44:59 by jwe]
jwe
parents: 2847
diff changeset
84
1960
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
85 for (int i = 0; i < len; i++)
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
86 {
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
87 swap_bytes<n> (t);
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
88 t += n;
1960
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
89 }
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
90 }
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
91
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
92 template <>
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
93 inline void
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
94 swap_bytes<1> (volatile void *, int)
1960
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
95 {
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
96 }
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
97
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
98 #endif
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
99
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
100 /*
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
101 ;;; Local Variables: ***
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
102 ;;; mode: C++ ***
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
103 ;;; End: ***
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
104 */