Skip to content

Commit 007f127

Browse files
jeplerdpgeorge
authored andcommitted
all: Simplify mp_int_t/mp_uint_t definition.
Assuming proper C99 language support, we can select "the int type as big as a pointer" (most of the time) or "the 64-bit int type" (nanboxing with REPR_D), and then define everything else automatically. This simplifies port configuration files. And the types can still be overridden if needed. Signed-off-by: Jeff Epler <[email protected]>
1 parent eac81de commit 007f127

File tree

40 files changed

+106
-188
lines changed

40 files changed

+106
-188
lines changed

docs/develop/porting.rst

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -161,8 +161,6 @@ The following is an example of an ``mpconfigport.h`` file:
161161
162162
// Type definitions for the specific machine.
163163
164-
typedef intptr_t mp_int_t; // must be pointer size
165-
typedef uintptr_t mp_uint_t; // must be pointer size
166164
typedef long mp_off_t;
167165
168166
// We need to provide a declaration/definition of alloca().

mpy-cross/mpconfigport.h

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -98,23 +98,6 @@
9898

9999
// type definitions for the specific machine
100100

101-
#ifdef __LP64__
102-
typedef long mp_int_t; // must be pointer size
103-
typedef unsigned long mp_uint_t; // must be pointer size
104-
#elif defined(__MINGW32__) && defined(_WIN64)
105-
#include <stdint.h>
106-
typedef __int64 mp_int_t;
107-
typedef unsigned __int64 mp_uint_t;
108-
#elif defined(_MSC_VER) && defined(_WIN64)
109-
typedef __int64 mp_int_t;
110-
typedef unsigned __int64 mp_uint_t;
111-
#else
112-
// These are definitions for machines where sizeof(int) == sizeof(void*),
113-
// regardless for actual size.
114-
typedef int mp_int_t; // must be pointer size
115-
typedef unsigned int mp_uint_t; // must be pointer size
116-
#endif
117-
118101
// Cannot include <sys/types.h>, as it may lead to symbol name clashes
119102
#if _FILE_OFFSET_BITS == 64 && !defined(__LP64__)
120103
typedef long long mp_off_t;

ports/alif/boards/OPENMV_AE3/mpconfigboard.h

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,6 @@
22
#define MICROPY_HW_MCU_NAME "AE302F80F55D5AE"
33

44
#define MICROPY_OBJ_REPR (MICROPY_OBJ_REPR_C)
5-
typedef intptr_t mp_int_t; // must be pointer size
6-
typedef uintptr_t mp_uint_t; // must be pointer size
7-
typedef intptr_t mp_off_t;
85

96
#define MICROPY_HW_USB_MSC (CORE_M55_HP)
107
#define MICROPY_HW_ENABLE_HW_I2C (1)

ports/alif/mpconfigport.h

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -191,12 +191,7 @@
191191

192192
#define MP_SSIZE_MAX (0x7fffffff)
193193

194-
// Assume that if we already defined the obj repr then we also defined these items
195-
#ifndef MICROPY_OBJ_REPR
196-
typedef intptr_t mp_int_t; // must be pointer size
197-
typedef uintptr_t mp_uint_t; // must be pointer size
198194
typedef intptr_t mp_off_t;
199-
#endif
200195

201196
// Board configuration settings.
202197

ports/bare-arm/mpconfigport.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,6 @@
4242

4343
// Type definitions for the specific machine
4444

45-
typedef int32_t mp_int_t; // must be pointer size
46-
typedef uint32_t mp_uint_t; // must be pointer size
4745
typedef long mp_off_t;
4846

4947
// Need to provide a declaration/definition of alloca()

ports/cc3200/mpconfigport.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -130,8 +130,6 @@
130130
#define MICROPY_MAKE_POINTER_CALLABLE(p) ((void *)((mp_uint_t)(p) | 1))
131131
#define MP_SSIZE_MAX (0x7FFFFFFF)
132132

133-
typedef int32_t mp_int_t; // must be pointer size
134-
typedef unsigned int mp_uint_t; // must be pointer size
135133
typedef long mp_off_t;
136134

137135
#define MICROPY_EVENT_POLL_HOOK __WFI();

ports/embed/port/mpconfigport_common.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,6 @@
2828

2929
// Type definitions for the specific machine
3030

31-
typedef intptr_t mp_int_t; // must be pointer size
32-
typedef uintptr_t mp_uint_t; // must be pointer size
3331
typedef long mp_off_t;
3432

3533
// Need to provide a declaration/definition of alloca()

ports/esp32/mpconfigport.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -337,8 +337,6 @@ void *esp_native_code_commit(void *, size_t, void *);
337337
#define MICROPY_WRAP_MP_SCHED_EXCEPTION(f) IRAM_ATTR f
338338
#define MICROPY_WRAP_MP_SCHED_KEYBOARD_INTERRUPT(f) IRAM_ATTR f
339339

340-
typedef int32_t mp_int_t; // must be pointer size
341-
typedef uint32_t mp_uint_t; // must be pointer size
342340
typedef long mp_off_t;
343341
// ssize_t, off_t as required by POSIX-signatured functions in stream.h
344342
#include <sys/types.h>

ports/esp32/mphalport.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -184,15 +184,15 @@ mp_uint_t mp_hal_stdout_tx_strn(const char *str, size_t len) {
184184
return did_write ? ret : 0;
185185
}
186186

187-
uint32_t mp_hal_ticks_ms(void) {
187+
mp_uint_t mp_hal_ticks_ms(void) {
188188
return esp_timer_get_time() / 1000;
189189
}
190190

191-
uint32_t mp_hal_ticks_us(void) {
191+
mp_uint_t mp_hal_ticks_us(void) {
192192
return esp_timer_get_time();
193193
}
194194

195-
void mp_hal_delay_ms(uint32_t ms) {
195+
void mp_hal_delay_ms(mp_uint_t ms) {
196196
uint64_t us = (uint64_t)ms * 1000ULL;
197197
uint64_t dt;
198198
uint64_t t0 = esp_timer_get_time();
@@ -220,7 +220,7 @@ void mp_hal_delay_ms(uint32_t ms) {
220220
}
221221
}
222222

223-
void mp_hal_delay_us(uint32_t us) {
223+
void mp_hal_delay_us(mp_uint_t us) {
224224
// these constants are tested for a 240MHz clock
225225
const uint32_t this_overhead = 5;
226226
const uint32_t pend_overhead = 150;

ports/esp32/mphalport.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,18 +82,18 @@ static inline void mp_end_atomic_section(mp_uint_t state) {
8282
#define MICROPY_BEGIN_ATOMIC_SECTION() mp_begin_atomic_section()
8383
#define MICROPY_END_ATOMIC_SECTION(state) mp_end_atomic_section(state)
8484

85-
uint32_t mp_hal_ticks_us(void);
86-
__attribute__((always_inline)) static inline uint32_t mp_hal_ticks_cpu(void) {
85+
mp_uint_t mp_hal_ticks_us(void);
86+
__attribute__((always_inline)) static inline mp_uint_t mp_hal_ticks_cpu(void) {
8787
uint32_t ccount;
8888
#if CONFIG_IDF_TARGET_ARCH_RISCV
8989
__asm__ __volatile__ ("csrr %0, 0x7E2" : "=r" (ccount)); // Machine Performance Counter Value
9090
#else
9191
__asm__ __volatile__ ("rsr %0,ccount" : "=a" (ccount));
9292
#endif
93-
return ccount;
93+
return (mp_uint_t)ccount;
9494
}
9595

96-
void mp_hal_delay_us(uint32_t);
96+
void mp_hal_delay_us(mp_uint_t);
9797
#define mp_hal_delay_us_fast(us) esp_rom_delay_us(us)
9898
void mp_hal_set_interrupt_char(int c);
9999
uint32_t mp_hal_get_cpu_freq(void);

0 commit comments

Comments
 (0)