Skip to content

Commit

Permalink
Clean up system os/arch macros
Browse files Browse the repository at this point in the history
  • Loading branch information
ZeroMemes committed Oct 7, 2024
1 parent 0d77b44 commit 88849ee
Show file tree
Hide file tree
Showing 6 changed files with 23 additions and 20 deletions.
33 changes: 18 additions & 15 deletions include/libhat/Defines.hpp
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
#pragma once

// Detect CPU Architecture
#if defined(_M_X64) || defined(__amd64__) || defined(_M_IX86) || defined(__i386__)
#if defined(_M_X64) || defined(__amd64__)
#define LIBHAT_X86_64
#elif defined(_M_IX86) || defined(__i386__)
#define LIBHAT_X86
#if defined(_M_X64) || defined(__amd64__)
#define LIBHAT_X86_64
#endif
#elif defined(_M_ARM64) || defined(__aarch64__) || defined(_M_ARM) || defined(__arm__)
#elif defined(_M_ARM64) || defined(__aarch64__)
#define LIBHAT_AARCH64
#elif defined(_M_ARM) || defined(__arm__)
#define LIBHAT_ARM
#else
#error Unsupported Architecture
Expand All @@ -15,22 +16,24 @@
// Detect Operating System
#if defined(_WIN32)
#define LIBHAT_WINDOWS
#elif defined(__unix__) || defined(__unix) || defined(__APPLE__) || defined(__MACH__)
#elif defined(linux) || defined(__linux__) || defined(__linux)
#define LIBHAT_UNIX
#define LIBHAT_LINUX
#elif defined(__APPLE__) && defined(__MACH__)
#define LIBHAT_UNIX
#define LIBHAT_MAC
#else
#error Unsupported Operating System
#endif

// Macros wrapping intrinsics
#ifdef LIBHAT_X86
#ifdef LIBHAT_X86_64
#define LIBHAT_TZCNT64(num) _tzcnt_u64(num)
#define LIBHAT_BLSR64(num) _blsr_u64(num)
#else
#include <bit>
#define LIBHAT_TZCNT64(num) std::countl_zero(num)
#define LIBHAT_BLSR64(num) num & (num - 1)
#endif
#if defined(LIBHAT_X86_64)
#define LIBHAT_TZCNT64(num) _tzcnt_u64(num)
#define LIBHAT_BLSR64(num) _blsr_u64(num)
#elif defined(LIBHAT_X86)
#include <bit>
#define LIBHAT_TZCNT64(num) std::countl_zero(num)
#define LIBHAT_BLSR64(num) num & (num - 1)
#endif

#ifdef _MSC_VER
Expand Down
2 changes: 1 addition & 1 deletion include/libhat/System.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ namespace hat {
};
}

#if defined(LIBHAT_X86)
#if defined(LIBHAT_X86) || defined(LIBHAT_X86_64)
namespace hat {

struct system_info_x86 : hat::system_info {
Expand Down
2 changes: 1 addition & 1 deletion src/Scanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ namespace hat::detail {
}

void scan_context::auto_resolve_scanner() {
#if defined(LIBHAT_X86)
#if defined(LIBHAT_X86) || defined(LIBHAT_X86_64)
const auto& ext = get_system().extensions;
if (ext.bmi) {
#if defined(LIBHAT_X86_64) && !defined(LIBHAT_DISABLE_AVX512)
Expand Down
2 changes: 1 addition & 1 deletion src/arch/x86/AVX2.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <libhat/Defines.hpp>

#ifdef LIBHAT_X86
#if defined(LIBHAT_X86) || defined(LIBHAT_X86_64)

#include <libhat/Scanner.hpp>

Expand Down
2 changes: 1 addition & 1 deletion src/arch/x86/SSE.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#include <libhat/Defines.hpp>

#if defined(LIBHAT_X86) && !defined(LIBHAT_DISABLE_SSE)
#if (defined(LIBHAT_X86) || defined(LIBHAT_X86_64)) && !defined(LIBHAT_DISABLE_SSE)

#include <libhat/Scanner.hpp>

Expand Down
2 changes: 1 addition & 1 deletion src/arch/x86/System.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#include <libhat/Defines.hpp>
#ifdef LIBHAT_X86
#if defined(LIBHAT_X86) || defined(LIBHAT_X86_64)

#include <libhat/System.hpp>

Expand Down

0 comments on commit 88849ee

Please sign in to comment.