Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use a structure for XYZE-oriented data #15204

Merged

Conversation

thinkyhead
Copy link
Member

@thinkyhead thinkyhead commented Sep 9, 2019

Use structures with anonymous unions to store axis-oriented arrays for easier access to fields and easier copying of positional data.

Old code:

    float raw[XYZE] = {
      current_position[X_AXIS],
      current_position[Y_AXIS],
      current_position[Z_AXIS],
      current_position[E_AXIS]
    };

New code:

    xyze_pos_t raw = current_position;

@AnHardt
Copy link
Member

AnHardt commented Sep 9, 2019

Did you check the impact on 8-bitters, with their slow (16 bit) address arithmetic?
Does it make a difference?
What version is calculated by the preprocessor or compiler? What at runtime?

@thinkyhead thinkyhead force-pushed the bf2_position_struct_pr branch 3 times, most recently from 1b2af7a to dd789fa Compare September 9, 2019 09:10
@thinkyhead
Copy link
Member Author

These changes will only affect compile-time behavior. It's not meant to produce any change in the underlying binary output, but just a change in the semantics. The main purpose is to allow myvar.x to be used wherever myvar[X_AXIS] can be used. As a bonus it also adds shorthand for assignment, copying, and comparison so that current_position = destination does what you would expect.

@thinkyhead thinkyhead force-pushed the bf2_position_struct_pr branch 6 times, most recently from 5bdedd4 to efec686 Compare September 10, 2019 07:39
Marlin/src/core/types.h Outdated Show resolved Hide resolved
@thinkyhead thinkyhead force-pushed the bf2_position_struct_pr branch 14 times, most recently from e30a626 to db477df Compare September 11, 2019 22:56
@thinkyhead thinkyhead force-pushed the bf2_position_struct_pr branch 15 times, most recently from db5a1f5 to 54d8ce3 Compare September 29, 2019 08:05
@thinkyhead thinkyhead merged commit 50e4545 into MarlinFirmware:bugfix-2.0.x Sep 29, 2019
@thinkyhead thinkyhead deleted the bf2_position_struct_pr branch September 29, 2019 09:25
rolkun pushed a commit to rolkun/Marlin that referenced this pull request Oct 25, 2019
markus-seidl pushed a commit to markus-seidl/Marlin that referenced this pull request Oct 31, 2019
robbycandra added a commit to robbycandra/Marlin that referenced this pull request Nov 16, 2019
# Conflicts:
#	Marlin/src/feature/power_loss_recovery.cpp
#	Marlin/src/gcode/bedlevel/abl/G29.cpp
#	Marlin/src/gcode/calibrate/G425.cpp
#	Marlin/src/gcode/feature/pause/M701_M702.cpp
#	Marlin/src/lcd/menu/menu_advanced.cpp
#	Marlin/src/libs/nozzle.cpp
#	Marlin/src/module/configuration_store.cpp
#	Marlin/src/module/delta.cpp
#	Marlin/src/module/motion.cpp
#	Marlin/src/module/motion.h
#	Marlin/src/module/probe.cpp
#	Marlin/src/module/probe.h
#	Marlin/src/module/scara.cpp
robbycandra added a commit to robbycandra/Marlin that referenced this pull request Nov 16, 2019
thinkyhead added a commit to drunken-octopus/drunken-octopus-marlin that referenced this pull request Apr 1, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants