Skip to content

Commit 6619e1d

Browse files
committed
Always inline simple mach_read/write
At least in some ATTRIBUTE_COLD code, mach_read_from_8() could be invoked as a function call that could be as simple as wrapping one or two instructions. Let us declare __attribute__((always_inline)) on those memory accessor functions that operate on 1, 2, 4, or 8 bytes and are therefore likely to translate into few instructions, such as mov;bswap or movbe on x86.
1 parent cc277a7 commit 6619e1d

File tree

2 files changed

+25
-25
lines changed

2 files changed

+25
-25
lines changed

storage/innobase/include/mach0data.h

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ module. */
4040

4141
/*******************************************************//**
4242
The following function is used to store data in one byte. */
43-
UNIV_INLINE
43+
inline __attribute__((always_inline))
4444
void
4545
mach_write_to_1(
4646
/*============*/
@@ -49,15 +49,15 @@ mach_write_to_1(
4949
/** The following function is used to fetch data from one byte.
5050
@param[in] b pointer to a byte to read
5151
@return ulint integer, >= 0, < 256 */
52-
UNIV_INLINE
52+
inline __attribute__((always_inline))
5353
uint8_t
5454
mach_read_from_1(
5555
const byte* b)
5656
MY_ATTRIBUTE((warn_unused_result));
5757
/*******************************************************//**
5858
The following function is used to store data in two consecutive
5959
bytes. We store the most significant byte to the lower address. */
60-
UNIV_INLINE
60+
inline __attribute__((always_inline))
6161
void
6262
mach_write_to_2(
6363
/*============*/
@@ -68,7 +68,7 @@ mach_write_to_2(
6868
bytes. The most significant byte is at the lowest address.
6969
@param[in] b pointer to 2 bytes where to store
7070
@return 2-byte integer, >= 0, < 64k */
71-
UNIV_INLINE
71+
inline __attribute__((always_inline))
7272
uint16_t
7373
mach_read_from_2(
7474
const byte* b)
@@ -80,7 +80,7 @@ The following function is used to convert a 16-bit data item
8080
to the canonical format, for fast bytewise equality test
8181
against memory.
8282
@return 16-bit integer in canonical format */
83-
UNIV_INLINE
83+
inline __attribute__((always_inline))
8484
uint16
8585
mach_encode_2(
8686
/*==========*/
@@ -91,7 +91,7 @@ The following function is used to convert a 16-bit data item
9191
from the canonical format, for fast bytewise equality test
9292
against memory.
9393
@return integer in machine-dependent format */
94-
UNIV_INLINE
94+
inline __attribute__((always_inline))
9595
ulint
9696
mach_decode_2(
9797
/*==========*/
@@ -118,7 +118,7 @@ mach_read_from_3(
118118
/*******************************************************//**
119119
The following function is used to store data in four consecutive
120120
bytes. We store the most significant byte to the lowest address. */
121-
UNIV_INLINE
121+
inline __attribute__((always_inline))
122122
void
123123
mach_write_to_4(
124124
/*============*/
@@ -128,7 +128,7 @@ mach_write_to_4(
128128
bytes. The most significant byte is at the lowest address.
129129
@param[in] b pointer to 4 bytes to read
130130
@return 32 bit integer */
131-
UNIV_INLINE
131+
inline __attribute__((always_inline))
132132
uint32_t
133133
mach_read_from_4(
134134
const byte* b)
@@ -200,7 +200,7 @@ mach_read_from_7(
200200
/*******************************************************//**
201201
The following function is used to store data in 8 consecutive
202202
bytes. We store the most significant byte to the lowest address. */
203-
UNIV_INLINE
203+
inline __attribute__((always_inline))
204204
void
205205
mach_write_to_8(
206206
/*============*/
@@ -210,7 +210,7 @@ mach_write_to_8(
210210
The following function is used to fetch data from 8 consecutive
211211
bytes. The most significant byte is at the lowest address.
212212
@return 64-bit integer */
213-
UNIV_INLINE
213+
inline __attribute__((always_inline))
214214
ib_uint64_t
215215
mach_read_from_8(
216216
/*=============*/
@@ -301,7 +301,7 @@ mach_read_from_n_little_endian(
301301
/** Reads a 64 bit stored in big endian format
302302
@param buf From where to read
303303
@return uint64_t */
304-
UNIV_INLINE
304+
inline __attribute__((always_inline))
305305
uint64_t
306306
mach_read_uint64_little_endian(const byte* buf)
307307
{
@@ -330,15 +330,15 @@ mach_write_to_n_little_endian(
330330
/*********************************************************//**
331331
Reads a ulint stored in the little-endian format.
332332
@return unsigned long int */
333-
UNIV_INLINE
333+
inline __attribute__((always_inline))
334334
ulint
335335
mach_read_from_2_little_endian(
336336
/*===========================*/
337337
const byte* buf) /*!< in: from where to read */
338338
MY_ATTRIBUTE((warn_unused_result));
339339
/*********************************************************//**
340340
Writes a ulint in the little-endian format. */
341-
UNIV_INLINE
341+
inline __attribute__((always_inline))
342342
void
343343
mach_write_to_2_little_endian(
344344
/*==========================*/

storage/innobase/include/mach0data.inl

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ Created 11/28/1995 Heikki Tuuri
3333

3434
/*******************************************************//**
3535
The following function is used to store data in one byte. */
36-
UNIV_INLINE
36+
inline __attribute__((always_inline))
3737
void
3838
mach_write_to_1(
3939
/*============*/
@@ -52,7 +52,7 @@ mach_write_to_1(
5252
/*******************************************************//**
5353
The following function is used to store data in two consecutive
5454
bytes. We store the most significant byte to the lowest address. */
55-
UNIV_INLINE
55+
inline __attribute__((always_inline))
5656
void
5757
mach_write_to_2(
5858
/*============*/
@@ -70,7 +70,7 @@ mach_write_to_2(
7070
/** The following function is used to fetch data from one byte.
7171
@param[in] b pointer to a byte to read
7272
@return ulint integer, >= 0, < 256 */
73-
UNIV_INLINE
73+
inline __attribute__((always_inline))
7474
uint8_t
7575
mach_read_from_1(
7676
const byte* b)
@@ -82,7 +82,7 @@ mach_read_from_1(
8282
bytes. The most significant byte is at the lowest address.
8383
@param[in] b pointer to 2 bytes to read
8484
@return 2-byte integer, >= 0, < 64k */
85-
UNIV_INLINE
85+
inline __attribute__((always_inline))
8686
uint16_t
8787
mach_read_from_2(
8888
const byte* b)
@@ -97,7 +97,7 @@ The following function is used to convert a 16-bit data item
9797
to the canonical format, for fast bytewise equality test
9898
against memory.
9999
@return 16-bit integer in canonical format */
100-
UNIV_INLINE
100+
inline __attribute__((always_inline))
101101
uint16
102102
mach_encode_2(
103103
/*==========*/
@@ -113,7 +113,7 @@ The following function is used to convert a 16-bit data item
113113
from the canonical format, for fast bytewise equality test
114114
against memory.
115115
@return integer in machine-dependent format */
116-
UNIV_INLINE
116+
inline __attribute__((always_inline))
117117
ulint
118118
mach_decode_2(
119119
/*==========*/
@@ -159,7 +159,7 @@ mach_read_from_3(
159159
/*******************************************************//**
160160
The following function is used to store data in four consecutive
161161
bytes. We store the most significant byte to the lowest address. */
162-
UNIV_INLINE
162+
inline __attribute__((always_inline))
163163
void
164164
mach_write_to_4(
165165
/*============*/
@@ -176,7 +176,7 @@ mach_write_to_4(
176176
bytes. The most significant byte is at the lowest address.
177177
@param[in] b pointer to 4 bytes to read
178178
@return 32 bit integer */
179-
UNIV_INLINE
179+
inline __attribute__((always_inline))
180180
uint32_t
181181
mach_read_from_4(
182182
const byte* b)
@@ -336,7 +336,7 @@ mach_read_next_compressed(
336336
/*******************************************************//**
337337
The following function is used to store data in 8 consecutive
338338
bytes. We store the most significant byte to the lowest address. */
339-
UNIV_INLINE
339+
inline __attribute__((always_inline))
340340
void
341341
mach_write_to_8(
342342
/*============*/
@@ -353,7 +353,7 @@ mach_write_to_8(
353353
The following function is used to fetch data from 8 consecutive
354354
bytes. The most significant byte is at the lowest address.
355355
@return 64-bit integer */
356-
UNIV_INLINE
356+
inline __attribute__((always_inline))
357357
ib_uint64_t
358358
mach_read_from_8(
359359
/*=============*/
@@ -717,7 +717,7 @@ mach_write_to_n_little_endian(
717717
/*********************************************************//**
718718
Reads a ulint stored in the little-endian format.
719719
@return unsigned long int */
720-
UNIV_INLINE
720+
inline __attribute__((always_inline))
721721
ulint
722722
mach_read_from_2_little_endian(
723723
/*===========================*/
@@ -728,7 +728,7 @@ mach_read_from_2_little_endian(
728728

729729
/*********************************************************//**
730730
Writes a ulint in the little-endian format. */
731-
UNIV_INLINE
731+
inline __attribute__((always_inline))
732732
void
733733
mach_write_to_2_little_endian(
734734
/*==========================*/

0 commit comments

Comments
 (0)