-
Notifications
You must be signed in to change notification settings - Fork 8
/
plasma_endian.c
106 lines (96 loc) · 3.59 KB
/
plasma_endian.c
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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
/*
* plasma_endian - portability macros for byteorder conversion
*
* inline assembly and compiler intrinsics for byteorder conversion
* (little endian <=> big endian)
*
*
* Copyright (c) 2012, Glue Logic LLC. All rights reserved. code()gluelogic.com
*
* This file is part of plasma.
*
* plasma is free software: you can redistribute it and/or modify it under
* the terms of the GNU Lesser General Public License as published by
* the Free Software Foundation, either version 2.1 of the License, or
* (at your option) any later version.
*
* plasma is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with plasma. If not, see <http://www.gnu.org/licenses/>.
*/
#define PLASMA_ENDIAN_C99INLINE_FUNCS
/* inlined functions defined in header
* (generate external linkage definition in GCC versions earlier than GCC 4.3)*/
#if defined(NO_C99INLINE) \
|| defined(__clang__) || (defined(__GNUC__) && !defined(__GNUC_STDC_INLINE__))
#define PLASMA_ENDIAN_C99INLINE
#endif
#include "plasma_endian.h"
/* inlined functions defined in header
* (generate external linkage definition in C99-compliant compilers)
* (need to -duplicate- definition from header for non-C99-compliant compiler)
*/
#if !defined(__GNUC__) || defined(__GNUC_STDC_INLINE__)
#if defined(plasma_endian_swap16_func) \
&&!defined(plasma_endian_swap16_funcmacro)
extern inline
uint16_t plasma_endian_swap16_func (uint16_t);
uint16_t plasma_endian_swap16_func (uint16_t);
#endif
#if defined(plasma_endian_swap16p_func) \
&&!defined(plasma_endian_swap16p_funcmacro)
extern inline
uint16_t plasma_endian_swap16p_func (const uint16_t * restrict);
uint16_t plasma_endian_swap16p_func (const uint16_t * restrict);
#endif
#if defined(plasma_endian_swap32_func) \
&&!defined(plasma_endian_swap32_funcmacro)
extern inline
uint32_t plasma_endian_swap32_func (uint32_t);
uint32_t plasma_endian_swap32_func (uint32_t);
#endif
#if defined(plasma_endian_swap32p_func) \
&&!defined(plasma_endian_swap32p_funcmacro)
extern inline
uint32_t plasma_endian_swap32p_func (const uint32_t * restrict);
uint32_t plasma_endian_swap32p_func (const uint32_t * restrict);
#endif
#if defined(plasma_endian_swap64_func) \
&&!defined(plasma_endian_swap64_funcmacro)
extern inline
uint64_t plasma_endian_swap64_func (uint64_t);
uint64_t plasma_endian_swap64_func (uint64_t);
#endif
#if defined(plasma_endian_swap64p_func) \
&&!defined(plasma_endian_swap64p_funcmacro)
extern inline
uint64_t plasma_endian_swap64p_func (const uint64_t * restrict);
uint64_t plasma_endian_swap64p_func (const uint64_t * restrict);
#endif
#endif
#ifdef __sparc
#if (defined(__SUNPRO_C) && __SUNPRO_C < 0x5100) \
|| (defined(__SUNPRO_CC) && __SUNPRO_CC < 0x5100) /* Sun Studio < 12.1 */
void
plasma_endian_SPARC_asm (void)
{
/* SPARC Assembly Language Reference Manual
* http://docs.oracle.com/cd/E26502_01/html/E28387/gmadm.html */
__asm__(".global plasma_endian_swap32_SPARC\n"
".type plasma_endian_swap32_SPARC,#function\n"
"plasma_endian_swap32_SPARC:\n"
"retl\n"
"lduwa [%o0] 0x88, %o0\n");
__asm__(".global plasma_endian_swap64_SPARC\n"
".type plasma_endian_swap64_SPARC,#function\n"
"plasma_endian_swap64_SPARC:\n"
"retl\n"
"ldxa [%o0] 0x88, %o0\n");
}
PLASMA_ATTR_Pragma_rarely_called(plasma_endian_SPARC_asm)
#endif
#endif