summaryrefslogtreecommitdiffstats
path: root/all_pairs/source/ammunition/ammunition.c
diff options
context:
space:
mode:
Diffstat (limited to 'all_pairs/source/ammunition/ammunition.c')
-rw-r--r--all_pairs/source/ammunition/ammunition.c1185
1 files changed, 1185 insertions, 0 deletions
diff --git a/all_pairs/source/ammunition/ammunition.c b/all_pairs/source/ammunition/ammunition.c
new file mode 100644
index 0000000..224babd
--- /dev/null
+++ b/all_pairs/source/ammunition/ammunition.c
@@ -0,0 +1,1185 @@
1/*
2
3 This program is part of the TACLeBench benchmark suite.
4 Version V 2.0
5
6 Name: ammunition
7
8 Author: Vladimir Makarov <vmakarov@gcc.gnu.org>
9
10 Function: Tests reusable packages bits and arith
11 bits: Work with bit strings (copying, moving, setting, testing, comparison).
12 arith: Implementing host machine-independently arbitrary precision integer
13 numbers arithmetic. The implementation of the package functions are not
14 sufficiently efficient in order to use for run-time. The package
15 functions are oriented to implement constant-folding in compilers,
16 cross-compilers.
17
18 Source: DINO programming language repository
19 https://github.com/dino-lang/dino/
20
21 Changes: no major functional changes
22
23 License: GPL 2 and LGPL 2
24
25*/
26
27#include "../extra.h"
28#include "bits.h"
29#include "arithm.h"
30#include "ammunition_stdlib.h"
31#include "ammunition_stdio.h"
32#include "ammunition_string.h"
33
34/*
35 Forward declaration of functions
36*/
37
38void ammunition_reset_str_bits( char *str, char *s );
39void ammunition_reset_str_arithm( char *str, char *s, char *d, char *e,
40 char *g );
41int ammunition_bits_test();
42int ammunition_arithm_test();
43void ammunition_init( void );
44int ammunition_return( void );
45void ammunition_main( void );
46//int main( void );
47
48
49/*
50 Forward declaration of global variables
51*/
52
53int ammunition_result;
54
55
56/*
57 Core functions
58*/
59
60void ammunition_reset_str_bits( char *str, char *s )
61{
62 int i;
63 _Pragma( "loopbound min 8 max 8" )
64 for ( i = 0; i < 8; i++ ) {
65 str[i] = 0;
66 s[i] = 0;
67 }
68}
69
70
71void ammunition_reset_str_arithm( char *str, char *s, char *d, char *e,
72 char *g )
73{
74 int i;
75 _Pragma( "loopbound min 20 max 20" )
76 for ( i = 0; i < 20; i++ ) {
77 str[i] = 0;
78 s[i] = 0;
79 }
80
81 _Pragma( "loopbound min 4 max 4" )
82 for ( i = 0; i < 4; i++ ) {
83 d[i] = 0;
84 e[i] = 0;
85 }
86
87 _Pragma( "loopbound min 6 max 6" )
88 for ( i = 0; i < 6; i++ )
89 g[i] = 0;
90}
91
92
93int ammunition_bits_test()
94{
95 char str[8];
96 char str1[8];
97
98 int result = 0;
99 unsigned int i, j;
100
101 /* Test 1 */
102 ammunition_reset_str_bits( str, str1 );
103
104 _Pragma( "loopbound min 64 max 64" )
105 for ( i = 0; i < sizeof ( str ) * CHAR_BIT; i++ ) {
106 if ( BIT ( str, i ) )
107 result = 1;
108 }
109
110 _Pragma( "loopbound min 64 max 64" )
111 for ( i = 0; i < sizeof ( str ) * CHAR_BIT; i++ ) {
112 SET_BIT ( str, i, 1 );
113 _Pragma( "loopbound min 64 max 64" )
114 for ( j = 0; j < sizeof ( str ) * CHAR_BIT; j++ )
115 if ( j <= i ) {
116 if ( BIT ( str, j ) == 0 )
117 result = 1;
118 } else
119 if ( BIT ( str, j ) )
120 result = 1;
121 }
122
123 /* Test 2 */
124 ammunition_reset_str_bits( str, str1 );
125
126 _Pragma( "loopbound min 64 max 64" )
127 for ( i = 0; i < sizeof ( str ) * CHAR_BIT; i++ )
128 if ( !ammunition_is_zero_bit_string (
129 str, i, ( sizeof ( str ) * CHAR_BIT - i ) / 2 + 1 ) )
130 result = 1;
131 ammunition_bit_string_set ( str, 13, 1, 35 );
132 _Pragma( "loopbound min 13 max 13" )
133 for ( i = 0; i < 13; i++ )
134 if ( !ammunition_is_zero_bit_string ( str, i, 13 - i ) )
135 result = 1;
136 _Pragma( "loopbound min 35 max 35" )
137 for ( i = 13; i < 48; i++ )
138 if ( ammunition_is_zero_bit_string ( str, i, 48 - i ) )
139 result = 1;
140 _Pragma( "loopbound min 16 max 16" )
141 for ( i = 48; i < sizeof ( str ) * CHAR_BIT; i++ )
142 if ( !ammunition_is_zero_bit_string ( str, i,
143 sizeof ( str ) * CHAR_BIT - i ) )
144 result = 1;
145
146 /* Test 3 */
147 ammunition_reset_str_bits( str, str1 );
148
149 _Pragma( "loopbound min 42 max 42" )
150 for ( i = 0; i + i / 2 + 1 < sizeof ( str ) * CHAR_BIT; i++ ) {
151 ammunition_bit_string_set ( str, i, 1, i / 2 + 1 );
152 if ( !ammunition_is_zero_bit_string ( str, 0, i - 1 ) )
153 result = 1;
154 if ( ammunition_is_zero_bit_string ( str, i, i / 2 + 1 ) )
155 result = 1;
156 if ( !ammunition_is_zero_bit_string (
157 str, i + i / 2 + 1, sizeof ( str ) * CHAR_BIT - ( i + i / 2 + 1 ) ) )
158 result = 1;
159 ammunition_bit_string_set ( str, 0, 0, sizeof ( str ) * CHAR_BIT );
160 }
161
162 /* Test 4 */
163 ammunition_reset_str_bits( str, str1 );
164
165 ammunition_bit_string_set ( str, 2, 1, 43 );
166 ammunition_bit_string_set ( str1, 2, 1, 40 );
167 _Pragma( "loopbound min 42 max 42" )
168 for ( i = 0; i < 42; i++ )
169 if ( ammunition_bit_string_comparison ( str, i, str1, i, 42 - i ) != 0 )
170 result = 1;
171 _Pragma( "loopbound min 43 max 43" )
172 for ( i = 0; i < 43; i++ )
173 if ( ammunition_bit_string_comparison ( str, i, str1, i,
174 sizeof ( str ) * CHAR_BIT - i )
175 <= 0 )
176 result = 1;
177 _Pragma( "loopbound min 43 max 43" )
178 for ( i = 0; i < 43; i++ )
179 if ( ammunition_bit_string_comparison ( str1, i, str, i,
180 sizeof ( str ) * CHAR_BIT - i )
181 >= 0 )
182 result = 1;
183
184 /* Test 5 */
185 ammunition_reset_str_bits( str, str1 );
186
187 ammunition_bit_string_set ( str, 2, 1, 43 );
188 _Pragma( "loopbound min 59 max 59" )
189 for ( i = 0; i + 5 < sizeof ( str ) * CHAR_BIT; i++ ) {
190 ammunition_bit_string_copy ( str1, i + 5, str, i,
191 sizeof ( str ) * CHAR_BIT - i - 5 );
192 if ( ammunition_bit_string_comparison (
193 str1, i + 5, str, i, sizeof ( str ) * CHAR_BIT - i - 5 ) != 0 )
194 result = 1;
195 }
196
197 /* Test 6 */
198 ammunition_reset_str_bits( str, str1 );
199
200 ammunition_bit_string_set ( str, 2, 1, 43 );