2020-02-21 20:07:49 +01:00
|
|
|
// Matrix Construct
|
|
|
|
//
|
|
|
|
// Copyright (C) Matrix Construct Developers, Authors & Contributors
|
|
|
|
// Copyright (C) 2016-2018 Jason Volk <jason@zemos.net>
|
|
|
|
//
|
|
|
|
// Permission to use, copy, modify, and/or distribute this software for any
|
|
|
|
// purpose with or without fee is hereby granted, provided that the above
|
|
|
|
// copyright notice and this permission notice is present in all copies. The
|
|
|
|
// full license for this software is available in the LICENSE file.
|
|
|
|
|
|
|
|
//
|
|
|
|
// Portability Macros & Developer Tools
|
|
|
|
//
|
|
|
|
|
2022-05-14 22:23:09 +02:00
|
|
|
#pragma once
|
2020-02-21 20:07:49 +01:00
|
|
|
#define HAVE_IRCD_PORTABLE_H
|
|
|
|
|
2020-04-25 06:57:54 +02:00
|
|
|
//
|
|
|
|
// For non-clang
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef __has_builtin
|
|
|
|
#define __has_builtin(x) 0
|
|
|
|
#endif
|
|
|
|
|
2020-04-27 22:58:39 +02:00
|
|
|
#ifndef __is_identifier
|
|
|
|
#define __is_identifier(x) 0
|
|
|
|
#endif
|
|
|
|
|
2023-02-07 20:26:32 +01:00
|
|
|
#ifndef __has_feature
|
|
|
|
#define __has_feature(x) 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef __has_cpp_attribute
|
|
|
|
#define __has_cpp_attribute(x) 0
|
|
|
|
#endif
|
|
|
|
|
2020-02-21 20:07:49 +01:00
|
|
|
//
|
|
|
|
// Common branch prediction macros
|
|
|
|
//
|
|
|
|
|
2022-10-09 02:09:28 +02:00
|
|
|
#if !defined(likely)
|
|
|
|
#if __has_builtin(__builtin_expect)
|
|
|
|
#define likely(x) __builtin_expect(!!(x), 1)
|
|
|
|
#else
|
|
|
|
#define likely(x) (x)
|
|
|
|
#endif
|
2020-02-21 20:07:49 +01:00
|
|
|
#endif
|
|
|
|
|
2022-10-09 02:09:28 +02:00
|
|
|
#if !defined(unlikely)
|
|
|
|
#if __has_builtin(__builtin_expect)
|
|
|
|
#define unlikely(x) __builtin_expect(!!(x), 0)
|
|
|
|
#else
|
|
|
|
#define unlikely(x) (x)
|
|
|
|
#endif
|
2020-02-21 20:07:49 +01:00
|
|
|
#endif
|
|
|
|
|
2022-11-03 19:30:16 +01:00
|
|
|
#if !defined(unpredictable)
|
|
|
|
#if __has_builtin(__builtin_unpredictable)
|
2023-02-12 20:51:55 +01:00
|
|
|
#define unpredictable(x) __builtin_unpredictable(!!(x))
|
2022-11-03 19:30:16 +01:00
|
|
|
#else
|
|
|
|
#define unpredictable(x) (x)
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2022-05-03 02:52:37 +02:00
|
|
|
//
|
|
|
|
// Assume
|
|
|
|
//
|
|
|
|
|
2022-10-09 02:09:28 +02:00
|
|
|
#if !defined(assume)
|
2023-02-09 02:24:02 +01:00
|
|
|
#if __has_builtin(__builtin_assume) && defined(__cplusplus)
|
|
|
|
// If the expression is 'evaluated' (llvm) (which includes any
|
|
|
|
// function call not explicitly annotated pure, even when fully
|
|
|
|
// inlined) then the assume is diagnosed by -Wassume and ignored.
|
|
|
|
// Declaring the bool mitigates this.
|
|
|
|
#define assume(x) assert(x); ({ const bool y(x); __builtin_assume(y); })
|
|
|
|
#elif __has_builtin(__builtin_assume)
|
|
|
|
#define assume(x) assert(x); __builtin_assume(x)
|
2022-10-09 02:09:28 +02:00
|
|
|
#else
|
2023-02-09 02:24:02 +01:00
|
|
|
#define assume(x) assert(x)
|
2022-10-09 02:09:28 +02:00
|
|
|
#endif
|
2022-05-03 02:52:37 +02:00
|
|
|
#endif
|
|
|
|
|
2023-03-04 05:39:17 +01:00
|
|
|
//
|
|
|
|
// Target clones
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifdef RB_CLONES
|
|
|
|
#define IRCD_CLONES(features) gnu::target_clones(features)
|
|
|
|
#else
|
|
|
|
#define IRCD_CLONES(features)
|
|
|
|
#endif
|
|
|
|
|
2020-02-21 20:07:49 +01:00
|
|
|
//
|
|
|
|
// 128 bit integer support
|
|
|
|
//
|
|
|
|
|
2021-04-11 01:34:19 +02:00
|
|
|
#if defined(__cplusplus) && (!defined(HAVE_INT128_T) || !defined(HAVE_UINT128_T))
|
2020-02-21 20:07:49 +01:00
|
|
|
namespace ircd
|
|
|
|
{
|
|
|
|
#if defined(HAVE___INT128_T) && defined(HAVE__UINT128_T)
|
2023-01-16 01:37:26 +01:00
|
|
|
using int128_t = __int128_t;
|
|
|
|
using uint128_t = __uint128_t;
|
2020-02-21 20:07:49 +01:00
|
|
|
#elif defined(HAVE___INT128)
|
2023-01-16 01:37:26 +01:00
|
|
|
using int128_t = signed __int128;
|
|
|
|
using uint128_t = unsigned __int128;
|
2020-02-21 20:07:49 +01:00
|
|
|
#else
|
|
|
|
#error "Missing 128 bit integer types on this platform."
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
//
|
2021-04-11 01:34:19 +02:00
|
|
|
// Other convenience typedefs
|
2020-02-21 20:07:49 +01:00
|
|
|
//
|
|
|
|
|
2021-04-11 01:34:19 +02:00
|
|
|
#if defined(__cplusplus)
|
|
|
|
namespace ircd
|
|
|
|
{
|
2022-10-09 02:09:28 +02:00
|
|
|
using longlong = long long;
|
|
|
|
using ulonglong = unsigned long long;
|
2021-04-11 01:34:19 +02:00
|
|
|
}
|
2020-02-21 20:07:49 +01:00
|
|
|
#endif
|
2021-04-02 21:57:39 +02:00
|
|
|
|
|
|
|
//
|
2021-04-11 01:34:19 +02:00
|
|
|
// OpenCL compat
|
2021-04-02 21:57:39 +02:00
|
|
|
//
|
|
|
|
|
|
|
|
#if !defined(uchar)
|
|
|
|
typedef unsigned char uchar;
|
|
|
|
#endif
|
2021-04-11 01:34:19 +02:00
|
|
|
|
|
|
|
//
|
|
|
|
// Trouble; FreeBSD unsigned long ctype
|
|
|
|
//
|
|
|
|
|
|
|
|
#if defined(__FreeBSD__) && !defined(ulong)
|
|
|
|
typedef u_long ulong;
|
|
|
|
#endif
|