From 7b343b25cc70be4eaddba6d0257afe8e412a6e22 Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Tue, 26 Dec 2023 14:13:01 -0500 Subject: [PATCH 1/3] Mildly reduce bit count weight; eliminate !!s. --- Components/DiskII/DiskII.cpp | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/Components/DiskII/DiskII.cpp b/Components/DiskII/DiskII.cpp index d08636035..19d3febe7 100644 --- a/Components/DiskII/DiskII.cpp +++ b/Components/DiskII/DiskII.cpp @@ -61,7 +61,12 @@ void DiskII::set_control(Control control, bool on) { if(stepper_mask_&2) direction += (((stepper_position_ - 2) + 4)&7) - 4; if(stepper_mask_&4) direction += (((stepper_position_ - 4) + 4)&7) - 4; if(stepper_mask_&8) direction += (((stepper_position_ - 6) + 4)&7) - 4; - const int bits_set = (stepper_mask_&1) + ((stepper_mask_ >> 1)&1) + ((stepper_mask_ >> 2)&1) + ((stepper_mask_ >> 3)&1); + + // TODO: when adopting C++20, replace with std::popcount. + int bits_set = stepper_mask_; + bits_set = (bits_set & 0x5) + ((bits_set >> 1) & 0x5); + bits_set = (bits_set & 0x3) + ((bits_set >> 2) & 0x3); + direction /= bits_set; // Compare to the stepper position to decide whether that pulls in the current cog notch, @@ -126,7 +131,7 @@ void DiskII::run_for(const Cycles cycles) { if(inputs_&input_mode) { // state_ & 0x80 should be the current level sent to the disk; // therefore transitions in that bit should become flux transitions - drives_[active_drive_].write_bit(!!((state_ ^ address) & 0x80)); + drives_[active_drive_].write_bit((state_ ^ address) & 0x80); } // TODO: surely there's a less heavyweight solution than inline updates? @@ -179,7 +184,7 @@ void DiskII::decide_clocking_preference() { } bool DiskII::is_write_protected() { - return !!(stepper_mask_ & 2) | drives_[active_drive_].get_is_read_only(); + return (stepper_mask_ & 2) || drives_[active_drive_].get_is_read_only(); } void DiskII::set_state_machine(const std::vector &state_machine) { From f83c3e7af06fd356b1aa9ef7c43ef14adfc9629a Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Wed, 27 Dec 2023 10:00:01 -0500 Subject: [PATCH 2/3] Name repeated constant. (... and, I think, four is enough) --- Storage/Disk/DiskImage/Formats/NIB.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Storage/Disk/DiskImage/Formats/NIB.cpp b/Storage/Disk/DiskImage/Formats/NIB.cpp index a85e395a8..eacb963e4 100644 --- a/Storage/Disk/DiskImage/Formats/NIB.cpp +++ b/Storage/Disk/DiskImage/Formats/NIB.cpp @@ -55,6 +55,8 @@ long NIB::file_offset(Track::Address address) { } std::shared_ptr<::Storage::Disk::Track> NIB::get_track_at_position(::Storage::Disk::Track::Address address) { + static constexpr size_t MinimumSyncByteCount = 4; + // NIBs contain data for a fixed quantity of integer-position tracks underneath a single head only. // // Therefore: @@ -91,8 +93,8 @@ std::shared_ptr<::Storage::Disk::Track> NIB::get_track_at_position(::Storage::Di } // If that's at least five, regress and mark all as syncs. - if(length >= 5) { - for(int c = 0; c < 5; c++) { + if(length >= MinimumSyncByteCount) { + for(int c = 0; c < int(MinimumSyncByteCount); c++) { end = (end + track_data.size() - 1) % track_data.size(); sync_locations.insert(end); } From db4c8020030dcf625b8cb5f735de42a62674dd0b Mon Sep 17 00:00:00 2001 From: Thomas Harte Date: Tue, 2 Jan 2024 09:26:47 -0500 Subject: [PATCH 3/3] Make references to constant non-specific. --- Storage/Disk/DiskImage/Formats/NIB.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/Storage/Disk/DiskImage/Formats/NIB.cpp b/Storage/Disk/DiskImage/Formats/NIB.cpp index eacb963e4..4e301bfba 100644 --- a/Storage/Disk/DiskImage/Formats/NIB.cpp +++ b/Storage/Disk/DiskImage/Formats/NIB.cpp @@ -79,9 +79,9 @@ std::shared_ptr<::Storage::Disk::Track> NIB::get_track_at_position(::Storage::Di } // NIB files leave sync bytes implicit and make no guarantees - // about overall track positioning. The attempt works by locating - // any single run of FF that is sufficiently long and marking the last - // five as including slip bits. + // about overall track positioning. This attempt to map to real + // flux locates any single run of FF that is sufficiently long + // and marks the last few as including slip bits. std::set sync_locations; for(size_t index = 0; index < track_data.size(); ++index) { // Count the number of FFs starting from here. @@ -92,7 +92,7 @@ std::shared_ptr<::Storage::Disk::Track> NIB::get_track_at_position(::Storage::Di ++length; } - // If that's at least five, regress and mark all as syncs. + // If that's long enough, regress and mark syncs. if(length >= MinimumSyncByteCount) { for(int c = 0; c < int(MinimumSyncByteCount); c++) { end = (end + track_data.size() - 1) % track_data.size();