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

Subversion Repositories systemc_cordic

[/] [systemc_cordic/] [trunk/] [cordic_ip/] [adjust.cpp] - Blame information for rev 4

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 3 wwcheng
// adjust.cpp: source file
2
/********************************************************************
3
//
4
// Module:
5
//   Pipeline Output Adjusting Unit
6
//
7
// Implementation:
8
//   This module performs some of the shifts there are needed to
9
//   obtain final results.
10
//
11
//
12
// Authors:     Winnie Cheng <wwcheng@stanford.edu>,
13
//              Peter Wu <peter5@stanford.edu>
14
//
15
 *********************************************************************/
16
 
17
#include "adjust.h"
18
#include "opcode.h"
19
 
20
#ifdef MODULE_NAME
21
#undef MODULE_NAME
22
#endif
23
 
24
#define MODULE_NAME     "adjust"
25
 
26
#define DEBUG           1
27
#if DEBUG
28
#define dprintf         printf
29
#else
30
#define dprintf
31
#endif
32
 
33
void adjust::adjust_process()
34
{
35
    sc_uint<UNIT_SEL_WIDTH> opcode;
36
    short x, y, acc_phase;
37
    short result1, result2;
38
 
39
    // On Reset, initialize output
40
    result_valid.write(true);
41
    out_opcode.write(I_NOP);
42
    out_result1.write(0);
43
    out_result2.write(0);
44
    wait();
45
 
46
    while(1) {
47
 
48
        wait();
49
 
50
        // propagate through
51
        opcode = in_opcode.read();
52
        out_opcode.write(opcode);
53
 
54
        if(in_valid.read()==true){
55
            // Register input
56
            x = in_x.read();
57
            y = in_y.read();
58
            acc_phase = in_acc_phase.read();
59
 
60
            // Adjust according to opcode
61
            if(opcode == I_ROTATE) {
62
 
63
                // Rotate Instruction Format
64
                //   operand1 : orgX
65
                //   operand2 : orgY
66
                //   operand3 : angle
67
                // returns
68
                //   result1 : rotated x-coordinate
69
                //   result2 : rotated y-coordinate
70
 
71
                // Reduce vector size by multiplier
72
                //   (1/2+1/8-1/64-1/512)
73
 
74
                // adjust
75
                result1=(x>>1)+(x>>3)-(x>>6)-(x>>9);
76
                result2=(y>>1)+(y>>3)-(y>>6)-(y>>9);
77
 
78
                // output results
79
                out_result1.write(result1);
80
                out_result2.write(result2);
81
                result_valid.write(true);
82
 
83
                dprintf("[%s] Adjust ROTATE\n", MODULE_NAME);
84
 
85
            } else if (opcode == I_MAGPHASE) {
86
 
87
                // Magphase Instruction Format
88
                //   operand1 : X
89
                //   operand2 : Y
90
                // returns
91
                //   result1 : magnitude
92
                //   result2 : phase
93
 
94
                // adjust
95
                result1 = (x>>1)+(x>>3)-(x>>6)-(x>>9);
96
                result2 = -acc_phase;
97
 
98
                // output results
99
                out_result1.write(result1);
100
                out_result2.write(result2);
101
                result_valid.write(true);
102
 
103
                dprintf("[%s] Adjust MAG-PHASE\n", MODULE_NAME);
104
 
105
            } else if (opcode == I_SINCOS || opcode == I_SINHCOSH) {
106
 
107
                // SinCos/SinhCosh Instruction Format
108
                //   operand1 : phase
109
                // return
110
                //   result1 : sin/sinh(phase)
111
                //   result2 : cos/cosh(phase)
112
 
113
                // no adjustment needed
114
 
115
                // output results
116
                out_result1.write(y);   // sin/sinh result
117
                out_result2.write(x);   // cos/cosh result
118
                result_valid.write(true);
119
 
120
                dprintf("[%s] Adjust SINCOS or SINHCOSH\n", MODULE_NAME);
121
 
122
            } else {
123
                // filter out NOP results
124
                result_valid.write(false);
125
 
126
                dprintf("[%s] Adjust ignored NOP\n", MODULE_NAME);
127
            }
128
 
129
        } else {
130
            result_valid.write(false);
131
            dprintf("[%s] Nothing to adjust\n", MODULE_NAME);
132
        }
133
    } // forever loop   
134
}

powered by: WebSVN 2.1.0

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