File: i32operations.c

package info (click to toggle)
llvm-3.0 3.0-10
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 75,412 kB
  • sloc: cpp: 468,043; asm: 109,345; ansic: 13,782; sh: 12,935; ml: 4,716; python: 4,351; perl: 2,096; makefile: 1,905; pascal: 1,578; exp: 389; xml: 283; lisp: 187; csh: 117
file content (69 lines) | stat: -rw-r--r-- 2,142 bytes parent folder | download | duplicates (6)
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
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
#include <stdio.h>

typedef unsigned int  		uint32_t;
typedef int           		int32_t;

const char *boolstring(int val) {
  return val ? "true" : "false";
}

int i32_eq(int32_t a, int32_t b) {
  return (a == b);
}

int i32_neq(int32_t a, int32_t b) {
  return (a != b);
}

int32_t i32_eq_select(int32_t a, int32_t b, int32_t c, int32_t d) {
  return ((a == b) ? c : d);
}

int32_t i32_neq_select(int32_t a, int32_t b, int32_t c, int32_t d) {
  return ((a != b) ? c : d);
}

struct pred_s {
  const char *name;
  int (*predfunc)(int32_t, int32_t);
  int (*selfunc)(int32_t, int32_t, int32_t, int32_t);
};

struct pred_s preds[] = {
  { "eq",  i32_eq,  i32_eq_select },
  { "neq", i32_neq, i32_neq_select }
};

int main(void) {
  int i;
  int32_t a = 1234567890;
  int32_t b =  345678901;
  int32_t c = 1234500000;
  int32_t d =      10001;
  int32_t e =      10000;

  printf("a = %12d (0x%08x)\n", a, a);
  printf("b = %12d (0x%08x)\n", b, b);
  printf("c = %12d (0x%08x)\n", c, c);
  printf("d = %12d (0x%08x)\n", d, d);
  printf("e = %12d (0x%08x)\n", e, e);
  printf("----------------------------------------\n");

  for (i = 0; i < sizeof(preds)/sizeof(preds[0]); ++i) {
    printf("a %s a = %s\n", preds[i].name, boolstring((*preds[i].predfunc)(a, a)));
    printf("a %s a = %s\n", preds[i].name, boolstring((*preds[i].predfunc)(a, a)));
    printf("a %s b = %s\n", preds[i].name, boolstring((*preds[i].predfunc)(a, b)));
    printf("a %s c = %s\n", preds[i].name, boolstring((*preds[i].predfunc)(a, c)));
    printf("d %s e = %s\n", preds[i].name, boolstring((*preds[i].predfunc)(d, e)));
    printf("e %s e = %s\n", preds[i].name, boolstring((*preds[i].predfunc)(e, e)));

    printf("a %s a ? c : d = %d\n", preds[i].name, (*preds[i].selfunc)(a, a, c, d));
    printf("a %s a ? c : d == c (%s)\n", preds[i].name, boolstring((*preds[i].selfunc)(a, a, c, d) == c));
    printf("a %s b ? c : d = %d\n", preds[i].name, (*preds[i].selfunc)(a, b, c, d));
    printf("a %s b ? c : d == d (%s)\n", preds[i].name, boolstring((*preds[i].selfunc)(a, b, c, d) == d));

    printf("----------------------------------------\n");
  }

  return 0;
}