[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [MiNT] Alignment 2
Frank Naumann wrote:
The kernel manage big memory chunks, e.g. the
smallest block you get from kernel by Mxalloc() is the system page size
(8 kb [except 68000 CPU where it is 512 byte]).
I don't looked at the code but I would assume that the Pexec loader load
the code aligned into the memory block (the memory block is page aligned
for sure).
He he... The BASEPAGE is aligned on a memory block. The text segment is
256 bytes further... so it is only aligned on a 256 byte boundary !
Anyway, it is far enough :-)
I made some tests with the attached program, in order to determine the
worst (lower) alignment where the OS loads the .text segment.
Here are the results:
Real Atari STe with TOS 1.62: 2
ARAnyM with TOS 4.04 (without MiNT): 4
ARAnyM with FreeMiNT: 256
So the conclusion is:
On the ST: alignment to more than 2 will not be respected by the OS.
Furthermore, it would be useless for the 68000 CPU. So, definitely, the
good alignment for the ST target is 2 bytes (not a real surprise :-) )
On the Falcon: alignment of 4 will be respected by the OS. Such
alignment is useless for the standard hardware, but it is faster when
using an accelerator card with FastRAM.
So we should have 2 configurations for our development tools for optimal
size and performance :
"Optimized for ST": -m68000, no FPU, alignment on 2
"Optimized for Falcon": -m68020-60, with FPU, alignment on 4
That would be good.
--
Vincent Rivière
/* pralign.c
* By Vincent Riviere, 2008
*
* Compile with:
* gcc -O2 -s -Wl,--mno-altram,--mno-altalloc -s pralign.c -o pralign.tos
*
* This program displays the alignment of the current .text segment.
* Then it Malloc's a buffer of different sizes, and it runs itself again.
*
* The purpose is to determine the worst possible .text alignment on a given system.
*/
#include <stdio.h>
#include <mint/basepage.h>
#include <mint/osbind.h>
int get_alignment(void* p)
{
unsigned long adr = (unsigned long)p;
int alignment = 1;
if (p == NULL)
return 32;
while (!(adr & 1))
{
alignment *= 2;
adr >>= 1;
}
return alignment;
}
int main(int argc, char* argv[])
{
unsigned long fillsize;
void* filler;
printf("text = 0x%08lx, align = %d\n", _base->p_tbase, get_alignment(_base->p_tbase));
if (argc > 1)
return 0;
for (fillsize = 1; fillsize <= 256*1024; fillsize += 2)
{
filler = (void*)Malloc(fillsize + 2);
if (filler == NULL)
{
puts("Out of memory");
return 1;
}
Pexec(0, "PRALIGN.TOS", "norecurse", NULL);
Mfree(filler);
}
return 0;
}