Zephyr Project API 4.4.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
bit_rev.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: Copyright The Zephyr Project Contributors
3 *
4 * SPDX-License-Identifier: Apache-2.0
5 */
6
7#ifndef ZEPHYR_INCLUDE_ARCH_RISCV_BIT_REV_H_
8#define ZEPHYR_INCLUDE_ARCH_RISCV_BIT_REV_H_
9
10#ifndef _ASMLANGUAGE
11
12#include <zephyr/types.h>
13#include <zephyr/sys/util.h>
14
15#ifdef __cplusplus
16extern "C" {
17#endif
18
25
26#if defined(CONFIG_ARCH_HAS_BIT_REV) || defined(__DOXYGEN__)
27
36{
37 unsigned long x_rev = x;
38
39 __asm__("rev8 %0, %1\n"
40 "brev8 %0, %0\n"
41 : "=r"(x_rev)
42 : "r"(x_rev));
43
44 return x_rev >> (__riscv_xlen - 32);
45}
46
55{
56 return arch_sys_bit_rev32(x) >> 16;
57}
58
67{
68 __asm__("brev8 %0, %1\n" : "=r"(x) : "r"(x));
69 return x;
70}
71
72#endif /* defined(CONFIG_ARCH_HAS_BIT_REV) || defined(__DOXYGEN__) */
73
77
78#ifdef __cplusplus
79}
80#endif
81
82#endif /* !_ASMLANGUAGE */
83#endif /* ZEPHYR_INCLUDE_ARCH_RISCV_BIT_REV_H_ */
static uint16_t arch_sys_bit_rev16(uint16_t x)
Reverse the bits in a 16-bit value.
Definition bit_rev.h:48
static uint8_t arch_sys_bit_rev8(uint8_t x)
Reverse the bits in an 8-bit value.
Definition bit_rev.h:60
static uint32_t arch_sys_bit_rev32(uint32_t x)
Reverse the bits in a 32-bit value.
Definition bit_rev.h:36
__UINT32_TYPE__ uint32_t
Definition stdint.h:90
__UINT8_TYPE__ uint8_t
Definition stdint.h:88
__UINT16_TYPE__ uint16_t
Definition stdint.h:89
Misc utilities.