the address returned from "new" statement is 32 bit aligned?

A

Asm23

Hi
i'm using intel P4.

when I write the statement like
char *p=new char[512]

what's the p value, is it aligned by 4 bytes? that's is p%4==0?
and, now I'm using the Intel SSE2 instruction to do some fast
algorthm, some instructions I need to move data from memory to XMM0
registers(which is 128 bits) should be be aligned on 16-byte
boundaries.

so, how can use these Instructions when I should take some operations
on data just "new" on the heap. Is there any suggestions to solve this
problems? thanks
 
E

Erik Wikström

Hi
i'm using intel P4.

when I write the statement like
char *p=new char[512]

what's the p value, is it aligned by 4 bytes? that's is p%4==0?

Platform/implementation specific, and therefore off topic in this group,
you could try asking in a group for your compiler/OS/platform.
and, now I'm using the Intel SSE2 instruction to do some fast
algorthm, some instructions I need to move data from memory to XMM0
registers(which is 128 bits) should be be aligned on 16-byte
boundaries.

I do not know how you use these instructions but I seem to recall that
there were special functions/instructions for putting data in special
128 bit data-types which will be operated on.
 
A

Asm23

Hi
i'm using intel P4.
when I write the statement like
char *p=new char[512]
what's the p value, is it aligned by 4 bytes? that's is p%4==0?

Platform/implementation specific, and therefore off topic in this group,
you could try asking in a group for your compiler/OS/platform.
and, now I'm using the Intel SSE2 instruction to do some fast
algorthm, some instructions I need to move data from memory to XMM0
registers(which is 128 bits) should be be aligned on 16-byte
boundaries.

I do not know how you use these instructions but I seem to recall that
there were special functions/instructions for putting data in special
128 bit data-types which will be operated on.

thanks, Erik, I have some answers on some visual studio forums, thanks
again for your help.

there is really some single instruction with SSE2 which could move
128bit data from memory to regsiter like XMM0.
 
R

Ron Natalie

Asm23 said:
Hi
i'm using intel P4.

when I write the statement like
char *p=new char[512]

what's the p value, is it aligned by 4 bytes? that's is p%4==0?

You'll have to look at the implementation (which you obviously are
if you're interfacing to assembler).

What the standard does guarantee is that
new char[X]

returns a piece of memory that is suitably aligned for any time
whose size is less than or equal to X.

Of course the Pentium doesn't have any real strict alignment
for any types, most compilers treat it as if they did for
some types such as double for efficiency.

I would guess (you'd have to experiment) that 4 byte alignment
is provided. Your other option would be to write your own
allocator.
 
A

Asm23

Asm23 said:
Hi
i'm using intel P4.
when I write the statement like
char *p=new char[512]
what's the p value, is it aligned by 4 bytes? that's is p%4==0?

You'll have to look at the implementation (which you obviously are
if you're interfacing to assembler).

What the standard does guarantee is that
        new char[X]

returns a piece of memory that is suitably aligned for any time
whose size is less than or equal to X.

Of course the Pentium doesn't have any real strict alignment
for any types, most compilers treat it as if they did for
some types such as double for efficiency.

I would guess (you'd have to experiment) that 4 byte alignment
is provided.  Your other option would be to write your own
allocator.

Thanks Ron, I can solve my problems, here are the steps:
assume we want to get some buffer aligned by Y.
1, char *p=new char[X]
2, than exam the value of p, if p is not aligned by Y, I could use
char *q=p+d, which q is some deviation that make q is aligned by Y.

....

Last: delete[] p;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,142
Latest member
DewittMill
Top