IF p1.bit = p2.bit
THEN {
mask: CARDINAL ← zeroFirst[p1.bit];
wordCount: NAT ← (p1.bit + bits-1)/Basics.bitsPerWord + 1;
wp1: WordPtr ← LOOPHOLE[p1.word];
wp2: WordPtr ← LOOPHOLE[p2.word];
FOR i:
NAT
IN [1 .. wordCount]
DO
IF i = wordCount THEN mask ← PrincOpsUtils.BITAND[mask, lastMasks[(p1.bit + bits) MOD Basics.bitsPerWord]];
IF 0 # PrincOpsUtils.BITAND[mask, PrincOpsUtils.BITXOR[wp1^, wp2^]] THEN RETURN [FALSE];
mask ← maskAll;
wp1 ← wp1 + 1;
wp2 ← wp2 + 1;
ENDLOOP;
}
ELSE {
mask: CARDINAL ← zeroFirst[p2.bit];
wordCount2: NAT ← (p2.bit + bits-1)/Basics.bitsPerWord + 1;
wp1: WordPtr ← LOOPHOLE[p1.word];
wp2: WordPtr ← LOOPHOLE[p2.word];
residue: CARDINAL ← 0;
rightPart, leftPart: INTEGER;
SELECT
TRUE
FROM
p1.bit > p2.bit => {
rightPart ← p1.bit - p2.bit;
residue ← PrincOpsUtils.BITSHIFT[wp1^, rightPart];
wp1 ← wp1 + 1;
};
p1.bit < p2.bit => {
rightPart ← p1.bit + Basics.bitsPerWord - p2.bit;
residue ← 0;
};
ENDCASE => ERROR;
leftPart ← rightPart - Basics.bitsPerWord;
FOR i:
NAT
IN [1 .. wordCount2]
DO
w1: CARDINAL;
repacked: CARDINAL;
IF i = wordCount2
THEN {
lastBits: NAT = sigBits[(p2.bit + bits) MOD Basics.bitsPerWord];
mask ← PrincOpsUtils.BITAND[mask, oneFirst[lastBits]];
IF lastBits > -leftPart THEN w1 ← wp1^;
}
ELSE w1 ← wp1^;
repacked ← PrincOpsUtils.BITOR[residue, PrincOpsUtils.BITSHIFT[w1, leftPart]];
IF 0 # PrincOpsUtils.BITAND[mask, PrincOpsUtils.BITXOR[repacked, wp2^]] THEN RETURN [FALSE];
residue ← PrincOpsUtils.BITSHIFT[w1, rightPart];
mask ← maskAll;
wp1 ← wp1 + 1;
wp2 ← wp2 + 1;
ENDLOOP;
};