TT Zephyr Platforms
18.11.99
Tenstorrent Firmware
Loading...
Searching...
No Matches
bitrev.h
Go to the documentation of this file.
1
/*
2
* Copyright (c) 2024 Tenstorrent AI ULC
3
*
4
* SPDX-License-Identifier: Apache-2.0
5
*/
6
7
#ifndef INCLUDE_TENSTORRENT_BITREV_H_
8
#define INCLUDE_TENSTORRENT_BITREV_H_
9
10
#include <
stdint.h
>
11
12
#ifdef __cplusplus
13
extern
"C"
{
14
#endif
15
16
static
inline
uint8_t
bitrev4
(
uint8_t
nibble)
17
{
18
const
uint8_t
rev4[] = {0x0, 0x8, 0x4, 0xc, 0x2, 0xa, 0x6, 0xe,
19
0x1, 0x9, 0x5, 0xd, 0x3, 0xb, 0x7, 0xf};
20
21
return
rev4[nibble & 0xf];
22
}
23
24
static
inline
uint8_t
bitrev8
(
uint8_t
byte
)
25
{
26
return
(
bitrev4
(
byte
) << 4) |
bitrev4
(
byte
>> 4);
27
}
28
29
static
inline
uint16_t
bitrev16
(
uint16_t
hword)
30
{
31
return
((
uint16_t
)
bitrev8
(hword) << 8) |
bitrev8
(hword >> 8);
32
}
33
34
static
inline
uint32_t
bitrev32
(
uint32_t
word)
35
{
36
return
((
uint32_t
)
bitrev16
(word) << 16) |
bitrev16
(word >> 16);
37
}
38
39
static
inline
uint64_t
bitrev64
(
uint64_t
dword)
40
{
41
return
((
uint64_t
)
bitrev32
(dword) << 32) |
bitrev32
(dword >> 32);
42
}
43
44
/*
45
* Note: arbitrary bit-widths can be reversed trivially by rounding
46
* up to the nearest power of 2, performing the bit-reverals, and then
47
* shifting.
48
*
49
* E.g. to reverse the 24 least-sigbnificant bits of a 32-bit word:
50
*
51
* static inline uint32_t bitrev24(uint32_t word) {
52
* return bitrev32(word) >> (32 - 24);
53
* }
54
*/
55
56
#ifdef __cplusplus
57
}
58
#endif
59
60
#endif
/* INCLUDE_TENSTORRENT_BITREV_H_ */
bitrev8
static uint8_t bitrev8(uint8_t byte)
Definition
bitrev.h:24
bitrev64
static uint64_t bitrev64(uint64_t dword)
Definition
bitrev.h:39
bitrev4
static uint8_t bitrev4(uint8_t nibble)
Definition
bitrev.h:16
bitrev32
static uint32_t bitrev32(uint32_t word)
Definition
bitrev.h:34
bitrev16
static uint16_t bitrev16(uint16_t hword)
Definition
bitrev.h:29
stdint.h
uint32_t
__UINT32_TYPE__ uint32_t
uint64_t
__UINT64_TYPE__ uint64_t
uint8_t
__UINT8_TYPE__ uint8_t
uint16_t
__UINT16_TYPE__ uint16_t
tenstorrent
bitrev.h
Generated by
1.14.0