-
Notifications
You must be signed in to change notification settings - Fork 42
Expand file tree
/
Copy pathDSP.java
More file actions
169 lines (129 loc) · 4.13 KB
/
DSP.java
File metadata and controls
169 lines (129 loc) · 4.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/**
* Java Grinder
* Author: Michael Kohn
* Email: mike@mikekohn.net
* Web: https://www.mikekohn.net/
* License: GPL
*
* Copyright 2014-2022 by Michael Kohn
*
*/
package net.mikekohn.java_grinder;
abstract public class DSP
{
static long A,B;
protected DSP()
{
}
/** Return value of A (only bits [31:16]) */
public static int getA()
{
short n = (short)(A >> 16);
return (int)n;
}
/** Return value of B (only bits [31:16]) */
public static int getB()
{
short n = (short)(B >> 16);
return (int)n;
}
/** Return value of A (only bits [38:23]) */
public static int getUpperA()
{
short n = (short)(A >> 23);
return (int)n;
}
/** Return value of B (only bits [38:23]) */
public static int getUpperB()
{
short n = (short)(B >> 23);
return (int)n;
}
/** Return value of A (only bits [23:8]) */
public static int getLowerA()
{
short n = (short)(A >> 8);
return (int)n;
}
/** Return value of B (only bits [23:8]) */
public static int getLowerB()
{
short n = (short)(B >> 8);
return (int)n;
}
/** Return value of A rounded */
public static int getRoundedA()
{
return 0;
}
/** Return value of B rounded */
public static int getRoundedB()
{
return 0;
}
/** Clear Accum A */
public static void clearA() { A = 0; }
/** Clear Accum B */
public static void clearB() { B = 0; }
/** Load Accum A */
public static void loadA(int n) { A = n; }
/** Load Accum B */
public static void loadB(int n) { B = n; }
/** Negate Accum A */
public static void negA() { A = -A; }
/** Negate Accum B */
public static void negB() { B = -B; }
/** Add Accum A with Accum B and store in Accum A */
public static void addABAndStoreInA() { A = A + B; }
/** Add Accum A with Accum B and store in Accum B */
public static void addABAndStoreInB() { B = A + B; }
/** Sub Accum A with Accum B (A-B) and store in Accum A */
public static void subABAndStoreInA() { A = A - B; }
/** Sub Accum A with Accum B (B-A) and store in Accum B */
public static void subBAAndStoreInB() { B = B - A; }
/** Add to Accum A */
public static void addToA(int n) { A += n; }
/** Add to Accum B */
public static void addToB(int n) { B += n; }
/** Square and store result in Accum A */
public static void squareToA(int n) { A = n * n; }
/** Square and store result in Accum B */
public static void squareToB(int n) { B = n * n; }
/** Multiply and store result in Accum A */
public static void mulToA(int n, int m) { A = n * m; }
/** Multiply and store result in Accum B */
public static void mulToB(int n, int m) { B = n * m; }
/** Euclidean distance to A */
//public static void euclideanDistanceToA(int n, int m) { }
/** Euclidean distance to B */
//public static void euclideanDistanceToB(int n, int m) { }
/** Square and add result in Accum A */
public static void squareAndAddToA(int n) { A += n * n; }
/** Square and add result in Accum B */
public static void squareAndAddToB(int n) { B += n * n; }
/** Multiply and add result in Accum A */
public static void mulAndAddToA(int n, int m) { A += n * m; }
/** Multiply and add result in Accum B */
public static void mulAndAddToB(int n, int m) { B += n * m; }
/** Multiply and substract result from Accum A */
public static void mulAndSubFromA(int n, int m) { A -= n * m; }
/** Multiply and substract result from Accum B */
public static void mulAndSubFromB(int n, int m) { B -= n * m; }
/** Euclidean distance added to A */
//public static void euclideanDistanceAndAddToA(int n, int m) { }
/** Euclidean distance added to B */
//public static void euclideanDistanceAndAddToB(int n, int m) { }
/** Arithmetic shift accumulator A (-16 to 16 bits only).
Negative n means shift left, positive is shift right. */
public static void shiftA(int n)
{
if (n > 0 && n <= 16) { A = A >> n; }
else if (n < 0 && n >= -16) { A = A << (-n); }
}
/** Arithmetic shift accumulator B (-16 to 16 bits only) */
public static void shiftB(int n)
{
if (n > 0 && n <= 16) { B = B >> n; }
else if (n < 0 && n >= -16) { B = B << (-n); }
}
}