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

Subversion Repositories openrisc

[/] [openrisc/] [trunk/] [or1ksim/] [testsuite/] [test-code-or1k/] [mul/] [mul.c] - Blame information for rev 114

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

Line No. Rev Author Line
1 90 jeremybenn
/* exit.c. Test of Or1ksim program multiplication instructions
2
 
3
   Copyright (C) 1999-2006 OpenCores
4
   Copyright (C) 2010 Embecosm Limited
5
 
6
   Contributors various OpenCores participants
7
   Contributor Jeremy Bennett <jeremy.bennett@embecosm.com>
8
 
9
   This file is part of OpenRISC 1000 Architectural Simulator.
10
 
11
   This program is free software; you can redistribute it and/or modify it
12
   under the terms of the GNU General Public License as published by the Free
13
   Software Foundation; either version 3 of the License, or (at your option)
14
   any later version.
15
 
16
   This program is distributed in the hope that it will be useful, but WITHOUT
17
   ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
18
   FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
19
   more details.
20
 
21
   You should have received a copy of the GNU General Public License along
22
   with this program.  If not, see <http:  www.gnu.org/licenses/>.  */
23
 
24
/* ----------------------------------------------------------------------------
25
   This code is commented throughout for use with Doxygen.
26
   --------------------------------------------------------------------------*/
27
 
28
/* Test l.mul, l.mac and l.macrc instructions */
29
 
30
#include "support.h"
31
 
32
#define T1 0xa6312f33
33
#define T2 0x0d4de375
34
#define T3 0x61ab48dc
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
long test_mul (long a, long b) {
45
  long t;
46
  int i;
47
  for (i = 0; i < 100; i++) {
48
    t = a * b;
49
    t += 153;
50
    a = t - a * 17;
51
    b = t + b * 13333;
52
 
53
    /*printf ("(%08x,%08x)", a, b);*/
54
  }
55
  return a;
56
}
57
 
58
long test_mac (long a, long b) {
59
  long t = 1234567;
60
  int i;
61
  for (i = 0; i < 100; i++) {
62
    MAC (a, b);
63
    if (i & 3) {
64
      a = t - a;
65
      b = t + a;
66
    } else {
67
      a = MACRC;
68
    }
69
    MAC (a, 3);
70
    MAC (a, 5);
71
    MAC (a, 7);
72
    //printf ("(%08x,%08x)", a, b);
73
  }
74
  return a;
75
}
76
 
77
long test_mul_mac (long a, long b) {
78
  long t = 1;
79
  int i;
80
  for (i = 0; i < 100; i++) {
81
    a = a * 119;
82
    MAC (a, b);
83
    MAC (b, 423490431);
84
    MAC (b, 113);
85
    MAC (a, 997);
86
    b = 87 * a * t;
87
    if (i & 3) {
88
      t = a * b;
89
      a = t - a;
90
      b = t + a;
91
    } else {
92
      a = MACRC;
93
    }
94
 //   printf ("(%08x,%08x)", a, b);
95
  }
96
  return a;
97
}
98
 
99
int main () {
100
  unsigned t1;
101
  unsigned t2;
102
  unsigned t3;
103
  printf ("%08lx\n", MACRC);
104
  MAC (888888887, 0x87654321);
105
  printf ("%08lx\n", MACRC);
106
  t1 = test_mul (888888887, 0x87654321);
107
  t2 = test_mac (888888887, 0x87654321);
108
  t3 = test_mul_mac (888888887, 0x87654321);
109
  printf ("%08x, expected %08x\n", t1, T1);
110
  printf ("%08x, expected %08x\n", t2, T2);
111
  printf ("%08x, expected %08x\n", t3, T3);
112
  report (t1 ^ t2 ^ t3 ^ T1 ^ T2 ^ T3 ^ 0xdeaddead);
113
  if (t1 != T1 || t2 != T2 || t3 != T3) {
114
    printf ("Test failed!\n");
115
    if (t1 != T1) exit (1);
116
    if (t2 != T2) exit (2);
117
    if (t3 != T3) exit (3);
118
  } else {
119
    printf ("Test succesful.\n");
120
    exit (0);
121
  }
122
  exit (0);
123
}

powered by: WebSVN 2.1.0

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