yang.li | e8fc87b | 2022-01-11 11:03:24 +0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2021-2022 Amlogic, Inc. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: MIT |
| 5 | */ |
| 6 | |
Xiaohu.Huang | f3d0a0c | 2021-10-15 11:13:17 +0800 | [diff] [blame] | 7 | #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.huang | 3826210 | 2022-05-06 22:21:48 +0800 | [diff] [blame] | 13 | #define ROUNDUP(a, b) ((((a)-1) / (b) + 1) * (b)) |
| 14 | #define ROUNDDOWN(a, b) ((a) / (b) * (b)) |
Xiaohu.Huang | f3d0a0c | 2021-10-15 11:13:17 +0800 | [diff] [blame] | 15 | |
| 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.huang | 3826210 | 2022-05-06 22:21:48 +0800 | [diff] [blame] | 21 | #define INSERT_FIELD(val, which, fieldval) \ |
| 22 | (((val) & ~(which)) | ((fieldval) * ((which) & ~((which)-1)))) |
Xiaohu.Huang | f3d0a0c | 2021-10-15 11:13:17 +0800 | [diff] [blame] | 23 | |
| 24 | #define STR(x) XSTR(x) |
| 25 | #define XSTR(x) #x |
| 26 | |
| 27 | #if __riscv_xlen == 64 |
xiaohu.huang | 3826210 | 2022-05-06 22:21:48 +0800 | [diff] [blame] | 28 | #define SLL32 sllw |
| 29 | #define STORE sd |
| 30 | #define LOAD ld |
| 31 | #define LWU lwu |
| 32 | #define LOG_REGBYTES 3 |
Xiaohu.Huang | f3d0a0c | 2021-10-15 11:13:17 +0800 | [diff] [blame] | 33 | #else |
xiaohu.huang | 3826210 | 2022-05-06 22:21:48 +0800 | [diff] [blame] | 34 | #define SLL32 sll |
| 35 | #define STORE sw |
| 36 | #define LOAD lw |
| 37 | #define LWU lw |
| 38 | #define LOG_REGBYTES 2 |
Xiaohu.Huang | f3d0a0c | 2021-10-15 11:13:17 +0800 | [diff] [blame] | 39 | #endif |
| 40 | #define REGBYTES (1 << LOG_REGBYTES) |
| 41 | |
| 42 | #if __riscv_flen == 64 |
xiaohu.huang | 3826210 | 2022-05-06 22:21:48 +0800 | [diff] [blame] | 43 | #define FPSTORE fsd |
| 44 | #define FPLOAD fld |
| 45 | #define LOG_FPREGBYTES 3 |
Xiaohu.Huang | f3d0a0c | 2021-10-15 11:13:17 +0800 | [diff] [blame] | 46 | #else |
xiaohu.huang | 3826210 | 2022-05-06 22:21:48 +0800 | [diff] [blame] | 47 | #define FPSTORE fsw |
| 48 | #define FPLOAD flw |
| 49 | #define LOG_FPREGBYTES 2 |
Xiaohu.Huang | f3d0a0c | 2021-10-15 11:13:17 +0800 | [diff] [blame] | 50 | #endif |
xiaohu.huang | 3826210 | 2022-05-06 22:21:48 +0800 | [diff] [blame] | 51 | #define FPREGBYTES (1 << LOG_FPREGBYTES) |
Xiaohu.Huang | f3d0a0c | 2021-10-15 11:13:17 +0800 | [diff] [blame] | 52 | |
| 53 | #endif |