Re: [Vala] Why the temporary variables in the C code are usefull ?

2011-07-07 Thread Jim Peters
Jacques-Pascal Deplaix wrote:
> >Unwanted side effects can happen if you evaluate an expression more
> >than once, e.g. if you substituted the full expression for every
> >_tmp2_ in the C code.  Expressions with side-effects include function
> >calls and stuff which modifies variables, e.g. p++.  You don't want to
> >do 'p++' twice or call the function twice.
>
> Thanks.  I give a clearer example of what you're saying:
> 
> y = x++ + --x;

No, that isn't what I meant.  Someone who knows the Vala compiler well
could probably come up with a better example, but the compiler could
in theory transform this:

  y = x++;
  z = y * y;

into this:

  z = x++ * x++;

But that would be a mistake.  You need to hold that intermediate 'y'
value somewhere to avoid doing x++ twice.  So some temporary variables
are always needed.

Jim

-- 
 Jim Peters  (_)/=\~/_(_) j...@uazu.net
  (_)  /=\  ~/_  (_)
 UazĂș  (_)/=\~/_(_)http://
 in Peru(_)  /=\  ~/_  (_)uazu.net
___
vala-list mailing list
vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Why the temporary variables in the C code are usefull ?

2011-07-07 Thread Jacques-Pascal Deplaix

On 07/07/2011 07:58 PM, Luca Bruno wrote:

There've been a number of refactoring lately that will hopefully lead to
dropping lots of useless temporary variables. That's for the sake of C
code readability and smaller C code footprint.

Fine !
I hope it will work better and faster
___
vala-list mailing list
vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Why the temporary variables in the C code are usefull ?

2011-07-07 Thread Jacques-Pascal Deplaix

On 07/07/2011 07:09 PM, Jim Peters wrote:

Unwanted side effects can happen if you evaluate an expression more
than once, e.g. if you substituted the full expression for every
_tmp2_ in the C code.  Expressions with side-effects include function
calls and stuff which modifies variables, e.g. p++.  You don't want to
do 'p++' twice or call the function twice.

As the other poster said, C compilers are very good at optimising away
temporary variables.

Jim

Thanks.
I give a clearer example of what you're saying:

y = x++ + --x;

The result depends of compiler.
___
vala-list mailing list
vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Why the temporary variables in the C code are usefull ?

2011-07-07 Thread Luca Bruno
On Thu, Jul 07, 2011 at 12:09:16PM -0500, Jim Peters wrote:
> Jacques-Pascal Deplaix wrote:
> > What are the side effects corrected by the temporary variables ?
> 
> Unwanted side effects can happen if you evaluate an expression more
> than once, e.g. if you substituted the full expression for every
> _tmp2_ in the C code.  Expressions with side-effects include function
> calls and stuff which modifies variables, e.g. p++.  You don't want to
> do 'p++' twice or call the function twice.
> 
> As the other poster said, C compilers are very good at optimising away
> temporary variables.

There've been a number of refactoring lately that will hopefully lead to
dropping lots of useless temporary variables. That's for the sake of C
code readability and smaller C code footprint.

-- 
http://www.debian.org - The Universal Operating System
___
vala-list mailing list
vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Why the temporary variables in the C code are usefull ?

2011-07-07 Thread Jim Peters
Jacques-Pascal Deplaix wrote:
> What are the side effects corrected by the temporary variables ?

Unwanted side effects can happen if you evaluate an expression more
than once, e.g. if you substituted the full expression for every
_tmp2_ in the C code.  Expressions with side-effects include function
calls and stuff which modifies variables, e.g. p++.  You don't want to
do 'p++' twice or call the function twice.

As the other poster said, C compilers are very good at optimising away
temporary variables.

Jim

-- 
 Jim Peters  (_)/=\~/_(_) j...@uazu.net
  (_)  /=\  ~/_  (_)
 UazĂș  (_)/=\~/_(_)http://
 in Peru(_)  /=\  ~/_  (_)uazu.net
___
vala-list mailing list
vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Why the temporary variables in the C code are usefull ?

2011-07-06 Thread Jacques-Pascal Deplaix

On 07/06/2011 08:15 PM, pancake wrote:

The compiler can optimize this. Those temp vars are just to make the vala 
compiler simpler.. It would be great if vala could do some minor optimization 
steps before spitting C. But if you compile with -O2 it shouldnt be something 
to worry.

Ok, fine...
Thank you !
___
vala-list mailing list
vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list


Re: [Vala] Why the temporary variables in the C code are usefull ?

2011-07-06 Thread pancake
The compiler can optimize this. Those temp vars are just to make the vala 
compiler simpler.. It would be great if vala could do some minor optimization 
steps before spitting C. But if you compile with -O2 it shouldnt be something 
to worry.

On 06/07/2011, at 18:51, Jacques-Pascal Deplaix  wrote:

> Hi everybody,
> 
> Why assignements in Vala make C code with multiples temporary variables ?
> It's not very good for the performances...
> I read codegen/valaccodeassignmentmodule.vala and I found this:
> 
> if (!is_pure_ccode_expression (lhs)) {
>/* Assign lhs to temp var to avoid repeating side effect */
>var lhs_value_type = assignment.left.value_type.copy ();
>string lhs_temp_name = "_tmp%d_".printf (next_temp_var_id++);
>var lhs_temp = new LocalVariable (lhs_value_type, "*" + lhs_temp_name);
>emit_temp_var (lhs_temp);
>ccode.add_assignment (get_variable_cexpression (lhs_temp_name), new 
> CCodeUnaryExpression (CCodeUnaryOperator.ADDRESS_OF, lhs));
> lhs = new CCodeParenthesizedExpression (new CCodeUnaryExpression 
> (CCodeUnaryOperator.POINTER_INDIRECTION, get_variable_cexpression 
> (lhs_temp_name)));
> }
> 
> What are the side effects corrected by the temporary variables ?
> ___
> vala-list mailing list
> vala-list@gnome.org
> http://mail.gnome.org/mailman/listinfo/vala-list
> 
___
vala-list mailing list
vala-list@gnome.org
http://mail.gnome.org/mailman/listinfo/vala-list