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

Subversion Repositories test_project

[/] [test_project/] [trunk/] [sw/] [mul/] [mul.c] - Blame information for rev 38

Go to most recent revision | Details | Compare with Previous | View Log

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

powered by: WebSVN 2.1.0

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