OpenCores
URL https://opencores.org/ocsvn/or1k/or1k/trunk

Subversion Repositories or1k

[/] [or1k/] [trunk/] [or1ksim/] [testbench/] [mul.c] - Blame information for rev 1765

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 224 markom
/* Test l.mul, l.mac and l.macrc instructions */
2
#include "support.h"
3
 
4
#define T1 0xa6312f33
5
#define T2 0x0d4de375
6
#define T3 0x61ab48dc
7
 
8
#ifndef OR1K
9
 
10
#include <stdlib.h>
11
#define LONGEST long long
12
 
13
LONGEST acc = 0;
14
#define MAC(x,y) {\
15 1024 simons
  printf ("[%08x,%08x]\t", (unsigned long)(x), (unsigned long)(y));\
16 224 markom
  acc += (LONGEST)(x) * (LONGEST)(y);\
17 1024 simons
  printf ("(%08x,%08x)\n", (unsigned long)(acc >> 32), (unsigned long)(acc & 0xffffffff));\
18 224 markom
}
19
#define MACRC    (macrc())
20
static inline long macrc() {
21
  long result = acc >> 28;
22 1024 simons
  //printf ("<%08x>\n", (unsigned long)result);
23 224 markom
  acc = 0;
24
  return result;
25
}
26
#else /* OR1K */
27
 
28
#define MAC(x,y) asm volatile ("l.mac\t%0,%1" : : "r" (x), "r" (y))
29
#define MACRC macrc()
30
static inline long macrc() {
31
  long x;
32
  asm volatile ("l.macrc\t%0" : "=r" (x));
33
  return x;
34
}
35
 
36
#endif /* SIM */
37
 
38
long test_mul (long a, long b) {
39
  long t;
40
  int i;
41
  for (i = 0; i < 100; i++) {
42
    t = a * b;
43
    t += 153;
44
    a = t - a * 17;
45
    b = t + b * 13333;
46
 
47 1024 simons
    /*printf ("(%08x,%08x)", a, b);*/
48 224 markom
  }
49
  return a;
50
}
51
 
52
long test_mac (long a, long b) {
53
  long t = 1234567;
54
  int i;
55
  for (i = 0; i < 100; i++) {
56
    MAC (a, b);
57
    if (i & 3) {
58
      a = t - a;
59
      b = t + a;
60
    } else {
61
      a = MACRC;
62
    }
63
    MAC (a, 3);
64
    MAC (a, 5);
65
    MAC (a, 7);
66 1024 simons
    //printf ("(%08x,%08x)", a, b);
67 224 markom
  }
68
  return a;
69
}
70
 
71
long test_mul_mac (long a, long b) {
72
  long t = 1;
73
  int i;
74
  for (i = 0; i < 100; i++) {
75
    a = a * 119;
76
    MAC (a, b);
77
    MAC (b, 423490431);
78
    MAC (b, 113);
79
    MAC (a, 997);
80
    b = 87 * a * t;
81
    if (i & 3) {
82
      t = a * b;
83
      a = t - a;
84
      b = t + a;
85
    } else {
86
      a = MACRC;
87
    }
88 1024 simons
 //   printf ("(%08x,%08x)", a, b);
89 224 markom
  }
90
  return a;
91
}
92
 
93
int main () {
94 604 markom
  unsigned t1;
95
  unsigned t2;
96
  unsigned t3;
97 1024 simons
  printf ("%08x\n", MACRC);
98 915 markom
  MAC (888888887, 0x87654321);
99 1024 simons
  printf ("%08x\n", MACRC);
100 604 markom
  t1 = test_mul (888888887, 0x87654321);
101
  t2 = test_mac (888888887, 0x87654321);
102
  t3 = test_mul_mac (888888887, 0x87654321);
103 1024 simons
  printf ("%08x, expected %08x\n", t1, T1);
104
  printf ("%08x, expected %08x\n", t2, T2);
105
  printf ("%08x, expected %08x\n", t3, T3);
106 309 markom
  report (t1 ^ t2 ^ t3 ^ T1 ^ T2 ^ T3 ^ 0xdeaddead);
107 224 markom
  if (t1 != T1 || t2 != T2 || t3 != T3) {
108 1024 simons
    printf ("Test failed!\n");
109 224 markom
    if (t1 != T1) exit (1);
110
    if (t2 != T2) exit (2);
111
    if (t3 != T3) exit (3);
112
  } else {
113 1024 simons
    printf ("Test succesful.\n");
114 224 markom
    exit (0);
115
  }
116
  exit (0);
117
}

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.