Frank Heckenbach wrote:
Gale Paeper wrote:
68K and PPC CodeWarrior Pascal, YHINK Pascal, and MPW Pascal all use the same data format for sets. The format is an array of bytes and (from the CodeWarrior Pascal documentation) the formula for determining a specific set element bit in the array is:
bit : BAND(SET[|SET| - 1 - EL div 8],(BSL(1,EL mod 8))
where BAND and BSL are 68K intrinsics for 68K instructions for respectively bitwise AND and bitwise shift left.
OK, so that's just the reverse of what Waldek suggested. It's also word-size-agnostic and allows for simple range operations with any word-size. (It's just quite different from the little-endian format in that the byte-order is completely reversed.)
At least for the 68K instruction set, it also has some nice "for free" space and cycle savings properties. The 68K simgle bit instructions (BCLR, BSET, BTST, etc.) automatically do a mod 8 on the element number when operating on a memory byte and a mod 32 on the element number when operating on a register. Although savings are down in the noise level on todays machines, saving a few bytes and cycles here and there on the machines in use when the format was established made a noticable difference.
Just to be certain the format is clear to everyone, the layout for the example being used is (with traditional MacPascal compilers):
Byte Elements 0 47..40 1 39..32 2 31..24 3 23..16 4 15..8 5 7..0
EL is the element number which corresponds to the ord of the element in the base type the set is derived from. |SET| is the number of bytes in the set, so the byte array has an index subrange of 0..(|SET| - 1).
The byte array is always sized/allocated with an element number zero base even in the cases of a subrange base type set (e.g., set of [5..15] will be allocated the same as set of [0..15] and the bits for 0..4 won't be used).
What about negative lower bounds? I take it they're not supported in this format.
Correct. No negative lower bounds are allowed for integer subrange sets. The lower bound must be greater than or equal to zero.
Gale Paeper gpaeper@empirenet.com