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
|
|
|
|
|
2020-02-21 20:07:49 +01:00
|
|
|
//
|
|
|
|
// Common branch prediction macros
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef likely
|
|
|
|
#define likely(x) __builtin_expect(!!(x), 1)
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifndef unlikely
|
|
|
|
#define unlikely(x) __builtin_expect(!!(x), 0)
|
|
|
|
#endif
|
|
|
|
|
2022-05-03 02:52:37 +02:00
|
|
|
//
|
|
|
|
// Assume
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef assume
|
|
|
|
#if __has_builtin(__builtin_assume)
|
|
|
|
#define assume(x) assert(x); __builtin_assume(x);
|
|
|
|
#else
|
|
|
|
#define assume(x) assert(x);
|
|
|
|
#endif
|
|
|
|
#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)
|
2020-10-09 03:18:54 +02:00
|
|
|
using int128_t = __int128_t __attribute__((aligned(16)));
|
|
|
|
using uint128_t = __uint128_t __attribute__((aligned(16)));
|
2020-02-21 20:07:49 +01:00
|
|
|
#elif defined(HAVE___INT128)
|
2020-10-09 03:18:54 +02:00
|
|
|
using int128_t = signed __int128 __attribute__((aligned(16)));
|
|
|
|
using uint128_t = unsigned __int128 __attribute__((aligned(16)));
|
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
|
|
|
|
{
|
|
|
|
using longlong = long long;
|
|
|
|
using ulonglong = unsigned long long;
|
|
|
|
}
|
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
|