Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
22 user(s) are online (15 user(s) are browsing Forums)

Members: 0
Guests: 22

more...

Support us!

Headlines

 
  Register To Post  

« 1 2 3 (4)
Re: A1222 support in the SDK and problems
Not too shy to talk
Not too shy to talk


See User information
I tried to link it with gcc 11.2 and 10.3, still receive allingnment error.
Next I will try pointers workaround.

@all, thanks for advice

AmigaOS3: Amiga 1200
AmigaOS4: Micro A1-C, AmigaOne XE, Pegasos II, Sam440ep, Sam440ep-flex, AmigaOne X1000
MorphOS: Efika 5200b, Pegasos I, Pegasos II, Powerbook, Mac Mini, iMac, Powermac Quad
Go to top
Re: A1222 support in the SDK and problems
Just can't stay away
Just can't stay away


See User information
@sailor

You could use a method similar to what has been used in m68k-amigaos C code to allocate long word aligned structures like FileInfoBlock from the stack:

static char align_buffer[3*sizeof(double)-1];
double *T1ptr;
double *T2ptr;
#define T1 (*T1ptr)
#define T2 (*T2ptr)

__attribute__((constructor))
static 
void __init_T1T2(void)
{
    
T1ptr = (double *)(((uintptr_t)align_buffer sizeof(double) - 1) & ~(sizeof(double) - 1));
    
T2ptr T1ptr 1;
}


If T1 and T2 were arrays instead of simple double variables you could even make use of C's pointer/array equivalence to get rid of the ugly macros.

Go to top
Re: A1222 support in the SDK and problems
Not too shy to talk
Not too shy to talk


See User information
@salass00
interesting idea - many thanks. For the first time I heard about constructor attribute. Looks nice, on weekend I will test.

Before you post this advice, I had in plan more dirty solution, something like:
double Tarray[3];
double *pT,*pT1;
pT= (double*)((long)(Tarray +1) - (long)(Tarray % 8));
pT1= pT+1;

Thx!


Edited by sailor on 2025/1/24 20:47:35
Edited by sailor on 2025/1/24 20:48:45
Edited by sailor on 2025/1/24 20:53:08
Edited by sailor on 2025/1/24 20:53:41
AmigaOS3: Amiga 1200
AmigaOS4: Micro A1-C, AmigaOne XE, Pegasos II, Sam440ep, Sam440ep-flex, AmigaOne X1000
MorphOS: Efika 5200b, Pegasos I, Pegasos II, Powerbook, Mac Mini, iMac, Powermac Quad
Go to top
Re: A1222 support in the SDK and problems
Not too shy to talk
Not too shy to talk


See User information
@salass00
thanks, it works nice!
For global vars and global arrys too.


Edited by sailor on 2025/1/25 12:58:29
Edited by sailor on 2025/1/25 12:58:47
AmigaOS3: Amiga 1200
AmigaOS4: Micro A1-C, AmigaOne XE, Pegasos II, Sam440ep, Sam440ep-flex, AmigaOne X1000
MorphOS: Efika 5200b, Pegasos I, Pegasos II, Powerbook, Mac Mini, iMac, Powermac Quad
Go to top
Re: A1222 support in the SDK and problems
Not too shy to talk
Not too shy to talk


See User information
@salass00Quote:
salass00 wrote:@sailor

You could use a method similar to what has been used in m68k-amigaos C code to allocate long word aligned structures like FileInfoBlock from the stack:

static char align_buffer[3*sizeof(double)-1];
double *T1ptr;
double *T2ptr;
#define T1 (*T1ptr)
#define T2 (*T2ptr)

__attribute__((constructor))
static 
void __init_T1T2(void)
{
    
T1ptr = (double *)(((uintptr_t)align_buffer sizeof(double) - 1) & ~(sizeof(double) - 1));
    
T2ptr T1ptr 1;
}


If T1 and T2 were arrays instead of simple double variables you could even make use of C's pointer/array equivalence to get rid of the ugly macros.


If I used single dimension array, as you said alignment is easy for array[A]:
static char align_buffer[(A+1)*sizeof(double)-1];
double *array;
__attribute__((constructor))
static 
void __init_array(void)
{
    array = (
double *)(((uintptr_t)align_buffer sizeof(double) - 1) & ~(sizeof(double) - 1));
}


And please, how it will work for multidimensional arrays - like array[A][B][C]? Should I use this?
static char align_buffer[(A*B*C+1)*sizeof(double)-1];
double (*array)[A][B][C];
__attribute__((constructor))
static 
void __init_array(void)
{
    array = (
double *)(((uintptr_t)align_buffer sizeof(double) - 1) & ~(sizeof(double) - 1));
}

and in the rest of code use normally array[a][b][c] ?

AmigaOS3: Amiga 1200
AmigaOS4: Micro A1-C, AmigaOne XE, Pegasos II, Sam440ep, Sam440ep-flex, AmigaOne X1000
MorphOS: Efika 5200b, Pegasos I, Pegasos II, Powerbook, Mac Mini, iMac, Powermac Quad
Go to top
Re: A1222 support in the SDK and problems
Just can't stay away
Just can't stay away


See User information
@sailor

I could be wrong but I don't think definining a pointer to a multi-dimensional array will work. In my experience multi-dimensional arrays in C are quite limited in how they can be used so I almost never use them in my code.

What should work however is something like (not quite as elegant):
static char align_buffer[(A*B*C+1)*sizeof(double)-1];
double *array[A][B];
__attribute__((constructor))
static 
void __init_array(void)
{
    
double *= (double *)(((uintptr_t)align_buffer sizeof(double) - 1) & ~(sizeof(double) - 1));
    
int ij;

    for (
0Ai++)
    {
        for (
0Bj++)
        {
            array[
i][j] = p;
            
+= C;
        }
    }
}

Go to top
Re: A1222 support in the SDK and problems
Just popping in
Just popping in


See User information
How can we get a fixed version of GCC to avoid all these workarounds/hacks?
Is there a guy able to fix it for a native version of GCC?

Memento audere semper!
Go to top
Re: A1222 support in the SDK and problems
Not too shy to talk
Not too shy to talk


See User information
@flash
native SPE version of gcc libraries will be fine, of course.
NXP had CodeWarrior IDE for SPE in past, but there were other compiller than gcc.
It will solve workarounds with float / double calls.

But global variable alignment error is probably directly in gcc - linking script error like salass00 said.

AmigaOS3: Amiga 1200
AmigaOS4: Micro A1-C, AmigaOne XE, Pegasos II, Sam440ep, Sam440ep-flex, AmigaOne X1000
MorphOS: Efika 5200b, Pegasos I, Pegasos II, Powerbook, Mac Mini, iMac, Powermac Quad
Go to top
Re: A1222 support in the SDK and problems
Home away from home
Home away from home


See User information
@sailor

static char align_buffer[3*sizeof(double)-1];


-1 ??


char does NOT add a extra 0\,
its not a string, so why do you want on less char?
a string is a class, not a array for chars.

GCC should automatilcy allign data, and you can use compiler options for it, "packed".

https://gcc.gnu.org/onlinedocs/gcc-4.0.1/gcc/Type-Attributes.html

(NutsAboutAmiga)

Basilisk II for AmigaOS4
AmigaInputAnywhere
Excalibur
and other tools and apps.
Go to top
Re: A1222 support in the SDK and problems
Not too shy to talk
Not too shy to talk


See User information
@LiveForItQuote:
LiveForIt wrote:@sailor
static char align_buffer[3*sizeof(double)-1];

-1 ??
char does NOT add a extra 0\,
its not a string, so why do you want on less char?
a string is a class, not a array for chars.

This is code from salass00 hint (see above). If I understand it correctly, "-1" is here to allocate only needed memory, not more:
allign_buffer should have size at least ( nr.of variables + 1 )*( sizeof(variable)) - we need to shift variable to correct aligned address.
If variable is not correctly alligned, is shifted of certain nr. of bytes ( i.e. maximally of var.size -1 ). Shifting of var.size have no sense, because it have the same alignment like original. Thus we allocated one byte less.
Of course, if var.size is less then 8 bytes, this shape should be corrected a little.
Quote:
GCC should automatilcy allign data, and you can use compiler options for it, "packed".

https://gcc.gnu.org/onlinedocs/gcc-4.0.1/gcc/Type-Attributes.html

Yes, in theory. Please, see post nr.53. Aligning not works always for global variables. In that case I need 8-byte alignment for experiments with SPE SIMD unit.
And this workaround helps me much.
This error is connected to gcc linker script ( see comment )

AmigaOS3: Amiga 1200
AmigaOS4: Micro A1-C, AmigaOne XE, Pegasos II, Sam440ep, Sam440ep-flex, AmigaOne X1000
MorphOS: Efika 5200b, Pegasos I, Pegasos II, Powerbook, Mac Mini, iMac, Powermac Quad
Go to top
Re: A1222 support in the SDK and problems
Just can't stay away
Just can't stay away


See User information
@LiveForIt

Quote:

its not a string, so why do you want on less char?


I'm not allocating one byte less, I'm allocating sizeof(double)-1 bytes more than needed. This is to ensure that a double (8-byte) aligned address of the required size can always be found within the aligned buffer no matter what the alignment of the array itself is.

Quote:

GCC should automatilcy allign data, and you can use compiler options for it, "packed".


It should but it doesn't.

Using my own compiled test code as example:

While the .data section itself is 16-byte aligned to the start of the executable file:
Section Headers:
  [
NrName              Type            Addr     Off    Size     
  
6] .ctors            PROGBITS        01011094 001094 000008 00  WA  0   0  4
  
7] .dtors            PROGBITS        010110900109000008 00  WA  0   0  4
  
8] .data             PROGBITS        010110b0 0010b0 000010 00  WA  0   0 16


it is preceeded in the segment by .ctors and .dtors sections which are only 4-byte aligned (see above):
Section to Segment mapping:
  
Segment Sections...
   
00     .text .rodata .__newlib_version 
   01     
.ctors .dtors .data .sbss


The result is that when elf.library loads the entire segment 32-byte aligned the .data section gets loaded into it at offset 10b0-1094=1c which is only 4-byte aligned.

Go to top
Re: A1222 support in the SDK and problems
Just can't stay away
Just can't stay away


See User information
@LiveForIt
Quote:
GCC should automatilcy allign data, and you can use compiler options for it, "packed".
"packed" (__attribute__, #pragma, etc.) can only be used to reduce alignment, for example from 4 bytes integer default on PPC to 2 bytes (for compatibility to m68k, as used in most exec, etc. includes), but not to increase alignment.

@salass00
Quote:
The result is that when elf.library loads the entire segment 32-byte aligned the .data section gets loaded into it at offset 10b0-1094=1c which is only 4-byte aligned.
Still sounds like a linker script bug to me, missing or wrong align for .ctors/.dtors, not a bug in gcc, binutils (ld) nor elf.library.
However the last time I worked on it in the AmigaOS 4.x ports was IIRC gcc 2.95.x/binutils 2.14.x versions, i.e. about 20 years ago...


Edited by joerg on 2025/2/5 18:59:54
Go to top
Re: A1222 support in the SDK and problems
Amigans Defender
Amigans Defender


See User information
We'll take care of it

i'm really tired...
Go to top
Re: A1222 support in the SDK and problems
Just popping in
Just popping in


See User information
So someone could try to compile and assemble SPE code with native GCC 4 and link objects with GCC 11.
If problem rely on linker, and if it's a text file it could be easily fixed with a diff between GCC4 and GCC11 linker cfg text files

Memento audere semper!
Go to top

  Register To Post
« 1 2 3 (4)

 




Currently Active Users Viewing This Thread: 1 ( 0 members and 1 Anonymous Users )




Powered by XOOPS 2.0 © 2001-2024 The XOOPS Project