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
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cython
Commits
2fa0e9f6
Commit
2fa0e9f6
authored
6 years ago
by
Stefan Behnel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Inline fast special cases for "abs(PyLong)" when the argument is non-negative or small.
parent
e4e2be30
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
34 additions
and
1 deletion
+34
-1
CHANGES.rst
CHANGES.rst
+5
-0
Cython/Compiler/Builtin.py
Cython/Compiler/Builtin.py
+2
-1
Cython/Utility/Builtins.c
Cython/Utility/Builtins.c
+27
-0
No files found.
CHANGES.rst
View file @
2fa0e9f6
...
@@ -5,6 +5,11 @@ Cython Changelog
...
@@ -5,6 +5,11 @@ Cython Changelog
0.28.2 (2018-??-??)
0.28.2 (2018-??-??)
===================
===================
Features added
--------------
* ``abs()`` is faster for Python long objects.
Bugs fixed
Bugs fixed
----------
----------
...
...
This diff is collapsed.
Click to expand it.
Cython/Compiler/Builtin.py
View file @
2fa0e9f6
...
@@ -124,7 +124,8 @@ builtin_function_table = [
...
@@ -124,7 +124,8 @@ builtin_function_table = [
PyrexTypes
.
c_double_complex_type
,
PyrexTypes
.
c_double_complex_type
,
PyrexTypes
.
c_longdouble_complex_type
)
PyrexTypes
.
c_longdouble_complex_type
)
)
+
[
)
+
[
BuiltinFunction
(
'abs'
,
"O"
,
"O"
,
"PyNumber_Absolute"
),
BuiltinFunction
(
'abs'
,
"O"
,
"O"
,
"__Pyx_PyNumber_Absolute"
,
utility_code
=
UtilityCode
.
load
(
"py_abs"
,
"Builtins.c"
)),
#('all', "", "", ""),
#('all', "", "", ""),
#('any', "", "", ""),
#('any', "", "", ""),
#('ascii', "", "", ""),
#('ascii', "", "", ""),
...
...
This diff is collapsed.
Click to expand it.
Cython/Utility/Builtins.c
View file @
2fa0e9f6
...
@@ -253,6 +253,33 @@ static CYTHON_INLINE PY_LONG_LONG __Pyx_abs_longlong(PY_LONG_LONG x) {
...
@@ -253,6 +253,33 @@ static CYTHON_INLINE PY_LONG_LONG __Pyx_abs_longlong(PY_LONG_LONG x) {
}
}
//////////////////// py_abs.proto ////////////////////
#if CYTHON_USE_PYLONG_INTERNALS
static
PyObject
*
__Pyx_PyLong_AbsNeg
(
PyObject
*
num
);
/*proto*/
#define __Pyx_PyNumber_Absolute(x) \
((likely(PyLong_CheckExact(x))) ? \
(likely(Py_SIZE(x) >= 0) ? (Py_INCREF(x), (x)) : __Pyx_PyLong_AbsNeg(x)) : \
PyNumber_Absolute(x))
#else
#define __Pyx_PyNumber_Absolute(x) PyNumber_Absolute(x)
#endif
//////////////////// py_abs ////////////////////
#if CYTHON_USE_PYLONG_INTERNALS
static
PyObject
*
__Pyx_PyLong_AbsNeg
(
PyObject
*
n
)
{
if
(
likely
(
Py_SIZE
(
n
)
==
-
1
))
{
// digits are unsigned
return
PyLong_FromLong
(((
PyLongObject
*
)
n
)
->
ob_digit
[
0
]);
}
return
((
PyTypeObject
*
)
Py_TYPE
(
n
))
->
tp_as_number
->
nb_negative
(
n
);
}
#endif
//////////////////// pow2.proto ////////////////////
//////////////////// pow2.proto ////////////////////
#define __Pyx_PyNumber_Power2(a, b) PyNumber_Power(a, b, Py_None)
#define __Pyx_PyNumber_Power2(a, b) PyNumber_Power(a, b, Py_None)
...
...
This diff is collapsed.
Click to expand it.
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