Example #1
0
 public UInt64BytesISegment(byte[] us, int len)
 {
     DEBUG.Assert(len > 0);
     _us                  = us;
     _len                 = len;
     _uint64Count         = (int)Math.Ceiling((decimal)len / 8);
     _lastUInt64ByteCount = 8 - (_uint64Count * 8 - _len);
 }
Example #2
0
        public static long WriteMapHead(ref BssomWriter writer, int valueCount, int maxDepth)
        {
            DEBUG.Assert(valueCount != 0 && maxDepth != 0);
            writer.FillUInt32FixNumber();           //len
            writer.WriteVariableNumber(valueCount); //count
            writer.WriteVariableNumber(maxDepth);   //depth
            long routeLenPos = writer.Position;

            writer.FillUInt32FixNumber();//routelen
            return(routeLenPos);
        }
Example #3
0
 private unsafe void WriteKeyBytes(byte lastValueByteCount, ulong keyBytes)
 {
     DEBUG.Assert(lastValueByteCount != 0 && lastValueByteCount <= 8);
     if (lastValueByteCount == 8)
     {
         writer.WriteWithOutTypeHead(keyBytes);
     }
     else
     {
         writer.WriteRaw64(keyBytes, lastValueByteCount);
     }
 }
Example #4
0
    static string Byte2HexChar(byte ch)
    {
        int ch1 = ch / 16;
        int ch2 = ch % 16;

        DEBUG.Assert(ch1 >= 0 && ch1 < 16, "ch1 is invalid");

        string table = "0123456789ABCDEF";
        string str   = table[ch1].ToString() + table[ch2].ToString();

        return(str);
    }
Example #5
0
        public static byte GetLessThenByteCount(BssMapRouteToken equalNext)
        {
            DEBUG.Assert(equalNext >= BssMapRouteToken.LessThen1 && equalNext <= BssMapRouteToken.LessThen8);

            byte t = (byte)equalNext;

            if (t > 20)
            {
                return((byte)(t - 20));
            }

            return(t);
        }
Example #6
0
        public static byte GetEqualNextOrLastByteCount(BssMapRouteToken equalNext)
        {
            DEBUG.Assert(equalNext >= BssMapRouteToken.EqualNext1 && equalNext <= BssMapRouteToken.EqualNext8 ||
                         equalNext >= BssMapRouteToken.EqualLast1 && equalNext <= BssMapRouteToken.EqualLast8);

            byte t = (byte)equalNext;

            if (t > 10)
            {
                return((byte)(t - 10));
            }

            return(t);
        }
Example #7
0
        public override bool sendFunctionalReq(PacketSource destiny, ref Packet pkt)
        {
            switch (destiny)
            {
            case PacketSource.TraceFetcher:
                DEBUG.Assert(pkt.isRequest() && pkt.isRead());
                pkt.ts_departure = GlobalTimer.tick;
                ins_port._masterPort.recvFunctionalReq(pkt);
                return(true);

            default:
                return(false);
            }
        }
Example #8
0
 public static void AssertNotSimilar(double[] left, double[] right, double tolerance)
 {
     if (left.Length != right.Length)
     {
         return;
     }
     for (int i = 0; i < left.Length; i++)
     {
         if (Math.Abs(left[i] - right[i]) <= tolerance)
         {
             continue;
         }
         return;
     }
     DEBUG.Assert(false);
 }
Example #9
0
    public static byte[] HexString2Bytes(string hex)
    {
        int len = hex.Length;

        DEBUG.Assert(len % 2 == 0, "hex string len must even number!");

        int arrLen = len / 2;

        byte[] bytes = new byte[arrLen];
        for (int i = 0; i < arrLen; i++)
        {
            byte ch = (byte)(HexChar2Byte(hex[i * 2]) * 16 + HexChar2Byte(hex[i * 2 + 1]));    //eg. E6 -> 15 * 16 + 6
            bytes[i] = ch;
        }

        return(bytes);
        //string totalStr = Encoding.UTF8.GetString(bytes);
        //return totalStr;
    }
Example #10
0
    static int HexChar2Byte(int ch)
    {
        if (ch >= '0' && ch <= '9')
        {
            return(ch - '0');
        }

        if (ch >= 'A' && ch <= 'Z')
        {
            return(ch - 'A' + 10);
        }

        if (ch >= 'a' && ch <= 'z')
        {
            return(ch - 'a' + 10);
        }

        DEBUG.Assert(false, "ch is invalid");
        return(-1);
    }
Example #11
0
        public static void AssertNotNull <T>(params T[] value)
            where T : class
        {
            bool assert = true;

            if (value == null)
            {
                assert = false;
            }
            else
            {
                for (int i = 0; i < value.Length; i++)
                {
                    if (value[i] == null)
                    {
                        assert = false;
                    }
                }
            }
            DEBUG.Assert(assert);
        }
Example #12
0
 public static void AssertNotSimilar(double[,] left, double[,] right, double tolerance)
 {
     if (left.GetLength(0) != right.GetLength(0))
     {
         return;
     }
     if (left.GetLength(1) != right.GetLength(1))
     {
         return;
     }
     for (int i = 0; i < left.GetLength(0); i++)
     {
         for (int j = 0; j < left.GetLength(1); j++)
         {
             if (Math.Abs(left[i, j] - right[i, j]) <= tolerance)
             {
                 continue;
             }
             return;
         }
     }
     DEBUG.Assert(false);
 }
Example #13
0
        public static void AssertNotNull <T>(T[,] value)
            where T : class
        {
            bool assert = true;

            if (value == null)
            {
                assert = false;
            }
            else
            {
                for (int i = 0; i < value.GetLength(0); i++)
                {
                    for (int j = 0; j < value.GetLength(1); j++)
                    {
                        if (value[i, j] == null)
                        {
                            assert = false;
                        }
                    }
                }
            }
            DEBUG.Assert(assert);
        }
Example #14
0
        public Instruction parse_ins(string line, int pid_)
        {
            try
            {
                //try one line
                DEBUG.Assert(line != null);

                string[]    split_ins = line.Split('|');
                Instruction ins       = new Instruction(split_ins[1]);
                ins.cycle = UInt64.Parse(split_ins[0]);
                ins.pid   = pid_;

                if (PIMConfigs.PIM_Fliter == PIM_input_type.All)
                {
                    //set all insruction to pim
                    ins.pim = PIMConfigs.PIM_Ins_List.Any(s => s == ins.Operation) ? true : false;
                }
                else
                {
                    //use PIM_ label to identify PIM operations
                    ins.pim = (ins.Operation.StartsWith("PIM_")) ? true : false;
                }
                //read address and data.
                if (split_ins.Length >= 4)
                {
                    ins.type = (split_ins[2] == "R") ? InstructionType.READ : InstructionType.WRITE;
                    //  ins.type = (split_ins[2] == "W") ? InstructionType.WRITE : InstructionType.CALCULATION;



                    string[] d_and_a = split_ins[3].Split(' ');
                    ins.is_mem = false;

                    //read data and address
                    foreach (string p in d_and_a)
                    {
                        if (p.Contains("A="))
                        {
                            ins.address = UInt64.Parse(p.Replace("A=0x", ""), System.Globalization.NumberStyles.AllowHexSpecifier);
                            ins.is_mem  = true;
                        }
                        else
                        {
                            if (p.Contains("D="))
                            {
                                ins.data   = UInt64.Parse(p.Replace("D=0x", ""), System.Globalization.NumberStyles.AllowHexSpecifier);
                                ins.is_mem = true;
                            }
                            else
                            {
                                DEBUG.Error("Error in parsing trace line.");
                                Environment.Exit(2);
                            }
                        }
                    }
                }
                else
                {
                    ins.type = InstructionType.CALCULATION;
                }
                return(ins);
            }

            catch
            {
                DEBUG.Error("Faied to parse trace in CPU:" + pid_ + "line=" + line);
                return(null);
            }
        }
Example #15
0
 public static int SizeMapHead(int valueCount, int maxDepth)
 {
     DEBUG.Assert(valueCount != 0 && maxDepth != 0);
     return(DefaultMapLengthFieldSize + BssomBinaryPrimitives.VariableNumberSize((ulong)valueCount) + BssomBinaryPrimitives.VariableNumberSize((ulong)maxDepth) + DefaultRouteLengthFieldSize);
 }
Example #16
0
 private unsafe void WriteKeyBytes(byte lastValueByteCount, ulong keyBytes)
 {
     DEBUG.Assert(lastValueByteCount != 0 && lastValueByteCount <= 8);
     AdvanceSize(lastValueByteCount);
 }