2022-08-30 10:20:04 +02:00
|
|
|
// Copyright 2022 Stefan Kerkmann (KarlK90)
|
|
|
|
// Copyright 2011 Jun Wako <wakojun@gmail.com>
|
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
|
|
|
|
2020-12-26 05:56:11 +01:00
|
|
|
#pragma once
|
2015-04-09 18:32:04 +02:00
|
|
|
|
2021-02-08 00:16:15 +01:00
|
|
|
#include "bitwise.h"
|
2015-04-09 18:32:04 +02:00
|
|
|
|
|
|
|
// convert to string
|
|
|
|
#define STR(s) XSTR(s)
|
|
|
|
#define XSTR(s) #s
|
2022-03-08 06:58:05 +01:00
|
|
|
|
|
|
|
#if !defined(MIN)
|
|
|
|
# define MIN(x, y) (((x) < (y)) ? (x) : (y))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(MAX)
|
|
|
|
# define MAX(x, y) (((x) > (y)) ? (x) : (y))
|
|
|
|
#endif
|
2022-08-30 10:20:04 +02:00
|
|
|
|
|
|
|
#if !defined(CEILING)
|
|
|
|
/**
|
|
|
|
* @brief Computes the rounded up result of a division of two integers at
|
|
|
|
* compile time.
|
|
|
|
*/
|
|
|
|
# define CEILING(dividend, divisor) (((dividend) + (divisor)-1) / (divisor))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(IS_ARRAY)
|
|
|
|
/**
|
|
|
|
* @brief Returns true if the value is an array, false if it's a pointer.
|
|
|
|
*
|
|
|
|
* This macro is ill-formed for scalars, which is OK for its intended use in
|
|
|
|
* ARRAY_SIZE.
|
|
|
|
*/
|
|
|
|
# define IS_ARRAY(value) (!__builtin_types_compatible_p(typeof((value)), typeof(&(value)[0])))
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#if !defined(ARRAY_SIZE)
|
|
|
|
/**
|
|
|
|
* @brief Computes the number of elements of the given array at compile time.
|
|
|
|
*
|
|
|
|
* This Macro can only be used for statically allocated arrays that have not
|
|
|
|
* been decayed into a pointer. This is detected at compile time, though the
|
|
|
|
* error message for scalar values is poor.
|
|
|
|
*/
|
|
|
|
# define ARRAY_SIZE(array) (__builtin_choose_expr(IS_ARRAY((array)), sizeof((array)) / sizeof((array)[0]), (void)0))
|
|
|
|
#endif
|
2023-09-20 08:33:54 +02:00
|
|
|
|
|
|
|
#if !defined(PACKED)
|
|
|
|
# define PACKED __attribute__((__packed__))
|
|
|
|
#endif
|