Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
mu-impl-fast
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
40
Issues
40
List
Board
Labels
Milestones
Merge Requests
1
Merge Requests
1
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
mu
mu-impl-fast
Commits
ed6a477b
Commit
ed6a477b
authored
May 09, 2017
by
qinsoon
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
int128 const
parent
4d292d54
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
69 additions
and
6 deletions
+69
-6
ir.rs
src/ast/src/ir.rs
+2
-0
inst_sel.rs
src/compiler/backend/arch/x86_64/inst_sel.rs
+14
-6
test_int128.rs
tests/test_compiler/test_int128.rs
+53
-0
No files found.
src/ast/src/ir.rs
View file @
ed6a477b
...
...
@@ -915,6 +915,7 @@ impl fmt::Display for SSAVarEntry {
#[derive(Debug,
Clone,
PartialEq,
RustcEncodable,
RustcDecodable)]
pub
enum
Constant
{
Int
(
u64
),
IntEx
(
Vec
<
u64
>
),
Float
(
f32
),
Double
(
f64
),
// IRef(Address),
...
...
@@ -931,6 +932,7 @@ impl fmt::Display for Constant {
fn
fmt
(
&
self
,
f
:
&
mut
fmt
::
Formatter
)
->
fmt
::
Result
{
match
self
{
&
Constant
::
Int
(
v
)
=>
write!
(
f
,
"{}"
,
v
as
i64
),
&
Constant
::
IntEx
(
ref
v
)
=>
write!
(
f
,
"IntEx {:?}"
,
v
),
&
Constant
::
Float
(
v
)
=>
write!
(
f
,
"{}"
,
v
),
&
Constant
::
Double
(
v
)
=>
write!
(
f
,
"{}"
,
v
),
// &Constant::IRef(v) => write!(f, "{}", v),
...
...
src/compiler/backend/arch/x86_64/inst_sel.rs
View file @
ed6a477b
...
...
@@ -1925,7 +1925,7 @@ impl <'a> InstructionSelection {
trace!
(
"emit shl-iregex-iregex"
);
let
(
op1_l
,
op1_h
)
=
self
.emit_ireg_ex
(
op1
,
f_content
,
f_context
,
vm
);
let
(
op2_l
,
op2_h
)
=
self
.emit_ireg_ex
(
op2
,
f_content
,
f_context
,
vm
);
let
(
op2_l
,
_
)
=
self
.emit_ireg_ex
(
op2
,
f_content
,
f_context
,
vm
);
let
(
res_l
,
res_h
)
=
self
.split_int128
(
&
res_tmp
,
f_context
,
vm
);
// mov op2_l -> ecx (we do not care higher bits)
...
...
@@ -1996,7 +1996,7 @@ impl <'a> InstructionSelection {
trace!
(
"emit lshr-iregex-iregex"
);
let
(
op1_l
,
op1_h
)
=
self
.emit_ireg_ex
(
op1
,
f_content
,
f_context
,
vm
);
let
(
op2_l
,
op2_h
)
=
self
.emit_ireg_ex
(
op2
,
f_content
,
f_context
,
vm
);
let
(
op2_l
,
_
)
=
self
.emit_ireg_ex
(
op2
,
f_content
,
f_context
,
vm
);
let
(
res_l
,
res_h
)
=
self
.split_int128
(
&
res_tmp
,
f_context
,
vm
);
// mov op2_l -> ecx (we do not care higher bits)
...
...
@@ -2067,7 +2067,7 @@ impl <'a> InstructionSelection {
trace!
(
"emit ashr-iregex-iregex"
);
let
(
op1_l
,
op1_h
)
=
self
.emit_ireg_ex
(
op1
,
f_content
,
f_context
,
vm
);
let
(
op2_l
,
op2_h
)
=
self
.emit_ireg_ex
(
op2
,
f_content
,
f_context
,
vm
);
let
(
op2_l
,
_
)
=
self
.emit_ireg_ex
(
op2
,
f_content
,
f_context
,
vm
);
let
(
res_l
,
res_h
)
=
self
.split_int128
(
&
res_tmp
,
f_context
,
vm
);
// mov op2_l -> ecx
...
...
@@ -3686,9 +3686,17 @@ impl <'a> InstructionSelection {
Value_
::
SSAVar
(
_
)
=>
{
self
.split_int128
(
pv
,
f_context
,
vm
)
},
Value_
::
Constant
(
ref
c
)
=>
{
unimplemented!
()
}
Value_
::
Constant
(
Constant
::
IntEx
(
ref
val
))
=>
{
assert
!
(
val
.len
()
==
2
);
let
tmp_l
=
self
.make_temporary
(
f_context
,
UINT64_TYPE
.clone
(),
vm
);
let
tmp_h
=
self
.make_temporary
(
f_context
,
UINT64_TYPE
.clone
(),
vm
);
self
.backend
.emit_mov_r64_imm64
(
&
tmp_l
,
val
[
0
]
as
i64
);
self
.backend
.emit_mov_r64_imm64
(
&
tmp_h
,
val
[
1
]
as
i64
);
(
tmp_l
,
tmp_h
)
},
_
=>
panic!
(
"expected ireg_ex"
)
}
}
...
...
tests/test_compiler/test_int128.rs
View file @
ed6a477b
...
...
@@ -64,6 +64,59 @@ fn add_u128() -> VM {
vm
}
#[test]
fn
test_add_const_u128
()
{
let
lib
=
testutil
::
compile_fnc
(
"add_const_u128"
,
&
add_const_u128
);
unsafe
{
use
std
::
u64
;
let
add_const_u128
:
libloading
::
Symbol
<
unsafe
extern
fn
(
u64
,
u64
)
->
(
u64
,
u64
)
>
=
lib
.get
(
b
"add_const_u128"
)
.unwrap
();
let
res
=
add_const_u128
(
1
,
0
);
println!
(
"add_const_u128(1, 1) = {:?}"
,
res
);
assert
!
(
res
==
(
2
,
0
));
let
res
=
add_const_u128
(
u64
::
MAX
,
0
);
println!
(
"add_const_u128(u64::MAX, 1) = {:?}"
,
res
);
assert
!
(
res
==
(
0
,
1
));
}
}
fn
add_const_u128
()
->
VM
{
let
vm
=
VM
::
new
();
typedef!
((
vm
)
u128
=
mu_int
(
128
));
constdef!
((
vm
)
<
u128
>
b
=
Constant
::
IntEx
(
vec!
[
1
,
0
]));
funcsig!
((
vm
)
sig
=
(
u128
)
->
(
u128
));
funcdecl!
((
vm
)
<
sig
>
add_const_u128
);
funcdef!
((
vm
)
<
sig
>
add_const_u128
VERSION
add_const_u128_v1
);
block!
((
vm
,
add_const_u128_v1
)
blk_entry
);
ssa!
((
vm
,
add_const_u128_v1
)
<
u128
>
a
);
// sum = Add %a %b
ssa!
((
vm
,
add_const_u128_v1
)
<
u128
>
sum
);
consta!
((
vm
,
add_const_u128_v1
)
b_local
=
b
);
inst!
((
vm
,
add_const_u128_v1
)
blk_entry_add_const_u128
:
sum
=
BINOP
(
BinOp
::
Add
)
a
b_local
);
inst!
((
vm
,
add_const_u128_v1
)
blk_entry_ret
:
RET
(
sum
)
);
define_block!
((
vm
,
add_const_u128_v1
)
blk_entry
(
a
)
{
blk_entry_add_const_u128
,
blk_entry_ret
});
define_func_ver!
((
vm
)
add_const_u128_v1
(
entry
:
blk_entry
)
{
blk_entry
});
vm
}
#[test]
fn
test_mul_u128
()
{
let
lib
=
testutil
::
compile_fnc
(
"mul_u128"
,
&
mul_u128
);
...
...
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