Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Wint2 #1071

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open

Wint2 #1071

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,43 @@
[PR #972](https://github.com/jasmin-lang/jasmin/pull/972),
[PR #995](https://github.com/jasmin-lang/jasmin/pull/995)).

- Introduction of types siXX and uiXX (XX in [8,16,32,64,128, 256]).
New notation for type uXX/sXX : wXX.
siXX represents signed integer of size XX, i.e in the range [-2^XX/2, 2^XX/2).
uiXX represents unsigned integer of size XX, i.e in the range [0, 2^XX).
Introduction of a new cast operorators:
(sint) e : from wXX/siXX to int, signed interpretation
(uint) e : from wXX/uiXX to int, unsigned interpretation
The previous cast operator (int) e stand for:
(uint) e if e has type wXX/uiXX
(sint) e if e has type siXX
All basic operations on uiXX/siXX perform the corresponding int operation and check
that the result is in the range of uiXX/siXX, if not it is a safety violation.
They can be selected explicitly using notation "e1 +XX(ui/si) e2"
Introduction of new cast operators:
(XXw) e : from siXX/uiXX to wXX
(XXsi) e :
if e has type wXX it the identity
if e has type int ensure that e is in the range of siXX, else it is a safety violation.
(XXui) e :
if e has type wXX it the identity
if e has type int ensure that e is in the range of siXX, else it is a safety violation.
Introduce zquot and zrem operators on int : "e1 /s e2" and "e1 %s e2".
The key feature of this new type are for the extraction to easycrypt.
They are extracted to int, removing the need to deal with modulus 2^XX operations.
([PR #1071](https://github.com/jasmin-lang/jasmin/pull/1071)).

## Bug fixes

- Fix EC extraction in case on nested loops
([PR #971](https://github.com/jasmin-lang/jasmin/pull/971)).

- Fix semantics of (e1 /XXu e2) and (e1 %XXu e2), the safety condition only require that e2 <> 0.
([PR #1071](https://github.com/jasmin-lang/jasmin/pull/1071)).

- Fix extraction of (e1 /XXs e2) and (e1 %XXs e2) they are now correctly extracted to zquot and zrem.
([PR #1071](https://github.com/jasmin-lang/jasmin/pull/1071)).

## Other changes

- The deprecated legacy interface to the LATEX pretty-printer has been removed
Expand Down
7 changes: 6 additions & 1 deletion compiler/entry/commonCLI.ml
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ let parse_and_compile (type reg regx xreg rflag cond asm_op extra_op)
and type rflag = rflag
and type cond = cond
and type asm_op = asm_op
and type extra_op = extra_op) pass file idirs =
and type extra_op = extra_op) ~wi2i pass file idirs =
let _env, pprog, _ast =
try Compile.parse_file Arch.arch_info ~idirs file with
| Annot.AnnotationError (loc, code) ->
Expand All @@ -90,6 +90,10 @@ let parse_and_compile (type reg regx xreg rflag cond asm_op extra_op)
hierror ~loc:(Lmore loc) ~kind:"typing error" "%s" code
in

let prog =
if not wi2i then prog
else Compile.do_wint_int (module Arch) prog in

let prog =
if pass <= Compiler.ParamsExpansion then prog
else
Expand All @@ -112,3 +116,4 @@ let parse_and_compile (type reg regx xreg rflag cond asm_op extra_op)
| exception E.Found -> !res
in
prog

3 changes: 2 additions & 1 deletion compiler/entry/commonCLI.mli
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,11 @@ val parse_and_compile :
and type regx = 'regx
and type rflag = 'rflag
and type xreg = 'xreg) ->
wi2i:bool -> (* true => start by replacing wint operation by int operation *)
Compiler.compiler_step ->
string ->
(string * string) list ->
( unit,
(unit,
( 'reg,
'regx,
'xreg,
Expand Down
3 changes: 1 addition & 2 deletions compiler/entry/jasmin2ec.ml
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,7 @@ let parse_and_extract arch call_conv idirs =
let module A = (val get_arch_module arch call_conv) in

let extract model amodel functions array_dir output pass file =
let prog = parse_and_compile (module A) pass file idirs in

let prog = parse_and_compile (module A) ~wi2i:true pass file idirs in
extract_to_file prog arch A.reg_size A.asmOp model amodel functions
array_dir output
in
Expand Down
2 changes: 1 addition & 1 deletion compiler/entry/jasmin_ct.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ open Utils
let parse_and_check arch call_conv idirs =
let module A = (val get_arch_module arch call_conv) in
let check ~doit infer ct_list speculative pass file =
let prog = parse_and_compile (module A) pass file idirs in
let prog = parse_and_compile (module A) ~wi2i:false pass file idirs in

if speculative then
let prog =
Expand Down
Loading