You can use the `--emit-llvm` flag with rustc to check out the IR. To increase 
the optimisation amount, you can use `--opt-level LEVEL`, or just `-O` for an 
optimisation level of 2.

~Brendan

On 29/10/2013, at 6:00 AM, Rémi Fontan <[email protected]> wrote:

> Thanks.
> 
> I hope that llvm its capable optimizing the code,I wouldn't want an option 
> struct to be created each time I call this function.
> 
> What would be the way to verify that llvm did the job correctly?
> 
> Cheers
> 
> Remi
> 
> On Oct 28, 2013 11:12 PM, "Brendan Zabarauskas" <[email protected]> wrote:
> Yes, it's a static cast, so llvm should optimise that out.
> 
> Do note however that the API has changed in 0.9-pre, and num::cast now 
> returns an Option<T>. So your code would be:
> 
> ~~~
> let res: T = aVariable / num::cast(2).unwrap();
> ~~~
> 
> LLVM should resolve the conditional at statically - I haven't checked though.
> 
> ~Brendan
> 
> On 28/10/2013, at 8:26 PM, Rémi Fontan <[email protected]> wrote:
> 
>> Hi,
>> 
>> just checking performance wise, is num::cast() doing a dynamic type cast or 
>> a static cast.
>> 
>> I'm writing some template code that works on Real and I need sometime to 
>> divide T:Real by 2 or compate with 0 or 1.
>> 
>> I've been using num::zero() and num::one() so far but how about dividing by 
>> 2?
>> 
>> should I write something like this:
>> 
>> let two = num::one::<T>()+ num::one::<T>();
>> let res:T = aVariable / two;
>> 
>> or would be just as efficient?
>> let res:T = aVariable / num::cast::<float, T>(2.0);
>> 
>>  or is there an even better alternative?
>> 
>> with rust 0.8.
>> 
>> cheers,
>> 
>> Rémi
>> 
>> -- 
>> Rémi Fontan : [email protected]
>> mobile: +64 21 855 351
>> 93 Otaki Street, Miramar 6022
>> Wellington, New Zealand
>> _______________________________________________
>> Rust-dev mailing list
>> [email protected]
>> https://mail.mozilla.org/listinfo/rust-dev
> 

_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to