Home » U++ Library support » U++ Core » Writing Bits object to disk
Re: Writing Bits object to disk [message #47960 is a reply to message #47952] |
Thu, 27 April 2017 10:31   |
crydev
Messages: 151 Registered: October 2012 Location: Netherlands
|
Experienced Member |
|
|
Thanks Mirek!
I have been trying a thing or two myself. I wrote a version of the Set(int, bool) method that accepts four bool values at the same time. This version _probably_ has more pipelining capabilities, and is faster than the regular set method!
union BitBoolPipeline
{
struct
{
bool b1;
bool b2;
bool b3;
bool b4;
};
dword dw;
};
// Different function implementing Bits, but with a pipelined set method.
const int VectorBoolOrBitsetTestBitSetPipeline(Bits& buffer, const Vector<bool>& rand)
{
const int count = rand.GetCount();
for (int i = 0; i < count; i += 4)
{
// We can now set four bools at the same time. However, we must assume that a bool that
// is set to true has value 0x1, and a bool set to false has value 0x0.
BitBoolPipeline b;
b.b1 = rand[i];
b.b2 = rand[i + 1];
b.b3 = rand[i + 2];
b.b4 = rand[i + 3];
buffer.PipelineSet(i, b.dw);
}
int alloc = 0;
buffer.Raw(alloc);
return alloc;
}
const dword PowersOfTwo[] =
{
0x1, 0x2, 0x4, 0x8, 0x10, 0x20, 0x40, 0x80, 0x100, 0x200, 0x400, 0x800, 0x1000, 0x2000,
0x4000, 0x8000, 0x10000, 0x20000, 0x40000, 0x80000, 0x100000, 0x200000, 0x400000, 0x800000,
0x1000000, 0x2000000, 0x4000000, 0x8000000, 0x10000000, 0x20000000, 0x40000000, 0x80000000
};
// Testing pipelined version of Bits::Set(int, bool)
void Bits::PipelineSet(int i, const dword bs)
{
// Check whether i is within the bounds of the container.
ASSERT(i >= 0 && alloc >= 0);
// Get the DWORD index for the internal buffer.
int q = i >> 5;
// Get the bit index of the next available DWORD.
i &= 31;
// Do we need to expand the internal buffer first?
// Also check whether we can place 4 bits in the existing DWORD. If not, we should expand.
if(q >= alloc)
Expand(q);
// Get integer bit values according to existing DWORD value and indices.
// Assuming default value of bool is 0x1 if true!
bp[q] = (bp[q] | bs & PowersOfTwo[1] | bs & PowersOfTwo[8] | bs & PowersOfTwo[16] | bs & PowersOfTwo[24]);
}
This function assumes that a bool set to true has value 0x1, and 0x0 otherwise. I made the array of constant powers of two in advance. Replacing the array indices with the array constant itself doesn't improve any further, because the compiler propagates the constants by itself. The measurement is as follows:

I'm also working on a SIMD version that should be able to set 16 bools in parallel, having some assumptions about the input. 
crydev
-
Attachment: Capture.PNG
(Size: 17.25KB, Downloaded 626 times)
[Updated on: Thu, 27 April 2017 10:33] Report message to a moderator
|
|
|
 |
|
Writing Bits object to disk
By: crydev on Wed, 11 January 2017 17:07
|
 |
|
Re: Writing Bits object to disk
By: mr_ped on Thu, 12 January 2017 01:20
|
 |
|
Re: Writing Bits object to disk
By: crydev on Thu, 12 January 2017 09:03
|
 |
|
Re: Writing Bits object to disk
By: mirek on Fri, 13 January 2017 08:39
|
 |
|
Re: Writing Bits object to disk
By: crydev on Wed, 18 January 2017 08:51
|
 |
|
Re: Writing Bits object to disk
By: crydev on Mon, 24 April 2017 19:19
|
 |
|
Re: Writing Bits object to disk
By: mirek on Mon, 24 April 2017 21:08
|
 |
|
Re: Writing Bits object to disk
By: crydev on Tue, 25 April 2017 09:36
|
 |
|
Re: Writing Bits object to disk
|
 |
|
Re: Writing Bits object to disk
By: mirek on Tue, 25 April 2017 10:31
|
 |
|
Re: Writing Bits object to disk
By: mirek on Tue, 25 April 2017 10:34
|
 |
|
Re: Writing Bits object to disk
By: crydev on Tue, 25 April 2017 11:37
|
 |
|
Re: Writing Bits object to disk
By: mirek on Tue, 25 April 2017 11:59
|
 |
|
Re: Writing Bits object to disk
By: mirek on Tue, 25 April 2017 12:38
|
 |
|
Re: Writing Bits object to disk
By: crydev on Tue, 25 April 2017 13:35
|
 |
|
Re: Writing Bits object to disk
By: mirek on Tue, 25 April 2017 13:39
|
 |
|
Re: Writing Bits object to disk
By: crydev on Tue, 25 April 2017 14:03
|
 |
|
Re: Writing Bits object to disk
By: mirek on Tue, 25 April 2017 16:40
|
 |
|
Re: Writing Bits object to disk
By: crydev on Wed, 26 April 2017 08:27
|
 |
|
Re: Writing Bits object to disk
By: crydev on Wed, 26 April 2017 08:50
|
 |
|
Re: Writing Bits object to disk
By: mirek on Wed, 26 April 2017 13:38
|
 |
|
Re: Writing Bits object to disk
By: crydev on Thu, 27 April 2017 10:31
|
 |
|
Re: Writing Bits object to disk
By: mirek on Thu, 27 April 2017 23:50
|
 |
|
Re: Writing Bits object to disk
By: crydev on Fri, 28 April 2017 19:04
|
 |
|
Re: Writing Bits object to disk
By: mirek on Sat, 29 April 2017 09:05
|
 |
|
Re: Writing Bits object to disk
By: omari on Fri, 28 April 2017 19:31
|
 |
|
Re: Writing Bits object to disk
By: mirek on Sat, 29 April 2017 09:53
|
 |
|
Re: Writing Bits object to disk
By: crydev on Tue, 02 May 2017 22:54
|
 |
|
Re: Writing Bits object to disk
By: mirek on Tue, 02 May 2017 23:55
|
 |
|
Re: Writing Bits object to disk
By: crydev on Wed, 03 May 2017 09:00
|
 |
|
Re: Writing Bits object to disk
By: mirek on Wed, 03 May 2017 09:53
|
 |
|
Re: Writing Bits object to disk
By: crydev on Wed, 03 May 2017 11:12
|
 |
|
Re: Writing Bits object to disk
By: mirek on Wed, 03 May 2017 11:27
|
 |
|
Re: Writing Bits object to disk
By: crydev on Wed, 03 May 2017 12:24
|
 |
|
Re: Writing Bits object to disk
By: mirek on Wed, 03 May 2017 12:37
|
 |
|
Re: Writing Bits object to disk
By: crydev on Wed, 03 May 2017 18:33
|
 |
|
Re: Writing Bits object to disk
By: crydev on Sat, 06 May 2017 10:28
|
 |
|
Re: Writing Bits object to disk
By: crydev on Tue, 16 May 2017 09:12
|
 |
|
Re: Writing Bits object to disk
By: mirek on Tue, 16 May 2017 10:39
|
 |
|
Re: Writing Bits object to disk
By: mirek on Tue, 16 May 2017 13:12
|
 |
|
Re: Writing Bits object to disk
By: crydev on Tue, 16 May 2017 20:17
|
Goto Forum:
Current Time: Sat May 10 16:48:07 CEST 2025
Total time taken to generate the page: 0.01340 seconds
|