Skip to content

Shrink non-FULL builds (SAMDs mostly) #10269

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

Merged
merged 2 commits into from
Apr 21, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion ports/atmel-samd/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ CFLAGS += \
-msoft-float \
-mfloat-abi=soft \
-DSAMD21
LIBS := libs/libgcc-12.1.0-Os-v6-m-nofp.a -lc
LIBS := libs/libgcc-14.2.0-Os-v6-m-nofp.a -lc
else
LIBS := -lgcc -lc
endif
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,3 +40,6 @@
// no PA29
#define IGNORE_PIN_PA30 1
#define IGNORE_PIN_PA31 1

// A couple Learn examples do `array.array('d', ...)` so enable it.
#define MICROPY_PY_DOUBLE_TYPECODE 1
Binary file removed ports/atmel-samd/libs/libgcc-12.1.0-Os-v6-m-nofp.a
Binary file not shown.
Binary file not shown.
10 changes: 10 additions & 0 deletions py/binary.c
Original file line number Diff line number Diff line change
Expand Up @@ -289,8 +289,10 @@ mp_obj_t mp_binary_get_val_array(char typecode, void *p, size_t index) {
#if MICROPY_PY_BUILTINS_FLOAT
case 'f':
return mp_obj_new_float_from_f(((float *)p)[index]);
#if MICROPY_PY_DOUBLE_TYPECODE
case 'd':
return mp_obj_new_float_from_d(((double *)p)[index]);
#endif
#endif
// CIRCUITPY-CHANGE: non-standard typecodes can be turned off
#if MICROPY_NONSTANDARD_TYPECODES
Expand Down Expand Up @@ -367,13 +369,15 @@ mp_obj_t mp_binary_get_val(char struct_type, char val_type, byte *p_base, byte *
float f;
} fpu = {val};
return mp_obj_new_float_from_f(fpu.f);
#if MICROPY_PY_DOUBLE_TYPECODE
} else if (val_type == 'd') {
union {
uint64_t i;
double f;
} fpu = {val};
return mp_obj_new_float_from_d(fpu.f);
#endif
#endif
} else if (is_signed(val_type)) {
if ((long long)MP_SMALL_INT_MIN <= val && val <= (long long)MP_SMALL_INT_MAX) {
return mp_obj_new_int((mp_int_t)val);
Expand Down Expand Up @@ -445,6 +449,7 @@ void mp_binary_set_val(char struct_type, char val_type, mp_obj_t val_in, byte *p
val = fp_sp.i;
break;
}
#if MICROPY_PY_DOUBLE_TYPECODE
case 'd': {
union {
uint64_t i64;
Expand All @@ -463,6 +468,7 @@ void mp_binary_set_val(char struct_type, char val_type, mp_obj_t val_in, byte *p
break;
}
#endif
#endif
default: {
// CIRCUITPY-CHANGE: add overflow checks
bool signed_type = is_signed(val_type);
Expand Down Expand Up @@ -501,10 +507,12 @@ void mp_binary_set_val_array(char typecode, void *p, size_t index, mp_obj_t val_
case 'f':
((float *)p)[index] = mp_obj_get_float_to_f(val_in);
break;
#if MICROPY_PY_DOUBLE_TYPECODE
case 'd':
((double *)p)[index] = mp_obj_get_float_to_d(val_in);
break;
#endif
#endif
// CIRCUITPY-CHANGE: non-standard typecodes can be turned off
#if MICROPY_NONSTANDARD_TYPECODES
// Extension to CPython: array of objects
Expand Down Expand Up @@ -574,9 +582,11 @@ void mp_binary_set_val_array_from_int(char typecode, void *p, size_t index, mp_i
case 'f':
((float *)p)[index] = (float)val;
break;
#if MICROPY_PY_DOUBLE_TYPECODE
case 'd':
((double *)p)[index] = (double)val;
break;
#endif
#endif
// CIRCUITPY-CHANGE: non-standard typecodes can be turned off
#if MICROPY_NONSTANDARD_TYPECODES
Expand Down
8 changes: 8 additions & 0 deletions py/circuitpy_mpconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,11 @@ extern void common_hal_mcu_enable_interrupts(void);
#define MICROPY_PY_UCTYPES (0)
#define MICROPY_PY___FILE__ (1)

#if CIRCUITPY_FULL_BUILD
#define MICROPY_QSTR_BYTES_IN_HASH (1)
#else
#define MICROPY_QSTR_BYTES_IN_HASH (0)
#endif
#define MICROPY_REPL_AUTO_INDENT (1)
#define MICROPY_REPL_EVENT_DRIVEN (0)
#define MICROPY_STACK_CHECK (1)
Expand Down Expand Up @@ -257,6 +261,10 @@ typedef long mp_off_t;
#define MICROPY_PY_COLLECTIONS_DEQUE_SUBSCR (CIRCUITPY_FULL_BUILD)
#endif

#ifndef MICROPY_PY_DOUBLE_TYPECODE
#define MICROPY_PY_DOUBLE_TYPECODE (CIRCUITPY_FULL_BUILD ? 1 : 0)
#endif

#ifndef MICROPY_PY_FUNCTION_ATTRS
#define MICROPY_PY_FUNCTION_ATTRS (CIRCUITPY_FULL_BUILD)
#endif
Expand Down
4 changes: 4 additions & 0 deletions py/mpconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -881,6 +881,10 @@ typedef double mp_float_t;
#define MICROPY_PY_BUILTINS_COMPLEX (MICROPY_PY_BUILTINS_FLOAT)
#endif

#ifndef MICROPY_PY_DOUBLE_TYPECODE
#define MICROPY_PY_DOUBLE_TYPECODE (MICROPY_PY_BUILTINS_FLOAT)
#endif

// Whether to use the native _Float16 for 16-bit float support
#ifndef MICROPY_FLOAT_USE_NATIVE_FLT16
#ifdef __FLT16_MAX__
Expand Down
Loading