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

Subversion Repositories kvcordic

[/] [kvcordic/] [trunk/] [sw/] [cordic.nac] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 kavi
//
2
// Filename: cordic.nac
3
// Purpose : N-address code (NAC) implementation for a fixed-point universal
4
//           CORDIC supporting all directions (ROTATION, VECTORING) and
5
//           operation modes (CIRCULAR, LINEAR, HYPERBOLIC).
6
//           The arithmetic representation used is signed fixed-point
7
//           (Q2.14S). The implementation is based partly on the following
8
//           sources (as references):
9
//           [1] The simple fixed-point CORDIC tools from:
10
//           http://www.dcs.gla.ac.uk/~jhw/cordic/
11
//           [2] Jorg Arndt, Matters Computational (free ebook):
12
//           http://www.jjj.de/fxt/
13
//           [3] Jean-Michel Muller, Elementary Functions: Algorithms and
14
//           Implementation, Second Edition, Birkhauser, 2006.
15
//           [4] Uwe Meyer-Baese, Digital Signal Processing with Field
16
//           Programmable Gate Arrays, Third Edition, Springer, 2007.
17
// Author  : Nikolaos Kavvadias (C) 2010
18
// Date    : 01-Nov-2010
19
// Revision: 0.3.0 (31/10/10)
20
//           Initial version.
21
//           0.3.1 (01/11/10)
22
//           Some hand optimizations.
23
//           0.3.2 (01/11/10)
24
//           Interface changes, implementation of a unified CORDIC (can
25
//           compute any function).
26
//           0.3.3 (08/11/10)
27
//           Replaced the three coefficient LUTs with a single one.
28
//
29
 
30
constant s16 0, 1, 2, 4, 14, 28, 15;
31
globalvar s16 cordic_tab[42]={65535,8999,4184,2058,1025,512,256,128,64,32,16,8,4,2,16384,8192,4096,2048,1024,512,256,128,64,32,16,8,4,2,12867,7596,4013,2037,1022,511,255,127,63,31,15,7,3,1};
32
 
33
procedure cordic (in s16 direction, in s16 mode, in s16 xin, in s16 yin, in s16 zin, out s16 xout, out s16 yout, out s16 zout)
34
{
35
  localvar s16 k, d;
36
  localvar s16 x, y, z;
37
  localvar s16 xbyk, ybyk, i, tabval;
38
  localvar s16 t0, t1, t2, t3, t4, t5, t6, t7;
39
  localvar s16 zero, one, ldirection, lmode, offset;
40
 
41
S_1:
42
  zero <= ldc 0;
43
  one <= ldc 1;
44
  x <= mov xin;
45
  y <= mov yin;
46
  z <= mov zin;
47
  ldirection <= mov direction;
48
  lmode <= mov mode;
49
//  kstart = ((mode == HYPERBOLIC) ? 1 : 0);
50
  k <= muxeq lmode, 2, one, zero;
51
//  offset = ((mode == HYPERBOLIC) ? 0 : ((mode == LINEAR) ? 14 : 28));
52
  t0 <= muxeq lmode, 1, 14, 28;
53
  offset <= muxeq lmode, 2, 0, t0;
54
  i <= ldc 4;
55
  S_2 <= jmpun;
56
 
57
//  for (k = kstart; k < CORDIC_NTAB; ++k) {
58
S_2:
59
  S_3, S_EXIT <= jmplt k, 14;
60
 
61
//again:
62
S_3:
63
  // precompute invariants: y>>k, -(y>>k), x>>k, cordic_ctab[k]
64
  t0 <= shr y, k;
65
  t1 <= neg t0;
66
//  xbyk = (x>>k);
67
  xbyk <= shr x, k;
68
//  ybyk = ((mode == HYPERBOLIC) ? -(y>>k) : ((mode == LINEAR) ? 0 : (y>>k)));
69
  t5 <= muxeq lmode, 1, zero, t0;
70
  ybyk <= muxeq lmode, 2, t1, t5;
71
//  tabval = ((mode == HYPERBOLIC) ? cordic_htab[k] : ((mode == LINEAR) ? cordic_btab[k] : cordic_ctab[k]));
72
  t2 <= add k, offset;
73
  tabval <= load cordic_tab, t2;
74
//  if (direction == ROTATION) {
75
//    d = ((z>=0) ? 0 : 1);
76
  t7 <= shr z, 15;
77
  t1 <= muxeq t7, 0, zero, one;
78
//  } else { // VECTORING
79
//    d = ((y<0) ? 0 : 1);
80
//  }
81
  t2 <= shr y, 15;
82
  t3 <= muxne t2, 0, zero, one;
83
  d <= muxeq ldirection, 0, t1, t3;
84
  S_4, S_5 <= jmpeq d, 0;
85
 
86
S_4:
87
//   x = x - ybyk;
88
  x <= sub x, ybyk;
89
//   y = y + xbyk;
90
  y <= add y, xbyk;
91
//   z = z - tabval;
92
  z <= sub z, tabval;
93
  S_6 <= jmpun;
94
 
95
S_5:
96
//  x = x + ybyk;
97
  x <= add x, ybyk;
98
//  y = y - xbyk;
99
  y <= sub y, xbyk;
100
//  z = z + tabval;
101
  z <= add z, tabval;
102
  S_6 <= jmpun;
103
 
104
S_6:
105
//  if ((k == i) && (mode == HYPERBOLIC)) {
106
  t0 <= seteq k, i;
107
  t1 <= seteq lmode, 2;
108
  t2 <= and t0, t1;
109
  S_7, S_8 <= jmpeq t2, 1;
110
 
111
S_7:
112
//    i = ((i << 1) + i) + 1;
113
//    goto again;
114
//  }
115
  t3 <= shl i, 1;
116
  t4 <= add t3, i;
117
  i <= add t4, 1;
118
  S_3 <= jmpun;
119
 
120
S_8:
121
  k <= add k, 1;
122
  S_2 <= jmpun;
123
 
124
S_EXIT:
125
  xout <= mov x;
126
  yout <= mov y;
127
  zout <= mov z;
128
}

powered by: WebSVN 2.1.0

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