Commit Graph

24 Commits

Author SHA1 Message Date
Zoltan Somogyi
3c931d074c Delete old_list_to_set.
library/fat_sparse_bitset.m:
library/sparse_bitset.m:
    As above.

tests/hard_coded/speedtest_bitset.m:
    Delete references to old_list_to_set.
2023-02-03 19:30:53 +11:00
Zoltan Somogyi
ee0f9f73d7 Add library/fatter_sparse_bitset.m.
library/fatter_sparse_bitset.m:
    Add this version of fat_sparse_bitset.m, which stores *two* words
    worth of bits in each cell, not one. This word would otherwise be unused,
    because the Boehm-Demers-Weiser allocator rounds up requests for three
    word cells to four.

library/MODULES_DOC:
library/library.m:
    Add the new module to the list of library modules.

library/fat_sparse_bitset.m:
library/sparse_bitset.m:
library/tree_bitset.m:
    Update the documentation of all these other bitset modules. Copy
    the same basic introduction to all the relevant modules. Add documentation
    of the differences to tree_bitset.m and fatter_sparse_bitset.m, with
    a pointer in fat_sparse_bitset.m to fatter_sparse_bitset.m.

library/test_bitset.m:
    Test the new module as well as the others.

tests/hard_coded/speedtest_bitset.m:
    Extend the benchmarking of list_to_set operations to the new module.
    To allow the benchmarking to be tough enough to be informative, comment
    out the benchmarking of the old_list_to_set operations.
2023-01-31 18:36:16 +11:00
Zoltan Somogyi
6f6d30b8f2 Improve the speed of fat_sparse_bitset.list_to_set ...
... by using the algorithm now in sparse_bitset.list_to_set.

Keep the old list_to_set algorithm around in both modules for a short while
to allow comparative benchmarking.

library/fat_sparse_bitset.m:
library/sparse_bitset.m:
    As above.

tests/hard_coded/speedtest_bitset.m:
    A benchmark program to compare the old and new list_to_set algorithms,
    both versus each other, and between sparse_bitset and fat_sparse_bitset.
2023-01-29 07:57:44 +11:00
Zoltan Somogyi
0497e18e7b Clarity the prereqs of sorted_list_to_set for bitsets. 2023-01-23 00:20:48 +11:00
Zoltan Somogyi
4a14c05ccc Union and intersect up to 8 bitsets at a time. 2023-01-19 15:36:49 +11:00
Zoltan Somogyi
56ed26f650 Improve the remove_{leq,gt} sparse bitset ops.
library/sparse_bitset.m:
library/fat_sparse_bitset.m:
    Speed up the remove_leq and remove_gt operations by moving a
    loop invariant computation, the conversion of the boundary item's index
    into an <offset,bitposn> pair, out of the loop.

    Eliminate some unnecessary differences between the two modules,
    e.g. clear_bit being a predicate rather than a function.

library/test_bitset.m:
    Add facilities to test the remove_leq and remove_gt operations
    of sparse_bitset.m, fat_sparse_bitset.m, and tree_bitset.m
    against the same operations on plain old set_ordlists.

    Bring this module up to date by requiring set elements to be
    members of the uenum typeclass, not the enum typeclass.

    Make the test_bitset type a bespoke type.

library/tree_bitset.m:
    Add predicate versions of the remove_leq and remove_gt operations
    alongside the existing function versions, to allow the new code
    in test_bitset.m to work the same way regardless of which bitset module
    it is testing.

    For uniformity with the other bitset modules, require set elements to be
    members of the uenum typeclass, not the enum typeclass.

    Change the other integers, such as level numbers, to be unsigned
    as well, to avoid the need for casts.

NEWS:
    Announce the new additions and changes.

tests/hard_coded/test_tree_bitset.{m,exp}:
    Use those new facilities to test those operations, and add some
    test sets designed for that purpose.

    Add a comment about the limitations of this testing strategy.

tests/hard_coded/bitset_tester.m:
    Delete this long-unused module. (It was the original basis of
    the test_bitset.m module in the library directory, but it became unused
    when test_tree_bitset.m switched to using that module a long time ago.)
2023-01-19 14:42:34 +11:00
Zoltan Somogyi
17165b9b5d Start using shifts by uints.
library/fat_sparse_bitset.m:
library/sparse_bitset.m:
    Replace shifts by ints (most cast from uints) with shifts where
    the number of bits to shift is specified as a uint.
2022-12-09 15:13:26 +11:00
Zoltan Somogyi
ec20b1ed0a Make sparse_bitset.m operate on uints.
NEWS:
    Mention all the user-visible changes below.

library/enum.m:
    Add the typeclass uenum, which is a version of the existing enum typeclass
    that maps items to uints, not ints. It also uses a semidet predicate,
    not a semidet function, to get back to the item from the uint.

library/sparse_bitset.m:
library/fat_sparse_bitset.m:
    Make these modules operate on uints, which means requiring the items
    in the sets to be instances of uenum, not enum.

    If a few places, improve loops by doing previously-repeated conversions
    of [u]ints into <offset, bit-to-set> pairs just once.

library/counter.m:
    Define ucounters, which allocate uints. Improve documentation.

library/digraph.m:
    Change digraph_keys from ints to uints, since we put them into
    sparse_bitsets.

library/int.m:
    Make int an instance of the uenum typeclass. This can help users
    who currently put ints into sparse_bitsets.

library/pprint.m:
    Prettyprint sparse_bitsets as lists of uints.

library/term.m:
    Make vars instances of uenum as well as enum.

library/uint.m:
    Make uint an instance of the uenum typeclass.

    Add the ubits_per_uint function, which allows some casts to be avoided.

compiler/make.deps_set.m:
    Change the indexes we put into sparse_bitsets from ints to uints.

compiler/make.make_info.m:
    Change the source of those indexes from ints to uints.

compiler/make.top_level.m:
compiler/make.util.m:
    Conform to the changes above.

compiler/pre_quantification.m:
    Change zones from ints to uints, since we put them into sparse_bitsets.

tests/hard_coded/int_uenum.{m,exp}:
tests/hard_coded/Mmakefile:
    Enable the new test case.

tests/valid/use_import_only_for_instance.m:
    Update this extract from library/digraph.m the same way as
    library/digraph.m itself.
2022-12-05 09:45:11 +11:00
Zoltan Somogyi
c464dc17d7 Improve {fat_,}_sparse_bitset.m.
library/fat_sparse_bitset.m:
library/sparse_bitset.m:
    Change the auxiliary functions of these modules into predicates,
    since their main job is to update the bitset_elems data structure.
    Make the converted predicates use state variable notation
    where this is useful.

    When an operation has two versions, a function and a predicate,
    the predicate used to be implemented in terms of the function.
    Switch this: implement the functions in terms of the predicates.

    Use a consistent naming scheme for variables: ItemX for the things
    stored in the sparse bitset; SetX for representing whole sparse bitsets,
    and ElemsX for repreresenting bitset_elems.

    Fix some minor problems in the comments describing the exported operations.

    Note opportunities for improvement.
2022-11-30 12:34:04 +11:00
Julien Fischer
a7a6db5112 Delete obsolete predicates from set modules.
library/diet.m:
library/fat_sparse_bitset.m:
library/set.m:
library/set_bbbtree.m:
library/set_ctree234.m:
library/set_ordlist.m:
library/set_tree234.m:
library/set_unordlist.m:
library/sparse_bitset.m:
library/tree_bitset.m:
    Delete predicates and functions that have been marked as obsolete
    since at least 2019.

    Adjust documentation as required.

NEWS:
    Announce the deletions.
2022-04-13 19:53:47 +10:00
Zoltan Somogyi
8ff61f8a4b Delete quotes from `VarNames' in stdlib comments.
In the Mercury standard library, every exported predicate or function
has (or at least *should* have) a comment that documents it, including
the meanings of its arguments. About 35-40% of these modules put `'s
(left and right quotes) around the names of the variable representing
those arguments. Some tried to do it consistently (though there were spots
with unquoted or half quoted names), while some did it only a few places.
This is inconsistent: we should either do it everywhere, or nowhere.
This diff makes it nowhere, because

- this is what the majority of the standard library modules do;
- this is what virtually all of the modules in the compiler, profiler,
  deep_profiler etc directories do;
- typing all those quotes when adding new predicates in modules that
  follow this convention is a pain in the ass; and because
- on many modern terminals, `' looks non-symmetrical and weird.

Likewise, the comment explaining a predicate often started with

    % `predname(arguments)' returns ...

This diff deletes these quotes as well, since they add nothing useful.

This diff does leave in place quotes around code fragments, both terms
and goals, where this helps delineate the boundaries of that fragment.
2022-03-07 11:49:00 +11:00
Zoltan Somogyi
0d7c8a7654 Specify pred or func for all pragmas.
*/*.m:
    As above.

configure.ac:
    Require the installed compiler to support this capability.
2021-06-16 15:23:58 +10:00
Zoltan Somogyi
f90e0c3c90 Improve sparse_bitset.m and fat_sparse_bitset.m.
library/sparse_bitset.m:
library/fat_sparse_bitset.m:
    Improve these modules in several ways.

    Provide more detailed documentation for the main data structures
    and for several predicates.

    Give some internal predicates more meaningful names.

    Make union_list and intersect_list merge four sets per pass instead of two,
    and encode the pass's main invariant (that both the input and output lists
    of sets are nonempty) in the types.

    Provide distinct low_to_high and high_to_low versions of both fold_bits
    and fold2_bits, in order to avoid having to make repeated switches
    based on the direction.

    Use predmode declarations when possible.

    Use variable names in a more consistent manner.

    Move initial det computations out of the conditions of if-then-elses.

    Eliminate negated tests in the conditions of if-then-elses.

    Use det_from_int where relevant.

    Eliminate nil/cons switches where both arms do the same thing.

    Eliminate unnecessary differences between the two modules.
2020-06-19 18:06:17 +10:00
Zoltan Somogyi
b0e8c56092 Make the remaining set modules follow our standard order.
library/diet.m:
library/fat_sparse_bitset.m:
library/sparse_bitset.m:
library/test_bitset.m:
library/tree_bitset.m:
    As above. Also, mark as obsolete the same predicates as were marked obsolete
    in the other set modules recently.

compiler/mode_robdd.equiv_vars.m:
compiler/mode_robdd.implications.m:
compiler/mode_robdd.tfeirn.m:
library/robdd.m:
library/digraph.m:
    Avoid using predicates that are now marked obsolete.
2019-09-14 00:03:44 +10:00
Zoltan Somogyi
95f8f56716 Delete unneeded $module args from calls to expect/unexpected. 2019-07-03 22:37:19 +02:00
Mark Brown
d465fa53cb Update the COPYING.LIB file and references to it.
Discussion of these changes can be found on the Mercury developers
mailing list archives from June 2018.

COPYING.LIB:
    Add a special linking exception to the LGPL.

*:
    Update references to COPYING.LIB.

    Clean up some minor errors that have accumulated in copyright
    messages.
2018-06-09 17:43:12 +10:00
Peter Wang
f580a90c33 Use uints to represent bit vectors.
library/fat_sparse_bitset.m
library/sparse_bitset.m:
library/tree_bitset.m:
    Use uints to represent bit vectors in these modules.
2018-04-15 17:03:56 +10:00
Zoltan Somogyi
0027db99fe Fix more warnings from --warn-inconsistent-pred-order-clauses. 2017-05-04 02:17:42 +10:00
Zoltan Somogyi
44f9f1f405 Convert (C->T;E) to (if C then T else E). 2015-12-01 07:58:07 +11:00
Julien Fischer
e66457155b Additional modes for folds over sparse_bitsets.
library/sparse_bitset.m:
library/fat_sparse_bitset.m:
	Add modes for folds with unique and mostly-unique accumulators.

library/diet.m:
	Fix some formatting.
2015-04-10 10:28:29 +10:00
Zoltan Somogyi
7f9791aa26 Standardize divider line lengths in the library.
library/*.m:
    As above.

tool/stdlines:
    A new shell script to do the job.
2014-11-23 22:05:34 +11:00
Zoltan Somogyi
30383a8c47 Avoid some redundant work during determinism analysis.
Estimated hours taken: 3
Branches: main

Avoid some redundant work during determinism analysis. This diff speeds up
tools/speedtest by just shy of 0.7%.

compiler/det_analysis.m:
	Instead of (a) getting a list of procedures in the module and then
	(b) classifying them into three categories, do both jobs at once.
	This avoids some redundant traversals and map lookups, and avoids
	the creation of an intermediate data structure.

compiler/instmap.m:
	Instead of converting a set into a list and iterating over that list
	to check that elements of the set have a given property, iterate over
	the set elements directly.

	Put the arguments of a predicate in a more logical order.

compiler/det_util.m:
	Conform to the change in instmap.m.

compiler/set_of_var.m:
	Provide the all_true predicate needed by det_util.

library/*set*.m:
	In every module that implements sets, provide an all_true predicate.

NEWS:
	Mention the new predicates in the library.
2012-04-24 09:18:29 +00:00
Zoltan Somogyi
a54ae6232d Instead of first testing whether an inst exists in a set
Estimated hours taken: 8
Branches: main

compiler/inst_match.m:
	Instead of first testing whether an inst exists in a set
	and then inserting it if does not, use a single predicate
	that does both the membership test and the insertion (if
	the membership test failed) in one pass.

	This speeds up compilation of one version of the rcpsp_cpx
	stress test by about 9%, with negligible effect on tools/speedtest.

	Some cleanups that should have been committed before this diff follow.

	Change the structure of many of the predicates in this module from
	containing multiple clauses, to a single clause with an explicit
	disjunction, which (where relevant) now gets a require_comple_switch
	wrapper. In several cases, this change has shown that we were
	missing code for handling some kinds of insts. For example, some
	predicates handled free/0 but not free/1, even though there was
	no reason for the difference. This diff fixes such oversights
	in places where the right action seems obvious to me, and adds
	XXXs in places where I see no obvious fix.

	Rename several predicates and function symbols to avoid ambiguities.

	Add some XXXs on potential problems.

library/*set*.m:
	Implement this insert_new predicate for all the implementations
	of sets we have. The code in each case is copied from the code
	of insert, with code to return a set unchanged replaced with `fail'.

NEWS:
	Mention the new predicates.
2012-04-02 03:58:56 +00:00
Zoltan Somogyi
71b4e1db8d Add the predicates and functions needed to allow this module
Estimated hours taken: 6
Branches: main

library/sparse_bitset.m:
	Add the predicates and functions needed to allow this module
	to replace tree_bitset.m in implementing the operations of
	set_of_var.m.

	Convert the module to call unexpected instead of error.

library/fat_sparse_bitset.m:
	A new module. It is a copy of the updated version of sparse_bitset.m
	modified to use fat lists instead of plain lists. This means that
	instead of representations such as

		[bitset_elem(Offset1, Bits1), bitset_elem(Offset2, Bits2)]

	it has representations such as

		node(Offset1, Bits1, node(Offset2, Bits2, empty))

	These have half the number of nodes and thus half the number of
	allocations. In theory, they could also need only 75% of the space
	(one three-word cell instead of two two-word cells), but the Boehm
	collector rounds up three words to four.

library/library.m:
	Add the new module.
2011-08-22 06:33:02 +00:00