// File: /workspace/github_cpp_makefile_star2_O3/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 0x22fff
movq 0x1ce50(%rip), %rbx     # 0x36fd0
leaq 0x12dfa(%rip), %rsi     # 0x2cf81
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 0x12de1(%rip), %rsi     # 0x2cfa3
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 0x12da8(%rip), %rsi     # 0x2cfb5
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 0x12d6f(%rip), %rsi     # 0x2cfc7
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 0x12d0f(%rip), %rsi     # 0x2cfd9
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 0x12cf8(%rip), %rsi     # 0x2cffd
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 0x12cec(%rip), %rsi     # 0x2d03c
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 0xfc9d(%rip), %xmm0     # 0x2a058
callq 0x23033
movsd %xmm0, (%r14,%r12,8)
incq %r12
cmpq $0x4, %r12
jne 0x1a3b3
incq %r15
addq $0x20, %r14
cmpq $0x4, %r15
jne 0x1a3b0
movq (%rbx), %rax
movq -0x18(%rax), %rax
movq $0x8, 0x8(%rbx,%rax)
leaq 0x12c90(%rip), %rsi     # 0x2d083
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 0x12c83(%rip), %rsi     # 0x2d0b1
movl $0x6, %edx
movq %rbx, %rdi
callq 0x3360
leaq 0x10(%rsp), %r12
xorl %r13d, %r13d
leaq 0x1201d(%rip), %r14     # 0x2c467
leaq 0x12c67(%rip), %r15     # 0x2d0b8
movq %r13, %rax
shlq $0x5, %rax
movsd 0x10(%rsp,%rax), %xmm0
movq %rbx, %rdi
callq 0x3480
movl $0x1, %ebp
movl $0x2, %edx
movq %rbx, %rdi
movq %r14, %rsi
callq 0x3360
movsd (%r12,%rbp,8), %xmm0
movq %rbx, %rdi
callq 0x3480
incq %rbp
cmpq $0x4, %rbp
jne 0x1a46b
cmpq $0x3, %r13
je 0x1a4b1
movl $0x2, %edx
movq %rbx, %rdi
movq %r15, %rsi
callq 0x3360
incq %r13
addq $0x20, %r12
jmp 0x1a451
leaq 0x12c03(%rip), %rsi     # 0x2d0bb
movl $0x2, %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 0x12bcb(%rip), %rsi     # 0x2d0be
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 0x12b9c(%rip), %rsi     # 0x2d0ca
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 0x12b47(%rip), %rsi     # 0x2d0d7
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 0x1a5cf
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 0x1a5cc
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 0x233f4
testl %eax, %eax
je 0x1a69c
movq 0x1c965(%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 0x23e14
leaq 0x12a2e(%rip), %rsi     # 0x2d0e8
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 0x1a6f4
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 0x1a6f1
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 0x24141
leaq 0x12967(%rip), %rsi     # 0x2d0fb
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 0x1a7ce
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 0x1a7cb
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 0x128e4(%rip), %rsi     # 0x2d13b
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 0x1276b(%rip), %rsi     # 0x2cffd
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 0x1275f(%rip), %rsi     # 0x2d03c
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 0xf702(%rip), %xmm0     # 0x2a058
callq 0x23033
movsd %xmm0, (%r15,%r12,8)
incq %r12
cmpq $0x200, %r12            # imm = 0x200
jne 0x1a94e
incq %r14
addq $0x1000, %r15           # imm = 0x1000
cmpq $0x200, %r14            # imm = 0x200
jne 0x1a94b
movl $0x9, %edi
movl $0x9, %esi
callq 0x233f4
testl %eax, %eax
je 0x1a9cb
movq 0x1c636(%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 0x23e14
callq 0x4288
subq %r14, %rax
movq %rax, %xmm0
punpckldq 0xf617(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0xf61f(%rip), %xmm0     # 0x2a030
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movsd 0x8(%rsp), %xmm0
divsd 0x121a5(%rip), %xmm1    # 0x2cbd0
addsd %xmm1, %xmm0
decl %ebp
jne 0x1a9d4
divsd 0x11135(%rip), %xmm0    # 0x2bb70
movsd %xmm0, 0x8(%rsp)
movq 0x1c588(%rip), %r14     # 0x36fd0
leaq 0x1270a(%rip), %rsi     # 0x2d159
movl $0x2f, %edx
movq %r14, %rdi
callq 0x3360
movq %r14, %rdi
movl $0x200, %esi            # imm = 0x200
callq 0x34e0
movq %rax, %r14
leaq 0x12716(%rip), %rsi     # 0x2d189
movl $0x3, %edx
movq %rax, %rdi
callq 0x3360
movq %r14, %rdi
movl $0x200, %esi            # imm = 0x200
callq 0x34e0
movq %rax, %r14
leaq 0x126f6(%rip), %rsi     # 0x2d18d
movl $0x8, %edx
movq %rax, %rdi
callq 0x3360
movq %r14, %rdi
movsd 0x8(%rsp), %xmm0
callq 0x3480
movq %rax, %r14
leaq 0x126da(%rip), %rsi     # 0x2d196
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