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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
|
#ifndef UNITY_ENDIAN_HELPER_H_
#define UNITY_ENDIAN_HELPER_H_
enum EndianMode {
kEndianDirect = 0,
kEndianConvert = 1,
#if UNITY_BIG_ENDIAN
kHostEndian = kEndianDirect,
kTargetEndian = kEndianDirect,
#else
kHostEndian = kEndianConvert,
kTargetEndian = kEndianConvert,
#endif
};
template<EndianMode Endian>
struct EndianHelper;
template<>
struct EndianHelper<kEndianDirect>
{
static UInt16 Load( UInt16 const* p ) {
return *p;
}
static UInt32 Load( UInt32 const* p ) {
return *p;
}
template<int Offset>
static void Store( UInt16* p, UInt16 arg ) {
*reinterpret_cast<UInt16*>( ((intptr_t)p + Offset) ) = arg;
}
template<int Offset>
static void Store( UInt32* p, UInt32 arg ) {
*reinterpret_cast<UInt32*>( ((intptr_t)p + Offset) ) = arg;
}
};
template<>
struct EndianHelper<kEndianConvert>
{
static UInt16 Load( register UInt16 const* p ) {
//#if defined(__native_client__) || (defined(__GNUC__) && !defined(__APPLE__))
return ((*p&0xff00U)>>8) | ((*p&0x00ffU)<<8);
//#elif defined(__ppc__)
// register UInt16 temp;
// __asm {
// lhbrx temp, 0, p
// }
// return temp;
//#elif defined(__i386) || defined(_M_IX86)
// register UInt16 temp = *p;
// __asm {
// mov ax, temp
// xchg ah, al
// mov temp, ax
// }
// return temp;
//#else
//#error "Unsupported architecture"
//#endif
}
static UInt32 Load( register UInt32 const* p ) {
//#if defined(__native_client__) || (defined(__GNUC__) && !defined(__APPLE__))
return
((*p&0xff000000U)>>24) |
((*p&0x00ff0000U)>>8) |
((*p&0x0000ff00U)<<8) |
((*p&0x000000ffU)<<24)
;
//#elif defined(__ppc__)
// register UInt32 temp;
// __asm {
// lwbrx r4, 0, p
// }
// return temp;
//#elif defined(__i386) || defined(_M_IX86)
// register UInt32 temp = *p;
// __asm {
// mov eax, temp
// bswap eax
// mov temp, eax
// }
// return temp;
//#else
//#error "Unsupported architecture"
//#endif
}
// Offset is in bytes
template<int Offset>
static void Store( register UInt16* p, register UInt16 arg ) {
//#if defined(__native_client__) || (defined(__GNUC__) && !defined(__APPLE__))
UInt16 temp = ((arg&0xff00U)>>8) | ((arg&0x00ffU)<<8);
*(UInt16*)((UInt8*)p + Offset) = temp;
//#elif defined(__ppc__)
// register short int ofs = Offset;
// __asm {
// sthbrx arg, ofs, p
// }
//#elif defined(__i386) || defined(_M_IX86)
// register void* pp = (void*)((uintptr_t)p + Offset);
// __asm {
// mov ax, arg
// xchg ah, al
// mov ecx, dword ptr [pp]
// mov word ptr [ecx], ax
// }
//#else
//#error "Unsupported architecture"
//#endif
}
template<int Offset>
static void Store( register UInt32* p, register UInt32 arg ) {
//#if defined(__native_client__) || (defined(__GNUC__) && !defined(__APPLE__))
UInt32 temp =
((arg&0xff000000U)>>24) |
((arg&0x00ff0000U)>>8) |
((arg&0x0000ff00U)<<8) |
((arg&0x000000ffU)<<24)
;
*(UInt32*)((UInt8*)p + Offset) = temp;
//#elif defined(__ppc__)
// register short int ofs = Offset;
// __asm {
// stwbrx arg, ofs, p
// }
//#elif defined(__i386) || defined(_M_IX86)
// register void* pp = (void*)((uintptr_t)p + Offset);
// __asm {
// mov eax, arg
// bswap eax
// mov ecx, dword ptr [pp]
// mov word ptr [ecx], eax
// }
//#else
//#error "Unsupported architecture"
//#endif
}
};
#endif // UNITY_ENDIAN_HELPER_H_
|