From 386b7d3366f1359a265da207a9cafa3edf553b64 Mon Sep 17 00:00:00 2001 From: Joshua Bakita Date: Mon, 7 Oct 2019 19:13:39 -0400 Subject: Reorganize and commit all the modified TACLeBench code and run scripts --- all_pairs/source/ammunition/ChangeLog.txt | 66 ++ all_pairs/source/ammunition/README | 86 ++ all_pairs/source/ammunition/ammunition.c | 1185 +++++++++++++++++++ all_pairs/source/ammunition/ammunitionTimed.txt | 100 ++ all_pairs/source/ammunition/ammunition_libc.c | 166 +++ all_pairs/source/ammunition/ammunition_limits.h | 35 + all_pairs/source/ammunition/ammunition_stdio.h | 8 + all_pairs/source/ammunition/ammunition_stdlib.h | 6 + all_pairs/source/ammunition/ammunition_string.h | 18 + all_pairs/source/ammunition/arithm.c | 1384 +++++++++++++++++++++++ all_pairs/source/ammunition/arithm.h | 123 ++ all_pairs/source/ammunition/bits.c | 313 +++++ all_pairs/source/ammunition/bits.h | 60 + all_pairs/source/ammunition/gmon.out | Bin 0 -> 31048 bytes all_pairs/source/ammunition/timeScript | 8 + 15 files changed, 3558 insertions(+) create mode 100644 all_pairs/source/ammunition/ChangeLog.txt create mode 100644 all_pairs/source/ammunition/README create mode 100644 all_pairs/source/ammunition/ammunition.c create mode 100644 all_pairs/source/ammunition/ammunitionTimed.txt create mode 100644 all_pairs/source/ammunition/ammunition_libc.c create mode 100644 all_pairs/source/ammunition/ammunition_limits.h create mode 100644 all_pairs/source/ammunition/ammunition_stdio.h create mode 100644 all_pairs/source/ammunition/ammunition_stdlib.h create mode 100644 all_pairs/source/ammunition/ammunition_string.h create mode 100644 all_pairs/source/ammunition/arithm.c create mode 100644 all_pairs/source/ammunition/arithm.h create mode 100644 all_pairs/source/ammunition/bits.c create mode 100644 all_pairs/source/ammunition/bits.h create mode 100644 all_pairs/source/ammunition/gmon.out create mode 100644 all_pairs/source/ammunition/timeScript (limited to 'all_pairs/source/ammunition') diff --git a/all_pairs/source/ammunition/ChangeLog.txt b/all_pairs/source/ammunition/ChangeLog.txt new file mode 100644 index 0000000..814ed86 --- /dev/null +++ b/all_pairs/source/ammunition/ChangeLog.txt @@ -0,0 +1,66 @@ +File: ammunition.c +Original provenience: DINO programming language + +2016-03-03: +- Add generic TACLeBench header +- Prefix global functions with benchmark name +- Introduce volatile result variable for return statements +- Split code into ammunition_init and ammunition_main +- Fix compiler warnings "array subscript is of type 'char'": + char => unsigned char +- Fix compiler warnings "'&&' within '||'": + Place additional parentheses +- Remove usages and comments related to the macros + HAVE_MEMMOVE, NDEBUG, HAVE_MEMCMP +- Remove comment related to unused NO_TEMPLATE macro +2016-05-02: +- Change C++ style comments to ISO C90 compliant comments +- Avoid mixing declarations and code: move declaration of variable writePos in + functions ammunition_sprintf_d and ammunition_sprintf_u +- Change datatype in function ammunition_bits_test of iteration variables i and + j from int to unsigned int to avoid comparison between signed and unsigned + integer expressions +- Add forward declarations to ammunition.c +- Introduce variable ammunition_result +- Parantheses around comparison in functions ammunition_isdigit and + ammunition_isspace +- Remove usage of limits.h, move definitions of limits into separate file + ammunition_limits.h +- Remove unconditional assignments of variable result to zero after each test in + functions ammunition_bits_test and ammunition_arithm_test +- Remove unused functions unsigned_integer_maximum, integer_minimum, + integer_maximum, integer_remainder +- Remove unused declaration of function default_arithmetic_overflow_reaction +- Remove unused variables zero_constant_itself, zero_constant +- Remove unused declarations of functions set_unsigned_integer_overflow_reaction + and set_integer_overflow_reaction +- Remove block #ifndef MAX_INTEGER_OPERAND_SIZE, set definition of + MAX_INTEGER_OPERAND_SIZE to 128, since this is default +2016-05-10: +- Integrate new version of arithm library from ammunition repository from + dino repository on github (commit: db9cfab042c332abb234ec8d72750103010981c1), + which hanles arithmetic shifts by negative numbers. This change now makes all + test cases in ammunition.c pass. Update headers unsigned int bits => int bits +- Remove assert statements +- Fix memcmp implementation: dereferencing pointer was missing +- Add loop-bound annotation to memcmp +- Fix strcmp implementation +- Integrate working versions of memcpy and memset from pm benchmark +- Update signature of ammunition_memcpy to original version: + void *memcpy(void *dest, const void *src, size_x n); +- Move functions from libc into separate file, introduce header files + ammunition_limits.h, ammunition_stdio.h, ammunition_stdlib.h, + ammunition_string.h +- Fix overflow in sprintf_d: change datatype of variable 'copyOfNumber' from int + to long, since the negative value of INT_MIN is undefined + 2016-05-17: +- Remove all static declarations of global functions +- Rename variables 'digit_number' to digit_num to keep lines below 80 characters +- Rename op1_digit_number to op1_digit_number and op1_digit_num in function + 'ammunition_multiply_unsigned_integer_without_overflow_reaction' +- Rename variable 'scaled_op1_digit_number' in function + 'ammunition_divide_unsigned_integer_without_overflow_reaction' +- Apply code formatting with astyle + +2017-08-18: +- Add explicit casts to silence g++ warnings. diff --git a/all_pairs/source/ammunition/README b/all_pairs/source/ammunition/README new file mode 100644 index 0000000..8caddf4 --- /dev/null +++ b/all_pairs/source/ammunition/README @@ -0,0 +1,86 @@ +This directory AMMUNITION contains reusable packages on C/C++: +`allocate', `vlobject', `objstack', `hashtab', `commline', `ticker', +`position', `errors', `bits', `arithm', `IEEE': + o allocate + Allocating and freeing memory with automatic fixing some + allocation errors. + o vlobject + Work with variable length objects (VLO). Any number of bytes + may be added to and removed from the end of VLO. If it is + needed the memory allocated for storing variable length object + may be expanded possibly with changing the object place. But + between any additions of the bytes (or tailoring) the object + place is not changed. To decrease number of changes of the + object place the memory being allocated for the object is + longer than the current object length. + o objstack + Work with stacks of objects (OS). Work with the object on the + stack top is analogous to one with a variable length object. + One motivation for the package is the problem of growing char + strings in symbol tables. Memory for OS is allocated by + segments. A segment may contain more one objects. The most + recently allocated segment contains object on the top of OS. + If there is not sufficient free memory for the top object than + new segment is created and the top object is transferred into + the new segment, i.e. there is not any memory reallocation. + Therefore the top object may change its address. But other + objects never change address. + o hashtab + Work with hash tables. The package permits to work + simultaneously with several expandable hash tables. Besides + insertion and search of elements the elements from the hash + tables can be also removed. The table element can be only a + pointer. The size of hash tables is not fixed. The hash + table will be automatically expanded when its occupancy will + became big. + o position + Work with source code positions. The package serves to + support information about source positions of compiled files + taking all included files into account. + o errors + Output of compiler messages. The package serves output + one-pass or multi-pass compiler messages of various modes + (errors, warnings, fatal, system errors and appended messages) + in Unix style or for traditional listing. The package also + permits adequate error reporting for included files. + o commline + Work with command line. The package implements features + analogous to ones of public domain function `getopt'. The + goal of the package creation is to use more readable language + of command line description and to use command line + description as help output of program. + o ticker + Simultaneous work with several tickers (timers). + o bits + Work with bit strings (copying, moving, setting, testing, + comparison). + o arithm + Implementing host machine-independently arbitrary precision + integer numbers arithmetic. The implementation of the package + functions are not sufficiently efficient in order to use for + run-time. The package functions are oriented to implement + constant-folding in compilers, cross-compilers. + o IEEE + Implementing host machine-independently IEEE floating point + arithmetic. The implementation of the package functions are + not sufficiently efficient in order to use for run-time. The + package functions are oriented to implement constant-folding + in compilers, cross-compilers. + + There are files with corresponding names and extensions `.h' +(interface file for C/C++), `.c' (implementation file on C), and +`.cpp' (implementation file on C++). + + To install AMMUNITION see file INSTALL in the current directory. + + There are also shell scripts for testing the package with +corresponding names and extension `.tst'. Documentation of the +reusable packages is in files `ammunition.txt', `ammunition.dvi', +`ammunition.ps', `ammunition.info*', `ammunition*.html', +`ammunition*.rtf' for C and `ammunition++.txt', `ammunition++.dvi', +`ammunition++.ps', `ammunition++.info*', `ammunition++*.html', +`ammunition++*.rtf'. + +Please send bug reports and comments to vmakarov@fnmail.com + +Vladimir Makarov diff --git a/all_pairs/source/ammunition/ammunition.c b/all_pairs/source/ammunition/ammunition.c new file mode 100644 index 0000000..224babd --- /dev/null +++ b/all_pairs/source/ammunition/ammunition.c @@ -0,0 +1,1185 @@ +/* + + This program is part of the TACLeBench benchmark suite. + Version V 2.0 + + Name: ammunition + + Author: Vladimir Makarov + + Function: Tests reusable packages bits and arith + bits: Work with bit strings (copying, moving, setting, testing, comparison). + arith: Implementing host machine-independently arbitrary precision integer + numbers arithmetic. The implementation of the package functions are not + sufficiently efficient in order to use for run-time. The package + functions are oriented to implement constant-folding in compilers, + cross-compilers. + + Source: DINO programming language repository + https://github.com/dino-lang/dino/ + + Changes: no major functional changes + + License: GPL 2 and LGPL 2 + +*/ + +#include "../extra.h" +#include "bits.h" +#include "arithm.h" +#include "ammunition_stdlib.h" +#include "ammunition_stdio.h" +#include "ammunition_string.h" + +/* + Forward declaration of functions +*/ + +void ammunition_reset_str_bits( char *str, char *s ); +void ammunition_reset_str_arithm( char *str, char *s, char *d, char *e, + char *g ); +int ammunition_bits_test(); +int ammunition_arithm_test(); +void ammunition_init( void ); +int ammunition_return( void ); +void ammunition_main( void ); +//int main( void ); + + +/* + Forward declaration of global variables +*/ + +int ammunition_result; + + +/* + Core functions +*/ + +void ammunition_reset_str_bits( char *str, char *s ) +{ + int i; + _Pragma( "loopbound min 8 max 8" ) + for ( i = 0; i < 8; i++ ) { + str[i] = 0; + s[i] = 0; + } +} + + +void ammunition_reset_str_arithm( char *str, char *s, char *d, char *e, + char *g ) +{ + int i; + _Pragma( "loopbound min 20 max 20" ) + for ( i = 0; i < 20; i++ ) { + str[i] = 0; + s[i] = 0; + } + + _Pragma( "loopbound min 4 max 4" ) + for ( i = 0; i < 4; i++ ) { + d[i] = 0; + e[i] = 0; + } + + _Pragma( "loopbound min 6 max 6" ) + for ( i = 0; i < 6; i++ ) + g[i] = 0; +} + + +int ammunition_bits_test() +{ + char str[8]; + char str1[8]; + + int result = 0; + unsigned int i, j; + + /* Test 1 */ + ammunition_reset_str_bits( str, str1 ); + + _Pragma( "loopbound min 64 max 64" ) + for ( i = 0; i < sizeof ( str ) * CHAR_BIT; i++ ) { + if ( BIT ( str, i ) ) + result = 1; + } + + _Pragma( "loopbound min 64 max 64" ) + for ( i = 0; i < sizeof ( str ) * CHAR_BIT; i++ ) { + SET_BIT ( str, i, 1 ); + _Pragma( "loopbound min 64 max 64" ) + for ( j = 0; j < sizeof ( str ) * CHAR_BIT; j++ ) + if ( j <= i ) { + if ( BIT ( str, j ) == 0 ) + result = 1; + } else + if ( BIT ( str, j ) ) + result = 1; + } + + /* Test 2 */ + ammunition_reset_str_bits( str, str1 ); + + _Pragma( "loopbound min 64 max 64" ) + for ( i = 0; i < sizeof ( str ) * CHAR_BIT; i++ ) + if ( !ammunition_is_zero_bit_string ( + str, i, ( sizeof ( str ) * CHAR_BIT - i ) / 2 + 1 ) ) + result = 1; + ammunition_bit_string_set ( str, 13, 1, 35 ); + _Pragma( "loopbound min 13 max 13" ) + for ( i = 0; i < 13; i++ ) + if ( !ammunition_is_zero_bit_string ( str, i, 13 - i ) ) + result = 1; + _Pragma( "loopbound min 35 max 35" ) + for ( i = 13; i < 48; i++ ) + if ( ammunition_is_zero_bit_string ( str, i, 48 - i ) ) + result = 1; + _Pragma( "loopbound min 16 max 16" ) + for ( i = 48; i < sizeof ( str ) * CHAR_BIT; i++ ) + if ( !ammunition_is_zero_bit_string ( str, i, + sizeof ( str ) * CHAR_BIT - i ) ) + result = 1; + + /* Test 3 */ + ammunition_reset_str_bits( str, str1 ); + + _Pragma( "loopbound min 42 max 42" ) + for ( i = 0; i + i / 2 + 1 < sizeof ( str ) * CHAR_BIT; i++ ) { + ammunition_bit_string_set ( str, i, 1, i / 2 + 1 ); + if ( !ammunition_is_zero_bit_string ( str, 0, i - 1 ) ) + result = 1; + if ( ammunition_is_zero_bit_string ( str, i, i / 2 + 1 ) ) + result = 1; + if ( !ammunition_is_zero_bit_string ( + str, i + i / 2 + 1, sizeof ( str ) * CHAR_BIT - ( i + i / 2 + 1 ) ) ) + result = 1; + ammunition_bit_string_set ( str, 0, 0, sizeof ( str ) * CHAR_BIT ); + } + + /* Test 4 */ + ammunition_reset_str_bits( str, str1 ); + + ammunition_bit_string_set ( str, 2, 1, 43 ); + ammunition_bit_string_set ( str1, 2, 1, 40 ); + _Pragma( "loopbound min 42 max 42" ) + for ( i = 0; i < 42; i++ ) + if ( ammunition_bit_string_comparison ( str, i, str1, i, 42 - i ) != 0 ) + result = 1; + _Pragma( "loopbound min 43 max 43" ) + for ( i = 0; i < 43; i++ ) + if ( ammunition_bit_string_comparison ( str, i, str1, i, + sizeof ( str ) * CHAR_BIT - i ) + <= 0 ) + result = 1; + _Pragma( "loopbound min 43 max 43" ) + for ( i = 0; i < 43; i++ ) + if ( ammunition_bit_string_comparison ( str1, i, str, i, + sizeof ( str ) * CHAR_BIT - i ) + >= 0 ) + result = 1; + + /* Test 5 */ + ammunition_reset_str_bits( str, str1 ); + + ammunition_bit_string_set ( str, 2, 1, 43 ); + _Pragma( "loopbound min 59 max 59" ) + for ( i = 0; i + 5 < sizeof ( str ) * CHAR_BIT; i++ ) { + ammunition_bit_string_copy ( str1, i + 5, str, i, + sizeof ( str ) * CHAR_BIT - i - 5 ); + if ( ammunition_bit_string_comparison ( + str1, i + 5, str, i, sizeof ( str ) * CHAR_BIT - i - 5 ) != 0 ) + result = 1; + } + + /* Test 6 */ + ammunition_reset_str_bits( str, str1 ); + + ammunition_bit_string_set ( str, 2, 1, 43 ); + ammunition_bit_string_set ( str1, 2, 1, 43 ); + _Pragma( "loopbound min 59 max 59" ) + for ( i = 0; i + 5 < sizeof ( str ) * CHAR_BIT; i++ ) { + ammunition_bit_string_set ( str, 0, 0, sizeof ( str ) * CHAR_BIT ); + ammunition_bit_string_set ( str, 2, 1, 43 ); + ammunition_bit_string_move ( str, i + 5, str, i, + sizeof ( str ) * CHAR_BIT - i - 5 ); + if ( ammunition_bit_string_comparison ( + str, i + 5, str1, i, sizeof ( str ) * CHAR_BIT - i - 5 ) != 0 ) + result = 1; + } + + /* Test 7 */ + ammunition_reset_str_bits( str, str1 ); + + ammunition_bit_string_set ( str, 2, 1, 43 ); + ammunition_bit_string_set ( str1, 2, 1, 43 ); + _Pragma( "loopbound min 59 max 59" ) + for ( i = 0; i + 5 < sizeof ( str ) * CHAR_BIT; i++ ) { + ammunition_bit_string_set ( str, 0, 0, sizeof ( str ) * CHAR_BIT ); + ammunition_bit_string_set ( str, 2, 1, 43 ); + ammunition_bit_string_move ( str, i, str, i + 5, + sizeof ( str ) * CHAR_BIT - i - 5 ); + if ( ammunition_bit_string_comparison ( + str, i, str1, i + 5, sizeof ( str ) * CHAR_BIT - i - 5 ) != 0 ) + result = 1; + } + + return result; +} + + +int ammunition_arithm_test() +{ + int result = 0; + + /* Test 1 */ + int i; + char str [20], s[20], d[4], e[4], g[6]; + + ammunition_integer_from_string ( 4, "-2147483649", d ); + if ( !ammunition_overflow_bit ) + result = 1; + ammunition_sprintf_d( str, INT_MIN ); + ammunition_integer_from_string ( 4, str, d ); + if ( ammunition_overflow_bit ) + result = 1; + ammunition_integer_to_string( 4, d, s ); + if ( ammunition_strcmp ( s, str ) != 0 ) + result = 1; + ammunition_integer_from_string ( 4, "2147483648", d ); + if ( !ammunition_overflow_bit ) + result = 1; + ammunition_sprintf_d( str, INT_MAX ); + ammunition_integer_from_string ( 4, str, d ); + if ( ammunition_overflow_bit ) + result = 1; + ammunition_integer_to_string( 4, d, s ); + if ( ammunition_strcmp ( s, str ) != 0 ) + result = 1; + _Pragma( "loopbound min 4000 max 4000" ) + for ( i = -2000; i < 2000 ; i++ ) { + ammunition_sprintf_d( str, i ); + ammunition_integer_from_string ( 4, str, d ); + if ( ammunition_overflow_bit ) + result = 1; + ammunition_integer_to_string( 4, d, s ); + if ( ammunition_strcmp ( s, str ) != 0 ) + result = 1; + } + + /* Test 2 */ + ammunition_reset_str_arithm( str, s, d, e, g ); + + ammunition_unsigned_integer_from_string ( 4, "4294967296", d ); + if ( !ammunition_overflow_bit ) + result = 1; + ammunition_sprintf_u( str, UINT_MAX ); + ammunition_unsigned_integer_from_string ( 4, str, d ); + if ( ammunition_overflow_bit ) + result = 1; + ammunition_unsigned_integer_to_string ( 4, d, s ); + if ( ammunition_strcmp ( s, str ) != 0 ) + result = 1; + _Pragma( "loopbound min 4000 max 4000" ) + for ( i = 0; i < 4000 ; i++ ) { + ammunition_sprintf_u( str, i ); + ammunition_unsigned_integer_from_string ( 4, str, d ); + if ( ammunition_overflow_bit ) + result = 1; + ammunition_unsigned_integer_to_string ( 4, d, s ); + if ( ammunition_strcmp ( s, str ) != 0 ) + result = 1; + } + + /* Test 3 */ + ammunition_reset_str_arithm( str, s, d, e, g ); + + ammunition_sprintf_d( str, INT_MAX ); + ammunition_integer_from_string ( 4, str, d ); + ammunition_integer_from_string ( 4, "1", e ); + ammunition_add_integer ( 4, d, e, d ); + if ( !ammunition_overflow_bit ) + result = 1; + ammunition_sprintf_d( str, INT_MAX - 4 ); + ammunition_integer_from_string ( 4, str, d ); + ammunition_sprintf_d( str, 4 ); + ammunition_integer_from_string ( 4, str, e ); + ammunition_add_integer ( 4, d, e, d ); + if ( ammunition_overflow_bit ) + result = 1; + ammunition_integer_to_string( 4, d, s ); + ammunition_sprintf_d( str, INT_MAX ); + if ( ammunition_strcmp ( s, str ) != 0 ) + result = 1; + _Pragma( "loopbound min 4000 max 4000" ) + for ( i = -2000; i < 2000 ; i++ ) { + ammunition_sprintf_d( str, i ); + ammunition_integer_from_string ( 4, str, d ); + ammunition_sprintf_d( str, i + 1 ); + ammunition_integer_from_string ( 4, str, e ); + ammunition_add_integer ( 4, d, e, d ); + if ( ammunition_overflow_bit ) + result = 1; + ammunition_integer_to_string( 4, d, s ); + if ( ammunition_atoi ( s ) != i + i + 1 ) + result = 1; + } + + /* Test 4 */ + ammunition_reset_str_arithm( str, s, d, e, g ); + + ammunition_sprintf_u( str, UINT_MAX ); + ammunition_unsigned_integer_from_string ( 4, str, d ); + ammunition_unsigned_integer_from_string ( 4, "1", e ); + ammunition_add_unsigned_integer ( 4, d, e, d ); + if ( !ammunition_overflow_bit ) + result = 1; + ammunition_sprintf_u( str, UINT_MAX - 4 ); + ammunition_unsigned_integer_from_string ( 4, str, d ); + ammunition_sprintf_u( str, 4 ); + ammunition_unsigned_integer_from_string ( 4, str, e ); + ammunition_add_unsigned_integer ( 4, d, e, d ); + if ( ammunition_overflow_bit ) + result = 1; + ammunition_unsigned_integer_to_string ( 4, d, s ); + ammunition_sprintf_u( str, UINT_MAX ); + if ( ammunition_strcmp ( s, str ) != 0 ) + result = 1; + _Pragma( "loopbound min 4000 max 4000" ) + for ( i = 0; i < 4000 ; i++ ) { + ammunition_sprintf_u( str, i ); + ammunition_unsigned_integer_from_string ( 4, str, d ); + ammunition_sprintf_u( str, i + 1 ); + ammunition_unsigned_integer_from_string ( 4, str, e ); + ammunition_add_unsigned_integer ( 4, d, e, d ); + if ( ammunition_overflow_bit ) + result = 1; + ammunition_unsigned_integer_to_string ( 4, d, s ); + if ( ammunition_atoi ( s ) != i + i + 1 ) + result = 1; + } + + /* Test 5 */ + ammunition_reset_str_arithm( str, s, d, e, g ); + + ammunition_sprintf_d( str, INT_MIN ); + ammunition_integer_from_string ( 4, str, d ); + ammunition_integer_from_string ( 4, "1", e ); + ammunition_subtract_integer ( 4, d, e, d ); + if ( !ammunition_overflow_bit ) + result = 1; + ammunition_sprintf_d( str, INT_MIN + 4 ); + ammunition_integer_from_string ( 4, str, d ); + ammunition_sprintf_d( str, 4 ); + ammunition_integer_from_string ( 4, str, e ); + ammunition_subtract_integer ( 4, d, e, d ); + if ( ammunition_overflow_bit ) + result = 1; + ammunition_integer_to_string( 4, d, s ); + ammunition_sprintf_d( str, INT_MIN ); + if ( ammunition_strcmp ( s, str ) != 0 ) + result = 1; + _Pragma( "loopbound min 4000 max 4000" ) + for ( i = -2000; i < 2000 ; i++ ) { + ammunition_sprintf_d( str, i ); + ammunition_integer_from_string ( 4, str, d ); + ammunition_sprintf_d( str, 10 - i ); + ammunition_integer_from_string ( 4, str, e ); + ammunition_subtract_integer ( 4, d, e, d ); + if ( ammunition_overflow_bit ) + result = 1; + ammunition_integer_to_string( 4, d, s ); + if ( ammunition_atoi ( s ) != i + i - 10 ) + result = 1; + } + + /* Test 6 */ + ammunition_reset_str_arithm( str, s, d, e, g ); + + ammunition_sprintf_u( str, UINT_MAX - 2 ); + ammunition_unsigned_integer_from_string ( 4, str, d ); + ammunition_sprintf_u( str, UINT_MAX - 1 ); + ammunition_unsigned_integer_from_string ( 4, str, e ); + ammunition_subtract_unsigned_integer ( 4, d, e, d ); + if ( !ammunition_overflow_bit ) + result = 1; + ammunition_sprintf_u( str, UINT_MAX ); + ammunition_unsigned_integer_from_string ( 4, str, d ); + ammunition_subtract_unsigned_integer ( 4, d, d, d ); + if ( ammunition_overflow_bit ) + result = 1; + ammunition_unsigned_integer_to_string ( 4, d, s ); + if ( ammunition_strcmp ( s, "0" ) != 0 ) + result = 1; + _Pragma( "loopbound min 4000 max 4000" ) + for ( i = 0; i < 4000 ; i++ ) { + ammunition_sprintf_u( str, i ); + ammunition_unsigned_integer_from_string ( 4, str, d ); + ammunition_sprintf_u( str, i / 2 ); + ammunition_unsigned_integer_from_string ( 4, str, e ); + ammunition_subtract_unsigned_integer ( 4, d, e, d ); + if ( ammunition_overflow_bit ) + result = 1; + ammunition_unsigned_integer_to_string ( 4, d, s ); + if ( ammunition_atoi ( s ) != i - i / 2 ) + result = 1; + } + + /* Test 7 */ + ammunition_reset_str_arithm( str, s, d, e, g ); + + ammunition_sprintf_d( str, INT_MAX / 2 + 1 ); + ammunition_integer_from_string ( 4, str, d ); + ammunition_integer_from_string ( 4, "2", e ); + ammunition_multiply_integer ( 4, d, e, d ); + if ( !ammunition_overflow_bit ) + result = 1; + ammunition_sprintf_d( str, INT_MIN / 2 - 1 ); + ammunition_integer_from_string ( 4, str, d ); + ammunition_integer_from_string ( 4, "2", e ); + ammunition_multiply_integer ( 4, d, e, d ); + if ( !ammunition_overflow_bit ) + result = 1; + ammunition_sprintf_d( str, INT_MAX / 3 ); + ammunition_integer_from_string ( 4, str, d ); + ammunition_sprintf_d( str, 3 ); + ammunition_integer_from_string ( 4, str, e ); + ammunition_multiply_integer ( 4, d, e, d ); + if ( ammunition_overflow_bit ) + result = 1; + ammunition_integer_to_string( 4, d, s ); + ammunition_sprintf_d( str, ( INT_MAX / 3 ) * 3 ); + if ( ammunition_strcmp ( s, str ) != 0 ) + result = 1; + ammunition_sprintf_d( str, INT_MIN / 2 ); + ammunition_integer_from_string ( 4, str, d ); + ammunition_sprintf_d( str, 2 ); + ammunition_integer_from_string ( 4, str, e ); + ammunition_multiply_integer ( 4, d, e, d ); + if ( ammunition_overflow_bit ) + result = 1; + ammunition_integer_to_string( 4, d, s ); + ammunition_sprintf_d( str, ( INT_MIN / 2 ) * 2 ); + if ( ammunition_strcmp ( s, str ) != 0 ) + result = 1; + _Pragma( "loopbound min 4000 max 4000" ) + for ( i = -2000; i < 2000 ; i++ ) { + ammunition_sprintf_d( str, i ); + ammunition_integer_from_string ( 4, str, d ); + ammunition_sprintf_d( str, i + 1000 ); + ammunition_integer_from_string ( 4, str, e ); + ammunition_multiply_integer ( 4, d, e, d ); + if ( ammunition_overflow_bit ) + result = 1; + ammunition_integer_to_string( 4, d, s ); + if ( ammunition_atoi ( s ) != i * ( i + 1000 ) ) + result = 1; + } + + /* Test 8 */ + ammunition_reset_str_arithm( str, s, d, e, g ); + + ammunition_sprintf_u( str, UINT_MAX / 5 + 1 ); + ammunition_unsigned_integer_from_string ( 4, str, d ); + ammunition_sprintf_u( str, 5 ); + ammunition_unsigned_integer_from_string ( 4, str, e ); + ammunition_multiply_unsigned_integer ( 4, d, e, d ); + if ( !ammunition_overflow_bit ) + result = 1; + ammunition_sprintf_u( str, UINT_MAX / 2 ); + ammunition_unsigned_integer_from_string ( 4, str, d ); + ammunition_sprintf_u( str, 2 ); + ammunition_unsigned_integer_from_string ( 4, str, e ); + ammunition_multiply_unsigned_integer ( 4, d, e, d ); + if ( ammunition_overflow_bit ) + result = 1; + ammunition_unsigned_integer_to_string ( 4, d, s ); + ammunition_sprintf_u( str, ( UINT_MAX / 2 ) * 2 ); + if ( ammunition_strcmp ( s, str ) != 0 ) + result = 1; + _Pragma( "loopbound min 4000 max 4000" ) + for ( i = 0; i < 4000 ; i++ ) { + ammunition_sprintf_u( str, i ); + ammunition_unsigned_integer_from_string ( 4, str, d ); + ammunition_sprintf_u( str, i / 2 ); + ammunition_unsigned_integer_from_string ( 4, str, e ); + ammunition_multiply_unsigned_integer ( 4, d, e, d ); + if ( ammunition_overflow_bit ) + result = 1; + ammunition_unsigned_integer_to_string ( 4, d, s ); + if ( ammunition_atoi ( s ) != i * ( i / 2 ) ) + result = 1; + } + + /* Test 9 */ + ammunition_reset_str_arithm( str, s, d, e, g ); + + ammunition_integer_from_string ( 4, "10", d ); + ammunition_integer_from_string ( 4, "0", e ); + ammunition_divide_integer ( 4, d, e, d ); + if ( !ammunition_overflow_bit ) + result = 1; + _Pragma( "loopbound min 4000 max 4000" ) + for ( i = -2000; i < 2000 ; i++ ) { + ammunition_sprintf_d( str, i ); + ammunition_integer_from_string ( 4, str, d ); + ammunition_sprintf_d( str, ( i < 0 ? - i / 20 + 1 : - i / 20 - 1 ) ); + ammunition_integer_from_string ( 4, str, e ); + ammunition_divide_integer ( 4, d, e, d ); + if ( ammunition_overflow_bit ) + result = 1; + ammunition_integer_to_string( 4, d, s ); + if ( ammunition_atoi ( s ) != i / ( i < 0 ? - i / 20 + 1 : - i / 20 - 1 ) ) + result = 1; + ammunition_sprintf_d( str, i ); + ammunition_integer_from_string ( 4, str, d ); + ammunition_divide_integer ( 4, d, e, e ); + if ( ammunition_overflow_bit ) + result = 1; + ammunition_integer_to_string( 4, e, s ); + if ( ammunition_atoi ( s ) != i / ( i < 0 ? - i / 20 + 1 : - i / 20 - 1 ) ) + result = 1; + } + + /* Test 10 */ + ammunition_reset_str_arithm( str, s, d, e, g ); + + ammunition_unsigned_integer_from_string ( 4, "10", d ); + ammunition_unsigned_integer_from_string ( 4, "0", e ); + ammunition_divide_unsigned_integer ( 4, d, e, d ); + if ( !ammunition_overflow_bit ) + result = 1; + _Pragma( "loopbound min 4000 max 4000" ) + for ( i = 0; i < 4000 ; i++ ) { + ammunition_sprintf_u( str, i ); + ammunition_unsigned_integer_from_string ( 4, str, d ); + ammunition_sprintf_u( str, i / 20 + 1 ); + ammunition_unsigned_integer_from_string ( 4, str, e ); + ammunition_divide_unsigned_integer ( 4, d, e, d ); + if ( ammunition_overflow_bit ) + result = 1; + ammunition_unsigned_integer_to_string ( 4, d, s ); + if ( ammunition_atoi ( s ) != i / ( i / 20 + 1 ) ) + result = 1; + } + + /* Test 11 */ + ammunition_reset_str_arithm( str, s, d, e, g ); + + ammunition_unsigned_integer_from_string ( 4, "10", d ); + ammunition_unsigned_integer_from_string ( 4, "0", e ); + ammunition_unsigned_integer_remainder ( 4, d, e, d ); + if ( !ammunition_overflow_bit ) + result = 1; + _Pragma( "loopbound min 4000 max 4000" ) + for ( i = 0; i < 4000 ; i++ ) { + ammunition_sprintf_u( str, i ); + ammunition_unsigned_integer_from_string ( 4, str, d ); + ammunition_sprintf_u( str, i / 20 + 1 ); + ammunition_unsigned_integer_from_string ( 4, str, e ); + ammunition_unsigned_integer_remainder ( 4, d, e, d ); + if ( ammunition_overflow_bit ) + result = 1; + ammunition_unsigned_integer_to_string ( 4, d, s ); + if ( ammunition_atoi ( s ) != i % ( i / 20 + 1 ) ) + result = 1; + } + + /* Test 12 */ + ammunition_reset_str_arithm( str, s, d, e, g ); + + ammunition_unsigned_integer_from_string ( 4, "1348", d ); + ammunition_unsigned_integer_shift_right ( 4, d, 0, d ); + ammunition_unsigned_integer_to_string ( 4, d, s ); + if ( ammunition_overflow_bit || ammunition_strcmp ( s, "1348" ) != 0 ) + result = 1; + ammunition_unsigned_integer_from_string ( 4, "1348", d ); + ammunition_unsigned_integer_shift_right ( 4, d, 32, d ); + ammunition_unsigned_integer_to_string ( 4, d, s ); + if ( !ammunition_overflow_bit || ammunition_strcmp ( s, "0" ) != 0 ) + result = 1; + ammunition_unsigned_integer_from_string ( 4, "1348", d ); + ammunition_unsigned_integer_shift_right ( 4, d, 8, d ); + ammunition_unsigned_integer_to_string ( 4, d, s ); + if ( !ammunition_overflow_bit || ammunition_strcmp ( s, "5" ) != 0 ) + result = 1; + ammunition_unsigned_integer_from_string ( 4, "134890", d ); + ammunition_unsigned_integer_shift_right ( 4, d, 13, d ); + ammunition_unsigned_integer_to_string ( 4, d, s ); + if ( !ammunition_overflow_bit || ammunition_strcmp ( s, "16" ) != 0 ) + result = 1; + ammunition_unsigned_integer_from_string ( 4, "134890", d ); + ammunition_unsigned_integer_shift_left ( 4, d, -13, d ); + ammunition_unsigned_integer_to_string ( 4, d, s ); + if ( !ammunition_overflow_bit || ammunition_strcmp ( s, "16" ) != 0 ) + result = 1; + + /* Test 13 */ + ammunition_reset_str_arithm( str, s, d, e, g ); + + ammunition_integer_from_string ( 4, "1348", d ); + ammunition_integer_shift_right ( 4, d, 0, d ); + ammunition_integer_to_string( 4, d, s ); + if ( ammunition_overflow_bit || ammunition_strcmp ( s, "1348" ) != 0 ) + result = 1; + ammunition_integer_from_string ( 4, "1348", d ); + ammunition_integer_shift_right ( 4, d, 32, d ); + ammunition_integer_to_string( 4, d, s ); + if ( !ammunition_overflow_bit || ammunition_strcmp ( s, "0" ) != 0 ) + result = 1; + ammunition_integer_from_string ( 4, "1348", d ); + ammunition_integer_shift_right ( 4, d, 8, d ); + ammunition_integer_to_string( 4, d, s ); + if ( !ammunition_overflow_bit || ammunition_strcmp ( s, "5" ) != 0 ) + result = 1; + ammunition_integer_from_string ( 4, "134890", d ); + ammunition_integer_shift_right ( 4, d, 13, d ); + ammunition_integer_to_string( 4, d, s ); + if ( !ammunition_overflow_bit || ammunition_strcmp ( s, "16" ) != 0 ) + result = 1; + ammunition_integer_from_string ( 4, "134890", d ); + ammunition_integer_shift_left ( 4, d, -13, d ); + ammunition_integer_to_string( 4, d, s ); + if ( !ammunition_overflow_bit || ammunition_strcmp ( s, "16" ) != 0 ) + result = 1; + ammunition_integer_from_string ( 4, "-1348", d ); + ammunition_integer_shift_right ( 4, d, 0, d ); + ammunition_integer_to_string( 4, d, s ); + if ( ammunition_overflow_bit || ammunition_strcmp ( s, "-1348" ) != 0 ) + result = 1; + ammunition_integer_from_string ( 4, "-1348", d ); + ammunition_integer_shift_right ( 4, d, 32, d ); + ammunition_integer_to_string( 4, d, s ); + if ( !ammunition_overflow_bit || ammunition_strcmp ( s, "-1" ) != 0 ) + result = 1; + ammunition_integer_from_string ( 4, "-1348", d ); + ammunition_integer_shift_right ( 4, d, 8, d ); + ammunition_integer_to_string( 4, d, s ); + if ( !ammunition_overflow_bit || ammunition_strcmp ( s, "-6" ) != 0 ) + result = 1; + ammunition_integer_from_string ( 4, "-134890", d ); + ammunition_integer_shift_right ( 4, d, 13, d ); + ammunition_integer_to_string( 4, d, s ); + if ( !ammunition_overflow_bit || ammunition_strcmp ( s, "-17" ) != 0 ) + result = 1; + ammunition_integer_from_string ( 4, "-134890", d ); + ammunition_integer_shift_left ( 4, d, -13, d ); + ammunition_integer_to_string( 4, d, s ); + if ( !ammunition_overflow_bit || ammunition_strcmp ( s, "-17" ) != 0 ) + result = 1; + + /* Test 14 */ + ammunition_reset_str_arithm( str, s, d, e, g ); + + ammunition_unsigned_integer_from_string ( 4, "1348", d ); + ammunition_unsigned_integer_shift_left ( 4, d, 0, d ); + ammunition_unsigned_integer_to_string ( 4, d, s ); + if ( ammunition_overflow_bit || ammunition_strcmp ( s, "1348" ) != 0 ) + result = 1; + ammunition_unsigned_integer_from_string ( 4, "1348", d ); + ammunition_unsigned_integer_shift_left ( 4, d, 22, d ); + if ( !ammunition_overflow_bit ) + result = 1; + ammunition_unsigned_integer_from_string ( 4, "1348", d ); + ammunition_unsigned_integer_shift_left ( 4, d, 8, d ); + ammunition_unsigned_integer_to_string ( 4, d, s ); + if ( ammunition_overflow_bit || ammunition_strcmp ( s, "345088" ) != 0 ) + result = 1; + ammunition_unsigned_integer_from_string ( 4, "134890", d ); + ammunition_unsigned_integer_shift_left ( 4, d, 13, d ); + ammunition_unsigned_integer_to_string ( 4, d, s ); + if ( ammunition_overflow_bit || ammunition_strcmp ( s, "1105018880" ) != 0 ) + result = 1; + ammunition_unsigned_integer_from_string ( 4, "134890", d ); + ammunition_unsigned_integer_shift_right ( 4, d, -13, d ); + ammunition_unsigned_integer_to_string ( 4, d, s ); + if ( ammunition_overflow_bit || ammunition_strcmp ( s, "1105018880" ) != 0 ) + result = 1; + + /* Test 15 */ + ammunition_reset_str_arithm( str, s, d, e, g ); + + ammunition_integer_from_string ( 4, "1348", d ); + ammunition_integer_shift_left ( 4, d, 0, d ); + ammunition_integer_to_string( 4, d, s ); + if ( ammunition_overflow_bit || ammunition_strcmp ( s, "1348" ) != 0 ) + result = 1; + ammunition_integer_from_string ( 4, "1348", d ); + ammunition_integer_shift_left ( 4, d, 21, d ); + if ( !ammunition_overflow_bit ) + result = 1; + ammunition_integer_from_string ( 4, "1348", d ); + ammunition_integer_shift_left ( 4, d, 8, d ); + ammunition_integer_to_string( 4, d, s ); + if ( ammunition_overflow_bit || ammunition_strcmp ( s, "345088" ) != 0 ) + result = 1; + ammunition_integer_from_string ( 4, "134890", d ); + ammunition_integer_shift_left ( 4, d, 13, d ); + ammunition_integer_to_string( 4, d, s ); + if ( ammunition_overflow_bit || ammunition_strcmp ( s, "1105018880" ) != 0 ) + result = 1; + ammunition_integer_from_string ( 4, "134890", d ); + ammunition_integer_shift_right ( 4, d, -13, d ); + ammunition_integer_to_string( 4, d, s ); + if ( ammunition_overflow_bit || ammunition_strcmp ( s, "1105018880" ) != 0 ) + result = 1; + ammunition_integer_from_string ( 4, "-1348", d ); + ammunition_integer_shift_left ( 4, d, 0, d ); + ammunition_integer_to_string( 4, d, s ); + if ( ammunition_overflow_bit || ammunition_strcmp ( s, "-1348" ) != 0 ) + result = 1; + ammunition_integer_from_string ( 4, "-1348", d ); + ammunition_integer_shift_left ( 4, d, 21, d ); + if ( !ammunition_overflow_bit ) + result = 1; + ammunition_integer_from_string ( 4, "-1348", d ); + ammunition_integer_shift_left ( 4, d, 8, d ); + ammunition_integer_to_string( 4, d, s ); + if ( ammunition_overflow_bit || ammunition_strcmp ( s, "-345088" ) != 0 ) + result = 1; + ammunition_integer_from_string ( 4, "-134890", d ); + ammunition_integer_shift_left ( 4, d, 13, d ); + ammunition_integer_to_string( 4, d, s ); + if ( ammunition_overflow_bit || ammunition_strcmp ( s, "-1105018880" ) != 0 ) + result = 1; + ammunition_integer_from_string ( 4, "-134890", d ); + ammunition_integer_shift_right ( 4, d, -13, d ); + ammunition_integer_to_string( 4, d, s ); + if ( ammunition_overflow_bit || ammunition_strcmp ( s, "-1105018880" ) != 0 ) + result = 1; + + /* Test 16 */ + ammunition_reset_str_arithm( str, s, d, e, g ); + + ammunition_integer_from_string ( 4, "-10", d ); + ammunition_integer_from_string ( 4, "1348", e ); + if ( ammunition_eq_integer ( 4, d, e ) ) + result = 1; + ammunition_integer_from_string ( 4, "-1348", d ); + ammunition_integer_from_string ( 4, "-1348", e ); + if ( !ammunition_eq_integer ( 4, d, e ) ) + result = 1; + + /* Test 17 */ + ammunition_reset_str_arithm( str, s, d, e, g ); + + ammunition_unsigned_integer_from_string ( 4, "10", d ); + ammunition_unsigned_integer_from_string ( 4, "1348", e ); + if ( ammunition_eq_unsigned_integer ( 4, d, e ) ) + result = 1; + ammunition_unsigned_integer_from_string ( 4, "1348", d ); + ammunition_unsigned_integer_from_string ( 4, "1348", e ); + if ( !ammunition_eq_unsigned_integer ( 4, d, e ) ) + result = 1; + + /* Test 18 */ + ammunition_reset_str_arithm( str, s, d, e, g ); + + ammunition_integer_from_string ( 4, "-10", d ); + ammunition_integer_from_string ( 4, "1348", e ); + if ( !ammunition_ne_integer ( 4, d, e ) ) + result = 1; + ammunition_integer_from_string ( 4, "-1348", d ); + ammunition_integer_from_string ( 4, "-1348", e ); + if ( ammunition_ne_integer ( 4, d, e ) ) + result = 1; + + /* Test 19 */ + ammunition_reset_str_arithm( str, s, d, e, g ); + + ammunition_unsigned_integer_from_string ( 4, "10", d ); + ammunition_unsigned_integer_from_string ( 4, "1348", e ); + if ( !ammunition_ne_unsigned_integer ( 4, d, e ) ) + result = 1; + ammunition_unsigned_integer_from_string ( 4, "1348", d ); + ammunition_unsigned_integer_from_string ( 4, "1348", e ); + if ( ammunition_ne_unsigned_integer ( 4, d, e ) ) + result = 1; + + /* Test 20 */ + ammunition_reset_str_arithm( str, s, d, e, g ); + + ammunition_integer_from_string ( 4, "-10", d ); + ammunition_integer_from_string ( 4, "1348", e ); + if ( ammunition_gt_integer ( 4, d, e ) ) + result = 1; + ammunition_integer_from_string ( 4, "-1348", d ); + ammunition_integer_from_string ( 4, "-1348", e ); + if ( ammunition_gt_integer ( 4, d, e ) ) + result = 1; + ammunition_integer_from_string ( 4, "-1000000", d ); + ammunition_integer_from_string ( 4, "-1348", e ); + if ( ammunition_gt_integer ( 4, d, e ) ) + result = 1; + ammunition_integer_from_string ( 4, "1000000", d ); + ammunition_integer_from_string ( 4, "1348", e ); + if ( !ammunition_gt_integer ( 4, d, e ) ) + result = 1; + + /* Test 21 */ + ammunition_reset_str_arithm( str, s, d, e, g ); + + ammunition_unsigned_integer_from_string ( 4, "10", d ); + ammunition_unsigned_integer_from_string ( 4, "1348", e ); + if ( ammunition_gt_unsigned_integer ( 4, d, e ) ) + result = 1; + ammunition_unsigned_integer_from_string ( 4, "1348", d ); + ammunition_unsigned_integer_from_string ( 4, "1348", e ); + if ( ammunition_gt_unsigned_integer ( 4, d, e ) ) + result = 1; + ammunition_unsigned_integer_from_string ( 4, "1000000", d ); + ammunition_unsigned_integer_from_string ( 4, "1348", e ); + if ( !ammunition_gt_unsigned_integer ( 4, d, e ) ) + result = 1; + + /* Test 22 */ + ammunition_reset_str_arithm( str, s, d, e, g ); + + ammunition_integer_from_string ( 4, "-10", d ); + ammunition_integer_from_string ( 4, "1348", e ); + if ( !ammunition_lt_integer ( 4, d, e ) ) + result = 1; + ammunition_integer_from_string ( 4, "-1348", d ); + ammunition_integer_from_string ( 4, "-1348", e ); + if ( ammunition_lt_integer ( 4, d, e ) ) + result = 1; + ammunition_integer_from_string ( 4, "-1000000", d ); + ammunition_integer_from_string ( 4, "-1348", e ); + if ( !ammunition_lt_integer ( 4, d, e ) ) + result = 1; + ammunition_integer_from_string ( 4, "1000000", d ); + ammunition_integer_from_string ( 4, "1348", e ); + if ( ammunition_lt_integer ( 4, d, e ) ) + result = 1; + + /* Test 23 */ + ammunition_reset_str_arithm( str, s, d, e, g ); + + ammunition_unsigned_integer_from_string ( 4, "10", d ); + ammunition_unsigned_integer_from_string ( 4, "1348", e ); + if ( !ammunition_lt_unsigned_integer ( 4, d, e ) ) + result = 1; + ammunition_unsigned_integer_from_string ( 4, "1348", d ); + ammunition_unsigned_integer_from_string ( 4, "1348", e ); + if ( ammunition_lt_unsigned_integer ( 4, d, e ) ) + result = 1; + ammunition_unsigned_integer_from_string ( 4, "1000000", d ); + ammunition_unsigned_integer_from_string ( 4, "1348", e ); + if ( ammunition_lt_unsigned_integer ( 4, d, e ) ) + result = 1; + + /* Test 24 */ + ammunition_reset_str_arithm( str, s, d, e, g ); + + ammunition_integer_from_string ( 4, "-10", d ); + ammunition_integer_from_string ( 4, "1348", e ); + if ( ammunition_ge_integer ( 4, d, e ) ) + result = 1; + ammunition_integer_from_string ( 4, "-1348", d ); + ammunition_integer_from_string ( 4, "-1348", e ); + if ( !ammunition_ge_integer ( 4, d, e ) ) + result = 1; + ammunition_integer_from_string ( 4, "-1000000", d ); + ammunition_integer_from_string ( 4, "-1348", e ); + if ( ammunition_ge_integer ( 4, d, e ) ) + result = 1; + ammunition_integer_from_string ( 4, "1000000", d ); + ammunition_integer_from_string ( 4, "1348", e ); + if ( !ammunition_ge_integer ( 4, d, e ) ) + result = 1; + + /* Test 25 */ + ammunition_reset_str_arithm( str, s, d, e, g ); + + ammunition_unsigned_integer_from_string ( 4, "10", d ); + ammunition_unsigned_integer_from_string ( 4, "1348", e ); + if ( ammunition_ge_unsigned_integer ( 4, d, e ) ) + result = 1; + ammunition_unsigned_integer_from_string ( 4, "1348", d ); + ammunition_unsigned_integer_from_string ( 4, "1348", e ); + if ( !ammunition_ge_unsigned_integer ( 4, d, e ) ) + result = 1; + ammunition_unsigned_integer_from_string ( 4, "1000000", d ); + ammunition_unsigned_integer_from_string ( 4, "1348", e ); + if ( !ammunition_ge_unsigned_integer ( 4, d, e ) ) + result = 1; + + /* Test 26 */ + ammunition_reset_str_arithm( str, s, d, e, g ); + + ammunition_integer_from_string ( 4, "-10", d ); + ammunition_integer_from_string ( 4, "1348", e ); + if ( !ammunition_le_integer ( 4, d, e ) ) + result = 1; + ammunition_integer_from_string ( 4, "-1348", d ); + ammunition_integer_from_string ( 4, "-1348", e ); + if ( !ammunition_le_integer ( 4, d, e ) ) + result = 1; + ammunition_integer_from_string ( 4, "-1000000", d ); + ammunition_integer_from_string ( 4, "-1348", e ); + if ( !ammunition_le_integer ( 4, d, e ) ) + result = 1; + ammunition_integer_from_string ( 4, "1000000", d ); + ammunition_integer_from_string ( 4, "1348", e ); + if ( ammunition_le_integer ( 4, d, e ) ) + result = 1; + + /* Test 27 */ + ammunition_reset_str_arithm( str, s, d, e, g ); + + ammunition_unsigned_integer_from_string ( 4, "10", d ); + ammunition_unsigned_integer_from_string ( 4, "1348", e ); + if ( !ammunition_le_unsigned_integer ( 4, d, e ) ) + result = 1; + ammunition_unsigned_integer_from_string ( 4, "1348", d ); + ammunition_unsigned_integer_from_string ( 4, "1348", e ); + if ( !ammunition_le_unsigned_integer ( 4, d, e ) ) + result = 1; + ammunition_unsigned_integer_from_string ( 4, "1000000", d ); + ammunition_unsigned_integer_from_string ( 4, "1348", e ); + if ( ammunition_le_unsigned_integer ( 4, d, e ) ) + result = 1; + + /* Test 28 */ + ammunition_reset_str_arithm( str, s, d, e, g ); + + ammunition_unsigned_integer_from_string ( 4, "70000", d ); + ammunition_change_unsigned_integer_size ( 4, d, 2, d ); + if ( !ammunition_overflow_bit ) + result = 1; + ammunition_unsigned_integer_from_string ( 4, "30000", d ); + ammunition_change_unsigned_integer_size ( 4, d, 2, d ); + ammunition_integer_to_string( 2, d, s ); + if ( ammunition_overflow_bit || ammunition_strcmp ( s, "30000" ) != 0 ) + result = 1; + ammunition_unsigned_integer_from_string ( 4, "11230000", g ); + ammunition_change_unsigned_integer_size ( 4, g, 6, g ); + ammunition_integer_to_string( 6, g, s ); + if ( ammunition_overflow_bit || ammunition_strcmp ( s, "11230000" ) != 0 ) + result = 1; + + /* Test 29 */ + ammunition_reset_str_arithm( str, s, d, e, g ); + + ammunition_integer_from_string ( 4, "40000", d ); + ammunition_change_integer_size ( 4, d, 2, d ); + if ( !ammunition_overflow_bit ) + result = 1; + ammunition_integer_from_string ( 4, "-33000", d ); + ammunition_change_integer_size ( 4, d, 2, d ); + if ( !ammunition_overflow_bit ) + result = 1; + ammunition_integer_from_string ( 4, "30000", d ); + ammunition_change_integer_size ( 4, d, 2, d ); + ammunition_integer_to_string( 2, d, s ); + if ( ammunition_overflow_bit || ammunition_strcmp ( s, "30000" ) != 0 ) + result = 1; + ammunition_integer_from_string ( 4, "-30000", d ); + ammunition_change_integer_size ( 4, d, 2, d ); + ammunition_integer_to_string( 2, d, s ); + if ( ammunition_overflow_bit || ammunition_strcmp ( s, "-30000" ) != 0 ) + result = 1; + ammunition_integer_from_string ( 4, "11230000", g ); + ammunition_change_integer_size ( 4, g, 6, g ); + ammunition_integer_to_string( 6, g, s ); + if ( ammunition_overflow_bit || ammunition_strcmp ( s, "11230000" ) != 0 ) + result = 1; + ammunition_integer_from_string ( 4, "-11230000", g ); + ammunition_change_integer_size ( 4, g, 6, g ); + ammunition_integer_to_string( 6, g, s ); + if ( ammunition_overflow_bit || ammunition_strcmp ( s, "-11230000" ) != 0 ) + result = 1; + + /* Test 30 */ + ammunition_reset_str_arithm( str, s, d, e, g ); + + ammunition_unsigned_integer_from_string ( 4, "1348", d ); + ammunition_unsigned_integer_from_string ( 4, "1348", e ); + ammunition_unsigned_integer_or ( 4, d, e, e ); + ammunition_unsigned_integer_to_string ( 4, e, s ); + if ( ammunition_strcmp ( s, "1348" ) != 0 ) + result = 1; + ammunition_unsigned_integer_from_string ( 4, "1348", d ); + ammunition_unsigned_integer_from_string ( 4, "0", e ); + ammunition_unsigned_integer_or ( 4, d, e, e ); + ammunition_unsigned_integer_to_string ( 4, e, s ); + if ( ammunition_strcmp ( s, "1348" ) != 0 ) + result = 1; + ammunition_unsigned_integer_from_string ( 4, "1348", d ); + ammunition_unsigned_integer_from_string ( 4, "4294967295", e ); + ammunition_unsigned_integer_or ( 4, d, e, e ); + ammunition_unsigned_integer_to_string ( 4, e, s ); + if ( ammunition_strcmp ( s, "4294967295" ) != 0 ) + result = 1; + ammunition_unsigned_integer_from_string ( 4, "1348", d ); + ammunition_unsigned_integer_from_string ( 4, "96", e ); + ammunition_unsigned_integer_or ( 4, d, e, e ); + ammunition_unsigned_integer_to_string ( 4, e, s ); + if ( ammunition_strcmp ( s, "1380" ) != 0 ) + result = 1; + + /* Test 31 */ + ammunition_reset_str_arithm( str, s, d, e, g ); + + ammunition_integer_from_string ( 4, "1348", d ); + ammunition_integer_from_string ( 4, "1348", e ); + ammunition_integer_or ( 4, d, e, e ); + ammunition_integer_to_string( 4, e, s ); + if ( ammunition_strcmp ( s, "1348" ) != 0 ) + result = 1; + ammunition_integer_from_string ( 4, "1348", d ); + ammunition_integer_from_string ( 4, "0", e ); + ammunition_integer_or ( 4, d, e, e ); + ammunition_integer_to_string( 4, e, s ); + if ( ammunition_strcmp ( s, "1348" ) != 0 ) + result = 1; + ammunition_integer_from_string ( 4, "1348", d ); + ammunition_integer_from_string ( 4, "-1", e ); + ammunition_integer_or ( 4, d, e, e ); + ammunition_integer_to_string( 4, e, s ); + if ( ammunition_strcmp ( s, "-1" ) != 0 ) + result = 1; + ammunition_integer_from_string ( 4, "1348", d ); + ammunition_integer_from_string ( 4, "96", e ); + ammunition_integer_or ( 4, d, e, e ); + ammunition_integer_to_string( 4, e, s ); + if ( ammunition_strcmp ( s, "1380" ) != 0 ) + result = 1; + + /* Test 32 */ + ammunition_reset_str_arithm( str, s, d, e, g ); + + ammunition_unsigned_integer_from_string ( 4, "1348", d ); + ammunition_unsigned_integer_from_string ( 4, "1348", e ); + ammunition_unsigned_integer_and ( 4, d, e, e ); + ammunition_unsigned_integer_to_string ( 4, e, s ); + if ( ammunition_strcmp ( s, "1348" ) != 0 ) + result = 1; + ammunition_unsigned_integer_from_string ( 4, "1348", d ); + ammunition_unsigned_integer_from_string ( 4, "0", e ); + ammunition_unsigned_integer_and ( 4, d, e, e ); + ammunition_unsigned_integer_to_string ( 4, e, s ); + if ( ammunition_strcmp ( s, "0" ) != 0 ) + result = 1; + ammunition_unsigned_integer_from_string ( 4, "1348", d ); + ammunition_unsigned_integer_from_string ( 4, "4294967295", e ); + ammunition_unsigned_integer_and ( 4, d, e, e ); + ammunition_unsigned_integer_to_string ( 4, e, s ); + if ( ammunition_strcmp ( s, "1348" ) != 0 ) + result = 1; + ammunition_unsigned_integer_from_string ( 4, "1348", d ); + ammunition_unsigned_integer_from_string ( 4, "96", e ); + ammunition_unsigned_integer_and ( 4, d, e, e ); + ammunition_unsigned_integer_to_string ( 4, e, s ); + if ( ammunition_strcmp ( s, "64" ) != 0 ) + result = 1; + + /* Test 33 */ + ammunition_reset_str_arithm( str, s, d, e, g ); + + ammunition_integer_from_string ( 4, "1348", d ); + ammunition_integer_from_string ( 4, "1348", e ); + ammunition_integer_and ( 4, d, e, e ); + ammunition_integer_to_string( 4, e, s ); + if ( ammunition_strcmp ( s, "1348" ) != 0 ) + result = 1; + ammunition_integer_from_string ( 4, "1348", d ); + ammunition_integer_from_string ( 4, "0", e ); + ammunition_integer_and ( 4, d, e, e ); + ammunition_integer_to_string( 4, e, s ); + if ( ammunition_strcmp ( s, "0" ) != 0 ) + result = 1; + ammunition_integer_from_string ( 4, "1348", d ); + ammunition_integer_from_string ( 4, "-1", e ); + ammunition_integer_and ( 4, d, e, e ); + ammunition_integer_to_string( 4, e, s ); + if ( ammunition_strcmp ( s, "1348" ) != 0 ) + result = 1; + ammunition_integer_from_string ( 4, "1348", d ); + ammunition_integer_from_string ( 4, "96", e ); + ammunition_integer_and ( 4, d, e, e ); + ammunition_integer_to_string( 4, e, s ); + if ( ammunition_strcmp ( s, "64" ) != 0 ) + result = 1; + + /* Test 34 */ + ammunition_reset_str_arithm( str, s, d, e, g ); + + ammunition_unsigned_integer_from_string ( 4, "1348", d ); + ammunition_unsigned_integer_not ( 4, d, d ); + ammunition_unsigned_integer_to_string ( 4, d, s ); + if ( ammunition_strcmp ( s, "4294965947" ) != 0 ) + result = 1; + ammunition_unsigned_integer_from_string ( 4, "0", d ); + ammunition_unsigned_integer_not ( 4, d, d ); + ammunition_unsigned_integer_to_string ( 4, d, s ); + if ( ammunition_strcmp ( s, "4294967295" ) != 0 ) + result = 1; + ammunition_unsigned_integer_from_string ( 4, "4294967295", d ); + ammunition_unsigned_integer_not ( 4, d, d ); + ammunition_unsigned_integer_to_string ( 4, d, s ); + if ( ammunition_strcmp ( s, "0" ) != 0 ) + result = 1; + + /* Test 35 */ + ammunition_reset_str_arithm( str, s, d, e, g ); + + ammunition_integer_from_string ( 4, "1348", d ); + ammunition_integer_not ( 4, d, d ); + ammunition_integer_to_string( 4, d, s ); + if ( ammunition_strcmp ( s, "-1349" ) != 0 ) + result = 1; + ammunition_integer_from_string ( 4, "0", d ); + ammunition_integer_not ( 4, d, d ); + ammunition_integer_to_string( 4, d, s ); + if ( ammunition_strcmp ( s, "-1" ) != 0 ) + result = 1; + ammunition_integer_from_string ( 4, "-1", d ); + ammunition_integer_not ( 4, d, d ); + ammunition_integer_to_string( 4, d, s ); + if ( ammunition_strcmp ( s, "0" ) != 0 ) + result = 1; + + return result; +} + + +/* + Initialization- and return-value-related functions +*/ + +void ammunition_init( void ) +{ + ammunition_result = 0; +} + +int ammunition_return( void ) +{ + return ammunition_result; +} + +/* + Main functions +*/ + +void _Pragma( "entrypoint" ) ammunition_main( void ) +{ + ammunition_result |= ammunition_bits_test(); + ammunition_result |= ammunition_arithm_test(); +} + + +int main( int argc, char **argv ) +{ + SET_UP + for (jobsComplete=-1; jobsComplete= '0' ) & ( c <= '9' ) ) + return 1; + else + return 0; +} + +int ammunition_isspace( int c ) +{ + return ( c == ' ' ) | ( c == '\t' ) | ( c == '\n' ) | ( c == '\r' ); +} + +void *ammunition_memcpy( void *dest, const void *src, size_x size ) +{ + size_x i; + _Pragma( "loopbound min 2 max 6" ) + for ( i = 0; i < size; i++ ) + ( ( unsigned char * )dest )[i] = ( ( unsigned char * )src )[i]; + + return dest; +} + + +void *ammunition_memset( void *s, int c, size_x n ) +{ + size_x i; + _Pragma( "loopbound min 0 max 4" ) + for ( i = 0; i < n; i++ ) + ( ( unsigned char * )s )[i] = ( unsigned char )c; + + return s; +} + + +int ammunition_memcmp ( const void *mem1, const void *mem2, size_x size ) +{ + const unsigned char *p1 = (const unsigned char *) mem1, + *p2 = (const unsigned char *) mem2; + _Pragma( "loopbound min 0 max 4" ) + while ( size-- ) + if ( *p1 != *p2 ) + return ( *p1 - *p2 ); + else + p1++, p2++; + return 0; +} + + +/* The following function is an analog of standard C function + `memmove'. The function returns the first operand. */ + +void *ammunition_memmove ( void *s1, const void *s2, size_x n ) +{ + int i; + + if ( ( ( char * ) s1 < ( char * ) s2 && ( char * ) s1 + n <= ( char * ) s2 ) + || ( ( char * ) s2 < ( char * ) s1 + && ( char * ) s2 + n <= ( char * ) s1 ) ) + return ( void * ) ammunition_memcpy ( s1, s2, n ); + if ( ( char * ) s1 < ( char * ) s2 && ( char * ) s1 + n > ( char * ) s2 ) { + _Pragma( "loopbound min 0 max 4" ) + for ( i = 0; ( size_x ) i < n; i++ ) + ( ( char * ) s1 ) [i] = ( ( char * ) s2 ) [i]; + } else { + _Pragma( "loopbound min 0 max 4" ) + for ( i = n - 1; i >= 0; i-- ) + ( ( char * ) s1 )[i] = ( ( char * ) s2 ) [i]; + } + return s1; +} + +int ammunition_strcmp ( const char *str1, const char *str2 ) +{ + _Pragma( "loopbound min 1 max 4008" ) + while ( *str1 && ( *str1 == *str2 ) ) + str1++, str2++; + return *( const unsigned char * )str1 - *( const unsigned char * )str2; +} + +int ammunition_atoi ( const char *str ) +{ + int result = 0; + int sign = ( str[0] == '-' ? -1 : 1 ); + + int readingPos = 0; + if ( str[0] == '-' || str[0] == '+' ) + readingPos++; + _Pragma( "loopbound min 1 max 1" ) + do { + result *= 10; + result += str[readingPos++] - 48; + } while ( str[readingPos] != 0 ); + + return sign * result; +} + + +int ammunition_sprintf_d( char *s, int number ) +{ + /* How many decimal digits do we need? */ + char digits = 0; + unsigned char writePos = 0; + long long copyOfNumber = number; + _Pragma( "loopbound min 1 max 10" ) + do { + digits++; + copyOfNumber /= 10; + } while ( copyOfNumber != 0 ); + + writePos = digits; + if ( number < 0 ) { + writePos++; + s[0] = '-'; + } + s[writePos] = 0; + + copyOfNumber = number; + _Pragma( "loopbound min 1 max 10" ) + do { + s[--writePos] = 48 + ( ( copyOfNumber >= 0 ? + copyOfNumber : -copyOfNumber ) % 10 ); + copyOfNumber /= 10; + } while ( copyOfNumber != 0 ); + + return digits + ( number < 0 ? 1 : 0 ); +} + + +int ammunition_sprintf_u( char *s, unsigned int number ) +{ + /* How many decimal digits do we need? */ + char digits = 0; + unsigned char writePos = 0; + unsigned long copyOfNumber = number; + _Pragma( "loopbound min 1 max 10" ) + do { + digits++; + copyOfNumber /= 10; + } while ( copyOfNumber != 0 ); + + writePos = digits; + s[writePos] = 0; + + copyOfNumber = number; + _Pragma( "loopbound min 1 max 10" ) + do { + s[--writePos] = 48 + ( copyOfNumber % 10 ); + copyOfNumber /= 10; + } while ( copyOfNumber != 0 ); + + return digits; +} diff --git a/all_pairs/source/ammunition/ammunition_limits.h b/all_pairs/source/ammunitio