PhraseSet.FillPhraseSet rewritten to use pointers only

master
Inga 🏳‍🌈 8 years ago
parent a154b211a5
commit c5e129ffd9
  1. 19
      dotnet/WhiteRabbit/PhraseSet.cs
  2. 25
      dotnet/WhiteRabbit/Word.cs

@ -19,13 +19,16 @@
{
fixed (int* wordIndexesPointer = wordIndexes)
{
FillPhraseSet(bufferPointer, allWords, wordIndexesPointer, permutationsPointer, permutationOffset, numberOfCharacters, wordIndexes.Length);
fixed (Word* allWordsPointer = allWords)
{
FillPhraseSet(bufferPointer, (long*)allWordsPointer, wordIndexesPointer, permutationsPointer, permutationOffset, numberOfCharacters, wordIndexes.Length);
}
}
}
}
}
private static unsafe void FillPhraseSet(long* bufferPointer, Word[] allWords, int* wordIndexes, ulong* permutationsPointer, int permutationOffset, int numberOfCharacters, int numberOfWords)
private static unsafe void FillPhraseSet(long* bufferPointer, long* allWordsPointer, int* wordIndexes, ulong* permutationsPointer, int permutationOffset, int numberOfCharacters, int numberOfWords)
{
long* longBuffer = (long*)bufferPointer;
@ -41,13 +44,13 @@
var cumulativeWordOffsetX4 = 0;
for (var j = 0; j < numberOfWords; j++)
{
var currentWord = allWords[wordIndexes[permutation & 15]];
var currentWord = allWordsPointer + wordIndexes[permutation & 15] * 128;
permutation = permutation >> 4;
longBuffer[0] |= currentWord.Buffers[cumulativeWordOffsetX4 + 0];
longBuffer[1] |= currentWord.Buffers[cumulativeWordOffsetX4 + 1];
longBuffer[2] ^= currentWord.Buffers[cumulativeWordOffsetX4 + 2];
longBuffer[3] ^= currentWord.Buffers[cumulativeWordOffsetX4 + 3];
cumulativeWordOffsetX4 += currentWord.LengthX4;
longBuffer[0] |= currentWord[cumulativeWordOffsetX4 + 0];
longBuffer[1] |= currentWord[cumulativeWordOffsetX4 + 1];
longBuffer[2] ^= currentWord[cumulativeWordOffsetX4 + 2];
longBuffer[3] ^= currentWord[cumulativeWordOffsetX4 + 3];
cumulativeWordOffsetX4 += unchecked((int)currentWord[127]);
}
longBuffer += 4;

@ -1,19 +1,8 @@
namespace WhiteRabbit
{
class Word
internal unsafe struct Word
{
public byte[] Original;
public long[] Buffers { get; }
public int LengthX4 { get; }
private Word()
{
this.Original = new byte[0];
this.Buffers = new long[128];
this.LengthX4 = 0;
}
public fixed long Buffers[128];
public unsafe Word(byte[] word)
{
@ -24,10 +13,7 @@
tmpWord[i] = word[i];
}
this.Original = tmpWord;
var buffers = new long[128];
fixed (long* buffersPointer = buffers)
fixed (long* buffersPointer = this.Buffers)
{
for (var i = 0; i < 32; i++)
{
@ -39,10 +25,9 @@
*currentPointer = tmpWord[j];
}
}
}
this.Buffers = buffers;
this.LengthX4 = tmpWord.Length * 4;
buffersPointer[127] = tmpWord.Length * 4;
}
}
private static Word Empty { get; } = new Word();

Loading…
Cancel
Save