darcs patch: Implementation of aton and ntoa outside the IO monad

Robert Marlow bobstopper at bobturf.org
Mon Sep 25 06:17:54 EDT 2006


On Mon, 2006-09-25 at 12:47 +0400, Bulat Ziganshin wrote:
> Hello Robert,
>
> jfyi: there are (very rare) computers that are not LE nor BE. afaik,
> VAX was one - it has smth like 1032 byte order, mixing BE in 2-byte
> words and LE of 2-byte words in 4-byte word (or vice versa, i'm not
> sure)

Yeah, I had a look for how people check such things in C and I didn't
come accross any solutions for "middle-endianness" like that so I
figured it was rare enough to ignore. Ultimately, it's not going to
matter unless there are haskell compilers for these crazy platforms :)
Is there any haskell compilers running on middle-endian platforms?


> > flipEndian :: Integral a => a -> a
> > flipEndian = wordConcat . reverse . toWord8s

Heh, yeah I guess that was pretty lazy of me :)


> a bit faster:
> 
> flipEndian n = let w1 = (n       ) .&. 0xff
>                    w2 = (n >>#  8) .&. 0xff
>                    w3 = (n >># 16) .&. 0xff
>                    w4 = (n >># 24)
>                    in (w1 <<# 24) .|. (w2 <<# 16) .|. (w3 <<# 8) .|. w4
> 
> #ifdef __GLASGOW_HASKELL__
> 
> (I# a) <<# (I# b) = (I# (a `iShiftL#` b))
> (I# a) >># (I# b) = (I# (a `uncheckedIShiftRL#` b))
> 
> #else /* ! __GLASGOW_HASKELL__ */
> 
> a <<# b = a `shiftL` b
> a >># b = a `shiftR` b
> 
> #endif /* ! __GLASGOW_HASKELL__ */

Thanks


-- 
Robert Marlow <bobstopper at bobturf.org>



More information about the Libraries mailing list