Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Labels
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Commits
Open sidebar
nexedi
cython
Commits
091bdf3c
Commit
091bdf3c
authored
Jan 21, 2013
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
optimise abs(long long)
parent
d0da3179
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
0 deletions
+30
-0
Cython/Compiler/Builtin.py
Cython/Compiler/Builtin.py
+28
-0
tests/run/builtin_abs.pyx
tests/run/builtin_abs.pyx
+2
-0
No files found.
Cython/Compiler/Builtin.py
View file @
091bdf3c
...
...
@@ -35,6 +35,27 @@ static CYTHON_INLINE unsigned long __Pyx_abs_long(long x) {
}
'''
)
abs_longlong_utility_code
=
UtilityCode
(
proto
=
'''
static CYTHON_INLINE unsigned PY_LONG_LONG __Pyx_abs_longlong(PY_LONG_LONG x) {
#ifndef PY_LLONG_MAX
#ifdef LLONG_MAX
const PY_LONG_LONG PY_LLONG_MAX = LLONG_MAX;
#else
// copied from pyport.h in CPython 3.3, missing in 2.4
const PY_LONG_LONG PY_LLONG_MAX = (1 + 2 * ((1LL << (CHAR_BIT * sizeof(PY_LONG_LONG) - 2)) - 1));
#endif
#endif
if (unlikely(x == -PY_LLONG_MAX-1))
return ((unsigned PY_LONG_LONG)PY_LLONG_MAX) + 1U;
#if defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
return (unsigned PY_LONG_LONG) llabs(x);
#else
return (x<0) ? (unsigned PY_LONG_LONG)-x : (unsigned PY_LONG_LONG)x;
#endif
}
'''
)
iter_next_utility_code
=
UtilityCode
.
load_cached
(
"IterNext"
,
"ObjectHandling.c"
)
getattr3_utility_code
=
UtilityCode
(
...
...
@@ -211,6 +232,13 @@ builtin_function_table = [
PyrexTypes
.
CFuncTypeArg
(
"arg"
,
PyrexTypes
.
c_long_type
,
None
)
],
is_strict_signature
=
True
)),
BuiltinFunction
(
'abs'
,
None
,
None
,
"__Pyx_abs_longlong"
,
utility_code
=
abs_longlong_utility_code
,
func_type
=
PyrexTypes
.
CFuncType
(
PyrexTypes
.
c_ulonglong_type
,
[
PyrexTypes
.
CFuncTypeArg
(
"arg"
,
PyrexTypes
.
c_longlong_type
,
None
)
],
is_strict_signature
=
True
)),
BuiltinFunction
(
'abs'
,
"O"
,
"O"
,
"PyNumber_Absolute"
),
BuiltinFunction
(
'callable'
,
"O"
,
"b"
,
"__Pyx_PyCallable_Check"
,
utility_code
=
UtilityCode
.
load_cached
(
"CallableCheck"
,
"ObjectHandling.c"
)),
...
...
tests/run/builtin_abs.pyx
View file @
091bdf3c
...
...
@@ -84,6 +84,8 @@ def ulong_abs(unsigned long a):
"""
return
abs
(
a
)
@
cython
.
test_assert_path_exists
(
"//ReturnStatNode//NameNode[@entry.name = 'abs']"
,
"//ReturnStatNode//NameNode[@entry.cname = '__Pyx_abs_longlong']"
)
def
long_long_abs
(
long
long
a
):
"""
>>> long_long_abs(-(2**33)) == 2**33
...
...
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