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 591

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 116 jeremybenn
#define T2 0x059b8f08
34
#define T3 0x00000000
35 90 jeremybenn
 
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 458 julius
  asm volatile ("l.nop\t");
41
  asm volatile ("l.nop\t");
42 90 jeremybenn
  asm volatile ("l.macrc\t%0" : "=r" (x));
43
  return x;
44
}
45
 
46
long test_mul (long a, long b) {
47
  long t;
48
  int i;
49
  for (i = 0; i < 100; i++) {
50
    t = a * b;
51
    t += 153;
52
    a = t - a * 17;
53
    b = t + b * 13333;
54
 
55
    /*printf ("(%08x,%08x)", a, b);*/
56
  }
57
  return a;
58
}
59
 
60
long test_mac (long a, long b) {
61
  long t = 1234567;
62
  int i;
63
  for (i = 0; i < 100; i++) {
64
    MAC (a, b);
65
    if (i & 3) {
66
      a = t - a;
67
      b = t + a;
68
    } else {
69
      a = MACRC;
70
    }
71
    MAC (a, 3);
72
    MAC (a, 5);
73
    MAC (a, 7);
74
    //printf ("(%08x,%08x)", a, b);
75
  }
76
  return a;
77
}
78
 
79
long test_mul_mac (long a, long b) {
80
  long t = 1;
81
  int i;
82
  for (i = 0; i < 100; i++) {
83
    a = a * 119;
84
    MAC (a, b);
85
    MAC (b, 423490431);
86
    MAC (b, 113);
87
    MAC (a, 997);
88
    b = 87 * a * t;
89
    if (i & 3) {
90
      t = a * b;
91
      a = t - a;
92
      b = t + a;
93
    } else {
94
      a = MACRC;
95
    }
96
 //   printf ("(%08x,%08x)", a, b);
97
  }
98
  return a;
99
}
100
 
101
int main () {
102
  unsigned t1;
103
  unsigned t2;
104
  unsigned t3;
105
  printf ("%08lx\n", MACRC);
106
  MAC (888888887, 0x87654321);
107
  printf ("%08lx\n", MACRC);
108
  t1 = test_mul (888888887, 0x87654321);
109
  t2 = test_mac (888888887, 0x87654321);
110
  t3 = test_mul_mac (888888887, 0x87654321);
111
  printf ("%08x, expected %08x\n", t1, T1);
112
  printf ("%08x, expected %08x\n", t2, T2);
113
  printf ("%08x, expected %08x\n", t3, T3);
114
  report (t1 ^ t2 ^ t3 ^ T1 ^ T2 ^ T3 ^ 0xdeaddead);
115
  if (t1 != T1 || t2 != T2 || t3 != T3) {
116
    printf ("Test failed!\n");
117
    if (t1 != T1) exit (1);
118
    if (t2 != T2) exit (2);
119
    if (t3 != T3) exit (3);
120
  } else {
121
    printf ("Test succesful.\n");
122
    exit (0);
123
  }
124
  exit (0);
125
}

powered by: WebSVN 2.1.0

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