Topics: Binary arithmetic

No changes were pushed to devel branch this week. Everything this post is about is happening on issue/e8113638/math-on-bits.

Binary arithmetic

Viua VM added bit string manipulation to the instruction set some time ago. Now, artihmetic on bit strings is in the works.


Implementing arithmetic in Viua VM that is independent of the underlying hardware is a step forward in making the VM more reliable and predictable. If the arithmetic is wholly contained inside the VM kernel than the VM defines the rules, and can prevent such errors as silent truncation of results.


The behaviour of bit strings arithmetic is still in a state of flux. Final definition of the semantics of bit string arithmetic will probably not come soon. Most probably there will be two sets of operations: a fixed one, keeping the width of the result the same as the width of the operands; and an "arithmetic" one, extending result as needed.

Available operations

Operations implemented so far include increment, decrement, addition, subtraction (using two's complement), and multiplication.