1 #include <stdlib.h>
2 #ifndef CHEATING_VEC_INIT_H_
3 #define CHEATING_VEC_INIT_H_
4 
5 #include "macros.h"
6 #include "memory.h"
7 #include "mpfq/mpfq_vbase.h"
8 
9 #define FORCED_ALIGNMENT_ON_MPFQ_VEC_TYPES      32
10 #define MINIMUM_ITEM_SIZE_OF_MPFQ_VEC_TYPES     4
11 
12 /* The mpfq routines for doing vec_init rely on simple malloc() to do their
13  * job.
14  *
15  * Unfortunately our alignment constraints are stricter.
16  *
17  * We could consider modifying mpfq to allow an alignment constraint in
18  * vec_init, but that would be clutter.
19  *
20  * Instead, we cheat on vec_init, and leverage the fact that cado-nfs
21  * already has all sorts of aligned_malloc's and friends
22  */
23 #ifdef __cplusplus
24 extern "C" {
25 #endif
26 
cheating_vec_init(mpfq_vbase_ptr A,void ** p,size_t nitems)27 static inline void cheating_vec_init(mpfq_vbase_ptr A, void ** p, size_t nitems)
28 {
29     *p = malloc_aligned(A->vec_elt_stride(A, nitems), FORCED_ALIGNMENT_ON_MPFQ_VEC_TYPES);
30 }
31 
cheating_vec_clear(mpfq_vbase_ptr A MAYBE_UNUSED,void ** p,size_t nitems MAYBE_UNUSED)32 static inline void cheating_vec_clear(mpfq_vbase_ptr A MAYBE_UNUSED, void ** p, size_t nitems MAYBE_UNUSED)
33 {
34     free_aligned(*p);
35     *p=NULL;
36 }
37 
38 
39 #ifdef __cplusplus
40 }
41 #endif
42 
43 #endif	/* CHEATING_VEC_INIT_H_ */
44