@@ -1452,21 +1452,30 @@ let check_simd_instr (simd : Simd.instr) imm instr =
1452
1452
| First_arg -> assert (Reg. same_loc instr.arg.(0 ) instr.res.(0 ))
1453
1453
| Res { loc; _ } -> assert_loc loc instr.res.(0 )
1454
1454
1455
+ let to_arg_with_width loc instr i =
1456
+ match Simd. loc_requires_width loc with
1457
+ | Some Eight -> arg8 instr i
1458
+ | Some Sixteen -> arg16 instr i
1459
+ | Some Thirtytwo -> arg32 instr i
1460
+ | Some Sixtyfour | None -> arg instr i
1461
+
1462
+ let to_res_with_width loc instr i =
1463
+ match Simd. loc_requires_width loc with
1464
+ | Some Eight -> res8 instr i
1465
+ | Some Sixteen -> res16 instr i
1466
+ | Some Thirtytwo -> res32 instr i
1467
+ | Some Sixtyfour | None -> res instr i
1468
+
1455
1469
let emit_simd_instr (simd : Simd.instr ) imm instr =
1456
1470
check_simd_instr simd imm instr;
1457
1471
let total_args = Array. length instr.arg in
1458
1472
if total_args <> Array. length simd.args
1459
1473
then Misc. fatal_errorf " wrong number of arguments for %s" simd.mnemonic;
1460
1474
let args =
1461
- List. init total_args (fun j ->
1462
- if Simd. arg_is_implicit simd.args.(j )
1475
+ List. init total_args (fun i ->
1476
+ if Simd. arg_is_implicit simd.args.(i )
1463
1477
then None
1464
- else
1465
- match Simd. loc_requires_width simd.args.(j).loc with
1466
- | Some Eight -> Some (arg8 instr j)
1467
- | Some Sixteen -> Some (arg16 instr j)
1468
- | Some Thirtytwo -> Some (arg32 instr j)
1469
- | Some Sixtyfour | None -> Some (arg instr j))
1478
+ else Some (to_arg_with_width simd.args.(i).loc instr i))
1470
1479
|> List. filter_map (fun arg -> arg)
1471
1480
in
1472
1481
let args =
@@ -1475,13 +1484,7 @@ let emit_simd_instr (simd : Simd.instr) imm instr =
1475
1484
| Res { loc; enc = RM_r | RM_rm | Vex_v } -> (
1476
1485
match Simd. loc_is_pinned loc with
1477
1486
| Some _ -> args
1478
- | None ->
1479
- (match Simd. loc_requires_width loc with
1480
- | Some Eight -> res8 instr 0
1481
- | Some Sixteen -> res16 instr 0
1482
- | Some Thirtytwo -> res32 instr 0
1483
- | Some Sixtyfour | None -> res instr 0 )
1484
- :: args)
1487
+ | None -> to_res_with_width loc instr 0 :: args)
1485
1488
in
1486
1489
let args =
1487
1490
match imm with
@@ -1490,38 +1493,33 @@ let emit_simd_instr (simd : Simd.instr) imm instr =
1490
1493
in
1491
1494
I. simd simd (Array. of_list args)
1492
1495
1493
- let emit_simd (simd : Simd.operation ) instr =
1494
- match simd with
1495
- | Instruction { instr = simd ; imm } -> emit_simd_instr simd imm instr
1496
- | Sequence { seq; imm } -> (
1497
- (* Prefix *)
1498
- ( match seq.id with
1496
+ let emit_simd (op : Simd.operation ) instr =
1497
+ let imm = op.imm in
1498
+ match op. instr with
1499
+ | Instruction simd -> emit_simd_instr simd imm instr
1500
+ | Sequence seq -> (
1501
+ match seq.id with
1499
1502
| Sqrtss | Sqrtsd | Roundss | Roundsd ->
1500
1503
(* Avoids partial register stall *)
1501
1504
if not (equal_arg (arg instr 0 ) (res instr 0 ))
1502
- then I. xorpd (res instr 0 ) (res instr 0 )
1503
- | Pcmpestra | Pcmpistra | Pcmpestrc | Pcmpistrc | Pcmpestro | Pcmpistro
1504
- | Pcmpestrs | Pcmpistrs | Pcmpestrz | Pcmpistrz ->
1505
- () );
1506
- (* Instruction *)
1507
- emit_simd_instr seq.instr imm instr;
1508
- (* Suffix *)
1509
- match seq.id with
1510
- | Sqrtss | Sqrtsd | Roundss | Roundsd -> ()
1511
- | Pcmpestra | Pcmpistra ->
1512
- I. set A (res8 instr 0 );
1513
- I. movzx (res8 instr 0 ) (res instr 0 )
1514
- | Pcmpestrc | Pcmpistrc ->
1515
- I. set B (res8 instr 0 );
1516
- I. movzx (res8 instr 0 ) (res instr 0 )
1517
- | Pcmpestro | Pcmpistro ->
1518
- I. set O (res8 instr 0 );
1519
- I. movzx (res8 instr 0 ) (res instr 0 )
1520
- | Pcmpestrs | Pcmpistrs ->
1521
- I. set S (res8 instr 0 );
1522
- I. movzx (res8 instr 0 ) (res instr 0 )
1523
- | Pcmpestrz | Pcmpistrz ->
1524
- I. set E (res8 instr 0 );
1505
+ then I. xorpd (res instr 0 ) (res instr 0 );
1506
+ emit_simd_instr seq.instr imm instr
1507
+ | Pcompare_string p ->
1508
+ let cond : X86_ast.condition =
1509
+ match p with
1510
+ | Pcmpestra -> A
1511
+ | Pcmpestrc -> B
1512
+ | Pcmpestro -> O
1513
+ | Pcmpestrs -> S
1514
+ | Pcmpestrz -> E
1515
+ | Pcmpistra -> A
1516
+ | Pcmpistrc -> B
1517
+ | Pcmpistro -> O
1518
+ | Pcmpistrs -> S
1519
+ | Pcmpistrz -> E
1520
+ in
1521
+ emit_simd_instr seq.instr imm instr;
1522
+ I. set cond (res8 instr 0 );
1525
1523
I. movzx (res8 instr 0 ) (res instr 0 ))
1526
1524
1527
1525
let emit_simd_instr_with_memory_arg (simd : Simd.Mem.operation ) i addr =
0 commit comments