Skip to content

Commit

Permalink
endian.h stuff and type_traits is_trivial
Browse files Browse the repository at this point in the history
  • Loading branch information
theverygaming committed Oct 1, 2024
1 parent 3f384c6 commit 2c0be6d
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 14 deletions.
2 changes: 1 addition & 1 deletion bridgenet_clean.sh
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#! /usr/bin/env nix-shell
#! nix-shell -i bash -p bash -p bridge-utils -p tunctl

TAP_INTERFACE_VM=tap1
TAP_INTERFACE_VM=tap0
BRIDGE_INTERFACE=br0

sudo brctl delif ${BRIDGE_INTERFACE} ${TAP_INTERFACE_VM}
Expand Down
58 changes: 45 additions & 13 deletions kernel/include/vix/endian.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,51 @@
#include <vix/types.h>

// clang-format off
#define E_SWAP_16(x) ((x >> 8) | ((x & 0xFF) << 8))
#define E_SWAP_32(x) ((x >> 24) | ((x & 0x00FF0000) >> 8) | ((x & 0x0000FF00) << 8) | (x << 24))
#define E_SWAP_64(x) ((x >> 56) | ((x & 0x00FF000000000000) >> (5 * 8)) | ((x & 0x0000FF0000000000) >> (3 * 8)) | ((x & 0x000000FF00000000) >> 8) | ((x & 0x00000000FF000000) << 8) |((x & 0x0000000000FF0000) << (3 * 8)) | ((x & 0x000000000000FF00) << (5 * 8)) | (x << 56))
// clang-format on

#if (CONFIG_ENDIAN_BIG == 0)
#define LE_16(x) ()
#define LE_32(x) ()
#define LE_64(x) ()
#define BE_16(x) ((x >> 8) | ((x & 0xFF) << 8))
#define BE_32(x) ((x >> 24) | ((x & 0x00FF0000) >> 8) | ((x & 0x0000FF00) << 8) | (x << 24))
#define BE_64(x) ((x >> 56) | ((x & 0x00FF000000000000) >> (5 * 8)) | ((x & 0x0000FF0000000000) >> (3 * 8)) | ((x & 0x000000FF00000000) >> 8) | ((x & 0x00000000FF000000) << 8) |((x & 0x0000000000FF0000) << (3 * 8)) | ((x & 0x000000000000FF00) << (5 * 8)) | (x << 56))
#define LE_16(x) (x)
#define LE_32(x) (x)
#define LE_64(x) (x)
#define BE_16(x) E_SWAP_16(x)
#define BE_32(x) E_SWAP_32(x)
#define BE_64(x) E_SWAP_64(x)
#else
#define LE_16(x) ((x >> 8) | ((x & 0xFF) << 8))
#define LE_32(x) ((x >> 24) | ((x & 0x00FF0000) >> 8) | ((x & 0x0000FF00) << 8) | (x << 24))
#define LE_64(x) ((x >> 56) | ((x & 0x00FF000000000000) >> (5 * 8)) | ((x & 0x0000FF0000000000) >> (3 * 8)) | ((x & 0x000000FF00000000) >> 8) | ((x & 0x00000000FF000000) << 8) |((x & 0x0000000000FF0000) << (3 * 8)) | ((x & 0x000000000000FF00) << (5 * 8)) | (x << 56))
#define BE_16(x) ()
#define BE_32(x) ()
#define BE_64(x) ()
#define LE_16(x) E_SWAP_16(x)
#define LE_32(x) E_SWAP_32(x)
#define LE_64(x) E_SWAP_64(x)
#define BE_16(x) (x)
#define BE_32(x) (x)
#define BE_64(x) (x)
#endif

#ifdef __cplusplus
namespace endian {
constexpr uint16_t c_be_16(uint16_t x) {
return BE_16(x);
}

constexpr uint32_t c_be_32(uint32_t x) {
return BE_32(x);
}

constexpr uint64_t c_be_64(uint64_t x) {
return BE_64(x);
}

constexpr uint16_t c_le_16(uint16_t x) {
return LE_16(x);
}

constexpr uint32_t c_le_32(uint32_t x) {
return LE_32(x);
}

constexpr uint64_t c_le_64(uint64_t x) {
return LE_64(x);
}
}
#endif
// clang-format on
9 changes: 9 additions & 0 deletions kernel/stdlibs/libcxx/include/type_traits
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
#pragma once

namespace std {
template <class T> struct is_trivial {
static constexpr bool value = __is_trivial(T);
};

template <class T> constexpr bool is_trivial_v = is_trivial<T>::value;
}

0 comments on commit 2c0be6d

Please sign in to comment.