[m-dev.] diff: fix nondet_c problem

Zoltan Somogyi zs at cs.mu.OZ.AU
Sat Mar 27 19:39:34 AEDT 1999


> compiler/pragma_c_gen.m:
> 	For nondet pragma c_code, don't output calls to save_registers()
> 	or restore_registers() unless the procedure may_call_mercury.
> 	This is necessary to make tests/hard_coded/nondet_c.m work,
> 	since that test case uses will_not_call_mercury and incr_hp_atomic()
> 	rather than incr_saved_hp_atomic().
> 	It's also desirable from an efficiency standpoint and for
> 	consistency with ordinary (model_det or model_semi) pragma c_code.

Go ahead and commit this change. However, this does not fix the full problem.
Those saves and restores were there for a reason (which *you*, Fergus, had
pointed out in the first place), which is documented in pragma_c_gen.m).
What we want to achieve is (a) allowing the included C code to allocate
memory, and (b) allowing the included C code to call exported Mercury
code which may allocate memory. At the moment, (a) requires not doing
save/restore, while (b) requires doing save/restore, which means you
can't satisfy both at the same time.

BTW, using incr_saved_hp_atomic instead of incr_hp_atomic in nondet_c.m
does *not* cure the problem. The reason for that is that despite its name,
incr_saved_hp_atomic does *not* update the copy of hp in MR_fake_reg,
unless hp is stored in a transient register, of which the Alpha has none.
This should be fixed, by renaming the existing incr_saved_hp{,_atomic} macros
and possibly creating new ones in their place.

Zoltan.



More information about the developers mailing list