1/*****************************************************************************
2
3Copyright (c) 1994, 2016, Oracle and/or its affiliates. All Rights Reserved.
4
5This program is free software; you can redistribute it and/or modify it under
6the terms of the GNU General Public License as published by the Free Software
7Foundation; version 2 of the License.
8
9This program is distributed in the hope that it will be useful, but WITHOUT
10ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
11FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
12
13You should have received a copy of the GNU General Public License along with
14this program; if not, write to the Free Software Foundation, Inc.,
1551 Franklin Street, Suite 500, Boston, MA 02110-1335 USA
16
17*****************************************************************************/
18
19/******************************************************************//**
20@file include/ut0byte.h
21Utilities for byte operations
22
23Created 1/20/1994 Heikki Tuuri
24***********************************************************************/
25
26#ifndef ut0byte_h
27#define ut0byte_h
28
29
30
31#include "univ.i"
32
33/*******************************************************//**
34Creates a 64-bit integer out of two 32-bit integers.
35@return created integer */
36UNIV_INLINE
37ib_uint64_t
38ut_ull_create(
39/*==========*/
40 ulint high, /*!< in: high-order 32 bits */
41 ulint low) /*!< in: low-order 32 bits */
42 MY_ATTRIBUTE((const));
43
44/********************************************************//**
45Rounds a 64-bit integer downward to a multiple of a power of 2.
46@return rounded value */
47UNIV_INLINE
48ib_uint64_t
49ut_uint64_align_down(
50/*=================*/
51 ib_uint64_t n, /*!< in: number to be rounded */
52 ulint align_no); /*!< in: align by this number
53 which must be a power of 2 */
54/********************************************************//**
55Rounds ib_uint64_t upward to a multiple of a power of 2.
56@return rounded value */
57UNIV_INLINE
58ib_uint64_t
59ut_uint64_align_up(
60/*===============*/
61 ib_uint64_t n, /*!< in: number to be rounded */
62 ulint align_no); /*!< in: align by this number
63 which must be a power of 2 */
64/*********************************************************//**
65The following function rounds up a pointer to the nearest aligned address.
66@return aligned pointer */
67UNIV_INLINE
68void*
69ut_align(
70/*=====*/
71 const void* ptr, /*!< in: pointer */
72 ulint align_no); /*!< in: align by this number */
73/*********************************************************//**
74The following function rounds down a pointer to the nearest
75aligned address.
76@return aligned pointer */
77UNIV_INLINE
78void*
79ut_align_down(
80/*==========*/
81 const void* ptr, /*!< in: pointer */
82 ulint align_no) /*!< in: align by this number */
83 MY_ATTRIBUTE((const));
84/*********************************************************//**
85The following function computes the offset of a pointer from the nearest
86aligned address.
87@return distance from aligned pointer */
88UNIV_INLINE
89ulint
90ut_align_offset(
91/*============*/
92 const void* ptr, /*!< in: pointer */
93 ulint align_no) /*!< in: align by this number */
94 MY_ATTRIBUTE((const));
95/*****************************************************************//**
96Gets the nth bit of a ulint.
97@return TRUE if nth bit is 1; 0th bit is defined to be the least significant */
98UNIV_INLINE
99ibool
100ut_bit_get_nth(
101/*===========*/
102 ulint a, /*!< in: ulint */
103 ulint n); /*!< in: nth bit requested */
104/*****************************************************************//**
105Sets the nth bit of a ulint.
106@return the ulint with the bit set as requested */
107UNIV_INLINE
108ulint
109ut_bit_set_nth(
110/*===========*/
111 ulint a, /*!< in: ulint */
112 ulint n, /*!< in: nth bit requested */
113 ibool val); /*!< in: value for the bit to set */
114
115#include "ut0byte.ic"
116
117#endif
118