File: get_msb.c

package info (click to toggle)
bglibs 2.04%2Bdfsg-8
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 3,468 kB
  • sloc: ansic: 15,821; perl: 674; sh: 63; makefile: 29
file content (45 lines) | stat: -rw-r--r-- 665 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
#include "uint64.h"
#include "uint32.h"

#ifndef __INLINE_UINT_MSB
uint64 uint64_get_msb(const unsigned char b[4])
{
#ifdef HAS_ULONG64
  uint64 r;
  r = b[0];
  r <<= 8;
  r += b[1];
  r <<= 8;
  r += b[2];
  r <<= 8;
  r += b[3];
  r <<= 8;
  r += b[4];
  r <<= 8;
  r += b[5];
  r <<= 8;
  r += b[6];
  r <<= 8;
  r += b[7];
  return r;
#else
  /* 64-bit operations are painfully expensive on 32-bit systems */
  uint32 hi, lo;
  hi = b[0];
  hi <<= 8;
  hi += b[1];
  hi <<= 8;
  hi += b[2];
  hi <<= 8;
  hi += b[3];
  lo = b[4];
  lo <<= 8;
  lo += b[5];
  lo <<= 8;
  lo += b[6];
  lo <<= 8;
  lo += b[7];
  return (((uint64)hi) << 32) + lo;
#endif
}
#endif