Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
micropython
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
This is an archived project. Repository and other project resources are read-only.
Show more breadcrumbs
card10
micropython
Commits
c59fc141
Commit
c59fc141
authored
7 years ago
by
Damien George
Browse files
Options
Downloads
Patches
Plain Diff
py/emitnative: Simplify binary op emitter, no need to check inplace ops.
parent
a3afa8cf
Branches
Branches containing commit
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
py/emitnative.c
+17
-16
17 additions, 16 deletions
py/emitnative.c
with
17 additions
and
16 deletions
py/emitnative.c
+
17
−
16
View file @
c59fc141
...
@@ -1825,18 +1825,20 @@ STATIC void emit_native_binary_op(emit_t *emit, mp_binary_op_t op) {
...
@@ -1825,18 +1825,20 @@ STATIC void emit_native_binary_op(emit_t *emit, mp_binary_op_t op) {
vtype_kind_t
vtype_lhs
=
peek_vtype
(
emit
,
1
);
vtype_kind_t
vtype_lhs
=
peek_vtype
(
emit
,
1
);
vtype_kind_t
vtype_rhs
=
peek_vtype
(
emit
,
0
);
vtype_kind_t
vtype_rhs
=
peek_vtype
(
emit
,
0
);
if
(
vtype_lhs
==
VTYPE_INT
&&
vtype_rhs
==
VTYPE_INT
)
{
if
(
vtype_lhs
==
VTYPE_INT
&&
vtype_rhs
==
VTYPE_INT
)
{
// for integers, inplace and normal ops are equivalent, so use just normal ops
if
(
MP_BINARY_OP_INPLACE_OR
<=
op
&&
op
<=
MP_BINARY_OP_INPLACE_POWER
)
{
op
+=
MP_BINARY_OP_OR
-
MP_BINARY_OP_INPLACE_OR
;
}
#if N_X64 || N_X86
#if N_X64 || N_X86
// special cases for x86 and shifting
// special cases for x86 and shifting
if
(
op
==
MP_BINARY_OP_LSHIFT
if
(
op
==
MP_BINARY_OP_LSHIFT
||
op
==
MP_BINARY_OP_RSHIFT
)
{
||
op
==
MP_BINARY_OP_INPLACE_LSHIFT
||
op
==
MP_BINARY_OP_RSHIFT
||
op
==
MP_BINARY_OP_INPLACE_RSHIFT
)
{
#if N_X64
#if N_X64
emit_pre_pop_reg_reg
(
emit
,
&
vtype_rhs
,
ASM_X64_REG_RCX
,
&
vtype_lhs
,
REG_RET
);
emit_pre_pop_reg_reg
(
emit
,
&
vtype_rhs
,
ASM_X64_REG_RCX
,
&
vtype_lhs
,
REG_RET
);
#else
#else
emit_pre_pop_reg_reg
(
emit
,
&
vtype_rhs
,
ASM_X86_REG_ECX
,
&
vtype_lhs
,
REG_RET
);
emit_pre_pop_reg_reg
(
emit
,
&
vtype_rhs
,
ASM_X86_REG_ECX
,
&
vtype_lhs
,
REG_RET
);
#endif
#endif
if
(
op
==
MP_BINARY_OP_LSHIFT
||
op
==
MP_BINARY_OP_INPLACE_LSHIFT
)
{
if
(
op
==
MP_BINARY_OP_LSHIFT
)
{
ASM_LSL_REG
(
emit
->
as
,
REG_RET
);
ASM_LSL_REG
(
emit
->
as
,
REG_RET
);
}
else
{
}
else
{
ASM_ASR_REG
(
emit
->
as
,
REG_RET
);
ASM_ASR_REG
(
emit
->
as
,
REG_RET
);
...
@@ -1847,10 +1849,9 @@ STATIC void emit_native_binary_op(emit_t *emit, mp_binary_op_t op) {
...
@@ -1847,10 +1849,9 @@ STATIC void emit_native_binary_op(emit_t *emit, mp_binary_op_t op) {
#endif
#endif
// special cases for floor-divide and module because we dispatch to helper functions
// special cases for floor-divide and module because we dispatch to helper functions
if
(
op
==
MP_BINARY_OP_FLOOR_DIVIDE
||
op
==
MP_BINARY_OP_INPLACE_FLOOR_DIVIDE
if
(
op
==
MP_BINARY_OP_FLOOR_DIVIDE
||
op
==
MP_BINARY_OP_MODULO
)
{
||
op
==
MP_BINARY_OP_MODULO
||
op
==
MP_BINARY_OP_INPLACE_MODULO
)
{
emit_pre_pop_reg_reg
(
emit
,
&
vtype_rhs
,
REG_ARG_2
,
&
vtype_lhs
,
REG_ARG_1
);
emit_pre_pop_reg_reg
(
emit
,
&
vtype_rhs
,
REG_ARG_2
,
&
vtype_lhs
,
REG_ARG_1
);
if
(
op
==
MP_BINARY_OP_FLOOR_DIVIDE
||
op
==
MP_BINARY_OP_INPLACE_FLOOR_DIVIDE
)
{
if
(
op
==
MP_BINARY_OP_FLOOR_DIVIDE
)
{
emit_call
(
emit
,
MP_F_SMALL_INT_FLOOR_DIVIDE
);
emit_call
(
emit
,
MP_F_SMALL_INT_FLOOR_DIVIDE
);
}
else
{
}
else
{
emit_call
(
emit
,
MP_F_SMALL_INT_MODULO
);
emit_call
(
emit
,
MP_F_SMALL_INT_MODULO
);
...
@@ -1865,29 +1866,29 @@ STATIC void emit_native_binary_op(emit_t *emit, mp_binary_op_t op) {
...
@@ -1865,29 +1866,29 @@ STATIC void emit_native_binary_op(emit_t *emit, mp_binary_op_t op) {
if
(
0
)
{
if
(
0
)
{
// dummy
// dummy
#if !(N_X64 || N_X86)
#if !(N_X64 || N_X86)
}
else
if
(
op
==
MP_BINARY_OP_LSHIFT
||
op
==
MP_BINARY_OP_INPLACE_LSHIFT
)
{
}
else
if
(
op
==
MP_BINARY_OP_LSHIFT
)
{
ASM_LSL_REG_REG
(
emit
->
as
,
REG_ARG_2
,
reg_rhs
);
ASM_LSL_REG_REG
(
emit
->
as
,
REG_ARG_2
,
reg_rhs
);
emit_post_push_reg
(
emit
,
VTYPE_INT
,
REG_ARG_2
);
emit_post_push_reg
(
emit
,
VTYPE_INT
,
REG_ARG_2
);
}
else
if
(
op
==
MP_BINARY_OP_RSHIFT
||
op
==
MP_BINARY_OP_INPLACE_RSHIFT
)
{
}
else
if
(
op
==
MP_BINARY_OP_RSHIFT
)
{
ASM_ASR_REG_REG
(
emit
->
as
,
REG_ARG_2
,
reg_rhs
);
ASM_ASR_REG_REG
(
emit
->
as
,
REG_ARG_2
,
reg_rhs
);
emit_post_push_reg
(
emit
,
VTYPE_INT
,
REG_ARG_2
);
emit_post_push_reg
(
emit
,
VTYPE_INT
,
REG_ARG_2
);
#endif
#endif
}
else
if
(
op
==
MP_BINARY_OP_OR
||
op
==
MP_BINARY_OP_INPLACE_OR
)
{
}
else
if
(
op
==
MP_BINARY_OP_OR
)
{
ASM_OR_REG_REG
(
emit
->
as
,
REG_ARG_2
,
reg_rhs
);
ASM_OR_REG_REG
(
emit
->
as
,
REG_ARG_2
,
reg_rhs
);
emit_post_push_reg
(
emit
,
VTYPE_INT
,
REG_ARG_2
);
emit_post_push_reg
(
emit
,
VTYPE_INT
,
REG_ARG_2
);
}
else
if
(
op
==
MP_BINARY_OP_XOR
||
op
==
MP_BINARY_OP_INPLACE_XOR
)
{
}
else
if
(
op
==
MP_BINARY_OP_XOR
)
{
ASM_XOR_REG_REG
(
emit
->
as
,
REG_ARG_2
,
reg_rhs
);
ASM_XOR_REG_REG
(
emit
->
as
,
REG_ARG_2
,
reg_rhs
);
emit_post_push_reg
(
emit
,
VTYPE_INT
,
REG_ARG_2
);
emit_post_push_reg
(
emit
,
VTYPE_INT
,
REG_ARG_2
);
}
else
if
(
op
==
MP_BINARY_OP_AND
||
op
==
MP_BINARY_OP_INPLACE_AND
)
{
}
else
if
(
op
==
MP_BINARY_OP_AND
)
{
ASM_AND_REG_REG
(
emit
->
as
,
REG_ARG_2
,
reg_rhs
);
ASM_AND_REG_REG
(
emit
->
as
,
REG_ARG_2
,
reg_rhs
);
emit_post_push_reg
(
emit
,
VTYPE_INT
,
REG_ARG_2
);
emit_post_push_reg
(
emit
,
VTYPE_INT
,
REG_ARG_2
);
}
else
if
(
op
==
MP_BINARY_OP_ADD
||
op
==
MP_BINARY_OP_INPLACE_ADD
)
{
}
else
if
(
op
==
MP_BINARY_OP_ADD
)
{
ASM_ADD_REG_REG
(
emit
->
as
,
REG_ARG_2
,
reg_rhs
);
ASM_ADD_REG_REG
(
emit
->
as
,
REG_ARG_2
,
reg_rhs
);
emit_post_push_reg
(
emit
,
VTYPE_INT
,
REG_ARG_2
);
emit_post_push_reg
(
emit
,
VTYPE_INT
,
REG_ARG_2
);
}
else
if
(
op
==
MP_BINARY_OP_SUBTRACT
||
op
==
MP_BINARY_OP_INPLACE_SUBTRACT
)
{
}
else
if
(
op
==
MP_BINARY_OP_SUBTRACT
)
{
ASM_SUB_REG_REG
(
emit
->
as
,
REG_ARG_2
,
reg_rhs
);
ASM_SUB_REG_REG
(
emit
->
as
,
REG_ARG_2
,
reg_rhs
);
emit_post_push_reg
(
emit
,
VTYPE_INT
,
REG_ARG_2
);
emit_post_push_reg
(
emit
,
VTYPE_INT
,
REG_ARG_2
);
}
else
if
(
op
==
MP_BINARY_OP_MULTIPLY
||
op
==
MP_BINARY_OP_INPLACE_MULTIPLY
)
{
}
else
if
(
op
==
MP_BINARY_OP_MULTIPLY
)
{
ASM_MUL_REG_REG
(
emit
->
as
,
REG_ARG_2
,
reg_rhs
);
ASM_MUL_REG_REG
(
emit
->
as
,
REG_ARG_2
,
reg_rhs
);
emit_post_push_reg
(
emit
,
VTYPE_INT
,
REG_ARG_2
);
emit_post_push_reg
(
emit
,
VTYPE_INT
,
REG_ARG_2
);
}
else
if
(
MP_BINARY_OP_LESS
<=
op
&&
op
<=
MP_BINARY_OP_NOT_EQUAL
)
{
}
else
if
(
MP_BINARY_OP_LESS
<=
op
&&
op
<=
MP_BINARY_OP_NOT_EQUAL
)
{
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment