PhraseSet filling moved out to separate method

master
Inga 🏳‍🌈 8 years ago
parent cbb7ccb59b
commit a154b211a5
  1. 75
      dotnet/WhiteRabbit/PhraseSet.cs

@ -15,51 +15,58 @@
fixed (long* bufferPointer = this.Buffer) fixed (long* bufferPointer = this.Buffer)
{ {
long* longBuffer = (long*)bufferPointer;
int numberOfWords = wordIndexes.Length;
fixed (ulong* permutationsPointer = permutations) fixed (ulong* permutationsPointer = permutations)
{ {
var currentPermutationPointer = permutationsPointer + permutationOffset; fixed (int* wordIndexesPointer = wordIndexes)
for (var i = 0; i < Constants.PhrasesPerSet; i++, currentPermutationPointer++)
{ {
var permutation = *currentPermutationPointer; FillPhraseSet(bufferPointer, allWords, wordIndexesPointer, permutationsPointer, permutationOffset, numberOfCharacters, wordIndexes.Length);
if (permutation == 0)
{
continue;
}
var cumulativeWordOffsetX4 = 0;
for (var j = 0; j < numberOfWords; j++)
{
var currentWord = allWords[wordIndexes[permutation & 15]];
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 += 4;
} }
} }
}
}
private static unsafe void FillPhraseSet(long* bufferPointer, Word[] allWords, int* wordIndexes, ulong* permutationsPointer, int permutationOffset, int numberOfCharacters, int numberOfWords)
{
long* longBuffer = (long*)bufferPointer;
var length = numberOfCharacters + numberOfWords - 1; var currentPermutationPointer = permutationsPointer + permutationOffset;
byte* byteBuffer = ((byte*)bufferPointer) + length; for (var i = 0; i < Constants.PhrasesPerSet; i++, currentPermutationPointer++)
for (var i = 0; i < Constants.PhrasesPerSet; i++) {
var permutation = *currentPermutationPointer;
if (permutation == 0)
{ {
*byteBuffer = 128; continue;
byteBuffer += 32;
} }
var lengthInBits = (uint)(length << 3); var cumulativeWordOffsetX4 = 0;
uint* uintBuffer = ((uint*)bufferPointer) + 7; for (var j = 0; j < numberOfWords; j++)
for (var i = 0; i < Constants.PhrasesPerSet; i++)
{ {
*uintBuffer = lengthInBits; var currentWord = allWords[wordIndexes[permutation & 15]];
uintBuffer += 8; 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 += 4;
}
var length = numberOfCharacters + numberOfWords - 1;
byte* byteBuffer = ((byte*)bufferPointer) + length;
for (var i = 0; i < Constants.PhrasesPerSet; i++)
{
*byteBuffer = 128;
byteBuffer += 32;
}
var lengthInBits = (uint)(length << 3);
uint* uintBuffer = ((uint*)bufferPointer) + 7;
for (var i = 0; i < Constants.PhrasesPerSet; i++)
{
*uintBuffer = lengthInBits;
uintBuffer += 8;
} }
} }

Loading…
Cancel
Save