[m-dev.] for review: MLDS back-end: library fixes

Mark Anthony BROWN dougl at cs.mu.OZ.AU
Tue Dec 7 14:43:11 AEDT 1999


Fergus Henderson writes:
> 
> Estimated hours taken: 8
> 
> Add support for the MLDS back-end (i.e. the `--high-level-code'
> option) to various parts of the standard library.
> 
> library/benchmarking.m:
> 	Add `#ifndef MR_HIGHLEVEL_CODE' to ifdef out the parts
> 	of `report_stats' which depend on the details of the
> 	low-level execution model.
> 
> 	Rewrite benchmark_det and benchmark_nondet using
> 	impure Mercury with `pragma c_code' fragments,
> 	rather than using low-level C code.
> 	The low-level C code was a maintenance problem
> 	(e.g. I don't think it was restoring the
> 	MR_ticket_counter properly in trailing grades)
> 	and this way avoids the need to duplicate the
> 	hand-written code for the MLDS back-end.

Also, the impure Mercury is much *MUCH* easier to read.

> 
> library/exception.m:
> 	Implement exception handling for the MLDS back-end,
> 	using setjmp() and longjmp().

I haven't reviewed the changes to this module yet.

> 
> library/math.m:
> 	Add `#ifndef MR_HIGHLEVEL_CODE' around the call to
> 	MR_dump_stack(), since that code requires the
> 	low-level execution model.

This change is fine.

> 
> Workspace: /d-drive/home/hg/fjh/mercury
> Index: library/benchmarking.m
> ===================================================================
> RCS file: /home/mercury1/repository/mercury/library/benchmarking.m,v
> retrieving revision 1.27
> diff -u -d -r1.27 benchmarking.m
> --- library/benchmarking.m	1999/11/22 04:25:55	1.27
> +++ library/benchmarking.m	1999/12/06 14:40:18
> @@ -152,18 +156,33 @@
>  	time_at_prev_stat = time_at_last_stat;
>  	time_at_last_stat = MR_get_user_cpu_miliseconds();
>  
> +#ifdef MR_HIGHLEVEL_CODE
>  	eng = MR_get_engine();
> +#endif
>  
>  	fprintf(stderr, 
> -		""[Time: +%.3fs, %.3fs, D Stack: %.3fk, ND Stack: %.3fk,"",
> +		""[Time: +%.3fs, %.3fs,"",
>  		(time_at_last_stat - time_at_prev_stat) / 1000.0,
> -		(time_at_last_stat - time_at_start) / 1000.0,
> +		(time_at_last_stat - time_at_start) / 1000.0
> +

There is an extra line here.

>  
> -BEGIN_MODULE(benchmark_det_module)
> -	init_entry_sl(mercury__benchmarking__benchmark_det_5_0);
> -	MR_INIT_PROC_LAYOUT_ADDR(mercury__benchmarking__benchmark_det_5_0);
> -	init_label_sl(mercury__benchmarking__benchmark_det_5_0_i1);
> -BEGIN_CODE
> +:- impure pred benchmark_det_loop(pred(T1, T2), T1, T2, int).
> +:- mode benchmark_det_loop(pred(in, out) is det, in, out, in) is cc_multi.
>  

I don't understand why this is cc_multi.  Couldn't you make
this procedure det, and call cc_multi_equal in benchmark_det/5
before returning the time?

> +:- pragma promise_pure(benchmark_nondet/5).
> +benchmark_nondet(Pred, In, Count, Repeats, Time) :-
> +	impure get_user_cpu_miliseconds(StartTime),
> +	impure benchmark_nondet_loop(Pred, In, Count, Repeats),
> +	impure get_user_cpu_miliseconds(EndTime),
> +	Time = StartTime - EndTime.
>  
> +:- impure pred benchmark_nondet_loop(pred(T1, T2), T1, int, int).
> +:- mode benchmark_nondet_loop(pred(in, out) is nondet, in, out, in) is cc_multi.
>  
> +benchmark_nondet_loop(Pred, In, Count, Repeats) :-
> +	impure new_int_reference(0, SolutionCounter),
> +	(
> +		impure repeat(Repeats),
> +		impure update_ref(SolutionCounter, 0),
> +		Pred(In, Out0),
> +		impure do_nothing(Out0),
> +		impure incr_ref(SolutionCounter),
> +		fail
> +	;
> +		true
> +	),
> +	semipure ref_value(SolutionCounter, Count0),
> +	cc_multi_equal(Count0, Count).

Likewise here.  Couldn't cc_multi_equal/2 be used on the value of Time
in benchmark_nondet/5?

The rest is fine, apart from the changes to exception.m, which
I haven't yet looked at.

Cheers,
Mark
-- 
Mark Brown, PhD student            )O+  |  "Another of Fortran's breakthroughs
(m.brown at cs.mu.oz.au)                   |  was the GOTO statement, which was...
Dept. of Computer Science and Software  |  uniquely simple and understandable"
Engineering, University of Melbourne    |              -- IEEE, 1994
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list