[m-users.] Best way to implement constants ?
Sean Charles (emacstheviking)
objitsu at gmail.com
Fri Aug 18 19:54:01 AEST 2023
Excellent!
I did a little experiment for myself, first this program, compiled at -O3 without the explicit command line option, using
Mercury Compiler, version 22.01.6, on aarch64-apple-darwin22.5.0
Copyright (C) 1993-2012 The University of Melbourne
Copyright (C) 2013-2023 The Mercury team
Usage: mmc [<options>] <arguments>
Use `mmc --help' for more information.
The code:
main(!IO) :-
RESULT = 22.0 / 7.0,
io.format("Mercury demands focus! %f\n", [f(RESULT)], !IO).
This yields this C code:
void MR_CALL
main_2_p_0(void)
{
{
MR_Float RESULT_4;
MR_Float Var_7 = (MR_Float) 22.000000000000000;
MR_Float Var_8 = (MR_Float) 7.0000000000000000;
MR_String Var_15;
MR_String Var_17;
MR_Word Var_23;
MR_Word Var_24;
MR_String Var_25;
RESULT_4 = mercury__float__f_slash_2_f_0(Var_7, Var_8);
So I see that yes, it is still performing the evaluation at runtime, but with the --optimize-constant-propogation option:
void MR_CALL
main_2_p_0(void)
{
{
MR_Float RESULT_4 = (MR_Float) 3.1428571428571428;
So, thank you Zoltan.
> On 18 Aug 2023, at 10:48, Zoltan Somogyi <zoltan.somogyi at runbox.com> wrote:
>
>
> On 2023-08-18 11:37 +02:00 CEST, "Julien Fischer" <jfischer at opturion.com> wrote:
>> At -O3 and above the Mercury compiler will (generally) evaluate a
>> variety of operations (see compiler/const_prop.m for details).
>> Float division is included in those operations
>
> Actually, constant propagation is not enabled automatically at any
> optimization level; you have to enable manually, with --optimize-constant-propagation.
> What is enabled at -O3 is *constraint* propagation, which I also
> misread as *constant* propagation at first :-(
>
> I will add constant propagation to -O3.
>
> Zoltan.
> _______________________________________________
> users mailing list
> users at lists.mercurylang.org
> https://lists.mercurylang.org/listinfo/users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurylang.org/archives/users/attachments/20230818/3ebb8dd4/attachment.html>
More information about the users
mailing list