disas/riscv: Move operand extractors earlier in file
Reviewed-by: Alistair Francis <alistair.francis@wdc.com> Signed-off-by: Richard Henderson <richard.henderson@linaro.org> Message-ID: <20260812223142.349142-2-richard.henderson@linaro.org> Signed-off-by: Alistair Francis <alistair.francis@wdc.com>
Richard Henderson committed
Aug 12, 2026 at 15:30 UTC
df975586d89f59c93c944815c69bef188bbde572
1 file changed
+435
-435
disas/riscv.c
+435
-435
@@ -1259,6 +1259,401 @@ static const rv_comp_data rvcp_fsgnjx_q[] = {
1259
{ rv_op_illegal, NULL }
1260
};
1261
1262
+/* operand extractors */
1263
+
1264
+static uint32_t operand_rd(rv_inst inst)
1265
+{
1266
+ return extract32(inst, 7, 5);
1267
+}
1268
+
1269
+static uint32_t operand_rs1(rv_inst inst)
1270
+{
1271
+ return extract32(inst, 15, 5);
1272
+}
1273
+
1274
+static uint32_t operand_rs2(rv_inst inst)
1275
+{
1276
+ return extract32(inst, 20, 5);
1277
+}
1278
+
1279
+static uint32_t operand_rs3(rv_inst inst)
1280
+{
1281
+ return extract32(inst, 27, 5);
1282
+}
1283
+
1284
+static uint32_t operand_aq(rv_inst inst)
1285
+{
1286
+ return extract32(inst, 26, 1);
1287
+}
1288
+
1289
+static uint32_t operand_rl(rv_inst inst)
1290
+{
1291
+ return extract32(inst, 25, 1);
1292
+}
1293
+
1294
+static uint32_t operand_pred(rv_inst inst)
1295
+{
1296
+ return extract32(inst, 24, 4);
1297
+}
1298
+
1299
+static uint32_t operand_succ(rv_inst inst)
1300
+{
1301
+ return extract32(inst, 20, 4);
1302
+}
1303
+
1304
+static uint32_t operand_rm(rv_inst inst)
1305
+{
1306
+ return extract32(inst, 12, 3);
1307
+}
1308
+
1309
+static uint32_t operand_shamt5(rv_inst inst)
1310
+{
1311
+ return extract32(inst, 20, 5);
1312
+}
1313
+
1314
+static uint32_t operand_shamt6(rv_inst inst)
1315
+{
1316
+ return extract32(inst, 20, 6);
1317
+}
1318
+
1319
+static uint32_t operand_shamt7(rv_inst inst)
1320
+{
1321
+ return extract32(inst, 20, 7);
1322
+}
1323
+
1324
+static uint32_t operand_crdq(rv_inst inst)
1325
+{
1326
+ return extract32(inst, 2, 3);
1327
+}
1328
+
1329
+static uint32_t operand_crs1q(rv_inst inst)
1330
+{
1331
+ return extract32(inst, 7, 3);
1332
+}
1333
+
1334
+static uint32_t operand_crs1rdq(rv_inst inst)
1335
+{
1336
+ return extract32(inst, 7, 3);
1337
+}
1338
+
1339
+static uint32_t operand_crs2q(rv_inst inst)
1340
+{
1341
+ return extract32(inst, 2, 3);
1342
+}
1343
+
1344
+static uint32_t calculate_xreg(uint32_t sreg)
1345
+{
1346
+ return sreg < 2 ? sreg + 8 : sreg + 16;
1347
+}
1348
+
1349
+static uint32_t operand_sreg1(rv_inst inst)
1350
+{
1351
+ return calculate_xreg(extract32(inst, 7, 3));
1352
+}
1353
+
1354
+static uint32_t operand_sreg2(rv_inst inst)
1355
+{
1356
+ return calculate_xreg(extract32(inst, 2, 3));
1357
+}
1358
+
1359
+static uint32_t operand_crd(rv_inst inst)
1360
+{
1361
+ return extract32(inst, 7, 5);
1362
+}
1363
+
1364
+static uint32_t operand_crs1(rv_inst inst)
1365
+{
1366
+ return extract32(inst, 7, 5);
1367
+}
1368
+
1369
+static uint32_t operand_crs1rd(rv_inst inst)
1370
+{
1371
+ return extract32(inst, 7, 5);
1372
+}
1373
+
1374
+static uint32_t operand_crs2(rv_inst inst)
1375
+{
1376
+ return extract32(inst, 2, 5);
1377
+}
1378
+
1379
+static uint32_t operand_cimmsh5(rv_inst inst)
1380
+{
1381
+ return extract32(inst, 2, 5);
1382
+}
1383
+
1384
+static uint32_t operand_csr12(rv_inst inst)
1385
+{
1386
+ return extract32(inst, 20, 12);
1387
+}
1388
+
1389
+static int32_t operand_imm12(rv_inst inst)
1390
+{
1391
+ return sextract32(inst, 20, 12);
1392
+}
1393
+
1394
+static int32_t operand_imm20(rv_inst inst)
1395
+{
1396
+ return sextract32(inst, 12, 20) << 12;
1397
+}
1398
+
1399
+static int32_t operand_jimm20(rv_inst inst)
1400
+{
1401
+ return sextract32(inst, 31, 1) << 20 |
1402
+ extract32(inst, 21, 10) << 1 |
1403
+ extract32(inst, 20, 1) << 11 |
1404
+ extract32(inst, 12, 8) << 12;
1405
+}
1406
+
1407
+static int32_t operand_simm12(rv_inst inst)
1408
+{
1409
+ return sextract32(inst, 25, 7) << 5 |
1410
+ extract32(inst, 7, 5);
1411
+}
1412
+
1413
+static int32_t operand_sbimm12(rv_inst inst)
1414
+{
1415
+ return sextract32(inst, 31, 1) << 12 |
1416
+ extract32(inst, 25, 6) << 5 |
1417
+ extract32(inst, 8, 4) << 1 |
1418
+ extract32(inst, 7, 1) << 11;
1419
+}
1420
+
1421
+static uint32_t operand_cimmshl6(rv_inst inst, rv_isa isa)
1422
+{
1423
+ int imm = extract32(inst, 12, 1) << 5 |
1424
+ extract32(inst, 2, 5);
1425
+ if (isa == rv128) {
1426
+ imm = imm ? imm : 64;
1427
+ }
1428
+ return imm;
1429
+}
1430
+
1431
+static uint32_t operand_cimmshr6(rv_inst inst, rv_isa isa)
1432
+{
1433
+ int imm = extract32(inst, 12, 1) << 5 |
1434
+ extract32(inst, 2, 5);
1435
+ if (isa == rv128) {
1436
+ imm = imm | (imm & 32) << 1;
1437
+ imm = imm ? imm : 64;
1438
+ }
1439
+ return imm;
1440
+}
1441
+
1442
+static int32_t operand_cimmi(rv_inst inst)
1443
+{
1444
+ return sextract32(inst, 12, 1) << 5 |
1445
+ extract32(inst, 2, 5);
1446
+}
1447
+
1448
+static int32_t operand_cimmui(rv_inst inst)
1449
+{
1450
+ return sextract32(inst, 12, 1) << 17 |
1451
+ extract32(inst, 2, 5) << 12;
1452
+}
1453
+
1454
+static uint32_t operand_cimmlwsp(rv_inst inst)
1455
+{
1456
+ return extract32(inst, 12, 1) << 5 |
1457
+ extract32(inst, 4, 3) << 2 |
1458
+ extract32(inst, 2, 2) << 6;
1459
+}
1460
+
1461
+static uint32_t operand_cimmldsp(rv_inst inst)
1462
+{
1463
+ return extract32(inst, 12, 1) << 5 |
1464
+ extract32(inst, 5, 2) << 3 |
1465
+ extract32(inst, 2, 3) << 6;
1466
+}
1467
+
1468
+static uint32_t operand_cimmlqsp(rv_inst inst)
1469
+{
1470
+ return extract32(inst, 12, 1) << 5 |
1471
+ extract32(inst, 6, 1) << 4 |
1472
+ extract32(inst, 2, 4) << 6;
1473
+}
1474
+
1475
+static int32_t operand_cimm16sp(rv_inst inst)
1476
+{
1477
+ return sextract32(inst, 12, 1) << 9 |
1478
+ extract32(inst, 6, 1) << 4 |
1479
+ extract32(inst, 5, 1) << 6 |
1480
+ extract32(inst, 3, 2) << 7 |
1481
+ extract32(inst, 2, 1) << 5;
1482
+}
1483
+
1484
+static int32_t operand_cimmj(rv_inst inst)
1485
+{
1486
+ return sextract32(inst, 12, 1) << 11 |
1487
+ extract32(inst, 11, 1) << 4 |
1488
+ extract32(inst, 9, 2) << 8 |
1489
+ extract32(inst, 8, 1) << 10 |
1490
+ extract32(inst, 7, 1) << 6 |
1491
+ extract32(inst, 6, 1) << 7 |
1492
+ extract32(inst, 3, 3) << 1 |
1493
+ extract32(inst, 2, 1) << 5;
1494
+}
1495
+
1496
+static int32_t operand_cimmb(rv_inst inst)
1497
+{
1498
+ return sextract32(inst, 12, 1) << 8 |
1499
+ extract32(inst, 10, 2) << 3 |
1500
+ extract32(inst, 5, 2) << 6 |
1501
+ extract32(inst, 3, 2) << 1 |
1502
+ extract32(inst, 2, 1) << 5;
1503
+}
1504
+
1505
+static uint32_t operand_cimmswsp(rv_inst inst)
1506
+{
1507
+ return extract32(inst, 9, 4) << 2 |
1508
+ extract32(inst, 7, 2) << 6;
1509
+}
1510
+
1511
+static uint32_t operand_cimmsdsp(rv_inst inst)
1512
+{
1513
+ return extract32(inst, 10, 3) << 3 |
1514
+ extract32(inst, 7, 3) << 6;
1515
+}
1516
+
1517
+static uint32_t operand_cimmsqsp(rv_inst inst)
1518
+{
1519
+ return extract32(inst, 11, 2) << 4 |
1520
+ extract32(inst, 7, 4) << 6;
1521
+}
1522
+
1523
+static uint32_t operand_cimm4spn(rv_inst inst)
1524
+{
1525
+ return extract32(inst, 11, 2) << 4 |
1526
+ extract32(inst, 7, 4) << 6 |
1527
+ extract32(inst, 6, 1) << 2 |
1528
+ extract32(inst, 5, 1) << 3;
1529
+}
1530
+
1531
+static uint32_t operand_cimmw(rv_inst inst)
1532
+{
1533
+ return extract32(inst, 10, 3) << 3 |
1534
+ extract32(inst, 6, 1) << 2 |
1535
+ extract32(inst, 5, 1) << 6;
1536
+}
1537
+
1538
+static uint32_t operand_cimmd(rv_inst inst)
1539
+{
1540
+ return extract32(inst, 10, 3) << 3 |
1541
+ extract32(inst, 5, 2) << 6;
1542
+}
1543
+
1544
+static uint32_t operand_cimmq(rv_inst inst)
1545
+{
1546
+ return extract32(inst, 11, 2) << 4 |
1547
+ extract32(inst, 10, 1) << 8 |
1548
+ extract32(inst, 5, 2) << 6;
1549
+}
1550
+
1551
+static int32_t operand_vimm(rv_inst inst)
1552
+{
1553
+ return sextract32(inst, 15, 5);
1554
+}
1555
+
1556
+static uint32_t operand_vuimm(rv_inst inst)
1557
+{
1558
+ return extract32(inst, 15, 5);
1559
+}
1560
+
1561
+static uint32_t operand_vzimm11(rv_inst inst)
1562
+{
1563
+ return extract32(inst, 20, 11);
1564
+}
1565
+
1566
+static uint32_t operand_vzimm10(rv_inst inst)
1567
+{
1568
+ return extract32(inst, 20, 10);
1569
+}
1570
+
1571
+static uint32_t operand_vzimm6(rv_inst inst)
1572
+{
1573
+ return extract32(inst, 26, 1) << 5 |
1574
+ extract32(inst, 15, 5);
1575
+}
1576
+
1577
+static uint32_t operand_bs(rv_inst inst)
1578
+{
1579
+ return extract32(inst, 30, 2);
1580
+}
1581
+
1582
+static uint32_t operand_rnum(rv_inst inst)
1583
+{
1584
+ return extract32(inst, 20, 4);
1585
+}
1586
+
1587
+static uint32_t operand_vm(rv_inst inst)
1588
+{
1589
+ return extract32(inst, 25, 1);
1590
+}
1591
+
1592
+static uint32_t operand_uimm_c_lb(rv_inst inst)
1593
+{
1594
+ return extract32(inst, 5, 1) << 1 |
1595
+ extract32(inst, 6, 1);
1596
+}
1597
+
1598
+static uint32_t operand_uimm_c_lh(rv_inst inst)
1599
+{
1600
+ return extract32(inst, 5, 1) << 1;
1601
+}
1602
+
1603
+static uint32_t operand_zcmp_spimm(rv_inst inst)
1604
+{
1605
+ return extract32(inst, 2, 2) << 4;
1606
+}
1607
+
1608
+static uint32_t operand_zcmp_rlist(rv_inst inst)
1609
+{
1610
+ return extract32(inst, 4, 4);
1611
+}
1612
+
1613
+static uint32_t operand_imm6(rv_inst inst)
1614
+{
1615
+ return extract32(inst, 20, 6);
1616
+}
1617
+
1618
+static uint32_t operand_imm2(rv_inst inst)
1619
+{
1620
+ return extract32(inst, 25, 2);
1621
+}
1622
+
1623
+static uint32_t operand_immh(rv_inst inst)
1624
+{
1625
+ return extract32(inst, 26, 6);
1626
+}
1627
+
1628
+static uint32_t operand_imml(rv_inst inst)
1629
+{
1630
+ return extract32(inst, 20, 6);
1631
+}
1632
+
1633
+static uint32_t calculate_stack_adj(rv_isa isa, uint32_t rlist, uint32_t spimm)
1634
+{
1635
+ int xlen_bytes_log2 = isa == rv64 ? 3 : 2;
1636
+ int regs = rlist == 15 ? 13 : rlist - 3;
1637
+ uint32_t stack_adj_base = ROUND_UP(regs << xlen_bytes_log2, 16);
1638
+ return stack_adj_base + spimm;
1639
+}
1640
+
1641
+static uint32_t operand_zcmp_stack_adj(rv_inst inst, rv_isa isa)
1642
+{
1643
+ return calculate_stack_adj(isa, operand_zcmp_rlist(inst),
1644
+ operand_zcmp_spimm(inst));
1645
+}
1646
+
1647
+static uint32_t operand_tbl_index(rv_inst inst)
1648
+{
1649
+ return extract32(inst, 2, 8);
1650
+}
1651
+
1652
+static uint32_t operand_lpl(rv_inst inst)
1653
+{
1654
+ return extract32(inst, 12, 20);
1655
+}
1656
+
1657
/* instruction metadata */
1658
1659
const rv_opcode_data rvi_opcode_data[] = {
@@ -4155,442 +4550,47 @@ static void decode_inst_opcode(rv_decode *dec, rv_isa isa)
4550
case 2: op = rv_op_vaesem_vv; break;
4551
case 3: op = rv_op_vaesef_vv; break;
4552
case 16: op = rv_op_vsm4r_vv; break;
4158
- case 17: op = rv_op_vgmul_vv; break;
4159
- }
4160
- break;
4161
- case 41:
4162
- switch ((inst >> 15) & 0b11111) {
4163
- case 0: op = rv_op_vaesdm_vs; break;
4164
- case 1: op = rv_op_vaesdf_vs; break;
4165
- case 2: op = rv_op_vaesem_vs; break;
4166
- case 3: op = rv_op_vaesef_vs; break;
4167
- case 7: op = rv_op_vaesz_vs; break;
4168
- case 16: op = rv_op_vsm4r_vs; break;
4169
- }
4170
- break;
4171
- case 42: op = rv_op_vaeskf2_vi; break;
4172
- case 43: op = rv_op_vsm3c_vi; break;
4173
- case 44: op = rv_op_vghsh_vv; break;
4174
- case 45: op = rv_op_vsha2ms_vv; break;
4175
- case 46: op = rv_op_vsha2ch_vv; break;
4176
- case 47: op = rv_op_vsha2cl_vv; break;
4177
- }
4178
- }
4179
- break;
4180
- case 30:
4181
- switch (((inst >> 22) & 0b1111111000) |
4182
- ((inst >> 12) & 0b0000000111)) {
4183
- case 0: op = rv_op_addd; break;
4184
- case 1: op = rv_op_slld; break;
4185
- case 5: op = rv_op_srld; break;
4186
- case 8: op = rv_op_muld; break;
4187
- case 12: op = rv_op_divd; break;
4188
- case 13: op = rv_op_divud; break;
4189
- case 14: op = rv_op_remd; break;
4190
- case 15: op = rv_op_remud; break;
4191
- case 256: op = rv_op_subd; break;
4192
- case 261: op = rv_op_srad; break;
4193
- }
4194
- break;
4195
- }
4196
- break;
4197
- }
4198
- dec->op = op;
4199
-}
4200
-
4201
-/* operand extractors */
4202
-
4203
-static uint32_t operand_rd(rv_inst inst)
4204
-{
4205
- return extract32(inst, 7, 5);
4206
-}
4207
-
4208
-static uint32_t operand_rs1(rv_inst inst)
4209
-{
4210
- return extract32(inst, 15, 5);
4211
-}
4212
-
4213
-static uint32_t operand_rs2(rv_inst inst)
4214
-{
4215
- return extract32(inst, 20, 5);
4216
-}
4217
-
4218
-static uint32_t operand_rs3(rv_inst inst)
4219
-{
4220
- return extract32(inst, 27, 5);
4221
-}
4222
-
4223
-static uint32_t operand_aq(rv_inst inst)
4224
-{
4225
- return extract32(inst, 26, 1);
4226
-}
4227
-
4228
-static uint32_t operand_rl(rv_inst inst)
4229
-{
4230
- return extract32(inst, 25, 1);
4231
-}
4232
-
4233
-static uint32_t operand_pred(rv_inst inst)
4234
-{
4235
- return extract32(inst, 24, 4);
4236
-}
4237
-
4238
-static uint32_t operand_succ(rv_inst inst)
4239
-{
4240
- return extract32(inst, 20, 4);
4241
-}
4242
-
4243
-static uint32_t operand_rm(rv_inst inst)
4244
-{
4245
- return extract32(inst, 12, 3);
4246
-}
4247
-
4248
-static uint32_t operand_shamt5(rv_inst inst)
4249
-{
4250
- return extract32(inst, 20, 5);
4251
-}
4252
-
4253
-static uint32_t operand_shamt6(rv_inst inst)
4254
-{
4255
- return extract32(inst, 20, 6);
4256
-}
4257
-
4258
-static uint32_t operand_shamt7(rv_inst inst)
4259
-{
4260
- return extract32(inst, 20, 7);
4261
-}
4262
-
4263
-static uint32_t operand_crdq(rv_inst inst)
4264
-{
4265
- return extract32(inst, 2, 3);
4266
-}
4267
-
4268
-static uint32_t operand_crs1q(rv_inst inst)
4269
-{
4270
- return extract32(inst, 7, 3);
4271
-}
4272
-
4273
-static uint32_t operand_crs1rdq(rv_inst inst)
4274
-{
4275
- return extract32(inst, 7, 3);
4276
-}
4277
-
4278
-static uint32_t operand_crs2q(rv_inst inst)
4279
-{
4280
- return extract32(inst, 2, 3);
4281
-}
4282
-
4283
-static uint32_t calculate_xreg(uint32_t sreg)
4284
-{
4285
- return sreg < 2 ? sreg + 8 : sreg + 16;
4286
-}
4287
-
4288
-static uint32_t operand_sreg1(rv_inst inst)
4289
-{
4290
- return calculate_xreg(extract32(inst, 7, 3));
4291
-}
4292
-
4293
-static uint32_t operand_sreg2(rv_inst inst)
4294
-{
4295
- return calculate_xreg(extract32(inst, 2, 3));
4296
-}
4297
-
4298
-static uint32_t operand_crd(rv_inst inst)
4299
-{
4300
- return extract32(inst, 7, 5);
4301
-}
4302
-
4303
-static uint32_t operand_crs1(rv_inst inst)
4304
-{
4305
- return extract32(inst, 7, 5);
4306
-}
4307
-
4308
-static uint32_t operand_crs1rd(rv_inst inst)
4309
-{
4310
- return extract32(inst, 7, 5);
4311
-}
4312
-
4313
-static uint32_t operand_crs2(rv_inst inst)
4314
-{
4315
- return extract32(inst, 2, 5);
4316
-}
4317
-
4318
-static uint32_t operand_cimmsh5(rv_inst inst)
4319
-{
4320
- return extract32(inst, 2, 5);
4321
-}
4322
-
4323
-static uint32_t operand_csr12(rv_inst inst)
4324
-{
4325
- return extract32(inst, 20, 12);
4326
-}
4327
-
4328
-static int32_t operand_imm12(rv_inst inst)
4329
-{
4330
- return sextract32(inst, 20, 12);
4331
-}
4332
-
4333
-static int32_t operand_imm20(rv_inst inst)
4334
-{
4335
- return sextract32(inst, 12, 20) << 12;
4336
-}
4337
-
4338
-static int32_t operand_jimm20(rv_inst inst)
4339
-{
4340
- return sextract32(inst, 31, 1) << 20 |
4341
- extract32(inst, 21, 10) << 1 |
4342
- extract32(inst, 20, 1) << 11 |
4343
- extract32(inst, 12, 8) << 12;
4344
-}
4345
-
4346
-static int32_t operand_simm12(rv_inst inst)
4347
-{
4348
- return sextract32(inst, 25, 7) << 5 |
4349
- extract32(inst, 7, 5);
4350
-}
4351
-
4352
-static int32_t operand_sbimm12(rv_inst inst)
4353
-{
4354
- return sextract32(inst, 31, 1) << 12 |
4355
- extract32(inst, 25, 6) << 5 |
4356
- extract32(inst, 8, 4) << 1 |
4357
- extract32(inst, 7, 1) << 11;
4358
-}
4359
-
4360
-static uint32_t operand_cimmshl6(rv_inst inst, rv_isa isa)
4361
-{
4362
- int imm = extract32(inst, 12, 1) << 5 |
4363
- extract32(inst, 2, 5);
4364
- if (isa == rv128) {
4365
- imm = imm ? imm : 64;
4366
- }
4367
- return imm;
4368
-}
4369
-
4370
-static uint32_t operand_cimmshr6(rv_inst inst, rv_isa isa)
4371
-{
4372
- int imm = extract32(inst, 12, 1) << 5 |
4373
- extract32(inst, 2, 5);
4374
- if (isa == rv128) {
4375
- imm = imm | (imm & 32) << 1;
4376
- imm = imm ? imm : 64;
4553
+ case 17: op = rv_op_vgmul_vv; break;
4554
+ }
4555
+ break;
4556
+ case 41:
4557
+ switch ((inst >> 15) & 0b11111) {
4558
+ case 0: op = rv_op_vaesdm_vs; break;
4559
+ case 1: op = rv_op_vaesdf_vs; break;
4560
+ case 2: op = rv_op_vaesem_vs; break;
4561
+ case 3: op = rv_op_vaesef_vs; break;
4562
+ case 7: op = rv_op_vaesz_vs; break;
4563
+ case 16: op = rv_op_vsm4r_vs; break;
4564
+ }
4565
+ break;
4566
+ case 42: op = rv_op_vaeskf2_vi; break;
4567
+ case 43: op = rv_op_vsm3c_vi; break;
4568
+ case 44: op = rv_op_vghsh_vv; break;
4569
+ case 45: op = rv_op_vsha2ms_vv; break;
4570
+ case 46: op = rv_op_vsha2ch_vv; break;
4571
+ case 47: op = rv_op_vsha2cl_vv; break;
4572
+ }
4573
+ }
4574
+ break;
4575
+ case 30:
4576
+ switch (((inst >> 22) & 0b1111111000) |
4577
+ ((inst >> 12) & 0b0000000111)) {
4578
+ case 0: op = rv_op_addd; break;
4579
+ case 1: op = rv_op_slld; break;
4580
+ case 5: op = rv_op_srld; break;
4581
+ case 8: op = rv_op_muld; break;
4582
+ case 12: op = rv_op_divd; break;
4583
+ case 13: op = rv_op_divud; break;
4584
+ case 14: op = rv_op_remd; break;
4585
+ case 15: op = rv_op_remud; break;
4586
+ case 256: op = rv_op_subd; break;
4587
+ case 261: op = rv_op_srad; break;
4588
+ }
4589
+ break;
4590
+ }
4591
+ break;
4592
}
4378
- return imm;
4379
-}
4380
-
4381
-static int32_t operand_cimmi(rv_inst inst)
4382
-{
4383
- return sextract32(inst, 12, 1) << 5 |
4384
- extract32(inst, 2, 5);
4385
-}
4386
-
4387
-static int32_t operand_cimmui(rv_inst inst)
4388
-{
4389
- return sextract32(inst, 12, 1) << 17 |
4390
- extract32(inst, 2, 5) << 12;
4391
-}
4392
-
4393
-static uint32_t operand_cimmlwsp(rv_inst inst)
4394
-{
4395
- return extract32(inst, 12, 1) << 5 |
4396
- extract32(inst, 4, 3) << 2 |
4397
- extract32(inst, 2, 2) << 6;
4398
-}
4399
-
4400
-static uint32_t operand_cimmldsp(rv_inst inst)
4401
-{
4402
- return extract32(inst, 12, 1) << 5 |
4403
- extract32(inst, 5, 2) << 3 |
4404
- extract32(inst, 2, 3) << 6;
4405
-}
4406
-
4407
-static uint32_t operand_cimmlqsp(rv_inst inst)
4408
-{
4409
- return extract32(inst, 12, 1) << 5 |
4410
- extract32(inst, 6, 1) << 4 |
4411
- extract32(inst, 2, 4) << 6;
4412
-}
4413
-
4414
-static int32_t operand_cimm16sp(rv_inst inst)
4415
-{
4416
- return sextract32(inst, 12, 1) << 9 |
4417
- extract32(inst, 6, 1) << 4 |
4418
- extract32(inst, 5, 1) << 6 |
4419
- extract32(inst, 3, 2) << 7 |
4420
- extract32(inst, 2, 1) << 5;
4421
-}
4422
-
4423
-static int32_t operand_cimmj(rv_inst inst)
4424
-{
4425
- return sextract32(inst, 12, 1) << 11 |
4426
- extract32(inst, 11, 1) << 4 |
4427
- extract32(inst, 9, 2) << 8 |
4428
- extract32(inst, 8, 1) << 10 |
4429
- extract32(inst, 7, 1) << 6 |
4430
- extract32(inst, 6, 1) << 7 |
4431
- extract32(inst, 3, 3) << 1 |
4432
- extract32(inst, 2, 1) << 5;
4433
-}
4434
-
4435
-static int32_t operand_cimmb(rv_inst inst)
4436
-{
4437
- return sextract32(inst, 12, 1) << 8 |
4438
- extract32(inst, 10, 2) << 3 |
4439
- extract32(inst, 5, 2) << 6 |
4440
- extract32(inst, 3, 2) << 1 |
4441
- extract32(inst, 2, 1) << 5;
4442
-}
4443
-
4444
-static uint32_t operand_cimmswsp(rv_inst inst)
4445
-{
4446
- return extract32(inst, 9, 4) << 2 |
4447
- extract32(inst, 7, 2) << 6;
4448
-}
4449
-
4450
-static uint32_t operand_cimmsdsp(rv_inst inst)
4451
-{
4452
- return extract32(inst, 10, 3) << 3 |
4453
- extract32(inst, 7, 3) << 6;
4454
-}
4455
-
4456
-static uint32_t operand_cimmsqsp(rv_inst inst)
4457
-{
4458
- return extract32(inst, 11, 2) << 4 |
4459
- extract32(inst, 7, 4) << 6;
4460
-}
4461
-
4462
-static uint32_t operand_cimm4spn(rv_inst inst)
4463
-{
4464
- return extract32(inst, 11, 2) << 4 |
4465
- extract32(inst, 7, 4) << 6 |
4466
- extract32(inst, 6, 1) << 2 |
4467
- extract32(inst, 5, 1) << 3;
4468
-}
4469
-
4470
-static uint32_t operand_cimmw(rv_inst inst)
4471
-{
4472
- return extract32(inst, 10, 3) << 3 |
4473
- extract32(inst, 6, 1) << 2 |
4474
- extract32(inst, 5, 1) << 6;
4475
-}
4476
-
4477
-static uint32_t operand_cimmd(rv_inst inst)
4478
-{
4479
- return extract32(inst, 10, 3) << 3 |
4480
- extract32(inst, 5, 2) << 6;
4481
-}
4482
-
4483
-static uint32_t operand_cimmq(rv_inst inst)
4484
-{
4485
- return extract32(inst, 11, 2) << 4 |
4486
- extract32(inst, 10, 1) << 8 |
4487
- extract32(inst, 5, 2) << 6;
4488
-}
4489
-
4490
-static int32_t operand_vimm(rv_inst inst)
4491
-{
4492
- return sextract32(inst, 15, 5);
4493
-}
4494
-
4495
-static uint32_t operand_vuimm(rv_inst inst)
4496
-{
4497
- return extract32(inst, 15, 5);
4498
-}
4499
-
4500
-static uint32_t operand_vzimm11(rv_inst inst)
4501
-{
4502
- return extract32(inst, 20, 11);
4503
-}
4504
-
4505
-static uint32_t operand_vzimm10(rv_inst inst)
4506
-{
4507
- return extract32(inst, 20, 10);
4508
-}
4509
-
4510
-static uint32_t operand_vzimm6(rv_inst inst)
4511
-{
4512
- return extract32(inst, 26, 1) << 5 |
4513
- extract32(inst, 15, 5);
4514
-}
4515
-
4516
-static uint32_t operand_bs(rv_inst inst)
4517
-{
4518
- return extract32(inst, 30, 2);
4519
-}
4520
-
4521
-static uint32_t operand_rnum(rv_inst inst)
4522
-{
4523
- return extract32(inst, 20, 4);
4524
-}
4525
-
4526
-static uint32_t operand_vm(rv_inst inst)
4527
-{
4528
- return extract32(inst, 25, 1);
4529
-}
4530
-
4531
-static uint32_t operand_uimm_c_lb(rv_inst inst)
4532
-{
4533
- return extract32(inst, 5, 1) << 1 |
4534
- extract32(inst, 6, 1);
4535
-}
4536
-
4537
-static uint32_t operand_uimm_c_lh(rv_inst inst)
4538
-{
4539
- return extract32(inst, 5, 1) << 1;
4540
-}
4541
-
4542
-static uint32_t operand_zcmp_spimm(rv_inst inst)
4543
-{
4544
- return extract32(inst, 2, 2) << 4;
4545
-}
4546
-
4547
-static uint32_t operand_zcmp_rlist(rv_inst inst)
4548
-{
4549
- return extract32(inst, 4, 4);
4550
-}
4551
-
4552
-static uint32_t operand_imm6(rv_inst inst)
4553
-{
4554
- return extract32(inst, 20, 6);
4555
-}
4556
-
4557
-static uint32_t operand_imm2(rv_inst inst)
4558
-{
4559
- return extract32(inst, 25, 2);
4560
-}
4561
-
4562
-static uint32_t operand_immh(rv_inst inst)
4563
-{
4564
- return extract32(inst, 26, 6);
4565
-}
4566
-
4567
-static uint32_t operand_imml(rv_inst inst)
4568
-{
4569
- return extract32(inst, 20, 6);
4570
-}
4571
-
4572
-static uint32_t calculate_stack_adj(rv_isa isa, uint32_t rlist, uint32_t spimm)
4573
-{
4574
- int xlen_bytes_log2 = isa == rv64 ? 3 : 2;
4575
- int regs = rlist == 15 ? 13 : rlist - 3;
4576
- uint32_t stack_adj_base = ROUND_UP(regs << xlen_bytes_log2, 16);
4577
- return stack_adj_base + spimm;
4578
-}
4579
-
4580
-static uint32_t operand_zcmp_stack_adj(rv_inst inst, rv_isa isa)
4581
-{
4582
- return calculate_stack_adj(isa, operand_zcmp_rlist(inst),
4583
- operand_zcmp_spimm(inst));
4584
-}
4585
-
4586
-static uint32_t operand_tbl_index(rv_inst inst)
4587
-{
4588
- return extract32(inst, 2, 8);
4589
-}
4590
-
4591
-static uint32_t operand_lpl(rv_inst inst)
4592
-{
4593
- return extract32(inst, 12, 20);
4593
+ dec->op = op;
4594
}
4595
4596
/* decode operands */