Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Support restrict and const qualifiers for array expression arguments

  • Loading branch information...
commit 6a6e9a7090cc4b1a397129ad8afba0c960da7b97 1 parent 0653f04
@markflorisson authored
View
30 Cython/Compiler/Vector.py
@@ -44,6 +44,31 @@ def map_type(self, type, wrap=False):
raise minierror.UnmappableTypeError(type)
class CythonSpecializerMixin(object):
+ def visit_FunctionNode(self, node):
+ node = super(CythonSpecializerMixin, self).visit_FunctionNode(node)
+
+ qualifiers = [
+ "const",
+ "CYTHON_RESTRICT",
+ ]
+ data_qualifiers = ["const"]
+
+ node.shape.type.qualifiers.update(qualifiers)
+ for idx, arg in enumerate(arg for arg in node.arguments
+ if arg.is_array_funcarg):
+ arg.data_pointer.type.qualifiers.update(qualifiers)
+ if arg.strides_pointer:
+ arg.strides_pointer.type.qualifiers.update(qualifiers)
+
+ if idx > 0:
+ arg.data_pointer.type.base_type.qualifiers.update(
+ data_qualifiers)
+ if arg.strides_pointer:
+ arg.strides_pointer.type.base_type.qualifiers.update(
+ data_qualifiers)
+
+ return node
+
def visit_NodeWrapper(self, node):
for op in node.operands:
op.variable = self.visit(op.variable)
@@ -1282,6 +1307,7 @@ def load_utilities(env):
env.use_utility_code(overlap_utility)
env.use_utility_code(array_order_utility)
+ env.use_utility_code(restrict_utility)
def load_vector_utility(name, context, **kwargs):
return Code.TempitaUtilityCode.load(name, "Vector.c", context=context, **kwargs)
@@ -1293,4 +1319,6 @@ def load_vector_utility(name, context, **kwargs):
MemoryView.view_utility_code.requires.append(broadcast_utility)
overlap_utility = MemoryView.load_memview_c_utility("ReadAfterWrite",
context=context)
-array_order_utility = load_vector_utility("GetOrder", context)
+array_order_utility = load_vector_utility("GetOrder", context)
+restrict_utility = load_vector_utility(
+ "RestrictUtility", context, proto_block='utility_code_proto_before_types')
View
13 Cython/Utility/Vector.c
@@ -63,3 +63,16 @@ __pyx_get_arrays_ordering(const {{memviewslice_name}} **ops, const int *ndims,
return __PYX_ARRAYS_ARE_INNER_CONTIG | !!seen_c_ish;
}
+
+////////// RestrictUtility.proto //////////
+#ifndef CYTHON_RESTRICT
+ #if defined(__GNUC__)
+ #define CYTHON_RESTRICT __restrict__
+ #elif defined(_MSC_VER)
+ #define CYTHON_RESTRICT __restrict
+ #elif defined (__STDC_VERSION__) && __STDC_VERSION__ >= 199901L
+ #define CYTHON_RESTRICT restrict
+ #else
+ #define CYTHON_RESTRICT
+ #endif
+#endif
2  Cython/minivect
@@ -1 +1 @@
-Subproject commit d66bb051d62c8465c914425ae6608ad379d973bc
+Subproject commit c1d62728e1bc590a4ae4d66e0e7e761834a72355
Please sign in to comment.
Something went wrong with that request. Please try again.