-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathComplexArray2MeC.cs
More file actions
117 lines (111 loc) · 4.5 KB
/
Copy pathComplexArray2MeC.cs
File metadata and controls
117 lines (111 loc) · 4.5 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
using System.Diagnostics;
using System.Numerics;
using System.Runtime.InteropServices;
namespace GigaFFT
{
public class ComplexArray2MeC : MMFArray32MeB
{
private const ulong COMPLEX_SIZE_16_BYTES = 16UL;
private const ulong COMPLEX_ARRAY_16_MEBYTES = 16UL * 1024 * 1024;
private static ulong ComplexSize16Bytes = (ulong)Marshal.SizeOf(typeof(Complex));
private long offsetLO;
private Complex[] bufferLO;
private long offsetHI;
private Complex[] bufferHI;
public ComplexArray2MeC(ulong totalCapacityComplexStructs)
: base(totalCapacityComplexStructs * COMPLEX_SIZE_16_BYTES)
{
checked
{
Debug.Assert(COMPLEX_ARRAY_16_MEBYTES == 16777216UL, "Error in copy paste for COMPLEX_ARRAY_16_MEBYTES. Expected 16777216UL");
Debug.Assert(ComplexSize16Bytes == COMPLEX_SIZE_16_BYTES, "Unexpected value of ComplexSize16Bytes. Expected 16.");
Debug.Assert((totalCapacityComplexStructs / 2) * 2 == totalCapacityComplexStructs, "totalCapacityComplexStructs must be an even ulong");
this.Length = totalCapacityComplexStructs;
this.LengthDiv2 = this.Length / 2;
this.offsetLO = -1;
this.bufferLO = new Complex[4096];
this.offsetHI = -1;
this.bufferHI = new Complex[4096];
}
}
public ulong Length
{
get;
private set;
}
private ulong LengthDiv2
{
get;
set;
}
public Complex this[ulong index]
{
get
{
ushort immva = (ushort)((index * COMPLEX_SIZE_16_BYTES) / COMPLEX_ARRAY_16_MEBYTES);
long offset = (long)((index * COMPLEX_SIZE_16_BYTES) - (immva * COMPLEX_ARRAY_16_MEBYTES));
Debug.Assert(offset >= 0);
if (index < this.LengthDiv2)
{
if (immva != this.immvaLO)
{
this.immvaLO = immva;
this.mmvaLO.Dispose();
this.mmvaLO = this.files[immva].CreateViewAccessor();
this.offsetLO = -1;
}
if (this.offsetLO != (offset & 0x7FFFFFFFFFFF0000L))
{
this.offsetLO = offset & 0x7FFFFFFFFFFF0000L;
this.mmvaLO.ReadArray<Complex>(offsetLO, this.bufferLO, 0, 4096);
}
//this.mmvaLO.Read(offset, out result);
return this.bufferLO[index % 0x1000];
}
else
{
if (immva != this.immvaHI)
{
this.immvaHI = immva;
this.mmvaHI.Dispose();
this.mmvaHI = this.files[immva].CreateViewAccessor();
this.offsetLO = -1;
}
if (this.offsetHI != (offset & 0x7FFFFFFFFFFF0000L))
{
this.offsetHI = offset & 0x7FFFFFFFFFFF0000L;
this.mmvaHI.ReadArray<Complex>(offsetHI, this.bufferHI, 0, 4096);
}
//this.mmvaHI.Read(offset, out result);
return this.bufferHI[index % 0x1000];
}
}
set
{
ushort immva = (ushort)((index * COMPLEX_SIZE_16_BYTES) / COMPLEX_ARRAY_16_MEBYTES);
long offset = (long)((index * COMPLEX_SIZE_16_BYTES) - (immva * COMPLEX_ARRAY_16_MEBYTES));
Debug.Assert(offset >= 0);
if (index < this.LengthDiv2)
{
if (immva != this.immvaLO)
{
this.immvaLO = immva;
this.mmvaLO.Dispose();
this.mmvaLO = this.files[immva].CreateViewAccessor();
}
this.mmvaLO.Write(offset, ref value);
}
else
{
if (immva != this.immvaHI)
{
this.immvaHI = immva;
this.mmvaHI.Dispose();
this.mmvaHI = this.files[immva].CreateViewAccessor();
}
this.mmvaHI.Write(offset, ref value);
}
}
}
}
}