About no_opt macro

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

About no_opt macro

Mathieu Suen-2
Hi,

Will reading the vm.def, I cam across the no_opt macro.
I guess is to avoid some optimization but but what kind of optimization and why.

The macro is define as:

#define no_opt(x)    ({ __typeof__ ((x)) _result; \
             asm ("" : "=r" (_result) : "0" ((x))); _result; })


From what I understand is that it define a variable _result and force to move x
into _result.

The macro is used in tha bytecode PLUS_SPECIAL an MINUS SPECIAL ... :

 intptr_t iresult = no_opt (iop1 + iop2);

Thanks for shading the light on this point.

-Mathk




_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re: About no_opt macro

Paolo Bonzini-2
On 10/12/2010 03:28 PM, Mathieu Suen wrote:

> Will reading the vm.def, I cam across the no_opt macro.
> I guess is to avoid some optimization but but what kind of optimization and why.
>
> The macro is define as:
>
> #define no_opt(x)    ({ __typeof__ ((x)) _result; \
>               asm ("" : "=r" (_result) : "0" ((x))); _result; })
>
>
>  From what I understand is that it define a variable _result and force to move x
> into _result.
>
> The macro is used in tha bytecode PLUS_SPECIAL an MINUS SPECIAL ... :
>
>   intptr_t iresult = no_opt (iop1 + iop2);
>
> Thanks for shading the light on this point.

Here is the context:

       intptr_t iop1 = (intptr_t) op1;
       intptr_t iop2 = ((intptr_t) op2) - 1;
       intptr_t iresult = no_opt (iop1 + iop2);
       if (iresult < iop1)

Remember that these snippets are copied in many places.  For example,
when compiling code for a superoperator (compound bytecode) like

      PUSH_TEMPORARY(*)
      PUSH_INTEGER(1)
      PLUS_SPECIAL()

GCC would have

       intptr_t iop1 = (intptr_t) op1;
       intptr_t iresult = no_opt (iop1 + 2);
       if (iresult < iop1)

Without no_opt, "iop1 + 2 < iop1" would be simplified to "false", thus
causing the overflow check to misbehave.

Paolo

_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk
Reply | Threaded
Open this post in threaded view
|

Re : [Help-smalltalk] About no_opt macro

Mathieu Suen-2
:) thanks for make it perfectly clear.




----- Message d'origine ----

> De : Paolo Bonzini <[hidden email]>
> À : Mathieu Suen <[hidden email]>
> Cc : [hidden email]
> Envoyé le : Mar 12 octobre 2010, 16h 29min 14s
> Objet : Re: [Help-smalltalk] About no_opt macro
>
> On 10/12/2010 03:28 PM, Mathieu Suen wrote:
> > Will reading the vm.def, I  cam across the no_opt macro.
> > I guess is to avoid some optimization but  but what kind of optimization and
>why.
> >
> > The macro is define  as:
> >
> > #define no_opt(x)    ({ __typeof__ ((x)) _result;  \
> >               asm ("" : "=r"  (_result) : "0" ((x))); _result; })
> >
> >
> >  From what I  understand is that it define a variable _result and force to
>move x
> > into  _result.
> >
> > The macro is used in tha bytecode PLUS_SPECIAL an  MINUS SPECIAL ... :
> >
> >   intptr_t iresult = no_opt (iop1 +  iop2);
> >
> > Thanks for shading the light on this point.
>
> Here  is the context:
>
>       intptr_t iop1 = (intptr_t)  op1;
>       intptr_t iop2 = ((intptr_t) op2) - 1;
>        intptr_t iresult = no_opt (iop1 + iop2);
>        if (iresult < iop1)
>
> Remember that these snippets are copied in many  places.  For example, when
>compiling code for a superoperator (compound  bytecode) like
>
>      PUSH_TEMPORARY(*)
>       PUSH_INTEGER(1)
>      PLUS_SPECIAL()
>
> GCC would  have
>
>       intptr_t iop1 = (intptr_t) op1;
>        intptr_t iresult = no_opt (iop1 + 2);
>       if  (iresult < iop1)
>
> Without no_opt, "iop1 + 2 < iop1" would be  simplified to "false", thus causing
>the overflow check to  misbehave.
>
> Paolo
>




_______________________________________________
help-smalltalk mailing list
[hidden email]
http://lists.gnu.org/mailman/listinfo/help-smalltalk