[netcore] Make the load hook ALC-aware (#16012)
[mono-project.git] / mono / metadata / mono-endian.c
blobd7822c72ff6306bcdd732310b8a2555085d2e50b
1 /**
2 * \file
4 * Author:
5 * Mono Project (http://www.mono-project.com)
7 * Copyright 2001-2003 Ximian, Inc (http://www.ximian.com)
8 * Copyright 2004-2009 Novell, Inc (http://www.novell.com)
9 * Licensed under the MIT license. See LICENSE file in the project root for full license information.
11 #include <config.h>
12 #include <mono/utils/mono-compiler.h>
13 #include "mono-endian.h"
15 #if NO_UNALIGNED_ACCESS
17 typedef union {
18 char c [2];
19 guint16 i;
20 } mono_rint16;
22 typedef union {
23 char c [4];
24 guint32 i;
25 } mono_rint32;
27 typedef union {
28 char c [8];
29 guint64 i;
30 } mono_rint64;
32 guint16
33 mono_read16 (const unsigned char *x)
35 mono_rint16 r;
36 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
37 r.c [0] = x [0];
38 r.c [1] = x [1];
39 #else
40 r.c [1] = x [0];
41 r.c [0] = x [1];
42 #endif
43 return r.i;
46 guint32
47 mono_read32 (const unsigned char *x)
49 mono_rint32 r;
50 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
51 r.c [0] = x [0];
52 r.c [1] = x [1];
53 r.c [2] = x [2];
54 r.c [3] = x [3];
55 #else
56 r.c [3] = x [0];
57 r.c [2] = x [1];
58 r.c [1] = x [2];
59 r.c [0] = x [3];
60 #endif
61 return r.i;
64 guint64
65 mono_read64 (const unsigned char *x)
67 mono_rint64 r;
68 #if G_BYTE_ORDER == G_LITTLE_ENDIAN
69 r.c [0] = x [0];
70 r.c [1] = x [1];
71 r.c [2] = x [2];
72 r.c [3] = x [3];
73 r.c [4] = x [4];
74 r.c [5] = x [5];
75 r.c [6] = x [6];
76 r.c [7] = x [7];
77 #else
78 r.c [7] = x [0];
79 r.c [6] = x [1];
80 r.c [5] = x [2];
81 r.c [4] = x [3];
82 r.c [3] = x [4];
83 r.c [2] = x [5];
84 r.c [1] = x [6];
85 r.c [0] = x [7];
86 #endif
87 return r.i;
90 #else /* NO_UNALIGNED_ACCESS */
92 MONO_EMPTY_SOURCE_FILE (mono_endian);
94 #endif