[m-rev.] for review: resets and statistics for tabling

Julien Fischer juliensf at cs.mu.OZ.AU
Fri Jun 9 11:56:29 AEST 2006


On Thu, 8 Jun 2006, Zoltan Somogyi wrote:

> Index: runtime/mercury_table_int_fix_index_body.h
> ===================================================================
> RCS file: runtime/mercury_table_int_fix_index_body.h
> diff -N runtime/mercury_table_int_fix_index_body.h
> --- /dev/null	1 Jan 1970 00:00:00 -0000
> +++ runtime/mercury_table_int_fix_index_body.h	21 May 2006 10:49:30 -0000
> @@ -0,0 +1,30 @@
> +/*
> +** vim: ts=4 sw=4 expandtab
> +*/
> +/*
> +** Copyright (C) 2006 The University of Melbourne.
> +** This file may only be copied under the terms of the GNU Library General
> +** Public License - see the file COPYING.LIB in the Mercury distribution.
> +*/
> +
> +/*
> +** This files defines the bodies of the variants of the
> +** MR_int_fix_index_lookup_or_add() function.
> +**
> +** NOTE: changes to this function will probably also have to be reflected
> +** in the places listed in mercury_type_info.h.
> +*/
> +
> +    if (t->MR_fix_table == NULL) {
> +        record_alloc();
> +        t->MR_fix_table = MR_TABLE_NEW_ARRAY(MR_TableNode, range);
> +        memset(t->MR_fix_table, 0, sizeof(MR_TableNode) * range);

s/memset/MR_memset/

> +    }
> +
> +#ifdef  MR_TABLE_DEBUG
> +    if (key >= range) {
> +        MR_fatal_error("MR_int_fix_index_lookup_or_add: key out of range");
> +    }
> +#endif
> +
> +    return &t->MR_fix_table[key];
> Index: runtime/mercury_table_int_start_index_body.h

...

> ===================================================================
> RCS file: runtime/mercury_table_int_start_index_body.h
> diff -N runtime/mercury_table_int_start_index_body.h
> --- /dev/null	1 Jan 1970 00:00:00 -0000
> +++ runtime/mercury_table_int_start_index_body.h	21 May 2006 10:58:43 -0000
> @@ -0,0 +1,55 @@
> +/*
> +** vim: ts=4 sw=4 expandtab
> +*/
> +/*
> +** Copyright (C) 2006 The University of Melbourne.
> +** This file may only be copied under the terms of the GNU Library General
> +** Public License - see the file COPYING.LIB in the Mercury distribution.
> +*/
> +
> +/*
> +** This files defines the bodies of the variants of the
> +** MR_int_start_index_lookup_or_add() function.
> +*/
> +
> +    MR_Integer      diff, size;
> +
> +    diff = key - start;
> +
> +#ifdef  MR_TABLE_DEBUG
> +    if (key < start) {
> +        MR_fatal_error("MR_int_start_index_lookup_or_add: too small key");
> +    }
> +#endif
> +
> +    if (table->MR_start_table == NULL) {
> +        record_alloc();
> +        size = MR_max(MR_START_TABLE_INIT_SIZE, diff + 1);
> +        table->MR_start_table = MR_TABLE_NEW_ARRAY(MR_TableNode, size + 1);
> +        memset(table->MR_start_table + 1, 0, sizeof(MR_TableNode) * size);

s/memset/MR_memset/

> +        table->MR_start_table[0].MR_integer = size;
> +    } else {
> +        size = table->MR_start_table[0].MR_integer;
> +    }
> +
> +    if (diff >= size) {
> +        MR_TableNode    *new_array;
> +        MR_Integer      new_size, i;
> +
> +        new_size = MR_max(2 * size, diff + 1);
> +        new_array = MR_TABLE_NEW_ARRAY(MR_TableNode, new_size + 1);
> +
> +        new_array[0].MR_integer = new_size;
> +
> +        for (i = 0; i < size; i++) {
> +            new_array[i + 1] = table->MR_start_table[i + 1];
> +        }
> +
> +        for (; i < new_size; i++) {
> +            new_array[i + 1].MR_integer = 0;
> +        }
> +
> +        table->MR_start_table = new_array;
> +    }
> +
> +    return &table->MR_start_table[diff + 1];

...

> Index: runtime/mercury_table_type_body.h
> ===================================================================
> RCS file: runtime/mercury_table_type_body.h
> diff -N runtime/mercury_table_type_body.h
> --- /dev/null	1 Jan 1970 00:00:00 -0000
> +++ runtime/mercury_table_type_body.h	6 Jun 2006 06:03:34 -0000
> @@ -0,0 +1,461 @@
> +/*
> +** vim: ts=4 sw=4 expandtab
> +*/
> +/*
> +** Copyright (C) 2006 The University of Melbourne.
> +** This file may only be copied under the terms of the GNU Library General
> +** Public License - see the file COPYING.LIB in the Mercury distribution.
> +*/
> +
> +/*
> +** This files defines the bodies of the various variants of the
> +** MR_table_type() function.
> +**
> +** NOTE: Any changes to this function will probably also have to be reflected
> +** in the places listed in mercury_type_info.h.
> +*/
> +
> +    MR_TypeCtorInfo type_ctor_info;
> +    MR_DuTypeLayout du_type_layout;
> +    MR_TrieNode     table_next;
> +
> +    type_ctor_info = MR_TYPEINFO_GET_TYPE_CTOR_INFO(type_info);
> +
> +    if (DEBUG && MR_tabledebug) {
> +        printf("ENTRY %p %x, data rep: %d\n",
> +            table, data, MR_type_ctor_rep(type_ctor_info));
> +    }

Please change %d to %" MR_INTEGER_LENGTH_MODIFIER "d above and in
lots of other places in order to avoid gcc warnings on 64-bit machines.
(Compiling the runtime on saturn will tell you which places.)

> +
> +    if (! MR_type_ctor_has_valid_rep(type_ctor_info)) {
> +        MR_fatal_error("MR_table_type: term of unknown representation");
> +    }
> +
> +    switch (MR_type_ctor_rep(type_ctor_info)) {
> +        case MR_TYPECTOR_REP_ENUM:
> +        case MR_TYPECTOR_REP_ENUM_USEREQ:
> +            MR_TABLE_ENUM(STATS, DEBUG, BACK, table_next, table,
> +                MR_type_ctor_num_functors(type_ctor_info), data);
> +            table = table_next;
> +            return table;
> +
> +        case MR_TYPECTOR_REP_DUMMY:
> +            /*
> +            ** If we are ever asked to table a value of a dummy type, we treat
> +            ** it mostly as an enum, with the exception being that we ignore
> +            ** the actual value to be table (since it contains garbage) and

s/table/tabled/

> +            ** substitute the constant zero, which ought to be the enum value
> +            ** assigned to the type's only function symbol.
> +            **
> +            ** It would of course be preferable for the compiler to simply
> +            ** not insert any arguments of dummy types into tables.
> +            */
> +            MR_TABLE_ENUM(STATS, DEBUG, BACK, table_next, table, 1, 0);
> +            table = table_next;
> +            return table;
> +

...

The rest of that looks fine.

Julien.
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list