Closed dirkwhoffmann closed 1 year ago
Many functions of the Disk class such as the following one utilize the modulo operator to compute bit positions.
Disk
u8 _readBitFromHalftrack(Halftrack ht, HeadPos pos) const { assert(isValidHeadPos(ht, pos)); return (data.halftrack[ht][pos / 8] & (0x80 >> (pos % 8))) != 0; }
Although HeadPos is a signed type, pos is required to be non-negative:
HeadPos
pos
bool Disk::isValidHeadPos(Halftrack ht, HeadPos pos) const { return isHalftrackNumber(ht) && pos >= 0 && pos < length.halftrack[ht]; }
Using the modulo operator on signed types is costly, however, even if the modulus is a power of 2:
Work item: Replace the modulo operator by an AND operation in all functions that only accept a positive values as arguments.
AND
Many functions of the
Disk
class such as the following one utilize the modulo operator to compute bit positions.Although
HeadPos
is a signed type,pos
is required to be non-negative:Using the modulo operator on signed types is costly, however, even if the modulus is a power of 2:
Work item: Replace the modulo operator by an
AND
operation in all functions that only accept a positive values as arguments.