omega-mv
Omega: a language for verified programs, semantic identity and machine realization. Seed-born work and existing implementations have distinct provenance.
Brought by drakestapleton
omega-mv / seed / equiv / pop16.unit.om
| 1 | note irequiv fixture (issue 826): population count of a ushort (u16 domain). |
| 2 | note pop16 counts bit by bit; pop16s is the SWAR refactor. pop16z and pop16e are |
| 3 | note deliberate mutants of pop16s that differ at exactly one input: the first |
| 4 | note (x = 0) and the last (x = 65535) of the enumeration. |
| 5 | fn pop16 x ushort to ushort |
| 6 | c = ushort 0 |
| 7 | for i uint 16 |
| 8 | c = add c and x 1 |
| 9 | x = shr x 1 |
| 10 | end |
| 11 | ret c |
| 12 | end |
| 13 | fn pop16s x ushort to ushort |
| 14 | x = sub x and shr x 1 21845 |
| 15 | x = add and x 13107 and shr x 2 13107 |
| 16 | x = and add x shr x 4 3855 |
| 17 | ret and add x shr x 8 31 |
| 18 | end |
| 19 | fn pop16z x ushort to ushort |
| 20 | if eq x 0 |
| 21 | ret 1 |
| 22 | end |
| 23 | x = sub x and shr x 1 21845 |
| 24 | x = add and x 13107 and shr x 2 13107 |
| 25 | x = and add x shr x 4 3855 |
| 26 | ret and add x shr x 8 31 |
| 27 | end |
| 28 | fn pop16e x ushort to ushort |
| 29 | if eq x 65535 |
| 30 | ret 15 |
| 31 | end |
| 32 | x = sub x and shr x 1 21845 |
| 33 | x = add and x 13107 and shr x 2 13107 |
| 34 | x = and add x shr x 4 3855 |
| 35 | ret and add x shr x 8 31 |
| 36 | end |