Skip to content

Commit

Permalink
Add signed and unsigned bitvector extensions
Browse files Browse the repository at this point in the history
  • Loading branch information
robdockins committed Aug 5, 2017
1 parent 9a3b64e commit 2b9e5a2
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions lib/Cryptol.cry
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,19 @@ primitive scarry : {n} (fin n, n >= 1) => [n] -> [n] -> Bit
sborrow : {n} (fin n, n >= 1) => [n] -> [n] -> Bit
sborrow x y = ( x <$ (x-y) ) ^ y@0

/**
* Zero extension of a bitvector.
*/
zext : {n, m} (fin m, m >= n) => [n] -> [m]
zext x = zero # x

/**
* Sign extension of a bitvector.
*/
sext : {n, m} (fin m, m >= n, n >= 1) => [n] -> [m]
sext x = newbits # x
where newbits = if x@0 then ~zero else zero

/**
* Short-cutting boolean conjuction function.
* If the first argument is False, the second argument
Expand Down

0 comments on commit 2b9e5a2

Please sign in to comment.