1/* Copyright (c) 2001, 2012, Oracle and/or its affiliates. All rights reserved.
2
3 This program is free software; you can redistribute it and/or modify
4 it under the terms of the GNU General Public License as published by
5 the Free Software Foundation; version 2 of the License.
6
7 This program is distributed in the hope that it will be useful,
8 but WITHOUT ANY WARRANTY; without even the implied warranty of
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 GNU General Public License for more details.
11
12 You should have received a copy of the GNU General Public License
13 along with this program; if not, write to the Free Software
14 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02111-1307 USA */
15
16/*
17 Optimized function-like macros for the x86 architecture (_WIN32 included).
18*/
19
20#define sint2korr(A) (int16) (*((int16 *) (A)))
21#define sint3korr(A) ((int32) ((((uchar) (A)[2]) & 128) ? \
22 (((uint32) 255L << 24) | \
23 (((uint32) (uchar) (A)[2]) << 16) |\
24 (((uint32) (uchar) (A)[1]) << 8) | \
25 ((uint32) (uchar) (A)[0])) : \
26 (((uint32) (uchar) (A)[2]) << 16) |\
27 (((uint32) (uchar) (A)[1]) << 8) | \
28 ((uint32) (uchar) (A)[0])))
29#define sint4korr(A) (int32) (*((int32 *) (A)))
30#define uint2korr(A) (uint16) (*((uint16 *) (A)))
31#define uint3korr(A) (uint32) (((uint32) ((uchar) (A)[0])) +\
32 (((uint32) ((uchar) (A)[1])) << 8) +\
33 (((uint32) ((uchar) (A)[2])) << 16))
34#define uint4korr(A) (uint32) (*((uint32 *) (A)))
35
36
37static inline ulonglong uint5korr(const void *p)
38{
39 ulonglong a= *(uint32 *) p;
40 ulonglong b= *(4 + (uchar *) p);
41 return a | (b << 32);
42}
43static inline ulonglong uint6korr(const void *p)
44{
45 ulonglong a= *(uint32 *) p;
46 ulonglong b= *(uint16 *) (4 + (char *) p);
47 return a | (b << 32);
48}
49
50#define uint8korr(A) (ulonglong) (*((ulonglong *) (A)))
51#define sint8korr(A) (longlong) (*((longlong *) (A)))
52
53#define int2store(T,A) do { uchar *pT= (uchar*)(T);\
54 *((uint16*)(pT))= (uint16) (A);\
55 } while (0)
56
57#define int3store(T,A) do { *(T)= (uchar) ((A));\
58 *(T+1)=(uchar) (((uint) (A) >> 8));\
59 *(T+2)=(uchar) (((A) >> 16));\
60 } while (0)
61
62#define int4store(T,A) do { uchar *pT= (uchar*)(T);\
63 *((uint32 *) (pT))= (uint32) (A); \
64 } while (0)
65
66#define int5store(T,A) do { uchar *pT= (uchar*)(T);\
67 *((uint32 *) (pT))= (uint32) (A); \
68 *((pT)+4)=(uchar) (((A) >> 32));\
69 } while (0)
70
71#define int6store(T,A) do { uchar *pT= (uchar*)(T);\
72 *((uint32 *) (pT))= (uint32) (A); \
73 *((uint16*)(pT+4))= (uint16) (A >> 32);\
74 } while (0)
75
76#define int8store(T,A) do { uchar *pT= (uchar*)(T);\
77 *((ulonglong *) (pT))= (ulonglong) (A);\
78 } while(0)
79
80#if defined(__GNUC__)
81
82#define HAVE_mi_uint5korr
83#define HAVE_mi_uint6korr
84#define HAVE_mi_uint7korr
85#define HAVE_mi_uint78orr
86
87/* Read numbers stored in high-bytes-first order */
88
89static inline ulonglong mi_uint5korr(const void *p)
90{
91 ulonglong a= *(uint32 *) p;
92 ulonglong b= *(4 + (uchar *) p);
93 ulonglong v= (a | (b << 32)) << 24;
94 asm ("bswapq %0" : "=r" (v) : "0" (v));
95 return v;
96}
97
98static inline ulonglong mi_uint6korr(const void *p)
99{
100 ulonglong a= *(uint32 *) p;
101 ulonglong b= *(uint16 *) (4 + (char *) p);
102 ulonglong v= (a | (b << 32)) << 16;
103 asm ("bswapq %0" : "=r" (v) : "0" (v));
104 return v;
105}
106
107static inline ulonglong mi_uint7korr(const void *p)
108{
109 ulonglong a= *(uint32 *) p;
110 ulonglong b= *(uint16 *) (4 + (char *) p);
111 ulonglong c= *(6 + (uchar *) p);
112 ulonglong v= (a | (b << 32) | (c << 48)) << 8;
113 asm ("bswapq %0" : "=r" (v) : "0" (v));
114 return v;
115}
116
117static inline ulonglong mi_uint8korr(const void *p)
118{
119 ulonglong v= *(ulonglong *) p;
120 asm ("bswapq %0" : "=r" (v) : "0" (v));
121 return v;
122}
123
124#endif
125