Created
November 3, 2022 08:21
-
-
Save hades2510/78bb8e241004fe7978ce01ef71b54f68 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
type PartialAdd< | |
LHS extends Bit[], | |
RHS extends Bit[], | |
CF extends CarryFlag = Zero | |
> = LHS extends [...infer LHSU extends Bit[], infer LHSR extends Bit] | |
? RHS extends [...infer RHSU extends Bit[], infer RHSR extends Bit] | |
? [ | |
...PartialAdd<LHSU, RHSU, AddBitsWithCarry<LHSR, RHSR, CF>["cf"]>, | |
AddBitsWithCarry<LHSR, RHSR, CF>["value"] | |
] | |
: [] | |
: []; | |
type Add<LHS extends Byte, RHS extends Byte> = LHS extends [ | |
...infer LHSU extends Bit[], | |
infer LHSR extends Bit | |
] | |
? RHS extends [...infer RHSU extends Bit[], infer RHSR extends Bit] | |
? [ | |
...PartialAdd<LHSU, RHSU, AddBitsWithCarry<LHSR, RHSR>["cf"]>, | |
AddBitsWithCarry<LHSR, RHSR>["value"] | |
] | |
: [] | |
: []; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment