speeduino/speeduino/table3d_typedefs.h

50 lines
1.4 KiB
C
Raw Normal View History

Reduce 3d table memory usage (>500 bytes) (#662) * Use table_row_iterator_t to adjust ignitionTable * Separate 2d & 3d table code, abstract page to table iterator conversion. This is just moving code around in preparation for future changes. * Reduce table RAM (.bss) usage Generate a separate type for each possible 3d axis & size combination. This turns what was runtime information into compile time data. * Save 1 byte per table. Use a flag value (INT16_MAX) instead of a separate boolean flag * File renaming table_iterator -> table3d_iterator.h table3d.h -> table3d_interpolate.h table3d.cpp -> table3d_interpolate.cpp table3d_types.h -> table3d.h * Optimize page.cpp: reduce code clutter, maintain performance * Reduce flash usage * Encapsulate table metadata * Performance - hoist if statement * Replace function with macro * Use a packed enum as a type identifier Use a packed enum as a type identifier Slimmer data types * Use table iterators for random access to table values and axis. * Centralize write buffer check * Encapsulate 16-bit reference concept * Performance: make table iterators proper classes This allows us to chain calls on temporaries - not possible with regular function calls. * Performance: encapsulate EEPROM update & address increment * Save flash - don't duplicate function * Performance: directly invalidate table cache * Separate out iterator reversal * Separate out entity mapping & per-byte access Much faster, smaller code footprint & easier to understand * Code quality fixes * Separate out axis metadata * Doxygen comments * Separate int16_ref into separate file * Separate out table axies & values into separate types No need for metadata types & more localised code. E.g. creating iterators is now alongside the data over which they iterate. * Doxygen
2021-11-17 16:30:29 -08:00
/**
* @addtogroup table_3d
* @{
*/
/** \file
* @brief Typedefs for primitive 3D table elements
*
* These used are for consistency across functions that work on 3D table data.
* For example:<br>
* <c>table3d_value_t foo(table3d_axis_t input);</c><br>
* instead of:<br>
* <c>uint8_t foo(int16_t input);</c>
*/
#pragma once
#include <stdint.h>
/** @brief Encodes the \b length of the axes */
2023-01-10 17:58:48 -08:00
using table3d_dim_t = uint8_t;
Reduce 3d table memory usage (>500 bytes) (#662) * Use table_row_iterator_t to adjust ignitionTable * Separate 2d & 3d table code, abstract page to table iterator conversion. This is just moving code around in preparation for future changes. * Reduce table RAM (.bss) usage Generate a separate type for each possible 3d axis & size combination. This turns what was runtime information into compile time data. * Save 1 byte per table. Use a flag value (INT16_MAX) instead of a separate boolean flag * File renaming table_iterator -> table3d_iterator.h table3d.h -> table3d_interpolate.h table3d.cpp -> table3d_interpolate.cpp table3d_types.h -> table3d.h * Optimize page.cpp: reduce code clutter, maintain performance * Reduce flash usage * Encapsulate table metadata * Performance - hoist if statement * Replace function with macro * Use a packed enum as a type identifier Use a packed enum as a type identifier Slimmer data types * Use table iterators for random access to table values and axis. * Centralize write buffer check * Encapsulate 16-bit reference concept * Performance: make table iterators proper classes This allows us to chain calls on temporaries - not possible with regular function calls. * Performance: encapsulate EEPROM update & address increment * Save flash - don't duplicate function * Performance: directly invalidate table cache * Separate out iterator reversal * Separate out entity mapping & per-byte access Much faster, smaller code footprint & easier to understand * Code quality fixes * Separate out axis metadata * Doxygen comments * Separate int16_ref into separate file * Separate out table axies & values into separate types No need for metadata types & more localised code. E.g. creating iterators is now alongside the data over which they iterate. * Doxygen
2021-11-17 16:30:29 -08:00
/** @brief The type of each table value */
2023-01-10 17:58:48 -08:00
using table3d_value_t = uint8_t;
Reduce 3d table memory usage (>500 bytes) (#662) * Use table_row_iterator_t to adjust ignitionTable * Separate 2d & 3d table code, abstract page to table iterator conversion. This is just moving code around in preparation for future changes. * Reduce table RAM (.bss) usage Generate a separate type for each possible 3d axis & size combination. This turns what was runtime information into compile time data. * Save 1 byte per table. Use a flag value (INT16_MAX) instead of a separate boolean flag * File renaming table_iterator -> table3d_iterator.h table3d.h -> table3d_interpolate.h table3d.cpp -> table3d_interpolate.cpp table3d_types.h -> table3d.h * Optimize page.cpp: reduce code clutter, maintain performance * Reduce flash usage * Encapsulate table metadata * Performance - hoist if statement * Replace function with macro * Use a packed enum as a type identifier Use a packed enum as a type identifier Slimmer data types * Use table iterators for random access to table values and axis. * Centralize write buffer check * Encapsulate 16-bit reference concept * Performance: make table iterators proper classes This allows us to chain calls on temporaries - not possible with regular function calls. * Performance: encapsulate EEPROM update & address increment * Save flash - don't duplicate function * Performance: directly invalidate table cache * Separate out iterator reversal * Separate out entity mapping & per-byte access Much faster, smaller code footprint & easier to understand * Code quality fixes * Separate out axis metadata * Doxygen comments * Separate int16_ref into separate file * Separate out table axies & values into separate types No need for metadata types & more localised code. E.g. creating iterators is now alongside the data over which they iterate. * Doxygen
2021-11-17 16:30:29 -08:00
/** @brief The type of each axis value */
2023-01-10 17:58:48 -08:00
using table3d_axis_t = int16_t;
Reduce 3d table memory usage (>500 bytes) (#662) * Use table_row_iterator_t to adjust ignitionTable * Separate 2d & 3d table code, abstract page to table iterator conversion. This is just moving code around in preparation for future changes. * Reduce table RAM (.bss) usage Generate a separate type for each possible 3d axis & size combination. This turns what was runtime information into compile time data. * Save 1 byte per table. Use a flag value (INT16_MAX) instead of a separate boolean flag * File renaming table_iterator -> table3d_iterator.h table3d.h -> table3d_interpolate.h table3d.cpp -> table3d_interpolate.cpp table3d_types.h -> table3d.h * Optimize page.cpp: reduce code clutter, maintain performance * Reduce flash usage * Encapsulate table metadata * Performance - hoist if statement * Replace function with macro * Use a packed enum as a type identifier Use a packed enum as a type identifier Slimmer data types * Use table iterators for random access to table values and axis. * Centralize write buffer check * Encapsulate 16-bit reference concept * Performance: make table iterators proper classes This allows us to chain calls on temporaries - not possible with regular function calls. * Performance: encapsulate EEPROM update & address increment * Save flash - don't duplicate function * Performance: directly invalidate table cache * Separate out iterator reversal * Separate out entity mapping & per-byte access Much faster, smaller code footprint & easier to understand * Code quality fixes * Separate out axis metadata * Doxygen comments * Separate int16_ref into separate file * Separate out table axies & values into separate types No need for metadata types & more localised code. E.g. creating iterators is now alongside the data over which they iterate. * Doxygen
2021-11-17 16:30:29 -08:00
/** @brief Core 3d table generation macro
*
* We have a fixed number of table types: they are defined by this macro.
* GENERATOR is expected to be another macros that takes at least 3 arguments:
* axis length, x-axis domain, y-axis domain
*/
#define TABLE3D_GENERATOR(GENERATOR, ...) \
GENERATOR(6, Rpm, Load, ##__VA_ARGS__) \
GENERATOR(4, Rpm, Load, ##__VA_ARGS__) \
GENERATOR(8, Rpm, Load, ##__VA_ARGS__) \
GENERATOR(8, Rpm, Tps, ##__VA_ARGS__) \
GENERATOR(16, Rpm, Load, ##__VA_ARGS__)
// Each 3d table is given a distinct type based on size & axis domains
// This encapsulates the generation of the type name
#define TABLE3D_TYPENAME_BASE(size, xDom, yDom) table3d ## size ## xDom ## yDom
#define CAT_HELPER(a, b) a ## b
#define CONCAT(A, B) CAT_HELPER(A, B)
/** @} */