Skip to content

Commit

Permalink
Add setl function
Browse files Browse the repository at this point in the history
  • Loading branch information
jochasinga committed Oct 7, 2023
1 parent 735507d commit a0538fc
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 1 deletion.
30 changes: 30 additions & 0 deletions modules/lib/asm_x86.wat
Original file line number Diff line number Diff line change
@@ -1,6 +1,36 @@
(module
(type $t0 (func (param i32 i32) (result i32)))
(type $t1 (func (param i32 i32) (result i32)))
(func $setl (export "setl") (param $cmpl_flag i32) (param $val i32) (result i32)
(local $var i32)
local.get $cmpl_flag
i32.const 0
i32.lt_s
(if
(then
local.get $cmpl_flag
i32.const 1
i32.and
local.set $var
)
(else
local.get $cmpl_flag
i32.const 0
i32.and
local.set $var
)
)
local.get $var
(if
(then
local.get $val
i32.const 0xff
i32.or
return
)
)
local.get $val
)
(func $sete (export "sete") (param $zf i32) (param $val i32) (result i32)
;; - arg0 | $zf is the zero flag
;; - arg1 | $val is the value to set
Expand Down
25 changes: 25 additions & 0 deletions modules/lib/tests.wat
Original file line number Diff line number Diff line change
@@ -1,6 +1,31 @@
(module
(import "asm_x86" "sete" (func $sete (param i32 i32) (result i32)))
(import "asm_x86" "cmpl" (func $cmpl (param i32 i32) (result i32)))
(import "asm_x86" "setl" (func $setl (param i32 i32) (result i32)))
(func $test_setl_eq (export "test_setl_eq") (result i32)
i32.const 3
i32.const 3
;; 3 == 3 so setl should return 0
call $cmpl
i32.const 0
call $setl
)
(func $test_setl_mt (export "test_setl_mt") (result i32)
i32.const 4
i32.const 3
;; 4 > 3 so setl should return 0
call $cmpl
i32.const 0
call $setl
)
(func $test_setl_lt (export "test_setl_lt") (result i32)
i32.const 1
i32.const 3
;; 1 < 3 so setl should return 255
call $cmpl
i32.const 0
call $setl
)
(func $test_sete_eq (export "test_sete_eq") (result i32)
i32.const 3
i32.const 3
Expand Down
2 changes: 1 addition & 1 deletion rts
Submodule rts updated from 45c68d to 37b004

0 comments on commit a0538fc

Please sign in to comment.