annotate liboctave/util/byte-swap.h @ 20354:227d582fa300 stable

build: Sort generated PKG_ADD contents consistently * libinterp/mk-pkg-add: Set LC_COLLATE=C when sorting for consistent output.
author Mike Miller <mtmiller@octave.org>
date Fri, 10 Jul 2015 01:10:30 -0400
parents 4197fc428c7d
children
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
19731
4197fc428c7d maint: Update copyright notices for 2015.
John W. Eaton <jwe@octave.org>
parents: 17744
diff changeset
3 Copyright (C) 1996-2015 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
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5775
diff changeset
9 Free Software Foundation; either version 3 of the License, or (at your
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5775
diff changeset
10 option) any later version.
1960
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
7016
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5775
diff changeset
18 along with Octave; see the file COPYING. If not, see
93c65f2a5668 [project @ 2007-10-12 06:40:56 by jwe]
jwe
parents: 5775
diff changeset
19 <http://www.gnu.org/licenses/>.
1960
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
20
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 #if !defined (octave_byte_swap_h)
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
24 #define octave_byte_swap_h 1
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
25
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
26 static inline void
17413
e89e86e1a551 eliminate unnecessary volatile declarations
John W. Eaton <jwe@octave.org>
parents: 15271
diff changeset
27 swap_bytes (void *ptr, unsigned int i, unsigned int j)
1960
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
28 {
17413
e89e86e1a551 eliminate unnecessary volatile declarations
John W. Eaton <jwe@octave.org>
parents: 15271
diff changeset
29 char *t = static_cast<char *> (ptr);
3145
0d640dc625c7 [project @ 1998-02-05 08:44:59 by jwe]
jwe
parents: 2847
diff changeset
30
1960
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
31 char tmp = t[i];
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
32 t[i] = t[j];
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
33 t[j] = tmp;
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
34 }
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
35
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
36 template <int n>
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
37 void
17413
e89e86e1a551 eliminate unnecessary volatile declarations
John W. Eaton <jwe@octave.org>
parents: 15271
diff changeset
38 swap_bytes (void *ptr)
1960
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
39 {
8381
ad896677a2e2 implement binary saving of diag & perm matrices
Jaroslav Hajek <highegg@gmail.com>
parents: 7017
diff changeset
40 for (int i = 0; i < n/2; i++)
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
41 swap_bytes (ptr, i, n-1-i);
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
42 }
3145
0d640dc625c7 [project @ 1998-02-05 08:44:59 by jwe]
jwe
parents: 2847
diff changeset
43
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
44 template <>
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
45 inline void
17413
e89e86e1a551 eliminate unnecessary volatile declarations
John W. Eaton <jwe@octave.org>
parents: 15271
diff changeset
46 swap_bytes<1> (void *)
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
47 {
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
48 }
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
49
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
50 template <>
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
51 inline void
17413
e89e86e1a551 eliminate unnecessary volatile declarations
John W. Eaton <jwe@octave.org>
parents: 15271
diff changeset
52 swap_bytes<2> (void *ptr)
4944
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 swap_bytes (ptr, 0, 1);
1960
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
55 }
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
56
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
57 template <>
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
58 inline void
17413
e89e86e1a551 eliminate unnecessary volatile declarations
John W. Eaton <jwe@octave.org>
parents: 15271
diff changeset
59 swap_bytes<4> (void *ptr)
1960
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 swap_bytes (ptr, 0, 3);
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
62 swap_bytes (ptr, 1, 2);
1960
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
63 }
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 template <>
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
66 inline void
17413
e89e86e1a551 eliminate unnecessary volatile declarations
John W. Eaton <jwe@octave.org>
parents: 15271
diff changeset
67 swap_bytes<8> (void *ptr)
1960
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 swap_bytes (ptr, 0, 7);
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
70 swap_bytes (ptr, 1, 6);
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
71 swap_bytes (ptr, 2, 5);
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
72 swap_bytes (ptr, 3, 4);
1960
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
73 }
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
74
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
75 template <int n>
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
76 void
17413
e89e86e1a551 eliminate unnecessary volatile declarations
John W. Eaton <jwe@octave.org>
parents: 15271
diff changeset
77 swap_bytes (void *ptr, int len)
1960
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
78 {
17413
e89e86e1a551 eliminate unnecessary volatile declarations
John W. Eaton <jwe@octave.org>
parents: 15271
diff changeset
79 char *t = static_cast<char *> (ptr);
3145
0d640dc625c7 [project @ 1998-02-05 08:44:59 by jwe]
jwe
parents: 2847
diff changeset
80
1960
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
81 for (int i = 0; i < len; i++)
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
82 {
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
83 swap_bytes<n> (t);
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
84 t += n;
1960
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
85 }
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
86 }
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
87
4944
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
88 template <>
44046bbaa52c [project @ 2004-08-31 05:30:46 by jwe]
jwe
parents: 3215
diff changeset
89 inline void
17413
e89e86e1a551 eliminate unnecessary volatile declarations
John W. Eaton <jwe@octave.org>
parents: 15271
diff changeset
90 swap_bytes<1> (void *, int)
1960
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
91 {
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
92 }
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
93
285a7f683a4c [project @ 1996-02-16 04:03:01 by jwe]
jwe
parents:
diff changeset
94 #endif