[m-rev.] for review: unify/compare as MR_Unsigned
Julien Fischer
jfischer at opturion.com
Fri Oct 5 11:23:01 AEST 2018
Hi Zoltan,
On Fri, 5 Oct 2018, Zoltan Somogyi wrote:
> Unify and compare terms as MR_Unsigned when possible.
...
> diff --git a/compiler/unify_proc.m b/compiler/unify_proc.m
> index 4232e85..198528e 100644
> --- a/compiler/unify_proc.m
> +++ b/compiler/unify_proc.m
...
> @@ -1187,33 +1218,137 @@ generate_compare_proc_body_du(SpecDefnInfo, Ctors0, Res, X, Y, Clause,
> ErlangOrder),
> (
> ErlangOrder = yes,
> - list.sort(compare_ctors_for_erlang, Ctors0, Ctors)
> + list.sort(compare_ctors_for_erlang, CtorRepns0, CtorRepns)
> ;
> ErlangOrder = no,
> - Ctors = Ctors0
> + CtorRepns = CtorRepns0
> ),
> - (
> - Ctors = [],
> - unexpected($pred, "compare for type with no functors")
> - ;
> - Ctors = [_ | _],
> - UCOptions = lookup_unify_compare_options(!.Info),
> + expect_not(unify(CtorRepns, []), $pred,
> + "compare for type with no functors"),
> + UCOptions = lookup_unify_compare_options(!.Info),
> + Context = SpecDefnInfo ^ spdi_context,
> + ( if
> + UCOptions ^ uco_constants_as_ints = compare_constants_as_ints,
> + UCOptions ^ uco_packed_unify_compare = allow_packed_unify_compare,
> + % Can we compare two values of this type by casting both values
> + % to unsigned and comparing the results?
> + (
> + CtorRepns = [CtorRepnA],
> + % If all the arguments of functor A are stored next to the ptag,
> + % and if they are all comparable as unsigned, two conditions
> + % that is_ctor_with_all_locally_packed_unsigned_args will test,
> + % and if they are arranged earlier-args-in-more-significant-bits,
> + % which is always guaranteed for packed arguments by
> + % du_type_layout.m, then yes, cast-to-unsigned-and-compare
> + % will work.
> + is_ctor_with_all_locally_packed_unsigned_args(CtorRepnA, _)
> + ;
> + CtorRepns = [CtorRepnA, CtorRepnB],
> + % If functor A comes before functor B, and
> + %
> + % - the value of a term whose functor is A *must* be all zeroes
> + % - the value of a term whose functor is B *cannot* be all zeroes
The second condition is unclear, I think you also need something along the
lines of
and to which cast-to-unsigned-and-compare would apply
(i.e B must also meet conditions described in the first disjunct.)
> + %
> + % then comparing two terms, one bound to A and one bound to B,
> + % by casting both to unsigned and comparing the results, will yield
> + % the correct result.
> + %
> + % If A has arity zero, then there is only one possible term whose
> + % functor is A, so cast-to-unsigned-and-compare works when
> + % both terms are bound to A. And for the reason explained above,
> + % it also works when both terms are bound to B.
> + CtorRepnA = ctor_repn(_OrdinalA, _MaybeExistConstraintsA,
> + _FunctorNameA, ConsTagA, _CtorArgRepnsA, ArityA, _CtxtA),
> + ArityA = 0,
> + ConsTagA = local_args_tag(LocalArgsTagInfoA),
> + LocalArgsTagInfoA =
> + local_args_not_only_functor(PtagA, LocalSecTagA),
> + PtagA = ptag(0u8),
> + LocalSecTagA = local_sectag(0u, _, _),
The rest looks fine.
Julien.
More information about the reviews
mailing list