Blender V5.3
BLI_endian_switch_inline.hh
Go to the documentation of this file.
1/* SPDX-FileCopyrightText: 2023 Blender Authors
2 *
3 * SPDX-License-Identifier: GPL-2.0-or-later */
4
5#pragma once
6
8#include "BLI_sys_types.hh"
9
10/* only include from header */
11#ifndef __BLI_ENDIAN_SWITCH_H__
12# error "this file isn't to be directly included"
13#endif
14
18
19namespace blender {
20
21/* NOTE: using a temp char to switch endian is a lot slower,
22 * use bit shifting instead. */
23
24/* *** 16 *** */
25
27{
28 BLI_endian_switch_uint16(reinterpret_cast<unsigned short *>(val));
29}
30BLI_INLINE void BLI_endian_switch_uint16(unsigned short *val)
31{
32#ifdef __GNUC__
33 *val = __builtin_bswap16(*val);
34#else
35 unsigned short tval = *val;
36 *val = (tval >> 8) | (tval << 8);
37#endif
38}
39
40/* *** 32 *** */
41
43{
44 BLI_endian_switch_uint32(reinterpret_cast<unsigned int *>(val));
45}
46BLI_INLINE void BLI_endian_switch_uint32(unsigned int *val)
47{
48#ifdef __GNUC__
49 *val = __builtin_bswap32(*val);
50#else
51 unsigned int tval = *val;
52 *val = ((tval >> 24)) | ((tval << 8) & 0x00ff0000) | ((tval >> 8) & 0x0000ff00) | ((tval << 24));
53#endif
54}
56{
57 BLI_endian_switch_uint32(reinterpret_cast<unsigned int *>(val));
58}
59
60/* *** 64 *** */
61
63{
64 BLI_endian_switch_uint64(reinterpret_cast<uint64_t *>(val));
65}
67{
68#ifdef __GNUC__
69 *val = __builtin_bswap64(*val);
70#else
71 uint64_t tval = *val;
72 *val = ((tval >> 56)) | ((tval << 40) & 0x00ff000000000000ll) |
73 ((tval << 24) & 0x0000ff0000000000ll) | ((tval << 8) & 0x000000ff00000000ll) |
74 ((tval >> 8) & 0x00000000ff000000ll) | ((tval >> 24) & 0x0000000000ff0000ll) |
75 ((tval >> 40) & 0x000000000000ff00ll) | ((tval << 56));
76#endif
77}
79{
80 BLI_endian_switch_uint64(reinterpret_cast<uint64_t *>(val));
81}
82
83} // namespace blender
#define BLI_INLINE
BMesh Iterators.
unsigned __int64 uint64_t
Definition BKE_text.h:91
__int64 int64_t
Definition BKE_text.h:90
BLI_INLINE void BLI_endian_switch_int64(int64_t *val) ATTR_NONNULL(1)
BLI_INLINE void BLI_endian_switch_float(float *val) ATTR_NONNULL(1)
BLI_INLINE void BLI_endian_switch_double(double *val) ATTR_NONNULL(1)
BLI_INLINE void BLI_endian_switch_int16(short *val) ATTR_NONNULL(1)
BLI_INLINE void BLI_endian_switch_uint16(unsigned short *val) ATTR_NONNULL(1)
BLI_INLINE void BLI_endian_switch_uint32(unsigned int *val) ATTR_NONNULL(1)
BLI_INLINE void BLI_endian_switch_int32(int *val) ATTR_NONNULL(1)
BLI_INLINE void BLI_endian_switch_uint64(uint64_t *val) ATTR_NONNULL(1)