Mercurial > pub > dyncall > dyncall
comparison test/call_suite_aggrs/globals.c @ 485:0c68b3f91367
- renamed suite_aggrs to call_suite_aggrs for consistency (callback version will be called callback_suite_aggrs)
author | Tassilo Philipp |
---|---|
date | Thu, 17 Mar 2022 15:41:26 +0100 |
parents | test/suite_aggrs/globals.c@0f3b6898078d |
children | 29d09d10ecd9 |
comparison
equal
deleted
inserted
replaced
484:74a4f682d1ef | 485:0c68b3f91367 |
---|---|
1 /* | |
2 | |
3 Package: dyncall | |
4 Library: test | |
5 File: test/call_suite_aggrs/globals.c | |
6 Description: | |
7 License: | |
8 | |
9 Copyright (c) 2022 Tassilo Philipp <tphilipp@potion-studios.com> | |
10 | |
11 Permission to use, copy, modify, and distribute this software for any | |
12 purpose with or without fee is hereby granted, provided that the above | |
13 copyright notice and this permission notice appear in all copies. | |
14 | |
15 THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES | |
16 WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF | |
17 MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR | |
18 ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES | |
19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN | |
20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF | |
21 OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. | |
22 | |
23 */ | |
24 | |
25 #include <stdlib.h> | |
26 #include "globals.h" | |
27 #include <float.h> | |
28 #include <string.h> | |
29 | |
30 #define X(CH,T) T *V_##CH; T *K_##CH; | |
31 DEF_TYPES | |
32 #undef X | |
33 | |
34 #define AGGR_MISALIGN 1 | |
35 | |
36 static double rand_d() { return ( ( (double) rand() ) / ( (double) RAND_MAX ) ); } | |
37 | |
38 /* fill mem with random values, make sure no float aligned memory location | |
39 * results in a NaN, as they always compare to false; so avaid all ones in | |
40 * exporent (for simplicity we just look at first 7 exponent bits and make sure | |
41 * they aren't all set, which would work for all IEEE754 precision formats) */ | |
42 static void rand_mem__fp_friendly(void* p, size_t s) | |
43 { | |
44 int i; | |
45 for(i = 0; i<s; ++i) { | |
46 char* c = (char*)p; | |
47 c[i] = (char)rand(); /* slowish, byte by byte, but whatev */ | |
48 if((c[i]&0x7f) == 0x7f) | |
49 c[i] ^= 1; | |
50 } | |
51 } | |
52 | |
53 int get_max_aggr_size() | |
54 { | |
55 static int s = 0; | |
56 int i; | |
57 if(s == 0) { | |
58 for(i=0; i<G_naggs; ++i) | |
59 if(G_agg_sizes[i] > s) | |
60 s = G_agg_sizes[i]; | |
61 } | |
62 return s; | |
63 } | |
64 | |
65 void init_test_data() | |
66 { | |
67 int i; | |
68 int maxaggrsize = get_max_aggr_size(); | |
69 #define X(CH,T) V_##CH = (T*) malloc(sizeof(T)*(G_maxargs+1)); K_##CH = (T*) malloc(sizeof(T)*(G_maxargs+1)); | |
70 DEF_TYPES | |
71 #undef X | |
72 | |
73 for(i=0;i<G_maxargs+1;++i) { | |
74 K_c[i] = (char) (((rand_d()-0.5)*2) * (1<<7)); | |
75 K_s[i] = (short) (((rand_d()-0.5)*2) * (1<<(sizeof(short)*8-1))); | |
76 K_i[i] = (int) (((rand_d()-0.5)*2) * (1<<(sizeof(int)*8-2))); | |
77 K_j[i] = (long) (((rand_d()-0.5)*2) * (1L<<(sizeof(long)*8-2))); | |
78 K_l[i] = (long long) (((rand_d()-0.5)*2) * (1LL<<(sizeof(long long)*8-2))); | |
79 K_p[i] = (void*) (long) (((rand_d()-0.5)*2) * (1LL<<(sizeof(void*)*8-1))); | |
80 K_f[i] = (float) (rand_d() * FLT_MAX); | |
81 K_d[i] = (double) (((rand_d()-0.5)*2) * DBL_MAX); | |
82 K_a[i] = malloc(maxaggrsize+AGGR_MISALIGN); | |
83 rand_mem__fp_friendly(K_a[i], maxaggrsize+AGGR_MISALIGN); | |
84 K_a[i] = (char*)K_a[i]+AGGR_MISALIGN; | |
85 } | |
86 } | |
87 | |
88 void clear_V() | |
89 { | |
90 static int aggr_init = 0; | |
91 int maxaggrsize = get_max_aggr_size(); | |
92 | |
93 int i; | |
94 for(i=0;i<G_maxargs+1;++i) { | |
95 if(aggr_init) | |
96 free((char*)V_a[i]-AGGR_MISALIGN); | |
97 #define X(CH,T) V_##CH[i] = (T) 0; | |
98 DEF_TYPES | |
99 #undef X | |
100 V_a[i] = malloc(maxaggrsize+AGGR_MISALIGN); | |
101 memset(V_a[i], 0, maxaggrsize+AGGR_MISALIGN); | |
102 V_a[i] = (char*)V_a[i]+AGGR_MISALIGN; | |
103 } | |
104 aggr_init = 1; | |
105 } | |
106 | |
107 void deinit_test_data() | |
108 { | |
109 int i; | |
110 for(i=0;i<G_maxargs+1;++i) { | |
111 free((char*)V_a[i]-AGGR_MISALIGN); | |
112 free((char*)K_a[i]-AGGR_MISALIGN); | |
113 } | |
114 | |
115 #define X(CH,T) free(V_##CH); free(K_##CH); | |
116 DEF_TYPES | |
117 #undef X | |
118 } | |
119 |