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
f12f8f21
Commit
f12f8f21
authored
Nov 16, 2016
by
John Zhang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
create mu instance and tag current thread using ctypes for test_cmpop; preload_mu() function
parent
04711fe7
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
27 additions
and
6 deletions
+27
-6
perfcmp.py
tests/test_jit/perfcmp.py
+2
-3
test_cmpops.py
tests/test_jit/test_cmpops.py
+21
-1
util.py
tests/test_jit/util.py
+4
-2
No files found.
tests/test_jit/perfcmp.py
View file @
f12f8f21
...
...
@@ -10,7 +10,7 @@ import ctypes
from
rpython.translator.interactive
import
Translation
from
rpython.config.translationoption
import
set_opt_level
from
util
import
libmu_path
,
libext
from
util
import
libmu_path
,
libext
,
preload_libmu
CPYTHON
=
os
.
environ
.
get
(
'CPYTHON'
,
'python'
)
PYPY
=
os
.
environ
.
get
(
'PYPY'
,
'pypy'
)
...
...
@@ -153,8 +153,7 @@ uint64_t fib(uint64_t n) {
exec
(
py_code_str
,
mod
)
rpy_fnc
=
mod
[
'fib'
]
# load libmu before rffi so to load it with RTLD_GLOBAL
libmu
=
ctypes
.
CDLL
(
libmu_path
.
strpath
,
ctypes
.
RTLD_GLOBAL
)
preload_libmu
()
t
=
Translation
(
rpy_fnc
,
[
int
],
backend
=
'mu'
,
muimpl
=
'fast'
,
mucodegen
=
'api'
,
mutestjit
=
True
)
...
...
tests/test_jit/test_cmpops.py
View file @
f12f8f21
from
util
import
fncptr_from_c_script
from
util
import
fncptr_from_c_script
,
preload_libmu
import
ctypes
def
test_eq_int
():
fn
,
_
=
fncptr_from_c_script
(
"test_eq_int.c"
,
"test_fnc"
)
assert
fn
()
==
0
def
mu_instance_via_ctyeps
():
libmu
=
preload_libmu
()
class
MuVM
(
ctypes
.
Structure
):
pass
MuVM
.
_fields_
=
[
(
'header'
,
ctypes
.
c_voidp
),
(
'new_context'
,
ctypes
.
c_voidp
),
# function pointers should have the same size as c_voidp
(
'id_of'
,
ctypes
.
c_voidp
),
(
'name_of'
,
ctypes
.
c_voidp
),
(
'set_trap_handler'
,
ctypes
.
c_voidp
),
(
'compile_to_sharedlib'
,
ctypes
.
c_voidp
),
(
'current_thread_as_mu_thread'
,
ctypes
.
CFUNCTYPE
(
None
,
ctypes
.
POINTER
(
MuVM
),
ctypes
.
c_voidp
)),
]
libmu
.
mu_fastimpl_new
.
restype
=
ctypes
.
POINTER
(
MuVM
)
mu
=
libmu
.
mu_fastimpl_new
()
mu
.
contents
.
current_thread_as_mu_thread
(
mu
,
None
)
return
mu
def
test_eq_ref
():
mu
=
mu_instance_via_ctyeps
()
fn
,
_
=
fncptr_from_c_script
(
"test_eq_ref.c"
,
"test_fnc"
)
assert
fn
()
==
0
...
...
@@ -14,6 +33,7 @@ def test_ne_int():
assert
fn
()
==
1
def
test_ne_ref
():
mu
=
mu_instance_via_ctyeps
()
fn
,
_
=
fncptr_from_c_script
(
"test_ne_ref.c"
,
"test_fnc"
)
assert
fn
()
==
1
...
...
tests/test_jit/util.py
View file @
f12f8f21
...
...
@@ -84,6 +84,9 @@ def fncptr_from_py_script(py_fnc, name, argtypes=[], restype=ctypes.c_longlong):
lib
=
ctypes
.
CDLL
(
'emit/
%(libname)
s'
%
locals
())
return
fncptr_from_lib
(
lib
,
name
,
argtypes
,
restype
),
(
mu
,
ctx
,
bldr
)
def
preload_libmu
():
# load libmu before rffi so to load it with RTLD_GLOBAL
return
ctypes
.
CDLL
(
libmu_path
.
strpath
,
ctypes
.
RTLD_GLOBAL
)
def
fncptr_from_rpy_func
(
rpy_fnc
,
llargtypes
,
llrestype
,
**
kwargs
):
# NOTE: requires mu-client-pypy
...
...
@@ -91,8 +94,7 @@ def fncptr_from_rpy_func(rpy_fnc, llargtypes, llrestype, **kwargs):
from
rpython.translator.interactive
import
Translation
from
rpython.config.translationoption
import
set_opt_level
# load libmu before rffi so to load it with RTLD_GLOBAL
libmu
=
ctypes
.
CDLL
(
libmu_path
.
strpath
,
ctypes
.
RTLD_GLOBAL
)
preload_libmu
()
kwargs
.
setdefault
(
'backend'
,
'mu'
)
kwargs
.
setdefault
(
'muimpl'
,
'fast'
)
...
...
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