public void u16(RawBitWriter <TMemory> b, u16 value)
        {
            value++;
            u32 map   = 0;
            i32 index = -1;

            for (var i = Coder.Fibonacci.u16Lookup.Length - 1; i >= 0; i--)
            {
                if (value >= Coder.Fibonacci.u16Lookup[i])
                {
                    if (index == -1)
                    {
                        index = i + 1;
                        map   = BitOperations.WriteBit(map, index, true);
                    }

                    map    = BitOperations.WriteBit(map, i, true);
                    value -= Coder.Fibonacci.u16Lookup[i];
                }
            }

            for (var i = 0; i <= index; i++)
            {
                // TODO: optimize
                var bit = BitOperations.ExtractBit(map, i);
                b.b(bit);
            }
        }
Example #2
0
 public void u16(RawBitWriter <TMemory> b, u16 value)
 {
     while (value >= 0b10000000)
     {
         b.u8Raw((u8)(value | 0b10000000)); value >>= 7;
     }
     b.u8Raw((u8)value);
 }
Example #3
0
 public void u32(RawBitWriter <TMemory> b, u32 value)
 // 1. trying to use generic method or class with call for inline and optimize with only interface constraint losses great of performance
 // 2. passing instance of class buffer by `in` slows down by 10
 // 3. per call instance of holder struct  also losts 10 percentage of performance (not sure if share per thread)
 {
     // TODO: how to use CPU parallelism here ? unrol loop? couple of temporal variables?
     // TODO: mere 8 and 8 into one 16? write special handling code for 8 and 16 coming from outside?
     // oneliner version to use if need copy paste
     while (value >= 0b10000000)
     {
         b.u8Raw((u8)(value | 0b10000000)); value >>= 7;
     }
     b.u8Raw((u8)value);
 }
Example #4
0
        public void u8()
        {
            var storage = new u32ArrayMemory(new u32[42]);
            var writer  = new RawBitWriter <u32ArrayMemory>(storage);
            u16 v1      = 42;
            u16 v2      = 666;

            writer.u16(v1, 16);
            Assert.AreEqual(16, writer.BitsWritten);
            writer.u16(v2, 10);
            writer.Align();
            var reader = new RawBitReader <u32ArrayMemory>(storage);
            var rv1    = reader.u16(16);
            var rv2    = reader.u16(10);

            Assert.AreEqual(v1, rv1);
            Assert.AreEqual(v2, rv2);
        }
Example #5
0
 public void u8(RawBitWriter <TMemory> b, u8 value) => b.u8Raw(value);
Example #6
0
 public void u16(RawBitWriter <TMemory> b, u16 value) => b.u16(value, 16);
Example #7
0
 public void i32(RawBitWriter <TMemory> b, i32 value, u8 numberOfBits) => i32(b, value);
Example #8
0
 public void u32(RawBitWriter <TMemory> b, u32 value) => b.u32(value, 32);
Example #9
0
 public void i32(RawBitWriter <TMemory> b, i32 value) => b.u32((u32)value, 32);
 public void i32(RawBitWriter <TMemory> b, i32 value, u8 numberOfBits) =>
 b.u32(encode(value), numberOfBits);
 public void i32(RawBitWriter <TMemory> b, i32 value)
 {
     u32(b, encode(value));
 }
Example #12
0
 public void i32(RawBitWriter <TMemory> b, i32 value)
 {
     // have tried to have only encode, with no i32 method,
     // but double layer of constrained generics does not propagate on .NET Core and leads to loss of performance
     u32(b, encode(value));
 }