1 using System;
2
3 namespace cmsx.machine
4 {
5 public inline nothrow ulong BitCount(ulong x)
6 {
7 ulong c = 0u;
8 ulong m = 1u;
9 for (int i = 0; i < 64; ++i;)
10 {
11 if ((x & m) != 0u)
12 {
13 ++c;
14 }
15 m = m << 1u;
16 }
17 return c;
18 }
19
20 public inline nothrow byte SaturatingSubtraction(byte x, byte y)
21 {
22 if (x >= y) return x - y; else return 0u;
23 }
24
25 public inline nothrow ushort SaturatingSubtraction(ushort x, ushort y)
26 {
27 if (x >= y) return x - y; else return 0u;
28 }
29
30 public inline nothrow uint SaturatingSubtraction(uint x, uint y)
31 {
32 if (x >= y) return x - y; else return 0u;
33 }
34
35 public inline nothrow ulong SaturatingSubtraction(ulong x, ulong y)
36 {
37 if (x >= y) return x - y; else return 0u;
38 }
39 }