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

Subversion Repositories or1k_old

[/] [or1k_old/] [trunk/] [mp3/] [sw/] [mul/] [mul.c] - Blame information for rev 564

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

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

powered by: WebSVN 2.1.0

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