8000 Make "unix" target be crossplatform and support x86, x64, ARM hosts. by pfalcon · Pull Request #10 · micropython/micropython · GitHub
[go: up one dir, main page]

Skip to content

Make "unix" target be crossplatform and support x86, x64, ARM hosts. #10

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 1 commit into from
Dec 30, 2013
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
3 changes: 2 additions & 1 deletion py/asmx64.c
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include <string.h>

#include "misc.h"
#include "mpconfig.h"
#include "asmx64.h"

/* all offsets are measured in multiples of 8 bytes */
Expand Down Expand Up @@ -602,7 +603,7 @@ void asm_x64_call_i1(asm_x64_t* as, void* func, int i1)
*/

void asm_x64_call_ind(asm_x64_t* as, void *ptr, int temp_r64) {
asm_x64_mov_i64_to_r64_optimised(as, (int64_t)ptr, temp_r64);
asm_x64_mov_i64_to_r64_optimised(as, (machine_int_t)ptr, temp_r64);
asm_x64_write_byte_2(as, OPCODE_CALL_RM32, MODRM_R64(2) | MODRM_RM_REG | MODRM_RM_R64(temp_r64));
// this reduces code size by 2 bytes per call, but doesn't seem to speed it up at all
// doesn't work anymore because calls are 64 bits away
Expand Down
10 changes: 6 additions & 4 deletions py/nlrthumb.s → py/nlrthumb.S
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
@ thumb callee save: bx, bp, sp, r12, r14, r14, r15
#ifdef __thumb2__
/* thumb callee save: bx, bp, sp, r12, r14, r14, r15 */

.syntax unified
.cpu cortex-m4
.thumb
.text
.align 2

@ uint nlr_push(r0=nlr_buf_t *nlr)
/* uint nlr_push(r0=nlr_buf_t *nlr) */
.global nlr_push
.thumb
.thumb_func
Expand Down Expand Up @@ -51,7 +52,7 @@ nlr_pop:
.word .LANCHOR0
.size nlr_pop, .-nlr_pop

@ void nlr_jump(r0=uint val)
/* void nlr_jump(r0=uint val) */
.global nlr_jump
.thumb
.thumb_func
Expand Down Expand Up @@ -81,11 +82,12 @@ nlr_jump:
.word .LANCHOR0
.size nlr_jump, .-nlr_jump

@ local variable nlr_top
/* local variable nlr_top */
.bss
.align 2
.set .LANCHOR0,. + 0
.type nlr_top, %object
.size nlr_top, 4
nlr_top:
.space 4
#endif
10 changes: 6 additions & 4 deletions py/nlrx64.s → py/nlrx64.S
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# x64 callee save: bx, bp, sp, r12, r14, r14, r15
#ifdef __x86_64__
/* x64 callee save: bx, bp, sp, r12, r14, r14, r15 */

.file "nlr.s"
.text

# uint nlr_push(rdi=nlr_buf_t *nlr)
/* uint nlr_push(rdi=nlr_buf_t *nlr) */
.globl nlr_push
.type nlr_push, @function
nlr_push:
Expand All @@ -23,7 +24,7 @@ nlr_push:
ret # return
.size nlr_push, .-nlr_push

# void nlr_pop()
/* void nlr_pop() */
.globl nlr_pop
.type nlr_pop, @function
nlr_pop:
Expand All @@ -33,7 +34,7 @@ nlr_pop:
ret # return
.size nlr_pop, .-nlr_pop

# void nlr_jump(rdi=uint val)
/* void nlr_jump(rdi=uint val) */
.globl nlr_jump
.type nlr_jump, @function
nlr_jump:
Expand All @@ -58,3 +59,4 @@ nlr_jump:

.local nlr_top
.comm nlr_top,8,8
#endif
10 changes: 6 additions & 4 deletions py/nlrx86.s → py/nlrx86.S
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
# x86 callee save: bx, di, si, bp, sp
#ifdef __i386__
/* x86 callee save: bx, di, si, bp, sp */

.file "nlr.s"
.text

# uint nlr_push(4(%esp)=nlr_buf_t *nlr)
/* uint nlr_push(4(%esp)=nlr_buf_t *nlr) */
.globl nlr_push
.type nlr_push, @function
nlr_push:
Expand All @@ -22,7 +23,7 @@ nlr_push:
ret # return
.size nlr_push, .-nlr_push

# void nlr_pop()
/* void nlr_pop() */
.globl nlr_pop
.type nlr_pop, @function
nlr_pop:
Expand All @@ -32,7 +33,7 @@ nlr_pop:
ret # return
.size nlr_pop, .-nlr_pop

# void nlr_jump(4(%esp)=uint val)
/* void nlr_jump(4(%esp)=uint val) */
.globl nlr_jump
.type nlr_jump, @function
nlr_jump:
Expand All @@ -55,3 +56,4 @@ nlr_jump:

.local nlr_top
.comm nlr_top,4,4
#endif
32 changes: 16 additions & 16 deletions py/showbc.c
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ void mp_show_byte_code(const byte *ip, int len) {

case MP_BC_LOAD_FAST_N:
DECODE_UINT;
printf("LOAD_FAST_N %lu", unum);
printf("LOAD_FAST_N " UINT_FMT, unum);
break;

case MP_BC_LOAD_NAME:
Expand Down Expand Up @@ -111,7 +111,7 @@ void mp_show_byte_code(const byte *ip, int len) {

case MP_BC_STORE_FAST_N:
DECODE_UINT;
printf("STORE_FAST_N %lu", unum);
printf("STORE_FAST_N " UINT_FMT, unum);
break;

case MP_BC_STORE_NAME:
Expand Down Expand Up @@ -161,17 +161,17 @@ void mp_show_byte_code(const byte *ip, int len) {

case MP_BC_JUMP:
DECODE_SLABEL;
printf("JUMP %lu", ip + unum - ip_start);
printf("JUMP " UINT_FMT, ip + unum - ip_start);
break;

case MP_BC_POP_JUMP_IF_TRUE:
DECODE_SLABEL;
printf("POP_JUMP_IF_TRUE %lu", ip + unum - ip_start);
printf("POP_JUMP_IF_TRUE " UINT_FMT, ip + unum - ip_start);
break;

case MP_BC_POP_JUMP_IF_FALSE:
DECODE_SLABEL;
printf("POP_JUMP_IF_FALSE %lu", ip + unum - ip_start);
printf("POP_JUMP_IF_FALSE " UINT_FMT, ip + unum - ip_start);
break;

/*
Expand All @@ -196,7 +196,7 @@ void mp_show_byte_code(const byte *ip, int len) {

case MP_BC_SETUP_EXCEPT:
DECODE_ULABEL; // except labels are always forward
printf("SETUP_EXCEPT %lu", ip + unum - ip_start);
printf("SETUP_EXCEPT " UINT_FMT, ip + unum - ip_start);
break;

case MP_BC_END_FINALLY:
Expand All @@ -213,7 +213,7 @@ void mp_show_byte_code(const byte *ip, int len) {

case MP_BC_FOR_ITER:
DECODE_ULABEL; // the jump offset if iteration finishes; for labels are always forward
printf("FOR_ITER %lu", ip + unum - ip_start);
printf("FOR_ITER " UINT_FMT, ip + unum - ip_start);
break;

case MP_BC_POP_BLOCK:
Expand All @@ -235,22 +235,22 @@ void mp_show_byte_code(const byte *ip, int len) {

case MP_BC_BINARY_OP:
unum = *ip++;
printf("BINARY_OP %lu", unum);
printf("BINARY_OP " UINT_FMT, unum);
break;

case MP_BC_COMPARE_OP:
unum = *ip++;
printf("COMPARE_OP %lu", unum);
printf("COMPARE_OP " UINT_FMT, unum);
break;

case MP_BC_BUILD_TUPLE:
DECODE_UINT;
printf("BUILD_TUPLE %lu", unum);
printf("BUILD_TUPLE " UINT_FMT, unum);
break;

case MP_BC_BUILD_LIST:
DECODE_UINT;
printf("BUILD_LIST %lu", unum);
printf("BUILD_LIST " UINT_FMT, unum);
break;

/*
Expand All @@ -264,7 +264,7 @@ void mp_show_byte_code(const byte *ip, int len) {

case MP_BC_BUILD_MAP:
DECODE_UINT;
printf("BUILD_MAP %lu", unum);
printf("BUILD_MAP " UINT_FMT, unum);
break;

/*
Expand Down Expand Up @@ -297,22 +297,22 @@ void mp_show_byte_code(const byte *ip, int len) {

case MP_BC_UNPACK_SEQUENCE:
DECODE_UINT;
printf("UNPACK_SEQUENCE %lu", unum);
printf("UNPACK_SEQUENCE " UINT_FMT, unum);
break;

case MP_BC_MAKE_FUNCTION:
DECODE_UINT;
printf("MAKE_FUNCTION %lu", unum);
printf("MAKE_FUNCTION " UINT_FMT, unum);
break;

case MP_BC_CALL_FUNCTION:
DECODE_UINT;
printf("CALL_FUNCTION n=%lu nkw=%lu", unum & 0xff, (unum >> 8) & 0xff);
printf("CALL_FUNCTION n=" UINT_FMT " nkw=" UINT_FMT, unum & 0xff, (unum >> 8) & 0xff);
break;

case MP_BC_CALL_METHOD:
DECODE_UINT;
printf("CALL_METHOD n=%lu nkw=%lu", unum & 0xff, (unum >> 8) & 0xff);
printf("CALL_METHOD n=" UINT_FMT " nkw=" UINT_FMT, unum & 0xff, (unum >> 8) & 0xff);
break;

case MP_BC_RETURN_VALUE:
Expand Down
5 changes: 5 additions & 0 deletions unix/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ SRC_C = \
main.c \

PY_O = \
nlrx86.o \
nlrx64.o \
nlrthumb.o \
malloc.o \
qstr.o \
vstr.o \
Expand Down Expand Up @@ -73,6 +75,9 @@ $(BUILD)/%.o: %.c
$(BUILD)/%.o: $(PYSRC)/%.s
$(AS) -o $@ $<

$(BUILD)/%.o: $(PYSRC)/%.S
$(CC) $(CFLAGS) -c -o $@ $<

$(BUILD)/%.o: $(PYSRC)/%.c mpconfig.h
$(CC) $(CFLAGS) -c -o $@ $<

Expand Down
18 changes: 15 additions & 3 deletions unix/mpconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,22 @@

// type definitions for the specific machine

#define BYTES_PER_WORD (8)
#ifdef __LP64__
typedef long machine_int_t; // must be pointer size
typedef unsigned long machine_uint_t; // must be pointer size
#define UINT_FMT "%lu"
#define INT_FMT "%ld"
#else
// These are definitions for machines where sizeof(int) == sizeof(void*),
// regardless for actual size.
typedef int machine_int_t; // must be pointer size
typedef unsigned int machine_uint_t; // must be pointer size
#define UINT_FMT "%u"
#define INT_FMT "%d"
#endif

#define BYTES_PER_WORD sizeof(machine_int_t)

typedef int64_t machine_int_t; // must be pointer size
typedef uint64_t machine_uint_t; // must be pointer size
typedef void *machine_ptr_t; // must be of pointer size
typedef const void *machine_const_ptr_t; // must be of pointer size
typedef double machine_float_t;
Expand Down
0