// File: /workspace/github_cpp_makefile_star2_O1/kebwi[P]Trifid/src/FourierTransform.cpp
// Function: fourierTest()
void fourierTest()
{
	SeedRandom(0);
	
	cout << "Float type sizes on this machine:" << endl;
	cout << "    float:       " << sizeof(float) << endl;
	cout << "    double:      " << sizeof(double) << endl;
	cout << "    long double: " << sizeof(long double) << endl;
	cout << endl;
	
	cout << "Fourier Transform correctness test:" << endl;
	cout << "This test being performed with a floating point type of size: " << sizeof(Float_t) << endl;
	cout << "See FloatType.h for information on how to set the floating point type." << endl;
	cout << endl;
	
	Float_t a[16];
	for (int j = 0; j < 4; j++)
		for (int i = 0; i < 4; i++)
			a[j * 4 + i] = RandZeroFloat(1.0);
	
	cout.precision(8);
	cout << "Input array and copy/paste for matlab script:" << endl;
	cout << "a = [ ";
	for (int j = 0; j < 4; j++)
		for (int i = 0; i < 4; i++)
		{
			cout << a[j * 4 + i];
			if (i != 4 - 1)
				cout << ", ";
			else if (j != 4 - 1)
				cout << "; ";
			else cout << " ]" << endl;
		}
	cout << "b = fft2(a)" << endl;
	cout << "c = ifft2(b)" << endl;
	cout << endl;
	
	cout << "Original signal:" << endl;
	for (int j = 0; j < 4; j++)
	{
		for (int i = 0; i < 4; i++)
			cout << setw(15) << a[j * 4 + i];
		cout << endl;
	}
	cout << endl;
	
	int err = fft2dInit(log2(4), log2(4));
	if (err != 0)
		cout << err << endl;
	
	rfft2d(a, log2(4), log2(4));
	
	cout << "Fourier Transform:" << endl;
	for (int j = 0; j < 4; j++)
	{
		for (int i = 0; i < 4; i++)
			cout << setw(15) << a[j * 4 + i];
		cout << endl;
	}
	cout << endl;
	
	rifft2d(a, log2(4), log2(4));
	
	cout << "Inverse Fourier Transform (should match original signal above):" << endl;
	for (int j = 0; j < 4; j++)
	{
		for (int i = 0; i < 4; i++)
			cout << setw(15) << a[j * 4 + i];
		cout << endl;
	}
	cout << endl;
	
	//=======================================================================
	
	cout << "Fourier Transform timing test" << endl;
	cout << "This test being performed with a floating point type of size: " << sizeof(Float_t) << endl;
	cout << "See FloatType.h for information on how to set the floating point type." << endl;
	cout << endl;
	
	int dim = 512;
	Float_t *a2 = new Float_t[dim * dim];
	for (int j = 0; j < dim; j++)
		for (int i = 0; i < dim; i++)
			a2[j * dim + i] = RandZeroFloat(1.0);
	
	err = fft2dInit(log2(dim), log2(dim));
	if (err != 0)
		cout << err << endl;
	
	Float_t meanTime_s = 0;
	int numPasses = 100;
	for (int i = 0; i < numPasses; i++)
	{
		unsigned long startTime = getCurrentTime_ms();
		rfft2d(a2, log2(dim), log2(dim));
		unsigned long elapsedTime = getCurrentTime_ms() - startTime;
		meanTime_s += (Float_t)elapsedTime / CURRENT_TIME_PER_SEC_F;
	}
	meanTime_s /= (Float_t)numPasses;
	cout << "Mean time to perform 2D Fourier Transform on a " << dim << " x " << dim << " image: "
		<< meanTime_s << " seconds" << endl << endl;
	
	delete [] a2;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x98, %rsp
xorl %r15d, %r15d
xorl %edi, %edi
callq 0x2326b
movq 0x1c9a9(%rip), %rbx     # 0x36fd0
leaq 0x1391b(%rip), %rsi     # 0x2df49
movl $0x21, %edx
movq %rbx, %rdi
callq 0x3360
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x32e0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31f0
leaq 0x13902(%rip), %rsi     # 0x2df6b
movl $0x11, %edx
movq %rbx, %rdi
callq 0x3360
movl $0x4, %esi
movq %rbx, %rdi
callq 0x31e0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x32e0
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31f0
leaq 0x138c9(%rip), %rsi     # 0x2df7d
movl $0x11, %edx
movq %rbx, %rdi
callq 0x3360
movl $0x8, %esi
movq %rbx, %rdi
callq 0x31e0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x32e0
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31f0
leaq 0x13890(%rip), %rsi     # 0x2df8f
movl $0x11, %edx
movq %rbx, %rdi
callq 0x3360
movl $0x10, %esi
movq %rbx, %rdi
callq 0x31e0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x32e0
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31f0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x32e0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31f0
leaq 0x13830(%rip), %rsi     # 0x2dfa1
movl $0x23, %edx
movq %rbx, %rdi
callq 0x3360
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x32e0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31f0
leaq 0x13819(%rip), %rsi     # 0x2dfc5
movl $0x3e, %edx
movq %rbx, %rdi
callq 0x3360
movl $0x8, %esi
movq %rbx, %rdi
callq 0x31e0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x32e0
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31f0
leaq 0x1380d(%rip), %rsi     # 0x2e004
movl $0x46, %edx
movq %rbx, %rdi
callq 0x3360
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x32e0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31f0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x32e0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31f0
leaq 0x10(%rsp), %r14
xorl %r12d, %r12d
movsd 0x107f6(%rip), %xmm0    # 0x2b058
callq 0x2329f
movsd %xmm0, (%r14,%r12,8)
incq %r12
cmpq $0x4, %r12
jne 0x1a85a
incq %r15
addq $0x20, %r14
cmpq $0x4, %r15
jne 0x1a857
movq (%rbx), %rax
movq -0x18(%rax), %rax
movq $0x8, 0x8(%rbx,%rax)
leaq 0x137b1(%rip), %rsi     # 0x2e04b
movl $0x2d, %edx
movq %rbx, %rdi
callq 0x3360
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x32e0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31f0
leaq 0x137a4(%rip), %rsi     # 0x2e079
movl $0x6, %edx
movq %rbx, %rdi
callq 0x3360
leaq 0x10(%rsp), %r13
xorl %ebp, %ebp
leaq 0x13790(%rip), %r15     # 0x2e080
leaq 0x12b68(%rip), %r12     # 0x2d45f
xorl %r14d, %r14d
movsd (%r13,%r14,8), %xmm0
movq %rbx, %rdi
callq 0x3480
movl $0x2, %edx
movq %rbx, %rdi
cmpq $0x3, %r14
jne 0x1a952
cmpq $0x3, %rbp
jne 0x1a957
leaq 0x1375f(%rip), %rsi     # 0x2e083
callq 0x3360
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x32e0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31f0
jmp 0x1a95f
movq %r12, %rsi
jmp 0x1a95a
movq %r15, %rsi
callq 0x3360
incq %r14
cmpq $0x4, %r14
jne 0x1a8fa
incq %rbp
addq $0x20, %r13
cmpq $0x4, %rbp
jne 0x1a8f7
leaq 0x1370a(%rip), %rsi     # 0x2e086
movl $0xb, %edx
movq %rbx, %rdi
callq 0x3360
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x32e0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31f0
leaq 0x136db(%rip), %rsi     # 0x2e092
movl $0xc, %edx
movq %rbx, %rdi
callq 0x3360
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x32e0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31f0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x32e0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31f0
leaq 0x13686(%rip), %rsi     # 0x2e09f
movl $0x10, %edx
movq %rbx, %rdi
callq 0x3360
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x32e0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31f0
leaq 0x10(%rsp), %r14
xorl %r15d, %r15d
xorl %r12d, %r12d
movq (%rbx), %rax
movq -0x18(%rax), %rax
movq $0xf, 0x10(%rbx,%rax)
movsd (%r14,%r12,8), %xmm0
movq %rbx, %rdi
callq 0x3480
incq %r12
cmpq $0x4, %r12
jne 0x1aa58
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x32e0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31f0
incq %r15
addq $0x20, %r14
cmpq $0x4, %r15
jne 0x1aa55
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x32e0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31f0
movl $0x2, %edi
movl $0x2, %esi
callq 0x23658
testl %eax, %eax
je 0x1ab25
movq 0x1c4dc(%rip), %rdi     # 0x36fd0
movl %eax, %esi
callq 0x34e0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x32e0
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31f0
leaq 0x10(%rsp), %r14
movl $0x2, %esi
movl $0x2, %edx
movq %r14, %rdi
callq 0x2407f
leaq 0x1356d(%rip), %rsi     # 0x2e0b0
movl $0x12, %edx
movq %rbx, %rdi
callq 0x3360
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x32e0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31f0
xorl %r15d, %r15d
xorl %r12d, %r12d
movq (%rbx), %rax
movq -0x18(%rax), %rax
movq $0xf, 0x10(%rbx,%rax)
movsd (%r14,%r12,8), %xmm0
movq %rbx, %rdi
callq 0x3480
incq %r12
cmpq $0x4, %r12
jne 0x1ab7d
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x32e0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31f0
incq %r15
addq $0x20, %r14
cmpq $0x4, %r15
jne 0x1ab7a
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x32e0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31f0
leaq 0x10(%rsp), %r14
movl $0x2, %esi
movl $0x2, %edx
movq %r14, %rdi
callq 0x243ac
leaq 0x134a6(%rip), %rsi     # 0x2e0c3
movl $0x3f, %edx
movq %rbx, %rdi
callq 0x3360
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x32e0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31f0
xorl %r15d, %r15d
xorl %r12d, %r12d
movq (%rbx), %rax
movq -0x18(%rax), %rax
movq $0xf, 0x10(%rbx,%rax)
movsd (%r14,%r12,8), %xmm0
movq %rbx, %rdi
callq 0x3480
incq %r12
cmpq $0x4, %r12
jne 0x1ac57
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x32e0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31f0
incq %r15
addq $0x20, %r14
cmpq $0x4, %r15
jne 0x1ac54
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x32e0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31f0
leaq 0x13423(%rip), %rsi     # 0x2e103
movl $0x1d, %edx
movq %rbx, %rdi
callq 0x3360
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x32e0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31f0
leaq 0x132aa(%rip), %rsi     # 0x2dfc5
movl $0x3e, %edx
movq %rbx, %rdi
callq 0x3360
movl $0x8, %esi
movq %rbx, %rdi
callq 0x31e0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x32e0
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31f0
leaq 0x1329e(%rip), %rsi     # 0x2e004
movl $0x46, %edx
movq %rbx, %rdi
callq 0x3360
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x32e0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31f0
movq (%rbx), %rax
movq -0x18(%rax), %rdi
addq %rbx, %rdi
movl $0xa, %esi
callq 0x32e0
movsbl %al, %esi
movq %rbx, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31f0
movl $0x200000, %edi         # imm = 0x200000
callq 0x3030
movq %rax, %rbx
xorl %r14d, %r14d
movq %rax, %r15
xorl %r12d, %r12d
movsd 0x10279(%rip), %xmm0    # 0x2b058
callq 0x2329f
movsd %xmm0, (%r15,%r12,8)
incq %r12
cmpq $0x200, %r12            # imm = 0x200
jne 0x1add7
incq %r14
addq $0x1000, %r15           # imm = 0x1000
cmpq $0x200, %r14            # imm = 0x200
jne 0x1add4
movl $0x9, %edi
movl $0x9, %esi
callq 0x23658
testl %eax, %eax
je 0x1ae54
movq 0x1c1ad(%rip), %rdi     # 0x36fd0
movl %eax, %esi
callq 0x34e0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x32e0
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31f0
xorpd %xmm0, %xmm0
movl $0x64, %ebp
movsd %xmm0, 0x8(%rsp)
callq 0x4288
movq %rax, %r14
movl $0x9, %esi
movl $0x9, %edx
movq %rbx, %rdi
callq 0x2407f
callq 0x4288
subq %r14, %rax
movq %rax, %xmm0
punpckldq 0x1018e(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x10196(%rip), %xmm0    # 0x2b030
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movsd 0x8(%rsp), %xmm0
divsd 0x12ce4(%rip), %xmm1    # 0x2db98
addsd %xmm1, %xmm0
decl %ebp
jne 0x1ae5d
divsd 0x11cc4(%rip), %xmm0    # 0x2cb88
movsd %xmm0, 0x8(%rsp)
movq 0x1c0ff(%rip), %r14     # 0x36fd0
leaq 0x13249(%rip), %rsi     # 0x2e121
movl $0x2f, %edx
movq %r14, %rdi
callq 0x3360
movq %r14, %rdi
movl $0x200, %esi            # imm = 0x200
callq 0x34e0
movq %rax, %r14
leaq 0x13255(%rip), %rsi     # 0x2e151
movl $0x3, %edx
movq %rax, %rdi
callq 0x3360
movq %r14, %rdi
movl $0x200, %esi            # imm = 0x200
callq 0x34e0
movq %rax, %r14
leaq 0x13235(%rip), %rsi     # 0x2e155
movl $0x8, %edx
movq %rax, %rdi
callq 0x3360
movq %r14, %rdi
movsd 0x8(%rsp), %xmm0
callq 0x3480
movq %rax, %r14
leaq 0x13219(%rip), %rsi     # 0x2e15e
movl $0x8, %edx
movq %rax, %rdi
callq 0x3360
movq (%r14), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x32e0
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31f0
movq %rax, %r14
movq (%rax), %rax
movq -0x18(%rax), %rdi
addq %r14, %rdi
movl $0xa, %esi
callq 0x32e0
movsbl %al, %esi
movq %r14, %rdi
callq 0x3040
movq %rax, %rdi
callq 0x31f0
movq %rbx, %rdi
callq 0x33c0
addq $0x98, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
nopl (%rax)