Forum > General

question about bitpacking

(1/1)

440bx:
Hello,

I just want to make sure I don't make the wrong assumption about how the compiler bitpacks ranges. 

I expect that when bitpacked, the following two ranges will be packed in the _same_ number of bits:
--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---type  RANGE_1 = 0..7;  RANGE_2 = 0..4;
In both cases, I expect the number of bits required to be 3 (bits 0, 1 and 2 - ignoring ordering dependencies that may vary from one cpu to another).  I'm seeking confirmation of that and if it is not, then some explanation that sheds light on the reason(s) why not.

Thank you for your help.

Fibonacci:
I think I can confirm, both ranges when bitpacked will take 3 bits each. Of course they need to sit next to each other, eg in a bitpacked record, otherwise they will be padded to full byte.

440bx:
Thank you Fibonacci.

I understand the padding part.

I just want to make sure that the compiler doesn't do something unexpected if all the possible bits in the range are not specified (or just plain zeroes), e.g, it takes 3 bits to make the number 4 and also takes 3 bits for the number 7.

PascalDragon:

--- Quote from: 440bx on February 26, 2024, 06:34:28 am ---I expect that when bitpacked, the following two ranges will be packed in the _same_ number of bits:
--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---type  RANGE_1 = 0..7;  RANGE_2 = 0..4;
--- End quote ---

Correct.


--- Code: Pascal  [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---program tbitsize; type  RANGE_1 = 0..7;  RANGE_2 = 0..4;   R = bitpacked record    r1: RANGE_1;    r2: RANGE_2;    b1: Boolean;    b2: Boolean;  end;   A = bitpacked array[0..3] of RANGE_1;  B = bitpacked array[0..3] of RANGE_2; begin  Writeln(BitSizeOf(RANGE_1));  Writeln(BitSizeOf(RANGE_2));  Writeln(BitSizeOf(R));  Writeln(BitSizeOf(A));  Writeln(BitSizeOf(B));end.

--- Code: ---PS C:\fpc\git> .\testoutput\tbitsize.exe
8
8
8
16
16
--- End code ---

440bx:
Excellent !

Thank you for confirming that PascalDragon.  That's what makes sense but I still wanted confirmation.

Navigation

[0] Message Index

Go to full version