blob: dd03ac5aa6026d020cec649e9a4fde5703fd88ec [file] [log] [blame]
yang.lie8fc87b2022-01-11 11:03:24 +08001/*
2 * Copyright (c) 2021-2022 Amlogic, Inc. All rights reserved.
3 *
4 * SPDX-License-Identifier: MIT
5 */
6
Xiaohu.Huangf3d0a0c2021-10-15 11:13:17 +08007#ifndef _RISCV_BITS_H
8#define _RISCV_BITS_H
9
10#define likely(x) __builtin_expect((x), 1)
11#define unlikely(x) __builtin_expect((x), 0)
12
xiaohu.huang38262102022-05-06 22:21:48 +080013#define ROUNDUP(a, b) ((((a)-1) / (b) + 1) * (b))
14#define ROUNDDOWN(a, b) ((a) / (b) * (b))
Xiaohu.Huangf3d0a0c2021-10-15 11:13:17 +080015
16#define MAX(a, b) ((a) > (b) ? (a) : (b))
17#define MIN(a, b) ((a) < (b) ? (a) : (b))
18#define CLAMP(a, lo, hi) MIN(MAX(a, lo), hi)
19
20#define EXTRACT_FIELD(val, which) (((val) & (which)) / ((which) & ~((which)-1)))
xiaohu.huang38262102022-05-06 22:21:48 +080021#define INSERT_FIELD(val, which, fieldval) \
22 (((val) & ~(which)) | ((fieldval) * ((which) & ~((which)-1))))
Xiaohu.Huangf3d0a0c2021-10-15 11:13:17 +080023
24#define STR(x) XSTR(x)
25#define XSTR(x) #x
26
27#if __riscv_xlen == 64
xiaohu.huang38262102022-05-06 22:21:48 +080028#define SLL32 sllw
29#define STORE sd
30#define LOAD ld
31#define LWU lwu
32#define LOG_REGBYTES 3
Xiaohu.Huangf3d0a0c2021-10-15 11:13:17 +080033#else
xiaohu.huang38262102022-05-06 22:21:48 +080034#define SLL32 sll
35#define STORE sw
36#define LOAD lw
37#define LWU lw
38#define LOG_REGBYTES 2
Xiaohu.Huangf3d0a0c2021-10-15 11:13:17 +080039#endif
40#define REGBYTES (1 << LOG_REGBYTES)
41
42#if __riscv_flen == 64
xiaohu.huang38262102022-05-06 22:21:48 +080043#define FPSTORE fsd
44#define FPLOAD fld
45#define LOG_FPREGBYTES 3
Xiaohu.Huangf3d0a0c2021-10-15 11:13:17 +080046#else
xiaohu.huang38262102022-05-06 22:21:48 +080047#define FPSTORE fsw
48#define FPLOAD flw
49#define LOG_FPREGBYTES 2
Xiaohu.Huangf3d0a0c2021-10-15 11:13:17 +080050#endif
xiaohu.huang38262102022-05-06 22:21:48 +080051#define FPREGBYTES (1 << LOG_FPREGBYTES)
Xiaohu.Huangf3d0a0c2021-10-15 11:13:17 +080052
53#endif