(2014/08/11 21:50), P8 wrote:
> I have been trying to find good references how V8 uses small ints and I
> hope someone here can give me some pointers or at least answers to these
> couple of questions:

Not sure if there are good references about this...

> 1) When does it store a number to memory as a direct 31-bit int instead
> of a (double) reference? Does it work only for constant values or
> calculation results as well under some conditions?

Latter. Mostly for '*', '+' and '-' when that calculation doesn't
overflow to non-31/32-bit numbers and for '\' when the result is an
integer. (By the way, for 64-bit systems, SMIs are 32-bits).

> Can I instruct it to do that by for example using an AND mask or
> right shift that guarantees 31-bit result?

You don't have to. It's pretty much automatic.

> 2) Which math operations can I use for such numbers so that it doesn't
> convert the (intermediate) results to double? For example, if I subtract
> or multiply a couple of variables that contain SMIs and AND the result
> with some mask, does it perform type conversions for that subtraction or
> multiplication or keep the whole calculation as SMIs?

You don't have to. It's pretty much automatic as long as the result is
representable in SMI.

I don't think there's any good "optimization" you can do with SMIs (on
the other hand, there are hints with hidden classes). The only thing to
keep in mind is to avoid non-31/32-bit integers, which are rare in a
normal application anyway, and non-integers if you can.


Cheers,
Kenny

-- 
-- 
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
--- 
You received this message because you are subscribed to the Google Groups 
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to