Skip to content

Commit da03d8f

Browse files
committed
Fix translation of VPBROADCAST
1 parent 1f88087 commit da03d8f

File tree

1 file changed

+37
-30
lines changed

1 file changed

+37
-30
lines changed

compiler/src/toCL.ml

+37-30
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ open Utils
2020
open Prog
2121
open Glob_options
2222
open Utils
23+
open Wsize
2324

2425
let unsharp = String.map (fun c -> if c = '#' then '_' else c)
2526

@@ -849,7 +850,7 @@ module X86BaseOpU : BaseOp
849850
let v = int_of_velem v in
850851
let s = int_of_ws ws in
851852
let l_tmp = I.mk_tmp_lval ~vector:(1,s) (CoreIdent.tu ws) in
852-
let l_tmp2 = I.mk_tmp_lval ~vector:(v,s/v) (CoreIdent.tu ws) in
853+
let l_tmp2 = I.mk_tmp_lval ~vector:(s/v,v) (CoreIdent.tu ws) in
853854
let l_tmp2v = I.get_lval l_tmp2 in
854855
let ty = CL.(Vector (v, Uint (s/v))) in
855856
CL.Instr.Avar l_tmp2v,
@@ -1222,7 +1223,7 @@ module X86BaseOpU : BaseOp
12221223
let a2,i2 = cast_vector_atome ws ve (List.nth es 1) in
12231224
let v = int_of_velem ve in
12241225
let s = int_of_ws ws in
1225-
let l_tmp = I.mk_tmp_lval ~vector:(v,s/v) (CoreIdent.tu ws) in
1226+
let l_tmp = I.mk_tmp_lval ~vector:(s/v,v) (CoreIdent.tu ws) in
12261227
let l = I.glval_to_lval (List.nth xs 0) in
12271228
let i3 = cast_atome_vector ws v !l_tmp l in
12281229
match trans with
@@ -1243,7 +1244,7 @@ module X86BaseOpU : BaseOp
12431244
let a2,i2 = cast_vector_atome ws VE16 (List.nth es 1) in
12441245
let s = int_of_ws ws in
12451246
let v = s / 16 in
1246-
let l_tmp = I.mk_tmp_lval ~vector:(v,s/v) (CoreIdent.tu ws) in
1247+
let l_tmp = I.mk_tmp_lval ~vector:(s/v,v) (CoreIdent.tu ws) in
12471248
let l = I.glval_to_lval (List.nth xs 0) in
12481249
let i3 = cast_atome_vector ws v !l_tmp l in
12491250
i1 @ i2 @ [CL.Instr.Op2.and_ l_tmp a1 a2] @ i3
@@ -1256,7 +1257,7 @@ module X86BaseOpU : BaseOp
12561257
let a2,i2 = cast_vector_atome ws ve (List.nth es 1) in
12571258
let v = int_of_velem ve in
12581259
let s = int_of_ws ws in
1259-
let l_tmp = I.mk_tmp_lval ~vector:(v,s/v) (CoreIdent.tu ws) in
1260+
let l_tmp = I.mk_tmp_lval ~vector:(s/v,v) (CoreIdent.tu ws) in
12601261
let l = I.glval_to_lval (List.nth xs 0) in
12611262
let i3 = cast_atome_vector ws v !l_tmp l in
12621263
match trans with
@@ -1272,8 +1273,8 @@ module X86BaseOpU : BaseOp
12721273
let a2,i2 = cast_vector_atome ws v (List.nth es 1) in
12731274
let v = int_of_velem v in
12741275
let s = int_of_ws ws in
1275-
let l0_tmp = I.mk_tmp_lval ~vector:(v,s/v) (CoreIdent.tu ws) in
1276-
let l1_tmp = I.mk_tmp_lval ~sign:true ~vector:(v,s/v) (CoreIdent.tu ws) in
1276+
let l0_tmp = I.mk_tmp_lval ~vector:(s/v,v) (CoreIdent.tu ws) in
1277+
let l1_tmp = I.mk_tmp_lval ~sign:true ~vector:(s/v,v) (CoreIdent.tu ws) in
12771278
let (_, l1_ty) = I.get_lval l1_tmp in
12781279
let l = I.glval_to_lval (List.nth xs 0) in
12791280
let i3 = cast_atome_vector ws v !l1_tmp l in
@@ -1288,10 +1289,10 @@ module X86BaseOpU : BaseOp
12881289
let a2,i2 = cast_vector_atome ws VE16 (List.nth es 1) in
12891290
let s = int_of_ws ws in
12901291
let v = s / 16 in
1291-
let l_tmp = I.mk_tmp_lval ~vector:(v,s/v) (CoreIdent.tu ws) in
1292+
let l_tmp = I.mk_tmp_lval ~vector:(s/v,v) (CoreIdent.tu ws) in
12921293
let l = I.glval_to_lval (List.nth xs 0) in
12931294
let i3 = cast_atome_vector ws v !l_tmp l in
1294-
let l_tmp1 = I.mk_tmp_lval ~vector:(v,s/v) (CoreIdent.tu ws) in
1295+
let l_tmp1 = I.mk_tmp_lval ~vector:(s/v,v) (CoreIdent.tu ws) in
12951296
i1 @ i2 @ [CL.Instr.Op2_2.mull l_tmp l_tmp1 a1 a2] @ i3
12961297

12971298
| VPSRA (ve, ws) ->
@@ -1304,34 +1305,37 @@ module X86BaseOpU : BaseOp
13041305
let s = int_of_ws ws in
13051306
match trans with
13061307
| `Default ->
1307-
let l_tmp = I.mk_tmp_lval ~vector:(v,s/v) (CoreIdent.tu ws) in
1308+
let l_tmp = I.mk_tmp_lval ~vector:(s/v,v) (CoreIdent.tu ws) in
13081309
let l = I.glval_to_lval (List.nth xs 0) in
13091310
let i3 = cast_atome_vector ws v !l_tmp l in
1310-
let l_tmp1 = I.mk_tmp_lval ~vector:(v,s/v) (CoreIdent.tu ws) in
1311+
let l_tmp1 = I.mk_tmp_lval ~vector:(s/v,v) (CoreIdent.tu ws) in
13111312
i1 @ [CL.Instr.Shifts.split l_tmp l_tmp1 a1 c] @ i3
13121313
| `Smt ->
1313-
let l1_tmp = I.mk_tmp_lval ~sign:true ~vector:(v,s/v) (CoreIdent.tu ws) in
1314+
let l1_tmp = I.mk_tmp_lval ~sign:true ~vector:(s/v,v) (CoreIdent.tu ws) in
13141315
let (_, l1_ty) = I.get_lval l1_tmp in
1315-
let l2_tmp = I.mk_tmp_lval ~sign:true ~vector:(v,s/v) (CoreIdent.tu ws) in
1316+
let l2_tmp = I.mk_tmp_lval ~sign:true ~vector:(s/v,v) (CoreIdent.tu ws) in
13161317
let (_, l2_ty) = I.get_lval l2_tmp in
1317-
let l3_tmp = I.mk_tmp_lval ~vector:(v,s/v) (CoreIdent.tu ws) in
1318-
let l4_tmp = I.mk_tmp_lval ~vector:(v,s/v) (CoreIdent.tu ws) in
1318+
let l3_tmp = I.mk_tmp_lval ~vector:(s/v,v) (CoreIdent.tu ws) in
1319+
let l4_tmp = I.mk_tmp_lval ~vector:(s/v,v) (CoreIdent.tu ws) in
13191320
let l = I.glval_to_lval (List.nth xs 0) in
13201321
let i2 = cast_atome_vector ws v !l4_tmp l in
13211322
i1 @ [CL.Instr.cast l1_ty l1_tmp a1;
13221323
CL.Instr.Shifts.split l2_tmp l3_tmp !l1_tmp c;
13231324
CL.Instr.cast l2_ty l4_tmp !l2_tmp] @ i2
13241325
end
13251326

1326-
| VPBROADCAST (ve, ws) -> (* FIXME *)
1327+
| VPBROADCAST (ve, ws) ->
13271328
begin
1328-
let a1,i1 = cast_vector_atome ws ve (List.nth es 0) in
1329+
let a1,i1 = cast_atome (wsize_of_velem ve) (List.nth es 0) in
13291330
let v = int_of_velem ve in
13301331
let s = int_of_ws ws in
1331-
let l_tmp = I.mk_tmp_lval ~vector:(v,s/v) (CoreIdent.tu ws) in
1332+
let rec repeat acc n x =
1333+
if n == 0 then acc else repeat (x :: acc) (n - 1) x in
1334+
let ac = CL.Instr.Avatome (repeat [] (s/v) a1) in
1335+
let l_tmp = I.mk_tmp_lval ~vector:(s/v,v) (CoreIdent.tu ws) in
13321336
let l = I.glval_to_lval (List.nth xs 0) in
13331337
let i2 = cast_atome_vector ws v !l_tmp l in
1334-
i1 @ [CL.Instr.Op1.mov l_tmp a1] @ i2
1338+
i1 @ [CL.Instr.Op1.mov l_tmp ac] @ i2
13351339
end
13361340

13371341
| _ ->
@@ -1414,7 +1418,7 @@ module X86BaseOpS : BaseOp
14141418
let v = int_of_velem v in
14151419
let s = int_of_ws ws in
14161420
let l_tmp = I.mk_tmp_lval ~vector:(1,s) (CoreIdent.tu ws) in
1417-
let l_tmp2 = I.mk_tmp_lval ~vector:(v,s/v) (CoreIdent.tu ws) in
1421+
let l_tmp2 = I.mk_tmp_lval ~vector:(s/v,v) (CoreIdent.tu ws) in
14181422
let l_tmp2v = I.get_lval l_tmp2 in
14191423
let ty = CL.(Vector (v, Sint (s/v))) in
14201424
CL.Instr.Avar l_tmp2v,
@@ -1620,15 +1624,18 @@ module X86BaseOpS : BaseOp
16201624
let l = I.glval_to_lval (List.nth xs 0) in
16211625
i @ [CL.Instr.Op1.mov l a]
16221626

1623-
| VPBROADCAST (ve, ws) -> (* FIXME *)
1627+
| VPBROADCAST (ve, ws) ->
16241628
begin
1625-
let a1,i1 = cast_vector_atome ws ve (List.nth es 0) in
1629+
let a1,i1 = cast_atome (wsize_of_velem ve) (List.nth es 0) in
16261630
let v = int_of_velem ve in
16271631
let s = int_of_ws ws in
1628-
let l_tmp = I.mk_tmp_lval ~vector:(v,s/v) (CoreIdent.tu ws) in
1632+
let rec repeat acc n x =
1633+
if n == 0 then acc else repeat (x :: acc) (n - 1) x in
1634+
let ac = CL.Instr.Avatome (repeat [] (s/v) a1) in
1635+
let l_tmp = I.mk_tmp_lval ~vector:(s/v,v) (CoreIdent.tu ws) in
16291636
let l = I.glval_to_lval (List.nth xs 0) in
16301637
let i2 = cast_atome_vector ws v !l_tmp l in
1631-
i1 @ [CL.Instr.Op1.mov l_tmp a1] @ i2
1638+
i1 @ [CL.Instr.Op1.mov l_tmp ac] @ i2
16321639
end
16331640

16341641
| VPADD (ve,ws) ->
@@ -1639,7 +1646,7 @@ module X86BaseOpS : BaseOp
16391646
let a2,i2 = cast_vector_atome ws ve (List.nth es 1) in
16401647
let v = int_of_velem ve in
16411648
let s = int_of_ws ws in
1642-
let l_tmp = I.mk_tmp_lval ~vector:(v,s/v) (CoreIdent.tu ws) in
1649+
let l_tmp = I.mk_tmp_lval ~vector:(s/v,v) (CoreIdent.tu ws) in
16431650
let l = I.glval_to_lval (List.nth xs 0) in
16441651
let i3 = cast_atome_vector ws v !l_tmp l in
16451652
match trans with
@@ -1658,7 +1665,7 @@ module X86BaseOpS : BaseOp
16581665
let a2,i2 = cast_vector_atome ws ve (List.nth es 1) in
16591666
let v = int_of_velem ve in
16601667
let s = int_of_ws ws in
1661-
let l_tmp = I.mk_tmp_lval ~vector:(v,s/v) (CoreIdent.tu ws) in
1668+
let l_tmp = I.mk_tmp_lval ~vector:(s/v,v) (CoreIdent.tu ws) in
16621669
let l = I.glval_to_lval (List.nth xs 0) in
16631670
let i3 = cast_atome_vector ws v !l_tmp l in
16641671
match trans with
@@ -1674,7 +1681,7 @@ module X86BaseOpS : BaseOp
16741681
let a2,i2 = cast_vector_atome ws v (List.nth es 1) in
16751682
let v = int_of_velem v in
16761683
let s = int_of_ws ws in
1677-
let l0_tmp = I.mk_tmp_lval ~vector:(v,s/v) (CoreIdent.tu ws) in
1684+
let l0_tmp = I.mk_tmp_lval ~vector:(s/v,v) (CoreIdent.tu ws) in
16781685
let l = I.glval_to_lval (List.nth xs 0) in
16791686
let i3 = cast_atome_vector ws v !l0_tmp l in
16801687
i1 @ i2 @ [CL.Instr.Op2.smul l0_tmp a1 a2 ] @ i3
@@ -1684,8 +1691,8 @@ module X86BaseOpS : BaseOp
16841691
let a2,i2 = cast_vector_atome ws VE16 (List.nth es 1) in
16851692
let s = int_of_ws ws in
16861693
let v = s / 16 in
1687-
let l_tmp = I.mk_tmp_lval ~vector:(v,s/v) (CoreIdent.tu ws) in
1688-
let l_tmp1 = I.mk_tmp_lval ~sign:false ~vector:(v,s/v) (CoreIdent.tu ws) in
1694+
let l_tmp = I.mk_tmp_lval ~vector:(s/v,v) (CoreIdent.tu ws) in
1695+
let l_tmp1 = I.mk_tmp_lval ~sign:false ~vector:(s/v,v) (CoreIdent.tu ws) in
16891696
let l = I.glval_to_lval (List.nth xs 0) in
16901697
let i3 = cast_atome_vector ws v !l_tmp l in
16911698
i1 @ i2 @ [CL.Instr.Op2_2.mull l_tmp l_tmp1 a1 a2] @ i3
@@ -1701,12 +1708,12 @@ module X86BaseOpS : BaseOp
17011708
let ac = repeat [] 16 c in
17021709
let v = int_of_velem ve in
17031710
let s = int_of_ws ws in
1704-
let l_tmp = I.mk_tmp_lval ~vector:(v,s/v) (CoreIdent.tu ws) in
1711+
let l_tmp = I.mk_tmp_lval ~vector:(s/v,v) (CoreIdent.tu ws) in
17051712
let l = I.glval_to_lval (List.nth xs 0) in
17061713
let i2 = cast_atome_vector ws v !l_tmp l in
17071714
match trans with
17081715
| `Default ->
1709-
let l_tmp1 = I.mk_tmp_lval ~sign:false ~vector:(v,s/v) (CoreIdent.tu ws) in
1716+
let l_tmp1 = I.mk_tmp_lval ~sign:false ~vector:(s/v,v) (CoreIdent.tu ws) in
17101717
i1 @ [CL.Instr.Shifts.vsars l_tmp l_tmp1 a1 ac] @ i2
17111718
| `Smt ->
17121719
i1 @ [CL.Instr.Shift.vsar l_tmp a1 ac] @ i2

0 commit comments

Comments
 (0)