>
> You can just hack in some code in SAFE_HEAP_LOAD/STORE to actually do 
> unaligned loads and stores. We could add an option for that, in fact.
>

Yeah that would be nice :).
 
In my case it doesn't really help though, since I can't avoid unaligned 
accesses. But there are only few places where unaligned access is possible 
so that's a special case for me. Luckily my described macro-based fix was 
enough to cover them all. I am not sure if the following is the fastest way 
to do it but that is what I am using to "align" unaligned accesses:


template<class T>
>
> inline T __read_aligned_internal(void* ptr)
>
> {
>
> auto bPtr = (byte*)ptr;
>
> T res = 0; 
>
> switch (sizeof(T))
>
> {
>
> case 2:
>
> res = (*bPtr) | (((T)*(bPtr+1)) << 8);
>
> break;
>
> case 4:
>
> res = (*bPtr) | (((T)*(bPtr+1)) << 8) | (((T)*(bPtr+2)) << 16) | 
>> (((T)*(bPtr+3)) << 24);
>
> break;
>
> default:
>
> throw "Unknown alignment.";
>
> }
>
> return res;
>
> }
>
>
>> template<class T>
>
> inline T __write_aligned_internal(void* ptr, T val)
>
> {
>
> auto bPtr = (byte*)ptr;
>
>
>> switch (sizeof(T))
>
> {
>
> case 2:
>
> (*bPtr) = val & 0xFF;
>
> (*(bPtr + 1)) = (val & 0xFF00) >> 8;
>
> break;
>
> case 4:
>
> (*bPtr) = val & 0xFF;
>
> (*(bPtr + 1)) = (val & 0xFF00) >> 8;
>
> (*(bPtr + 2)) = (val & 0xFF0000) >> 16;
>
> (*(bPtr + 3)) = (val & 0xFF000000) >> 24;
>
> break;
>
> default:
>
> throw "Unknown alignment.";
>
> }
>
>
>> return val;
>
> }
>
>
 

-- 
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.

Reply via email to