2 * Copyright (C) 2009-2016, Intel Corporation
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
9 * * Redistributions of source code must retain the above copyright
10 * notice, this list of conditions and the following disclaimer.
11 * * Redistributions in binary form must reproduce the above copyright
12 * notice, this list of conditions and the following disclaimer in
13 * the documentation and/or other materials provided with the
15 * * Neither the name of Intel Corporation nor the names of its
16 * contributors may be used to endorse or promote products derived
17 * from this software without specific prior written permission.
19 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
20 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
21 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
22 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
23 * HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
24 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
25 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
26 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
27 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY
29 * WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
30 * POSSIBILITY OF SUCH DAMAGE.
32 * *********************************************************************
34 * PLEASE NOTE: This file is a downstream copy of a file mainitained in
35 * a repository at cilkplus.org. Changes made to this file that are not
36 * submitted through the contribution process detailed at
37 * http://www.cilkplus.org/submit-cilk-contribution will be lost the next
38 * time that a new version is released. Changes only submitted to the
39 * GNU compiler collection or posted to the git repository at
40 * https://bitbucket.org/intelcilkruntime/intel-cilk-runtime.git are
43 * We welcome your contributions to this open source project. Thank you
44 * for your assistance in helping us improve Cilk Plus.
48 #ifndef INCLUDED_CILK_HYPEROBJECT_BASE
49 #define INCLUDED_CILK_HYPEROBJECT_BASE
59 #include <cilk/common.h>
61 #if defined _WIN32 || defined _WIN64
62 # if !defined CILK_STUB && !defined IN_CILK_RUNTIME
63 /* bring in the Intel(R) Cilk(TM) Plus library, which has definitions for some of these
65 # pragma comment(lib, "cilkrts")
69 /* The __CILKRTS_STRAND_PURE attribute tells the compiler that the value
70 * returned by 'func' for a given argument to 'func' will remain valid until
71 * the next strand boundary (spawn or sync) or until the next call to a
72 * function with the __CILKRTS_STRAND_STALE attribute using the same function
75 #if 0 && defined __cilk && (defined __GNUC__ && !defined _WIN32) && defined __cilkartsrev
76 # define __CILKRTS_STRAND_PURE(func) \
77 func __attribute__((__cilk_hyper__("lookup")))
78 # define __CILKRTS_STRAND_STALE(func) \
79 func __attribute__((__cilk_hyper__("flush")))
81 # define __CILKRTS_STRAND_PURE(func) func
82 # define __CILKRTS_STRAND_STALE(func) func
85 /*****************************************************************************
86 * C runtime interface to the hyperobject subsystem
87 *****************************************************************************/
89 __CILKRTS_BEGIN_EXTERN_C
91 /* Callback function signatures. The 'r' argument always points to the
92 * reducer itself and is commonly ignored. */
93 typedef void (*cilk_c_reducer_reduce_fn_t
)(void* r
, void* lhs
, void* rhs
);
94 typedef void (*cilk_c_reducer_identity_fn_t
)(void* r
, void* view
);
95 typedef void (*cilk_c_reducer_destroy_fn_t
)(void* r
, void* view
);
96 typedef void* (*cilk_c_reducer_allocate_fn_t
)(void* r
, __STDNS
size_t bytes
);
97 typedef void (*cilk_c_reducer_deallocate_fn_t
)(void* r
, void* view
);
99 /** Representation of the monoid */
100 typedef struct cilk_c_monoid
{
101 cilk_c_reducer_reduce_fn_t reduce_fn
;
102 cilk_c_reducer_identity_fn_t identity_fn
;
103 cilk_c_reducer_destroy_fn_t destroy_fn
;
104 cilk_c_reducer_allocate_fn_t allocate_fn
;
105 cilk_c_reducer_deallocate_fn_t deallocate_fn
;
108 /** Base of the hyperobject */
109 typedef struct __cilkrts_hyperobject_base
111 cilk_c_monoid __c_monoid
;
112 unsigned long long __flags
;
113 __STDNS
ptrdiff_t __view_offset
; /* offset (in bytes) to leftmost view */
114 __STDNS
size_t __view_size
; /* Size of each view */
115 } __cilkrts_hyperobject_base
;
120 /* Library functions. */
122 void __cilkrts_hyper_create(__cilkrts_hyperobject_base
*key
);
123 CILK_EXPORT
void __CILKRTS_STRAND_STALE(
124 __cilkrts_hyper_destroy(__cilkrts_hyperobject_base
*key
));
125 CILK_EXPORT
void* __CILKRTS_STRAND_PURE(
126 __cilkrts_hyper_lookup(__cilkrts_hyperobject_base
*key
));
129 void* __cilkrts_hyperobject_alloc(void* ignore
, __STDNS
size_t bytes
);
131 void __cilkrts_hyperobject_dealloc(void* ignore
, void* view
);
133 /* No-op destroy function */
135 void __cilkrts_hyperobject_noop_destroy(void* ignore
, void* ignore2
);
140 // Programs compiled with CILK_STUB are not linked with the Intel Cilk Plus runtime
141 // library, so they should not have external references to cilkrts functions.
142 // Furthermore, they don't need the hyperobject functionality, so the
143 // functions can be stubbed.
145 #define __cilkrts_hyperobject_create __cilkrts_hyperobject_create__stub
147 void __cilkrts_hyper_create(__cilkrts_hyperobject_base
*key
)
150 #define __cilkrts_hyperobject_destroy __cilkrts_hyperobject_destroy__stub
152 void __cilkrts_hyper_destroy(__cilkrts_hyperobject_base
*key
)
155 #define __cilkrts_hyperobject_lookup __cilkrts_hyperobject_lookup__stub
157 void* __cilkrts_hyper_lookup(__cilkrts_hyperobject_base
*key
)
158 { return (char*)(key
) + key
->__view_offset
; }
160 // Pointers to these functions are stored into monoids, so real functions
163 #define __cilkrts_hyperobject_alloc __cilkrts_hyperobject_alloc__stub
165 void* __cilkrts_hyperobject_alloc(void* ignore
, __STDNS
size_t bytes
)
166 { assert(0); return __STDNS
malloc(bytes
); }
168 #define __cilkrts_hyperobject_dealloc __cilkrts_hyperobject_dealloc__stub
170 void __cilkrts_hyperobject_dealloc(void* ignore
, void* view
)
171 { assert(0); __STDNS
free(view
); }
173 #define __cilkrts_hyperobject_noop_destroy \
174 __cilkrts_hyperobject_noop_destroy__stub
176 void __cilkrts_hyperobject_noop_destroy(void* ignore
, void* ignore2
)
181 __CILKRTS_END_EXTERN_C
183 #endif /* INCLUDED_CILK_HYPEROBJECT_BASE */