Determining the CPU Endianness!

Hello All

How do I determine the CPU endianness of the processor in which my code
runs?
Basically RTL functions swap LE to BE and viceversa. But how do i determine
when
to swap or when not to swap? I was going through windows.h. there are a few
defines
like MPPC, 68K, _M_ALPHA, _M_IX86 etc. Will _M_IX86 be defined for all
x86 CPUs (irrespective of PENTIUM, PENTIUM2 etc.)?

Could anybody give any pointers on this?

Thanks
Venky


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

How about this:

// Compute CPU Endianness
i = 1;
if ( *((unsigned char *) (&i)) == (unsigned char)1 )
CPU_Endianness = LE;
else
CPU_Endianness = BE;

Niraj

-----Original Message-----
From: Varadan Venkatesh [mailto:xxxxx@tataelxsi.co.in]
Sent: Thursday, May 10, 2001 12:27 AM
To: NT Developers Interest List
Subject: [ntdev] Determining the CPU Endianness!

Hello All

How do I determine the CPU endianness of the processor in which my code
runs?
Basically RTL functions swap LE to BE and viceversa. But how do i determine
when
to swap or when not to swap? I was going through windows.h. there are a few
defines
like MPPC, 68K, _M_ALPHA, _M_IX86 etc. Will _M_IX86 be defined for all
x86 CPUs (irrespective of PENTIUM, PENTIUM2 etc.)?

Could anybody give any pointers on this?

Thanks
Venky


You are currently subscribed to ntdev as: xxxxx@netapp.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

void main()
{
union {
DWORD a;
CHAR b[4];
} x;
x.a = 0x12345678;
for (int j = 0; j < 4; j++)
printf ("%02x ", x.b[j]);
}

-----Original Message-----
From: Varadan Venkatesh
To: NT Developers Interest List
Date: Thursday, May 10, 2001 11:37 AM
Subject: [ntdev] Determining the CPU Endianness!

>Hello All
>
>How do I determine the CPU endianness of the processor in which my code
>runs?
>Basically RTL functions swap LE to BE and viceversa. But how do i determine
>when
>to swap or when not to swap? I was going through windows.h. there are a few
>defines
>like MPPC, 68K, _M_ALPHA, _M_IX86 etc. Will _M_IX86 be defined for all
>x86 CPUs (irrespective of PENTIUM, PENTIUM2 etc.)?
>
>Could anybody give any pointers on this?
>
>Thanks
>Venky
>
>
>—
>You are currently subscribed to ntdev as: xxxxx@bigfoot.com
>To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com
>


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Here is a quick ENDIAN detection fragment:

BOOLEAN UTIL_IsBigEndian()
{
static USHORT _I_ENDIAN_TEST = 0xFF00;

return( *(PUCHAR )&_I_ENDIAN_TEST );
}

Good luck,

Thomas F. Divine

PCAUSA - Toolkits & Resources For Network Software Developers
NDIS Protocol - NDIS Intermediate - TDI Client
http: - http:

----- Original Message -----
From: Jacob
To: NT Developers Interest List
Sent: Thursday, May 10, 2001 11:44 AM
Subject: [ntdev] Re: Determining the CPU Endianness!

> void main()
> {
> union {
> DWORD a;
> CHAR b[4];
> } x;
> x.a = 0x12345678;
> for (int j = 0; j < 4; j++)
> printf ("%02x ", x.b[j]);
> }
>
> -----Original Message-----
> From: Varadan Venkatesh
> To: NT Developers Interest List
> Date: Thursday, May 10, 2001 11:37 AM
> Subject: [ntdev] Determining the CPU Endianness!
>
>
> >Hello All
> >
> >How do I determine the CPU endianness of the processor in which my code
> >runs?
> >Basically RTL functions swap LE to BE and viceversa. But how do i
determine
> >when
> >to swap or when not to swap? I was going through windows.h. there are a
few
> >defines
> >like MPPC, 68K, _M_ALPHA, _M_IX86 etc. Will _M_IX86 be defined for
all
> >x86 CPUs (irrespective of PENTIUM, PENTIUM2 etc.)?
> >
> >Could anybody give any pointers on this?
> >
> >Thanks
> >Venky
> >


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com</http:></http:>

Pardon me for demonstrating my ignorance here, isn’t the endianness of your
hardware known at compile time? Is there any ISA on which NT is supported
that can be big- or little-endian? In other words, is it even possible to
produce a binary for NT that can run on systems with both endiannesses
without modification?

Thanks for educating me,

Phil

-----Original Message-----
From: Thomas F. Divine [mailto:xxxxx@pcausa.com]
Sent: Thursday, May 10, 2001 9:10 AM
To: NT Developers Interest List
Subject: [ntdev] Re: Determining the CPU Endianness!

Here is a quick ENDIAN detection fragment:

BOOLEAN UTIL_IsBigEndian()
{
static USHORT _I_ENDIAN_TEST = 0xFF00;

return( *(PUCHAR )&_I_ENDIAN_TEST );
}

Good luck,

Thomas F. Divine

PCAUSA - Toolkits & Resources For Network Software Developers
NDIS Protocol - NDIS Intermediate - TDI Client
http: - http:

----- Original Message -----
From: Jacob
To: NT Developers Interest List
Sent: Thursday, May 10, 2001 11:44 AM
Subject: [ntdev] Re: Determining the CPU Endianness!

> void main()
> {
> union {
> DWORD a;
> CHAR b[4];
> } x;
> x.a = 0x12345678;
> for (int j = 0; j < 4; j++)
> printf ("%02x ", x.b[j]);
> }
>
> -----Original Message-----
> From: Varadan Venkatesh
> To: NT Developers Interest List
> Date: Thursday, May 10, 2001 11:37 AM
> Subject: [ntdev] Determining the CPU Endianness!
>
>
> >Hello All
> >
> >How do I determine the CPU endianness of the processor in which my code
> >runs?
> >Basically RTL functions swap LE to BE and viceversa. But how do i
determine
> >when
> >to swap or when not to swap? I was going through windows.h. there are a
few
> >defines
> >like MPPC, 68K, _M_ALPHA, _M_IX86 etc. Will _M_IX86 be defined for
all
> >x86 CPUs (irrespective of PENTIUM, PENTIUM2 etc.)?
> >
> >Could anybody give any pointers on this?
> >
> >Thanks
> >Venky
> >


You are currently subscribed to ntdev as: xxxxx@intel.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com</http:></http:>

Varadan Venkatesh wrote:

Hello All

How do I determine the CPU endianness of the processor in which my
code runs?

All Intel x86/Pentium/PII/PIII family CPUs are little endian, as are
all of the x86 clones, such as the AMD CPUs.

All non-x86 CPUs (MIPS, PowerPC, and Alpha) are set to little endian
mode to run Windows NT. Windows 2000 and XP no longer support these
CPUs.

Although I haven’t actually checked, I have to believe that the IA64
is also little endian (or either endian and set to little endian to
run Whistler).

Therefore, if you are running Windows (any variant), you are ALWAYS
executing little endian. I do not believe that there are any
exceptions to this.

Now, if you are off in unix/linux land, then all bets are off… but
if you are writing Windows code, you will always be executing in a
little endian environment.

  • Jay


Jay Talbott
Staff Software Engineer
Motorola Computer Group
2900 S. Diablo Way
DW220
Tempe, AZ 85282
(602) 438-3481
xxxxx@mcg.mot.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

You might be communicating with hardware that has different endianess.

Mark Roddy
xxxxx@hollistech.com
www.hollistech.com
603 321 1032
WindowsNT Windows 2000 Consulting Services

-----Original Message-----
From: Barila, Phil [mailto:xxxxx@intel.com]
Sent: Thursday, May 10, 2001 12:44 PM
To: NT Developers Interest List
Subject: [ntdev] Re: Determining the CPU Endianness!

Pardon me for demonstrating my ignorance here, isn’t the endianness of your
hardware known at compile time? Is there any ISA on which NT is supported
that can be big- or little-endian? In other words, is it even possible to
produce a binary for NT that can run on systems with both endiannesses
without modification?

Thanks for educating me,

Phil

-----Original Message-----
From: Thomas F. Divine [mailto:xxxxx@pcausa.com]
Sent: Thursday, May 10, 2001 9:10 AM
To: NT Developers Interest List
Subject: [ntdev] Re: Determining the CPU Endianness!

Here is a quick ENDIAN detection fragment:

BOOLEAN UTIL_IsBigEndian()
{
static USHORT _I_ENDIAN_TEST = 0xFF00;

return( *(PUCHAR )&_I_ENDIAN_TEST );
}

Good luck,

Thomas F. Divine

PCAUSA - Toolkits & Resources For Network Software Developers
NDIS Protocol - NDIS Intermediate - TDI Client
http: - http:

----- Original Message -----
From: Jacob
To: NT Developers Interest List
Sent: Thursday, May 10, 2001 11:44 AM
Subject: [ntdev] Re: Determining the CPU Endianness!

> void main()
> {
> union {
> DWORD a;
> CHAR b[4];
> } x;
> x.a = 0x12345678;
> for (int j = 0; j < 4; j++)
> printf ("%02x ", x.b[j]);
> }
>
> -----Original Message-----
> From: Varadan Venkatesh
> To: NT Developers Interest List
> Date: Thursday, May 10, 2001 11:37 AM
> Subject: [ntdev] Determining the CPU Endianness!
>
>
> >Hello All
> >
> >How do I determine the CPU endianness of the processor in which my code
> >runs?
> >Basically RTL functions swap LE to BE and viceversa. But how do i
determine
> >when
> >to swap or when not to swap? I was going through windows.h. there are a
few
> >defines
> >like MPPC, 68K, _M_ALPHA, _M_IX86 etc. Will _M_IX86 be defined for
all
> >x86 CPUs (irrespective of PENTIUM, PENTIUM2 etc.)?
> >
> >Could anybody give any pointers on this?
> >
> >Thanks
> >Venky
> >


You are currently subscribed to ntdev as: xxxxx@intel.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: xxxxx@stratus.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com</http:></http:>

CPU endianess is relevant to networking code. The sender protocol stack and
receiving protocol stack must agree on a format . Internet protocols uses
big endian for this , so such a code must be aware by CPU endianess to
corectly build a TCP packet for example. Thats one of the cases then CPU
endianess is important.

----- Original Message -----
From: “Barila, Phil”
To: “NT Developers Interest List”
Sent: Thursday, May 10, 2001 7:44 PM
Subject: [ntdev] Re: Determining the CPU Endianness!

> Pardon me for demonstrating my ignorance here, isn’t the endianness of
your
> hardware known at compile time? Is there any ISA on which NT is supported
> that can be big- or little-endian? In other words, is it even possible to
> produce a binary for NT that can run on systems with both endiannesses
> without modification?
>
> Thanks for educating me,
>
> Phil
>
> -----Original Message-----
> From: Thomas F. Divine [mailto:xxxxx@pcausa.com]
> Sent: Thursday, May 10, 2001 9:10 AM
> To: NT Developers Interest List
> Subject: [ntdev] Re: Determining the CPU Endianness!
>
>
> Here is a quick ENDIAN detection fragment:
>
>
> BOOLEAN UTIL_IsBigEndian()
> {
> static USHORT _I_ENDIAN_TEST = 0xFF00;
>
> return( *(PUCHAR )&_I_ENDIAN_TEST );
> }
>
> Good luck,
>
> Thomas F. Divine
>
> PCAUSA - Toolkits & Resources For Network Software Developers
> NDIS Protocol - NDIS Intermediate - TDI Client
> http: - http:
>
>
> ----- Original Message -----
> From: Jacob
> To: NT Developers Interest List
> Sent: Thursday, May 10, 2001 11:44 AM
> Subject: [ntdev] Re: Determining the CPU Endianness!
>
>
> > void main()
> > {
> > union {
> > DWORD a;
> > CHAR b[4];
> > } x;
> > x.a = 0x12345678;
> > for (int j = 0; j < 4; j++)
> > printf ("%02x ", x.b[j]);
> > }
> >
> > -----Original Message-----
> > From: Varadan Venkatesh
> > To: NT Developers Interest List
> > Date: Thursday, May 10, 2001 11:37 AM
> > Subject: [ntdev] Determining the CPU Endianness!
> >
> >
> > >Hello All
> > >
> > >How do I determine the CPU endianness of the processor in which my code
> > >runs?
> > >Basically RTL functions swap LE to BE and viceversa. But how do i
> determine
> > >when
> > >to swap or when not to swap? I was going through windows.h. there are a
> few
> > >defines
> > >like MPPC, 68K, _M_ALPHA, _M_IX86 etc. Will _M_IX86 be defined for
> all
> > >x86 CPUs (irrespective of PENTIUM, PENTIUM2 etc.)?
> > >
> > >Could anybody give any pointers on this?
> > >
> > >Thanks
> > >Venky
> > >
>
>
>
> —
> You are currently subscribed to ntdev as: xxxxx@intel.com
> To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com
>
>
> —
> You are currently subscribed to ntdev as: danp@jb.rdsor.ro
> To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com
>


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com</http:></http:>

----- Original Message -----
From: Barila, Phil
To: NT Developers Interest List
Sent: Thursday, May 10, 2001 12:44 PM
Subject: [ntdev] Re: Determining the CPU Endianness!

> Pardon me for demonstrating my ignorance here, isn’t the endianness of
your
> hardware known at compile time? Is there any ISA on which NT is supported
> that can be big- or little-endian? In other words, is it even possible to
> produce a binary for NT that can run on systems with both endiannesses
> without modification?
>
> Thanks for educating me,
>
Actually, the endianness IS known at compile time.

However, there isn’t a universal definition in DDK and user-space headers
that specifies this. I just go bit by the lack of such a universal
definition. I blindly copied code from a driver (where it worked) to a user
application (where it didn’t work because of a missing definition)

An alternative is to just make a simple routine to detect endianess at
run-time.

Regards,

Thomas


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Same is the case with Fibre Channel Adapters, which has on-board CPU.
(most of them). The CPU Endianness would also depend on the Firmware.
Because the Firmware can decide whether to return LE or BE.

Niraj

-----Original Message-----
From: Dan Partelly [mailto:danp@jb.rdsor.ro]
Sent: Sunday, May 20, 2001 11:02 AM
To: NT Developers Interest List
Subject: [ntdev] Re: Determining the CPU Endianness!

CPU endianess is relevant to networking code. The sender protocol stack and
receiving protocol stack must agree on a format. Internet protocols uses
big endian for this , so such a code must be aware by CPU endianess to
corectly build a TCP packet for example. Thats one of the cases then CPU
endianess is important.

----- Original Message -----
From: “Barila, Phil”
To: “NT Developers Interest List”
Sent: Thursday, May 10, 2001 7:44 PM
Subject: [ntdev] Re: Determining the CPU Endianness!

> Pardon me for demonstrating my ignorance here, isn’t the endianness of
your
> hardware known at compile time? Is there any ISA on which NT is supported
> that can be big- or little-endian? In other words, is it even possible to
> produce a binary for NT that can run on systems with both endiannesses
> without modification?
>
> Thanks for educating me,
>
> Phil
>
> -----Original Message-----
> From: Thomas F. Divine [mailto:xxxxx@pcausa.com]
> Sent: Thursday, May 10, 2001 9:10 AM
> To: NT Developers Interest List
> Subject: [ntdev] Re: Determining the CPU Endianness!
>
>
> Here is a quick ENDIAN detection fragment:
>
>
> BOOLEAN UTIL_IsBigEndian()
> {
> static USHORT _I_ENDIAN_TEST = 0xFF00;
>
> return( *(PUCHAR )&_I_ENDIAN_TEST );
> }
>
> Good luck,
>
> Thomas F. Divine
>
> PCAUSA - Toolkits & Resources For Network Software Developers
> NDIS Protocol - NDIS Intermediate - TDI Client
> http: - http:
>
>
> ----- Original Message -----
> From: Jacob
> To: NT Developers Interest List
> Sent: Thursday, May 10, 2001 11:44 AM
> Subject: [ntdev] Re: Determining the CPU Endianness!
>
>
> > void main()
> > {
> > union {
> > DWORD a;
> > CHAR b[4];
> > } x;
> > x.a = 0x12345678;
> > for (int j = 0; j < 4; j++)
> > printf ("%02x ", x.b[j]);
> > }
> >
> > -----Original Message-----
> > From: Varadan Venkatesh
> > To: NT Developers Interest List
> > Date: Thursday, May 10, 2001 11:37 AM
> > Subject: [ntdev] Determining the CPU Endianness!
> >
> >
> > >Hello All
> > >
> > >How do I determine the CPU endianness of the processor in which my code
> > >runs?
> > >Basically RTL functions swap LE to BE and viceversa. But how do i
> determine
> > >when
> > >to swap or when not to swap? I was going through windows.h. there are a
> few
> > >defines
> > >like MPPC, 68K, _M_ALPHA, _M_IX86 etc. Will _M_IX86 be defined for
> all
> > >x86 CPUs (irrespective of PENTIUM, PENTIUM2 etc.)?
> > >
> > >Could anybody give any pointers on this?
> > >
> > >Thanks
> > >Venky
> > >
>
>
>
> —
> You are currently subscribed to ntdev as: xxxxx@intel.com
> To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com
>
>
> —
> You are currently subscribed to ntdev as: danp@jb.rdsor.ro
> To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com
>


You are currently subscribed to ntdev as: xxxxx@netapp.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com</http:></http:>

That’s precisely what ntohx calls are for. They wrap the knowledge of
endianness in standard calls.

Greg

-----Original Message-----
From: xxxxx@lists.osr.com
[mailto:xxxxx@lists.osr.com]On Behalf Of Dan Partelly
Sent: Sunday, May 20, 2001 1:02 PM
To: NT Developers Interest List
Subject: [ntdev] Re: Determining the CPU Endianness!

CPU endianess is relevant to networking code. The sender protocol
stack and
receiving protocol stack must agree on a format . Internet protocols uses
big endian for this , so such a code must be aware by CPU endianess to
corectly build a TCP packet for example. Thats one of the cases then CPU
endianess is important.

----- Original Message -----
From: “Barila, Phil”
> To: “NT Developers Interest List”
> Sent: Thursday, May 10, 2001 7:44 PM
> Subject: [ntdev] Re: Determining the CPU Endianness!
>
>
> > Pardon me for demonstrating my ignorance here, isn’t the endianness of
> your
> > hardware known at compile time? Is there any ISA on which NT
> is supported
> > that can be big- or little-endian? In other words, is it even
> possible to
> > produce a binary for NT that can run on systems with both endiannesses
> > without modification?
> >
> > Thanks for educating me,
> >
> > Phil
> >
> > -----Original Message-----
> > From: Thomas F. Divine [mailto:xxxxx@pcausa.com]
> > Sent: Thursday, May 10, 2001 9:10 AM
> > To: NT Developers Interest List
> > Subject: [ntdev] Re: Determining the CPU Endianness!
> >
> >
> > Here is a quick ENDIAN detection fragment:
> >
> >
> > BOOLEAN UTIL_IsBigEndian()
> > {
> > static USHORT _I_ENDIAN_TEST = 0xFF00;
> >
> > return( *(PUCHAR )&_I_ENDIAN_TEST );
> > }
> >
> > Good luck,
> >
> > Thomas F. Divine
> >
> > PCAUSA - Toolkits & Resources For Network Software Developers
> > NDIS Protocol - NDIS Intermediate - TDI Client
> > http: - http:
> >
> >
> > ----- Original Message -----
> > From: Jacob
> > To: NT Developers Interest List
> > Sent: Thursday, May 10, 2001 11:44 AM
> > Subject: [ntdev] Re: Determining the CPU Endianness!
> >
> >
> > > void main()
> > > {
> > > union {
> > > DWORD a;
> > > CHAR b[4];
> > > } x;
> > > x.a = 0x12345678;
> > > for (int j = 0; j < 4; j++)
> > > printf ("%02x ", x.b[j]);
> > > }
> > >
> > > -----Original Message-----
> > > From: Varadan Venkatesh
> > > To: NT Developers Interest List
> > > Date: Thursday, May 10, 2001 11:37 AM
> > > Subject: [ntdev] Determining the CPU Endianness!
> > >
> > >
> > > >Hello All
> > > >
> > > >How do I determine the CPU endianness of the processor in
> which my code
> > > >runs?
> > > >Basically RTL functions swap LE to BE and viceversa. But how do i
> > determine
> > > >when
> > > >to swap or when not to swap? I was going through windows.h.
> there are a
> > few
> > > >defines
> > > >like MPPC, 68K, _M_ALPHA, _M_IX86 etc. Will _M_IX86 be
> defined for
> > all
> > > >x86 CPUs (irrespective of PENTIUM, PENTIUM2 etc.)?
> > > >
> > > >Could anybody give any pointers on this?
> > > >
> > > >Thanks
> > > >Venky
> > > >
> >
> >
> >
> > —
> > You are currently subscribed to ntdev as: xxxxx@intel.com
> > To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com
> >
> >
> > —
> > You are currently subscribed to ntdev as: danp@jb.rdsor.ro
> > To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com
> >
>
>
>
> —
> You are currently subscribed to ntdev as: xxxxx@pdq.net
> To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com</http:></http:>

That wasn’t the original poster’s question. His question was, how do I
determine the endianness of the CPU on which I am executing? Is there a
possibility of a CPU executing your code in either BE or LE mode? Jay
Talbott says no. I think he’s right.

I can see conditional compilation might be required, depending on the target
ISA, but I can’t imagine any situation in which runtime detection of the
endianness of your current environment is necessary, unless there is a CPU
that will run in both modes, and you can be run in an arbitrary mode. Does
such an environment exist?

-----Original Message-----
From: Roddy, Mark [mailto:xxxxx@stratus.com]
Sent: Thursday, May 10, 2001 10:35 AM
To: NT Developers Interest List
Subject: [ntdev] Re: Determining the CPU Endianness!

You might be communicating with hardware that has different endianess.

Mark Roddy
xxxxx@hollistech.com
www.hollistech.com
603 321 1032
WindowsNT Windows 2000 Consulting Services

-----Original Message-----
From: Barila, Phil [mailto:xxxxx@intel.com]
Sent: Thursday, May 10, 2001 12:44 PM
To: NT Developers Interest List
Subject: [ntdev] Re: Determining the CPU Endianness!

Pardon me for demonstrating my ignorance here, isn’t the endianness of your
hardware known at compile time? Is there any ISA on which NT is supported
that can be big- or little-endian? In other words, is it even possible to
produce a binary for NT that can run on systems with both endiannesses
without modification?

Thanks for educating me,

Phil

-----Original Message-----
From: Thomas F. Divine [mailto:xxxxx@pcausa.com]
Sent: Thursday, May 10, 2001 9:10 AM
To: NT Developers Interest List
Subject: [ntdev] Re: Determining the CPU Endianness!

Here is a quick ENDIAN detection fragment:

BOOLEAN UTIL_IsBigEndian()
{
static USHORT _I_ENDIAN_TEST = 0xFF00;

return( *(PUCHAR )&_I_ENDIAN_TEST );
}

Good luck,

Thomas F. Divine

PCAUSA - Toolkits & Resources For Network Software Developers
NDIS Protocol - NDIS Intermediate - TDI Client
http: - http:

----- Original Message -----
From: Jacob
To: NT Developers Interest List
Sent: Thursday, May 10, 2001 11:44 AM
Subject: [ntdev] Re: Determining the CPU Endianness!

> void main()
> {
> union {
> DWORD a;
> CHAR b[4];
> } x;
> x.a = 0x12345678;
> for (int j = 0; j < 4; j++)
> printf ("%02x ", x.b[j]);
> }
>
> -----Original Message-----
> From: Varadan Venkatesh
> To: NT Developers Interest List
> Date: Thursday, May 10, 2001 11:37 AM
> Subject: [ntdev] Determining the CPU Endianness!
>
>
> >Hello All
> >
> >How do I determine the CPU endianness of the processor in which my code
> >runs?
> >Basically RTL functions swap LE to BE and viceversa. But how do i
determine
> >when
> >to swap or when not to swap? I was going through windows.h. there are a
few
> >defines
> >like MPPC, 68K, _M_ALPHA, _M_IX86 etc. Will _M_IX86 be defined for
all
> >x86 CPUs (irrespective of PENTIUM, PENTIUM2 etc.)?
> >
> >Could anybody give any pointers on this?
> >
> >Thanks
> >Venky
> >


You are currently subscribed to ntdev as: xxxxx@intel.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: xxxxx@stratus.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: xxxxx@intel.com
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com</http:></http:>

NT absolutely CANNOT run on a big-endian processor … EVER. It can run on a
bi-endian processor (eg Alpha) and in such cases the PAL/HAL’s first assignment is
to switch the CPU into little-endian mode where it will remain for the duration,
until the next reboot.

Therefore, all NT code can assume that all structures are little-endian. You only
need to use #ifdef’s etc when you need to target other OS’s from the same source
code.

Regards,

Paul Bunn, UltraBac.com, 425-644-6000
Microsoft MVP - WindowsNT/2000
http://www.ultrabac.com

-----Original Message-----
From: Barila, Phil [mailto:xxxxx@intel.com]
Sent: Thursday, May 10, 2001 11:35 AM
To: NT Developers Interest List
Subject: [ntdev] Re: Determining the CPU Endianness!

That wasn’t the original poster’s question. His question was, how do I
determine the endianness of the CPU on which I am executing? Is there a
possibility of a CPU executing your code in either BE or LE mode? Jay
Talbott says no. I think he’s right.

I can see conditional compilation might be required, depending on the target
ISA, but I can’t imagine any situation in which runtime detection of the
endianness of your current environment is necessary, unless there is a CPU
that will run in both modes, and you can be run in an arbitrary mode. Does
such an environment exist?


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

----- Original Message -----
From: Paul Bunn
To: NT Developers Interest List
Sent: Thursday, May 10, 2001 5:36 PM
Subject: [ntdev] Re: Determining the CPU Endianness!

> NT absolutely CANNOT run on a big-endian processor … EVER. It can run on
a
> bi-endian processor (eg Alpha) and in such cases the PAL/HAL’s first
assignment is
> to switch the CPU into little-endian mode where it will remain for the
duration,
> until the next reboot.
>
> Therefore, all NT code can assume that all structures are little-endian.
You only
> need to use #ifdef’s etc when you need to target other OS’s from the same
source
> code.
>
Thanks for the insight. I certainly didn’t know that!

A mistaken impression that there was really “portability” - although not at
the moment…

Regards,

Thomas


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

xxxxx@UltraBac.com said:

NT absolutely CANNOT run on a big-endian processor … EVER.

That’s a pretty strong statement:-) I believe you, but I wonder if
there are and specific technical details that make that case.

Steve Williams “The woods are lovely, dark and deep.
xxxxx@icarus.com But I have promises to keep,
xxxxx@picturel.com and lines to code before I sleep,
http://www.picturel.com And lines to code before I sleep.”


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

> CPU endianess is relevant to networking code. The sender protocol stack
and

receiving protocol stack must agree on a format . Internet protocols uses
big endian for this , so such a code must be aware by CPU endianess to
corectly build a TCP packet for example. Thats one of the cases then CPU
endianess is important.

Anyway I think that a compile-time #define is a correct place for this
check, not the runtime code.

Max


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

OK, the real problem here is maybe not so much the OS itself, but the interaction
of itself over the network using structures such as SMB. One might also assume
that the HAL code (in assembler) manages bits directly of kernel structures.
Since HALs have to be written from scratch for the processor/architecture being
used, this might not be a big deal, though it does make the job more difficult.

I think technically it is possible given enough work and motivation, I’m just
repeating the emphatic assertion from the MS guys I’ve spoken that NT will forever
be little-endian.

Regards,

Paul Bunn, UltraBac.com, 425-644-6000
Microsoft MVP - WindowsNT/2000
http://www.ultrabac.com

-----Original Message-----
From: Stephen Williams [mailto:xxxxx@icarus.com]
Sent: Thursday, May 10, 2001 3:31 PM
To: NT Developers Interest List
Subject: [ntdev] Re: Determining the CPU Endianness!

xxxxx@UltraBac.com said:

NT absolutely CANNOT run on a big-endian processor … EVER.

That’s a pretty strong statement:-) I believe you, but I wonder if
there are and specific technical details that make that case.


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

Dan,

can it be that your system date is one week ahead of the rest of us?

Robin

-----Original Message-----
From: Dan Partelly [mailto:danp@jb.rdsor.ro]
Sent: Sunday, May 20, 2001 8:02 PM
To: NT Developers Interest List
Subject: [ntdev] Re: Determining the CPU Endianness!

CPU endianess is relevant to networking code. The sender
protocol stack and
receiving protocol stack must agree on a format . Internet
protocols uses
big endian for this , so such a code must be aware by CPU endianess to
corectly build a TCP packet for example. Thats one of the
cases then CPU
endianess is important.

----- Original Message -----
From: “Barila, Phil”
> To: “NT Developers Interest List”
> Sent: Thursday, May 10, 2001 7:44 PM
> Subject: [ntdev] Re: Determining the CPU Endianness!
>
>
> > Pardon me for demonstrating my ignorance here, isn’t the
> endianness of
> your
> > hardware known at compile time? Is there any ISA on which
> NT is supported
> > that can be big- or little-endian? In other words, is it
> even possible to
> > produce a binary for NT that can run on systems with both
> endiannesses
> > without modification?
> >
> > Thanks for educating me,
> >
> > Phil
> >
> > -----Original Message-----
> > From: Thomas F. Divine [mailto:xxxxx@pcausa.com]
> > Sent: Thursday, May 10, 2001 9:10 AM
> > To: NT Developers Interest List
> > Subject: [ntdev] Re: Determining the CPU Endianness!
> >
> >
> > Here is a quick ENDIAN detection fragment:
> >
> >
> > BOOLEAN UTIL_IsBigEndian()
> > {
> > static USHORT _I_ENDIAN_TEST = 0xFF00;
> >
> > return( *(PUCHAR )&_I_ENDIAN_TEST );
> > }
> >
> > Good luck,
> >
> > Thomas F. Divine
> >
> > PCAUSA - Toolkits & Resources For Network Software Developers
> > NDIS Protocol - NDIS Intermediate - TDI Client
> > http: - http:
> >
> >
> > ----- Original Message -----
> > From: Jacob
> > To: NT Developers Interest List
> > Sent: Thursday, May 10, 2001 11:44 AM
> > Subject: [ntdev] Re: Determining the CPU Endianness!
> >
> >
> > > void main()
> > > {
> > > union {
> > > DWORD a;
> > > CHAR b[4];
> > > } x;
> > > x.a = 0x12345678;
> > > for (int j = 0; j < 4; j++)
> > > printf ("%02x ", x.b[j]);
> > > }
> > >
> > > -----Original Message-----
> > > From: Varadan Venkatesh
> > > To: NT Developers Interest List
> > > Date: Thursday, May 10, 2001 11:37 AM
> > > Subject: [ntdev] Determining the CPU Endianness!
> > >
> > >
> > > >Hello All
> > > >
> > > >How do I determine the CPU endianness of the processor
> in which my code
> > > >runs?
> > > >Basically RTL functions swap LE to BE and viceversa. But how do i
> > determine
> > > >when
> > > >to swap or when not to swap? I was going through
> windows.h. there are a
> > few
> > > >defines
> > > >like MPPC, 68K, _M_ALPHA, _M_IX86 etc. Will _M_IX86
> be defined for
> > all
> > > >x86 CPUs (irrespective of PENTIUM, PENTIUM2 etc.)?
> > > >
> > > >Could anybody give any pointers on this?
> > > >
> > > >Thanks
> > > >Venky
> > > >
> >
> >
> >
> > —
> > You are currently subscribed to ntdev as: xxxxx@intel.com
> > To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com
> >
> >
> > —
> > You are currently subscribed to ntdev as: danp@jb.rdsor.ro
> > To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com
> >
>
>
>
> —
> You are currently subscribed to ntdev as: xxxxx@exgate.tek.com
> To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com
>


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com</http:></http:>

If not, could you please tell me the filly that wins Newmarket 2pm this Friday.
Thanks. Oh and stock prices for CSCO, IBM and GE wouldn’t hurt either.

:slight_smile:

-----Original Message-----
From: xxxxx@exgate.tek.com [mailto:xxxxx@exgate.tek.com]
Sent: Monday, May 14, 2001 2:20 AM
To: NT Developers Interest List
Subject: [ntdev] Re: Determining the CPU Endianness!

Dan,

can it be that your system date is one week ahead of the rest of us?

Robin

-----Original Message-----
From: Dan Partelly [mailto:danp@jb.rdsor.ro]
Sent: Sunday, May 20, 2001 8:02 PM
To: NT Developers Interest List
Subject: [ntdev] Re: Determining the CPU Endianness!

CPU endianess is relevant to networking code. The sender
protocol stack and
receiving protocol stack must agree on a format . Internet
protocols uses
big endian for this , so such a code must be aware by CPU endianess to
corectly build a TCP packet for example. Thats one of the
cases then CPU
endianess is important.


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com

RE: [ntdev] Re: Determining the CPU Endianness!Sorry guys … indeed my home machine was with the date wrong set , I got a private mail from somone on the list and fixed the issue … with a bit fo dealy . Again sorry for any unintentioned trouble I caused.

As for stock prices … well Im still fighting on NT field , not on Wall Street so you can imagine how much I know about them :=)

----- Original Message -----
From: Paul Bunn
To: NT Developers Interest List
Sent: Tuesday, May 15, 2001 1:17 AM
Subject: [ntdev] Re: Determining the CPU Endianness!

If not, could you please tell me the filly that wins Newmarket 2pm this Friday. Thanks. Oh and stock prices for CSCO, IBM and GE wouldn’t hurt either.

:slight_smile:

-----Original Message-----
From: xxxxx@exgate.tek.com [mailto:xxxxx@exgate.tek.com]
Sent: Monday, May 14, 2001 2:20 AM
To: NT Developers Interest List
Subject: [ntdev] Re: Determining the CPU Endianness!

Dan,

can it be that your system date is one week ahead of the rest of us?

Robin

-----Original Message-----
> From: Dan Partelly [mailto:danp@jb.rdsor.ro]
> Sent: Sunday, May 20, 2001 8:02 PM
> To: NT Developers Interest List
> Subject: [ntdev] Re: Determining the CPU Endianness!
>
>
> CPU endianess is relevant to networking code. The sender
> protocol stack and
> receiving protocol stack must agree on a format . Internet
> protocols uses
> big endian for this , so such a code must be aware by CPU endianess to
> corectly build a TCP packet for example. Thats one of the
> cases then CPU
> endianess is important.


You are currently subscribed to ntdev as: danp@jb.rdsor.ro
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com


You are currently subscribed to ntdev as: $subst(‘Recip.EmailAddr’)
To unsubscribe send a blank email to leave-ntdev-$subst(‘Recip.MemberIDChar’)@lists.osr.com