packages feed

cpu 0.1.1 → 0.1.2

raw patch · 3 files changed

+58/−4 lines, 3 files

Files

System/Endian.hs view
@@ -12,13 +12,17 @@     -- little endian to and from cpu     , fromLE32     , fromLE64+    , fromLE16     , toLE32     , toLE64+    , toLE16     -- big endian to and from cpu     , fromBE32     , fromBE64+    , fromBE16     , toBE32     , toBE64+    , toBE16     ) where  #include "MachDeps.h"@@ -60,6 +64,15 @@ fromLE32 :: Word32 -> Word32 fromLE32 = if getSystemEndianness == LittleEndian then id else swap32 +-- | Convert from a big endian 16 bit value to the cpu endianness+fromBE16 :: Word16 -> Word16+fromBE16 = if getSystemEndianness == BigEndian then id else swap16++-- | Convert from a little endian 16 bit value to the cpu endianness+fromLE16 :: Word16 -> Word16+fromLE16 = if getSystemEndianness == LittleEndian then id else swap16++ -- | Convert a 64 bit value in cpu endianess to big endian toBE64 :: Word64 -> Word64 toBE64 = fromBE64@@ -76,7 +89,36 @@ toLE32 :: Word32 -> Word32 toLE32 = fromLE32 +-- | Convert a 16 bit value in cpu endianness to big endian+toBE16 :: Word16 -> Word16+toBE16 = fromBE16++-- | Convert a 16 bit value in cpu endianness to little endian+toLE16 :: Word16 -> Word16+toLE16 = fromLE16++#if MIN_VERSION_base(4,7,0)++-- | Transform a 16 bit value bytes from a.b to b.a+swap16 :: Word16 -> Word16+swap16 = byteSwap16+     -- | Transform a 32 bit value bytes from a.b.c.d to d.c.b.a+swap32 :: Word32 -> Word32+swap32 = byteSwap32++-- | Transform a 64 bit value bytes from a.b.c.d.e.f.g.h to h.g.f.e.d.c.b.a+swap64 :: Word64 -> Word64+swap64 = byteSwap64++#else++-- | Transform a 16 bit value bytes from a.b to b.a+{-# INLINE swap16 #-}+swap16 :: Word16 -> Word16+swap16 = fromIntegral . c_swap16 . fromIntegral++-- | Transform a 32 bit value bytes from a.b.c.d to d.c.b.a {-# INLINE swap32 #-} swap32 :: Word32 -> Word32 swap32 = fromIntegral . c_swap32 . fromIntegral@@ -86,5 +128,10 @@ swap64 :: Word64 -> Word64 swap64 = fromIntegral . c_swap64 . fromIntegral -foreign import ccall safe "bitfn_swap32" c_swap32 :: CUInt -> CUInt-foreign import ccall safe "bitfn_swap64" c_swap64 :: CULLong -> CULLong+foreign import ccall unsafe "bitfn_swap16" c_swap16 :: CUShort -> CUShort+foreign import ccall unsafe "bitfn_swap32" c_swap32 :: CUInt -> CUInt+foreign import ccall unsafe "bitfn_swap64" c_swap64 :: CULLong -> CULLong++#endif++
cbits/endian.c view
@@ -52,3 +52,8 @@ 	        (((uint64_t) bitfn_swap32((uint32_t) a)) << 32); } #endif++uint16_t bitfn_swap16(uint16_t a)+{+  return (a << 8) | (a >> 8);+}
cpu.cabal view
@@ -1,5 +1,5 @@ Name:                cpu-Version:             0.1.1+Version:             0.1.2 Description:              Lowlevel cpu routines to get basic properties of the cpu platform, like endianness and architecture. License:             BSD3@@ -14,6 +14,7 @@ Cabal-Version:       >=1.8 Homepage:            http://github.com/vincenthz/hs-cpu data-files:          README.md+Extra-source-files:  cbits/endian.c  Flag executable   Description:       Build the executable@@ -26,7 +27,8 @@                      System.Arch   ghc-options:       -Wall -  C-sources:   cbits/endian.c+  if impl(ghc < 7.8)+    C-sources:   cbits/endian.c    if arch(i386)     Cpp-options: -DARCH_X86