Login
Username:

Password:

Remember me



Lost Password?

Register now!

Sections

Who's Online
55 user(s) are online (31 user(s) are browsing Forums)

Members: 0
Guests: 55

more...

Headlines

 
  Register To Post  

« 1 (2)
Re: Integer in source code
Home away from home
Home away from home


See User information
@KimmoK

your code is not uniendian friendly!

for uniendian try this:

typedef long long int int64;
typedef unsigned long long int uint64;

#define get_high32(var) (uint32) ( var>>32 )
#define get_low32(var) (uint32) ( var & 0xFFFFFFFF ) 
#define set_high32( var, value) var = ((uint64) value<<32 ) | (var & 0xFFFFFFFF)
#define set_low32( var, value) var = ((var & 0xFFFFFF000000) | (uint64) value)


Anyway you should not declare uint64 and int64, this are already defined in types.h


You might consider using symbols, if you do:
GCC on Mac defines __LITTLE_ENDIAN__ or __BIG_ENDIAN__

If does not work on AmigaOS, you can send symbols whit option -D on the command line.
gcc my_src.c -o my_exe -D__USE_INLINE__ -D__BIG_ENDIEN__

#ifdef __BIG_ENDIAN__
#define get_high32(var) ((uint32 *) & var) [0]
#define get_low32(var) ((uint32 *) & var) [1]
#define set_high32( var, value) ((uint32 *) & var) [0] = value
#define set_low32( var, value) ((uint32 *) & var) [1] = value
#endif

#ifdef __LITTLE_ENDIAN__
#define get_high32(var) ((uint32 *) & var) [1]
#define get_low32(var) ((uint32 *) & var) [0]
#define set_high32( var, value) ((uint32 *) & var) [1] = value
#define set_low32( var, value) ((uint32 *) & var) [0] = value
#endif


(This macros should work, I have not tested.)


http://stackoverflow.com/questions/21 ... -or-little-endian-machine


Edited by LiveForIt on 2012/9/24 17:00:19
Edited by LiveForIt on 2012/9/24 17:06:07
Edited by LiveForIt on 2012/9/24 17:56:28
Edited by LiveForIt on 2012/9/24 19:22:30
Edited by LiveForIt on 2012/9/24 20:22:24
Edited by LiveForIt on 2012/9/24 20:25:08
Edited by LiveForIt on 2012/9/24 20:46:16
Edited by LiveForIt on 2012/9/24 23:57:06
(NutsAboutAmiga)

Basilisk II for AmigaOS4
AmigaInputAnywhere
Excalibur
and other tools and apps.
Go to top
Re: Integer in source code
Home away from home
Home away from home


See User information
64bit on 32bit PowerPC cpu.

v64 0;

 
1000268:       39 20 00 00     li      r9,0
 100026c
:       39 40 00 00     li      r10,0
 1000270
:       91 3f 00 08     stw     r9,8(r31)
 
1000274:       91 5f 00 0c     stw     r10,12(r31)

v64+=1000;

 
1000278:       81 3f 00 08     lwz     r9,8(r31)
 
100027c:       81 5f 00 0c     lwz     r10,12(r31)
 
1000280:       31 4a 03 e8     addic   r10,r10,1000
 1000284
:       7d 29 01 94     addze   r9,r9
 1000288
:       91 3f 00 08     stw     r9,8(r31)
 
100028c:       91 5f 00 0c     stw     r10,12(r31)


32bit on 64bit and 32bit PowerPC cpu (upper bits are zero on 64bit)

v32 0;

 
1000290:       38 00 00 00     li      r0,0
 1000294
:       90 1f 00 10     stw     r0,16(r31)

v32+=1000;

 
1000298:       81 3f 00 10     lwz     r9,16(r31)
 
100029c:       38 09 03 e8     addi    r0,r9,1000
 10002a0
:       90 1f 00 10     stw     r0,16(r31)


(NutsAboutAmiga)

Basilisk II for AmigaOS4
AmigaInputAnywhere
Excalibur
and other tools and apps.
Go to top
Re: Integer in source code
Quite a regular
Quite a regular


See User information
Quote:

LiveForIt wrote:
Way is this important:

int cnt;
For (cnt=0;cnt<10;cnt++) {
}

does not use the register as count but stores the value in a memory address, so the number of bits on outside of processor is probably more important than the number of bits in the registers.

Anyway if really wont the compiler to optimize for using registers.


That depends on the code and the target CPU. If there is no reference to variable and free registers in the loop it will be put in a register and written back to memory after the loop, if necessary.

On the contrary if you really need it in memory you will have to declare it volatile. The PPC has a lot of registers. Make no sense not to use them all all the time.

I think I read somewhere that the register directive have no meaning, or at best is a hint to the compiler on PPC, or was it GCC.

Software developer for Amiga OS3 and OS4.
Develops for OnyxSoft and the Amiga using E and C and occasionally C++
Go to top
Re: Integer in source code
Home away from home
Home away from home


See User information
@Deniil

Be careful "register" keyword is strong, the compiler quicly removes every thing, if GCC find out your not going to save the values.

yes its a "hint" to the compiler if you abuse it most likely wont work, but as you see it does cut down a allot when it works.

Easy to test if compile your code whit --ggdb flag and the use objdump to see what result is.

register int v32;
        
register long long int v64;

        
v64 0;
 
1000270:       39 20 00 00     li      r9,0
 1000274
:       39 40 00 00     li      r10,0

        v64
+=1000;
 
1000278:       31 4a 03 e8     addic   r10,r10,1000
 100027c
:       7d 29 01 94     addze   r9,r9

        v32 
0;
 
1000280:       39 00 00 00     li      r8,0

        v32
+=1000;
 
1000284:       39 08 03 e8     addi    r8,r8,1000


(But if you use optimization flags it might be done automaticly.)

32 registers becomes 16 when you have lot of 64bit variables on 32bit CPU
some registers are reserved like r1 (stack pointer).

http://www.ibm.com/developerworks/linux/library/l-powarch/

Well PowerPC has many registers, and many special registers like CTR that is reserved for loop, and branches, maybe this what your where thinking about?


Edited by LiveForIt on 2012/9/25 0:28:24
Edited by LiveForIt on 2012/9/25 0:38:34
Edited by LiveForIt on 2012/9/25 8:39:50
(NutsAboutAmiga)

Basilisk II for AmigaOS4
AmigaInputAnywhere
Excalibur
and other tools and apps.
Go to top

  Register To Post
« 1 (2)

 




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




Powered by XOOPS 2.0 © 2001-2023 The XOOPS Project