Thanks Alon. This is clear to me now. On Monday, August 18, 2014 1:12:00 AM UTC+8, Alon Zakai wrote: > > It does divide it by 4, which is necessary because of how typed arrays > work. If HEAP32 aliases HEAP8, then HEAP32[0] refers to bytes 0,1,2,3 as a > single 32-bit integer, and HEAP32[1] refers to bytes 4,5,6,7, and so forth. > That means that if you are given a pointer to a 32-bit integer at memory > address 4, you need to access it using HEAP32[1] === HEAP32[4>>2]. > > - Alon > > > > On Sun, Aug 17, 2014 at 9:17 AM, awt <[email protected] <javascript:>> > wrote: > >> Hi, >> >> I read in the asm.js specs that: >> >> As an example of the former, if we have an Int32Array >> <https://developer.mozilla.org/en-US/docs/JavaScript/Typed_arrays/Int32Array> >> view of the heap called HEAP32, then we can load the 32-bit integer at >> byte offset p: >> >> HEAP32[p >> 2]|0 >> >> The shift converts the byte offset to a 32-bit element offset, and the >> bitwise coercion ensures that an out-of-bounds access is coerced from >> undefined back to an integer. >> >> I understand that performing a bitwise operation will perform an integer >> coercion but why do we shift it 2 bits for a 32bit integer? Similarly, I >> notice that we shift it by 1 bit for a 16 bit short in cpp. Doesn't a shift >> of 2 bits divide the value of p by 4? >> >> -- >> You received this message because you are subscribed to the Google Groups >> "emscripten-discuss" group. >> To unsubscribe from this group and stop receiving emails from it, send an >> email to [email protected] <javascript:>. >> For more options, visit https://groups.google.com/d/optout. >> > >
-- You received this message because you are subscribed to the Google Groups "emscripten-discuss" 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.
