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 52

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 52 julius
#if USE_UCLIBC
8
#include "stdio.h"
9
#endif
10
 
11 25 julius
#define T1 0xa6312f33
12
#define T2 0x0d4de375
13
#define T3 0x61ab48dc
14
 
15
#ifndef __or32__
16
 
17
#include <stdlib.h>
18
#define LONGEST long long
19
 
20 52 julius
 
21 25 julius
LONGEST acc = 0;
22
#define MAC(x,y) {\
23
  printf ("[%08x,%08x]\t", (unsigned long)(x), (unsigned long)(y));\
24
  acc += (LONGEST)(x) * (LONGEST)(y);\
25
  printf ("(%08x,%08x)\n", (unsigned long)(acc >> 32), (unsigned long)(acc & 0xffffffff));\
26
}
27
#define MACRC    (macrc())
28
static inline long macrc() {
29
  long result = acc >> 28;
30
  //printf ("<%08x>\n", (unsigned long)result);
31
  acc = 0;
32
  return result;
33
}
34
#else /* OR1K */
35
 
36
#define MAC(x,y) asm volatile ("l.mac\t%0,%1" : : "r" (x), "r" (y))
37
#define MACRC macrc()
38
static inline long macrc() {
39
  long x;
40
  asm volatile ("l.macrc\t%0" : "=r" (x));
41
  return x;
42
}
43
 
44
#endif /* SIM */
45
 
46 52 julius
// Define dummpy or32 trap vectors
47
void buserr_except(){}
48
void dpf_except(){}
49
void ipf_except(){}
50
void lpint_except(){}
51
void align_except(){}
52
void illegal_except(){}
53
void hpint_except(){}
54
void dtlbmiss_except(){}
55
void itlbmiss_except(){}
56
void range_except(){}
57
void syscall_except(){}
58
void res1_except(){}
59
void trap_except(){}
60
void res2_except(){}
61
 
62
 
63 25 julius
long test_mul (long a, long b) {
64
  long t;
65
  int i;
66
  for (i = 0; i < 100; i++) {
67
    t = a * b;
68
    t += 153;
69
    a = t - a * 17;
70
    b = t + b * 13333;
71
 
72
    /*printf ("(%08x,%08x)", a, b);*/
73
  }
74
  return a;
75
}
76
 
77
long test_mac (long a, long b) {
78
  long t = 1234567;
79
  int i;
80
  for (i = 0; i < 100; i++) {
81
    MAC (a, b);
82
    if (i & 3) {
83
      a = t - a;
84
      b = t + a;
85
    } else {
86
      a = MACRC;
87
      report(a);
88
    }
89
    MAC (a, 3);
90
    MAC (a, 5);
91
    MAC (a, 7);
92
    //printf ("(%08x,%08x)", a, b);
93
  }
94
  return a;
95
}
96
 
97
long test_mul_mac (long a, long b) {
98
  long t = 1;
99
  int i;
100
  for (i = 0; i < 100; i++) {
101
    a = a * 119;
102
    MAC (a, b);
103
    MAC (b, 423490431);
104
    MAC (b, 113);
105
    MAC (a, 997);
106
    b = 87 * a * t;
107
    if (i & 3) {
108
      t = a * b;
109
      a = t - a;
110
      b = t + a;
111
    } else {
112
      a = MACRC;
113
    }
114
 //   printf ("(%08x,%08x)", a, b);
115
  }
116
  return a;
117
}
118
 
119
int main () {
120
  unsigned t1;
121
  unsigned t2;
122
  unsigned t3;
123
/*
124
  report (MACRC);
125
  MAC ((unsigned long)888888887, (unsigned long)0x87654321);
126
  report (MACRC);
127
  MAC ((unsigned long)888888887, (unsigned long)0x87654321);
128
  MAC ((unsigned long)888888887, (unsigned long)0x87654321);
129
  report (MACRC);
130 52 julius
  or32_exit(0);
131 25 julius
*/
132
  printf ("%8x\n", MACRC);
133
  t1 = test_mul (888888887, 0x87654321);
134
  t2 = test_mac (888888887, 0x87654321);
135
  t3 = test_mul_mac (888888887, 0x87654321);
136
  printf ("%08x, expected %08x\n", t1, T1);
137
  printf ("%08x, expected %08x\n", t2, T2);
138
  printf ("%08x, expected %08x\n", t3, T3);
139
  report (t1 ^ t2 ^ t3 ^ T1 ^ T2 ^ T3 ^ 0xdeaddead);
140
  if (t1 != T1 || t2 != T2 || t3 != T3) {
141
    printf ("Test failed!\n");
142 52 julius
    if (t1 != T1) or32_exit (1);
143
    if (t2 != T2) or32_exit (2);
144
    if (t3 != T3) or32_exit (3);
145 25 julius
  } else {
146
    printf ("Test succesful.\n");
147 52 julius
    or32_exit (0);
148 25 julius
  }
149 52 julius
  or32_exit (0);
150 25 julius
}

powered by: WebSVN 2.1.0

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