Menu

#3 Do not 'init' locals

open
nobody
None
5
2009-12-09
2009-12-09
Erven
No

We had to initialize locals because of a bug in Mono.
Can we remove it?

Discussion

  • Andrea C. Ornstein

    You cannot remove them completely, they are used to initialize global variables as specified by the C language.
    If the problem is in the use of cpblk, we can add a flag that avoids its generation (it is an optimization of the code after all).
    But the initialization of a constant array or struct will take a lot of instructions, the init functions can be really big.

     
  • Erven

    Erven - 2009-12-10

    Not sure I am following. I was referring to local variables, not global. That is: the '.locals init' at the top of a function. Am I missing your point?

     
  • Andrea C. Ornstein

    Sorry for that, I missunderstood the problem
    I was referring to the init functions we create for the global variables and not to the init attribute to the .local directive.

    We have to check with Gabriele, I recall that we added the init to avoid a bug in Mono 2.4

     
  • Gabriele Svelto

    Gabriele Svelto - 2009-12-11

    The init attribute was added because Mono 2.4's register allocator was confused by the presence of non-initialized locals. The problem descends from the fact that in C you can access uninitialized variables even though the behavior is undefined. We did use the init attribute because we didn't have enough time to roll a clean-up phase that would look for non-initialized locals and emitted 0 initializations for them. Theoretically speaking it would be better to have such pass because init may impose a burden on the JIT and force it to emit unnecessary code at the function entry point.

     
  • Nobody/Anonymous

    Then, we can probably remove the 'init', which is not required by the C language.
    We can also add a flag to control whether it is emitted or not, in case somebody uses an older version of Mono.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.