summaryrefslogtreecommitdiffstats
path: root/baseline/source/ammunition
diff options
context:
space:
mode:
authorJoshua Bakita <bakitajoshua@gmail.com>2019-10-07 19:13:39 -0400
committerJoshua Bakita <bakitajoshua@gmail.com>2019-10-07 19:13:39 -0400
commit386b7d3366f1359a265da207a9cafa3edf553b64 (patch)
treec76120c2c138faed822e4ae386be6ef22a738a78 /baseline/source/ammunition
parent54a3f7091a2146b29c73a6fdc4b62a5c4ad7a3d8 (diff)
Reorganize and commit all the modified TACLeBench code and run scripts
Diffstat (limited to 'baseline/source/ammunition')
-rw-r--r--baseline/source/ammunition/ChangeLog.txt66
-rw-r--r--baseline/source/ammunition/README86
-rw-r--r--baseline/source/ammunition/ammunition.c1185
-rw-r--r--baseline/source/ammunition/ammunitionTimed.txt100
-rw-r--r--baseline/source/ammunition/ammunition_libc.c166
-rw-r--r--baseline/source/ammunition/ammunition_limits.h35
-rw-r--r--baseline/source/ammunition/ammunition_stdio.h8
-rw-r--r--baseline/source/ammunition/ammunition_stdlib.h6
-rw-r--r--baseline/source/ammunition/ammunition_string.h18
-rw-r--r--baseline/source/ammunition/arithm.c1384
-rw-r--r--baseline/source/ammunition/arithm.h123
-rw-r--r--baseline/source/ammunition/bits.c313
-rw-r--r--baseline/source/ammunition/bits.h60
-rw-r--r--baseline/source/ammunition/gmon.outbin0 -> 31048 bytes
-rw-r--r--baseline/source/ammunition/timeScript8
15 files changed, 3558 insertions, 0 deletions
diff --git a/baseline/source/ammunition/ChangeLog.txt b/baseline/source/ammunition/ChangeLog.txt
new file mode 100644
index 0000000..814ed86
--- /dev/null
+++ b/baseline/source/ammunition/ChangeLog.txt
@@ -0,0 +1,66 @@
1File: ammunition.c
2Original provenience: DINO programming language
3
42016-03-03:
5- Add generic TACLeBench header
6- Prefix global functions with benchmark name
7- Introduce volatile result variable for return statements
8- Split code into ammunition_init and ammunition_main
9- Fix compiler warnings "array subscript is of type 'char'":
10 char => unsigned char
11- Fix compiler warnings "'&&' within '||'":
12 Place additional parentheses
13- Remove usages and comments related to the macros
14 HAVE_MEMMOVE, NDEBUG, HAVE_MEMCMP
15- Remove comment related to unused NO_TEMPLATE macro
162016-05-02:
17- Change C++ style comments to ISO C90 compliant comments
18- Avoid mixing declarations and code: move declaration of variable writePos in
19 functions ammunition_sprintf_d and ammunition_sprintf_u
20- Change datatype in function ammunition_bits_test of iteration variables i and
21 j from int to unsigned int to avoid comparison between signed and unsigned
22 integer expressions
23- Add forward declarations to ammunition.c
24- Introduce variable ammunition_result
25- Parantheses around comparison in functions ammunition_isdigit and
26 ammunition_isspace
27- Remove usage of limits.h, move definitions of limits into separate file
28 ammunition_limits.h
29- Remove unconditional assignments of variable result to zero after each test in
30 functions ammunition_bits_test and ammunition_arithm_test
31- Remove unused functions unsigned_integer_maximum, integer_minimum,
32 integer_maximum, integer_remainder
33- Remove unused declaration of function default_arithmetic_overflow_reaction
34- Remove unused variables zero_constant_itself, zero_constant
35- Remove unused declarations of functions set_unsigned_integer_overflow_reaction
36 and set_integer_overflow_reaction
37- Remove block #ifndef MAX_INTEGER_OPERAND_SIZE, set definition of
38 MAX_INTEGER_OPERAND_SIZE to 128, since this is default
392016-05-10:
40- Integrate new version of arithm library from ammunition repository from
41 dino repository on github (commit: db9cfab042c332abb234ec8d72750103010981c1),
42 which hanles arithmetic shifts by negative numbers. This change now makes all
43 test cases in ammunition.c pass. Update headers unsigned int bits => int bits
44- Remove assert statements
45- Fix memcmp implementation: dereferencing pointer was missing
46- Add loop-bound annotation to memcmp
47- Fix strcmp implementation
48- Integrate working versions of memcpy and memset from pm benchmark
49- Update signature of ammunition_memcpy to original version:
50 void *memcpy(void *dest, const void *src, size_x n);
51- Move functions from libc into separate file, introduce header files
52 ammunition_limits.h, ammunition_stdio.h, ammunition_stdlib.h,
53 ammunition_string.h
54- Fix overflow in sprintf_d: change datatype of variable 'copyOfNumber' from int
55 to long, since the negative value of INT_MIN is undefined
56 2016-05-17:
57- Remove all static declarations of global functions
58- Rename variables 'digit_number' to digit_num to keep lines below 80 characters
59- Rename op1_digit_number to op1_digit_number and op1_digit_num in function
60 'ammunition_multiply_unsigned_integer_without_overflow_reaction'
61- Rename variable 'scaled_op1_digit_number' in function
62 'ammunition_divide_unsigned_integer_without_overflow_reaction'
63- Apply code formatting with astyle
64
652017-08-18:
66- Add explicit casts to silence g++ warnings.
diff --git a/baseline/source/ammunition/README b/baseline/source/ammunition/README
new file mode 100644
index 0000000..8caddf4
--- /dev/null
+++ b/baseline/source/ammunition/README
@@ -0,0 +1,86 @@
1This directory AMMUNITION contains reusable packages on C/C++:
2`allocate', `vlobject', `objstack', `hashtab', `commline', `ticker',
3`position', `errors', `bits', `arithm', `IEEE':
4 o allocate
5 Allocating and freeing memory with automatic fixing some
6 allocation errors.
7 o vlobject
8 Work with variable length objects (VLO). Any number of bytes
9 may be added to and removed from the end of VLO. If it is
10 needed the memory allocated for storing variable length object
11 may be expanded possibly with changing the object place. But
12 between any additions of the bytes (or tailoring) the object
13 place is not changed. To decrease number of changes of the
14 object place the memory being allocated for the object is
15 longer than the current object length.
16 o objstack
17 Work with stacks of objects (OS). Work with the object on the
18 stack top is analogous to one with a variable length object.
19 One motivation for the package is the problem of growing char
20 strings in symbol tables. Memory for OS is allocated by
21 segments. A segment may contain more one objects. The most
22 recently allocated segment contains object on the top of OS.
23 If there is not sufficient free memory for the top object than
24 new segment is created and the top object is transferred into
25 the new segment, i.e. there is not any memory reallocation.
26 Therefore the top object may change its address. But other
27 objects never change address.
28 o hashtab
29 Work with hash tables. The package permits to work
30 simultaneously with several expandable hash tables. Besides
31 insertion and search of elements the elements from the hash
32 tables can be also removed. The table element can be only a
33 pointer. The size of hash tables is not fixed. The hash
34 table will be automatically expanded when its occupancy will
35 became big.
36 o position
37 Work with source code positions. The package serves to
38 support information about source positions of compiled files
39 taking all included files into account.
40 o errors
41 Output of compiler messages. The package serves output
42 one-pass or multi-pass compiler messages of various modes
43 (errors, warnings, fatal, system errors and appended messages)
44 in Unix style or for traditional listing. The package also
45 permits adequate error reporting for included files.
46 o commline
47 Work with command line. The package implements features
48 analogous to ones of public domain function `getopt'. The
49 goal of the package creation is to use more readable language
50 of command line description and to use command line
51 description as help output of program.
52 o ticker
53 Simultaneous work with several tickers (timers).
54 o bits
55 Work with bit strings (copying, moving, setting, testing,
56 comparison).
57 o arithm
58 Implementing host machine-independently arbitrary precision
59 integer numbers arithmetic. The implementation of the package
60 functions are not sufficiently efficient in order to use for
61 run-time. The package functions are oriented to implement
62 constant-folding in compilers, cross-compilers.
63 o IEEE
64 Implementing host machine-independently IEEE floating point
65 arithmetic. The implementation of the package functions are
66 not sufficiently efficient in order to use for run-time. The
67 package functions are oriented to implement constant-folding
68 in compilers, cross-compilers.
69
70 There are files with corresponding names and extensions `.h'
71(interface file for C/C++), `.c' (implementation file on C), and
72`.cpp' (implementation file on C++).
73
74 To install AMMUNITION see file INSTALL in the current directory.
75
76 There are also shell scripts for testing the package with
77corresponding names and extension `.tst'. Documentation of the
78reusable packages is in files `ammunition.txt', `ammunition.dvi',
79`ammunition.ps', `ammunition.info*', `ammunition*.html',
80`ammunition*.rtf' for C and `ammunition++.txt', `ammunition++.dvi',
81`ammunition++.ps', `ammunition++.info*', `ammunition++*.html',
82`ammunition++*.rtf'.
83
84Please send bug reports and comments to vmakarov@fnmail.com
85
86Vladimir Makarov
diff --git a/baseline/source/ammunition/ammunition.c b/baseline/source/ammunition/ammunition.c
new file mode 100644
index 0000000..224babd
--- /dev/null
+++ b/baseline/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 );
201 ammunition_bit_string_set ( str1, 2, 1, 43 );
202 _Pragma( "loopbound min 59 max 59" )
203 for ( i = 0; i + 5 < sizeof ( str ) * CHAR_BIT; i++ ) {
204 ammunition_bit_string_set ( str, 0, 0, sizeof ( str ) * CHAR_BIT );
205 ammunition_bit_string_set ( str, 2, 1, 43 );
206 ammunition_bit_string_move ( str, i + 5, str, i,
207 sizeof ( str ) * CHAR_BIT - i - 5 );
208 if ( ammunition_bit_string_comparison (
209 str, i + 5, str1, i, sizeof ( str ) * CHAR_BIT - i - 5 ) != 0 )
210 result = 1;
211 }
212
213 /* Test 7 */
214 ammunition_reset_str_bits( str, str1 );
215
216 ammunition_bit_string_set ( str, 2, 1, 43 );
217 ammunition_bit_string_set ( str1, 2, 1, 43 );
218 _Pragma( "loopbound min 59 max 59" )
219 for ( i = 0; i + 5 < sizeof ( str ) * CHAR_BIT; i++ ) {
220 ammunition_bit_string_set ( str, 0, 0, sizeof ( str ) * CHAR_BIT );
221 ammunition_bit_string_set ( str, 2, 1, 43 );
222 ammunition_bit_string_move ( str, i, str, i + 5,
223 sizeof ( str ) * CHAR_BIT - i - 5 );
224 if ( ammunition_bit_string_comparison (
225 str, i, str1, i + 5, sizeof ( str ) * CHAR_BIT - i - 5 ) != 0 )
226 result = 1;
227 }
228
229 return result;
230}
231
232
233int ammunition_arithm_test()
234{
235 int result = 0;
236
237 /* Test 1 */
238 int i;
239 char str [20], s[20], d[4], e[4], g[6];
240
241 ammunition_integer_from_string ( 4, "-2147483649", d );
242 if ( !ammunition_overflow_bit )
243 result = 1;
244 ammunition_sprintf_d( str, INT_MIN );
245 ammunition_integer_from_string ( 4, str, d );
246 if ( ammunition_overflow_bit )
247 result = 1;
248 ammunition_integer_to_string( 4, d, s );
249 if ( ammunition_strcmp ( s, str ) != 0 )
250 result = 1;
251 ammunition_integer_from_string ( 4, "2147483648", d );
252 if ( !ammunition_overflow_bit )
253 result = 1;
254 ammunition_sprintf_d( str, INT_MAX );
255 ammunition_integer_from_string ( 4, str, d );
256 if ( ammunition_overflow_bit )
257 result = 1;
258 ammunition_integer_to_string( 4, d, s );
259 if ( ammunition_strcmp ( s, str ) != 0 )
260 result = 1;
261 _Pragma( "loopbound min 4000 max 4000" )
262 for ( i = -2000; i < 2000 ; i++ ) {
263 ammunition_sprintf_d( str, i );
264 ammunition_integer_from_string ( 4, str, d );
265 if ( ammunition_overflow_bit )
266 result = 1;
267 ammunition_integer_to_string( 4, d, s );
268 if ( ammunition_strcmp ( s, str ) != 0 )
269 result = 1;
270 }
271
272 /* Test 2 */
273 ammunition_reset_str_arithm( str, s, d, e, g );
274
275 ammunition_unsigned_integer_from_string ( 4, "4294967296", d );
276 if ( !ammunition_overflow_bit )
277 result = 1;
278 ammunition_sprintf_u( str, UINT_MAX );
279 ammunition_unsigned_integer_from_string ( 4, str, d );
280 if ( ammunition_overflow_bit )
281 result = 1;
282 ammunition_unsigned_integer_to_string ( 4, d, s );
283 if ( ammunition_strcmp ( s, str ) != 0 )
284 result = 1;
285 _Pragma( "loopbound min 4000 max 4000" )
286 for ( i = 0; i < 4000 ; i++ ) {
287 ammunition_sprintf_u( str, i );
288 ammunition_unsigned_integer_from_string ( 4, str, d );
289 if ( ammunition_overflow_bit )
290 result = 1;
291 ammunition_unsigned_integer_to_string ( 4, d, s );
292 if ( ammunition_strcmp ( s, str ) != 0 )
293 result = 1;
294 }
295
296 /* Test 3 */
297 ammunition_reset_str_arithm( str, s, d, e, g );
298
299 ammunition_sprintf_d( str, INT_MAX );
300 ammunition_integer_from_string ( 4, str, d );
301 ammunition_integer_from_string ( 4, "1", e );
302 ammunition_add_integer ( 4, d, e, d );
303 if ( !ammunition_overflow_bit )
304 result = 1;
305 ammunition_sprintf_d( str, INT_MAX - 4 );
306 ammunition_integer_from_string ( 4, str, d );
307 ammunition_sprintf_d( str, 4 );
308 ammunition_integer_from_string ( 4, str, e );
309 ammunition_add_integer ( 4, d, e, d );
310 if ( ammunition_overflow_bit )
311 result = 1;
312 ammunition_integer_to_string( 4, d, s );
313 ammunition_sprintf_d( str, INT_MAX );
314 if ( ammunition_strcmp ( s, str ) != 0 )
315 result = 1;
316 _Pragma( "loopbound min 4000 max 4000" )
317 for ( i = -2000; i < 2000 ; i++ ) {
318 ammunition_sprintf_d( str, i );
319 ammunition_integer_from_string ( 4, str, d );
320 ammunition_sprintf_d( str, i + 1 );
321 ammunition_integer_from_string ( 4, str, e );
322 ammunition_add_integer ( 4, d, e, d );
323 if ( ammunition_overflow_bit )
324 result = 1;
325 ammunition_integer_to_string( 4, d, s );
326 if ( ammunition_atoi ( s ) != i + i + 1 )
327 result = 1;
328 }
329
330 /* Test 4 */
331 ammunition_reset_str_arithm( str, s, d, e, g );
332
333 ammunition_sprintf_u( str, UINT_MAX );
334 ammunition_unsigned_integer_from_string ( 4, str, d );
335 ammunition_unsigned_integer_from_string ( 4, "1", e );
336 ammunition_add_unsigned_integer ( 4, d, e, d );
337 if ( !ammunition_overflow_bit )
338 result = 1;
339 ammunition_sprintf_u( str, UINT_MAX - 4 );
340 ammunition_unsigned_integer_from_string ( 4, str, d );
341 ammunition_sprintf_u( str, 4 );
342 ammunition_unsigned_integer_from_string ( 4, str, e );
343 ammunition_add_unsigned_integer ( 4, d, e, d );
344 if ( ammunition_overflow_bit )
345 result = 1;
346 ammunition_unsigned_integer_to_string ( 4, d, s );
347 ammunition_sprintf_u( str, UINT_MAX );
348 if ( ammunition_strcmp ( s, str ) != 0 )
349 result = 1;
350 _Pragma( "loopbound min 4000 max 4000" )
351 for ( i = 0; i < 4000 ; i++ ) {
352 ammunition_sprintf_u( str, i );
353 ammunition_unsigned_integer_from_string ( 4, str, d );
354 ammunition_sprintf_u( str, i + 1 );
355 ammunition_unsigned_integer_from_string ( 4, str, e );
356 ammunition_add_unsigned_integer ( 4, d, e, d );
357 if ( ammunition_overflow_bit )
358 result = 1;
359 ammunition_unsigned_integer_to_string ( 4, d, s );
360 if ( ammunition_atoi ( s ) != i + i + 1 )
361 result = 1;
362 }
363
364 /* Test 5 */
365 ammunition_reset_str_arithm( str, s, d, e, g );
366
367 ammunition_sprintf_d( str, INT_MIN );
368 ammunition_integer_from_string ( 4, str, d );
369 ammunition_integer_from_string ( 4, "1", e );
370 ammunition_subtract_integer ( 4, d, e, d );
371 if ( !ammunition_overflow_bit )
372 result = 1;
373 ammunition_sprintf_d( str, INT_MIN + 4 );
374 ammunition_integer_from_string ( 4, str, d );
375 ammunition_sprintf_d( str, 4 );
376 ammunition_integer_from_string ( 4, str, e );
377 ammunition_subtract_integer ( 4, d, e, d );
378 if ( ammunition_overflow_bit )
379 result = 1;
380 ammunition_integer_to_string( 4, d, s );
381 ammunition_sprintf_d( str, INT_MIN );
382 if ( ammunition_strcmp ( s, str ) != 0 )
383 result = 1;
384 _Pragma( "loopbound min 4000 max 4000" )
385 for ( i = -2000; i < 2000 ; i++ ) {
386 ammunition_sprintf_d( str, i );
387 ammunition_integer_from_string ( 4, str, d );
388 ammunition_sprintf_d( str, 10 - i );
389 ammunition_integer_from_string ( 4, str, e );
390 ammunition_subtract_integer ( 4, d, e, d );
391 if ( ammunition_overflow_bit )
392 result = 1;
393 ammunition_integer_to_string( 4, d, s );
394 if ( ammunition_atoi ( s ) != i + i - 10 )
395 result = 1;
396 }
397
398 /* Test 6 */
399 ammunition_reset_str_arithm( str, s, d, e, g );
400
401 ammunition_sprintf_u( str, UINT_MAX - 2 );
402 ammunition_unsigned_integer_from_string ( 4, str, d );
403 ammunition_sprintf_u( str, UINT_MAX - 1 );
404 ammunition_unsigned_integer_from_string ( 4, str, e );
405 ammunition_subtract_unsigned_integer ( 4, d, e, d );
406 if ( !ammunition_overflow_bit )
407 result = 1;
408 ammunition_sprintf_u( str, UINT_MAX );
409 ammunition_unsigned_integer_from_string ( 4, str, d );
410 ammunition_subtract_unsigned_integer ( 4, d, d, d );
411 if ( ammunition_overflow_bit )
412 result = 1;
413 ammunition_unsigned_integer_to_string ( 4, d, s );
414 if ( ammunition_strcmp ( s, "0" ) != 0 )
415 result = 1;
416 _Pragma( "loopbound min 4000 max 4000" )
417 for ( i = 0; i < 4000 ; i++ ) {
418 ammunition_sprintf_u( str, i );
419 ammunition_unsigned_integer_from_string ( 4, str, d );
420 ammunition_sprintf_u( str, i / 2 );
421 ammunition_unsigned_integer_from_string ( 4, str, e );
422 ammunition_subtract_unsigned_integer ( 4, d, e, d );
423 if ( ammunition_overflow_bit )
424 result = 1;
425 ammunition_unsigned_integer_to_string ( 4, d, s );
426 if ( ammunition_atoi ( s ) != i - i / 2 )
427 result = 1;
428 }
429
430 /* Test 7 */
431 ammunition_reset_str_arithm( str, s, d, e, g );
432
433 ammunition_sprintf_d( str, INT_MAX / 2 + 1 );
434 ammunition_integer_from_string ( 4, str, d );
435 ammunition_integer_from_string ( 4, "2", e );
436 ammunition_multiply_integer ( 4, d, e, d );
437 if ( !ammunition_overflow_bit )
438 result = 1;
439 ammunition_sprintf_d( str, INT_MIN / 2 - 1 );
440 ammunition_integer_from_string ( 4, str, d );
441 ammunition_integer_from_string ( 4, "2", e );
442 ammunition_multiply_integer ( 4, d, e, d );
443 if ( !ammunition_overflow_bit )
444 result = 1;
445 ammunition_sprintf_d( str, INT_MAX / 3 );
446 ammunition_integer_from_string ( 4, str, d );
447 ammunition_sprintf_d( str, 3 );
448 ammunition_integer_from_string ( 4, str, e );
449 ammunition_multiply_integer ( 4, d, e, d );
450 if ( ammunition_overflow_bit )
451 result = 1;
452 ammunition_integer_to_string( 4, d, s );
453 ammunition_sprintf_d( str, ( INT_MAX / 3 ) * 3 );
454 if ( ammunition_strcmp ( s, str ) != 0 )
455 result = 1;
456 ammunition_sprintf_d( str, INT_MIN / 2 );
457 ammunition_integer_from_string ( 4, str, d );
458 ammunition_sprintf_d( str, 2 );
459 ammunition_integer_from_string ( 4, str, e );
460 ammunition_multiply_integer ( 4, d, e, d );
461 if ( ammunition_overflow_bit )
462 result = 1;
463 ammunition_integer_to_string( 4, d, s );
464 ammunition_sprintf_d( str, ( INT_MIN / 2 ) * 2 );
465 if ( ammunition_strcmp ( s, str ) != 0 )
466 result = 1;
467 _Pragma( "loopbound min 4000 max 4000" )
468 for ( i = -2000; i < 2000 ; i++ ) {
469 ammunition_sprintf_d( str, i );
470 ammunition_integer_from_string ( 4, str, d );
471 ammunition_sprintf_d( str, i + 1000 );
472 ammunition_integer_from_string ( 4, str, e );
473 ammunition_multiply_integer ( 4, d, e, d );
474 if ( ammunition_overflow_bit )
475 result = 1;
476 ammunition_integer_to_string( 4, d, s );
477 if ( ammunition_atoi ( s ) != i * ( i + 1000 ) )
478 result = 1;
479 }
480
481 /* Test 8 */
482 ammunition_reset_str_arithm( str, s, d, e, g );
483
484 ammunition_sprintf_u( str, UINT_MAX / 5 + 1 );
485 ammunition_unsigned_integer_from_string ( 4, str, d );
486 ammunition_sprintf_u( str, 5 );
487 ammunition_unsigned_integer_from_string ( 4, str, e );
488 ammunition_multiply_unsigned_integer ( 4, d, e, d );
489 if ( !ammunition_overflow_bit )
490 result = 1;
491 ammunition_sprintf_u( str, UINT_MAX / 2 );
492 ammunition_unsigned_integer_from_string ( 4, str, d );
493 ammunition_sprintf_u( str, 2 );
494 ammunition_unsigned_integer_from_string ( 4, str, e );
495 ammunition_multiply_unsigned_integer ( 4, d, e, d );
496 if ( ammunition_overflow_bit )
497 result = 1;
498 ammunition_unsigned_integer_to_string ( 4, d, s );
499 ammunition_sprintf_u( str, ( UINT_MAX / 2 ) * 2 );
500 if ( ammunition_strcmp ( s, str ) != 0 )
501 result = 1;
502 _Pragma( "loopbound min 4000 max 4000" )
503 for ( i = 0; i < 4000 ; i++ ) {
504 ammunition_sprintf_u( str, i );
505 ammunition_unsigned_integer_from_string ( 4, str, d );
506 ammunition_sprintf_u( str, i / 2 );
507 ammunition_unsigned_integer_from_string ( 4, str, e );
508 ammunition_multiply_unsigned_integer ( 4, d, e, d );
509 if ( ammunition_overflow_bit )
510 result = 1;
511 ammunition_unsigned_integer_to_string ( 4, d, s );
512 if ( ammunition_atoi ( s ) != i * ( i / 2 ) )
513 result = 1;
514 }
515
516 /* Test 9 */
517 ammunition_reset_str_arithm( str, s, d, e, g );
518
519 ammunition_integer_from_string ( 4, "10", d );
520 ammunition_integer_from_string ( 4, "0", e );
521 ammunition_divide_integer ( 4, d, e, d );
522 if ( !ammunition_overflow_bit )
523 result = 1;
524 _Pragma( "loopbound min 4000 max 4000" )
525 for ( i = -2000; i < 2000 ; i++ ) {
526 ammunition_sprintf_d( str, i );
527 ammunition_integer_from_string ( 4, str, d );
528 ammunition_sprintf_d( str, ( i < 0 ? - i / 20 + 1 : - i / 20 - 1 ) );
529 ammunition_integer_from_string ( 4, str, e );
530 ammunition_divide_integer ( 4, d, e, d );
531 if ( ammunition_overflow_bit )
532 result = 1;
533 ammunition_integer_to_string( 4, d, s );
534 if ( ammunition_atoi ( s ) != i / ( i < 0 ? - i / 20 + 1 : - i / 20 - 1 ) )
535 result = 1;
536 ammunition_sprintf_d( str, i );
537 ammunition_integer_from_string ( 4, str, d );
538 ammunition_divide_integer ( 4, d, e, e );
539 if ( ammunition_overflow_bit )
540 result = 1;
541 ammunition_integer_to_string( 4, e, s );
542 if ( ammunition_atoi ( s ) != i / ( i < 0 ? - i / 20 + 1 : - i / 20 - 1 ) )
543 result = 1;
544 }
545
546 /* Test 10 */
547 ammunition_reset_str_arithm( str, s, d, e, g );
548
549 ammunition_unsigned_integer_from_string ( 4, "10", d );
550 ammunition_unsigned_integer_from_string ( 4, "0", e );
551 ammunition_divide_unsigned_integer ( 4, d, e, d );
552 if ( !ammunition_overflow_bit )
553 result = 1;
554 _Pragma( "loopbound min 4000 max 4000" )
555 for ( i = 0; i < 4000 ; i++ ) {
556 ammunition_sprintf_u( str, i );
557 ammunition_unsigned_integer_from_string ( 4, str, d );
558 ammunition_sprintf_u( str, i / 20 + 1 );
559 ammunition_unsigned_integer_from_string ( 4, str, e );
560 ammunition_divide_unsigned_integer ( 4, d, e, d );
561 if ( ammunition_overflow_bit )
562 result = 1;
563 ammunition_unsigned_integer_to_string ( 4, d, s );
564 if ( ammunition_atoi ( s ) != i / ( i / 20 + 1 ) )
565 result = 1;
566 }
567
568 /* Test 11 */
569 ammunition_reset_str_arithm( str, s, d, e, g );
570
571 ammunition_unsigned_integer_from_string ( 4, "10", d );
572 ammunition_unsigned_integer_from_string ( 4, "0", e );
573 ammunition_unsigned_integer_remainder ( 4, d, e, d );
574 if ( !ammunition_overflow_bit )
575 result = 1;
576 _Pragma( "loopbound min 4000 max 4000" )
577 for ( i = 0; i < 4000 ; i++ ) {
578 ammunition_sprintf_u( str, i );
579 ammunition_unsigned_integer_from_string ( 4, str, d );
580 ammunition_sprintf_u( str, i / 20 + 1 );
581 ammunition_unsigned_integer_from_string ( 4, str, e );
582 ammunition_unsigned_integer_remainder ( 4, d, e, d );
583 if ( ammunition_overflow_bit )
584 result = 1;
585 ammunition_unsigned_integer_to_string ( 4, d, s );
586 if ( ammunition_atoi ( s ) != i % ( i / 20 + 1 ) )
587 result = 1;
588 }
589
590 /* Test 12 */
591 ammunition_reset_str_arithm( str, s, d, e, g );
592
593 ammunition_unsigned_integer_from_string ( 4, "1348", d );
594 ammunition_unsigned_integer_shift_right ( 4, d, 0, d );
595 ammunition_unsigned_integer_to_string ( 4, d, s );
596 if ( ammunition_overflow_bit || ammunition_strcmp ( s, "1348" ) != 0 )
597 result = 1;
598 ammunition_unsigned_integer_from_string ( 4, "1348", d );
599 ammunition_unsigned_integer_shift_right ( 4, d, 32, d );
600 ammunition_unsigned_integer_to_string ( 4, d, s );
601 if ( !ammunition_overflow_bit || ammunition_strcmp ( s, "0" ) != 0 )
602 result = 1;
603 ammunition_unsigned_integer_from_string ( 4, "1348", d );
604 ammunition_unsigned_integer_shift_right ( 4, d, 8, d );
605 ammunition_unsigned_integer_to_string ( 4, d, s );
606 if ( !ammunition_overflow_bit || ammunition_strcmp ( s, "5" ) != 0 )
607 result = 1;
608 ammunition_unsigned_integer_from_string ( 4, "134890", d );
609 ammunition_unsigned_integer_shift_right ( 4, d, 13, d );
610 ammunition_unsigned_integer_to_string ( 4, d, s );
611 if ( !ammunition_overflow_bit || ammunition_strcmp ( s, "16" ) != 0 )
612 result = 1;
613 ammunition_unsigned_integer_from_string ( 4, "134890", d );
614 ammunition_unsigned_integer_shift_left ( 4, d, -13, d );
615 ammunition_unsigned_integer_to_string ( 4, d, s );
616 if ( !ammunition_overflow_bit || ammunition_strcmp ( s, "16" ) != 0 )
617 result = 1;
618
619 /* Test 13 */
620 ammunition_reset_str_arithm( str, s, d, e, g );
621
622 ammunition_integer_from_string ( 4, "1348", d );
623 ammunition_integer_shift_right ( 4, d, 0, d );
624 ammunition_integer_to_string( 4, d, s );
625 if ( ammunition_overflow_bit || ammunition_strcmp ( s, "1348" ) != 0 )
626 result = 1;
627 ammunition_integer_from_string ( 4, "1348", d );
628 ammunition_integer_shift_right ( 4, d, 32, d );
629 ammunition_integer_to_string( 4, d, s );
630 if ( !ammunition_overflow_bit || ammunition_strcmp ( s, "0" ) != 0 )
631 result = 1;
632 ammunition_integer_from_string ( 4, "1348", d );
633 ammunition_integer_shift_right ( 4, d, 8, d );
634 ammunition_integer_to_string( 4, d, s );
635 if ( !ammunition_overflow_bit || ammunition_strcmp ( s, "5" ) != 0 )
636 result = 1;
637 ammunition_integer_from_string ( 4, "134890", d );
638 ammunition_integer_shift_right ( 4, d, 13, d );
639 ammunition_integer_to_string( 4, d, s );
640 if ( !ammunition_overflow_bit || ammunition_strcmp ( s, "16" ) != 0 )
641 result = 1;
642 ammunition_integer_from_string ( 4, "134890", d );
643 ammunition_integer_shift_left ( 4, d, -13, d );
644 ammunition_integer_to_string( 4, d, s );
645 if ( !ammunition_overflow_bit || ammunition_strcmp ( s, "16" ) != 0 )
646 result = 1;
647 ammunition_integer_from_string ( 4, "-1348", d );
648 ammunition_integer_shift_right ( 4, d, 0, d );
649 ammunition_integer_to_string( 4, d, s );
650 if ( ammunition_overflow_bit || ammunition_strcmp ( s, "-1348" ) != 0 )
651 result = 1;
652 ammunition_integer_from_string ( 4, "-1348", d );
653 ammunition_integer_shift_right ( 4, d, 32, d );
654 ammunition_integer_to_string( 4, d, s );
655 if ( !ammunition_overflow_bit || ammunition_strcmp ( s, "-1" ) != 0 )
656 result = 1;
657 ammunition_integer_from_string ( 4, "-1348", d );
658 ammunition_integer_shift_right ( 4, d, 8, d );
659 ammunition_integer_to_string( 4, d, s );
660 if ( !ammunition_overflow_bit || ammunition_strcmp ( s, "-6" ) != 0 )
661 result = 1;
662 ammunition_integer_from_string ( 4, "-134890", d );
663 ammunition_integer_shift_right ( 4, d, 13, d );
664 ammunition_integer_to_string( 4, d, s );
665 if ( !ammunition_overflow_bit || ammunition_strcmp ( s, "-17" ) != 0 )
666 result = 1;
667 ammunition_integer_from_string ( 4, "-134890", d );
668 ammunition_integer_shift_left ( 4, d, -13, d );
669 ammunition_integer_to_string( 4, d, s );
670 if ( !ammunition_overflow_bit || ammunition_strcmp ( s, "-17" ) != 0 )
671 result = 1;
672
673 /* Test 14 */
674 ammunition_reset_str_arithm( str, s, d, e, g );
675
676 ammunition_unsigned_integer_from_string ( 4, "1348", d );
677 ammunition_unsigned_integer_shift_left ( 4, d, 0, d );
678 ammunition_unsigned_integer_to_string ( 4, d, s );
679 if ( ammunition_overflow_bit || ammunition_strcmp ( s, "1348" ) != 0 )
680 result = 1;
681 ammunition_unsigned_integer_from_string ( 4, "1348", d );
682 ammunition_unsigned_integer_shift_left ( 4, d, 22, d );
683 if ( !ammunition_overflow_bit )
684 result = 1;
685 ammunition_unsigned_integer_from_string ( 4, "1348", d );
686 ammunition_unsigned_integer_shift_left ( 4, d, 8, d );
687 ammunition_unsigned_integer_to_string ( 4, d, s );
688 if ( ammunition_overflow_bit || ammunition_strcmp ( s, "345088" ) != 0 )
689 result = 1;
690 ammunition_unsigned_integer_from_string ( 4, "134890", d );
691 ammunition_unsigned_integer_shift_left ( 4, d, 13, d );
692 ammunition_unsigned_integer_to_string ( 4, d, s );
693 if ( ammunition_overflow_bit || ammunition_strcmp ( s, "1105018880" ) != 0 )
694 result = 1;
695 ammunition_unsigned_integer_from_string ( 4, "134890", d );
696 ammunition_unsigned_integer_shift_right ( 4, d, -13, d );
697 ammunition_unsigned_integer_to_string ( 4, d, s );
698 if ( ammunition_overflow_bit || ammunition_strcmp ( s, "1105018880" ) != 0 )
699 result = 1;
700
701 /* Test 15 */
702 ammunition_reset_str_arithm( str, s, d, e, g );
703
704 ammunition_integer_from_string ( 4, "1348", d );
705 ammunition_integer_shift_left ( 4, d, 0, d );
706 ammunition_integer_to_string( 4, d, s );
707 if ( ammunition_overflow_bit || ammunition_strcmp ( s, "1348" ) != 0 )
708 result = 1;
709 ammunition_integer_from_string ( 4, "1348", d );
710 ammunition_integer_shift_left ( 4, d, 21, d );
711 if ( !ammunition_overflow_bit )
712 result = 1;
713 ammunition_integer_from_string ( 4, "1348", d );
714 ammunition_integer_shift_left ( 4, d, 8, d );
715 ammunition_integer_to_string( 4, d, s );
716 if ( ammunition_overflow_bit || ammunition_strcmp ( s, "345088" ) != 0 )
717 result = 1;
718 ammunition_integer_from_string ( 4, "134890", d );
719 ammunition_integer_shift_left ( 4, d, 13, d );
720 ammunition_integer_to_string( 4, d, s );
721 if ( ammunition_overflow_bit || ammunition_strcmp ( s, "1105018880" ) != 0 )
722 result = 1;
723 ammunition_integer_from_string ( 4, "134890", d );
724 ammunition_integer_shift_right ( 4, d, -13, d );
725 ammunition_integer_to_string( 4, d, s );
726 if ( ammunition_overflow_bit || ammunition_strcmp ( s, "1105018880" ) != 0 )
727 result = 1;
728 ammunition_integer_from_string ( 4, "-1348", d );
729 ammunition_integer_shift_left ( 4, d, 0, d );
730 ammunition_integer_to_string( 4, d, s );
731 if ( ammunition_overflow_bit || ammunition_strcmp ( s, "-1348" ) != 0 )
732 result = 1;
733 ammunition_integer_from_string ( 4, "-1348", d );
734 ammunition_integer_shift_left ( 4, d, 21, d );
735 if ( !ammunition_overflow_bit )
736 result = 1;
737 ammunition_integer_from_string ( 4, "-1348", d );
738 ammunition_integer_shift_left ( 4, d, 8, d );
739 ammunition_integer_to_string( 4, d, s );
740 if ( ammunition_overflow_bit || ammunition_strcmp ( s, "-345088" ) != 0 )
741 result = 1;
742 ammunition_integer_from_string ( 4, "-134890", d );
743 ammunition_integer_shift_left ( 4, d, 13, d );
744 ammunition_integer_to_string( 4, d, s );
745 if ( ammunition_overflow_bit || ammunition_strcmp ( s, "-1105018880" ) != 0 )
746 result = 1;
747 ammunition_integer_from_string ( 4, "-134890", d );
748 ammunition_integer_shift_right ( 4, d, -13, d );
749 ammunition_integer_to_string( 4, d, s );
750 if ( ammunition_overflow_bit || ammunition_strcmp ( s, "-1105018880" ) != 0 )
751 result = 1;
752
753 /* Test 16 */
754 ammunition_reset_str_arithm( str, s, d, e, g );
755
756 ammunition_integer_from_string ( 4, "-10", d );
757 ammunition_integer_from_string ( 4, "1348", e );
758 if ( ammunition_eq_integer ( 4, d, e ) )
759 result = 1;
760 ammunition_integer_from_string ( 4, "-1348", d );
761 ammunition_integer_from_string ( 4, "-1348", e );
762 if ( !ammunition_eq_integer ( 4, d, e ) )
763 result = 1;
764
765 /* Test 17 */
766 ammunition_reset_str_arithm( str, s, d, e, g );
767
768 ammunition_unsigned_integer_from_string ( 4, "10", d );
769 ammunition_unsigned_integer_from_string ( 4, "1348", e );
770 if ( ammunition_eq_unsigned_integer ( 4, d, e ) )
771 result = 1;
772 ammunition_unsigned_integer_from_string ( 4, "1348", d );
773 ammunition_unsigned_integer_from_string ( 4, "1348", e );
774 if ( !ammunition_eq_unsigned_integer ( 4, d, e ) )
775 result = 1;
776
777 /* Test 18 */
778 ammunition_reset_str_arithm( str, s, d, e, g );
779
780 ammunition_integer_from_string ( 4, "-10", d );
781 ammunition_integer_from_string ( 4, "1348", e );
782 if ( !ammunition_ne_integer ( 4, d, e ) )
783 result = 1;
784 ammunition_integer_from_string ( 4, "-1348", d );
785 ammunition_integer_from_string ( 4, "-1348", e );
786 if ( ammunition_ne_integer ( 4, d, e ) )
787 result = 1;
788
789 /* Test 19 */
790 ammunition_reset_str_arithm( str, s, d, e, g );
791
792 ammunition_unsigned_integer_from_string ( 4, "10", d );
793 ammunition_unsigned_integer_from_string ( 4, "1348", e );
794 if ( !ammunition_ne_unsigned_integer ( 4, d, e ) )
795 result = 1;
796 ammunition_unsigned_integer_from_string ( 4, "1348", d );
797 ammunition_unsigned_integer_from_string ( 4, "1348", e );
798 if ( ammunition_ne_unsigned_integer ( 4, d, e ) )
799 result = 1;
800
801 /* Test 20 */
802 ammunition_reset_str_arithm( str, s, d, e, g );
803
804 ammunition_integer_from_string ( 4, "-10", d );
805 ammunition_integer_from_string ( 4, "1348", e );
806 if ( ammunition_gt_integer ( 4, d, e ) )
807 result = 1;
808 ammunition_integer_from_string ( 4, "-1348", d );
809 ammunition_integer_from_string ( 4, "-1348", e );
810 if ( ammunition_gt_integer ( 4, d, e ) )
811 result = 1;
812 ammunition_integer_from_string ( 4, "-1000000", d );
813 ammunition_integer_from_string ( 4, "-1348", e );
814 if ( ammunition_gt_integer ( 4, d, e ) )
815 result = 1;
816 ammunition_integer_from_string ( 4, "1000000", d );
817 ammunition_integer_from_string ( 4, "1348", e );
818 if ( !ammunition_gt_integer ( 4, d, e ) )
819 result = 1;
820
821 /* Test 21 */
822 ammunition_reset_str_arithm( str, s, d, e, g );
823
824 ammunition_unsigned_integer_from_string ( 4, "10", d );
825 ammunition_unsigned_integer_from_string ( 4, "1348", e );
826 if ( ammunition_gt_unsigned_integer ( 4, d, e ) )
827 result = 1;
828 ammunition_unsigned_integer_from_string ( 4, "1348", d );
829 ammunition_unsigned_integer_from_string ( 4, "1348", e );
830 if ( ammunition_gt_unsigned_integer ( 4, d, e ) )
831 result = 1;
832 ammunition_unsigned_integer_from_string ( 4, "1000000", d );
833 ammunition_unsigned_integer_from_string ( 4, "1348", e );
834 if ( !ammunition_gt_unsigned_integer ( 4, d, e ) )
835 result = 1;
836
837 /* Test 22 */
838 ammunition_reset_str_arithm( str, s, d, e, g );
839
840 ammunition_integer_from_string ( 4, "-10", d );
841 ammunition_integer_from_string ( 4, "1348", e );
842 if ( !ammunition_lt_integer ( 4, d, e ) )
843 result = 1;
844 ammunition_integer_from_string ( 4, "-1348", d );
845 ammunition_integer_from_string ( 4, "-1348", e );
846 if ( ammunition_lt_integer ( 4, d, e ) )
847 result = 1;
848 ammunition_integer_from_string ( 4, "-1000000", d );
849 ammunition_integer_from_string ( 4, "-1348", e );
850 if ( !ammunition_lt_integer ( 4, d, e ) )
851 result = 1;
852 ammunition_integer_from_string ( 4, "1000000", d );
853 ammunition_integer_from_string ( 4, "1348", e );
854 if ( ammunition_lt_integer ( 4, d, e ) )
855 result = 1;
856
857 /* Test 23 */
858 ammunition_reset_str_arithm( str, s, d, e, g );
859
860 ammunition_unsigned_integer_from_string ( 4, "10", d );
861 ammunition_unsigned_integer_from_string ( 4, "1348", e );
862 if ( !ammunition_lt_unsigned_integer ( 4, d, e ) )
863 result = 1;
864 ammunition_unsigned_integer_from_string ( 4, "1348", d );
865 ammunition_unsigned_integer_from_string ( 4, "1348", e );
866 if ( ammunition_lt_unsigned_integer ( 4, d, e ) )
867 result = 1;
868 ammunition_unsigned_integer_from_string ( 4, "1000000", d );
869 ammunition_unsigned_integer_from_string ( 4, "1348", e );
870 if ( ammunition_lt_unsigned_integer ( 4, d, e ) )
871 result = 1;
872
873 /* Test 24 */
874 ammunition_reset_str_arithm( str, s, d, e, g );
875
876 ammunition_integer_from_string ( 4, "-10", d );
877 ammunition_integer_from_string ( 4, "1348", e );
878 if ( ammunition_ge_integer ( 4, d, e ) )
879 result = 1;
880 ammunition_integer_from_string ( 4, "-1348", d );
881 ammunition_integer_from_string ( 4, "-1348", e );
882 if ( !ammunition_ge_integer ( 4, d, e ) )
883 result = 1;
884 ammunition_integer_from_string ( 4, "-1000000", d );
885 ammunition_integer_from_string ( 4, "-1348", e );
886 if ( ammunition_ge_integer ( 4, d, e ) )
887 result = 1;
888 ammunition_integer_from_string ( 4, "1000000", d );
889 ammunition_integer_from_string ( 4, "1348", e );
890 if ( !ammunition_ge_integer ( 4, d, e ) )
891 result = 1;
892
893 /* Test 25 */
894 ammunition_reset_str_arithm( str, s, d, e, g );
895
896 ammunition_unsigned_integer_from_string ( 4, "10", d );
897 ammunition_unsigned_integer_from_string ( 4, "1348", e );
898 if ( ammunition_ge_unsigned_integer ( 4, d, e ) )
899 result = 1;
900 ammunition_unsigned_integer_from_string ( 4, "1348", d );
901 ammunition_unsigned_integer_from_string ( 4, "1348", e );
902 if ( !ammunition_ge_unsigned_integer ( 4, d, e ) )
903 result = 1;
904 ammunition_unsigned_integer_from_string ( 4, "1000000", d );
905 ammunition_unsigned_integer_from_string ( 4, "1348", e );
906 if ( !ammunition_ge_unsigned_integer ( 4, d, e ) )
907 result = 1;
908
909 /* Test 26 */
910 ammunition_reset_str_arithm( str, s, d, e, g );
911
912 ammunition_integer_from_string ( 4, "-10", d );
913 ammunition_integer_from_string ( 4, "1348", e );
914 if ( !ammunition_le_integer ( 4, d, e ) )
915 result = 1;
916 ammunition_integer_from_string ( 4, "-1348", d );
917 ammunition_integer_from_string ( 4, "-1348", e );
918 if ( !ammunition_le_integer ( 4, d, e ) )
919 result = 1;
920 ammunition_integer_from_string ( 4, "-1000000", d );
921 ammunition_integer_from_string ( 4, "-1348", e );
922 if ( !ammunition_le_integer ( 4, d, e ) )
923 result = 1;
924 ammunition_integer_from_string ( 4, "1000000", d );
925 ammunition_integer_from_string ( 4, "1348", e );
926 if ( ammunition_le_integer ( 4, d, e ) )
927 result = 1;
928
929 /* Test 27 */
930 ammunition_reset_str_arithm( str, s, d, e, g );
931
932 ammunition_unsigned_integer_from_string ( 4, "10", d );
933 ammunition_unsigned_integer_from_string ( 4, "1348", e );
934 if ( !ammunition_le_unsigned_integer ( 4, d, e ) )
935 result = 1;
936 ammunition_unsigned_integer_from_string ( 4, "1348", d );
937 ammunition_unsigned_integer_from_string ( 4, "1348", e );
938 if ( !ammunition_le_unsigned_integer ( 4, d, e ) )
939 result = 1;
940 ammunition_unsigned_integer_from_string ( 4, "1000000", d );
941 ammunition_unsigned_integer_from_string ( 4, "1348", e );
942 if ( ammunition_le_unsigned_integer ( 4, d, e ) )
943 result = 1;
944
945 /* Test 28 */
946 ammunition_reset_str_arithm( str, s, d, e, g );
947
948 ammunition_unsigned_integer_from_string ( 4, "70000", d );
949 ammunition_change_unsigned_integer_size ( 4, d, 2, d );
950 if ( !ammunition_overflow_bit )
951 result = 1;
952 ammunition_unsigned_integer_from_string ( 4, "30000", d );
953 ammunition_change_unsigned_integer_size ( 4, d, 2, d );
954 ammunition_integer_to_string( 2, d, s );
955 if ( ammunition_overflow_bit || ammunition_strcmp ( s, "30000" ) != 0 )
956 result = 1;
957 ammunition_unsigned_integer_from_string ( 4, "11230000", g );
958 ammunition_change_unsigned_integer_size ( 4, g, 6, g );
959 ammunition_integer_to_string( 6, g, s );
960 if ( ammunition_overflow_bit || ammunition_strcmp ( s, "11230000" ) != 0 )
961 result = 1;
962
963 /* Test 29 */
964 ammunition_reset_str_arithm( str, s, d, e, g );
965
966 ammunition_integer_from_string ( 4, "40000", d );
967 ammunition_change_integer_size ( 4, d, 2, d );
968 if ( !ammunition_overflow_bit )
969 result = 1;
970 ammunition_integer_from_string ( 4, "-33000", d );
971 ammunition_change_integer_size ( 4, d, 2, d );
972 if ( !ammunition_overflow_bit )
973 result = 1;
974 ammunition_integer_from_string ( 4, "30000", d );
975 ammunition_change_integer_size ( 4, d, 2, d );
976 ammunition_integer_to_string( 2, d, s );
977 if ( ammunition_overflow_bit || ammunition_strcmp ( s, "30000" ) != 0 )
978 result = 1;
979 ammunition_integer_from_string ( 4, "-30000", d );
980 ammunition_change_integer_size ( 4, d, 2, d );
981 ammunition_integer_to_string( 2, d, s );
982 if ( ammunition_overflow_bit || ammunition_strcmp ( s, "-30000" ) != 0 )
983 result = 1;
984 ammunition_integer_from_string ( 4, "11230000", g );
985 ammunition_change_integer_size ( 4, g, 6, g );
986 ammunition_integer_to_string( 6, g, s );
987 if ( ammunition_overflow_bit || ammunition_strcmp ( s, "11230000" ) != 0 )
988 result = 1;
989 ammunition_integer_from_string ( 4, "-11230000", g );
990 ammunition_change_integer_size ( 4, g, 6, g );
991 ammunition_integer_to_string( 6, g, s );
992 if ( ammunition_overflow_bit || ammunition_strcmp ( s, "-11230000" ) != 0 )
993 result = 1;
994
995 /* Test 30 */
996 ammunition_reset_str_arithm( str, s, d, e, g );
997
998 ammunition_unsigned_integer_from_string ( 4, "1348", d );
999 ammunition_unsigned_integer_from_string ( 4, "1348", e );
1000 ammunition_unsigned_integer_or ( 4, d, e, e );
1001 ammunition_unsigned_integer_to_string ( 4, e, s );
1002 if ( ammunition_strcmp ( s, "1348" ) != 0 )
1003 result = 1;
1004 ammunition_unsigned_integer_from_string ( 4, "1348", d );
1005 ammunition_unsigned_integer_from_string ( 4, "0", e );
1006 ammunition_unsigned_integer_or ( 4, d, e, e );
1007 ammunition_unsigned_integer_to_string ( 4, e, s );
1008 if ( ammunition_strcmp ( s, "1348" ) != 0 )
1009 result = 1;
1010 ammunition_unsigned_integer_from_string ( 4, "1348", d );
1011 ammunition_unsigned_integer_from_string ( 4, "4294967295", e );
1012 ammunition_unsigned_integer_or ( 4, d, e, e );
1013 ammunition_unsigned_integer_to_string ( 4, e, s );
1014 if ( ammunition_strcmp ( s, "4294967295" ) != 0 )
1015 result = 1;
1016 ammunition_unsigned_integer_from_string ( 4, "1348", d );
1017 ammunition_unsigned_integer_from_string ( 4, "96", e );
1018 ammunition_unsigned_integer_or ( 4, d, e, e );
1019 ammunition_unsigned_integer_to_string ( 4, e, s );
1020 if ( ammunition_strcmp ( s, "1380" ) != 0 )
1021 result = 1;
1022
1023 /* Test 31 */
1024 ammunition_reset_str_arithm( str, s, d, e, g );
1025
1026 ammunition_integer_from_string ( 4, "1348", d );
1027 ammunition_integer_from_string ( 4, "1348", e );
1028 ammunition_integer_or ( 4, d, e, e );
1029 ammunition_integer_to_string( 4, e, s );
1030 if ( ammunition_strcmp ( s, "1348" ) != 0 )
1031 result = 1;
1032 ammunition_integer_from_string ( 4, "1348", d );
1033 ammunition_integer_from_string ( 4, "0", e );
1034 ammunition_integer_or ( 4, d, e, e );
1035 ammunition_integer_to_string( 4, e, s );
1036 if ( ammunition_strcmp ( s, "1348" ) != 0 )
1037 result = 1;
1038 ammunition_integer_from_string ( 4, "1348", d );
1039 ammunition_integer_from_string ( 4, "-1", e );
1040 ammunition_integer_or ( 4, d, e, e );
1041 ammunition_integer_to_string( 4, e, s );
1042 if ( ammunition_strcmp ( s, "-1" ) != 0 )
1043 result = 1;
1044 ammunition_integer_from_string ( 4, "1348", d );
1045 ammunition_integer_from_string ( 4, "96", e );
1046 ammunition_integer_or ( 4, d, e, e );
1047 ammunition_integer_to_string( 4, e, s );
1048 if ( ammunition_strcmp ( s, "1380" ) != 0 )
1049 result = 1;
1050
1051 /* Test 32 */
1052 ammunition_reset_str_arithm( str, s, d, e, g );
1053
1054 ammunition_unsigned_integer_from_string ( 4, "1348", d );
1055 ammunition_unsigned_integer_from_string ( 4, "1348", e );
1056 ammunition_unsigned_integer_and ( 4, d, e, e );
1057 ammunition_unsigned_integer_to_string ( 4, e, s );
1058 if ( ammunition_strcmp ( s, "1348" ) != 0 )
1059 result = 1;
1060 ammunition_unsigned_integer_from_string ( 4, "1348", d );
1061 ammunition_unsigned_integer_from_string ( 4, "0", e );
1062 ammunition_unsigned_integer_and ( 4, d, e, e );
1063 ammunition_unsigned_integer_to_string ( 4, e, s );
1064 if ( ammunition_strcmp ( s, "0" ) != 0 )
1065 result = 1;
1066 ammunition_unsigned_integer_from_string ( 4, "1348", d );
1067 ammunition_unsigned_integer_from_string ( 4, "4294967295", e );
1068 ammunition_unsigned_integer_and ( 4, d, e, e );
1069 ammunition_unsigned_integer_to_string ( 4, e, s );
1070 if ( ammunition_strcmp ( s, "1348" ) != 0 )
1071 result = 1;
1072 ammunition_unsigned_integer_from_string ( 4, "1348", d );
1073 ammunition_unsigned_integer_from_string ( 4, "96", e );
1074 ammunition_unsigned_integer_and ( 4, d, e, e );
1075 ammunition_unsigned_integer_to_string ( 4, e, s );
1076 if ( ammunition_strcmp ( s, "64" ) != 0 )
1077 result = 1;
1078
1079 /* Test 33 */
1080 ammunition_reset_str_arithm( str, s, d, e, g );
1081
1082 ammunition_integer_from_string ( 4, "1348", d );
1083 ammunition_integer_from_string ( 4, "1348", e );
1084 ammunition_integer_and ( 4, d, e, e );
1085 ammunition_integer_to_string( 4, e, s );
1086 if ( ammunition_strcmp ( s, "1348" ) != 0 )
1087 result = 1;
1088 ammunition_integer_from_string ( 4, "1348", d );
1089 ammunition_integer_from_string ( 4, "0", e );
1090 ammunition_integer_and ( 4, d, e, e );
1091 ammunition_integer_to_string( 4, e, s );
1092 if ( ammunition_strcmp ( s, "0" ) != 0 )
1093 result = 1;
1094 ammunition_integer_from_string ( 4, "1348", d );
1095 ammunition_integer_from_string ( 4, "-1", e );
1096 ammunition_integer_and ( 4, d, e, e );
1097 ammunition_integer_to_string( 4, e, s );
1098 if ( ammunition_strcmp ( s, "1348" ) != 0 )
1099 result = 1;
1100 ammunition_integer_from_string ( 4, "1348", d );
1101 ammunition_integer_from_string ( 4, "96", e );
1102 ammunition_integer_and ( 4, d, e, e );
1103 ammunition_integer_to_string( 4, e, s );
1104 if ( ammunition_strcmp ( s, "64" ) != 0 )
1105 result = 1;
1106
1107 /* Test 34 */
1108 ammunition_reset_str_arithm( str, s, d, e, g );
1109
1110 ammunition_unsigned_integer_from_string ( 4, "1348", d );
1111 ammunition_unsigned_integer_not ( 4, d, d );
1112 ammunition_unsigned_integer_to_string ( 4, d, s );
1113 if ( ammunition_strcmp ( s, "4294965947" ) != 0 )
1114 result = 1;
1115 ammunition_unsigned_integer_from_string ( 4, "0", d );
1116 ammunition_unsigned_integer_not ( 4, d, d );
1117 ammunition_unsigned_integer_to_string ( 4, d, s );
1118 if ( ammunition_strcmp ( s, "4294967295" ) != 0 )
1119 result = 1;
1120 ammunition_unsigned_integer_from_string ( 4, "4294967295", d );
1121 ammunition_unsigned_integer_not ( 4, d, d );
1122 ammunition_unsigned_integer_to_string ( 4, d, s );
1123 if ( ammunition_strcmp ( s, "0" ) != 0 )
1124 result = 1;
1125
1126 /* Test 35 */
1127 ammunition_reset_str_arithm( str, s, d, e, g );
1128
1129 ammunition_integer_from_string ( 4, "1348", d );
1130 ammunition_integer_not ( 4, d, d );
1131 ammunition_integer_to_string( 4, d, s );
1132 if ( ammunition_strcmp ( s, "-1349" ) != 0 )
1133 result = 1;
1134 ammunition_integer_from_string ( 4, "0", d );
1135 ammunition_integer_not ( 4, d, d );
1136 ammunition_integer_to_string( 4, d, s );
1137 if ( ammunition_strcmp ( s, "-1" ) != 0 )
1138 result = 1;
1139 ammunition_integer_from_string ( 4, "-1", d );
1140 ammunition_integer_not ( 4, d, d );
1141 ammunition_integer_to_string( 4, d, s );
1142 if ( ammunition_strcmp ( s, "0" ) != 0 )
1143 result = 1;
1144
1145 return result;
1146}
1147
1148
1149/*
1150 Initialization- and return-value-related functions
1151*/
1152
1153void ammunition_init( void )
1154{
1155 ammunition_result = 0;
1156}
1157
1158int ammunition_return( void )
1159{
1160 return ammunition_result;
1161}
1162
1163/*
1164 Main functions
1165*/
1166
1167void _Pragma( "entrypoint" ) ammunition_main( void )
1168{
1169 ammunition_result |= ammunition_bits_test();
1170 ammunition_result |= ammunition_arithm_test();
1171}
1172
1173
1174int main( int argc, char **argv )
1175{
1176 SET_UP
1177 for (jobsComplete=-1; jobsComplete<maxJobs; jobsComplete++){
1178 START_LOOP
1179 ammunition_init();
1180 ammunition_main();
1181 STOP_LOOP
1182 }
1183 WRITE_TO_FILE
1184 return ( ammunition_return() );
1185}
diff --git a/baseline/source/ammunition/ammunitionTimed.txt b/baseline/source/ammunition/ammunitionTimed.txt
new file mode 100644
index 0000000..b49784b
--- /dev/null
+++ b/baseline/source/ammunition/ammunitionTimed.txt
@@ -0,0 +1,100 @@
1ammunition none 7 none 100 52370648 ammunitionTimed 0 (null)
2ammunition none 7 none 100 52473247 ammunitionTimed 1 (null)
3ammunition none 7 none 100 52317008 ammunitionTimed 2 (null)
4ammunition none 7 none 100 52427850 ammunitionTimed 3 (null)
5ammunition none 7 none 100 52418211 ammunitionTimed 4 (null)
6ammunition none 7 none 100 52452295 ammunitionTimed 5 (null)
7ammunition none 7 none 100 52400750 ammunitionTimed 6 (null)
8ammunition none 7 none 100 52491197 ammunitionTimed 7 (null)
9ammunition none 7 none 100 52383220 ammunitionTimed 8 (null)
10ammunition none 7 none 100 52455367 ammunitionTimed 9 (null)
11ammunition none 7 none 100 52359403 ammunitionTimed 10 (null)
12ammunition none 7 none 100 52366038 ammunitionTimed 11 (null)
13ammunition none 7 none 100 52373652 ammunitionTimed 12 (null)
14ammunition none 7 none 100 52349625 ammunitionTimed 13 (null)
15ammunition none 7 none 100 52418910 ammunitionTimed 14 (null)
16ammunition none 7 none 100 52359124 ammunitionTimed 15 (null)
17ammunition none 7 none 100 52403265 ammunitionTimed 16 (null)
18ammunition none 7 none 100 52403055 ammunitionTimed 17 (null)
19ammunition none 7 none 100 52355073 ammunitionTimed 18 (null)
20ammunition none 7 none 100 52359473 ammunitionTimed 19 (null)
21ammunition none 7 none 100 52337402 ammunitionTimed 20 (null)
22ammunition none 7 none 100 52367365 ammunitionTimed 21 (null)
23ammunition none 7 none 100 52290188 ammunitionTimed 22 (null)
24ammunition none 7 none 100 52308907 ammunitionTimed 23 (null)
25ammunition none 7 none 100 52417792 ammunitionTimed 24 (null)
26ammunition none 7 none 100 52284112 ammunitionTimed 25 (null)
27ammunition none 7 none 100 52490150 ammunitionTimed 26 (null)
28ammunition none 7 none 100 52386712 ammunitionTimed 27 (null)
29ammunition none 7 none 100 52323504 ammunitionTimed 28 (null)
30ammunition none 7 none 100 52339289 ammunitionTimed 29 (null)
31ammunition none 7 none 100 52340825 ammunitionTimed 30 (null)
32ammunition none 7 none 100 52367296 ammunitionTimed 31 (null)
33ammunition none 7 none 100 52336146 ammunitionTimed 32 (null)
34ammunition none 7 none 100 52374210 ammunitionTimed 33 (null)
35ammunition none 7 none 100 52414021 ammunitionTimed 34 (null)
36ammunition none 7 none 100 52441748 ammunitionTimed 35 (null)
37ammunition none 7 none 100 52366458 ammunitionTimed 36 (null)
38ammunition none 7 none 100 52371905 ammunitionTimed 37 (null)
39ammunition none 7 none 100 52367086 ammunitionTimed 38 (null)
40ammunition none 7 none 100 52324622 ammunitionTimed 39 (null)
41ammunition none 7 none 100 52381543 ammunitionTimed 40 (null)
42ammunition none 7 none 100 52295707 ammunitionTimed 41 (null)
43ammunition none 7 none 100 52346692 ammunitionTimed 42 (null)
44ammunition none 7 none 100 52314983 ammunitionTimed 43 (null)
45ammunition none 7 none 100 52349625 ammunitionTimed 44 (null)
46ammunition none 7 none 100 52466123 ammunitionTimed 45 (null)
47ammunition none 7 none 100 52374629 ammunitionTimed 46 (null)
48ammunition none 7 none 100 52358006 ammunitionTimed 47 (null)
49ammunition none 7 none 100 52392369 ammunitionTimed 48 (null)
50ammunition none 7 none 100 52480232 ammunitionTimed 49 (null)
51ammunition none 7 none 100 52368203 ammunitionTimed 50 (null)
52ammunition none 7 none 100 52430364 ammunitionTimed 51 (null)
53ammunition none 7 none 100 52342502 ammunitionTimed 52 (null)
54ammunition none 7 none 100 52345504 ammunitionTimed 53 (null)
55ammunition none 7 none 100 52495388 ammunitionTimed 54 (null)
56ammunition none 7 none 100 52344107 ammunitionTimed 55 (null)
57ammunition none 7 none 100 52388109 ammunitionTimed 56 (null)
58ammunition none 7 none 100 52431760 ammunitionTimed 57 (null)
59ammunition none 7 none 100 52364712 ammunitionTimed 58 (null)
60ammunition none 7 none 100 52337473 ammunitionTimed 59 (null)
61ammunition none 7 none 100 52433158 ammunitionTimed 60 (null)
62ammunition none 7 none 100 52458790 ammunitionTimed 61 (null)
63ammunition none 7 none 100 52402357 ammunitionTimed 62 (null)
64ammunition none 7 none 100 52307440 ammunitionTimed 63 (null)
65ammunition none 7 none 100 52515921 ammunitionTimed 64 (null)
66ammunition none 7 none 100 52419607 ammunitionTimed 65 (null)
67ammunition none 7 none 100 52401518 ammunitionTimed 66 (null)
68ammunition none 7 none 100 52432389 ammunitionTimed 67 (null)
69ammunition none 7 none 100 52310862 ammunitionTimed 68 (null)
70ammunition none 7 none 100 52279992 ammunitionTimed 69 (null)
71ammunition none 7 none 100 52402148 ammunitionTimed 70 (null)
72ammunition none 7 none 100 52390414 ammunitionTimed 71 (null)
73ammunition none 7 none 100 52374629 ammunitionTimed 72 (null)
74ammunition none 7 none 100 52377493 ammunitionTimed 73 (null)
75ammunition none 7 none 100 52334749 ammunitionTimed 74 (null)
76ammunition none 7 none 100 52402845 ammunitionTimed 75 (null)
77ammunition none 7 none 100 52391601 ammunitionTimed 76 (null)
78ammunition none 7 none 100 52382800 ammunitionTimed 77 (null)
79ammunition none 7 none 100 52471641 ammunitionTimed 78 (null)
80ammunition none 7 none 100 52349137 ammunitionTimed 79 (null)
81ammunition none 7 none 100 52408293 ammunitionTimed 80 (null)
82ammunition none 7 none 100 52454180 ammunitionTimed 81 (null)
83ammunition none 7 none 100 52407525 ammunitionTimed 82 (null)
84ammunition none 7 none 100 52463749 ammunitionTimed 83 (null)
85ammunition none 7 none 100 52335517 ammunitionTimed 84 (null)
86ammunition none 7 none 100 52338800 ammunitionTimed 85 (null)
87ammunition none 7 none 100 52406268 ammunitionTimed 86 (null)
88ammunition none 7 none 100 52269236 ammunitionTimed 87 (null)
89ammunition none 7 none 100 52310862 ammunitionTimed 88 (null)
90ammunition none 7 none 100 52286138 ammunitionTimed 89 (null)
91ammunition none 7 none 100 52381963 ammunitionTimed 90 (null)
92ammunition none 7 none 100 52390343 ammunitionTimed 91 (null)
93ammunition none 7 none 100 52426663 ammunitionTimed 92 (null)
94ammunition none 7 none 100 52344736 ammunitionTimed 93 (null)
95ammunition none 7 none 100 52346343 ammunitionTimed 94 (null)
96ammunition none 7 none 100 52380287 ammunitionTimed 95 (null)
97ammunition none 7 none 100 52344597 ammunitionTimed 96 (null)
98ammunition none 7 none 100 52315263 ammunitionTimed 97 (null)
99ammunition none 7 none 100 52418560 ammunitionTimed 98 (null)
100ammunition none 7 none 100 52333352 ammunitionTimed 99 (null)
diff --git a/baseline/source/ammunition/ammunition_libc.c b/baseline/source/ammunition/ammunition_libc.c
new file mode 100644
index 0000000..4cce6e9
--- /dev/null
+++ b/baseline/source/ammunition/ammunition_libc.c
@@ -0,0 +1,166 @@
1/*
2 Include section
3*/
4
5#include "ammunition_string.h"
6#include "ammunition_stdio.h"
7#include "ammunition_stdlib.h"
8
9
10/*
11 Standard library functions
12*/
13
14char ammunition_isdigit( unsigned char c )
15{
16 if ( ( c >= '0' ) & ( c <= '9' ) )
17 return 1;
18 else
19 return 0;
20}
21
22int ammunition_isspace( int c )
23{
24 return ( c == ' ' ) | ( c == '\t' ) | ( c == '\n' ) | ( c == '\r' );
25}
26
27void *ammunition_memcpy( void *dest, const void *src, size_x size )
28{
29 size_x i;
30 _Pragma( "loopbound min 2 max 6" )
31 for ( i = 0; i < size; i++ )
32 ( ( unsigned char * )dest )[i] = ( ( unsigned char * )src )[i];
33
34 return dest;
35}
36
37
38void *ammunition_memset( void *s, int c, size_x n )
39{
40 size_x i;
41 _Pragma( "loopbound min 0 max 4" )
42 for ( i = 0; i < n; i++ )
43 ( ( unsigned char * )s )[i] = ( unsigned char )c;
44
45 return s;
46}
47
48
49int ammunition_memcmp ( const void *mem1, const void *mem2, size_x size )
50{
51 const unsigned char *p1 = (const unsigned char *) mem1,
52 *p2 = (const unsigned char *) mem2;
53 _Pragma( "loopbound min 0 max 4" )
54 while ( size-- )
55 if ( *p1 != *p2 )
56 return ( *p1 - *p2 );
57 else
58 p1++, p2++;
59 return 0;
60}
61
62
63/* The following function is an analog of standard C function
64 `memmove'. The function returns the first operand. */
65
66void *ammunition_memmove ( void *s1, const void *s2, size_x n )
67{
68 int i;
69
70 if ( ( ( char * ) s1 < ( char * ) s2 && ( char * ) s1 + n <= ( char * ) s2 )
71 || ( ( char * ) s2 < ( char * ) s1
72 && ( char * ) s2 + n <= ( char * ) s1 ) )
73 return ( void * ) ammunition_memcpy ( s1, s2, n );
74 if ( ( char * ) s1 < ( char * ) s2 && ( char * ) s1 + n > ( char * ) s2 ) {
75 _Pragma( "loopbound min 0 max 4" )
76 for ( i = 0; ( size_x ) i < n; i++ )
77 ( ( char * ) s1 ) [i] = ( ( char * ) s2 ) [i];
78 } else {
79 _Pragma( "loopbound min 0 max 4" )
80 for ( i = n - 1; i >= 0; i-- )
81 ( ( char * ) s1 )[i] = ( ( char * ) s2 ) [i];
82 }
83 return s1;
84}
85
86int ammunition_strcmp ( const char *str1, const char *str2 )
87{
88 _Pragma( "loopbound min 1 max 4008" )
89 while ( *str1 && ( *str1 == *str2 ) )
90 str1++, str2++;
91 return *( const unsigned char * )str1 - *( const unsigned char * )str2;
92}
93
94int ammunition_atoi ( const char *str )
95{
96 int result = 0;
97 int sign = ( str[0] == '-' ? -1 : 1 );
98
99 int readingPos = 0;
100 if ( str[0] == '-' || str[0] == '+' )
101 readingPos++;
102 _Pragma( "loopbound min 1 max 1" )
103 do {
104 result *= 10;
105 result += str[readingPos++] - 48;
106 } while ( str[readingPos] != 0 );
107
108 return sign * result;
109}
110
111
112int ammunition_sprintf_d( char *s, int number )
113{
114 /* How many decimal digits do we need? */
115 char digits = 0;
116 unsigned char writePos = 0;
117 long long copyOfNumber = number;
118 _Pragma( "loopbound min 1 max 10" )
119 do {
120 digits++;
121 copyOfNumber /= 10;
122 } while ( copyOfNumber != 0 );
123
124 writePos = digits;
125 if ( number < 0 ) {
126 writePos++;
127 s[0] = '-';
128 }
129 s[writePos] = 0;
130
131 copyOfNumber = number;
132 _Pragma( "loopbound min 1 max 10" )
133 do {
134 s[--writePos] = 48 + ( ( copyOfNumber >= 0 ?
135 copyOfNumber : -copyOfNumber ) % 10 );
136 copyOfNumber /= 10;
137 } while ( copyOfNumber != 0 );
138
139 return digits + ( number < 0 ? 1 : 0 );
140}
141
142
143int ammunition_sprintf_u( char *s, unsigned int number )
144{
145 /* How many decimal digits do we need? */
146 char digits = 0;
147 unsigned char writePos = 0;
148 unsigned long copyOfNumber = number;
149 _Pragma( "loopbound min 1 max 10" )
150 do {
151 digits++;
152 copyOfNumber /= 10;
153 } while ( copyOfNumber != 0 );
154
155 writePos = digits;
156 s[writePos] = 0;
157
158 copyOfNumber = number;
159 _Pragma( "loopbound min 1 max 10" )
160 do {
161 s[--writePos] = 48 + ( copyOfNumber % 10 );
162 copyOfNumber /= 10;
163 } while ( copyOfNumber != 0 );
164
165 return digits;
166}
diff --git a/baseline/source/ammunition/ammunition_limits.h b/baseline/source/ammunition/ammunition_limits.h
new file mode 100644
index 0000000..0de4c82
--- /dev/null
+++ b/baseline/source/ammunition/ammunition_limits.h
@@ -0,0 +1,35 @@
1#ifndef AMMUNITION_LIMITS_H
2#define AMMUNITION_LIMITS_H
3
4#ifndef CHAR_BIT
5#define CHAR_BIT 8
6#endif
7#ifndef UCHAR_MAX
8#define UCHAR_MAX 255
9#endif
10#ifndef SCHAR_MAX
11#define SCHAR_MAX 127
12#endif
13#ifndef SCHAR_MIN
14#define SCHAR_MIN (-128)
15#endif
16#ifndef USHRT_MAX
17#define USHRT_MAX 65535
18#endif
19#ifndef SHRT_MAX
20#define SHRT_MAX 32767
21#endif
22#ifndef SHRT_MIN
23#define SHRT_MIN (-32768)
24#endif
25#ifndef UINT_MAX
26#define UINT_MAX (INT_MAX * 2U + 1)
27#endif
28#ifndef INT_MAX
29#define INT_MAX 2147483647
30#endif
31#ifndef INT_MIN
32#define INT_MIN (-INT_MAX-1)
33#endif
34
35#endif /* #ifndef AMMUNITION_LIMITS_H */
diff --git a/baseline/source/ammunition/ammunition_stdio.h b/baseline/source/ammunition/ammunition_stdio.h
new file mode 100644
index 0000000..a3a7a4b
--- /dev/null
+++ b/baseline/source/ammunition/ammunition_stdio.h
@@ -0,0 +1,8 @@
1#ifndef AMMUNITION_STDIO_H
2#define AMMUNITION_STDIO_H
3
4int ammunition_sprintf_d( char *s, int number );
5
6int ammunition_sprintf_u( char *s, unsigned int number );
7
8#endif
diff --git a/baseline/source/ammunition/ammunition_stdlib.h b/baseline/source/ammunition/ammunition_stdlib.h
new file mode 100644
index 0000000..d907212
--- /dev/null
+++ b/baseline/source/ammunition/ammunition_stdlib.h
@@ -0,0 +1,6 @@
1#ifndef AMMUNITION_STDLIB_H
2#define AMMUNITION_STDLIB_H
3
4int ammunition_atoi ( const char *str );
5
6#endif
diff --git a/baseline/source/ammunition/ammunition_string.h b/baseline/source/ammunition/ammunition_string.h
new file mode 100644
index 0000000..6b042f8
--- /dev/null
+++ b/baseline/source/ammunition/ammunition_string.h
@@ -0,0 +1,18 @@
1#ifndef AMMUNITION_STRING_H
2#define AMMUNITION_STRING_H
3
4typedef unsigned int size_x;
5//typedef __SIZE_TYPE__ size_x;
6
7/*
8 Forward declaration of functions
9*/
10
11void *ammunition_memcpy( void *, const void *, size_x );
12void *ammunition_memset( void *, int, size_x );
13int ammunition_memcmp ( const void *mem1, const void *mem2, size_x size );
14void *ammunition_memmove ( void *s1, const void *s2, size_x n );
15int ammunition_strcmp ( const char *str1, const char *str2 );
16
17#endif /* AMMUNITION_STRING_H */
18
diff --git a/baseline/source/ammunition/arithm.c b/baseline/source/ammunition/arithm.c
new file mode 100644
index 0000000..9480846
--- /dev/null
+++ b/baseline/source/ammunition/arithm.c
@@ -0,0 +1,1384 @@
1/*
2 FILE NAME: arithm.c
3
4 TITLE: Package for arbitrary precision integer arithmetic
5
6 DESCRIPTION: This abstract data implements arbitrary precision
7 integer and unsigned integer numbers by machine independent
8 way. The implementation of the package functions are not
9 sufficiently efficient in order to use for run-time. The
10 package functions are oriented to implement constant-folding in
11 compilers. This package is necessary because host machine may
12 not support such arithmetic for target machine. For example,
13 VAX does not support does not support more 32-bits integer
14 numbers arithmetic. The numbers are represented by bytes in
15 big endian mode, negative integer numbers are represented in
16 complementary code. All sizes are given in bytes and must be
17 positive. Results of executions of all functions can coincide
18 with a operand(s). All functions of addition, subtraction,
19 multiplication, division, evaluation of remainder, shift,
20 changing size and transformation of string into number fix
21 overflow. The overflow is fixed when result can not be
22 represented by number of given size.
23
24*/
25
26#include "arithm.h"
27#include "ammunition_string.h"
28
29
30/* This variable can have only two values 0 or 1. The value `1'
31 corresponds to overflow. The variable value are modified by all
32 functions of addition, subtract, multiplication, division,
33 evaluation of remainder, shift, changing size and transformation of
34 string into number fix overflow. */
35
36int ammunition_overflow_bit;
37
38
39/* The following function adds unsigned integers. The function
40 returns 1 if unsigned integer overflow is fixed, 0 otherwise.
41 Result can be placed in any operand. */
42
43int ammunition_add_unsigned_integer_without_overflow_reaction
44( int size, const void *op1, const void *op2, void *result )
45{
46 int digit_num;
47 int carry;
48 unsigned int sum;
49
50 _Pragma( "loopbound min 4 max 4" )
51 for ( digit_num = size - 1, carry = 0; digit_num >= 0; digit_num-- ) {
52 sum = ( ( ( unsigned char * ) op1 ) [digit_num]
53 + ( ( unsigned char * ) op2 ) [digit_num] + carry );
54 if ( sum > UCHAR_MAX ) {
55 sum -= UCHAR_MAX + 1;
56 carry = 1;
57 } else
58 carry = 0;
59 ( ( unsigned char * ) result ) [digit_num] = sum;
60 }
61 return carry != 0;
62}
63
64/* The following function adds unsigned integers. The function
65 returns 1 if unsigned integer overflow (the first operand is less
66 than the second) is fixed, 0 otherwise. Result can be placed in
67 any operand. */
68
69int ammunition_subtract_unsigned_integer_without_overflow_reaction
70( int size, const void *op1, const void *op2, void *result )
71{
72 int digit_num;
73 int carry;
74 int subtraction;
75
76 _Pragma( "loopbound min 4 max 4" )
77 for ( digit_num = size - 1, carry = 0; digit_num >= 0; digit_num-- ) {
78 subtraction = ( ( ( unsigned char * ) op1 ) [digit_num]
79 - ( ( unsigned char * ) op2 ) [digit_num] - carry );
80 if ( subtraction < 0 ) {
81 subtraction += UCHAR_MAX + 1;
82 carry = 1;
83 } else
84 carry = 0;
85 ( ( unsigned char * ) result ) [digit_num] = subtraction;
86 }
87 return carry != 0;
88}
89
90/* The following function makes complementary code of number. Result
91 can be placed in operand. */
92
93void ammunition_make_complementary_code
94( int size, const void *operand, void *result )
95{
96 int digit_num;
97 int carry;
98 int subtraction;
99
100 _Pragma( "loopbound min 2 max 6" )
101 for ( digit_num = size - 1, carry = 0; digit_num >= 0; digit_num-- ) {
102 subtraction = ( 0 - ( ( unsigned char * ) operand ) [digit_num] - carry );
103 if ( subtraction != 0 ) {
104 subtraction += UCHAR_MAX + 1;
105 carry = 1;
106 } else
107 carry = 0;
108 ( ( unsigned char * ) result ) [digit_num] = subtraction;
109 }
110}
111
112/* The following function multiplys unsigned integer by digit (byte
113 size). The function returns 1 if unsigned integer overflow is
114 fixed, 0 otherwise. */
115
116int ammunition_multiply_unsigned_integer_by_digit_without_overflow_reaction
117( int size, void *operand, unsigned int digit )
118{
119 int digit_num;
120 unsigned int carry;
121 unsigned int sum;
122
123 _Pragma( "loopbound min 4 max 4" )
124 for ( digit_num = size - 1, carry = 0; digit_num >= 0; digit_num-- ) {
125 sum = ( ( ( unsigned char * ) operand ) [digit_num] * digit + carry );
126 if ( sum > UCHAR_MAX ) {
127 carry = sum / ( UCHAR_MAX + 1 );
128 sum %= UCHAR_MAX + 1;
129 } else
130 carry = 0;
131 ( ( unsigned char * ) operand ) [digit_num] = sum;
132 }
133 return carry != 0;
134}
135
136
137/* Originally reaction on all integer and unsigned integer overflow is
138 equal to the following function. The function does nothing. */
139
140void
141ammunition_arithmetic_overflow_reaction ( void )
142{}
143
144
145/* Originally reaction on all integer and unsigned integer overflow is
146 equal to the following function. The function does nothing. */
147
148void
149ammunition_arithmetic_unsigned_overflow_reaction ( void )
150{}
151
152
153/* This page contains functions for arbitrary precision addition. */
154
155/* The function adds unsigned integers and fixes overflow reaction if
156 it is needed. The function makes this with the aid of function
157 `add_unsigned_integer_without_overflow_reaction'. Result can be
158 placed in any operand. */
159
160void
161ammunition_add_unsigned_integer ( int size, const void *op1, const void *op2,
162 void *result )
163{
164 ammunition_overflow_bit
165 = ammunition_add_unsigned_integer_without_overflow_reaction (
166 size, op1, op2, result );
167 if ( ammunition_overflow_bit != 0 )
168 ammunition_arithmetic_unsigned_overflow_reaction();
169}
170
171/* The function adds integers and fixes overflow reaction if it is
172 needed. The function makes this with the aid of function
173 `add_unsigned_integer_without_overflow_reaction'. Result can be
174 placed in any operand. */
175
176void
177ammunition_add_integer ( int size, const void *op1, const void *op2,
178 void *result )
179{
180 int op1_sign;
181 int sign_equality;
182
183 op1_sign = INTEGER_SIGN ( op1 );
184 sign_equality = INTEGER_SIGN ( op1 ) == INTEGER_SIGN ( op2 );
185 ammunition_add_unsigned_integer_without_overflow_reaction (
186 size, op1, op2, result );
187 ammunition_overflow_bit = sign_equality &&
188 ( op1_sign != INTEGER_SIGN ( result ) );
189 if ( ammunition_overflow_bit != 0 )
190 ammunition_arithmetic_overflow_reaction();
191}
192
193
194
195/* This page contains functions for arbitrary precision subtraction. */
196
197/* The function subtracts unsigned integers and fixes overflow
198 reaction if it is needed. The function makes this with the aid of
199 function `subtract_unsigned_integer_without_overflow_reaction'.
200 Result can be placed in any operand. */
201
202void
203ammunition_subtract_unsigned_integer ( int size, const void *op1,
204 const void *op2,
205 void *result )
206{
207 ammunition_overflow_bit
208 = ammunition_subtract_unsigned_integer_without_overflow_reaction (
209 size, op1, op2, result );
210 if ( ammunition_overflow_bit != 0 )
211 ammunition_arithmetic_unsigned_overflow_reaction();
212}
213
214/* The function subtracts integers and fixes overflow reaction if it
215 is needed. The function makes this with the aid of function
216 `subtract_unsigned_integer_without_overflow_reaction'. Result can
217 be placed in any operand. */
218
219void
220ammunition_subtract_integer ( int size, const void *op1, const void *op2,
221 void *result )
222{
223 int op1_sign;
224 int sign_unequality;
225
226 op1_sign = INTEGER_SIGN ( op1 );
227 sign_unequality = INTEGER_SIGN ( op1 ) != INTEGER_SIGN ( op2 );
228 ammunition_subtract_unsigned_integer_without_overflow_reaction (
229 size, op1, op2, result );
230 ammunition_overflow_bit = sign_unequality &&
231 ( op1_sign != INTEGER_SIGN ( result ) );
232 if ( ammunition_overflow_bit != 0 )
233 ammunition_arithmetic_overflow_reaction();
234}
235
236
237
238/* This page contains functions for arbitrary precision multiplication. */
239
240/* The following function multiplys unsigned integers. The function
241 returns 1 if unsigned integer overflow is fixed, 0 otherwise.
242 Result can be placed in any operand. */
243
244int ammunition_multiply_unsigned_integer_without_overflow_reaction
245( int size, const void *op1, const void *op2, void *result )
246{
247 int op1_digit_num;
248 int op2_digit_num;
249 int carry;
250 unsigned long int partial_sum;
251 int result_digit_number;
252 int overflow_flag;
253 unsigned char long_result [2 * MAX_INTEGER_OPERAND_SIZE];
254
255 ammunition_memset ( long_result + size, 0, ( size_x ) size );
256 _Pragma( "loopbound min 4 max 4" )
257 for ( op2_digit_num = size - 1; op2_digit_num >= 0; op2_digit_num-- ) {
258 if ( ( ( unsigned char * ) op2 ) [op2_digit_num] != 0 ) {
259 _Pragma( "loopbound min 4 max 4" )
260 for ( op1_digit_num = size - 1, carry = 0; op1_digit_num >= 0;
261 op1_digit_num-- ) {
262 partial_sum
263 = ( ( ( unsigned char * ) op1 ) [op1_digit_num]
264 * ( ( unsigned char * ) op2 ) [op2_digit_num]
265 + long_result [op1_digit_num + op2_digit_num + 1]
266 + carry );
267 long_result [op1_digit_num + op2_digit_num + 1]
268 = ( unsigned char ) ( partial_sum % ( UCHAR_MAX + 1 ) );
269 carry = partial_sum / ( UCHAR_MAX + 1 );
270 }
271 long_result [op2_digit_num] = carry;
272 } else
273 long_result [op2_digit_num] = 0;
274 }
275 overflow_flag = 0;
276 _Pragma( "loopbound min 1 max 4" )
277 for ( result_digit_number = size - 1; result_digit_number >= 0;
278 result_digit_number-- ) {
279 if ( long_result [result_digit_number] != 0 ) {
280 overflow_flag = 1;
281 break;
282 }
283 }
284 ammunition_memcpy ( result, long_result + size, ( size_x ) size );
285 return overflow_flag;
286}
287
288/* The following function multiplys unsigned integers and fixes
289 overflow reaction if it is needed. The function makes this with
290 the aid of function
291 `multiply_unsigned_integer_without_overflow_reaction'. Result can
292 be placed in any operand. */
293
294void
295ammunition_multiply_unsigned_integer ( int size, const void *op1,
296 const void *op2,
297 void *result )
298{
299 ammunition_overflow_bit =
300 ammunition_multiply_unsigned_integer_without_overflow_reaction (
301 size, op1, op2, result );
302 if ( ammunition_overflow_bit )
303 ammunition_arithmetic_unsigned_overflow_reaction();
304}
305
306/* The function multiplys integers and fixes overflow reaction if it
307 is needed. The function makes this with the aid of function
308 `multiply_unsigned_integer_without_overflow_reaction'. Result can
309 be placed in any operand. */
310
311void
312ammunition_multiply_integer ( int size, const void *op1, const void *op2,
313 void *result )
314{
315 int negative_result_flag;
316 unsigned char op1_complementary [MAX_INTEGER_OPERAND_SIZE];
317 unsigned char op2_complementary [MAX_INTEGER_OPERAND_SIZE];
318 unsigned const char *abs_op1;
319 unsigned const char *abs_op2;
320 int unsigned_result_sign;
321
322 negative_result_flag = INTEGER_SIGN ( op1 ) != INTEGER_SIGN ( op2 );
323 if ( INTEGER_SIGN ( op1 ) ) {
324 /* May be integer overflow. But result is correct because
325 it is unsigned. */
326 ammunition_make_complementary_code ( size, op1, op1_complementary );
327 abs_op1 = ( unsigned const char * )op1_complementary;
328 } else
329 abs_op1 = ( unsigned const char * )op1;
330 if ( INTEGER_SIGN ( op2 ) ) {
331 /* May be integer overflow. But result is correct because
332 it is unsigned. */
333 ammunition_make_complementary_code ( size, op2, op2_complementary );
334 abs_op2 = ( unsigned const char * )op2_complementary;
335 } else
336 abs_op2 = ( unsigned const char * )op2;
337 ammunition_overflow_bit =
338 ammunition_multiply_unsigned_integer_without_overflow_reaction (
339 size, abs_op1, abs_op2, result );
340 unsigned_result_sign = INTEGER_SIGN ( result );
341 if ( negative_result_flag )
342 ammunition_make_complementary_code ( size, result, result );
343 if ( unsigned_result_sign
344 && ( !negative_result_flag
345 || INTEGER_SIGN ( result ) != unsigned_result_sign ) )
346 /* Unsigned result can not be represented as integer. */
347 ammunition_overflow_bit = 1;
348 if ( ammunition_overflow_bit )
349 ammunition_arithmetic_overflow_reaction();
350}
351
352
353
354/* This page contains functions for arbitrary precision division. */
355
356/* The following function divides unsigned integers. The function
357 returns 1 if unsigned integer overflow (division by zero) is fixed,
358 0 otherwise. Result can be placed in any operand. See algorithm
359 in Knuth's book. */
360
361int ammunition_divide_unsigned_integer_without_overflow_reaction
362( int size, const void *op1, const void *op2, void *result )
363{
364 int scaled_op1_digit_num;
365 unsigned int q_approximation;
366 int first_nonzero_digit_number;
367 int op2_digit_number;
368 unsigned int scale;
369 unsigned char scaled_op1 [MAX_INTEGER_OPERAND_SIZE + 1];
370 unsigned char normalized_op2 [MAX_INTEGER_OPERAND_SIZE];
371 unsigned char extended_normalized_op2 [MAX_INTEGER_OPERAND_SIZE + 1];
372
373 _Pragma( "loopbound min 4 max 4" )
374 for ( op2_digit_number = 0; op2_digit_number < size; op2_digit_number++ ) {
375 if ( ( ( unsigned char * ) op2 ) [op2_digit_number] != 0 )
376 break;
377 }
378 first_nonzero_digit_number = op2_digit_number;
379 if ( first_nonzero_digit_number == size ) {
380 /* Zero divisor */
381 ammunition_memset ( result, 0, ( size_x ) size );
382 return 1 /* TRUE */;
383 } else
384 if ( first_nonzero_digit_number == size - 1 ) {
385 /* Division by digit. */
386 int digit_num;
387 int digit;
388 unsigned long divisable;
389 unsigned long remainder;
390
391 digit = ( ( unsigned char * ) op2 ) [first_nonzero_digit_number];
392 ammunition_memcpy ( result, op1, ( size_x ) size );
393 remainder = 0;
394 _Pragma( "loopbound min 4 max 4" )
395 for ( digit_num = 0; digit_num < size; digit_num++ ) {
396 divisable = ( remainder * ( UCHAR_MAX + 1 )
397 + ( ( unsigned char * ) result ) [digit_num] );
398 remainder = divisable % digit;
399 ( ( unsigned char * ) result ) [digit_num]
400 = ( unsigned char ) ( divisable / digit );
401 }
402 return 0 /* FALSE */;
403 }
404 /* Normalization of divisor. */
405 scale = ( UCHAR_MAX + 1 ) / ( ( ( unsigned char * ) op2 ) [op2_digit_number] +
406 1 );
407 ammunition_memcpy ( scaled_op1 + 1, op1, ( size_x ) size );
408 *scaled_op1 = 0;
409
410 ammunition_multiply_unsigned_integer_by_digit_without_overflow_reaction
411 ( size + 1, scaled_op1, scale );
412
413 ammunition_memcpy ( normalized_op2, op2, ( size_x ) size );
414
415 ammunition_multiply_unsigned_integer_by_digit_without_overflow_reaction
416 ( size, normalized_op2, scale );
417
418 _Pragma( "loopbound min 0 max 0" )
419 for ( scaled_op1_digit_num = 0;
420 scaled_op1_digit_num <= first_nonzero_digit_number;
421 scaled_op1_digit_num++ ) {
422 /* Division of `scaled_op1[scaled_op1_digit_number]..scaled_op1[size]' by
423 `normalized_op2[first_nonzero_digit_number]..normalized_op2[size-1]'
424 for evaluation of one digit of quotient
425 `result[size-1-first_nonzero_digit_number-scaled_op1_digit_number]'.
426 */
427 if ( scaled_op1 [scaled_op1_digit_num]
428 == normalized_op2 [first_nonzero_digit_number] )
429 q_approximation = UCHAR_MAX;
430 else
431 q_approximation
432 = ( scaled_op1 [scaled_op1_digit_num] * ( UCHAR_MAX + 1 )
433 + scaled_op1 [scaled_op1_digit_num + 1] )
434 / normalized_op2 [first_nonzero_digit_number];
435
436 _Pragma( "loopbound min 0 max 0" )
437 while ( normalized_op2 [first_nonzero_digit_number + 1] * q_approximation
438 > ( ( ( unsigned long int ) scaled_op1 [scaled_op1_digit_num]
439 * ( UCHAR_MAX + 1 )
440 + scaled_op1 [scaled_op1_digit_num + 1]
441 - q_approximation
442 * normalized_op2 [first_nonzero_digit_number] )
443 * ( UCHAR_MAX + 1 ) + scaled_op1 [scaled_op1_digit_num + 2] ) )
444 q_approximation --;
445
446 /* Multiply and subtract */
447 ammunition_memcpy ( extended_normalized_op2 + 1,
448 normalized_op2 + first_nonzero_digit_number,
449 ( size_x ) ( size - first_nonzero_digit_number ) );
450 *extended_normalized_op2 = 0;
451 ammunition_multiply_unsigned_integer_by_digit_without_overflow_reaction
452 ( size - first_nonzero_digit_number + 1, extended_normalized_op2,
453 q_approximation );
454 if ( ammunition_subtract_unsigned_integer_without_overflow_reaction
455 ( size - first_nonzero_digit_number + 1,
456 scaled_op1 + scaled_op1_digit_num, extended_normalized_op2,
457 scaled_op1 + scaled_op1_digit_num ) ) {
458 /* Negative result. Compensation by addition. */
459 q_approximation--;
460 ammunition_memcpy ( extended_normalized_op2 + 1,
461 normalized_op2 + first_nonzero_digit_number,
462 ( size_x ) ( size - first_nonzero_digit_number ) );
463 *extended_normalized_op2 = 0;
464
465 ammunition_add_unsigned_integer_without_overflow_reaction
466 ( size - first_nonzero_digit_number + 1,
467 scaled_op1 + scaled_op1_digit_num, extended_normalized_op2,
468 scaled_op1 + scaled_op1_digit_num );
469
470 }
471 ( ( unsigned char * ) result ) [size - 1 - first_nonzero_digit_number
472 + scaled_op1_digit_num] = q_approximation;
473 }
474 ammunition_memset ( result, 0,
475 ( size_x ) ( size - 1 - first_nonzero_digit_number ) );
476 return 0 /* TRUE */;
477}
478
479/* The function divides unsigned integers and fixes overflow reaction
480 if it is needed. The function makes this with the aid of function
481 `divide_unsigned_integer_without_overflow_reaction'. Result can be
482 placed in any operand. */
483
484void
485ammunition_divide_unsigned_integer ( int size, const void *op1, const void *op2,
486 void *result )
487{
488 ammunition_overflow_bit =
489 ammunition_divide_unsigned_integer_without_overflow_reaction (
490 size, op1, op2, result );
491 if ( ammunition_overflow_bit )
492 ammunition_arithmetic_unsigned_overflow_reaction();
493}
494
495/* The function divides integers and fixes overflow reaction if it is
496 needed. The function makes this with the aid of function
497 `divide_unsigned_integer_without_overflow_reaction'. Result can be
498 placed in any operand. */
499
500void
501ammunition_divide_integer ( int size, const void *op1, const void *op2,
502 void *result )
503{
504 int negative_result_flag;
505 unsigned char op1_complementary [MAX_INTEGER_OPERAND_SIZE];
506 unsigned char op2_complementary [MAX_INTEGER_OPERAND_SIZE];
507 unsigned const char *abs_op1;
508 unsigned const char *abs_op2;
509 int unsigned_result_sign;
510
511 negative_result_flag = INTEGER_SIGN ( op1 ) != INTEGER_SIGN ( op2 );
512 if ( INTEGER_SIGN ( op1 ) ) {
513 /* May be integer overflow for minimal int. But result is correct because
514 it is unsigned. */
515 ammunition_make_complementary_code ( size, op1, op1_complementary );
516 abs_op1 = ( unsigned const char * )op1_complementary;
517 } else
518 abs_op1 = ( unsigned const char * )op1;
519 if ( INTEGER_SIGN ( op2 ) ) {
520 /* May be integer overflow for minimal int. But result is correct
521 because it is unsigned. */
522 ammunition_make_complementary_code ( size, op2, op2_complementary );
523 abs_op2 = ( unsigned const char * )op2_complementary;
524 } else
525 abs_op2 = ( unsigned const char * )op2;
526 ammunition_overflow_bit =
527 ammunition_divide_unsigned_integer_without_overflow_reaction (
528 size, abs_op1, abs_op2, result );
529 unsigned_result_sign = INTEGER_SIGN ( result );
530 if ( negative_result_flag )
531 ammunition_make_complementary_code ( size, result, result );
532 if ( unsigned_result_sign
533 && ( !negative_result_flag
534 || INTEGER_SIGN ( result ) != unsigned_result_sign ) )
535 /* Unsigned result can not be represented as integer. */
536 ammunition_overflow_bit = 1;
537 if ( ammunition_overflow_bit )
538 ammunition_arithmetic_overflow_reaction();
539}
540
541
542
543/* This page contains functions for arbitrary precision evaluation of
544 remainder. */
545
546/* The function evaluates remainder of division of unsigned integers
547 as `op1 - (op1/op2)*op2' and fixes overflow reaction if it is
548 needed. Result can be placed in any operand. */
549
550void
551ammunition_unsigned_integer_remainder ( int size, const void *op1,
552 const void *op2,
553 void *result )
554{
555 unsigned char temporary [MAX_INTEGER_OPERAND_SIZE];
556
557 ammunition_divide_unsigned_integer ( size, op1, op2, temporary );
558 if ( ammunition_overflow_bit )
559 /* Reaction on zero is called from `divide_unsigned_integer'. */
560 ammunition_memset ( result, 0, ( size_x ) size );
561 else {
562 ammunition_multiply_unsigned_integer ( size, temporary, op2, temporary );
563 ammunition_subtract_unsigned_integer ( size, op1, temporary, result );
564 }
565}
566
567
568/* This page contains functions for arbitrary precision number shifts. */
569
570/* This function makes right shift of unsigned integer of given size
571 on given number of bits. If number of bits is negative the
572 function makes shift to left actually with the aid of function
573 `unsigned_integer_shift_left'. The function fixes overflow when
574 result can not be represented by number of given size, i.e. in
575 other words the opposite unsigned shift (to left) results in number
576 not equal to source operand. Result can be placed in operand. */
577
578void
579ammunition_unsigned_integer_shift_right ( int size, const void *operand,
580 int bits, void *result )
581{
582 int byte_number;
583 unsigned byte;
584 unsigned carry;
585 int bit_shift;
586 int byte_shift;
587
588
589 if ( bits < 0 )
590 ammunition_unsigned_integer_shift_left ( size, operand, -bits, result );
591 else {
592 ammunition_overflow_bit = 0;
593 byte_shift = bits / CHAR_BIT;
594 bit_shift = bits % CHAR_BIT;
595 _Pragma( "loopbound min 0 max 3" )
596 for ( byte_number = ( byte_shift >= size ? 0 : size - byte_shift );
597 byte_number < size; byte_number++ )
598 if ( ( ( unsigned char * ) operand ) [byte_number] != 0 ) {
599 ammunition_overflow_bit = 1;
600 break;
601 }
602 if ( byte_shift >= size )
603 ammunition_memset ( result, 0, ( size_x ) size );
604 else {
605 ammunition_memmove ( ( char * ) result + byte_shift, operand,
606 ( size_x ) ( size - byte_shift ) );
607 ammunition_memset ( result, 0, ( size_x ) byte_shift );
608 if ( bit_shift == 0 )
609 return;
610 _Pragma( "loopbound min 3 max 3" )
611 for ( byte_number = byte_shift, carry = 0; byte_number < size;
612 byte_number++ ) {
613 byte = ( ( unsigned char * ) result ) [byte_number];
614 ( ( unsigned char * ) result ) [byte_number]
615 = carry | ( byte >> bit_shift );
616 carry = ( byte << ( CHAR_BIT - bit_shift ) ) & UCHAR_MAX;
617 }
618 if ( carry != 0 )
619 ammunition_overflow_bit = 1;
620 }
621 if ( ammunition_overflow_bit )
622 ammunition_arithmetic_unsigned_overflow_reaction();
623 }
624}
625
626/* This function makes right arithmetic shift of integer of given size
627 on given number of bits. If number of bits is negative the
628 function makes shift to left actually with the aid of function
629 `integer_shift_left'. The function fixes overflow when result can
630 not be represented by number of given size, i.e. in other words the
631 opposite shift (to left) results in number not equal to source
632 operand. Result can be placed in operand. */
633
634void
635ammunition_integer_shift_right ( int size, const void *operand, int bits,
636 void *result )
637{
638 int byte_number;
639 unsigned byte;
640 unsigned carry;
641 int bit_shift;
642 int byte_shift;
643 int operand_sign;
644
645 if ( bits < 0 )
646 ammunition_integer_shift_left ( size, operand, -bits, result );
647 else {
648 operand_sign = INTEGER_SIGN ( operand );
649 ammunition_overflow_bit = 0;
650 byte_shift = bits / CHAR_BIT;
651 bit_shift = bits % CHAR_BIT;
652 _Pragma( "loopbound min 0 max 3" )
653 for ( byte_number = ( byte_shift >= size ? 0 : size - byte_shift );
654 byte_number < size; byte_number++ )
655 if ( ( ( unsigned char * ) operand ) [byte_number] != 0 ) {
656 ammunition_overflow_bit = 1;
657 break;
658 }
659 if ( byte_shift >= size )
660 ammunition_memset ( result,
661 ( operand_sign ? UCHAR_MAX : 0 ), ( size_x ) size );
662 else {
663 ammunition_memmove ( ( char * ) result + byte_shift, operand,
664 ( size_x ) ( size - byte_shift ) );
665 ammunition_memset ( result, ( operand_sign ? UCHAR_MAX : 0 ),
666 ( size_x ) byte_shift );
667 if ( bit_shift == 0 )
668 return;
669 carry = ( ( ( operand_sign ? UCHAR_MAX : 0 ) << ( CHAR_BIT - bit_shift ) )
670 & UCHAR_MAX );
671 _Pragma( "loopbound min 3 max 3" )
672 for ( byte_number = byte_shift; byte_number < size; byte_number++ ) {
673 byte = ( ( unsigned char * ) result ) [byte_number];
674 ( ( unsigned char * ) result ) [byte_number]
675 = carry | ( byte >> bit_shift );
676 carry = ( byte << ( CHAR_BIT - bit_shift ) ) & UCHAR_MAX;
677 }
678 if ( carry != 0 )
679 ammunition_overflow_bit = 1;
680 }
681 if ( ammunition_overflow_bit )
682 ammunition_arithmetic_overflow_reaction();
683 }
684}
685
686/* This function makes left shift of unsigned integer of given size on
687 given number of bits. If number of bits is negative the function
688 makes shift to left actually with the aid of function
689 `unsigned_integer_shift_right'. The function fixes overflow when
690 result can not be represented by number of given size, i.e. i.e. in
691 other words the opposite shift (to right) results in number not
692 equal to source operand. Result can be placed in operand. */
693
694void
695ammunition_unsigned_integer_shift_left ( int size, const void *operand,
696 int bits, void *result )
697{
698 int byte_number;
699 unsigned byte;
700 unsigned carry;
701 int bit_shift;
702 int byte_shift;
703
704 if ( bits < 0 )
705 ammunition_unsigned_integer_shift_right ( size, operand, -bits, result );
706 else {
707 ammunition_overflow_bit = 0;
708 byte_shift = bits / CHAR_BIT;
709 bit_shift = bits % CHAR_BIT;
710 _Pragma( "loopbound min 0 max 2" )
711 for ( byte_number = 0; byte_number < byte_shift && byte_number < size;
712 byte_number++ )
713 if ( ( ( unsigned char * ) operand ) [byte_number] != 0 ) {
714 ammunition_overflow_bit = 1;
715 break;
716 }
717 if ( byte_shift >= size )
718 ammunition_memset ( result, 0, ( size_x ) size );
719 else {
720 ammunition_memmove ( result, ( char * ) operand + byte_shift,
721 ( size_x ) ( size - byte_shift ) );
722 ammunition_memset ( ( char * ) result + ( size - byte_shift ), 0,
723 ( size_x ) byte_shift );
724 if ( bit_shift == 0 )
725 return;
726 _Pragma( "loopbound min 2 max 3" )
727 for ( byte_number = size - byte_shift - 1, carry = 0;
728 byte_number >= 0; byte_number-- ) {
729 byte = ( ( unsigned char * ) result ) [byte_number];
730 ( ( unsigned char * ) result ) [byte_number]
731 = carry | ( byte << bit_shift );
732 carry = byte >> ( CHAR_BIT - bit_shift );
733 }
734 if ( carry != 0 )
735 ammunition_overflow_bit = 1;
736 }
737 if ( ammunition_overflow_bit )
738 ammunition_arithmetic_unsigned_overflow_reaction();
739 }
740}
741
742/* This function makes left arithmetic shift of integer of given size
743 on given number of bits. If number of bits is negative the
744 function makes shift to left actually with the aid of function
745 `integer_shift_right'. The function fixes overflow when result can
746 not be represented by number of given size, i.e. in other words the
747 opposite shift (to right) results in number not equal to source
748 operand. Result can be placed in operand. */
749
750void
751ammunition_integer_shift_left ( int size, const void *operand, int bits,
752 void *result )
753{
754 int byte_number;
755 unsigned byte;
756 unsigned carry;
757 int bit_shift;
758 int byte_shift;
759 int operand_sign;
760
761 if ( bits < 0 )
762 ammunition_integer_shift_right ( size, operand, -bits, result );
763 else {
764 operand_sign = INTEGER_SIGN ( operand );
765 ammunition_overflow_bit = 0;
766 byte_shift = bits / CHAR_BIT;
767 bit_shift = bits % CHAR_BIT;
768 _Pragma( "loopbound min 0 max 2" )
769 for ( byte_number = 0; byte_number < byte_shift && byte_number < size;
770 byte_number++ )
771 if ( ( ( unsigned char * ) operand ) [byte_number]
772 != ( operand_sign ? UCHAR_MAX : 0 ) ) {
773 ammunition_overflow_bit = 1;
774 break;
775 }
776 if ( byte_shift >= size )
777 ammunition_memset ( result, 0, ( size_x ) size );
778 else {
779 ammunition_memmove ( result, ( char * ) operand + byte_shift,
780 ( size_x ) ( size - byte_shift ) );
781 ammunition_memset ( ( char * ) result + ( size - byte_shift ), 0,
782 ( size_x ) byte_shift );
783 if ( bit_shift == 0 )
784 return;
785 _Pragma( "loopbound min 2 max 3" )
786 for ( byte_number = size - byte_shift - 1, carry = 0;
787 byte_number >= 0; byte_number-- ) {
788 byte = ( ( unsigned char * ) result ) [byte_number];
789 ( ( unsigned char * ) result ) [byte_number]
790 = carry | ( byte << bit_shift );
791 carry = byte >> ( CHAR_BIT - bit_shift );
792 }
793 if ( carry != ( ( unsigned ) ( operand_sign ? UCHAR_MAX : 0 )
794 >> ( CHAR_BIT - bit_shift ) ) )
795 ammunition_overflow_bit = 1;
796 }
797 if ( operand_sign != INTEGER_SIGN ( result ) )
798 ammunition_overflow_bit = 1;
799 if ( ammunition_overflow_bit )
800 ammunition_arithmetic_overflow_reaction();
801 }
802}
803
804
805
806/* This page contains functions for bitwise operations of arbitrary
807 precision numbers. */
808
809/* This function makes bitwise `or' of two integers of given size. */
810
811void
812ammunition_integer_or ( int size, const void *op1, const void *op2,
813 void *result )
814{
815 int byte_number;
816
817 _Pragma( "loopbound min 4 max 4" )
818 for ( byte_number = 0; byte_number < size; byte_number++ ) {
819 ( ( unsigned char * ) result ) [byte_number]
820 = ( ( unsigned char * ) op1 ) [byte_number]
821 | ( ( unsigned char * ) op2 ) [byte_number];
822 }
823}
824
825/* This function makes bitwise `or' of two unsigned integers of given
826 size. */
827
828void
829ammunition_unsigned_integer_or ( int size, const void *op1, const void *op2,
830 void *result )
831{
832 ammunition_integer_or ( size, op1, op2, result );
833}
834
835
836/* This function makes bitwise `and' of two integers of given size. */
837
838void
839ammunition_integer_and ( int size, const void *op1, const void *op2,
840 void *result )
841{
842 int byte_number;
843
844 _Pragma( "loopbound min 4 max 4" )
845 for ( byte_number = 0; byte_number < size; byte_number++ ) {
846 ( ( unsigned char * ) result ) [byte_number]
847 = ( ( unsigned char * ) op1 ) [byte_number]
848 & ( ( unsigned char * ) op2 ) [byte_number];
849 }
850}
851
852/* This function makes bitwise `and' of two unsigned integers of given
853 size. */
854
855void
856ammunition_unsigned_integer_and ( int size, const void *op1, const void *op2,
857 void *result )
858{
859 ammunition_integer_and ( size, op1, op2, result );
860}
861
862
863/* This function makes bitwise `not' of integer of given size. */
864
865void
866ammunition_integer_not ( int size, const void *operand, void *result )
867{
868 int byte_number;
869
870 _Pragma( "loopbound min 4 max 4" )
871 for ( byte_number = 0; byte_number < size; byte_number++ ) {
872 ( ( unsigned char * ) result ) [byte_number]
873 = ( ( unsigned char * ) operand ) [byte_number] ^ UCHAR_MAX;
874 }
875}
876
877/* This function makes bitwise `not' of unsigned integer of given
878 size. */
879
880void
881ammunition_unsigned_integer_not ( int size, const void *operand, void *result )
882{
883 ammunition_integer_not ( size, operand, result );
884}
885
886
887
888/* This page contains functions for comparison of arbitrary precision
889 numbers. */
890
891/* This function compares two unsigned integers of given size on
892 equality. The function returns 1 if unsigned integers are equal, 0
893 otherwise. */
894
895int
896ammunition_eq_unsigned_integer ( int size, const void *op1, const void *op2 )
897{
898 return ammunition_memcmp ( op1, op2, ( size_x ) size ) == 0;
899}
900
901/* This function compares two integers of given size on equality. The
902 function returns 1 if integers are equal, 0 otherwise. */
903
904int
905ammunition_eq_integer ( int size, const void *op1, const void *op2 )
906{
907 return ammunition_memcmp ( op1, op2, ( size_x ) size ) == 0;
908}
909
910/* This function compares two unsigned integers of given size on
911 inequality. The function returns 1 if unsigned integers are not
912 equal, 0 otherwise. */
913
914int
915ammunition_ne_unsigned_integer ( int size, const void *op1, const void *op2 )
916{
917 return ammunition_memcmp ( op1, op2, ( size_x ) size ) != 0;
918}
919
920/* This function compares two integers of given size on inequality.
921 The function returns 1 if integers are not equal, 0 otherwise. */
922
923int
924ammunition_ne_integer ( int size, const void *op1, const void *op2 )
925{
926 return ammunition_memcmp ( op1, op2, ( size_x ) size ) != 0;
927}
928
929
930/* This function compares two memory parts of given size on that the
931 first operand is greater than the second. The bytes are described
932 as unsigned. The function returns 1 if the first operand is
933 greater than the second, - 1 if the first operand is less than the
934 second, 0 otherwise. */
935
936int ammunition_bytes_comparison ( const void *op1, const void *op2, int size )
937{
938 const unsigned char *str1 = ( unsigned const char * )op1;
939 const unsigned char *str2 = ( unsigned const char * )op2;
940
941 _Pragma( "loopbound min 1 max 4" )
942 while ( size > 0 && *str1 == *str2 ) {
943 str1++;
944 str2++;
945 size--;
946 }
947 if ( size <= 0 )
948 return 0;
949 else
950 if ( *str1 > *str2 )
951 return 1;
952 else
953 return -1;
954}
955
956/* This function compares two unsigned integers of given size on that
957 the first operand is greater than the second. The function returns
958 1 if the first unsigned integer is greater than the second, 0
959 otherwise. */
960
961int
962ammunition_gt_unsigned_integer ( int size, const void *op1, const void *op2 )
963{
964 return ammunition_bytes_comparison ( op1, op2, size ) > 0;
965}
966
967/* This function compares two integers of given size on that the first
968 operand is greater than the second. The function returns 1 if the
969 first integer is greater than the second, 0 otherwise. */
970
971int ammunition_gt_integer ( int size, const void *op1, const void *op2 )
972{
973 if ( INTEGER_SIGN ( op1 ) == 0 ) {
974 if ( INTEGER_SIGN ( op2 ) == 0 )
975 return ammunition_bytes_comparison ( op1, op2, size ) > 0;
976 else
977 return 1; /* TRUE */
978 } else
979 if ( INTEGER_SIGN ( op2 ) == 0 )
980 return 0; /*FALSE*/
981 else
982 return ammunition_bytes_comparison ( op1, op2, size ) > 0;
983}
984
985/* This function compares two unsigned integers of given size on that
986 the first operand is less than the second. The function returns 1
987 if the first unsigned integer is less than the second, 0
988 otherwise. */
989
990int
991ammunition_lt_unsigned_integer ( int size, const void *op1, const void *op2 )
992{
993 return ammunition_bytes_comparison ( op1, op2, size ) < 0;
994}
995
996/* This function compares two integers of given size on that the first
997 operand is less than the second. The function returns 1 if the
998 first integer is less than the second, 0 otherwise. */
999
1000int
1001ammunition_lt_integer ( int size, const void *op1, const void *op2 )
1002{
1003 if ( INTEGER_SIGN ( op1 ) == 0 ) {
1004 if ( INTEGER_SIGN ( op2 ) == 0 )
1005 return ammunition_bytes_comparison ( op1, op2, size ) < 0;
1006 else
1007 return 0; /*FALSE*/
1008 } else
1009 if ( INTEGER_SIGN ( op2 ) == 0 )
1010 return 1; /* TRUE */
1011 else
1012 return ammunition_bytes_comparison ( op1, op2, size ) < 0;
1013}
1014
1015/* This function compares two unsigned integers of given size on that
1016 the first operand is greater than or equal to the second. The
1017 function returns 1 if the first unsigned integer is greater than or
1018 equal to the second, 0 otherwise. */
1019
1020int
1021ammunition_ge_unsigned_integer ( int size, const void *op1, const void *op2 )
1022{
1023 return ammunition_bytes_comparison ( op1, op2, size ) >= 0;
1024}
1025
1026/* This function compares two integers of given size on that the first
1027 operand is greater than or equal to the second. The function
1028 returns 1 if the first integer is greater than or equal to the
1029 second, 0 otherwise. */
1030
1031int
1032ammunition_ge_integer ( int size, const void *op1, const void *op2 )
1033{
1034 if ( INTEGER_SIGN ( op1 ) == 0 ) {
1035 if ( INTEGER_SIGN ( op2 ) == 0 )
1036 return ammunition_bytes_comparison ( op1, op2, size ) >= 0;
1037 else
1038 return 1; /* TRUE */
1039 } else
1040 if ( INTEGER_SIGN ( op2 ) == 0 )
1041 return 0; /*FALSE*/
1042 else
1043 return ammunition_bytes_comparison ( op1, op2, size ) >= 0;
1044}
1045
1046/* This function compares two unsigned integers of given size on that
1047 the first operand is less than or equal to the second. The
1048 function returns 1 if the first unsigned integer is less than or
1049 equal to the second, 0 otherwise. */
1050
1051int
1052ammunition_le_unsigned_integer ( int size, const void *op1, const void *op2 )
1053{
1054 return ammunition_bytes_comparison ( op1, op2, size ) <= 0;
1055}
1056
1057/* This function compares two integers of given size on that the first
1058 operand is less than or equal to the second. The function returns
1059 1 if the first integer is less than or equal to the second, 0
1060 otherwise. */
1061
1062int
1063ammunition_le_integer ( int size, const void *op1, const void *op2 )
1064{
1065 if ( INTEGER_SIGN ( op1 ) == 0 ) {
1066 if ( INTEGER_SIGN ( op2 ) == 0 )
1067 return ammunition_bytes_comparison ( op1, op2, size ) <= 0;
1068 else
1069 return 0; /*FALSE*/
1070 } else
1071 if ( INTEGER_SIGN ( op2 ) == 0 )
1072 return 1; /* TRUE */
1073 else
1074 return ammunition_bytes_comparison ( op1, op2, size ) <= 0;
1075}
1076
1077
1078
1079/* This page contains functions for changing size of arbitrary
1080 precision numbers. */
1081
1082/* The function changes size of unsigned integer. The function fixes
1083 overflow when result can not be represented by number of given
1084 size. Result can be placed in operand. */
1085
1086void
1087ammunition_change_unsigned_integer_size ( int operand_size, const void *operand,
1088 int result_size, void *result )
1089{
1090 int operand_digit_number;
1091
1092 ammunition_overflow_bit = 0;
1093 if ( operand_size <= result_size ) {
1094 ammunition_memmove ( ( char * ) result + result_size - operand_size,
1095 operand, ( size_x ) operand_size );
1096 ammunition_memset ( result, 0, ( size_x ) ( result_size - operand_size ) );
1097 } else {
1098 _Pragma( "loopbound min 2 max 2" )
1099 for ( operand_digit_number = 0;
1100 operand_digit_number < operand_size - result_size;
1101 operand_digit_number++ ) {
1102 if ( ( ( unsigned char * ) operand ) [operand_digit_number] != 0 ) {
1103 ammunition_overflow_bit = 1;
1104 break;
1105 }
1106 }
1107 ammunition_memmove ( result,
1108 ( char * ) operand + operand_size - result_size,
1109 ( size_x ) result_size );
1110 }
1111 if ( ammunition_overflow_bit )
1112 ammunition_arithmetic_unsigned_overflow_reaction();
1113}
1114
1115/* The function changes size of integer. The function fixes overflow
1116 when result can not be represented by number of given size. Result
1117 can be placed in operand. */
1118
1119void
1120ammunition_change_integer_size ( int operand_size, const void *operand,
1121 int result_size, void *result )
1122{
1123 int operand_digit_number;
1124 int operand_sign;
1125
1126 ammunition_overflow_bit = 0;
1127 operand_sign = INTEGER_SIGN ( operand );
1128 if ( operand_size <= result_size ) {
1129 ammunition_memmove ( ( char * ) result + result_size - operand_size,
1130 operand, ( size_x ) operand_size );
1131 ammunition_memset ( result, ( operand_sign ? UCHAR_MAX : 0 ),
1132 ( size_x ) ( result_size - operand_size ) );
1133 } else {
1134 _Pragma( "loopbound min 2 max 2" )
1135 for ( operand_digit_number = 0;
1136 operand_digit_number < operand_size - result_size;
1137 operand_digit_number++ ) {
1138 if ( ( ( unsigned char * ) operand ) [operand_digit_number]
1139 != ( operand_sign ? UCHAR_MAX : 0 ) ) {
1140 ammunition_overflow_bit = 1;
1141 break;
1142 }
1143 }
1144 ammunition_memmove ( result,
1145 ( char * ) operand + operand_size - result_size,
1146 ( size_x ) result_size );
1147 if ( operand_sign != INTEGER_SIGN ( result ) )
1148 ammunition_overflow_bit = 1;
1149 }
1150 if ( ammunition_overflow_bit )
1151 ammunition_arithmetic_overflow_reaction();
1152}
1153
1154
1155
1156/* This page contains functions for conversion of arbitrary precision
1157 numbers to ascii representation. */
1158
1159/* This function transforms unsigned integer of given size to BASE
1160 ascii representation. BASE should be between 2 and 36 including
1161 them. Digits more 9 are represented by 'a', 'b' etc. Sign is
1162 absent in result string. The function returns the result
1163 string. */
1164
1165char *
1166ammunition_unsigned_integer_to_based_string ( int size, const void *operand,
1167 int base,
1168 char *result )
1169{
1170 int digit_num;
1171 int i;
1172 unsigned long divisable;
1173 unsigned long remainder;
1174 int nonzero_flag;
1175 int length;
1176 int temporary;
1177 unsigned char operand_copy [MAX_INTEGER_OPERAND_SIZE];
1178
1179 ammunition_memcpy ( operand_copy, operand, ( size_x ) size );
1180 length = 0;
1181 _Pragma( "loopbound min 1 max 10" )
1182 do {
1183 nonzero_flag = 0 /* FALSE */;
1184 _Pragma( "loopbound min 2 max 6" )
1185 for ( digit_num = 0, remainder = 0; digit_num < size; digit_num++ ) {
1186 divisable = remainder * ( UCHAR_MAX + 1 ) + operand_copy [digit_num];
1187 remainder = divisable % base;
1188 operand_copy [digit_num] = ( unsigned char ) ( divisable / base );
1189 if ( operand_copy [digit_num] != 0 )
1190 nonzero_flag = 1 /* TRUE */;
1191 }
1192 result [length++] = ( unsigned char ) ( remainder < 10 ? '0' + remainder
1193 : 'a' + remainder - 10 );
1194 } while ( nonzero_flag );
1195 result [length] = '\0';
1196 _Pragma( "loopbound min 0 max 5" )
1197 for ( i = 0; i < length / 2; i++ ) {
1198 temporary = result [i];
1199 result [i] = result [length - i - 1];
1200 result [length - i - 1] = temporary;
1201 }
1202 return result;
1203}
1204
1205
1206/* This function transforms unsigned integer of given size to decimal
1207 ascii representation. Sign is absent in result string. The
1208 function returns the result string. */
1209
1210char *
1211ammunition_unsigned_integer_to_string ( int size, const void *operand,
1212 char *result )
1213{
1214 return ammunition_unsigned_integer_to_based_string ( size, operand, 10,
1215 result );
1216}
1217
1218
1219/* This function transforms integer of given size to BASE ascii
1220 representation. BASE should be between 2 and 36 including them.
1221 Digits more 9 are represented by 'a', 'b' etc. Sign is present in
1222 result string only for negative numbers. The function returns the
1223 result string. */
1224
1225char *
1226ammunition_integer_to_based_string ( int size, const void *operand, int base,
1227 char *result )
1228{
1229 unsigned char operand_copy [MAX_INTEGER_OPERAND_SIZE];
1230
1231 if ( !INTEGER_SIGN ( operand ) )
1232 return ammunition_unsigned_integer_to_based_string ( size, operand, base,
1233 result );
1234 ammunition_memcpy ( operand_copy, operand, ( size_x ) size );
1235 /* May be integer overflow. But result is correct because it is unsigned. */
1236 ammunition_make_complementary_code ( size, operand_copy, operand_copy );
1237 *result = '-';
1238 ammunition_unsigned_integer_to_based_string ( size, operand_copy, base,
1239 result + 1 );
1240 return result;
1241}
1242
1243
1244
1245/* This function transforms integer of given size to decimal ascii
1246 representation. Sign is present in result string only for negative
1247 numbers. The function returns the result string. */
1248
1249char *
1250ammunition_integer_to_string ( int size, const void *operand, char *result )
1251{
1252 return ammunition_integer_to_based_string ( size, operand, 10, result );
1253}
1254
1255/* This page contains functions for conversion of decimal ascii
1256 representation to arbitrary precision numbers. */
1257
1258/* The function adds digit (byte size) to unsigned integer. The
1259 function returns 1 if unsigned integer overflow is fixed, 0
1260 otherwise. */
1261
1262int ammunition_add_digit_to_unsigned_integer_without_overflow_reaction
1263( int size, void *operand, unsigned int digit )
1264{
1265 int digit_num;
1266 unsigned int carry;
1267 unsigned int sum;
1268
1269 _Pragma( "loopbound min 4 max 4" )
1270 for ( digit_num = size - 1, carry = digit; digit_num >= 0;
1271 digit_num-- ) {
1272 sum = ( ( unsigned char * ) operand ) [digit_num] + carry;
1273 if ( sum > UCHAR_MAX ) {
1274 carry = sum / ( UCHAR_MAX + 1 );
1275 sum %= UCHAR_MAX + 1;
1276 } else
1277 carry = 0;
1278 ( ( unsigned char * ) operand ) [digit_num] = sum;
1279 }
1280 return carry != 0;
1281}
1282
1283/* This function transforms source string (decimal ascii
1284 representation without sign) to given size unsigned integer and
1285 returns pointer to first non digit in the source string through a
1286 parameter. If the string started with invalid integer
1287 representation the result will be zero and returns the operand
1288 through the parameter. The function returns 1 if unsigned integer
1289 overflow is fixed, 0 otherwise. */
1290
1291int ammunition_string_to_unsigned_integer_without_overflow_reaction
1292( int size, const char *operand, void *result, char **first_nondigit )
1293{
1294 int overflow_flag;
1295
1296 ammunition_memset ( result, 0, ( size_x ) size );
1297 _Pragma( "loopbound min 0 max 10" )
1298 for ( overflow_flag = 0; ammunition_isdigit ( *operand ); operand++ ) {
1299 overflow_flag
1300 = overflow_flag ||
1301 ammunition_multiply_unsigned_integer_by_digit_without_overflow_reaction
1302 ( size, result, 10 );
1303 overflow_flag
1304 = overflow_flag
1305 || ammunition_add_digit_to_unsigned_integer_without_overflow_reaction
1306 ( size, result, *operand - '0' );
1307 }
1308 *first_nondigit = ( char * ) operand;
1309 return overflow_flag;
1310}
1311
1312/* This function skips all white spaces at the begin of source string
1313 and transforms tail of the source string (decimal ascii
1314 representation without sign) to given size unsigned integer with
1315 the aid of function
1316 `string_to_unsigned_integer_without_overflow_reaction'. If the
1317 string started with invalid unsigned integer representation the
1318 result will be zero. The function fixes overflow when result can
1319 not be represented by number of given size. The function returns
1320 address of the first nondigit in the source string. */
1321
1322char *
1323ammunition_unsigned_integer_from_string ( int size, const char *operand,
1324 void *result )
1325{
1326 char *first_nondigit;
1327
1328 _Pragma( "loopbound min 0 max 0" )
1329 while ( ammunition_isspace ( *operand ) )
1330 operand++;
1331 ammunition_overflow_bit
1332 = ammunition_string_to_unsigned_integer_without_overflow_reaction
1333 ( size, operand, result, &first_nondigit );
1334 if ( ammunition_overflow_bit )
1335 ammunition_arithmetic_unsigned_overflow_reaction();
1336 return first_nondigit;
1337}
1338
1339/* This function skips all white spaces at the begin of source string
1340 and transforms tail of the source string (decimal ascii
1341 representation with possible sign `+' or `-') to given size integer
1342 with the aid of function
1343 `string_to_unsigned_integer_without_overflow_reaction'. If the
1344 string started with invalid integer representation the result will
1345 be zero. The function fixes overflow when result can not be
1346 represented by number of given size. the function returns Address
1347 of the first nondigit in the source string. */
1348
1349char *
1350ammunition_integer_from_string ( int size, const char *operand, void *result )
1351{
1352 int negative_number_flag;
1353 char *first_nondigit;
1354 int unsigned_result_sign;
1355
1356 _Pragma( "loopbound min 0 max 0" )
1357 while ( ammunition_isspace ( *operand ) )
1358 operand++;
1359 negative_number_flag = 0; /* FALSE */
1360 if ( *operand == '+' )
1361 operand++;
1362 else
1363 if ( *operand == '-' ) {
1364 operand++;
1365 negative_number_flag = 1; /* TRUE */
1366 }
1367 ammunition_overflow_bit
1368 = ammunition_string_to_unsigned_integer_without_overflow_reaction
1369 ( size, operand, result, &first_nondigit );
1370 unsigned_result_sign = INTEGER_SIGN ( result );
1371 if ( negative_number_flag )
1372 /* May be integer overflow when `result' is correct. But result
1373 is correct because it is unsigned. */
1374 ammunition_make_complementary_code ( size, result, result );
1375 ammunition_overflow_bit
1376 = ammunition_overflow_bit
1377 || ( unsigned_result_sign
1378 && ( !negative_number_flag
1379 || INTEGER_SIGN ( result ) != unsigned_result_sign ) );
1380 if ( ammunition_overflow_bit )
1381 ammunition_arithmetic_unsigned_overflow_reaction();
1382 return first_nondigit;
1383}
1384
diff --git a/baseline/source/ammunition/arithm.h b/baseline/source/ammunition/arithm.h
new file mode 100644
index 0000000..8ed78bf
--- /dev/null
+++ b/baseline/source/ammunition/arithm.h
@@ -0,0 +1,123 @@
1/*
2 FILE NAME: arithm.h
3
4 TITLE: Include file of package for arbitrary precision integer
5 arithmetic
6
7 DESCRIPTION: This header file contains ANSI C prototype definitions of
8 the package functions and definitions of external
9 variable of the package and C++ classes for arbitrary
10 precision integer arithmetic.
11
12*/
13
14
15#ifndef __ARITHMETIC__
16#define __ARITHMETIC__
17
18#include "ammunition_limits.h"
19
20
21/* This page contains definitions of variables and macros common for
22 all package functions. */
23
24/* The value of macro is suggested to be maximum length of integer operands
25 The length of use integers should be not greater than this value. */
26
27#define MAX_INTEGER_OPERAND_SIZE 128
28
29/* The following macro value is sign of integer number (0 or 1) given
30 as macro parameter. */
31
32#define INTEGER_SIGN(operand) (*(unsigned char *) (operand) >> (CHAR_BIT - 1))
33
34extern int ammunition_overflow_bit;
35
36extern void ammunition_add_unsigned_integer ( int size, const void *op1,
37 const void *op2,
38 void *result );
39extern void ammunition_add_integer ( int size, const void *op1, const void *op2,
40 void *result );
41extern void ammunition_subtract_unsigned_integer ( int size, const void *op1,
42 const void *op2, void *result );
43extern void ammunition_subtract_integer ( int size, const void *op1,
44 const void *op2,
45 void *result );
46extern void ammunition_multiply_unsigned_integer ( int size, const void *op1,
47 const void *op2, void *result );
48extern void ammunition_multiply_integer ( int size, const void *op1,
49 const void *op2,
50 void *result );
51extern void ammunition_divide_unsigned_integer ( int size, const void *op1,
52 const void *op2, void *result );
53extern void ammunition_divide_integer ( int size, const void *op1,
54 const void *op2,
55 void *result );
56extern void ammunition_unsigned_integer_remainder ( int size, const void *op1,
57 const void *op2, void *result );
58
59extern void ammunition_unsigned_integer_shift_right ( int size,
60 const void *operand,
61 int bits, void *result );
62extern void ammunition_integer_shift_right ( int size, const void *operand,
63 int bits, void *result );
64extern void ammunition_integer_shift_left ( int size, const void *operand,
65 int bits, void *result );
66extern void ammunition_unsigned_integer_shift_left ( int size,
67 const void *operand,
68 int bits, void *result );
69
70extern void ammunition_integer_or ( int size, const void *op1,
71 const void *op2, void *result );
72extern void ammunition_unsigned_integer_or ( int size, const void *op1,
73 const void *op2, void *result );
74extern void ammunition_integer_and ( int size, const void *op1,
75 const void *op2, void *result );
76extern void ammunition_unsigned_integer_and ( int size, const void *op1,
77 const void *op2, void *result );
78extern void ammunition_integer_not ( int size, const void *operand,
79 void *result );
80extern void ammunition_unsigned_integer_not ( int size, const void *operand,
81 void *result );
82
83extern int ammunition_eq_unsigned_integer ( int size, const void *op1,
84 const void *op2 );
85extern int ammunition_eq_integer ( int size, const void *op1, const void *op2 );
86extern int ammunition_ne_unsigned_integer ( int size, const void *op1,
87 const void *op2 );
88extern int ammunition_ne_integer ( int size, const void *op1, const void *op2 );
89extern int ammunition_gt_unsigned_integer ( int size, const void *op1,
90 const void *op2 );
91extern int ammunition_gt_integer ( int size, const void *op1, const void *op2 );
92extern int ammunition_lt_unsigned_integer ( int size, const void *op1,
93 const void *op2 );
94extern int ammunition_lt_integer ( int size, const void *op1, const void *op2 );
95extern int ammunition_ge_unsigned_integer ( int size, const void *op1,
96 const void *op2 );
97extern int ammunition_ge_integer ( int size, const void *op1, const void *op2 );
98extern int ammunition_le_unsigned_integer ( int size, const void *op1,
99 const void *op2 );
100extern int ammunition_le_integer ( int size, const void *op1, const void *op2 );
101
102extern void ammunition_change_unsigned_integer_size
103( int operand_size, const void *operand, int result_size, void *result );
104extern void ammunition_change_integer_size ( int operand_size,
105 const void *operand,
106 int result_size, void *result );
107
108extern char *ammunition_unsigned_integer_to_string ( int size,
109 const void *operand,
110 char *result );
111extern char *ammunition_integer_to_string ( int size, const void *operand,
112 char *result );
113
114extern char *ammunition_unsigned_integer_from_string ( int size,
115 const char *operand,
116 void *result );
117extern char *ammunition_integer_from_string ( int size, const char *operand,
118 void *result );
119
120char ammunition_isdigit( unsigned char c );
121int ammunition_isspace( int c );
122
123#endif /* #ifndef __ARITHMETIC__ */
diff --git a/baseline/source/ammunition/bits.c b/baseline/source/ammunition/bits.c
new file mode 100644
index 0000000..9169656
--- /dev/null
+++ b/baseline/source/ammunition/bits.c
@@ -0,0 +1,313 @@
1/*
2
3 FILE NAME: bits.c
4
5 TITLE: Package for work with bits
6
7 DESCRIPTION: This file implements functions of the package for work
8 with bit strings. A bit is given by address (start address) of
9 byte from which counting bits starts and its displacement which
10 is any non negative number of bit from the start address. The
11 most significant bit of the start address byte has number 0.
12 The bit string is given by its first bit and its length in
13 bits.
14
15*/
16
17#include "bits.h"
18
19/* This function determines that given bit string contains only zero
20 bits. The function retruns TRUE if all bits of given bit string
21 are zero or `bit_length' <= 0. Value of `bit_displacement' must be
22 non-negative and can be greater than CHAR_BIT. */
23
24int
25ammunition_is_zero_bit_string ( const void *start_byte, int bit_displacement,
26 int bit_length )
27{
28 const unsigned char *current_byte = ( unsigned const char * )start_byte;
29
30 if ( bit_length <= 0 )
31 return 1 /* TRUE */;
32 current_byte += bit_displacement / CHAR_BIT;
33 bit_displacement %= CHAR_BIT;
34 if ( bit_length < CHAR_BIT - bit_displacement )
35 return ( ( ( *current_byte << bit_displacement )
36 & ( UCHAR_MAX << ( CHAR_BIT - bit_length ) ) )
37 & UCHAR_MAX ) == 0;
38 else
39 if ( bit_displacement != 0 ) {
40 if ( ( ( *current_byte << bit_displacement ) & UCHAR_MAX ) != 0 )
41 return 0 /* FALSE */;
42 current_byte += 1;
43 bit_length -= CHAR_BIT - bit_displacement;
44 }
45 _Pragma( "loopbound min 0 max 7" )
46 while ( bit_length >= CHAR_BIT ) {
47 if ( *current_byte != 0 )
48 return 0 /* FALSE */;
49 current_byte++;
50 bit_length -= CHAR_BIT;
51 }
52 if ( bit_length > 0 && ( *current_byte >> ( CHAR_BIT - bit_length ) ) != 0 )
53 return 0 /* FALSE */;
54 return 1 /* TRUE */;
55}
56
57/* This function sets up new value of all bits of given bit string.
58 This function is analog of standard C function `memset'. Value of
59 `bit_displacement' must be non-negative and can be greater than
60 CHAR_BIT. */
61
62void
63ammunition_bit_string_set ( void *start_byte, int bit_displacement, int bit,
64 int bit_length )
65{
66 unsigned char *current_byte = ( unsigned char * )start_byte;
67 unsigned char filling_byte;
68 int mask;
69
70 if ( bit_length <= 0 )
71 return ;
72 bit = bit != 0; /* 1 or 0 */
73 filling_byte = ( bit ? UCHAR_MAX : 0 );
74 current_byte += bit_displacement / CHAR_BIT;
75 bit_displacement %= CHAR_BIT;
76 if ( bit_displacement != 0 ) {
77 mask = UCHAR_MAX << ( CHAR_BIT - bit_displacement );
78 if ( bit_length < CHAR_BIT - bit_displacement )
79 mask |= UCHAR_MAX >> ( bit_displacement + bit_length );
80 *current_byte = ( *current_byte & mask ) | ( filling_byte & ~mask );
81 current_byte += 1;
82 bit_length -= CHAR_BIT - bit_displacement;
83 }
84 _Pragma( "loopbound min 0 max 8" )
85 while ( bit_length >= CHAR_BIT ) {
86 *current_byte = filling_byte;
87 current_byte++;
88 bit_length -= CHAR_BIT;
89 }
90 if ( bit_length > 0 )
91 *current_byte
92 = ( *current_byte & ~( UCHAR_MAX << ( CHAR_BIT - bit_length ) ) )
93 | ( filling_byte & ( UCHAR_MAX << ( CHAR_BIT - bit_length ) ) );
94}
95
96/* This function copys a bit string to another bit string. This
97 function is analog of standard C function `memcpy'. Values of
98 `to_bit_displacement' and `from_bit_displacement' must be
99 non-negative and can be greater than CHAR_BIT. The bit string must
100 be non-overlapped. */
101
102void
103ammunition_bit_string_copy ( void *to, int to_bit_displacement,
104 const void *from, int from_bit_displacement,
105 int bit_length )
106{
107 unsigned char *current_to_byte = ( unsigned char * )to;
108 const unsigned char *current_from_byte = ( unsigned const char * )from;
109 int byte;
110 int mask;
111
112 if ( bit_length <= 0 )
113 return ;
114 current_to_byte += to_bit_displacement / CHAR_BIT;
115 to_bit_displacement %= CHAR_BIT;
116 current_from_byte += from_bit_displacement / CHAR_BIT;
117 from_bit_displacement %= CHAR_BIT;
118 _Pragma( "loopbound min 1 max 8" )
119 while ( 1 ) {
120 byte = ( ( ( *current_from_byte << from_bit_displacement ) & UCHAR_MAX )
121 | ( from_bit_displacement != 0
122 && bit_length > ( CHAR_BIT - from_bit_displacement )
123 ? current_from_byte [1] >> ( CHAR_BIT - from_bit_displacement )
124 : 0 ) );
125 if ( bit_length <= CHAR_BIT )
126 break;
127 /* Shift is correct when to_bit_displacement == 0 because its
128 value is less than word bit size. */
129 *current_to_byte
130 = ( *current_to_byte
131 & ( UCHAR_MAX << ( CHAR_BIT - to_bit_displacement ) ) )
132 | ( byte >> to_bit_displacement );
133 if ( to_bit_displacement != 0 )
134 current_to_byte [1]
135 = ( current_to_byte [1] & ( UCHAR_MAX >> to_bit_displacement ) )
136 | ( byte << ( CHAR_BIT - to_bit_displacement ) );
137 bit_length -= CHAR_BIT;
138 current_from_byte++;
139 current_to_byte++;
140 }
141 /* Shift is correct when to_bit_displacement == 0 because its
142 value is less than word bit size. */
143 mask = ( ( UCHAR_MAX << ( CHAR_BIT - to_bit_displacement ) )
144 | ( UCHAR_MAX >> ( to_bit_displacement + bit_length ) ) );
145 *current_to_byte
146 = ( *current_to_byte & mask ) | ( ( byte >> to_bit_displacement ) & ~mask );
147 bit_length -= CHAR_BIT - to_bit_displacement;
148 if ( bit_length > 0 )
149 current_to_byte [1]
150 = ( current_to_byte [1] & ( UCHAR_MAX >> bit_length ) )
151 | ( ( byte << ( CHAR_BIT - to_bit_displacement ) )
152 & ( UCHAR_MAX << ( CHAR_BIT - bit_length ) ) );
153}
154
155/* This function copys a bit string to another bit string. Copying
156 starts with the last bits of the bit strings. This function is
157 used by function `bit_string_move'. Values of
158 `to_bit_displacement' and `from_bit_displacement' must be
159 non-negative and can be greater than CHAR_BIT. The bit string must
160 be non-overlapped. */
161
162void ammunition_reverse_bit_string_copy ( void *to, int to_bit_displacement,
163 const void *from, int from_bit_displacement,
164 int bit_length )
165{
166 unsigned char *current_to_byte = ( unsigned char * )to;
167 const unsigned char *current_from_byte = ( unsigned const char * )from;
168 int byte;
169 int mask;
170
171 if ( bit_length <= 0 )
172 return ;
173 to_bit_displacement += bit_length - 1;
174 current_to_byte += to_bit_displacement / CHAR_BIT; /* last byte */
175 to_bit_displacement %= CHAR_BIT; /* last bit */
176 from_bit_displacement += bit_length - 1;
177 current_from_byte += from_bit_displacement / CHAR_BIT; /* last byte */
178 from_bit_displacement %= CHAR_BIT; /* last bit */
179 _Pragma( "loopbound min 1 max 8" )
180 while ( 1 ) {
181 /* Shift is correct when to_bit_displacement == 0 because its
182 value is less than word bit size. */
183 byte = ( ( *current_from_byte >> ( CHAR_BIT - 1 - from_bit_displacement ) )
184 | ( ( from_bit_displacement != CHAR_BIT - 1
185 && bit_length > from_bit_displacement + 1
186 ? current_from_byte [ -1 ] << ( from_bit_displacement + 1 )
187 : 0 )
188 & UCHAR_MAX ) );
189 if ( bit_length <= CHAR_BIT )
190 break;
191 /* Shift is correct when to_bit_displacement == 0 because its
192 value is less than word bit size. */
193 *current_to_byte
194 = ( *current_to_byte & ( UCHAR_MAX >> ( to_bit_displacement + 1 ) ) )
195 | ( byte << ( CHAR_BIT - 1 - to_bit_displacement ) );
196 if ( to_bit_displacement != CHAR_BIT - 1 )
197 current_to_byte [-1]
198 = ( current_to_byte [-1]
199 & ( UCHAR_MAX << ( CHAR_BIT - 1 - to_bit_displacement ) ) )
200 | ( byte >> ( to_bit_displacement + 1 ) );
201 bit_length -= CHAR_BIT;
202 current_from_byte--;
203 current_to_byte--;
204 }
205 /* Shift is correct when to_bit_displacement == 0 because its
206 value is less than word bit size. */
207 mask = ( ( UCHAR_MAX >> ( to_bit_displacement + 1 ) ) |
208 ( UCHAR_MAX << ( CHAR_BIT - 1 - to_bit_displacement
209 + bit_length ) ) );
210 *current_to_byte
211 = ( *current_to_byte & mask )
212 | ( ( byte << ( CHAR_BIT - 1 - to_bit_displacement ) ) & ~mask );
213 bit_length -= to_bit_displacement + 1;
214 if ( bit_length > 0 )
215 current_to_byte [-1]
216 = ( current_to_byte [-1] & ( UCHAR_MAX << bit_length ) )
217 | ( byte >> ( to_bit_displacement + 1 )
218 & ( UCHAR_MAX >> ( CHAR_BIT - bit_length ) ) );
219}
220
221/* This function copys a bit string to another bit string with the aid
222 of functions `bit_string_copy' and `reverse_bit_string_copy'. This
223 function is analog of standard C function `memmove'. Values of
224 `to_bit_displacement' and `from_bit_displacement' must be
225 non-negative and can be greater than CHAR_BIT. The bit string can
226 be overlapped. */
227
228void
229ammunition_bit_string_move ( void *to, int to_bit_displacement,
230 const void *from, int from_bit_displacement,
231 int bit_length )
232{
233 unsigned char *current_to_byte = ( unsigned char * )to;
234 const unsigned char *current_from_byte = ( unsigned const char * )from;
235
236 if ( bit_length <= 0 )
237 return ;
238 current_to_byte += to_bit_displacement / CHAR_BIT;
239 to_bit_displacement %= CHAR_BIT;
240 current_from_byte += from_bit_displacement / CHAR_BIT;
241 from_bit_displacement %= CHAR_BIT;
242 if ( current_from_byte > current_to_byte
243 || ( current_from_byte == current_to_byte
244 && from_bit_displacement > to_bit_displacement ) )
245 ammunition_bit_string_copy ( current_to_byte, to_bit_displacement,
246 current_from_byte, from_bit_displacement,
247 bit_length );
248 else
249 ammunition_reverse_bit_string_copy ( current_to_byte, to_bit_displacement,
250 current_from_byte,
251 from_bit_displacement, bit_length );
252}
253
254/* This function compares bit strings. This function is analog of
255 standard C function `memcmp'. The function returns 0 if the bit
256 strings are equal, 1 if the first bit string is greater than the
257 second, -1 if the first bit string is less than the first. Values
258 of `bit_displacement1' and `bit_displacement2' must be non-negative
259 and can be greater than CHAR_BIT. */
260
261int
262ammunition_bit_string_comparison ( const void *str1, int bit_displacement1,
263 const void *str2, int bit_displacement2,
264 int bit_length )
265{
266 const unsigned char *current_byte1 = ( unsigned const char * )str1;
267 const unsigned char *current_byte2 = ( unsigned const char * )str2;
268 int byte1;
269 int byte2;
270 int mask;
271
272 if ( bit_length <= 0 )
273 return 0;
274 current_byte1 += bit_displacement1 / CHAR_BIT;
275 bit_displacement1 %= CHAR_BIT;
276 current_byte2 += bit_displacement2 / CHAR_BIT;
277 bit_displacement2 %= CHAR_BIT;
278 _Pragma( "loopbound min 1 max 284" )
279 while ( 1 ) {
280 byte1 = ( ( ( *current_byte1 << bit_displacement1 ) & UCHAR_MAX )
281 | ( bit_displacement1 != 0
282 /* Shift is correct when to_bit_displacement == 0
283 because its value is less than word bit size. */
284 && bit_length > CHAR_BIT - bit_displacement1
285 ? current_byte1 [1] >> ( CHAR_BIT - bit_displacement1 )
286 : 0 ) );
287 byte2 = ( ( ( *current_byte2 << bit_displacement2 ) & UCHAR_MAX )
288 | ( bit_displacement2 != 0
289 && bit_length > CHAR_BIT - bit_displacement2
290 ? current_byte2 [1] >> ( CHAR_BIT - bit_displacement2 )
291 : 0 ) );
292 if ( bit_length <= CHAR_BIT )
293 break;
294 if ( byte1 > byte2 )
295 return 1;
296 else
297 if ( byte1 < byte2 )
298 return -1;
299 bit_length -= CHAR_BIT;
300 current_byte2++;
301 current_byte1++;
302 }
303 /* Shift is correct when to_bit_displacement == 0 because its value
304 is less than word bit size. */
305 mask = UCHAR_MAX << ( CHAR_BIT - bit_length );
306 if ( ( byte1 & mask ) > ( byte2 & mask ) )
307 return 1;
308 else
309 if ( ( byte1 & mask ) < ( byte2 & mask ) )
310 return -1;
311 else
312 return 0;
313}
diff --git a/baseline/source/ammunition/bits.h b/baseline/source/ammunition/bits.h
new file mode 100644
index 0000000..70cf8bd
--- /dev/null
+++ b/baseline/source/ammunition/bits.h
@@ -0,0 +1,60 @@
1/*
2 FILE NAME: bits.h
3
4 TITLE: Include file of package for work with bits
5
6 DESCRIPTION:
7 This is header file contains macros and the ANSI C prototype
8 definitions for the package for work with bits and bit strings
9 and C++ class for work with bits and bit strings. A bit is
10 given by address (start address) of byte from which counting
11 bits starts and its displacement which is any non negative
12 number of bit from the start address. The most significant bit
13 of the start address byte has number 0. The bit string is
14 given by its first bit and its length in bits.
15
16*/
17
18#ifndef __BITS__
19#define __BITS__
20
21#include "ammunition_limits.h"
22
23/* This macro value returns bit vlaue (0 or 1) with given bit
24 displacement (0, 1, ...). The macro has side effects! Value of
25 `bit_displacement' must be nonegative and can be greater than
26 CHAR_BIT. */
27
28#define BIT(start_byte, bit_displacement)\
29 ((((const char *) (start_byte)) [(bit_displacement) / CHAR_BIT]\
30 >> (CHAR_BIT - 1 - (bit_displacement) % CHAR_BIT)) & 1)
31
32
33/* This macro value sets up new value (must be `0' or `1') of a given
34 bit (bit displacement starts with 0). The macro has side effects!
35 Value of `bit_displacement' must be nonegative and can be greater
36 than CHAR_BIT. */
37
38#define SET_BIT(start_byte, bit_displacement, bit)\
39 (((char *) (start_byte)) [(bit_displacement) / CHAR_BIT]\
40 = (((char *) (start_byte)) [(bit_displacement) / CHAR_BIT]\
41 & ~(1 << (CHAR_BIT - 1 - (bit_displacement) % CHAR_BIT)))\
42 | ((bit) << (CHAR_BIT - 1 - (bit_displacement) % CHAR_BIT)))
43
44int ammunition_is_zero_bit_string ( const void *start_byte,
45 int bit_displacement,
46 int bit_length );
47void ammunition_bit_string_set ( void *start_byte, int bit_displacement,
48 int bit,
49 int bit_length );
50void ammunition_bit_string_copy ( void *to, int to_bit_displacement,
51 const void *from, int from_bit_displacement,
52 int bit_length );
53void ammunition_bit_string_move ( void *to, int to_bit_displacement,
54 const void *from, int from_bit_displacement,
55 int bit_length );
56int ammunition_bit_string_comparison ( const void *str1, int bit_displacement1,
57 const void *str2, int bit_displacement2,
58 int bit_length );
59
60#endif /* #ifndef __BITS__ */
diff --git a/baseline/source/ammunition/gmon.out b/baseline/source/ammunition/gmon.out
new file mode 100644
index 0000000..2d07b7f
--- /dev/null
+++ b/baseline/source/ammunition/gmon.out
Binary files differ
diff --git a/baseline/source/ammunition/timeScript b/baseline/source/ammunition/timeScript
new file mode 100644
index 0000000..33ba812
--- /dev/null
+++ b/baseline/source/ammunition/timeScript
@@ -0,0 +1,8 @@
1#!/bin/bash
2startTime=$(date +%N)
3echo start time $startTime
4$1
5stopTime=$(date +%N)
6echo stop time $stopTime
7totalTime=`expr $stopTime - $startTime`
8echo total time $totalTime