interplane.Get Omega
Read in your language

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

branch main Branches Tags History

omega-mv / seed / equiv / pop16.unit.om

36 lines · 891 bytes Raw Blame History
1note irequiv fixture (issue 826): population count of a ushort (u16 domain).
2note pop16 counts bit by bit; pop16s is the SWAR refactor. pop16z and pop16e are
3note deliberate mutants of pop16s that differ at exactly one input: the first
4note (x = 0) and the last (x = 65535) of the enumeration.
5fn pop16 x ushort to ushort
6c = ushort 0
7for i uint 16
8c = add c and x 1
9x = shr x 1
10end
11ret c
12end
13fn pop16s x ushort to ushort
14x = sub x and shr x 1 21845
15x = add and x 13107 and shr x 2 13107
16x = and add x shr x 4 3855
17ret and add x shr x 8 31
18end
19fn pop16z x ushort to ushort
20if eq x 0
21ret 1
22end
23x = sub x and shr x 1 21845
24x = add and x 13107 and shr x 2 13107
25x = and add x shr x 4 3855
26ret and add x shr x 8 31
27end
28fn pop16e x ushort to ushort
29if eq x 65535
30ret 15
31end
32x = sub x and shr x 1 21845
33x = add and x 13107 and shr x 2 13107
34x = and add x shr x 4 3855
35ret and add x shr x 8 31
36end