Skip to content

Commit

Permalink
Merge branch 'large-ctype-probes'
Browse files Browse the repository at this point in the history
  • Loading branch information
plobsing committed Feb 28, 2011
2 parents dbbf609 + d113423 commit 0321a4c
Show file tree
Hide file tree
Showing 12 changed files with 150 additions and 294 deletions.
4 changes: 0 additions & 4 deletions MANIFEST
Expand Up @@ -193,10 +193,6 @@ config/auto/signal/test1_c.in []
config/auto/signal/test2_c.in []
config/auto/signal/test_itimer_c.in []
config/auto/sizes.pm []
config/auto/sizes/floatval_maxmin_c.in []
config/auto/sizes/intval_maxmin_c.in []
config/auto/sizes/test2_c.in []
config/auto/sizes/test3_c.in []
config/auto/sizes/test_c.in []
config/auto/snprintf.pm []
config/auto/snprintf/test_c.in []
Expand Down
225 changes: 114 additions & 111 deletions config/auto/sizes.pm
Expand Up @@ -31,70 +31,75 @@ sub _init {
sub runstep {
my ( $self, $conf ) = @_;

$conf->cc_gen('config/auto/sizes/test_c.in');
$conf->cc_build();
my %results = eval $conf->cc_run();
$conf->cc_clean();

for ( keys %results ) {
$conf->data->set( $_ => $results{$_} );
}
my %types = (
intval => $conf->data->get('iv'),
numval => $conf->data->get('nv'),
opcode => $conf->data->get('opcode_t'),
short => 'short',
int => 'int',
long => 'long',
longlong => 'long long',
ptr => 'void *',
float => 'float',
double => 'double',
longdouble => 'long double',
);

_handle_intval_ptrsize_discrepancy(\%results);
my %sizes = map {
$_, test_size($conf, $types{$_})
} keys %types;

# set fixed sized types
_set_int2($conf, \%results);
for ( keys %sizes ) {
$conf->data->set( $_ . 'size' => $sizes{$_} );
}

_set_int4($conf, \%results);
_handle_intval_ptrsize_discrepancy(\%sizes);
_handle_longlong($conf, \%sizes);

_set_float4($conf, \%results);
# probe for 64-bit integer-types
foreach my $type ('int64_t', '__int64') {
my $size = test_size($conf, $type);
if ($size) {
$types{int64} = $type;
$sizes{int64} = $size;
last;
}
}

_set_float8($conf, \%results);
# set fixed sized types
_set_int2($conf, \%types, \%sizes);

my %hugeintval;
my $intval = $conf->data->get('iv');
my $intvalsize = $conf->data->get('intvalsize');
_set_int4($conf, \%types, \%sizes);

# Get HUGEINTVAL, note that we prefer standard types
foreach my $type ( 'long', 'int', 'long long', '__int64' ) {
_set_int8($conf, \%types, \%sizes);

$conf->data->set( int8_t => $type );
eval {
$conf->cc_gen('config/auto/sizes/test2_c.in');
$conf->cc_build();
%hugeintval = eval $conf->cc_run();
$conf->cc_clean();
};
_set_float4($conf, \%types, \%sizes);

# clear int8_t on error
if ( $@ || !exists $hugeintval{hugeintval} ) {
$conf->data->set( int8_t => undef );
next;
}
_set_float8($conf, \%types, \%sizes);

if ( $hugeintval{hugeintvalsize} > $intvalsize ) {
# get HUGEINTVAL
my $hiv = do {
my @t = ('long', 'int', 'longlong', 'int64', 'invtal');
my $i = maxind( @sizes{grep exists $sizes{$_}, @t} );
$t[$i];
};

# We found something bigger than intval.
$conf->data->set(%hugeintval);
last;
}
}
_handle_hugeintvalsize(
$conf,
{
hugeintval => \%hugeintval,
intval => $intval,
intvalsize => $intvalsize,
},
$conf->data->set(
hugeintval => $types{$hiv},
hugeintvalsize => $sizes{$hiv},
);

$conf->cc_clean();

#get HUGEFLOATVAL
my $size = _probe_for_hugefloatval( $conf );
_set_hugefloatval( $conf, $size );
# get HUGEFLOATVAL
my $hfv = do {
my @t = ('float', 'double', 'longdouble', 'numval');
my $i = maxind( @sizes{@t} );
$t[$i];
};

$conf->cc_clean();
$conf->data->set(
hugefloatval => $types{$hfv},
hugefloatvalsize => $sizes{$hfv},
);

_set_intvalmaxmin($conf);

Expand All @@ -105,9 +110,27 @@ sub runstep {

#################### INTERNAL SUBROUTINES ####################

sub test_size {
my ($conf, $type) = @_;

$conf->data->set( TEMP_type => $type );
$conf->cc_gen('config/auto/sizes/test_c.in');
$conf->cc_build();
my $ret = eval $conf->cc_run();
$conf->cc_clean();

return $ret;
}

sub maxind {
my $i = 0;
$_[$_] <= $_[$i] or $i = $_ for 0..$#_;
return $i;
}

sub _handle_intval_ptrsize_discrepancy {
my $resultsref = shift;
if ( $resultsref->{ptrsize} != $resultsref->{intvalsize} ) {
my $sizesref = shift;
if ( $sizesref->{ptr} != $sizesref->{intval} ) {
print <<"END";
Hmm, I see your chosen INTVAL isn't the same size as your pointers. Parrot
Expand All @@ -116,9 +139,14 @@ END
}
}

sub _handle_longlong {
my ($conf, $sizesref) = @_;
$conf->data->set( HAS_LONGLONG => !!($sizesref->{longlong} > 0) );
}

sub _set_int2 {
my ($conf, $resultsref) = @_;
if ( $resultsref->{shortsize} == 2 ) {
my ($conf, $typesref, $sizesref) = @_;
if ( $sizesref->{short} == 2 ) {
$conf->data->set( int2_t => 'short' );
}
else {
Expand All @@ -132,29 +160,45 @@ END
}

sub _set_int4 {
my ($conf, $resultsref) = @_;
if ( $resultsref->{shortsize} == 4 ) {
$conf->data->set( int4_t => 'short' );
}
elsif ( $resultsref->{intsize} == 4 ) {
$conf->data->set( int4_t => 'int' );
}
elsif ( $resultsref->{longsize} == 4 ) {
$conf->data->set( int4_t => 'long' );
my ($conf, $typesref, $sizesref) = @_;
foreach my $type (qw[ short int long ]) {
if ( $sizesref->{$type} == 4 ) {
$conf->data->set( int4_t => $typesref->{$type} );
return;
}
}
else {
$conf->data->set( int4_t => 'int' );
print <<'END';

$conf->data->set( int4_t => 'int' );
print <<'END';
Can't find a int type with size 4, conversion ops might fail!
END
}

sub _set_int8 {
my ($conf, $typesref, $sizesref) = @_;
foreach my $type (qw[ int long longlong int64 ]) {
if ( $sizesref->{$type} == 8 ) {
$conf->data->set(
int8_t => $typesref->{$type},
HAS_INT64 => 1,
);
return;
}
}

$conf->data->set( HAS_INT64 => 0 );
print <<'END';
Can't find an int type with size 8, 64-bit support dissabled.
END
}

sub _set_float4 {
my ($conf, $resultsref) = @_;
if ( $resultsref->{floatsize} == 4 ) {
my ($conf, $typesref, $sizesref) = @_;
if ( $sizesref->{float} == 4 ) {
$conf->data->set( float4_t => 'float' );
}
else {
Expand All @@ -168,8 +212,8 @@ END
}

sub _set_float8 {
my ($conf, $resultsref) = @_;
if ( $resultsref->{doublesize} == 8 ) {
my ($conf, $typesref, $sizesref) = @_;
if ( $sizesref->{double} == 8 ) {
$conf->data->set( float8_t => 'double' );
}
else {
Expand All @@ -182,47 +226,6 @@ END
}
}

sub _handle_hugeintvalsize {
my $conf = shift;
my $arg = shift;
if ( ! defined( $arg->{hugeintval}{hugeintvalsize} )
|| $arg->{hugeintval}{hugeintvalsize} == $arg->{intvalsize} )
{

# Could not find anything bigger than intval.
$conf->data->set(
hugeintval => $arg->{intval},
hugeintvalsize => $arg->{intvalsize},
);
}
}

sub _probe_for_hugefloatval {
my $conf = shift;
my $size;
$conf->cc_gen('config/auto/sizes/test3_c.in');
$conf->cc_build();
$size = eval $conf->cc_run();
$conf->cc_clean();
return $size;
}

sub _set_hugefloatval {
my ( $conf, $size ) = @_;
if ( $size ) {
$conf->data->set(
hugefloatval => 'long double',
hugefloatvalsize => $size
);
}
else {
$conf->data->set(
hugefloatval => 'double',
hugefloatvalsize => $conf->data->get('doublesize')
);
}
}

sub _set_intvalmaxmin {
my $conf = shift;
my $ivmin;
Expand Down
24 changes: 0 additions & 24 deletions config/auto/sizes/floatval_maxmin_c.in

This file was deleted.

25 changes: 0 additions & 25 deletions config/auto/sizes/intval_maxmin_c.in

This file was deleted.

29 changes: 0 additions & 29 deletions config/auto/sizes/test2_c.in

This file was deleted.

0 comments on commit 0321a4c

Please sign in to comment.