Skip to content

Commit 5edc59f

Browse files
authored
Merge pull request #6337 from jepler/property-storage
Optimize flash storage of properties
2 parents 30904a8 + 510890b commit 5edc59f

File tree

93 files changed

+671
-1505
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

93 files changed

+671
-1505
lines changed

extmod/vfs_fat.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -440,7 +440,7 @@ STATIC const mp_obj_property_t fat_vfs_label_obj = {
440440
.base.type = &mp_type_property,
441441
.proxy = {(mp_obj_t)&fat_vfs_getlabel_obj,
442442
(mp_obj_t)&fat_vfs_setlabel_obj,
443-
(mp_obj_t)MP_ROM_NONE},
443+
MP_ROM_NONE},
444444
};
445445
#endif
446446

ports/atmel-samd/bindings/samd/Clock.c

Lines changed: 9 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -53,12 +53,8 @@ STATIC mp_obj_t samd_clock_get_enabled(mp_obj_t self_in) {
5353

5454
MP_DEFINE_CONST_FUN_OBJ_1(samd_clock_get_enabled_obj, samd_clock_get_enabled);
5555

56-
const mp_obj_property_t samd_clock_enabled_obj = {
57-
.base.type = &mp_type_property,
58-
.proxy = {(mp_obj_t)&samd_clock_get_enabled_obj,
59-
MP_ROM_NONE,
60-
MP_ROM_NONE,},
61-
};
56+
MP_PROPERTY_GETTER(samd_clock_enabled_obj,
57+
(mp_obj_t)&samd_clock_get_enabled_obj);
6258

6359
//| parent: Union[Clock, None]
6460
//| """Clock parent. (read-only)"""
@@ -82,12 +78,8 @@ STATIC mp_obj_t samd_clock_get_parent(mp_obj_t self_in) {
8278

8379
MP_DEFINE_CONST_FUN_OBJ_1(samd_clock_get_parent_obj, samd_clock_get_parent);
8480

85-
const mp_obj_property_t samd_clock_parent_obj = {
86-
.base.type = &mp_type_property,
87-
.proxy = {(mp_obj_t)&samd_clock_get_parent_obj,
88-
MP_ROM_NONE,
89-
MP_ROM_NONE,},
90-
};
81+
MP_PROPERTY_GETTER(samd_clock_parent_obj,
82+
(mp_obj_t)&samd_clock_get_parent_obj);
9183

9284
//| frequency: int
9385
//| """Clock frequency in Herz. (read-only)"""
@@ -99,12 +91,8 @@ STATIC mp_obj_t samd_clock_get_frequency(mp_obj_t self_in) {
9991

10092
MP_DEFINE_CONST_FUN_OBJ_1(samd_clock_get_frequency_obj, samd_clock_get_frequency);
10193

102-
const mp_obj_property_t samd_clock_frequency_obj = {
103-
.base.type = &mp_type_property,
104-
.proxy = {(mp_obj_t)&samd_clock_get_frequency_obj,
105-
MP_ROM_NONE,
106-
MP_ROM_NONE,},
107-
};
94+
MP_PROPERTY_GETTER(samd_clock_frequency_obj,
95+
(mp_obj_t)&samd_clock_get_frequency_obj);
10896

10997
//| calibration: int
11098
//| """Clock calibration. Not all clocks can be calibrated."""
@@ -130,12 +118,9 @@ STATIC mp_obj_t samd_clock_set_calibration(mp_obj_t self_in, mp_obj_t calibratio
130118

131119
MP_DEFINE_CONST_FUN_OBJ_2(samd_clock_set_calibration_obj, samd_clock_set_calibration);
132120

133-
const mp_obj_property_t samd_clock_calibration_obj = {
134-
.base.type = &mp_type_property,
135-
.proxy = {(mp_obj_t)&samd_clock_get_calibration_obj,
136-
(mp_obj_t)&samd_clock_set_calibration_obj,
137-
MP_ROM_NONE,},
138-
};
121+
MP_PROPERTY_GETSET(samd_clock_calibration_obj,
122+
(mp_obj_t)&samd_clock_get_calibration_obj,
123+
(mp_obj_t)&samd_clock_set_calibration_obj);
139124

140125
STATIC const mp_rom_map_elem_t samd_clock_locals_dict_table[] = {
141126
{ MP_ROM_QSTR(MP_QSTR_enabled), MP_ROM_PTR(&samd_clock_enabled_obj) },

ports/atmel-samd/boards/common.template.ld

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,13 @@ SECTIONS
2828
_sfixed = .;
2929
KEEP(*(.vectors)) /* isr vector table */
3030

31+
__property_getter_start = .;
32+
*(.property_getter)
33+
__property_getter_end = .;
34+
__property_getset_start = .;
35+
*(.property_getset)
36+
__property_getset_end = .;
37+
3138
/* Sort text sections so that they have fewer *fill* bytes needed. */
3239
*(SORT_BY_ALIGNMENT(SORT_BY_NAME(.text))) /* .text sections (code) */
3340
*(SORT_BY_ALIGNMENT(SORT_BY_NAME(.text*))) /* .text* sections (code) */

ports/atmel-samd/mpconfigport.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ INTERNAL_LIBM = 1
88
USB_NUM_ENDPOINT_PAIRS = 8
99

1010
CIRCUITPY_ROTARYIO_SOFTENCODER = 1
11+
CIRCUITPY_OPTIMIZE_PROPERTY_FLASH_SIZE ?= 1
1112

1213
######################################################################
1314
# Put samd21-only choices here.

ports/broadcom/bindings/videocore/Framebuffer.c

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -96,12 +96,8 @@ STATIC mp_obj_t videocore_framebuffer_get_width(mp_obj_t self_in) {
9696
return MP_OBJ_NEW_SMALL_INT(common_hal_videocore_framebuffer_get_width(self));
9797
}
9898
MP_DEFINE_CONST_FUN_OBJ_1(videocore_framebuffer_get_width_obj, videocore_framebuffer_get_width);
99-
const mp_obj_property_t videocore_framebuffer_width_obj = {
100-
.base.type = &mp_type_property,
101-
.proxy = {(mp_obj_t)&videocore_framebuffer_get_width_obj,
102-
MP_ROM_NONE,
103-
MP_ROM_NONE},
104-
};
99+
MP_PROPERTY_GETTER(videocore_framebuffer_width_obj,
100+
(mp_obj_t)&videocore_framebuffer_get_width_obj);
105101

106102
//| height: int
107103
//| """The height of the display, in pixels"""
@@ -113,12 +109,8 @@ STATIC mp_obj_t videocore_framebuffer_get_height(mp_obj_t self_in) {
113109
}
114110
MP_DEFINE_CONST_FUN_OBJ_1(videocore_framebuffer_get_height_obj, videocore_framebuffer_get_height);
115111

116-
const mp_obj_property_t videocore_framebuffer_height_obj = {
117-
.base.type = &mp_type_property,
118-
.proxy = {(mp_obj_t)&videocore_framebuffer_get_height_obj,
119-
MP_ROM_NONE,
120-
MP_ROM_NONE},
121-
};
112+
MP_PROPERTY_GETTER(videocore_framebuffer_height_obj,
113+
(mp_obj_t)&videocore_framebuffer_get_height_obj);
122114

123115
STATIC const mp_rom_map_elem_t videocore_framebuffer_locals_dict_table[] = {
124116
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&videocore_framebuffer_deinit_obj) },

ports/raspberrypi/bindings/rp2pio/StateMachine.c

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -729,12 +729,9 @@ STATIC mp_obj_t rp2pio_statemachine_obj_set_frequency(mp_obj_t self_in, mp_obj_t
729729
}
730730
MP_DEFINE_CONST_FUN_OBJ_2(rp2pio_statemachine_set_frequency_obj, rp2pio_statemachine_obj_set_frequency);
731731

732-
const mp_obj_property_t rp2pio_statemachine_frequency_obj = {
733-
.base.type = &mp_type_property,
734-
.proxy = {(mp_obj_t)&rp2pio_statemachine_get_frequency_obj,
735-
(mp_obj_t)&rp2pio_statemachine_set_frequency_obj,
736-
MP_ROM_NONE},
737-
};
732+
MP_PROPERTY_GETSET(rp2pio_statemachine_frequency_obj,
733+
(mp_obj_t)&rp2pio_statemachine_get_frequency_obj,
734+
(mp_obj_t)&rp2pio_statemachine_set_frequency_obj);
738735

739736
//| rxstall: bool
740737
//| """True when the state machine has stalled due to a full RX FIFO since the last
@@ -748,12 +745,8 @@ STATIC mp_obj_t rp2pio_statemachine_obj_get_rxstall(mp_obj_t self_in) {
748745
}
749746
MP_DEFINE_CONST_FUN_OBJ_1(rp2pio_statemachine_get_rxstall_obj, rp2pio_statemachine_obj_get_rxstall);
750747

751-
const mp_obj_property_t rp2pio_statemachine_rxstall_obj = {
752-
.base.type = &mp_type_property,
753-
.proxy = {(mp_obj_t)&rp2pio_statemachine_get_rxstall_obj,
754-
MP_ROM_NONE,
755-
MP_ROM_NONE},
756-
};
748+
MP_PROPERTY_GETTER(rp2pio_statemachine_rxstall_obj,
749+
(mp_obj_t)&rp2pio_statemachine_get_rxstall_obj);
757750

758751
//| in_waiting: int
759752
//| """The number of words available to readinto"""
@@ -766,12 +759,8 @@ STATIC mp_obj_t rp2pio_statemachine_obj_get_in_waiting(mp_obj_t self_in) {
766759
}
767760
MP_DEFINE_CONST_FUN_OBJ_1(rp2pio_statemachine_get_in_waiting_obj, rp2pio_statemachine_obj_get_in_waiting);
768761

769-
const mp_obj_property_t rp2pio_statemachine_in_waiting_obj = {
770-
.base.type = &mp_type_property,
771-
.proxy = {(mp_obj_t)&rp2pio_statemachine_get_in_waiting_obj,
772-
MP_ROM_NONE,
773-
MP_ROM_NONE},
774-
};
762+
MP_PROPERTY_GETTER(rp2pio_statemachine_in_waiting_obj,
763+
(mp_obj_t)&rp2pio_statemachine_get_in_waiting_obj);
775764

776765
STATIC const mp_rom_map_elem_t rp2pio_statemachine_locals_dict_table[] = {
777766
{ MP_ROM_QSTR(MP_QSTR_deinit), MP_ROM_PTR(&rp2pio_statemachine_deinit_obj) },

ports/raspberrypi/link.ld

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,14 @@ SECTIONS
6868
/* bit of a hack right now to exclude all floating point and time critical (e.g. memset, memcpy) code from
6969
* FLASH ... we will include any thing excluded here in .data below by default */
7070
*(.init)
71+
72+
__property_getter_start = .;
73+
*(.property_getter)
74+
__property_getter_end = .;
75+
__property_getset_start = .;
76+
*(.property_getset)
77+
__property_getset_end = .;
78+
7179
*(EXCLUDE_FILE(*libgcc.a: *libc.a:*lib_a-mem*.o *libm.a:) .text*)
7280
*(.fini)
7381
/* Pull all c'tors into .text */

ports/raspberrypi/mpconfigport.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
# All raspberrypi ports have longints.
22
LONGINT_IMPL = MPZ
33

4+
CIRCUITPY_OPTIMIZE_PROPERTY_FLASH_SIZE ?= 1
45
CIRCUITPY_ALARM ?= 1
56

67
CIRCUITPY_RP2PIO ?= 1

py/circuitpy_mpconfig.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -573,4 +573,6 @@ void supervisor_run_background_tasks_if_tick(void);
573573
#define MICROPY_WRAP_MP_EXECUTE_BYTECODE PLACE_IN_ITCM
574574
#endif
575575

576+
#define MICROPY_PY_OPTIMIZE_PROPERTY_FLASH_SIZE (CIRCUITPY_OPTIMIZE_PROPERTY_FLASH_SIZE)
577+
576578
#endif // __INCLUDED_MPCONFIG_CIRCUITPY_H

py/circuitpy_mpconfig.mk

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,11 @@
3232
CIRCUITPY_FULL_BUILD ?= 1
3333
CFLAGS += -DCIRCUITPY_FULL_BUILD=$(CIRCUITPY_FULL_BUILD)
3434

35+
# Reduce the size of in-flash properties. Requires support in the .ld linker
36+
# file, so not enabled by default.
37+
CIRCUITPY_OPTIMIZE_PROPERTY_FLASH_SIZE ?= 0
38+
CFLAGS += -DCIRCUITPY_OPTIMIZE_PROPERTY_FLASH_SIZE=$(CIRCUITPY_OPTIMIZE_PROPERTY_FLASH_SIZE)
39+
3540
# async/await language keyword support
3641
MICROPY_PY_ASYNC_AWAIT ?= $(CIRCUITPY_FULL_BUILD)
3742
CFLAGS += -DMICROPY_PY_ASYNC_AWAIT=$(MICROPY_PY_ASYNC_AWAIT)

0 commit comments

Comments
 (0)