Comment

Comment by volta83

That conflicts.

Suppose you want to allocate 24 bytes and process them using SIMD instructions.

You call `aligned_alloc(24, 16)` to get a 24 byte allocation allocated to a 16 byte boundary.

Since the OS doesn't give the allocator 24 bytes, but whole memory pages, _it is valid_ for your program to read 32 bytes starting at the pointer returned, since that will never read out of the memory page in which this allocation resides.

This means that you can actually read the 24 bytes using 1 AVX instruction to read 32 bytes at once into a SIMD register, and do stuff with it (masking the uninitialized memory, etc.).

From those 32 bytes that you read, only the first 24 bytes might have been touched. That's a perfectly normal thing (e.g. you ask the allocator for 24 bytes, and it gives you a pointer to a 32 byte allocation, such that the last 8 bytes will never be touched by anyone).

parent volta83 5 years ago

Discussion

Live from the official Hacker News API

A modern reader for Hacker News · SvelteKit + Skeleton