Forums > Dev

Little and big endian

July 7, 2006 | 1:46 pm

Hi,

I have some problem with coding my old external Sd2fregions with UB SDK. I load in a handle the ressource ‘ddrl from Sd2f file. (Yes, ressource in OS X is deprecead but, …).

code is here

err = LoadResForkFile( fileName, path, &sampRegionDataH, ‘ddRL’, 1000); // responsible for disposing of the Handle.
if (err) {
post( " SD2_GetSndRegions() : Error=%d Impossible to get the ‘ddRL’ resource !n", err);
return err;

}

// Get the number of regions.

sysmem_copyptr( *sampRegionDataH + 14 , &numberOfRgns, 4);//kNumbOfRgnsOffset
numberOfRgns = SWAP_32(numberOfRgns); // only for mac-intel

numberOfRgns = numberOfRgns – 1;

I have crated a macro SWAP_32 in Sd2fregionsand code is running. But how can I do when I will use my code in a ppc machine.

ifdef ?

Is there in cycling74 .h definition for do this ? I have see in byteorder. h code for double, 64 bit variable but not for long.

sorry for my bad english and my probably stupid question.

dominique ehret


July 7, 2006 | 2:07 pm

dominique ehret wrote:

> I have crated a macro SWAP_32 in Sd2fregionsand code is running. But how can I do when I will use my code in a ppc machine.
>
> ifdef ?

I recently came across a similar problem with defining a union… what I
did was:

#ifdef __ALTIVEC__
/* PPC code goes here */
#else
/* Windows and Intel Macs will do this */
#endif

Not really nice but it works. And note that I wasn’t even using Altivec,
it was just the first thing that came to my mind that doesn’t exist any
longer on Intel Macs.

Since the compiler more or less compiles two different versions of your
code, you don’t need any runtime check to determine which hardware
you’re on.

Olaf


July 7, 2006 | 6:32 pm

On Jul 7, 2006, at 7:07 AM, Olaf Matthes wrote:

>
> #ifdef __ALTIVEC__
> /* PPC code goes here */
> #else
> /* Windows and Intel Macs will do this */
> #endif
>
> Not really nice but it works. And note that I wasn’t even using
> Altivec, it was just the first thing that came to my mind that
> doesn’t exist any longer on Intel Macs.

You can use

#if (C74_LITTLE_ENDIAN)
// little endian code here
#else
// big endian code here
#endif

Or rely on the macros in ext_byteorder.h such as BYTEORDER_MSBW32(x),
which is a big endian 32bit integer macro.

Lastly, if you prefer, the Apple specific macro to detect endianness
at compile time is TARGET_RT_LITTLE_ENDIAN, which is probably a
preferable approach to using __ALTIVEC__ to detect the endianness of
the compiler target.

-Joshua


July 9, 2006 | 10:29 am

Hi,

thanks for reply. Yes, macro of byteorder.h do the job. UB SDK is a very nice work. I promise to read the Cycling74.h before posting.

Dominique Ehret


July 10, 2006 | 7:49 am

On 9 juil. 06, at 12:29, dominique ehret wrote:

> thanks for reply. Yes, macro of byteorder.h do the job. UB SDK is a
> very nice work. I promise to read the Cycling74.h before posting.

I didn’t discover these macro when I ported my object to UB neither but
discovered some OSX functions…

I defined the following macros (the names SWAP/NO_SWAP are from a big
endian point of vue)

#define SWAP_16 CFSwapInt16LittleToHost
#define SWAP_32 CFSwapInt32LittleToHost

#define NO_SWAP_16 CFSwapInt16BigToHost
#define NO_SWAP_32 CFSwapInt32BigToHost

With these CFSwap*toHost functions, I don’t have to check on what
processor the object is running. Of course, it is not compatible with
Win code, but I only need to define my SWAP functions in a Win
compatible way to get a portable code.

I don’t know if it’s a very efficient method, but for my object, I
don’t really care.

p

_____________________________
Patrick Delges

Centre de Recherches et de Formation Musicales de Wallonie asbl

http://users.skynet.be/crfmw/max


Viewing 5 posts - 1 through 5 (of 5 total)