Skip to content

Commit

Permalink
x86 lowering: use XOR instead of MOV 0 in division
Browse files Browse the repository at this point in the history
There seem to be no good reason not to use “xor edx, edx” to set the
highest word to zero. The encoding is shorter and flags are obliterated
by the following DIV instruction.
  • Loading branch information
vbgl authored and bgregoir committed Sep 25, 2023
1 parent 060b41b commit 47cdf1e
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 3 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,9 @@
([PR #531](https://github.com/jasmin-lang/jasmin/pull/531);
fixes [#525](https://github.com/jasmin-lang/jasmin/issues/525)).

- Unsigned division on x86 emits a xor instead of “mov 0“
([PR #582](https://github.com/jasmin-lang/jasmin/pull/582)).

# Jasmin 2023.06.1 — 2023-07-31

## New features
Expand Down
2 changes: 1 addition & 1 deletion proofs/compiler/x86_lowering.v
Original file line number Diff line number Diff line change
Expand Up @@ -504,7 +504,7 @@ Definition lower_cassgn (ii:instr_info) (x: lval) (tg: assgn_tag) (ty: stype) (e
let i1 :=
match s with
| Signed => Copn [:: Lvar c ] tg (Ox86 (CQO sz)) [:: a]
| Unsigned => Copn [:: Lvar c ] tg (Ox86 (MOV sz)) [:: Papp1 (Oword_of_int sz) (Pconst 0)]
| Unsigned => Copn [:: f ; f ; f ; f ; f ; Lvar c ] tg (Oasm (ExtOp (Oset0 sz))) [::]
end in

[::MkI ii i1; MkI ii (Copn lv tg op [::Plvar c; a; b]) ]
Expand Down
4 changes: 2 additions & 2 deletions proofs/compiler/x86_lowering_proof.v
Original file line number Diff line number Diff line change
Expand Up @@ -1406,8 +1406,8 @@ Section PROOF.
/check_size_16_64 hle1 hle2 /= write_var_eq_type //.
+ by rewrite get_var_eq //= cmp_le_refl orbT.
+ by split => //; apply vmap_eq_except_set; apply multiplicand_in_fv.
+ by apply: EmkI; apply: Eopn; rewrite /sem_sopn /exec_sopn /sopn_sem /= truncate_word_u /=
/x86_MOV /check_size_8_64 hle2 /= write_var_eq_type.
+ by apply: EmkI; apply: Eopn; rewrite /sem_sopn /exec_sopn /sopn_sem /=
/Oset0_instr hle2 /= write_var_eq_type.
+ by rewrite /= get_var_eq /= cmp_le_refl orbT ?wrepr0.
split => //.
by apply vmap_eq_except_set; apply multiplicand_in_fv.
Expand Down

0 comments on commit 47cdf1e

Please sign in to comment.