Ernst-Georg Schmid <eschmid@blackbeauty.de> wrote in
news:70ai8a.31kb1.ln@ID-53885.user.dfncis.de:
Hello,
i need to align an array of float to a 16 Byte boundary in qcc/gcc to
pass it to an assembler Function that expects such alignement.
I’ve tried it with:
float attribute ((aligned(16))) tmpa[16] =
{4.0,2.0,5.0,9.0,2.0,3.51,0.0,11.0,1.0,0.0,0.0,0.0,0.0,0.0,0.0,0.0};
but this doesn’t seem to work as explained in the gcc docs (no
alignment is done)?
If i try it with a struct, it works as expected, but the docs say it
should work with simple variables and arrays also. I post this here,
because at the moment, i can’t figure out if this is a general gcc
issue/bug/feature or special to the QNX compiler.
regards,
Ernst-Georg
Inserted below is my saved file of an earlier discussion about
alignment. Hope it helps:
ewsgroups: qdn.public.qnxrtp.os
Subject: Re: dynamic allocation of aligned buffer
From: Donna Kinsman <dkinsman@qnx.com>
Date: 20 Dec 2001 13:47:31 GMT
posix_memalign() will be doc’d for 6.2.0…
Although there’s more doc work to be done,
here’s what we’ve got so far:
posix_memalign() Allocate aligned memory
Synopsis:
#include <stdlib.h>
int posix_memalign( void ** memptr,
size_t alignment,
size_t size );
Library:
libc
Description:
The posix_memalign() function allocates size bytes aligned on a
boundary specified by alignment.
It returns a pointer to the allocated memory in memptr.
The value of alignment must be a multiple of size(void*).
Returns:
0 Success.
-1 An error occurred (errno is set).
Errors:
EINVAL The value of alignment isn’t a multiple of size( void
*).
ENOMEM There’s insufficient memory available with the requested
alignment.
Classification:
POSIX
Safety:
Cancellation point No
Interrupt handler No
Signal handler Yes
Thread Yes
See also:
errno, free(), malloc()
Andray Kaganovsky wrote:
is there library routine that would allow me to allocate
buffer of
‘size’ bytes aligned at ‘alignment’ boundary (for example,
512 bytes buffer aligned at 4 byte boundary) ? Both’size’
and ‘alignment’ are powers of 2.
If I want to align pointer upward to ‘alignment’ boundary
(where
‘alignment’ is power of 2), is this the reliable way to do it:
#define ALIGN_PTR_UPWARD(p,alignment)
((void *) ((char *)p + ((int)p % alignment)))
Newsgroups: qdn.public.qnxrtp.os
Subject: Re: dynamic allocation of aligned buffer
From: “Operating Systems Group” <os@qnx.com>
Date: Wed, 2 Jan 2002 10:58:29 -0500
“Davide Ancri” <davidea@prisma-eng.it> wrote in message
news:3C32D754.87B8E285@prisma-eng.it…
Can I assume the buffer allocated by posix_memalign() is
contiguous in
physical memory?
No, it would be contiguous in the virtual address space, not the
physical
one. Of course if the amount is under 4K, you could make an
assumption it’s
physically contiguous (since physical memory is used in pages
size hunks)
but I would tend to avoid that assumption, since other platforms
(or future
systems) may not do 4K page sizes.
Which is the best way to obtain the physical memory address of
the
allocated buffer?
You can get the physical address of the start of the buffer using
mem_offset() with fd=NOFD.
-Adam
\
Bob Bottemiller
Stein.DSI
Redmond, WA USA