Skip to content

Commit

Permalink
⚡️ Use fast types where it helps
Browse files Browse the repository at this point in the history
  • Loading branch information
thinkyhead committed Mar 22, 2023
1 parent ca77850 commit 59a8b40
Show file tree
Hide file tree
Showing 46 changed files with 340 additions and 320 deletions.
4 changes: 2 additions & 2 deletions Marlin/src/core/macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -375,8 +375,8 @@
#define _JOIN_1(O) (O)
#define JOIN_N(N,C,V...) (DO(JOIN,C,LIST_N(N,V)))

#define LOOP_S_LE_N(VAR, S, N) for (uint8_t VAR=(S); VAR<=(N); VAR++)
#define LOOP_S_L_N(VAR, S, N) for (uint8_t VAR=(S); VAR<(N); VAR++)
#define LOOP_S_LE_N(VAR, S, N) for (uint_fast8_t VAR=(S); VAR<=uint_fast8_t(N); VAR++)
#define LOOP_S_L_N(VAR, S, N) for (uint_fast8_t VAR=(S); VAR<uint_fast8_t(N); VAR++)
#define LOOP_LE_N(VAR, N) LOOP_S_LE_N(VAR, 0, N)
#define LOOP_L_N(VAR, N) LOOP_S_L_N(VAR, 0, N)

Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/core/types.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ typedef struct AxisFlags {
// - A_AXIS, B_AXIS, and C_AXIS should be used for Steppers, corresponding to XYZ on Cartesians
// - X_HEAD, Y_HEAD, and Z_HEAD should be used for Steppers on Core kinematics
//
enum AxisEnum : uint8_t {
enum AxisEnum : uint_fast8_t {

// Linear axes may be controlled directly or indirectly
NUM_AXIS_LIST(X_AXIS, Y_AXIS, Z_AXIS, I_AXIS, J_AXIS, K_AXIS, U_AXIS, V_AXIS, W_AXIS)
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/feature/bedlevel/bedlevel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ void reset_bed_level() {
/**
* Print calibration results for plotting or manual frame adjustment.
*/
void print_2d_array(const uint8_t sx, const uint8_t sy, const uint8_t precision, const float *values) {
void print_2d_array(const uint_fast8_t sx, const uint_fast8_t sy, const uint_fast8_t precision, const float *values) {
#ifndef SCAD_MESH_OUTPUT
LOOP_L_N(x, sx) {
serial_spaces(precision + (x < 10 ? 3 : 2));
Expand All @@ -162,7 +162,7 @@ void reset_bed_level() {
}
else {
#ifdef SCAD_MESH_OUTPUT
for (uint8_t i = 3; i < precision + 3; i++)
for (uint_fast8_t i = 3; i < precision + 3; i++)
SERIAL_CHAR(' ');
SERIAL_ECHOPGM("NAN");
#else
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/feature/bedlevel/bedlevel.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,12 +73,12 @@ class TemporaryBedLevelingState {

#include <stdint.h>

typedef float (*element_2d_fn)(const uint8_t, const uint8_t);
typedef float (*element_2d_fn)(const uint_fast8_t, const uint_fast8_t);

/**
* Print calibration results for plotting or manual frame adjustment.
*/
void print_2d_array(const uint8_t sx, const uint8_t sy, const uint8_t precision, const float *values);
void print_2d_array(const uint_fast8_t sx, const uint_fast8_t sy, const uint_fast8_t precision, const float *values);

#endif

Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/feature/bedlevel/ubl/ubl_G29.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -307,7 +307,7 @@ void unified_bed_leveling::G29() {
const uint8_t p_val = parser.byteval('P');
const bool may_move = p_val == 1 || p_val == 2 || p_val == 4 || parser.seen_test('J');
#if HAS_MULTI_HOTEND
const uint8_t old_tool_index = active_extruder;
const uint_fast8_t old_tool_index = active_extruder;
#endif

// Check for commands that require the printer to be homed
Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/feature/mmu/mmu2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -477,7 +477,7 @@ static void mmu2_not_responding() {
/**
* Handle tool change
*/
void MMU2::tool_change(const uint8_t index) {
void MMU2::tool_change(const uint_fast8_t index) {

if (!_enabled) return;

Expand Down Expand Up @@ -559,7 +559,7 @@ static void mmu2_not_responding() {
/**
* Handle tool change
*/
void MMU2::tool_change(const uint8_t index) {
void MMU2::tool_change(const uint_fast8_t index) {
if (!_enabled) return;

set_runout_valid(false);
Expand Down Expand Up @@ -684,7 +684,7 @@ static void mmu2_not_responding() {
/**
* Handle tool change
*/
void MMU2::tool_change(const uint8_t index) {
void MMU2::tool_change(const uint_fast8_t index) {
if (!_enabled) return;

set_runout_valid(false);
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/feature/mmu/mmu2.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ class MMU2 {
static void reset();
static bool enabled() { return _enabled; }
static void mmu_loop();
static void tool_change(const uint8_t index);
static void tool_change(const uint_fast8_t index);
static void tool_change(const char *special);
static uint8_t get_current_tool();
static void set_filament_type(const uint8_t index, const uint8_t type);
Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/feature/pause.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ bool load_filament(const_float_t slow_load_length/*=0*/, const_float_t fast_load
if (show_lcd) ui.pause_show_message(PAUSE_MESSAGE_LOAD, mode);

#if ENABLED(DUAL_X_CARRIAGE)
const int8_t saved_ext = active_extruder;
const int_fast8_t saved_ext = active_extruder;
const bool saved_ext_dup_mode = extruder_duplication_enabled;
set_duplication_enabled(false, DXC_ext);
#endif
Expand Down Expand Up @@ -468,7 +468,7 @@ bool pause_print(const_float_t retract, const xyz_pos_t &park_point, const bool
TERN_(DWIN_LCD_PROUI, if (!do_park) ui.set_status(GET_TEXT_F(MSG_PARK_FAILED)));

#if ENABLED(DUAL_X_CARRIAGE)
const int8_t saved_ext = active_extruder;
const int_fast8_t saved_ext = active_extruder;
const bool saved_ext_dup_mode = extruder_duplication_enabled;
set_duplication_enabled(false, DXC_ext);
#endif
Expand Down Expand Up @@ -523,7 +523,7 @@ void wait_for_confirmation(const bool is_reload/*=false*/, const int8_t max_beep
HOTEND_LOOP() thermalManager.heater_idle[e].start(nozzle_timeout);

#if ENABLED(DUAL_X_CARRIAGE)
const int8_t saved_ext = active_extruder;
const int_fast8_t saved_ext = active_extruder;
const bool saved_ext_dup_mode = extruder_duplication_enabled;
set_duplication_enabled(false, DXC_ext);
#endif
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/feature/powerloss.h
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ typedef struct {
xyz_pos_t position_shift;
#endif
#if HAS_MULTI_EXTRUDER
uint8_t active_extruder;
uint_fast8_t active_extruder;
#endif

#if DISABLED(NO_VOLUMETRICS)
Expand All @@ -85,7 +85,7 @@ typedef struct {
celsius_t target_temperature_bed;
#endif
#if HAS_FAN
uint8_t fan_speed[FAN_COUNT];
uint_fast8_t fan_speed[FAN_COUNT];
#endif

#if HAS_LEVELING
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/feature/runout.h
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,11 @@ class TFilamentMonitor : public FilamentMonitorBase {
}
#else
const bool ran_out = TEST(runout_flags, active_extruder); // suppress non active extruders
uint8_t extruder = active_extruder;
uint_fast8_t extruder = active_extruder;
#endif
#else
const bool ran_out = !!runout_flags;
uint8_t extruder = active_extruder;
uint_fast8_t extruder = active_extruder;
#endif

#if ENABLED(FILAMENT_RUNOUT_SENSOR_DEBUG)
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/gcode/bedlevel/G35.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void GcodeSuite::G35() {

// Always home with tool 0 active
#if HAS_MULTI_HOTEND
const uint8_t old_tool_index = active_extruder;
const uint_fast8_t old_tool_index = active_extruder;
tool_change(0, true);
#endif

Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/gcode/calibrate/G28.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -341,7 +341,7 @@ void GcodeSuite::G28() {
// Always home with tool 0 active
#if HAS_MULTI_HOTEND
#if DISABLED(DELTA) || ENABLED(DELTA_HOME_TO_SAFE_ZONE)
const uint8_t old_tool_index = active_extruder;
const uint_fast8_t old_tool_index = active_extruder;
#endif
// PARKING_EXTRUDER homing requires different handling of movement / solenoid activation, depending on the side of homing
#if ENABLED(PARKING_EXTRUDER)
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/gcode/calibrate/G33.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@ enum CalEnum : char { // the 7 main calibration points -
#define LOOP_CAL_ACT(VAR, _4P, _OP) LOOP_CAL_PT(VAR, _OP ? _AB : __A, _4P ? _4P_STEP : _7P_STEP)

#if HAS_MULTI_HOTEND
const uint8_t old_tool_index = active_extruder;
const uint_fast8_t old_tool_index = active_extruder;
#endif

float lcd_probe_pt(const xy_pos_t &xy);
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/gcode/calibrate/G34_M422.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,7 +144,7 @@ void GcodeSuite::G34() {

// Always home with tool 0 active
#if HAS_MULTI_HOTEND
const uint8_t old_tool_index = active_extruder;
const uint_fast8_t old_tool_index = active_extruder;
tool_change(0, true);
#endif

Expand Down
6 changes: 3 additions & 3 deletions Marlin/src/gcode/config/M200-M205.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
if (!parser.seen("DST" TERN_(VOLUMETRIC_EXTRUDER_LIMIT, "L")))
return M200_report();

const int8_t target_extruder = get_target_extruder_from_command();
const int_fast8_t target_extruder = get_target_extruder_from_command();
if (target_extruder < 0) return;

bool vol_enable = parser.volumetric_enabled,
Expand Down Expand Up @@ -125,7 +125,7 @@ void GcodeSuite::M201() {
if (!parser.seen("T" STR_AXES_LOGICAL TERN_(XY_FREQUENCY_LIMIT, "FS")))
return M201_report();

const int8_t target_extruder = get_target_extruder_from_command();
const int_fast8_t target_extruder = get_target_extruder_from_command();
if (target_extruder < 0) return;

#ifdef XY_FREQUENCY_LIMIT
Expand Down Expand Up @@ -179,7 +179,7 @@ void GcodeSuite::M203() {
if (!parser.seen("T" STR_AXES_LOGICAL))
return M203_report();

const int8_t target_extruder = get_target_extruder_from_command();
const int_fast8_t target_extruder = get_target_extruder_from_command();
if (target_extruder < 0) return;

LOOP_LOGICAL_AXES(i)
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/gcode/config/M217.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ void GcodeSuite::M217() {
if (parser.seen('T')) { // Migrate now
if (parser.has_value()) {
const int16_t tval = parser.value_int();
if (WITHIN(tval, 0, EXTRUDERS - 1) && tval != active_extruder) {
if (WITHIN(tval, 0, EXTRUDERS - 1) && tval != signed(active_extruder)) {
migration.target = tval + 1;
extruder_migration();
migration.target = 0; // disable
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/gcode/config/M218.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ void GcodeSuite::M218() {

if (!parser.seen_any()) return M218_report();

const int8_t target_extruder = get_target_extruder_from_command();
const int_fast8_t target_extruder = get_target_extruder_from_command();
if (target_extruder < 0) return;

if (parser.seenval('X')) hotend_offset[target_extruder].x = parser.value_linear_units();
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/gcode/config/M221.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
*/
void GcodeSuite::M221() {

const int8_t target_extruder = get_target_extruder_from_command();
const int_fast8_t target_extruder = get_target_extruder_from_command();
if (target_extruder < 0) return;

if (parser.seenval('S'))
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/gcode/config/M92.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@
*/
void GcodeSuite::M92() {

const int8_t target_extruder = get_target_extruder_from_command();
const int_fast8_t target_extruder = get_target_extruder_from_command();
if (target_extruder < 0) return;

// No arguments? Show M92 report.
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/gcode/control/T.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
* Tx Same as T?, but nozzle doesn't have to be preheated. Tc requires a preheated nozzle to finish filament load.
* Tc Load to nozzle after filament was prepared by Tc and nozzle is already heated.
*/
void GcodeSuite::T(const int8_t tool_index) {
void GcodeSuite::T(const int_fast8_t tool_index) {

DEBUG_SECTION(log_T, "T", DEBUGGING(LEVELING));
if (DEBUGGING(LEVELING)) DEBUG_ECHOLNPGM("...(", tool_index, ")");
Expand Down
8 changes: 4 additions & 4 deletions Marlin/src/gcode/feature/pause/M600.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@
void GcodeSuite::M600() {

#if ENABLED(MIXING_EXTRUDER)
const int8_t eindex = get_target_e_stepper_from_command();
const int_fast8_t eindex = get_target_e_stepper_from_command();
if (eindex < 0) return;

const uint8_t old_mixing_tool = mixer.get_current_vtool();
Expand All @@ -82,9 +82,9 @@ void GcodeSuite::M600() {
MIXER_STEPPER_LOOP(i) mixer.set_collector(i, i == uint8_t(eindex) ? 1.0 : 0.0);
mixer.normalize();

const int8_t target_extruder = active_extruder;
const int_fast8_t target_extruder = active_extruder;
#else
const int8_t target_extruder = get_target_extruder_from_command();
const int_fast8_t target_extruder = get_target_extruder_from_command();
if (target_extruder < 0) return;
#endif

Expand Down Expand Up @@ -112,7 +112,7 @@ void GcodeSuite::M600() {

#if HAS_MULTI_EXTRUDER
// Change toolhead if specified
const uint8_t active_extruder_before_filament_change = active_extruder;
const uint_fast8_t active_extruder_before_filament_change = active_extruder;
if (active_extruder != target_extruder && TERN1(DUAL_X_CARRIAGE, !idex_is_duplicating()))
tool_change(target_extruder);
#endif
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/gcode/feature/pause/M603.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ void GcodeSuite::M603() {

if (!parser.seen("TUL")) return M603_report();

const int8_t target_extruder = get_target_extruder_from_command();
const int_fast8_t target_extruder = get_target_extruder_from_command();
if (target_extruder < 0) return;

// Unload length
Expand Down
16 changes: 8 additions & 8 deletions Marlin/src/gcode/feature/pause/M701_M702.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ void GcodeSuite::M701() {
if (TERN0(NO_MOTION_BEFORE_HOMING, axes_should_home())) park_point.z = 0;

#if ENABLED(MIXING_EXTRUDER)
const int8_t eindex = get_target_e_stepper_from_command();
const int_fast8_t eindex = get_target_e_stepper_from_command();
if (eindex < 0) return;

const uint8_t old_mixing_tool = mixer.get_current_vtool();
Expand All @@ -69,9 +69,9 @@ void GcodeSuite::M701() {
MIXER_STEPPER_LOOP(i) mixer.set_collector(i, i == uint8_t(eindex) ? 1.0 : 0.0);
mixer.normalize();

const int8_t target_extruder = active_extruder;
const int_fast8_t target_extruder = active_extruder;
#else
const int8_t target_extruder = get_target_extruder_from_command();
const int_fast8_t target_extruder = get_target_extruder_from_command();
if (target_extruder < 0) return;
#endif

Expand All @@ -83,7 +83,7 @@ void GcodeSuite::M701() {

#if HAS_MULTI_EXTRUDER && (HAS_PRUSA_MMU1 || !HAS_MMU)
// Change toolhead if specified
uint8_t active_extruder_before_filament_change = active_extruder;
uint_fast8_t active_extruder_before_filament_change = active_extruder;
if (active_extruder != target_extruder)
tool_change(target_extruder);
#endif
Expand Down Expand Up @@ -165,16 +165,16 @@ void GcodeSuite::M702() {
#endif

if (seenT) {
const int8_t eindex = get_target_e_stepper_from_command();
const int_fast8_t eindex = get_target_e_stepper_from_command();
if (eindex < 0) return;
mixer.T(MIXER_DIRECT_SET_TOOL);
MIXER_STEPPER_LOOP(i) mixer.set_collector(i, i == uint8_t(eindex) ? 1.0 : 0.0);
mixer.normalize();
}

const int8_t target_extruder = active_extruder;
const int_fast8_t target_extruder = active_extruder;
#else
const int8_t target_extruder = get_target_extruder_from_command();
const int_fast8_t target_extruder = get_target_extruder_from_command();
if (target_extruder < 0) return;
#endif

Expand All @@ -186,7 +186,7 @@ void GcodeSuite::M702() {

#if HAS_MULTI_EXTRUDER && (HAS_PRUSA_MMU1 || !HAS_MMU)
// Change toolhead if specified
uint8_t active_extruder_before_filament_change = active_extruder;
uint_fast8_t active_extruder_before_filament_change = active_extruder;
if (active_extruder != target_extruder)
tool_change(target_extruder);
#endif
Expand Down
2 changes: 1 addition & 1 deletion Marlin/src/gcode/feature/trinamic/M906.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,7 @@ void GcodeSuite::M906() {

#if AXIS_IS_TMC(E0) || AXIS_IS_TMC(E1) || AXIS_IS_TMC(E2) || AXIS_IS_TMC(E3) || AXIS_IS_TMC(E4) || AXIS_IS_TMC(E5) || AXIS_IS_TMC(E6) || AXIS_IS_TMC(E7)
case E_AXIS: {
const int8_t eindex = get_target_e_stepper_from_command(-2);
const int_fast8_t eindex = get_target_e_stepper_from_command(-2);
#if AXIS_IS_TMC(E0)
if (eindex < 0 || eindex == 0) TMC_SET_CURRENT(E0);
#endif
Expand Down
4 changes: 2 additions & 2 deletions Marlin/src/gcode/feature/trinamic/M911-M914.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,7 @@

#if E0_HAS_STEALTHCHOP || E1_HAS_STEALTHCHOP || E2_HAS_STEALTHCHOP || E3_HAS_STEALTHCHOP || E4_HAS_STEALTHCHOP || E5_HAS_STEALTHCHOP || E6_HAS_STEALTHCHOP || E7_HAS_STEALTHCHOP
case E_AXIS: {
const int8_t eindex = get_target_e_stepper_from_command(-2);
const int_fast8_t eindex = get_target_e_stepper_from_command(-2);
TERN_(E0_HAS_STEALTHCHOP, if (eindex < 0 || eindex == 0) TMC_SET_PWMTHRS_E(0));
TERN_(E1_HAS_STEALTHCHOP, if (eindex < 0 || eindex == 1) TMC_SET_PWMTHRS_E(1));
TERN_(E2_HAS_STEALTHCHOP, if (eindex < 0 || eindex == 2) TMC_SET_PWMTHRS_E(2));
Expand All @@ -345,7 +345,7 @@
TERN_(E6_HAS_STEALTHCHOP, if (eindex < 0 || eindex == 6) TMC_SET_PWMTHRS_E(6));
TERN_(E7_HAS_STEALTHCHOP, if (eindex < 0 || eindex == 7) TMC_SET_PWMTHRS_E(7));
} break;
#endif // E_STEPPERS
#endif // E*_HAS_STEALTHCHOP
}
}

Expand Down
Loading

0 comments on commit 59a8b40

Please sign in to comment.