|
| 1 | +/* |
| 2 | + * RISC-V translation routines for the (unratified) Zbr CRC32 bitmanip extension |
| 3 | + * version 0.93. |
| 4 | + * |
| 5 | + * Copyright (c) 2026 Rivos Inc. |
| 6 | + * |
| 7 | + * This program is free software; you can redistribute it and/or modify it |
| 8 | + * under the terms and conditions of the GNU General Public License, |
| 9 | + * version 2 or later, as published by the Free Software Foundation. |
| 10 | + * |
| 11 | + * This program is distributed in the hope it will be useful, but WITHOUT |
| 12 | + * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
| 13 | + * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for |
| 14 | + * more details. |
| 15 | + * |
| 16 | + * You should have received a copy of the GNU General Public License along with |
| 17 | + * this program. If not, see <http://www.gnu.org/licenses/>. |
| 18 | + */ |
| 19 | + |
| 20 | +#define REQUIRE_XBR0P93(ctx) do { \ |
| 21 | + if (!ctx->cfg_ptr->ext_xbr0p93) { \ |
| 22 | + return false; \ |
| 23 | + } \ |
| 24 | +} while (0) |
| 25 | + |
| 26 | +static bool gen_crc(DisasContext *ctx, arg_r2 *a, |
| 27 | + void (*func)(TCGv, TCGv, TCGv), TCGv tsz) |
| 28 | +{ |
| 29 | + REQUIRE_XBR0P93(ctx); |
| 30 | + TCGv dest = dest_gpr(ctx, a->rd); |
| 31 | + TCGv src1 = get_gpr(ctx, a->rs1, EXT_NONE); |
| 32 | + |
| 33 | + func(dest, src1, tsz); |
| 34 | + gen_set_gpr(ctx, a->rd, dest); |
| 35 | + |
| 36 | + return true; |
| 37 | +} |
| 38 | + |
| 39 | +#define TRANS_CRC32(NAME, SIZE) \ |
| 40 | + static bool trans_crc32_##NAME(DisasContext *ctx, arg_r2 *a) \ |
| 41 | + { if (SIZE == 8) { REQUIRE_64BIT(ctx); }; \ |
| 42 | + return gen_crc(ctx, a, gen_helper_crc32, tcg_constant_tl(SIZE)); } |
| 43 | +#define TRANS_CRC32C(NAME, SIZE) \ |
| 44 | + static bool trans_crc32c_##NAME(DisasContext *ctx, arg_r2 *a) \ |
| 45 | + { if (SIZE == 8) { REQUIRE_64BIT(ctx); }; \ |
| 46 | + return gen_crc(ctx, a, gen_helper_crc32c, tcg_constant_tl(SIZE)); } |
| 47 | + |
| 48 | +TRANS_CRC32(b, 1); |
| 49 | +TRANS_CRC32(h, 2); |
| 50 | +TRANS_CRC32(w, 4); |
| 51 | +TRANS_CRC32(d, 8); |
| 52 | +TRANS_CRC32C(b, 1); |
| 53 | +TRANS_CRC32C(h, 2); |
| 54 | +TRANS_CRC32C(w, 4); |
| 55 | +TRANS_CRC32C(d, 8); |
0 commit comments