[Solved] Why does bullet use 16-bit alignment?

Post Reply
tal500
Posts: 5
Joined: Mon Nov 03, 2014 6:56 pm

[Solved] Why does bullet use 16-bit alignment?

Post by tal500 »

I really don't know the exact reason for this.
I know why alignment is good for fast memory read/write, but I don't know why to override the default alignment of the machine specific, and use 16 for everything.

This is seem to be also for mathematical structures, like Vector3.

Is this for proper serialization?
Does type-independent constant alignment yields performance possibilities?
Last edited by tal500 on Sat Nov 08, 2014 5:56 pm, edited 1 time in total.
Basroil
Posts: 463
Joined: Fri Nov 30, 2012 4:50 am

Re: Why does bullet use 16-bit alignment?

Post by Basroil »

Are you sure it's using 16bit rather than 16byte? Typically 16byte alignment is done because SIMD requires 16byte alignment, and I would assume bullet's 16byte alignment is done mainly for the same reason
tal500
Posts: 5
Joined: Mon Nov 03, 2014 6:56 pm

Re: Why does bullet use 16-bit alignment?

Post by tal500 »

Thanks for your answer.
Yes, I meant 16 bytes, my mistake.
After traveling in Intel site and many stack overflow topics, I found that there are two reasons for custom 16 byte alignment:
1. SIMD
2. Avoid cache misses.

For the 16 "magic" number reason, it's because of de-facto 16 byte optional requirement in today machines, and because it's also applied to the "old" 8-byte ones.
So 16 byte alignment makes an unofficial standard, which is very good of Bullet, I suppose.

Am I wrong?
Is there any other reasons for custom 16 byte alignment?
Basroil
Posts: 463
Joined: Fri Nov 30, 2012 4:50 am

Re: Why does bullet use 16-bit alignment?

Post by Basroil »

I don't think there's "custom" alignment at all, rather it has a portable allocator. What it does have is a method to let you pick the allocation (and alignment) method in case you use the code in other systems (PS3 is supported after all, and you can switch between malloc library and stdlib), as well as debug allocation to make sure there aren't any leaks.

I don't think you need to worry too much about it unless you are building off of bullet for your own physics.
tal500
Posts: 5
Joined: Mon Nov 03, 2014 6:56 pm

Re: Why does bullet use 16-bit alignment?

Post by tal500 »

Thanks, I think I understand this now.
Post Reply