Download hardware/clash/EntropyAdderTree.hs from Snapkitty/marlborg-worm: direct link, hf CLI and curl.
- Browser
- Download file 3.05 kB
-
https://huggingface.co/Snapkitty/marlborg-worm/resolve/main/hardware/clash/EntropyAdderTree.hs
- Command line
-
hf download hf://Snapkitty/marlborg-worm/hardware/clash/EntropyAdderTree.hs
-
curl -L -o EntropyAdderTree.hs https://huggingface.co/Snapkitty/marlborg-worm/resolve/main/hardware/clash/EntropyAdderTree.hs
3.05 kB
| -- | |
| -- Copyright (c) 2026 BEL ESPRIT D ACCORD TRUST HOLDINGS INC | |
| -- All rights reserved. | |
| module MarlborgWorm.Hardware.EntropyAdderTree | |
| ( entropyAdderTree | |
| , topEntity | |
| ) where | |
| import Clash.Prelude | |
| -- | Fixed-point parameters (scaling by 10^4) | |
| -- H_BASE = 0.1000 nats -> 1000 | |
| -- H_HASH = 0.0400 nats -> 400 (when hash removed) | |
| -- H_MARLBORG = 0.0005 nats/rule -> 5 per rule | |
| -- epsilon = 168/10088352 nats/op -> (1680000 * N) / 10088352 in fixed-point | |
| type HBaseFixed = 1000 | |
| type HHashFixed = 400 | |
| type HMarlborgPerRule = 5 | |
| data AdderState = AdderState | |
| { hTruncAccum :: Unsigned 32 | |
| , lastOpCount :: Unsigned 32 | |
| } deriving (Show, Eq, Generic, NFDataX) | |
| initialAdderState :: AdderState | |
| initialAdderState = AdderState 0 0 | |
| -- | Mealy transition: compute total cognitive entropy in fixed-point | |
| adderStep :: AdderState | |
| -> (Bit, Unsigned 12, Unsigned 32, Bool, Unsigned 16) | |
| -> (AdderState, Unsigned 32) | |
| adderStep st (truncValid, _thetaFixed, opCount, hashRemoved, deltaRules) = | |
| let deltaN = if opCount >= lastOpCount st | |
| then opCount - lastOpCount st | |
| else 0 | |
| hTruncAdd = if deltaN == 0 | |
| then 0 | |
| else (1680000 * resize deltaN) `div` 10088352 | |
| hTruncNext = hTruncAccum st + hTruncAdd | |
| hHash = if hashRemoved then HHashFixed else 0 | |
| hMarlborg = resize deltaRules * HMarlborgPerRule | |
| hCogFixed = HBaseFixed + hTruncNext + hHash + hMarlborg | |
| in (AdderState hTruncNext opCount, hCogFixed) | |
| -- | Entropy adder tree: sums all entropy components | |
| entropyAdderTree | |
| :: Clock System | |
| -> Reset System | |
| -> Enable System | |
| -> Signal System Bit | |
| -> Signal System (Unsigned 12) | |
| -> Signal System (Unsigned 32) | |
| -> Signal System Bool | |
| -> Signal System (Unsigned 16) | |
| -> Signal System (Unsigned 32) | |
| entropyAdderTree clk rst en truncValid thetaFixed opCount hashRemoved deltaRules = | |
| mealy clk rst en adderStep initialAdderState | |
| (bundle (truncValid, thetaFixed, opCount, hashRemoved, deltaRules)) | |
| topEntity | |
| :: Clock System | |
| -> Reset System | |
| -> Enable System | |
| -> Signal System Bit | |
| -> Signal System (Unsigned 12) | |
| -> Signal System (Unsigned 32) | |
| -> Signal System Bool | |
| -> Signal System (Unsigned 16) | |
| -> Signal System (Unsigned 32) | |
| topEntity = entropyAdderTree | |