cvt.h 1.0 KB

123456789101112131415161718192021222324
  1. /*
  2. * This file is part of the UCB release of Plan 9. It is subject to the license
  3. * terms in the LICENSE file found in the top-level directory of this
  4. * distribution and at http://akaros.cs.berkeley.edu/files/Plan9License. No
  5. * part of the UCB release of Plan 9, including this file, may be copied,
  6. * modified, propagated, or distributed except according to the terms contained
  7. * in the LICENSE file.
  8. */
  9. /*
  10. * integer conversion routines
  11. */
  12. #define U8GET(p) ((p)[0])
  13. #define U16GET(p) (((p)[0]<<8)|(p)[1])
  14. #define U32GET(p) ((uint32_t)(((p)[0]<<24)|((p)[1]<<16)|((p)[2]<<8)|(p)[3]))
  15. #define U48GET(p) (((uint64_t)U16GET(p)<<32)|(uint64_t)U32GET((p)+2))
  16. #define U64GET(p) (((uint64_t)U32GET(p)<<32)|(uint64_t)U32GET((p)+4))
  17. #define U8PUT(p,v) (p)[0]=(v)
  18. #define U16PUT(p,v) (p)[0]=(v)>>8;(p)[1]=(v)
  19. #define U32PUT(p,v) (p)[0]=(v)>>24;(p)[1]=(v)>>16;(p)[2]=(v)>>8;(p)[3]=(v)
  20. #define U48PUT(p,v,t32) t32=(v)>>32;U16PUT(p,t32);t32=(v);U32PUT((p)+2,t32)
  21. #define U64PUT(p,v,t32) t32=(v)>>32;U32PUT(p,t32);t32=(v);U32PUT((p)+4,t32)