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
5ebb8cab
Commit
5ebb8cab
authored
Jul 05, 2015
by
Kevin Modzelewski
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #665 from undingen/mov_opt
assembler: Use 32bit moves if the immediate fits inside 32bit
parents
1ee49a67
7a8dea0e
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
7 deletions
+16
-7
src/asm_writing/assembler.cpp
src/asm_writing/assembler.cpp
+9
-5
src/asm_writing/assembler.h
src/asm_writing/assembler.h
+2
-2
src/asm_writing/types.h
src/asm_writing/types.h
+5
-0
No files found.
src/asm_writing/assembler.cpp
View file @
5ebb8cab
...
...
@@ -145,18 +145,20 @@ void Assembler::emitSIB(uint8_t scalebits, uint8_t index, uint8_t base) {
emitByte
((
scalebits
<<
6
)
|
(
index
<<
3
)
|
base
);
}
void
Assembler
::
mov
(
Immediate
val
,
Register
dest
)
{
int
rex
=
REX_W
;
void
Assembler
::
mov
(
Immediate
val
,
Register
dest
,
bool
force_64bit_load
)
{
force_64bit_load
=
force_64bit_load
||
!
val
.
fitsInto32Bit
()
;
int
rex
=
force_64bit_load
?
REX_W
:
0
;
int
dest_idx
=
dest
.
regnum
;
if
(
dest_idx
>=
8
)
{
rex
|=
REX_B
;
dest_idx
-=
8
;
}
emitRex
(
rex
);
if
(
rex
)
emitRex
(
rex
);
emitByte
(
0xb8
+
dest_idx
);
emitInt
(
val
.
val
,
8
);
emitInt
(
val
.
val
,
force_64bit_load
?
8
:
4
);
}
void
Assembler
::
movq
(
Immediate
src
,
Indirect
dest
)
{
...
...
@@ -975,7 +977,9 @@ void Assembler::leave() {
}
uint8_t
*
Assembler
::
emitCall
(
void
*
ptr
,
Register
scratch
)
{
mov
(
Immediate
(
ptr
),
scratch
);
// emit a 64bit movabs because some caller expect a fixed number of bytes.
// until they are fixed use the largest encoding.
mov
(
Immediate
(
ptr
),
scratch
,
true
/* force_64bit_load */
);
callq
(
scratch
);
return
addr
;
}
...
...
src/asm_writing/assembler.h
View file @
5ebb8cab
...
...
@@ -114,8 +114,8 @@ public:
void
nop
()
{
emitByte
(
0x90
);
}
void
trap
()
{
emitByte
(
0xcc
);
}
//
some things (such as objdump) call this "movabs" if the immediate is 64-bit
void
mov
(
Immediate
imm
,
Register
dest
);
//
emits a movabs if the immediate is a 64bit value or force_64bit_load = true otherwise it emits a 32bit mov
void
mov
(
Immediate
imm
,
Register
dest
,
bool
force_64bit_load
=
false
);
// not sure if we should use the 'q' suffix here, but this is the most ambiguous one;
// this does a 64-bit store of a 32-bit value.
void
movq
(
Immediate
imm
,
Indirect
dest
);
...
...
src/asm_writing/types.h
View file @
5ebb8cab
...
...
@@ -158,6 +158,11 @@ struct Immediate {
explicit
Immediate
(
uint64_t
val
)
:
val
(
val
)
{}
explicit
Immediate
(
void
*
val
)
:
val
((
uint64_t
)
val
)
{}
bool
fitsInto32Bit
()
const
{
uint32_t
val_32bit
=
(
uint32_t
)
val
;
return
val_32bit
==
val
;
}
};
struct
JumpDestination
{
...
...
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