Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pyston
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Boxiang Sun
Pyston
Commits
4f745cab
Commit
4f745cab
authored
Aug 27, 2015
by
Marius Wachtler
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use xor instead of a mov to clear a register
parent
051a4886
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
25 additions
and
4 deletions
+25
-4
src/asm_writing/assembler.cpp
src/asm_writing/assembler.cpp
+11
-0
src/asm_writing/assembler.h
src/asm_writing/assembler.h
+2
-0
src/asm_writing/rewriter.cpp
src/asm_writing/rewriter.cpp
+9
-1
src/codegen/baseline_jit.cpp
src/codegen/baseline_jit.cpp
+2
-2
src/codegen/baseline_jit.h
src/codegen/baseline_jit.h
+1
-1
No files found.
src/asm_writing/assembler.cpp
View file @
4f745cab
...
@@ -300,6 +300,17 @@ void Assembler::movslq(Indirect src, Register dest) {
...
@@ -300,6 +300,17 @@ void Assembler::movslq(Indirect src, Register dest) {
mov_generic
(
src
,
dest
,
MovType
::
SLQ
);
mov_generic
(
src
,
dest
,
MovType
::
SLQ
);
}
}
void
Assembler
::
clear_reg
(
Register
reg
)
{
int
reg_idx
=
reg
.
regnum
;
// we don't need to generate a REX_W because 32bit instructions will clear the upper 32bits.
if
(
reg_idx
>=
8
)
{
emitRex
(
REX_R
|
REX_B
);
reg_idx
-=
8
;
}
emitByte
(
0x31
);
emitModRM
(
0b11
,
reg_idx
,
reg_idx
);
}
void
Assembler
::
mov_generic
(
Indirect
src
,
Register
dest
,
MovType
type
)
{
void
Assembler
::
mov_generic
(
Indirect
src
,
Register
dest
,
MovType
type
)
{
int
rex
;
int
rex
;
switch
(
type
)
{
switch
(
type
)
{
...
...
src/asm_writing/assembler.h
View file @
4f745cab
...
@@ -144,6 +144,8 @@ public:
...
@@ -144,6 +144,8 @@ public:
void
movswq
(
Indirect
scr
,
Register
dest
);
void
movswq
(
Indirect
scr
,
Register
dest
);
void
movslq
(
Indirect
scr
,
Register
dest
);
void
movslq
(
Indirect
scr
,
Register
dest
);
void
clear_reg
(
Register
reg
);
// = xor reg, reg
void
mov_generic
(
Indirect
src
,
Register
dest
,
MovType
type
);
void
mov_generic
(
Indirect
src
,
Register
dest
,
MovType
type
);
void
push
(
Register
reg
);
void
push
(
Register
reg
);
...
...
src/asm_writing/rewriter.cpp
View file @
4f745cab
...
@@ -206,6 +206,11 @@ assembler::Register Rewriter::ConstLoader::findConst(uint64_t val, bool& found_v
...
@@ -206,6 +206,11 @@ assembler::Register Rewriter::ConstLoader::findConst(uint64_t val, bool& found_v
void
Rewriter
::
ConstLoader
::
loadConstIntoReg
(
uint64_t
val
,
assembler
::
Register
dst_reg
)
{
void
Rewriter
::
ConstLoader
::
loadConstIntoReg
(
uint64_t
val
,
assembler
::
Register
dst_reg
)
{
assert
(
rewriter
->
phase_emitting
);
assert
(
rewriter
->
phase_emitting
);
if
(
val
==
0
)
{
rewriter
->
assembler
->
clear_reg
(
dst_reg
);
return
;
}
if
(
tryRegRegMove
(
val
,
dst_reg
))
if
(
tryRegRegMove
(
val
,
dst_reg
))
return
;
return
;
...
@@ -892,7 +897,10 @@ void Rewriter::_setupCall(bool has_side_effects, llvm::ArrayRef<RewriterVar*> ar
...
@@ -892,7 +897,10 @@ void Rewriter::_setupCall(bool has_side_effects, llvm::ArrayRef<RewriterVar*> ar
assembler
::
Immediate
imm
=
var
->
tryGetAsImmediate
(
&
is_immediate
);
assembler
::
Immediate
imm
=
var
->
tryGetAsImmediate
(
&
is_immediate
);
if
(
is_immediate
)
{
if
(
is_immediate
)
{
assembler
->
mov
(
imm
,
r
);
if
(
imm
.
val
==
0
)
assembler
->
clear_reg
(
r
);
else
assembler
->
mov
(
imm
,
r
);
addLocationToVar
(
var
,
l
);
addLocationToVar
(
var
,
l
);
}
else
{
}
else
{
assembler
::
Register
r2
=
var
->
getInReg
(
l
);
assembler
::
Register
r2
=
var
->
getInReg
(
l
);
...
...
src/codegen/baseline_jit.cpp
View file @
4f745cab
...
@@ -810,7 +810,7 @@ void JitFragmentWriter::_emitOSRPoint(RewriterVar* result, RewriterVar* node_var
...
@@ -810,7 +810,7 @@ void JitFragmentWriter::_emitOSRPoint(RewriterVar* result, RewriterVar* node_var
assembler
->
test
(
result_reg
,
result_reg
);
assembler
->
test
(
result_reg
,
result_reg
);
{
{
assembler
::
ForwardJump
je
(
*
assembler
,
assembler
::
COND_EQUAL
);
assembler
::
ForwardJump
je
(
*
assembler
,
assembler
::
COND_EQUAL
);
assembler
->
mov
(
assembler
::
Immediate
(
0ul
),
assembler
::
RAX
);
// TODO: use xor
assembler
->
clear_reg
(
assembler
::
RAX
);
assembler
->
add
(
assembler
::
Immediate
(
JitCodeBlock
::
sp_adjustment
),
assembler
::
RSP
);
assembler
->
add
(
assembler
::
Immediate
(
JitCodeBlock
::
sp_adjustment
),
assembler
::
RSP
);
assembler
->
pop
(
assembler
::
R12
);
assembler
->
pop
(
assembler
::
R12
);
assembler
->
pop
(
assembler
::
R14
);
assembler
->
pop
(
assembler
::
R14
);
...
@@ -904,7 +904,7 @@ void JitFragmentWriter::_emitRecordType(RewriterVar* type_recorder_var, Rewriter
...
@@ -904,7 +904,7 @@ void JitFragmentWriter::_emitRecordType(RewriterVar* type_recorder_var, Rewriter
void
JitFragmentWriter
::
_emitReturn
(
RewriterVar
*
return_val
)
{
void
JitFragmentWriter
::
_emitReturn
(
RewriterVar
*
return_val
)
{
return_val
->
getInReg
(
assembler
::
RDX
,
true
);
return_val
->
getInReg
(
assembler
::
RDX
,
true
);
assembler
->
mov
(
assembler
::
Immediate
(
0ul
),
assembler
::
RAX
);
// TODO: use xor
assembler
->
clear_reg
(
assembler
::
RAX
);
assembler
->
add
(
assembler
::
Immediate
(
JitCodeBlock
::
sp_adjustment
),
assembler
::
RSP
);
assembler
->
add
(
assembler
::
Immediate
(
JitCodeBlock
::
sp_adjustment
),
assembler
::
RSP
);
assembler
->
pop
(
assembler
::
R12
);
assembler
->
pop
(
assembler
::
R12
);
assembler
->
pop
(
assembler
::
R14
);
assembler
->
pop
(
assembler
::
R14
);
...
...
src/codegen/baseline_jit.h
View file @
4f745cab
...
@@ -117,7 +117,7 @@ class JitFragmentWriter;
...
@@ -117,7 +117,7 @@ class JitFragmentWriter;
// second_JitFragment:
// second_JitFragment:
// ...
// ...
// ; this shows how a AST_Return looks like
// ; this shows how a AST_Return looks like
//
mov $0,%rax
; rax contains the next block to interpret.
//
xor %eax,%eax
; rax contains the next block to interpret.
// in this case 0 which means we are finished
// in this case 0 which means we are finished
// movabs $0x1270014108,%rdx ; rdx must contain the Box* value to return
// movabs $0x1270014108,%rdx ; rdx must contain the Box* value to return
// add $0x118,%rsp ; restore stack pointer
// add $0x118,%rsp ; restore stack pointer
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment