private static unsafe void FillRowSimd(int[] previousRow) { // First int i = 0; int count = System.Numerics.Vector <int> .Count; //int initialCount = Math.Min(count, previousRow.Length); for (i = 0; i < previousRow.Length && i < count; ++i) { previousRow[i] = i; } var a = new System.Numerics.Vector <int>(previousRow); var countV = new System.Numerics.Vector <int>(count); for (; i < previousRow.Length - count; i += count) { a = a + countV; a.CopyTo(previousRow, i); } for (; i < previousRow.Length; ++i) { previousRow[i] = i; } }
private void GetAndMoveToFrontDecode() { byte[] yy = new byte[256]; int nextSym; int limitLast = BZip2Constants.BaseBlockSize * blockSize100k; origPtr = BsGetIntVS(24); RecvDecodingTables(); int EOB = nInUse + 1; int groupNo = -1; int groupPos = 0; /*-- * Setting up the unzftab entries here is not strictly * necessary, but it does save having to do it later * in a separate pass, and so saves a block's worth of * cache misses. * --*/ for (int i = 0; i <= 255; i++) { unzftab[i] = 0; } for (int i = 0; i <= 255; i++) { yy[i] = (byte)i; } last = -1; if (groupPos == 0) { groupNo++; groupPos = BZip2Constants.GroupSize; } groupPos--; int zt = selector[groupNo]; int zn = minLens[zt]; int zvec = BsR(zn); int zj; while (zvec > limit[zt][zn]) { if (zn > 20) { // the longest code throw new BZip2Exception("Bzip data error"); } zn++; while (bsLive < 1) { FillBuffer(); } zj = (bsBuff >> (bsLive - 1)) & 1; bsLive--; zvec = (zvec << 1) | zj; } if (zvec - baseArray[zt][zn] < 0 || zvec - baseArray[zt][zn] >= BZip2Constants.MaximumAlphaSize) { throw new BZip2Exception("Bzip data error"); } nextSym = perm[zt][zvec - baseArray[zt][zn]]; while (true) { if (nextSym == EOB) { break; } if (nextSym == BZip2Constants.RunA || nextSym == BZip2Constants.RunB) { int s = -1; int n = 1; do { if (nextSym == BZip2Constants.RunA) { s += (0 + 1) * n; } else if (nextSym == BZip2Constants.RunB) { s += (1 + 1) * n; } n <<= 1; if (groupPos == 0) { groupNo++; groupPos = BZip2Constants.GroupSize; } groupPos--; zt = selector[groupNo]; zn = minLens[zt]; zvec = BsR(zn); while (zvec > limit[zt][zn]) { zn++; while (bsLive < 1) { FillBuffer(); } zj = (bsBuff >> (bsLive - 1)) & 1; bsLive--; zvec = (zvec << 1) | zj; } nextSym = perm[zt][zvec - baseArray[zt][zn]]; } while (nextSym == BZip2Constants.RunA || nextSym == BZip2Constants.RunB); s++; byte ch = seqToUnseq[yy[0]]; unzftab[ch] += s; while (s > 0) { last++; ll8[last] = ch; s--; } if (last >= limitLast) { BlockOverrun(); } continue; } else { last++; if (last >= limitLast) { BlockOverrun(); } byte tmp = yy[nextSym - 1]; unzftab[seqToUnseq[tmp]]++; ll8[last] = seqToUnseq[tmp]; var j = nextSym - 1; #if !NETSTANDARD2_0 && !NETFRAMEWORK // This is vectorized memory move. Going from the back, we're taking chunks of array // and write them at the new location shifted by one. Since chunks are VectorSize long, // at the end we have to move "tail" (or head actually) of the array using a plain loop. // If System.Numerics.Vector API is not available, the plain loop is used to do the whole copying. while (j >= VectorSize) { var arrayPart = new System.Numerics.Vector <byte>(yy, j - VectorSize); arrayPart.CopyTo(yy, j - VectorSize + 1); j -= VectorSize; } #endif while (j > 0) { yy[j] = yy[--j]; } yy[0] = tmp; if (groupPos == 0) { groupNo++; groupPos = BZip2Constants.GroupSize; } groupPos--; zt = selector[groupNo]; zn = minLens[zt]; zvec = BsR(zn); while (zvec > limit[zt][zn]) { zn++; while (bsLive < 1) { FillBuffer(); } zj = (bsBuff >> (bsLive - 1)) & 1; bsLive--; zvec = (zvec << 1) | zj; } nextSym = perm[zt][zvec - baseArray[zt][zn]]; continue; } } }
/////////////////////////////////// /////////Расчет на основе векторов public static int[,] FileVect() { string[] stchar; int i = 0, j = 0; int[,] cliArr = new int[9, 5]; int[,] ordArr = new int[9, 5]; int stout; ///////Читаем файлы var FileCli = System.IO.File.ReadAllLines("clients.txt"); var FileOrd = System.IO.File.ReadAllLines("orders.txt"); foreach (var sttr in FileCli) { stchar = sttr.Split("\t"); j = 0; foreach (var stch in stchar) { if (int.TryParse(stch, out stout) == false) { continue; } cliArr[i, j] = stout; j++; } i++; } // ///////Заполняем 4 вектора // //string[] ColA = FileOrd.Where(entry => // //(entry?.Split("\t")[2] == "A"))?.ToArray(); // //string[] ColB = FileOrd.Where(entry => // //(entry?.Split("\t")[2] == "B"))?.ToArray(); // //string[] ColC = FileOrd.Where(entry => // //(entry?.Split("\t")[2] == "C"))?.ToArray(); // //string[] ColD = FileOrd.Where(entry => // //(entry?.Split("\t")[2] == "D"))?.ToArray(); // ////////Переписываю с форами и молотилкой привидения к виду Array.Sort(FileOrd); // ////////Все ABCD для ячейки C1, C1 b A, C1 s A, C1 b B, C1 b // //////за один такт нужно посчитать минимум 4 ячейки // ////Получаем значения для одномерки // ////Будет форыч основанный на счетчиках, будем шагать при смене буквы и ячейки, при этом сразу считать. // ////координаты это счетчики int M = 0; int mstep = 0; bool flagS = false; int strNum = 0; int oldstrNum = 0; int colNum = 0; int oldcolNum = 0; int[] CalcMassive = new int[800]; int[] resArr = new int[4]; int SUMM = 0; int Dollars = 0; //float[] resArr2 = new float[2]; System.Diagnostics.Stopwatch swatch = new System.Diagnostics.Stopwatch(); swatch.Start(); foreach (var sttr in FileOrd) //for (i=0; i <= FileOrd.Length; i++) { //String sttr = FileOrd[i]; stchar = sttr.Split("\t"); //flagS = false; ////////Запоминаем текущую строку, как только меняется + и обновляем if (strNum != int.Parse(stchar[0].Substring(1)) - 1 || colNum != (int)Char.Parse(stchar[2]) - 65) { strNum = int.Parse(stchar[0].Substring(1)) - 1; colNum = (int)Char.Parse(stchar[2]) - 65; int Znak = 0; if (stchar[1] == "b") { Znak = 1; } else { Znak = -1; } Dollars = Dollars + int.Parse(stchar[4]) * Znak; //Console.WriteLine(CalcMassive.Sum()); //////Вычисляем кратность 8 количества элементов, будет происходить смещение на 4 индекса, //////разложил для удобства if (mstep % 8 != 0) { M = ((((mstep / 8) + 1) * 8) + 4); } else { M = mstep + 4; } //////Начиная с четырех элементов с шагом в 8 будет 4-8, 0-4; 12-16, 8-12 for (i = 4; i <= M; i += System.Numerics.Vector <int> .Count + 4) { //////Заполняем первые 8 System.Numerics.Vector <int> aSimd = new System.Numerics.Vector <int>(CalcMassive, i); System.Numerics.Vector <int> bSimd = new System.Numerics.Vector <int>(CalcMassive, i - 4); System.Numerics.Vector <int> cSimd = aSimd + bSimd; cSimd.CopyTo(resArr); int arrsum = resArr.Sum(); SUMM = SUMM + arrsum; } Array.Clear(CalcMassive, 0, mstep); Array.Clear(resArr, 0, resArr.Length); //////////Сумму ячейки считаем мы cliArr[oldstrNum, oldcolNum] = cliArr[oldstrNum, oldcolNum] + SUMM; cliArr[oldstrNum, 4] = cliArr[oldstrNum, 4] + Dollars; oldstrNum = strNum; oldcolNum = colNum; Dollars = 0; SUMM = 0; mstep = 0; } else { int Znak = 0; if (stchar[1] == "b") { Znak = 1; } else { Znak = -1; } CalcMassive[mstep] = int.Parse(stchar[3]) * Znak; Dollars = Dollars + int.Parse(stchar[4]) * Znak; mstep++; } } swatch.Stop(); Console.WriteLine(swatch.Elapsed); return(cliArr); }