Re: [m-users.] Best way to implement constants ?

"Sean Charles (emacstheviking)" <[email protected]>
Newsgroups gmane.comp.lang.mercury.general
Message-ID <[email protected]>
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 <[email protected]> wrote:
> 
> 
> On 2023-08-18 11:37 +02:00 CEST, "Julien Fischer" <[email protected]> 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
> [email protected]
> https://lists.mercurylang.org/listinfo/users

_______________________________________________
users mailing list
[email protected]
https://lists.mercurylang.org/listinfo/users
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.