diff options
| author | Kimplul <kimi.h.kuparinen@gmail.com> | 2021-08-31 00:13:40 +0300 |
|---|---|---|
| committer | Kimplul <kimi.h.kuparinen@gmail.com> | 2021-08-31 00:13:40 +0300 |
| commit | 1ab464d959b9ee3d3bb6758ac0d9d33fc6c77e46 (patch) | |
| tree | 8d6832f0eadacce1613778bcecfcdaa2391aba79 /common/bytes.c | |
| parent | 2939b749b1169a0c01c19698a3f0026034346ebd (diff) | |
| download | kmi-1ab464d959b9ee3d3bb6758ac0d9d33fc6c77e46.tar.gz kmi-1ab464d959b9ee3d3bb6758ac0d9d33fc6c77e46.zip | |
Improved linkind process, added padding generator
Diffstat (limited to 'common/bytes.c')
| -rw-r--r-- | common/bytes.c | 27 |
1 files changed, 5 insertions, 22 deletions
diff --git a/common/bytes.c b/common/bytes.c index 1196989..af65568 100644 --- a/common/bytes.c +++ b/common/bytes.c @@ -1,31 +1,14 @@ #include <apos/types.h> #include <apos/attrs.h> +#include <apos/bytes.h> +#include <apos/builtin.h> -/* Functions for swapping endianness. - * - * Typically you wouldn't call these directly, instead using macros such as - * le16_to_cpu, cpu_to_be32, etc. that take the system endianness into account. - * - * The macros cpu_to_be64 etc. use GCC's and Clang's __builtin_bswap16/32/64, but in - * the case that the arch compiler doesn't provide the __builtin functions they're replaced - * with __bswaphi2/si2/di2 respectively, and it is up to the developer to - * provide these. The naming scheme uses GCC's internal naming scheme, where - * - * HI ~= 16 bits - * SI ~= 32 bits - * DI ~= 64 bits - * - * Here we assume this to be true in all cases, and it probably is, but in the - * case that some architecture is different (SI ~= 64 bits or something) we define - * these functions as __weak, allowing any arch to redefine them. - */ - -__weak uint16_t __bswaphi2(uint16_t u) +__weak uint16_t __bswap16(uint16_t u) { return (u & 0xff00) >> 8 | (u & 0x00ff) << 8; } -__weak uint32_t __bswapsi2(uint32_t u) +__weak uint32_t __bswap32(uint32_t u) { return (u & 0xff000000) >> 24 | (u & 0x00ff0000) >> 8 | @@ -33,7 +16,7 @@ __weak uint32_t __bswapsi2(uint32_t u) (u & 0x000000ff) << 24; } -__weak uint64_t __bswapdi2(uint64_t u) +__weak uint64_t __bswap64(uint64_t u) { return (u & 0xff00000000000000ULL) >> 56 | (u & 0x00ff000000000000ULL) >> 40 | |
