MySQL 8.0.39
Source Code Documentation
big_endian.h
Go to the documentation of this file.
1/* Copyright (c) 2012, 2024, Oracle and/or its affiliates.
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, version 2.0,
5 as published by the Free Software Foundation.
6
7 This program is designed to work with certain software (including
8 but not limited to OpenSSL) that is licensed under separate terms,
9 as designated in a particular file or component or in included license
10 documentation. The authors of MySQL hereby grant you an additional
11 permission to link the program and your derivative works with the
12 separately licensed software that they have either included with
13 the program or referenced in the documentation.
14
15 This program is distributed in the hope that it will be useful,
16 but WITHOUT ANY WARRANTY; without even the implied warranty of
17 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 GNU General Public License, version 2.0, for more details.
19
20 You should have received a copy of the GNU General Public License
21 along with this program; if not, write to the Free Software
22 Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA */
23
24/**
25 @file include/big_endian.h
26
27 Endianness-independent definitions (little_endian.h contains optimized
28 versions if you know you are on a little-endian platform).
29*/
30
31// IWYU pragma: private, include "my_byteorder.h"
32
33#ifndef MY_BYTEORDER_INCLUDED
34#error This file should never be #included directly; use my_byteorder.h.
35#endif
36
37#include <string.h>
38
39#include "my_inttypes.h"
40
41static inline int16 sint2korr(const uchar *A) {
42 return (int16)(((int16)(A[0])) + ((int16)(A[1]) << 8));
43}
44
45static inline int32 sint4korr(const uchar *A) {
46 return (int32)(((int32)(A[0])) + (((int32)(A[1]) << 8)) +
47 (((int32)(A[2]) << 16)) + (((int32)(A[3]) << 24)));
48}
49
50static inline uint16 uint2korr(const uchar *A) {
51 return (uint16)(((uint16)(A[0])) + ((uint16)(A[1]) << 8));
52}
53
54static inline uint32 uint4korr(const uchar *A) {
55 return (uint32)(((uint32)(A[0])) + (((uint32)(A[1])) << 8) +
56 (((uint32)(A[2])) << 16) + (((uint32)(A[3])) << 24));
57}
58
59static inline ulonglong uint8korr(const uchar *A) {
60 return ((ulonglong)(((uint32)(A[0])) + (((uint32)(A[1])) << 8) +
61 (((uint32)(A[2])) << 16) + (((uint32)(A[3])) << 24)) +
62 (((ulonglong)(((uint32)(A[4])) + (((uint32)(A[5])) << 8) +
63 (((uint32)(A[6])) << 16) + (((uint32)(A[7])) << 24)))
64 << 32));
65}
66
67static inline longlong sint8korr(const uchar *A) {
68 return (longlong)uint8korr(A);
69}
70
71static inline void int2store(uchar *T, uint16 A) {
72 uint def_temp = A;
73 *(T) = (uchar)(def_temp);
74 *(T + 1) = (uchar)(def_temp >> 8);
75}
76
77static inline void int4store(uchar *T, uint32 A) {
78 *(T) = (uchar)(A);
79 *(T + 1) = (uchar)(A >> 8);
80 *(T + 2) = (uchar)(A >> 16);
81 *(T + 3) = (uchar)(A >> 24);
82}
83
84static inline void int7store(uchar *T, ulonglong A) {
85 *(T) = (uchar)(A);
86 *(T + 1) = (uchar)(A >> 8);
87 *(T + 2) = (uchar)(A >> 16);
88 *(T + 3) = (uchar)(A >> 24);
89 *(T + 4) = (uchar)(A >> 32);
90 *(T + 5) = (uchar)(A >> 40);
91 *(T + 6) = (uchar)(A >> 48);
92}
93
94static inline void int8store(uchar *T, ulonglong A) {
95 uint def_temp = (uint)A, def_temp2 = (uint)(A >> 32);
96 int4store(T, def_temp);
97 int4store(T + 4, def_temp2);
98}
99
100/*
101 Data in big-endian format.
102*/
103static inline void float4store(uchar *T, float A) {
104 *(T) = ((uchar *)&A)[3];
105 *((T) + 1) = (char)((uchar *)&A)[2];
106 *((T) + 2) = (char)((uchar *)&A)[1];
107 *((T) + 3) = (char)((uchar *)&A)[0];
108}
109
110static inline float float4get(const uchar *M) {
111 float def_temp;
112 ((uchar *)&def_temp)[0] = (M)[3];
113 ((uchar *)&def_temp)[1] = (M)[2];
114 ((uchar *)&def_temp)[2] = (M)[1];
115 ((uchar *)&def_temp)[3] = (M)[0];
116 return def_temp;
117}
118
119static inline void float8store(uchar *T, double V) {
120 *(T) = ((uchar *)&V)[7];
121 *((T) + 1) = (char)((uchar *)&V)[6];
122 *((T) + 2) = (char)((uchar *)&V)[5];
123 *((T) + 3) = (char)((uchar *)&V)[4];
124 *((T) + 4) = (char)((uchar *)&V)[3];
125 *((T) + 5) = (char)((uchar *)&V)[2];
126 *((T) + 6) = (char)((uchar *)&V)[1];
127 *((T) + 7) = (char)((uchar *)&V)[0];
128}
129
130static inline double float8get(const uchar *M) {
131 double def_temp;
132 ((uchar *)&def_temp)[0] = (M)[7];
133 ((uchar *)&def_temp)[1] = (M)[6];
134 ((uchar *)&def_temp)[2] = (M)[5];
135 ((uchar *)&def_temp)[3] = (M)[4];
136 ((uchar *)&def_temp)[4] = (M)[3];
137 ((uchar *)&def_temp)[5] = (M)[2];
138 ((uchar *)&def_temp)[6] = (M)[1];
139 ((uchar *)&def_temp)[7] = (M)[0];
140 return def_temp;
141}
static double float8get(const uchar *M)
Definition: big_endian.h:130
static void int8store(uchar *T, ulonglong A)
Definition: big_endian.h:94
static void int4store(uchar *T, uint32 A)
Definition: big_endian.h:77
static void float8store(uchar *T, double V)
Definition: big_endian.h:119
static float float4get(const uchar *M)
Definition: big_endian.h:110
static void float4store(uchar *T, float A)
Definition: big_endian.h:103
static void int7store(uchar *T, ulonglong A)
Definition: big_endian.h:84
static int16 sint2korr(const uchar *A)
Definition: big_endian.h:41
static void int2store(uchar *T, uint16 A)
Definition: big_endian.h:71
static uint16 uint2korr(const uchar *A)
Definition: big_endian.h:50
static ulonglong uint8korr(const uchar *A)
Definition: big_endian.h:59
static uint32 uint4korr(const uchar *A)
Definition: big_endian.h:54
static int32 sint4korr(const uchar *A)
Definition: big_endian.h:45
static longlong sint8korr(const uchar *A)
Definition: big_endian.h:67
#define M
Definition: ctype-tis620.cc:74
Some integer typedefs for easier portability.
unsigned long long int ulonglong
Definition: my_inttypes.h:56
unsigned char uchar
Definition: my_inttypes.h:52
long long int longlong
Definition: my_inttypes.h:55
int16_t int16
Definition: my_inttypes.h:64
int32_t int32
Definition: my_inttypes.h:66
uint16_t uint16
Definition: my_inttypes.h:65
uint32_t uint32
Definition: my_inttypes.h:67
unsigned int uint
Definition: uca9-dump.cc:75