Skip to content

Commit

Permalink
#283 Fixed n bit NOT wrong bitwidth (#342)
Browse files Browse the repository at this point in the history
* Fix n bit NOT wrong bitwidth

* Fix for 32 bit NOT

* Fix n bit not mask

* Fix bigint n bit NOT
  • Loading branch information
lucasng32 authored Aug 4, 2023
1 parent 69862cf commit 19491ea
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions src/Renderer/Simulator/Fast/FastReduce.fs
Original file line number Diff line number Diff line change
Expand Up @@ -796,16 +796,21 @@ let fastReduce (maxArraySize: int) (numStep: int) (isClockedReduction: bool) (co
putBigInt 0 res
| NbitsNot numberOfBits, false ->
let a = insUInt32 0
let res = ~~~a
let w = comp.InputWidth 0
let minusOne = (1u <<< w) - 1u
let res =
match w with
| 32 -> ~~~a
| _ -> minusOne &&& (~~~a)
putUInt32 0 res
| NbitsNot numberOfBits, true ->
let a = insBigInt 0
// failwithf $"TODO: fable does not support op_OnesComplement function"
// BigWord (System.Numerics.BigInteger.op_OnesComplement a) FIX: 2^n-1-a
let w = comp.InputWidth 0
// (bigint^w)
let (minusOne: bigint) = ((bigint 2) <<< w) - (bigint 1)
let res = minusOne - a
let mask = ((bigint 1) <<< w) - (bigint 1)
let res = mask - (a &&& mask)
putBigInt 0 res

| NbitSpreader numberOfBits, false ->
Expand Down

0 comments on commit 19491ea

Please sign in to comment.