mirror of
https://github.com/TomHarte/CLK.git
synced 2026-04-20 10:17:05 +00:00
Use std::popcount further.
This commit is contained in:
@@ -9,6 +9,7 @@
|
||||
#include "StaticAnalyser.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <bit>
|
||||
#include <cstddef>
|
||||
#include <cstdlib>
|
||||
#include <cstring>
|
||||
@@ -340,13 +341,7 @@ TargetList Analyser::Static::GetTargets(const std::string &file_name) {
|
||||
TargetPlatform::IntType potential_platforms = 0;
|
||||
Media media = GetMediaAndPlatforms(file_name, potential_platforms);
|
||||
|
||||
// TODO: std::popcount here.
|
||||
int total_options = 0;
|
||||
TargetPlatform::IntType mask = 1;
|
||||
while(mask) {
|
||||
total_options += bool(potential_platforms & mask);
|
||||
mask <<= 1;
|
||||
}
|
||||
int total_options = std::popcount(potential_platforms);
|
||||
const bool is_confident = total_options == 1;
|
||||
// i.e. This analyser `is_confident` if file analysis suggested only one potential target platform.
|
||||
// The machine-specific static analyser will still run in case it can provide meaningful annotations on
|
||||
|
||||
@@ -8,6 +8,7 @@
|
||||
|
||||
#include "DiskII.hpp"
|
||||
|
||||
#include <bit>
|
||||
#include <cstdio>
|
||||
#include <cstring>
|
||||
|
||||
@@ -62,11 +63,7 @@ void DiskII::set_control(const Control control, const bool on) {
|
||||
if(stepper_mask_&4) direction += (((stepper_position_ - 4) + 4)&7) - 4;
|
||||
if(stepper_mask_&8) direction += (((stepper_position_ - 6) + 4)&7) - 4;
|
||||
|
||||
// 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);
|
||||
|
||||
const int bits_set = std::popcount(uint8_t(stepper_mask_));
|
||||
direction /= bits_set;
|
||||
|
||||
// Compare to the stepper position to decide whether that pulls in the current cog notch,
|
||||
|
||||
Reference in New Issue
Block a user