File: check-shift.c

package info (click to toggle)
ucbmpeg 1r2-6
  • links: PTS
  • area: non-free
  • in suites: hamm, potato, slink
  • size: 9,504 kB
  • ctags: 7,643
  • sloc: ansic: 79,920; tcl: 2,985; perl: 313; asm: 284; makefile: 269; csh: 13
file content (40 lines) | stat: -rw-r--r-- 898 bytes parent folder | download | duplicates (7)
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
/*
 code "borrowed" from JPEG-5 config code
*/

#include <stdio.h>

int is_shifting_signed (arg)
     long arg;
/* See whether right-shift on a long is signed or not. */
{
  long res = arg >> 4;

  if (res == -0x7F7E80CL) {	/* expected result for signed shift */
    return 1;			/* right shift is signed */
  }

  /* see if unsigned-shift hack will fix it. */
  /* we can't just test exact value since it depends on width of long... */
  res |= (~0L) << (32-4);

  if (res == -0x7F7E80CL) {	/* expected result now? */
    return 0;			/* right shift is unsigned */
  }

  fprintf(stderr, "Right shift isn't acting as I expect it to.\n");
  fprintf(stderr, "I fear the DCT software will not work at all.\n\n");
  exit(1);
}

main()
{

  if (is_shifting_signed(-0x7F7E80B1L)) {
    printf("do not define RIGHT_SHIFT_IS_UNSIGNED\n");
  }
  else {
    printf("define RIGHT_SHIFT_IS_UNSIGNED\n");
  }

}