help-smalltalk
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: [Help-smalltalk] About no_opt macro


From: Paolo Bonzini
Subject: Re: [Help-smalltalk] About no_opt macro
Date: Tue, 12 Oct 2010 16:29:14 +0200
User-agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.2.9) Gecko/20100907 Fedora/3.1.3-1.fc13 Lightning/1.0b3pre Mnenhy/0.8.3 Thunderbird/3.1.3

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



reply via email to

[Prev in Thread] Current Thread [Next in Thread]