• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: htonl network byte ordering for 64 bit words...
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: htonl network byte ordering for 64 bit words...


  • Subject: Re: htonl network byte ordering for 64 bit words...
  • From: Wade Tregaskis <email@hidden>
  • Date: Tue, 2 Nov 2004 11:43:10 +1100

Is there a function to convert 64 bit words to network byte order (and back again)? ntohl convert uint_32 and ntohs converts uint_16. uint_64 anyone?

There's always <architecture/byte_order.h>, which is what ntohl gets mapped to anyway.


Also, while the man page for ntohl says it takes a uint32_t argument, the actual definition in the header files takes an unsigned long, and maps to the appropriate NXSwap... function, taking a long. So, on a 64-bit architecture, ntohl will swap 64-bit longs. Of course, you probably want behaviour that's the same on 32-bit and 64-bit systems...

The code for doing so is pretty trivial; define a union containing a uint64_t and an eight-byte character array, then swap the bytes. There are more efficient ways of doing so on 32-bit machines (you can swap the high and low 32-bits, then swap the bytes in them, allowing some minor level of parallelism), although you'll be hard pressed to find any open source* assembly implementations. I have written some, but the performance improvements in most cases are negligible, and not worth the associated issues (such as using inline assembly with gcc, which appears dangerous in 3.3).

As a special case you could probably optimise loads and stores to memory by using the appropriate byte-swapping load/store PPC instructions, but I don't think these are present on the G5 (re. the Virtual PC "fiasco"), so here be compatibility dragons...

Wade Tregaskis (AIM, Yahoo & Skype: wadetregaskis, ICQ: 40056898, MSN & email: email@hidden, Jabber: email@hidden
-- Sed quis custodiet ipsos custodes?


* = Open source is this context being "open" in the truer sense of the word, so no APSL/GPL/etc.

_______________________________________________
Do not post admin requests to the list. They will be ignored.
Cocoa-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden


References: 
 >htonl network byte ordering for 64 bit words... (From: "Hall, Warwick D" <email@hidden>)

  • Prev by Date: htonl network byte ordering for 64 bit words...
  • Next by Date: Building Text System by hand - View Displays Nothing
  • Previous by thread: htonl network byte ordering for 64 bit words...
  • Next by thread: Building Text System by hand - View Displays Nothing
  • Index(es):
    • Date
    • Thread