-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
This is supposedly SMT friendly, and keeps the bit-hacks for the concrete case.
- Loading branch information
Showing
10 changed files
with
162 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
(module | ||
(import "symbolic" "i32_symbol" (func $i32_symbol (result i32))) | ||
(import "symbolic" "assume" (func $assume (param i32))) | ||
(import "symbolic" "assert" (func $assert (param i32))) | ||
|
||
(func $countLeadingZeros (param i32) (result i32) | ||
(local $x i32) | ||
(local $res i32) | ||
|
||
|
||
;; Initialize local variables | ||
(local.set $res (i32.const 32)) ;; Initialize with the highest possible index of a bit | ||
(local.set $x (local.get 0)) ;; Store the input | ||
|
||
;; Loop to find the leading zeros | ||
(block $outter | ||
(loop $loop | ||
|
||
;; Check if all bits are shifted out | ||
(if (i32.eqz (local.get $x)) | ||
(then (br $outter)) | ||
) | ||
|
||
;; Shift the input to the right by 1 bit | ||
(local.set $x (i32.shr_u (local.get $x) (i32.const 1))) | ||
|
||
;; Decrement the count of zero bits | ||
(local.set $res (i32.sub (local.get $res) (i32.const 1))) | ||
|
||
(br $loop) | ||
) | ||
) | ||
|
||
;; Return the number of leading zeros | ||
(return (local.get $res)) | ||
) | ||
|
||
(func $start | ||
|
||
(local $n i32) | ||
(local.set $n (call $i32_symbol)) | ||
|
||
(call $assert (i32.eq | ||
(call $countLeadingZeros (local.get $n)) | ||
(i32.clz (local.get $n)) | ||
)) | ||
) | ||
|
||
|
||
(start $start) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
(module | ||
(import "symbolic" "i64_symbol" (func $i64_symbol (result i64))) | ||
(import "symbolic" "assume" (func $assume (param i32))) | ||
(import "symbolic" "assert" (func $assert (param i32))) | ||
|
||
(func $countLeadingZeros (param i64) (result i64) | ||
(local $x i64) | ||
(local $res i64) | ||
|
||
|
||
;; Initialize local variables | ||
(local.set $res (i64.const 64)) ;; Initialize with the highest possible index of a bit | ||
(local.set $x (local.get 0)) ;; Store the input | ||
|
||
;; Loop to find the leading zeros | ||
(block $outter | ||
(loop $loop | ||
|
||
;; Check if all bits are shifted out | ||
(if (i64.eqz (local.get $x)) | ||
(then (br $outter)) | ||
) | ||
|
||
;; Shift the input to the right by 1 bit | ||
(local.set $x (i64.shr_u (local.get $x) (i64.const 1))) | ||
|
||
;; Decrement the count of zero bits | ||
(local.set $res (i64.sub (local.get $res) (i64.const 1))) | ||
|
||
(br $loop) | ||
) | ||
) | ||
|
||
;; Return the number of leading zeros | ||
(return (local.get $res)) | ||
) | ||
|
||
(func $start | ||
|
||
(local $n i64) | ||
(local.set $n (call $i64_symbol)) | ||
|
||
(call $assert (i64.eq | ||
(call $countLeadingZeros (local.get $n)) | ||
(i64.clz (local.get $n)) | ||
)) | ||
) | ||
|
||
|
||
(start $start) | ||
) |