| 1 | /* |
| 2 | * RISC-V translation routines for xlrbr matching the unratified Zbr CRC32 |
| 3 | * bitmanip extension v0.93. |
| 4 | * |
| 5 | * Copyright (c) 2026 Rivos Inc. |
| 6 | * |
| 7 | * SPDX-License-Identifier: GPL-2.0-or-later |
| 8 | */ |
| 9 | |
| 10 | #define REQUIRE_XLRBR(ctx) do { \ |
| 11 | if (!ctx->cfg_ptr->ext_xlrbr) { \ |
| 12 | return false; \ |
| 13 | } \ |
| 14 | } while (0) |
| 15 | |
| 16 | static bool gen_crc(DisasContext *ctx, arg_r2 *a, |
| 17 | void (*func)(TCGv, TCGv, TCGv), TCGv tsz) |
| 18 | { |
| 19 | REQUIRE_XLRBR(ctx); |
| 20 | TCGv dest = dest_gpr(ctx, a->rd); |
| 21 | TCGv src1 = get_gpr(ctx, a->rs1, EXT_NONE); |
| 22 | |
| 23 | func(dest, src1, tsz); |
| 24 | gen_set_gpr(ctx, a->rd, dest); |
| 25 | |
| 26 | return true; |
| 27 | } |
| 28 | |
| 29 | #define TRANS_CRC32(NAME, SIZE) \ |
| 30 | static bool trans_crc32_##NAME(DisasContext *ctx, arg_r2 *a) \ |
| 31 | { if (SIZE == 8) { REQUIRE_64BIT(ctx); }; \ |
| 32 | return gen_crc(ctx, a, gen_helper_crc32, tcg_constant_tl(SIZE)); } |
| 33 | #define TRANS_CRC32C(NAME, SIZE) \ |
| 34 | static bool trans_crc32c_##NAME(DisasContext *ctx, arg_r2 *a) \ |
| 35 | { if (SIZE == 8) { REQUIRE_64BIT(ctx); }; \ |
| 36 | return gen_crc(ctx, a, gen_helper_crc32c, tcg_constant_tl(SIZE)); } |
| 37 | |
| 38 | TRANS_CRC32(b, 1); |
| 39 | TRANS_CRC32(h, 2); |
| 40 | TRANS_CRC32(w, 4); |
| 41 | TRANS_CRC32(d, 8); |
| 42 | TRANS_CRC32C(b, 1); |
| 43 | TRANS_CRC32C(h, 2); |
| 44 | TRANS_CRC32C(w, 4); |
| 45 | TRANS_CRC32C(d, 8); |