/*
This program is part of the TACLeBench benchmark suite.
Version V 2.0
Name: ammunition
Author: Vladimir Makarov <vmakarov@gcc.gnu.org>
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,
|