Files
test2/source/blender/blenlib/BLI_endian_switch_inline.h
Brecht Van Lommel 920e709069 Refactor: Make header files more clangd and clang-tidy friendly
When using clangd or running clang-tidy on headers there are
currently many errors. These are noisy in IDEs, make auto fixes
impossible, and break features like code completion, refactoring
and navigation.

This makes source/blender headers work by themselves, which is
generally the goal anyway. But #includes and forward declarations
were often incomplete.

* Add #includes and forward declarations
* Add IWYU pragma: export in a few places
* Remove some unused #includes (but there are many more)
* Tweak ShaderCreateInfo macros to work better with clangd

Some types of headers still have errors, these could be fixed or
worked around with more investigation. Mostly preprocessor
template headers like NOD_static_types.h.

Note that that disabling WITH_UNITY_BUILD is required for clangd to
work properly, otherwise compile_commands.json does not contain
the information for the relevant source files.

For more details see the developer docs:
https://developer.blender.org/docs/handbook/tooling/clangd/

Pull Request: https://projects.blender.org/blender/blender/pulls/132608
2025-01-07 12:39:13 +01:00

88 lines
1.9 KiB
C

/* SPDX-FileCopyrightText: 2023 Blender Authors
*
* SPDX-License-Identifier: GPL-2.0-or-later */
#pragma once
#include "BLI_compiler_compat.h"
#include "BLI_sys_types.h"
#ifdef __cplusplus
extern "C" {
#endif
/* only include from header */
#ifndef __BLI_ENDIAN_SWITCH_H__
# error "this file isn't to be directly included"
#endif
/** \file
* \ingroup bli
*/
/* NOTE: using a temp char to switch endian is a lot slower,
* use bit shifting instead. */
/* *** 16 *** */
BLI_INLINE void BLI_endian_switch_int16(short *val)
{
BLI_endian_switch_uint16((unsigned short *)val);
}
BLI_INLINE void BLI_endian_switch_uint16(unsigned short *val)
{
#ifdef __GNUC__
*val = __builtin_bswap16(*val);
#else
unsigned short tval = *val;
*val = (tval >> 8) | (tval << 8);
#endif
}
/* *** 32 *** */
BLI_INLINE void BLI_endian_switch_int32(int *val)
{
BLI_endian_switch_uint32((unsigned int *)val);
}
BLI_INLINE void BLI_endian_switch_uint32(unsigned int *val)
{
#ifdef __GNUC__
*val = __builtin_bswap32(*val);
#else
unsigned int tval = *val;
*val = ((tval >> 24)) | ((tval << 8) & 0x00ff0000) | ((tval >> 8) & 0x0000ff00) | ((tval << 24));
#endif
}
BLI_INLINE void BLI_endian_switch_float(float *val)
{
BLI_endian_switch_uint32((unsigned int *)val);
}
/* *** 64 *** */
BLI_INLINE void BLI_endian_switch_int64(int64_t *val)
{
BLI_endian_switch_uint64((uint64_t *)val);
}
BLI_INLINE void BLI_endian_switch_uint64(uint64_t *val)
{
#ifdef __GNUC__
*val = __builtin_bswap64(*val);
#else
uint64_t tval = *val;
*val = ((tval >> 56)) | ((tval << 40) & 0x00ff000000000000ll) |
((tval << 24) & 0x0000ff0000000000ll) | ((tval << 8) & 0x000000ff00000000ll) |
((tval >> 8) & 0x00000000ff000000ll) | ((tval >> 24) & 0x0000000000ff0000ll) |
((tval >> 40) & 0x000000000000ff00ll) | ((tval << 56));
#endif
}
BLI_INLINE void BLI_endian_switch_double(double *val)
{
BLI_endian_switch_uint64((uint64_t *)val);
}
#ifdef __cplusplus
}
#endif