.githooks/
riscv/
test/
.clang-format
570 B
.gitignore
5 B
.gitsigners
112 B
AGENTS.md
227 B
LICENSE
1.1 KiB
Makefile
3.5 KiB
README
12.5 KiB
STYLE
781 B
abi_host.c
12.2 KiB
abi_linux.c
3.7 KiB
bitmanip.h
5.8 KiB
color.h
567 B
debug_map.c
5.1 KiB
debug_map.h
1.3 KiB
emulator.c
87.3 KiB
host.h
5.5 KiB
host_posix.c
11.2 KiB
hosted.h
5.7 KiB
image_native.c
4.6 KiB
image_rad0.c
2.7 KiB
image_raw.c
2.6 KiB
io.c
1.1 KiB
io.h
444 B
jit.c
99.2 KiB
jit.h
7.8 KiB
machine.c
4.4 KiB
machine.h
2.1 KiB
machine_cpu.c
13.6 KiB
machine_csr.c
4.6 KiB
machine_devices.c
10.8 KiB
machine_fdt.c
8.7 KiB
machine_internal.h
7.4 KiB
muldiv.h
1.0 KiB
profile.c
17.5 KiB
profile.h
1.4 KiB
riscv.c
755 B
riscv.h
4.3 KiB
types.h
1019 B
vector.c
54.0 KiB
vector.h
1.3 KiB
muldiv.h
raw
| 1 | #ifndef MULDIV_H |
| 2 | #define MULDIV_H |
| 3 | |
| 4 | #include "types.h" |
| 5 | |
| 6 | __extension__ typedef unsigned __int128 u128; |
| 7 | |
| 8 | /* High 64 bits of the unsigned 128-bit product. */ |
| 9 | static inline u64 mulhu64(u64 a, u64 b) { |
| 10 | return (u64)(((u128)a * b) >> 64); |
| 11 | } |
| 12 | |
| 13 | /* High 64 bits of the signed x signed product. */ |
| 14 | static inline u64 mulh64(u64 a, u64 b) { |
| 15 | return mulhu64(a, b) - ((i64)a < 0 ? b : 0) - ((i64)b < 0 ? a : 0); |
| 16 | } |
| 17 | |
| 18 | /* High 64 bits of the signed x unsigned product. */ |
| 19 | static inline u64 mulhsu64(u64 a, u64 b) { |
| 20 | return mulhu64(a, b) - ((i64)a < 0 ? b : 0); |
| 21 | } |
| 22 | |
| 23 | /* Signed division with the RISC-V results for a zero divisor (quotient -1, |
| 24 | * remainder a) and for overflow (INT_MIN / -1: quotient INT_MIN, remainder 0). |
| 25 | * Operands are sign-extended, so the same helper serves the W forms. */ |
| 26 | static inline u64 divs64(u64 a, u64 b, bool remainder) { |
| 27 | if (b == 0) |
| 28 | return remainder ? a : (u64)-1; |
| 29 | if (b == (u64)-1) |
| 30 | return remainder ? 0 : -a; |
| 31 | return remainder ? (u64)((i64)a % (i64)b) : (u64)((i64)a / (i64)b); |
| 32 | } |
| 33 | |
| 34 | #endif /* MULDIV_H */ |