#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <math.h>

#define DOWNSAMPLE 25
#define SAMPLE_FREQ 800e6
#define LO_FREQ 302e6
#define THREADS_PER_BLOCK 512
#define BLOCKS_PER_GRID 32 * DOWNSAMPLE
 // keeps things a multiple of COS_TABLE_LENGTH to avoid edge effects
#define BLOCK_SIZE THREADS_PER_BLOCK * BLOCKS_PER_GRID
#define SECONDS_OF_DATA 10
#define COS_TABLE_LENGTH 8000
 // how many loops of block size to do
#define INPUT_SCALE 1.0f
 // input may need scaling to see tones clearly...

__constant__ float cTaps[512];
cudaEvent_t t_start, t_stop;
__constant__ float cCos[COS_TABLE_LENGTH];

__global__ void mix(char *input_buffer, float *output_buffer, int lo_interval, int cos_table_length, int lo_offset)
{
 int idx = blockIdx.x*blockDim.x + threadIdx.x;
 float mix_value = (float)cCos[(lo_interval*idx) % cos_table_length + lo_offset] * ((float)input_buffer[idx + blockDim.x] / INPUT_SCALE);

 output_buffer[idx + blockDim.x] = mix_value;
  // when mixing we skip the first blockDim.x (the number of threads) worth of input buffer (i.e. the memory portion)
}

__global__ void simple_fir(float *input_buffer, float *output_buffer, int no_taps, int upsample, int downsample, int poly_interval, int lo_interval, int cos_table_length)
{
 float temp_output = 0;
 int fir_idx = (blockIdx.x*blockDim.x + threadIdx.x)*downsample + blockDim.x;
    // idx starts from end of memory buffer which is blockDim.x in length

 for (int i=0; i < no_taps; i++) {
  temp_output += cTaps[i] * (float)input_buffer[fir_idx - i];
 }
 output_buffer[blockIdx.x*blockDim.x + threadIdx.x] = temp_output * (downsample / 8.0f);
}

__global__ void float_cast(float *in, char *out)
{
 int idx = blockDim.x*blockIdx.x + threadIdx.x;
 out[idx] = (char) in[idx];
}

int main(int argc, char **argv) {
 int write_block = BLOCK_SIZE;
  // 1 MB worth of data at a time...
  // this should be enough to allow at least a couple of output points per thread when tap overlap 
 int sample_rate = SAMPLE_FREQ;
  // our adc sampling frequency
 int upsample = 1;
 int downsample = DOWNSAMPLE;
  // coefficients to sort out the output sample rate
  // in this case giving us 128 MHz sampling
 int lo_freq = LO_FREQ;
  // the mixing frequency for the DDC
 int cos_table_length = COS_TABLE_LENGTH;
  // the number of samples in the sin lookup table
 int cos_table_size = sizeof(float) * cos_table_length;
 int lo_interval = int(((float)cos_table_length / sample_rate) * lo_freq);
  // the stepping interval through the lo sin table. May result in slightly different lo_freq from that
  // specified. The user is informed of this.
 int lo_offset = 0;
  // as we move from block to block our we need an lo_offset to maintain phase...
 int lo_remainder = (write_block * lo_interval) % cos_table_length;
  // the remainder at the end of each loop (i.e. the last point per block from the loop)
 int no_taps = 0;
  // number of filter taps. Calculated once filter data is loaded.
 int no_output_samples = int(((float)write_block / downsample));
  // overall number of output samples to produce for this block
 int loops = int(SECONDS_OF_DATA * (sample_rate / (float)write_block));
 fprintf(stderr,"%i, %i, %i, %i\n", loops, SECONDS_OF_DATA, sample_rate, write_block);

 int fh;
 char *data_file;
 char *fir_taps_file;
 float et;
 struct stat stat_buf;

 float *fir_taps;
 char *base_buffer;
 char *host_char_buffer;
 float *output_buffer;
 float *upsample_buffer;
 float *cos_table;
  // host buffers

 char *device_char_buffer;
 char *memory_buffer;
 float *device_fir_taps;
 float *device_output_buffer;
 float *device_upsample_buffer;
 float *device_float_buffer;
 float *device_fir_buffer;
  // device buffers

 if (argc > 2) {
  data_file = argv[1];
  fir_taps_file = argv[2];
 } else { printf("Please supply both data and fir_taps filenames...\n"); return -1;}

 fprintf(stderr,"Producing %i output samples per block (%i samples).\n",no_output_samples,write_block);

 base_buffer = (char*)malloc(write_block);
 host_char_buffer = (char*)malloc(no_output_samples);
 output_buffer = (float*)malloc(sizeof(float) * no_output_samples);
 upsample_buffer = (float*)malloc(sizeof(float) * upsample * (write_block + THREADS_PER_BLOCK));
 cos_table = (float*)malloc(cos_table_size);
 memset(host_char_buffer, (char) 0, no_output_samples);
 memset(base_buffer, (char) 0, write_block);
 memset(upsample_buffer, (char) 0, sizeof(float) * upsample * (write_block + THREADS_PER_BLOCK));
  // zero as we use part of this for our initial zero padding block

 fh = open(fir_taps_file, O_RDONLY);
 fstat(fh, &stat_buf);
 no_taps = stat_buf.st_size / sizeof(float);
 fprintf(stderr,"Using %i tap FIR filter.\n",no_taps);
 fir_taps = (float*)malloc(sizeof(float) * no_taps);
 read(fh, fir_taps, sizeof(float) * no_taps);
 close(fh);

 fprintf(stderr,"Preparing sin lookup table...\n");
 for (int i=0; i < cos_table_length; i++) {
  cos_table[i] = 2 * cos(i * (2*M_PI/cos_table_length));
 }

 fprintf(stderr,"Allocating block storage on GPU...\n");

 cudaEventCreate(&t_start);
 cudaEventCreate(&t_stop);

 cudaMalloc((void**)&device_char_buffer, write_block + THREADS_PER_BLOCK);
  // device buffer with space for initial zero padding
 cudaMalloc((void**)&memory_buffer, THREADS_PER_BLOCK);
  // previous loop memory
 cudaMalloc((void**)&device_output_buffer, sizeof(float) * no_output_samples);
 cudaMalloc((void**)&device_float_buffer, sizeof(float) * write_block);
 cudaMalloc((void**)&device_upsample_buffer, sizeof(float) * upsample * (write_block + THREADS_PER_BLOCK));
 cudaMalloc((void**)&device_fir_buffer, sizeof(float) * upsample * write_block);
 cudaMalloc((void**)&device_fir_taps, sizeof(float) * no_taps);
  // allocate the device storage

 cudaMemcpy(device_fir_taps, fir_taps, sizeof(float) * no_taps, cudaMemcpyHostToDevice);
  // copy the filter taps to the device
 cudaMemcpyToSymbol(cTaps, fir_taps, sizeof(float) * no_taps);
 cudaMemcpyToSymbol(cCos, cos_table, cos_table_size);
 cudaMemcpy(device_upsample_buffer, upsample_buffer, sizeof(float) * upsample * write_block, cudaMemcpyHostToDevice);
 cudaMemcpy(device_output_buffer, upsample_buffer, sizeof(float) * no_output_samples, cudaMemcpyHostToDevice);
 cudaMemcpy(device_fir_buffer, upsample_buffer, sizeof(float) * upsample * write_block, cudaMemcpyHostToDevice);
 cudaMemcpy(device_float_buffer, upsample_buffer, sizeof(float) * write_block, cudaMemcpyHostToDevice);
 cudaMemcpy(device_char_buffer, base_buffer, write_block + THREADS_PER_BLOCK, cudaMemcpyHostToDevice);
 cudaMemcpy(memory_buffer, base_buffer, THREADS_PER_BLOCK, cudaMemcpyHostToDevice);
  // init host memory to zero

 fprintf(stderr,"Actual lo freq is: %f MHz (interval: %i, reminader: %i)\n", (lo_interval / ((float)cos_table_length / sample_rate)) / 1e6, lo_interval, lo_remainder);
 fprintf(stderr,"GPU Configuration: blocks per grid: %i, threads per block: %i\n",BLOCKS_PER_GRID, THREADS_PER_BLOCK);

 fh = open(data_file, O_LARGEFILE);
// read(fh, base_buffer, write_block * LOOPS);
 fprintf(stderr,"Producing %.2f s of data (%i loops reading a total of %.2f Mbytes of data)\n", loops * (write_block / float(sample_rate)), loops, loops * (write_block / float(1024*1024)));

 for (int i=0; i <= loops; i++) {
  read(fh, base_buffer, write_block);

  //start = i * write_block;
  //fprintf(stderr,"Loop %i (start: %li, lo_offset: %i).\n",i,start, lo_offset);

  cudaEventRecord(t_start, 0);

  cudaMemcpy(device_char_buffer+THREADS_PER_BLOCK, base_buffer, write_block, cudaMemcpyHostToDevice);
   // need to recal lo_offset each loop
  lo_offset = (i * lo_remainder) % cos_table_length;
   // on the offchance that each block does not loop through the cos table exactly
   // we adjust the starting offset to match the end of the previous loop

   // polyphase method
  int poly_interval = 0;
   // hardcoded for now... l = 4; m = 25
  dim3 threads(THREADS_PER_BLOCK, 1);
   // the downsample spaced blocks are indexed by thread.x and the upsample number of fir filters are indexed by y
  dim3 blocks(BLOCKS_PER_GRID / downsample,1);

  mix<<<BLOCKS_PER_GRID, THREADS_PER_BLOCK>>>(device_char_buffer, device_float_buffer, lo_interval, cos_table_length, lo_offset);
  //poly_fir<<<blocks, threads>>>(device_char_buffer, memory_buffer, device_output_buffer, no_taps, upsample, downsample, poly_interval, lo_interval, cos_table_length);
  simple_fir<<<blocks, threads>>>(device_float_buffer, device_output_buffer, no_taps, upsample, downsample, poly_interval, lo_interval, cos_table_length);
  float_cast<<<no_output_samples/THREADS_PER_BLOCK, THREADS_PER_BLOCK>>>(device_output_buffer, device_char_buffer);
  //fill_memory_buffer<<<1, THREADS_PER_BLOCK>>>(device_char_buffer, memory_buffer, write_block - THREADS_PER_BLOCK);
   // fill memory buffer for next loop
  cudaMemcpy(host_char_buffer, device_char_buffer, no_output_samples, cudaMemcpyDeviceToHost);
  cudaMemcpy(device_char_buffer, base_buffer + write_block - THREADS_PER_BLOCK, THREADS_PER_BLOCK, cudaMemcpyHostToDevice);
   // prime memory buffer for next trip

  cudaEventRecord(t_stop, 0);
  cudaEventSynchronize(t_stop);
  cudaEventElapsedTime(&et, t_start, t_stop);
  if (i == 0) {for (int j=0; j < 20; j++) { fprintf(stderr,"%i ",host_char_buffer[j]); }}
  write(1, host_char_buffer, no_output_samples);
  //write(1, output_buffer, sizeof(float) * no_output_samples);
  //if (i % 20 == 0) fprintf(stderr,"Loop done. CUDA time is %f ms\n", et);
 }
 read(1, output_buffer, 1);
 return 0;
}

	.file	"tmpxft_00395d16_00000000-6_ddc_16m.cudafe1.cpp"
	.text
#APP

#NO_APP
	.type	_ZL26__cudaUnregisterBinaryUtilv, @function
_ZL26__cudaUnregisterBinaryUtilv:
.LFB2047:
	.cfi_startproc
	endbr64
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	jmp	__cudaUnregisterFatBinary@PLT
	.cfi_endproc
.LFE2047:
	.size	_ZL26__cudaUnregisterBinaryUtilv, .-_ZL26__cudaUnregisterBinaryUtilv
	.globl	_Z27__device_stub__Z3mixPcPfiiiPcPfiii
	.type	_Z27__device_stub__Z3mixPcPfiiiPcPfiii, @function
_Z27__device_stub__Z3mixPcPfiiiPcPfiii:
.LFB2069:
	.cfi_startproc
	endbr64
	subq	$152, %rsp
	.cfi_def_cfa_offset 160
	movq	%rdi, 24(%rsp)
	leaq	48(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	60(%rsp), %rsi
	movl	%edx, 12(%rsp)
	leaq	32(%rsp), %rdx
	movl	%ecx, 8(%rsp)
	leaq	40(%rsp), %rcx
	movl	%r8d, 4(%rsp)
	movq	%fs:40, %rax
	movq	%rax, 136(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 56(%rsp)
	movq	%rax, 96(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 104(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	4(%rsp), %rax
	movq	%rax, 128(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 48(%rsp)
	movq	%rax, 60(%rsp)
	movl	$1, 68(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L2
	pushq	40(%rsp)
	.cfi_def_cfa_offset 168
	leaq	_Z3mixPcPfiii(%rip), %rdi
	pushq	40(%rsp)
	.cfi_def_cfa_offset 176
	movq	76(%rsp), %rcx
	movl	84(%rsp), %r8d
	movq	64(%rsp), %rsi
	movl	72(%rsp), %edx
	leaq	112(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 168
	popq	%rdx
	.cfi_def_cfa_offset 160
.L2:
	movq	136(%rsp), %rax
	subq	%fs:40, %rax
	je	.L4
	call	__stack_chk_fail@PLT
.L4:
	addq	$152, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2069:
	.size	_Z27__device_stub__Z3mixPcPfiiiPcPfiii, .-_Z27__device_stub__Z3mixPcPfiiiPcPfiii
	.globl	_Z3mixPcPfiii
	.type	_Z3mixPcPfiii, @function
_Z3mixPcPfiii:
.LFB2070:
	.cfi_startproc
	endbr64
	jmp	_Z27__device_stub__Z3mixPcPfiiiPcPfiii
	.cfi_endproc
.LFE2070:
	.size	_Z3mixPcPfiii, .-_Z3mixPcPfiii
	.globl	_Z38__device_stub__Z10simple_firPfS_iiiiiiPfS_iiiiii
	.type	_Z38__device_stub__Z10simple_firPfS_iiiiiiPfS_iiiiii, @function
_Z38__device_stub__Z10simple_firPfS_iiiiiiPfS_iiiiii:
.LFB2071:
	.cfi_startproc
	endbr64
	subq	$184, %rsp
	.cfi_def_cfa_offset 192
	movq	%rdi, 24(%rsp)
	leaq	56(%rsp), %rdi
	movq	%rsi, 16(%rsp)
	leaq	68(%rsp), %rsi
	movl	%edx, 12(%rsp)
	leaq	40(%rsp), %rdx
	movl	%ecx, 8(%rsp)
	leaq	48(%rsp), %rcx
	movl	%r8d, 4(%rsp)
	movl	%r9d, (%rsp)
	movq	%fs:40, %rax
	movq	%rax, 168(%rsp)
	xorl	%eax, %eax
	leaq	24(%rsp), %rax
	movl	$1, 64(%rsp)
	movq	%rax, 104(%rsp)
	leaq	16(%rsp), %rax
	movq	%rax, 112(%rsp)
	leaq	12(%rsp), %rax
	movq	%rax, 120(%rsp)
	leaq	8(%rsp), %rax
	movq	%rax, 128(%rsp)
	leaq	4(%rsp), %rax
	movq	%rax, 136(%rsp)
	movq	%rsp, %rax
	movq	%rax, 144(%rsp)
	leaq	192(%rsp), %rax
	movq	%rax, 152(%rsp)
	leaq	200(%rsp), %rax
	movq	%rax, 160(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 56(%rsp)
	movq	%rax, 68(%rsp)
	movl	$1, 76(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L8
	pushq	48(%rsp)
	.cfi_def_cfa_offset 200
	leaq	_Z10simple_firPfS_iiiiii(%rip), %rdi
	pushq	48(%rsp)
	.cfi_def_cfa_offset 208
	movq	84(%rsp), %rcx
	movl	92(%rsp), %r8d
	movq	72(%rsp), %rsi
	movl	80(%rsp), %edx
	leaq	120(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 200
	popq	%rdx
	.cfi_def_cfa_offset 192
.L8:
	movq	168(%rsp), %rax
	subq	%fs:40, %rax
	je	.L10
	call	__stack_chk_fail@PLT
.L10:
	addq	$184, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2071:
	.size	_Z38__device_stub__Z10simple_firPfS_iiiiiiPfS_iiiiii, .-_Z38__device_stub__Z10simple_firPfS_iiiiiiPfS_iiiiii
	.globl	_Z10simple_firPfS_iiiiii
	.type	_Z10simple_firPfS_iiiiii, @function
_Z10simple_firPfS_iiiiii:
.LFB2072:
	.cfi_startproc
	endbr64
	jmp	_Z38__device_stub__Z10simple_firPfS_iiiiiiPfS_iiiiii
	.cfi_endproc
.LFE2072:
	.size	_Z10simple_firPfS_iiiiii, .-_Z10simple_firPfS_iiiiii
	.globl	_Z32__device_stub__Z10float_castPfPcPfPc
	.type	_Z32__device_stub__Z10float_castPfPcPfPc, @function
_Z32__device_stub__Z10float_castPfPcPfPc:
.LFB2073:
	.cfi_startproc
	endbr64
	subq	$120, %rsp
	.cfi_def_cfa_offset 128
	movq	%rdi, 8(%rsp)
	leaq	32(%rsp), %rcx
	leaq	24(%rsp), %rdx
	movq	%rsi, (%rsp)
	leaq	40(%rsp), %rdi
	leaq	52(%rsp), %rsi
	movq	%fs:40, %rax
	movq	%rax, 104(%rsp)
	xorl	%eax, %eax
	leaq	8(%rsp), %rax
	movl	$1, 48(%rsp)
	movq	%rax, 88(%rsp)
	movq	%rsp, %rax
	movq	%rax, 96(%rsp)
	movabsq	$4294967297, %rax
	movq	%rax, 40(%rsp)
	movq	%rax, 52(%rsp)
	movl	$1, 60(%rsp)
	call	__cudaPopCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L13
	pushq	32(%rsp)
	.cfi_def_cfa_offset 136
	leaq	_Z10float_castPfPc(%rip), %rdi
	pushq	32(%rsp)
	.cfi_def_cfa_offset 144
	movq	68(%rsp), %rcx
	movl	76(%rsp), %r8d
	movq	56(%rsp), %rsi
	movl	64(%rsp), %edx
	leaq	104(%rsp), %r9
	call	cudaLaunchKernel@PLT
	popq	%rax
	.cfi_def_cfa_offset 136
	popq	%rdx
	.cfi_def_cfa_offset 128
.L13:
	movq	104(%rsp), %rax
	subq	%fs:40, %rax
	je	.L15
	call	__stack_chk_fail@PLT
.L15:
	addq	$120, %rsp
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2073:
	.size	_Z32__device_stub__Z10float_castPfPcPfPc, .-_Z32__device_stub__Z10float_castPfPcPfPc
	.globl	_Z10float_castPfPc
	.type	_Z10float_castPfPc, @function
_Z10float_castPfPc:
.LFB2074:
	.cfi_startproc
	endbr64
	jmp	_Z32__device_stub__Z10float_castPfPcPfPc
	.cfi_endproc
.LFE2074:
	.size	_Z10float_castPfPc, .-_Z10float_castPfPc
	.section	.rodata.str1.1,"aMS",@progbits,1
.LC0:
	.string	"%i, %i, %i, %i\n"
.LC1:
	.string	"Producing %i output samples per block (%i samples).\n"
.LC2:
	.string	"Using %i tap FIR filter.\n"
.LC3:
	.string	"Preparing sin lookup table...\n"
.LC4:
	.string	"Please supply both data and fir_taps filenames...\n"
.LC6:
	.string	"Allocating block storage on GPU...\n"
.LC8:
	.string	"Actual lo freq is: %f MHz (interval: %i, reminader: %i)\n"
.LC9:
	.string	"GPU Configuration: blocks per grid: %i, threads per block: %i\n"
.LC12:
	.string	"Producing %.2f s of data (%i loops reading a total of %.2f Mbytes of data)\n"
.LC13:
	.string	"%i "
	.section	.text.startup,"ax",@progbits
	.globl	main
	.type	main, @function
main:
.LFB2044:
	.cfi_startproc
	endbr64
	pushq	%r15
	.cfi_def_cfa_offset 16
	.cfi_offset 15, -16
	movl	$19531, %ecx
	movl	$800000000, %r9d
	movl	$10, %r8d
	pushq	%r14
	.cfi_def_cfa_offset 24
	.cfi_offset 14, -24
	leaq	.LC0(%rip), %rdx
	pushq	%r13
	.cfi_def_cfa_offset 32
	.cfi_offset 13, -32
	pushq	%r12
	.cfi_def_cfa_offset 40
	.cfi_offset 12, -40
	pushq	%rbp
	.cfi_def_cfa_offset 48
	.cfi_offset 6, -48
	movl	%edi, %ebp
	pushq	%rbx
	.cfi_def_cfa_offset 56
	.cfi_offset 3, -56
	movq	%rsi, %rbx
	movl	$2, %esi
	subq	$320, %rsp
	.cfi_def_cfa_offset 376
	movq	stderr(%rip), %rdi
	movq	%fs:40, %rax
	movq	%rax, 304(%rsp)
	xorl	%eax, %eax
	pushq	$409600
	.cfi_def_cfa_offset 384
	call	__fprintf_chk@PLT
	popq	%rcx
	.cfi_def_cfa_offset 376
	popq	%rsi
	.cfi_def_cfa_offset 368
	cmpl	$2, %ebp
	jle	.L19
	movl	$16384, %ecx
	movl	$2, %esi
	xorl	%eax, %eax
	movq	8(%rbx), %r15
	movq	stderr(%rip), %rdi
	movl	$409600, %r8d
	leaq	.LC1(%rip), %rdx
	movq	16(%rbx), %rbx
	call	__fprintf_chk@PLT
	movl	$409600, %edi
	call	malloc@PLT
	movl	$16384, %edi
	movq	%rax, (%rsp)
	call	malloc@PLT
	movl	$65536, %edi
	movq	%rax, 8(%rsp)
	call	malloc@PLT
	movl	$1640448, %edi
	movq	%rax, 24(%rsp)
	call	malloc@PLT
	movl	$32000, %edi
	movq	%rax, %rbp
	call	malloc@PLT
	movq	8(%rsp), %rdi
	movl	$4096, %ecx
	xorl	%esi, %esi
	movq	%rax, %r14
	xorl	%eax, %eax
	rep stosl
	movq	(%rsp), %rdi
	movl	$102400, %ecx
	rep stosl
	movl	$410112, %ecx
	movq	%rbp, %rdi
	rep stosl
	movq	%rbx, %rdi
	call	__open_2@PLT
	leaq	152(%rsp), %rsi
	movl	%eax, %edi
	movl	%eax, %r13d
	call	fstat@PLT
	movq	200(%rsp), %rbx
	movl	$2, %esi
	xorl	%eax, %eax
	movq	stderr(%rip), %rdi
	leaq	.LC2(%rip), %rdx
	shrq	$2, %rbx
	movl	%ebx, %ecx
	movl	%ebx, 20(%rsp)
	movslq	%ebx, %rbx
	call	__fprintf_chk@PLT
	salq	$2, %rbx
	movq	%rbx, %rdi
	call	malloc@PLT
	movq	%rbx, %rcx
	movq	%rbx, %rdx
	movl	%r13d, %edi
	movq	%rax, %rsi
	movq	%rax, %r12
	call	__read_chk@PLT
	movl	%r13d, %edi
	xorl	%r13d, %r13d
	call	close@PLT
	movq	stderr(%rip), %rdi
	leaq	.LC3(%rip), %rdx
	xorl	%eax, %eax
	movl	$2, %esi
	call	__fprintf_chk@PLT
	jmp	.L20
.L19:
	leaq	.LC4(%rip), %rsi
	movl	$2, %edi
	xorl	%eax, %eax
	call	__printf_chk@PLT
	orl	$-1, %eax
	jmp	.L18
.L20:
	cvtsi2sdl	%r13d, %xmm0
	mulsd	.LC5(%rip), %xmm0
	call	cos@PLT
	addsd	%xmm0, %xmm0
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, (%r14,%r13,4)
	incq	%r13
	cmpq	$8000, %r13
	jne	.L20
	movq	stderr(%rip), %rdi
	leaq	.LC6(%rip), %rdx
	movl	$2, %esi
	xorl	%eax, %eax
	movabsq	$4294968096, %r13
	call	__fprintf_chk@PLT
	leaq	t_start(%rip), %rdi
	call	cudaEventCreate@PLT
	leaq	t_stop(%rip), %rdi
	call	cudaEventCreate@PLT
	leaq	48(%rsp), %rdi
	movl	$410112, %esi
	call	cudaMalloc@PLT
	leaq	56(%rsp), %rdi
	movl	$512, %esi
	call	cudaMalloc@PLT
	leaq	72(%rsp), %rdi
	movl	$65536, %esi
	call	cudaMalloc@PLT
	leaq	88(%rsp), %rdi
	movl	$1638400, %esi
	call	cudaMalloc@PLT
	leaq	80(%rsp), %rdi
	movl	$1640448, %esi
	call	cudaMalloc@PLT
	leaq	96(%rsp), %rdi
	movl	$1638400, %esi
	call	cudaMalloc@PLT
	movq	%rbx, %rsi
	leaq	64(%rsp), %rdi
	call	cudaMalloc@PLT
	movq	64(%rsp), %rdi
	movq	%rbx, %rdx
	movq	%r12, %rsi
	movl	$1, %ecx
	call	cudaMemcpy@PLT
	movq	%rbx, %rdx
	movq	%r12, %rsi
	xorl	%ecx, %ecx
	movl	$1, %r8d
	movl	$8388609, %ebx
	leaq	_ZL5cTaps(%rip), %rdi
	movabsq	$4294967328, %r12
	call	cudaMemcpyToSymbol@PLT
	movl	$1, %r8d
	xorl	%ecx, %ecx
	movq	%r14, %rsi
	movl	$32000, %edx
	leaq	_ZL4cCos(%rip), %rdi
	salq	$9, %rbx
	call	cudaMemcpyToSymbol@PLT
	movq	80(%rsp), %rdi
	movq	%rbp, %rsi
	movl	$1, %ecx
	movl	$1638400, %edx
	call	cudaMemcpy@PLT
	movq	72(%rsp), %rdi
	movq	%rbp, %rsi
	movl	$1, %ecx
	movl	$65536, %edx
	call	cudaMemcpy@PLT
	movq	96(%rsp), %rdi
	movq	%rbp, %rsi
	movl	$1, %ecx
	movl	$1638400, %edx
	call	cudaMemcpy@PLT
	movq	88(%rsp), %rdi
	movq	%rbp, %rsi
	movl	$1, %ecx
	movl	$1638400, %edx
	xorl	%ebp, %ebp
	call	cudaMemcpy@PLT
	movq	(%rsp), %rsi
	movq	48(%rsp), %rdi
	movl	$1, %ecx
	movl	$410112, %edx
	call	cudaMemcpy@PLT
	movq	(%rsp), %rsi
	movq	56(%rsp), %rdi
	movl	$1, %ecx
	movl	$512, %edx
	call	cudaMemcpy@PLT
	xorl	%r8d, %r8d
	movl	$3020, %ecx
	movb	$1, %al
	movsd	.LC7(%rip), %xmm0
	movq	stderr(%rip), %rdi
	movl	$2, %esi
	leaq	.LC8(%rip), %rdx
	call	__fprintf_chk@PLT
	movq	stderr(%rip), %rdi
	xorl	%eax, %eax
	movl	$512, %r8d
	movl	$800, %ecx
	leaq	.LC9(%rip), %rdx
	movl	$2, %esi
	call	__fprintf_chk@PLT
	movq	%r15, %rdi
	xorl	%esi, %esi
	call	__open_2@PLT
	movl	$19531, %ecx
	movl	$2, %esi
	movsd	.LC10(%rip), %xmm1
	movsd	.LC11(%rip), %xmm0
	movq	stderr(%rip), %rdi
	movl	%eax, %r15d
	movb	$2, %al
	leaq	.LC12(%rip), %rdx
	call	__fprintf_chk@PLT
.L27:
	movq	(%rsp), %rsi
	movl	$409600, %ecx
	movl	$409600, %edx
	movl	%r15d, %edi
	call	__read_chk@PLT
	movq	t_start(%rip), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	48(%rsp), %rax
	movq	(%rsp), %rsi
	movl	$1, %ecx
	movl	$409600, %edx
	leaq	512(%rax), %rdi
	call	cudaMemcpy@PLT
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	%rbx, %rdx
	movl	$1, %ecx
	movq	%r13, %rdi
	movl	$1, %esi
	movq	%rbx, 104(%rsp)
	movl	$1, 112(%rsp)
	movq	%r12, 116(%rsp)
	movl	$1, 124(%rsp)
	movq	%rbx, 140(%rsp)
	movl	$1, 148(%rsp)
	movq	%r13, 128(%rsp)
	movl	$1, 136(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L22
	movq	88(%rsp), %rsi
	movq	48(%rsp), %rdi
	xorl	%r8d, %r8d
	movl	$8000, %ecx
	movl	$3020, %edx
	call	_Z27__device_stub__Z3mixPcPfiiiPcPfiii
.L22:
	movl	112(%rsp), %ecx
	movq	104(%rsp), %rdx
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	116(%rsp), %rdi
	movl	124(%rsp), %esi
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L23
	pushq	$8000
	.cfi_def_cfa_offset 376
	xorl	%r9d, %r9d
	movl	$25, %r8d
	movl	$1, %ecx
	pushq	$3020
	.cfi_def_cfa_offset 384
	movl	36(%rsp), %edx
	movq	88(%rsp), %rsi
	movq	104(%rsp), %rdi
	call	_Z38__device_stub__Z10simple_firPfS_iiiiiiPfS_iiiiii
	popq	%rax
	.cfi_def_cfa_offset 376
	popq	%rdx
	.cfi_def_cfa_offset 368
.L23:
	xorl	%r9d, %r9d
	xorl	%r8d, %r8d
	movq	%rbx, %rdx
	movl	$1, %ecx
	movq	%r12, %rdi
	movl	$1, %esi
	movq	%rbx, 140(%rsp)
	movl	$1, 148(%rsp)
	movq	%r12, 128(%rsp)
	movl	$1, 136(%rsp)
	call	__cudaPushCallConfiguration@PLT
	testl	%eax, %eax
	jne	.L24
	movq	48(%rsp), %rsi
	movq	72(%rsp), %rdi
	call	_Z32__device_stub__Z10float_castPfPcPfPc
.L24:
	movq	48(%rsp), %rsi
	movq	8(%rsp), %rdi
	movl	$2, %ecx
	movl	$16384, %edx
	call	cudaMemcpy@PLT
	movq	(%rsp), %rax
	movq	48(%rsp), %rdi
	movl	$512, %edx
	movl	$1, %ecx
	leaq	409088(%rax), %rsi
	call	cudaMemcpy@PLT
	movq	t_stop(%rip), %rdi
	xorl	%esi, %esi
	call	cudaEventRecord@PLT
	movq	t_stop(%rip), %rdi
	call	cudaEventSynchronize@PLT
	movq	t_stop(%rip), %rdx
	leaq	44(%rsp), %rdi
	movq	t_start(%rip), %rsi
	call	cudaEventElapsedTime@PLT
	testl	%ebp, %ebp
	jne	.L25
	xorl	%r14d, %r14d
.L26:
	movq	8(%rsp), %rax
	movq	stderr(%rip), %rdi
	movl	$2, %esi
	leaq	.LC13(%rip), %rdx
	movsbl	(%rax,%r14), %ecx
	xorl	%eax, %eax
	incq	%r14
	call	__fprintf_chk@PLT
	cmpq	$20, %r14
	jne	.L26
.L25:
	movq	8(%rsp), %rsi
	movl	$16384, %edx
	movl	$1, %edi
	incl	%ebp
	call	write@PLT
	cmpl	$19532, %ebp
	jne	.L27
	movq	24(%rsp), %rsi
	movl	$65536, %ecx
	movl	$1, %edx
	movl	$1, %edi
	call	__read_chk@PLT
	xorl	%eax, %eax
.L18:
	movq	296(%rsp), %rdx
	subq	%fs:40, %rdx
	je	.L28
	call	__stack_chk_fail@PLT
.L28:
	addq	$312, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%rbp
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	ret
	.cfi_endproc
.LFE2044:
	.size	main, .-main
	.section	.rodata.str1.1
.LC14:
	.string	"_Z10float_castPfPc"
.LC15:
	.string	"_Z10simple_firPfS_iiiiii"
.LC16:
	.string	"_Z3mixPcPfiii"
.LC17:
	.string	"cTaps"
.LC18:
	.string	"cCos"
	.section	.text.startup
	.type	_ZL24__sti____cudaRegisterAllv, @function
_ZL24__sti____cudaRegisterAllv:
.LFB2076:
	.cfi_startproc
	endbr64
	pushq	%rbx
	.cfi_def_cfa_offset 16
	.cfi_offset 3, -16
	leaq	_ZL15__fatDeviceText(%rip), %rdi
	call	__cudaRegisterFatBinary@PLT
	pushq	$0
	.cfi_def_cfa_offset 24
	xorl	%r9d, %r9d
	orl	$-1, %r8d
	pushq	$0
	.cfi_def_cfa_offset 32
	leaq	.LC14(%rip), %rdx
	movq	%rax, %rdi
	movq	%rax, %rbx
	pushq	$0
	.cfi_def_cfa_offset 40
	movq	%rdx, %rcx
	leaq	_Z10float_castPfPc(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 48
	movq	%rax, _ZL20__cudaFatCubinHandle(%rip)
	call	__cudaRegisterFunction@PLT
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r9d, %r9d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC15(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z10simple_firPfS_iiiiii(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 40
	pushq	$0
	.cfi_def_cfa_offset 48
	call	__cudaRegisterFunction@PLT
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r9d, %r9d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC16(%rip), %rdx
	orl	$-1, %r8d
	leaq	_Z3mixPcPfiii(%rip), %rsi
	pushq	$0
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	pushq	$0
	.cfi_def_cfa_offset 40
	pushq	$0
	.cfi_def_cfa_offset 48
	call	__cudaRegisterFunction@PLT
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	pushq	$0
	.cfi_def_cfa_offset 24
	leaq	.LC17(%rip), %rdx
	movl	$2048, %r9d
	leaq	_ZL5cTaps(%rip), %rsi
	pushq	$1
	.cfi_def_cfa_offset 32
	movq	%rdx, %rcx
	call	__cudaRegisterVar@PLT
	popq	%rax
	.cfi_def_cfa_offset 24
	popq	%rdx
	.cfi_def_cfa_offset 16
	pushq	$0
	.cfi_def_cfa_offset 24
	pushq	$1
	.cfi_def_cfa_offset 32
	leaq	.LC18(%rip), %rdx
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	movq	%rdx, %rcx
	movl	$32000, %r9d
	leaq	_ZL4cCos(%rip), %rsi
	call	__cudaRegisterVar@PLT
	movq	_ZL20__cudaFatCubinHandle(%rip), %rdi
	popq	%rcx
	.cfi_def_cfa_offset 24
	popq	%rsi
	.cfi_def_cfa_offset 16
	call	__cudaRegisterFatBinaryEnd@PLT
	leaq	_ZL26__cudaUnregisterBinaryUtilv(%rip), %rdi
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit@PLT
	.cfi_endproc
.LFE2076:
	.size	_ZL24__sti____cudaRegisterAllv, .-_ZL24__sti____cudaRegisterAllv
	.section	.init_array,"aw"
	.align 8
	.quad	_ZL24__sti____cudaRegisterAllv
	.section	.nvFatBinSegment,"aw"
	.align 8
	.type	_ZL15__fatDeviceText, @object
	.size	_ZL15__fatDeviceText, 24
_ZL15__fatDeviceText:
	.long	1180844977
	.long	1
	.quad	fatbinData
	.quad	0
	.local	_ZL20__cudaFatCubinHandle
	.comm	_ZL20__cudaFatCubinHandle,8,8
	.local	_ZL4cCos
	.comm	_ZL4cCos,32000,32
	.globl	t_stop
	.bss
	.align 8
	.type	t_stop, @object
	.size	t_stop, 8
t_stop:
	.zero	8
	.globl	t_start
	.align 8
	.type	t_start, @object
	.size	t_start, 8
t_start:
	.zero	8
	.local	_ZL5cTaps
	.comm	_ZL5cTaps,2048,32
	.section	.rodata.cst8,"aM",@progbits,8
	.align 8
.LC5:
	.long	-1232375357
	.long	1061796965
	.align 8
.LC7:
	.long	0
	.long	1081270272
	.align 8
.LC10:
	.long	0
	.long	1086180684
	.align 8
.LC11:
	.long	1073741824
	.long	1076101103
	.ident	"GCC: (Ubuntu 13.3.0-6ubuntu2~24.04) 13.3.0"
	.section	.note.GNU-stack,"",@progbits
	.section	.note.gnu.property,"a"
	.align 8
	.long	1f - 0f
	.long	4f - 1f
	.long	5
0:
	.string	"GNU"
1:
	.align 8
	.long	0xc0000002
	.long	3f - 2f
2:
	.long	0x3
3:
	.align 8
4:


#include <hip/hip_runtime.h>
#include <stdlib.h>
#include <stdio.h>
#include <stdint.h>
#include <unistd.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <math.h>

#define DOWNSAMPLE 25
#define SAMPLE_FREQ 800e6
#define LO_FREQ 302e6
#define THREADS_PER_BLOCK 512
#define BLOCKS_PER_GRID 32 * DOWNSAMPLE
 // keeps things a multiple of COS_TABLE_LENGTH to avoid edge effects
#define BLOCK_SIZE THREADS_PER_BLOCK * BLOCKS_PER_GRID
#define SECONDS_OF_DATA 10
#define COS_TABLE_LENGTH 8000
 // how many loops of block size to do
#define INPUT_SCALE 1.0f
 // input may need scaling to see tones clearly...

__constant__ float cTaps[512];
hipEvent_t t_start, t_stop;
__constant__ float cCos[COS_TABLE_LENGTH];

__global__ void mix(char *input_buffer, float *output_buffer, int lo_interval, int cos_table_length, int lo_offset)
{
 int idx = blockIdx.x*blockDim.x + threadIdx.x;
 float mix_value = (float)cCos[(lo_interval*idx) % cos_table_length + lo_offset] * ((float)input_buffer[idx + blockDim.x] / INPUT_SCALE);

 output_buffer[idx + blockDim.x] = mix_value;
  // when mixing we skip the first blockDim.x (the number of threads) worth of input buffer (i.e. the memory portion)
}

__global__ void simple_fir(float *input_buffer, float *output_buffer, int no_taps, int upsample, int downsample, int poly_interval, int lo_interval, int cos_table_length)
{
 float temp_output = 0;
 int fir_idx = (blockIdx.x*blockDim.x + threadIdx.x)*downsample + blockDim.x;
    // idx starts from end of memory buffer which is blockDim.x in length

 for (int i=0; i < no_taps; i++) {
  temp_output += cTaps[i] * (float)input_buffer[fir_idx - i];
 }
 output_buffer[blockIdx.x*blockDim.x + threadIdx.x] = temp_output * (downsample / 8.0f);
}

__global__ void float_cast(float *in, char *out)
{
 int idx = blockDim.x*blockIdx.x + threadIdx.x;
 out[idx] = (char) in[idx];
}

int main(int argc, char **argv) {
 int write_block = BLOCK_SIZE;
  // 1 MB worth of data at a time...
  // this should be enough to allow at least a couple of output points per thread when tap overlap 
 int sample_rate = SAMPLE_FREQ;
  // our adc sampling frequency
 int upsample = 1;
 int downsample = DOWNSAMPLE;
  // coefficients to sort out the output sample rate
  // in this case giving us 128 MHz sampling
 int lo_freq = LO_FREQ;
  // the mixing frequency for the DDC
 int cos_table_length = COS_TABLE_LENGTH;
  // the number of samples in the sin lookup table
 int cos_table_size = sizeof(float) * cos_table_length;
 int lo_interval = int(((float)cos_table_length / sample_rate) * lo_freq);
  // the stepping interval through the lo sin table. May result in slightly different lo_freq from that
  // specified. The user is informed of this.
 int lo_offset = 0;
  // as we move from block to block our we need an lo_offset to maintain phase...
 int lo_remainder = (write_block * lo_interval) % cos_table_length;
  // the remainder at the end of each loop (i.e. the last point per block from the loop)
 int no_taps = 0;
  // number of filter taps. Calculated once filter data is loaded.
 int no_output_samples = int(((float)write_block / downsample));
  // overall number of output samples to produce for this block
 int loops = int(SECONDS_OF_DATA * (sample_rate / (float)write_block));
 fprintf(stderr,"%i, %i, %i, %i\n", loops, SECONDS_OF_DATA, sample_rate, write_block);

 int fh;
 char *data_file;
 char *fir_taps_file;
 float et;
 struct stat stat_buf;

 float *fir_taps;
 char *base_buffer;
 char *host_char_buffer;
 float *output_buffer;
 float *upsample_buffer;
 float *cos_table;
  // host buffers

 char *device_char_buffer;
 char *memory_buffer;
 float *device_fir_taps;
 float *device_output_buffer;
 float *device_upsample_buffer;
 float *device_float_buffer;
 float *device_fir_buffer;
  // device buffers

 if (argc > 2) {
  data_file = argv[1];
  fir_taps_file = argv[2];
 } else { printf("Please supply both data and fir_taps filenames...\n"); return -1;}

 fprintf(stderr,"Producing %i output samples per block (%i samples).\n",no_output_samples,write_block);

 base_buffer = (char*)malloc(write_block);
 host_char_buffer = (char*)malloc(no_output_samples);
 output_buffer = (float*)malloc(sizeof(float) * no_output_samples);
 upsample_buffer = (float*)malloc(sizeof(float) * upsample * (write_block + THREADS_PER_BLOCK));
 cos_table = (float*)malloc(cos_table_size);
 memset(host_char_buffer, (char) 0, no_output_samples);
 memset(base_buffer, (char) 0, write_block);
 memset(upsample_buffer, (char) 0, sizeof(float) * upsample * (write_block + THREADS_PER_BLOCK));
  // zero as we use part of this for our initial zero padding block

 fh = open(fir_taps_file, O_RDONLY);
 fstat(fh, &stat_buf);
 no_taps = stat_buf.st_size / sizeof(float);
 fprintf(stderr,"Using %i tap FIR filter.\n",no_taps);
 fir_taps = (float*)malloc(sizeof(float) * no_taps);
 read(fh, fir_taps, sizeof(float) * no_taps);
 close(fh);

 fprintf(stderr,"Preparing sin lookup table...\n");
 for (int i=0; i < cos_table_length; i++) {
  cos_table[i] = 2 * cos(i * (2*M_PI/cos_table_length));
 }

 fprintf(stderr,"Allocating block storage on GPU...\n");

 hipEventCreate(&t_start);
 hipEventCreate(&t_stop);

 hipMalloc((void**)&device_char_buffer, write_block + THREADS_PER_BLOCK);
  // device buffer with space for initial zero padding
 hipMalloc((void**)&memory_buffer, THREADS_PER_BLOCK);
  // previous loop memory
 hipMalloc((void**)&device_output_buffer, sizeof(float) * no_output_samples);
 hipMalloc((void**)&device_float_buffer, sizeof(float) * write_block);
 hipMalloc((void**)&device_upsample_buffer, sizeof(float) * upsample * (write_block + THREADS_PER_BLOCK));
 hipMalloc((void**)&device_fir_buffer, sizeof(float) * upsample * write_block);
 hipMalloc((void**)&device_fir_taps, sizeof(float) * no_taps);
  // allocate the device storage

 hipMemcpy(device_fir_taps, fir_taps, sizeof(float) * no_taps, hipMemcpyHostToDevice);
  // copy the filter taps to the device
 hipMemcpyToSymbol(HIP_SYMBOL(cTaps), fir_taps, sizeof(float) * no_taps);
 hipMemcpyToSymbol(HIP_SYMBOL(cCos), cos_table, cos_table_size);
 hipMemcpy(device_upsample_buffer, upsample_buffer, sizeof(float) * upsample * write_block, hipMemcpyHostToDevice);
 hipMemcpy(device_output_buffer, upsample_buffer, sizeof(float) * no_output_samples, hipMemcpyHostToDevice);
 hipMemcpy(device_fir_buffer, upsample_buffer, sizeof(float) * upsample * write_block, hipMemcpyHostToDevice);
 hipMemcpy(device_float_buffer, upsample_buffer, sizeof(float) * write_block, hipMemcpyHostToDevice);
 hipMemcpy(device_char_buffer, base_buffer, write_block + THREADS_PER_BLOCK, hipMemcpyHostToDevice);
 hipMemcpy(memory_buffer, base_buffer, THREADS_PER_BLOCK, hipMemcpyHostToDevice);
  // init host memory to zero

 fprintf(stderr,"Actual lo freq is: %f MHz (interval: %i, reminader: %i)\n", (lo_interval / ((float)cos_table_length / sample_rate)) / 1e6, lo_interval, lo_remainder);
 fprintf(stderr,"GPU Configuration: blocks per grid: %i, threads per block: %i\n",BLOCKS_PER_GRID, THREADS_PER_BLOCK);

 fh = open(data_file, O_LARGEFILE);
// read(fh, base_buffer, write_block * LOOPS);
 fprintf(stderr,"Producing %.2f s of data (%i loops reading a total of %.2f Mbytes of data)\n", loops * (write_block / float(sample_rate)), loops, loops * (write_block / float(1024*1024)));

 for (int i=0; i <= loops; i++) {
  read(fh, base_buffer, write_block);

  //start = i * write_block;
  //fprintf(stderr,"Loop %i (start: %li, lo_offset: %i).\n",i,start, lo_offset);

  hipEventRecord(t_start, 0);

  hipMemcpy(device_char_buffer+THREADS_PER_BLOCK, base_buffer, write_block, hipMemcpyHostToDevice);
   // need to recal lo_offset each loop
  lo_offset = (i * lo_remainder) % cos_table_length;
   // on the offchance that each block does not loop through the cos table exactly
   // we adjust the starting offset to match the end of the previous loop

   // polyphase method
  int poly_interval = 0;
   // hardcoded for now... l = 4; m = 25
  dim3 threads(THREADS_PER_BLOCK, 1);
   // the downsample spaced blocks are indexed by thread.x and the upsample number of fir filters are indexed by y
  dim3 blocks(BLOCKS_PER_GRID / downsample,1);

  mix<<<BLOCKS_PER_GRID, THREADS_PER_BLOCK>>>(device_char_buffer, device_float_buffer, lo_interval, cos_table_length, lo_offset);
  //poly_fir<<<blocks, threads>>>(device_char_buffer, memory_buffer, device_output_buffer, no_taps, upsample, downsample, poly_interval, lo_interval, cos_table_length);
  simple_fir<<<blocks, threads>>>(device_float_buffer, device_output_buffer, no_taps, upsample, downsample, poly_interval, lo_interval, cos_table_length);
  float_cast<<<no_output_samples/THREADS_PER_BLOCK, THREADS_PER_BLOCK>>>(device_output_buffer, device_char_buffer);
  //fill_memory_buffer<<<1, THREADS_PER_BLOCK>>>(device_char_buffer, memory_buffer, write_block - THREADS_PER_BLOCK);
   // fill memory buffer for next loop
  hipMemcpy(host_char_buffer, device_char_buffer, no_output_samples, hipMemcpyDeviceToHost);
  hipMemcpy(device_char_buffer, base_buffer + write_block - THREADS_PER_BLOCK, THREADS_PER_BLOCK, hipMemcpyHostToDevice);
   // prime memory buffer for next trip

  hipEventRecord(t_stop, 0);
  hipEventSynchronize(t_stop);
  hipEventElapsedTime(&et, t_start, t_stop);
  if (i == 0) {for (int j=0; j < 20; j++) { fprintf(stderr,"%i ",host_char_buffer[j]); }}
  write(1, host_char_buffer, no_output_samples);
  //write(1, output_buffer, sizeof(float) * no_output_samples);
  //if (i % 20 == 0) fprintf(stderr,"Loop done. CUDA time is %f ms\n", et);
 }
 read(1, output_buffer, 1);
 return 0;
}

	.text
	.file	"ddc_16m.hip"
	.globl	_Z18__device_stub__mixPcPfiii   # -- Begin function _Z18__device_stub__mixPcPfiii
	.type	_Z18__device_stub__mixPcPfiii,@function
_Z18__device_stub__mixPcPfiii:          # @_Z18__device_stub__mixPcPfiii
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$128, %rsp
	.cfi_def_cfa_offset 176
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	32(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	12(%rsp), %rsi
	movl	%edx, (%rsi)
	leaq	8(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	4(%rsp), %rcx
	movl	%r8d, (%rcx)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	24(%rsp), %r12
	leaq	16(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z3mixPcPfiii, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$144, %rsp
	.cfi_adjust_cfa_offset -144
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end0:
	.size	_Z18__device_stub__mixPcPfiii, .Lfunc_end0-_Z18__device_stub__mixPcPfiii
	.cfi_endproc
                                        # -- End function
	.globl	_Z25__device_stub__simple_firPfS_iiiiii # -- Begin function _Z25__device_stub__simple_firPfS_iiiiii
	.type	_Z25__device_stub__simple_firPfS_iiiiii,@function
_Z25__device_stub__simple_firPfS_iiiiii: # @_Z25__device_stub__simple_firPfS_iiiiii
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$144, %rsp
	.cfi_def_cfa_offset 192
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	40(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	32(%rsp), %rdi
	movq	%rsi, (%rdi)
	leaq	12(%rsp), %rsi
	movl	%edx, (%rsi)
	leaq	8(%rsp), %rdx
	movl	%ecx, (%rdx)
	leaq	4(%rsp), %rcx
	movl	%r8d, (%rcx)
	movq	%rsp, %r8
	movl	%r9d, (%r8)
	leaq	80(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rdi, 8(%rbx)
	movq	%rsi, 16(%rbx)
	movq	%rdx, 24(%rbx)
	movq	%rcx, 32(%rbx)
	movq	%r8, 40(%rbx)
	leaq	192(%rsp), %rax
	movq	%rax, 48(%rbx)
	leaq	200(%rsp), %rax
	movq	%rax, 56(%rbx)
	leaq	64(%rsp), %r14
	leaq	48(%rsp), %r15
	leaq	24(%rsp), %r12
	leaq	16(%rsp), %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z10simple_firPfS_iiiiii, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$160, %rsp
	.cfi_adjust_cfa_offset -160
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end1:
	.size	_Z25__device_stub__simple_firPfS_iiiiii, .Lfunc_end1-_Z25__device_stub__simple_firPfS_iiiiii
	.cfi_endproc
                                        # -- End function
	.globl	_Z25__device_stub__float_castPfPc # -- Begin function _Z25__device_stub__float_castPfPc
	.type	_Z25__device_stub__float_castPfPc,@function
_Z25__device_stub__float_castPfPc:      # @_Z25__device_stub__float_castPfPc
	.cfi_startproc
# %bb.0:
	pushq	%r15
	.cfi_def_cfa_offset 16
	pushq	%r14
	.cfi_def_cfa_offset 24
	pushq	%r13
	.cfi_def_cfa_offset 32
	pushq	%r12
	.cfi_def_cfa_offset 40
	pushq	%rbx
	.cfi_def_cfa_offset 48
	subq	$80, %rsp
	.cfi_def_cfa_offset 128
	.cfi_offset %rbx, -48
	.cfi_offset %r12, -40
	.cfi_offset %r13, -32
	.cfi_offset %r14, -24
	.cfi_offset %r15, -16
	leaq	24(%rsp), %rax
	movq	%rdi, (%rax)
	leaq	16(%rsp), %rcx
	movq	%rsi, (%rcx)
	leaq	64(%rsp), %rbx
	movq	%rax, (%rbx)
	movq	%rcx, 8(%rbx)
	leaq	48(%rsp), %r14
	leaq	32(%rsp), %r15
	leaq	8(%rsp), %r12
	movq	%rsp, %r13
	movq	%r14, %rdi
	movq	%r15, %rsi
	movq	%r12, %rdx
	movq	%r13, %rcx
	callq	__hipPopCallConfiguration
	movq	(%r14), %rsi
	movl	8(%r14), %edx
	movq	(%r15), %rcx
	movl	8(%r15), %r8d
	movl	$_Z10float_castPfPc, %edi
	movq	%rbx, %r9
	pushq	(%r13)
	.cfi_adjust_cfa_offset 8
	pushq	(%r12)
	.cfi_adjust_cfa_offset 8
	callq	hipLaunchKernel
	addq	$96, %rsp
	.cfi_adjust_cfa_offset -96
	popq	%rbx
	.cfi_def_cfa_offset 40
	popq	%r12
	.cfi_def_cfa_offset 32
	popq	%r13
	.cfi_def_cfa_offset 24
	popq	%r14
	.cfi_def_cfa_offset 16
	popq	%r15
	.cfi_def_cfa_offset 8
	retq
.Lfunc_end2:
	.size	_Z25__device_stub__float_castPfPc, .Lfunc_end2-_Z25__device_stub__float_castPfPc
	.cfi_endproc
                                        # -- End function
	.section	.rodata.cst8,"aM",@progbits,8
	.p2align	3, 0x0                          # -- Begin function main
.LCPI3_0:
	.quad	0x3f49bc65b68b71c3              # double 7.8539816339744833E-4
.LCPI3_1:
	.quad	0x4072e00000000000              # double 302
.LCPI3_2:
	.quad	0x4023ffef40000000              # double 9.9998722076416015
.LCPI3_3:
	.quad	0x40bdcd4c00000000              # double 7629.296875
	.text
	.globl	main
	.type	main,@function
main:                                   # @main
	.cfi_startproc
# %bb.0:
	pushq	%rbp
	.cfi_def_cfa_offset 16
	pushq	%r15
	.cfi_def_cfa_offset 24
	pushq	%r14
	.cfi_def_cfa_offset 32
	pushq	%r13
	.cfi_def_cfa_offset 40
	pushq	%r12
	.cfi_def_cfa_offset 48
	pushq	%rbx
	.cfi_def_cfa_offset 56
	subq	$248, %rsp
	.cfi_def_cfa_offset 304
	.cfi_offset %rbx, -56
	.cfi_offset %r12, -48
	.cfi_offset %r13, -40
	.cfi_offset %r14, -32
	.cfi_offset %r15, -24
	.cfi_offset %rbp, -16
	movq	%rsi, %rbx
	movl	%edi, %ebp
	movq	stderr(%rip), %rdi
	movl	$.L.str, %esi
	movl	$19531, %edx                    # imm = 0x4C4B
	movl	$10, %ecx
	movl	$800000000, %r8d                # imm = 0x2FAF0800
	movl	$409600, %r9d                   # imm = 0x64000
	xorl	%eax, %eax
	callq	fprintf
	cmpl	$3, %ebp
	jge	.LBB3_1
# %bb.15:
	movl	$.Lstr, %edi
	callq	puts@PLT
	movl	$-1, %eax
.LBB3_16:
	addq	$248, %rsp
	.cfi_def_cfa_offset 56
	popq	%rbx
	.cfi_def_cfa_offset 48
	popq	%r12
	.cfi_def_cfa_offset 40
	popq	%r13
	.cfi_def_cfa_offset 32
	popq	%r14
	.cfi_def_cfa_offset 24
	popq	%r15
	.cfi_def_cfa_offset 16
	popq	%rbp
	.cfi_def_cfa_offset 8
	retq
.LBB3_1:
	.cfi_def_cfa_offset 304
	movq	8(%rbx), %rax
	movq	%rax, 8(%rsp)                   # 8-byte Spill
	movq	16(%rbx), %r13
	movq	stderr(%rip), %rdi
	xorl	%ebx, %ebx
	movl	$.L.str.2, %esi
	movl	$16384, %edx                    # imm = 0x4000
	movl	$409600, %ecx                   # imm = 0x64000
	xorl	%eax, %eax
	callq	fprintf
	movl	$1, %edi
	movl	$409600, %esi                   # imm = 0x64000
	callq	calloc@PLT
	movq	%rax, 32(%rsp)                  # 8-byte Spill
	movl	$1, %edi
	movl	$16384, %esi                    # imm = 0x4000
	callq	calloc@PLT
	movq	%rax, %r15
	movl	$65536, %edi                    # imm = 0x10000
	callq	malloc
	movq	%rax, 48(%rsp)                  # 8-byte Spill
	movl	$1, %edi
	movl	$1640448, %esi                  # imm = 0x190800
	callq	calloc@PLT
	movq	%rax, 40(%rsp)                  # 8-byte Spill
	movl	$32000, %edi                    # imm = 0x7D00
	callq	malloc
	movq	%rax, %r12
	movq	%r13, %rdi
	xorl	%esi, %esi
	xorl	%eax, %eax
	callq	open
	movl	%eax, %r14d
	leaq	104(%rsp), %r13
	movl	%eax, %edi
	movq	%r13, %rsi
	callq	fstat
	movq	48(%r13), %r13
	shrq	$2, %r13
	movq	stderr(%rip), %rdi
	movl	$.L.str.3, %esi
	movl	%r13d, %edx
	xorl	%eax, %eax
	callq	fprintf
	movq	%r13, 56(%rsp)                  # 8-byte Spill
	movslq	%r13d, %r13
	shlq	$2, %r13
	movq	%r13, %rdi
	callq	malloc
	movq	%rax, %rbp
	movl	%r14d, %edi
	movq	%rax, %rsi
	movq	%r13, %rdx
	callq	read
	movl	%r14d, %edi
	callq	close
	movq	stderr(%rip), %rcx
	movl	$.L.str.4, %edi
	movl	$30, %esi
	movl	$1, %edx
	callq	fwrite@PLT
.LBB3_2:                                # =>This Inner Loop Header: Depth=1
	xorps	%xmm0, %xmm0
	cvtsi2sd	%ebx, %xmm0
	mulsd	.LCPI3_0(%rip), %xmm0
	callq	cos
	addsd	%xmm0, %xmm0
	cvtsd2ss	%xmm0, %xmm0
	movss	%xmm0, (%r12,%rbx,4)
	incq	%rbx
	cmpq	$8000, %rbx                     # imm = 0x1F40
	jne	.LBB3_2
# %bb.3:
	movq	stderr(%rip), %rcx
	movl	$.L.str.5, %edi
	movl	$35, %esi
	movl	$1, %edx
	callq	fwrite@PLT
	movl	$t_start, %edi
	callq	hipEventCreate
	movl	$t_stop, %edi
	callq	hipEventCreate
	movq	%rsp, %rdi
	movl	$410112, %esi                   # imm = 0x64200
	callq	hipMalloc
	leaq	72(%rsp), %rdi
	movl	$512, %esi                      # imm = 0x200
	callq	hipMalloc
	leaq	24(%rsp), %rdi
	movl	$65536, %esi                    # imm = 0x10000
	callq	hipMalloc
	leaq	16(%rsp), %rdi
	movl	$1638400, %esi                  # imm = 0x190000
	callq	hipMalloc
	leaq	88(%rsp), %rbx
	movl	$1640448, %esi                  # imm = 0x190800
	movq	%rbx, %rdi
	callq	hipMalloc
	leaq	64(%rsp), %rdi
	movl	$1638400, %esi                  # imm = 0x190000
	callq	hipMalloc
	leaq	96(%rsp), %r14
	movq	%r14, %rdi
	movq	%r13, %rsi
	callq	hipMalloc
	movq	(%r14), %rdi
	movq	%rbp, %rsi
	movq	%r13, %rdx
	movl	$1, %ecx
	callq	hipMemcpy
	movl	$cTaps, %edi
	movq	%rbp, %rsi
	movq	%r13, %rdx
	xorl	%ecx, %ecx
	movl	$1, %r8d
	callq	hipMemcpyToSymbol
	movl	$cCos, %edi
	movl	$32000, %edx                    # imm = 0x7D00
	movq	%r12, %rsi
	xorl	%ecx, %ecx
	movl	$1, %r8d
	callq	hipMemcpyToSymbol
	movq	(%rbx), %rdi
	movl	$1638400, %edx                  # imm = 0x190000
	movq	40(%rsp), %r14                  # 8-byte Reload
	movq	%r14, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	24(%rsp), %rax
	movq	(%rax), %rdi
	movl	$65536, %edx                    # imm = 0x10000
	movq	%r14, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	64(%rsp), %rax
	movq	(%rax), %rdi
	movl	$1638400, %edx                  # imm = 0x190000
	movq	%r14, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	16(%rsp), %rax
	movq	(%rax), %rdi
	movl	$1638400, %edx                  # imm = 0x190000
	movq	%r14, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movq	%rsp, %rax
	movq	(%rax), %rdi
	movl	$410112, %edx                   # imm = 0x64200
	movq	32(%rsp), %r14                  # 8-byte Reload
	movq	%r14, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	leaq	72(%rsp), %rax
	movq	(%rax), %rdi
	movl	$512, %edx                      # imm = 0x200
	movq	%r14, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movq	stderr(%rip), %rdi
	movsd	.LCPI3_1(%rip), %xmm0           # xmm0 = mem[0],zero
	movl	$.L.str.6, %esi
	movl	$3020, %edx                     # imm = 0xBCC
	xorl	%ecx, %ecx
	movb	$1, %al
	callq	fprintf
	movq	stderr(%rip), %rdi
	movl	$.L.str.7, %esi
	movl	$800, %edx                      # imm = 0x320
	movl	$512, %ecx                      # imm = 0x200
	xorl	%eax, %eax
	callq	fprintf
	movq	8(%rsp), %rdi                   # 8-byte Reload
	xorl	%esi, %esi
	xorl	%eax, %eax
	callq	open
	movl	%eax, 8(%rsp)                   # 4-byte Spill
	movq	stderr(%rip), %rdi
	movsd	.LCPI3_2(%rip), %xmm0           # xmm0 = mem[0],zero
	movsd	.LCPI3_3(%rip), %xmm1           # xmm1 = mem[0],zero
	movl	$.L.str.8, %esi
	movl	$19531, %edx                    # imm = 0x4C4B
	movb	$2, %al
	callq	fprintf
	addq	$409088, %r14                   # imm = 0x63E00
	movabsq	$4294967808, %rax               # imm = 0x100000200
	leaq	288(%rax), %r12
	leaq	-480(%rax), %r13
	xorl	%ebx, %ebx
.LBB3_4:                                # =>This Loop Header: Depth=1
                                        #     Child Loop BB3_12 Depth 2
	movl	$409600, %edx                   # imm = 0x64000
	movl	8(%rsp), %edi                   # 4-byte Reload
	movq	32(%rsp), %rbp                  # 8-byte Reload
	movq	%rbp, %rsi
	callq	read
	movq	t_start(%rip), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	(%rsp), %rdi
	movl	$512, %eax                      # imm = 0x200
	addq	%rax, %rdi
	movl	$409600, %edx                   # imm = 0x64000
	movq	%rbp, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movq	%r12, %rdi
	movl	$1, %esi
	movabsq	$4294967808, %rbp               # imm = 0x100000200
	movq	%rbp, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB3_6
# %bb.5:                                #   in Loop: Header=BB3_4 Depth=1
	movq	(%rsp), %rdi
	movq	16(%rsp), %rsi
	movl	$3020, %edx                     # imm = 0xBCC
	movl	$8000, %ecx                     # imm = 0x1F40
	xorl	%r8d, %r8d
	callq	_Z18__device_stub__mixPcPfiii
.LBB3_6:                                #   in Loop: Header=BB3_4 Depth=1
	movq	%r13, %rdi
	movl	$1, %esi
	movq	%rbp, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB3_8
# %bb.7:                                #   in Loop: Header=BB3_4 Depth=1
	movq	16(%rsp), %rdi
	movq	24(%rsp), %rsi
	movq	56(%rsp), %rdx                  # 8-byte Reload
                                        # kill: def $edx killed $edx killed $rdx
	movl	$1, %ecx
	movl	$25, %r8d
	xorl	%r9d, %r9d
	pushq	$8000                           # imm = 0x1F40
	.cfi_adjust_cfa_offset 8
	pushq	$3020                           # imm = 0xBCC
	.cfi_adjust_cfa_offset 8
	callq	_Z25__device_stub__simple_firPfS_iiiiii
	addq	$16, %rsp
	.cfi_adjust_cfa_offset -16
.LBB3_8:                                #   in Loop: Header=BB3_4 Depth=1
	movq	%r13, %rdi
	movl	$1, %esi
	movq	%rbp, %rdx
	movl	$1, %ecx
	xorl	%r8d, %r8d
	xorl	%r9d, %r9d
	callq	__hipPushCallConfiguration
	testl	%eax, %eax
	jne	.LBB3_10
# %bb.9:                                #   in Loop: Header=BB3_4 Depth=1
	movq	24(%rsp), %rdi
	movq	(%rsp), %rsi
	callq	_Z25__device_stub__float_castPfPc
.LBB3_10:                               #   in Loop: Header=BB3_4 Depth=1
	movq	(%rsp), %rsi
	movl	$16384, %edx                    # imm = 0x4000
	movq	%r15, %rdi
	movl	$2, %ecx
	callq	hipMemcpy
	movq	(%rsp), %rdi
	movl	$512, %edx                      # imm = 0x200
	movq	%r14, %rsi
	movl	$1, %ecx
	callq	hipMemcpy
	movq	t_stop(%rip), %rdi
	xorl	%esi, %esi
	callq	hipEventRecord
	movq	t_stop(%rip), %rdi
	callq	hipEventSynchronize
	movq	t_start(%rip), %rsi
	movq	t_stop(%rip), %rdx
	leaq	84(%rsp), %rdi
	callq	hipEventElapsedTime
	testl	%ebx, %ebx
	jne	.LBB3_13
# %bb.11:                               # %.preheader.preheader
                                        #   in Loop: Header=BB3_4 Depth=1
	xorl	%ebp, %ebp
.LBB3_12:                               # %.preheader
                                        #   Parent Loop BB3_4 Depth=1
                                        # =>  This Inner Loop Header: Depth=2
	movq	stderr(%rip), %rdi
	movsbl	(%r15,%rbp), %edx
	movl	$.L.str.9, %esi
	xorl	%eax, %eax
	callq	fprintf
	incq	%rbp
	cmpq	$20, %rbp
	jne	.LBB3_12
.LBB3_13:                               # %.loopexit
                                        #   in Loop: Header=BB3_4 Depth=1
	movl	$16384, %edx                    # imm = 0x4000
	movl	$1, %edi
	movq	%r15, %rsi
	callq	write
	incl	%ebx
	cmpl	$19532, %ebx                    # imm = 0x4C4C
	jne	.LBB3_4
# %bb.14:
	movl	$1, %edx
	movl	$1, %edi
	movq	48(%rsp), %rsi                  # 8-byte Reload
	callq	read
	xorl	%eax, %eax
	jmp	.LBB3_16
.Lfunc_end3:
	.size	main, .Lfunc_end3-main
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_ctor
	.type	__hip_module_ctor,@function
__hip_module_ctor:                      # @__hip_module_ctor
	.cfi_startproc
# %bb.0:
	pushq	%rbx
	.cfi_def_cfa_offset 16
	subq	$32, %rsp
	.cfi_def_cfa_offset 48
	.cfi_offset %rbx, -16
	movq	__hip_gpubin_handle(%rip), %rbx
	testq	%rbx, %rbx
	jne	.LBB4_2
# %bb.1:
	movl	$__hip_fatbin_wrapper, %edi
	callq	__hipRegisterFatBinary
	movq	%rax, %rbx
	movq	%rax, __hip_gpubin_handle(%rip)
.LBB4_2:
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z3mixPcPfiii, %esi
	movl	$.L__unnamed_1, %edx
	movl	$.L__unnamed_1, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z10simple_firPfS_iiiiii, %esi
	movl	$.L__unnamed_2, %edx
	movl	$.L__unnamed_2, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	xorps	%xmm0, %xmm0
	movups	%xmm0, 16(%rsp)
	movups	%xmm0, (%rsp)
	movl	$_Z10float_castPfPc, %esi
	movl	$.L__unnamed_3, %edx
	movl	$.L__unnamed_3, %ecx
	movq	%rbx, %rdi
	movl	$-1, %r8d
	xorl	%r9d, %r9d
	callq	__hipRegisterFunction
	movl	$0, 8(%rsp)
	movl	$1, (%rsp)
	movl	$cTaps, %esi
	movl	$.L__unnamed_4, %edx
	movl	$.L__unnamed_4, %ecx
	movl	$2048, %r9d                     # imm = 0x800
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	callq	__hipRegisterVar
	movl	$0, 8(%rsp)
	movl	$1, (%rsp)
	movl	$cCos, %esi
	movl	$.L__unnamed_5, %edx
	movl	$.L__unnamed_5, %ecx
	movl	$32000, %r9d                    # imm = 0x7D00
	movq	%rbx, %rdi
	xorl	%r8d, %r8d
	callq	__hipRegisterVar
	movl	$__hip_module_dtor, %edi
	addq	$32, %rsp
	.cfi_def_cfa_offset 16
	popq	%rbx
	.cfi_def_cfa_offset 8
	jmp	atexit                          # TAILCALL
.Lfunc_end4:
	.size	__hip_module_ctor, .Lfunc_end4-__hip_module_ctor
	.cfi_endproc
                                        # -- End function
	.p2align	4, 0x90                         # -- Begin function __hip_module_dtor
	.type	__hip_module_dtor,@function
__hip_module_dtor:                      # @__hip_module_dtor
	.cfi_startproc
# %bb.0:
	movq	__hip_gpubin_handle(%rip), %rdi
	testq	%rdi, %rdi
	je	.LBB5_2
# %bb.1:
	pushq	%rax
	.cfi_def_cfa_offset 16
	callq	__hipUnregisterFatBinary
	movq	$0, __hip_gpubin_handle(%rip)
	addq	$8, %rsp
	.cfi_def_cfa_offset 8
.LBB5_2:
	retq
.Lfunc_end5:
	.size	__hip_module_dtor, .Lfunc_end5-__hip_module_dtor
	.cfi_endproc
                                        # -- End function
	.type	cTaps,@object                   # @cTaps
	.local	cTaps
	.comm	cTaps,2048,16
	.type	t_start,@object                 # @t_start
	.bss
	.globl	t_start
	.p2align	3, 0x0
t_start:
	.quad	0
	.size	t_start, 8

	.type	t_stop,@object                  # @t_stop
	.globl	t_stop
	.p2align	3, 0x0
t_stop:
	.quad	0
	.size	t_stop, 8

	.type	cCos,@object                    # @cCos
	.local	cCos
	.comm	cCos,32000,16
	.type	_Z3mixPcPfiii,@object           # @_Z3mixPcPfiii
	.section	.rodata,"a",@progbits
	.globl	_Z3mixPcPfiii
	.p2align	3, 0x0
_Z3mixPcPfiii:
	.quad	_Z18__device_stub__mixPcPfiii
	.size	_Z3mixPcPfiii, 8

	.type	_Z10simple_firPfS_iiiiii,@object # @_Z10simple_firPfS_iiiiii
	.globl	_Z10simple_firPfS_iiiiii
	.p2align	3, 0x0
_Z10simple_firPfS_iiiiii:
	.quad	_Z25__device_stub__simple_firPfS_iiiiii
	.size	_Z10simple_firPfS_iiiiii, 8

	.type	_Z10float_castPfPc,@object      # @_Z10float_castPfPc
	.globl	_Z10float_castPfPc
	.p2align	3, 0x0
_Z10float_castPfPc:
	.quad	_Z25__device_stub__float_castPfPc
	.size	_Z10float_castPfPc, 8

	.type	.L.str,@object                  # @.str
	.section	.rodata.str1.1,"aMS",@progbits,1
.L.str:
	.asciz	"%i, %i, %i, %i\n"
	.size	.L.str, 16

	.type	.L.str.2,@object                # @.str.2
.L.str.2:
	.asciz	"Producing %i output samples per block (%i samples).\n"
	.size	.L.str.2, 53

	.type	.L.str.3,@object                # @.str.3
.L.str.3:
	.asciz	"Using %i tap FIR filter.\n"
	.size	.L.str.3, 26

	.type	.L.str.4,@object                # @.str.4
.L.str.4:
	.asciz	"Preparing sin lookup table...\n"
	.size	.L.str.4, 31

	.type	.L.str.5,@object                # @.str.5
.L.str.5:
	.asciz	"Allocating block storage on GPU...\n"
	.size	.L.str.5, 36

	.type	.L.str.6,@object                # @.str.6
.L.str.6:
	.asciz	"Actual lo freq is: %f MHz (interval: %i, reminader: %i)\n"
	.size	.L.str.6, 57

	.type	.L.str.7,@object                # @.str.7
.L.str.7:
	.asciz	"GPU Configuration: blocks per grid: %i, threads per block: %i\n"
	.size	.L.str.7, 63

	.type	.L.str.8,@object                # @.str.8
.L.str.8:
	.asciz	"Producing %.2f s of data (%i loops reading a total of %.2f Mbytes of data)\n"
	.size	.L.str.8, 76

	.type	.L.str.9,@object                # @.str.9
.L.str.9:
	.asciz	"%i "
	.size	.L.str.9, 4

	.type	.L__unnamed_1,@object           # @0
.L__unnamed_1:
	.asciz	"_Z3mixPcPfiii"
	.size	.L__unnamed_1, 14

	.type	.L__unnamed_2,@object           # @1
.L__unnamed_2:
	.asciz	"_Z10simple_firPfS_iiiiii"
	.size	.L__unnamed_2, 25

	.type	.L__unnamed_3,@object           # @2
.L__unnamed_3:
	.asciz	"_Z10float_castPfPc"
	.size	.L__unnamed_3, 19

	.type	.L__unnamed_4,@object           # @3
.L__unnamed_4:
	.asciz	"cTaps"
	.size	.L__unnamed_4, 6

	.type	.L__unnamed_5,@object           # @4
.L__unnamed_5:
	.asciz	"cCos"
	.size	.L__unnamed_5, 5

	.type	__hip_fatbin_wrapper,@object    # @__hip_fatbin_wrapper
	.section	.hipFatBinSegment,"a",@progbits
	.p2align	3, 0x0
__hip_fatbin_wrapper:
	.long	1212764230                      # 0x48495046
	.long	1                               # 0x1
	.quad	__hip_fatbin
	.quad	0
	.size	__hip_fatbin_wrapper, 24

	.type	__hip_gpubin_handle,@object     # @__hip_gpubin_handle
	.local	__hip_gpubin_handle
	.comm	__hip_gpubin_handle,8,8
	.section	.init_array,"aw",@init_array
	.p2align	3, 0x0
	.quad	__hip_module_ctor
	.type	__hip_cuid_,@object             # @__hip_cuid_
	.bss
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               # 0x0
	.size	__hip_cuid_, 1

	.type	.Lstr,@object                   # @str
	.section	.rodata.str1.1,"aMS",@progbits,1
.Lstr:
	.asciz	"Please supply both data and fir_taps filenames..."
	.size	.Lstr, 50

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym _Z18__device_stub__mixPcPfiii
	.addrsig_sym _Z25__device_stub__simple_firPfS_iiiiii
	.addrsig_sym _Z25__device_stub__float_castPfPc
	.addrsig_sym __hip_module_ctor
	.addrsig_sym __hip_module_dtor
	.addrsig_sym cTaps
	.addrsig_sym t_start
	.addrsig_sym t_stop
	.addrsig_sym cCos
	.addrsig_sym _Z3mixPcPfiii
	.addrsig_sym _Z10simple_firPfS_iiiiii
	.addrsig_sym _Z10float_castPfPc
	.addrsig_sym __hip_fatbin
	.addrsig_sym __hip_fatbin_wrapper
	.addrsig_sym __hip_cuid_

	.text
	.amdgcn_target "amdgcn-amd-amdhsa--gfx1100"
	.protected	_Z3mixPcPfiii           ; -- Begin function _Z3mixPcPfiii
	.globl	_Z3mixPcPfiii
	.p2align	8
	.type	_Z3mixPcPfiii,@function
_Z3mixPcPfiii:                          ; @_Z3mixPcPfiii
; %bb.0:
	s_clause 0x1
	s_load_b256 s[4:11], s[0:1], 0x0
	s_load_b32 s0, s[0:1], 0x2c
	s_waitcnt lgkmcnt(0)
	s_ashr_i32 s1, s9, 31
	s_and_b32 s0, s0, 0xffff
	s_add_i32 s2, s9, s1
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(SALU_CYCLE_1)
	s_xor_b32 s1, s2, s1
	v_cvt_f32_u32_e32 v1, s1
	s_sub_i32 s2, 0, s1
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_1)
	v_rcp_iflag_f32_e32 v3, v1
	v_mad_u64_u32 v[1:2], null, s15, s0, v[0:1]
	v_mul_lo_u32 v2, v1, s8
	s_waitcnt_depctr 0xfff
	v_mul_f32_e32 v0, 0x4f7ffffe, v3
	s_delay_alu instid0(VALU_DEP_1) | instskip(SKIP_1) | instid1(VALU_DEP_2)
	v_cvt_u32_f32_e32 v0, v0
	v_ashrrev_i32_e32 v4, 31, v2
	v_mul_lo_u32 v3, s2, v0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_add_nc_u32_e32 v2, v2, v4
	v_xor_b32_e32 v2, v2, v4
	s_delay_alu instid0(VALU_DEP_3) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_hi_u32 v3, v0, v3
	v_add_nc_u32_e32 v0, v0, v3
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mul_hi_u32 v0, v2, v0
	v_mul_lo_u32 v0, v0, s1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_sub_nc_u32_e32 v0, v2, v0
	v_subrev_nc_u32_e32 v2, s1, v0
	v_cmp_le_u32_e32 vcc_lo, s1, v0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cndmask_b32_e32 v0, v0, v2, vcc_lo
	v_subrev_nc_u32_e32 v2, s1, v0
	v_cmp_le_u32_e32 vcc_lo, s1, v0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_cndmask_b32_e32 v0, v0, v2, vcc_lo
	v_xor_b32_e32 v0, v0, v4
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_sub_nc_u32_e32 v0, v0, v4
	v_add_nc_u32_e32 v2, s10, v0
	v_add_nc_u32_e32 v0, s0, v1
	s_getpc_b64 s[0:1]
	s_add_u32 s0, s0, cCos@rel32@lo+4
	s_addc_u32 s1, s1, cCos@rel32@hi+12
	v_ashrrev_i32_e32 v3, 31, v2
	s_delay_alu instid0(VALU_DEP_1)
	v_lshlrev_b64 v[1:2], 2, v[2:3]
	global_load_i8 v3, v0, s[4:5]
	v_add_co_u32 v1, vcc_lo, v1, s0
	v_add_co_ci_u32_e32 v2, vcc_lo, s1, v2, vcc_lo
	global_load_b32 v2, v[1:2], off
	v_mov_b32_e32 v1, 0
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[0:1], 2, v[0:1]
	v_add_co_u32 v0, vcc_lo, s6, v0
	s_delay_alu instid0(VALU_DEP_2) | instskip(SKIP_3) | instid1(VALU_DEP_1)
	v_add_co_ci_u32_e32 v1, vcc_lo, s7, v1, vcc_lo
	s_waitcnt vmcnt(1)
	v_cvt_f32_i32_e32 v3, v3
	s_waitcnt vmcnt(0)
	v_mul_f32_e32 v2, v2, v3
	global_store_b32 v[0:1], v2, off
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z3mixPcPfiii
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 288
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 5
		.amdhsa_next_free_sgpr 16
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end0:
	.size	_Z3mixPcPfiii, .Lfunc_end0-_Z3mixPcPfiii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 352
; NumSgprs: 18
; NumVgprs: 5
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 5
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.protected	_Z10simple_firPfS_iiiiii ; -- Begin function _Z10simple_firPfS_iiiiii
	.globl	_Z10simple_firPfS_iiiiii
	.p2align	8
	.type	_Z10simple_firPfS_iiiiii,@function
_Z10simple_firPfS_iiiiii:               ; @_Z10simple_firPfS_iiiiii
; %bb.0:
	s_clause 0x3
	s_load_b32 s8, s[0:1], 0x34
	s_load_b32 s3, s[0:1], 0x10
	s_load_b128 s[4:7], s[0:1], 0x0
	s_load_b32 s2, s[0:1], 0x18
	s_waitcnt lgkmcnt(0)
	s_and_b32 s0, s8, 0xffff
	s_cmp_lt_i32 s3, 1
	v_mad_u64_u32 v[1:2], null, s15, s0, v[0:1]
	s_cbranch_scc1 .LBB1_3
; %bb.1:                                ; %.lr.ph.preheader
	s_delay_alu instid0(VALU_DEP_1)
	v_mad_u64_u32 v[2:3], null, v1, s2, s[0:1]
	v_mov_b32_e32 v0, 0
	s_getpc_b64 s[0:1]
	s_add_u32 s0, s0, cTaps@rel32@lo+4
	s_addc_u32 s1, s1, cTaps@rel32@hi+12
.LBB1_2:                                ; %.lr.ph
                                        ; =>This Inner Loop Header: Depth=1
	s_delay_alu instid0(VALU_DEP_2)
	v_ashrrev_i32_e32 v3, 31, v2
	s_load_b32 s8, s[0:1], 0x0
	s_add_i32 s3, s3, -1
	s_add_u32 s0, s0, 4
	s_addc_u32 s1, s1, 0
	v_lshlrev_b64 v[3:4], 2, v[2:3]
	v_add_nc_u32_e32 v2, -1, v2
	s_cmp_eq_u32 s3, 0
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_3)
	v_add_co_u32 v3, vcc_lo, s4, v3
	v_add_co_ci_u32_e32 v4, vcc_lo, s5, v4, vcc_lo
	global_load_b32 v3, v[3:4], off
	s_waitcnt vmcnt(0) lgkmcnt(0)
	v_fmac_f32_e32 v0, s8, v3
	s_cbranch_scc0 .LBB1_2
	s_branch .LBB1_4
.LBB1_3:
	v_mov_b32_e32 v0, 0
.LBB1_4:                                ; %Flow28
	v_cvt_f32_i32_e32 v3, s2
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_dual_mov_b32 v2, 0 :: v_dual_mul_f32 v3, 0x3e000000, v3
	v_lshlrev_b64 v[1:2], 2, v[1:2]
	s_delay_alu instid0(VALU_DEP_2) | instskip(NEXT) | instid1(VALU_DEP_2)
	v_mul_f32_e32 v3, v3, v0
	v_add_co_u32 v0, vcc_lo, s6, v1
	s_delay_alu instid0(VALU_DEP_3)
	v_add_co_ci_u32_e32 v1, vcc_lo, s7, v2, vcc_lo
	global_store_b32 v[0:1], v3, off
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z10simple_firPfS_iiiiii
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 296
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 5
		.amdhsa_next_free_sgpr 16
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end1:
	.size	_Z10simple_firPfS_iiiiii, .Lfunc_end1-_Z10simple_firPfS_iiiiii
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 260
; NumSgprs: 18
; NumVgprs: 5
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 5
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.protected	_Z10float_castPfPc      ; -- Begin function _Z10float_castPfPc
	.globl	_Z10float_castPfPc
	.p2align	8
	.type	_Z10float_castPfPc,@function
_Z10float_castPfPc:                     ; @_Z10float_castPfPc
; %bb.0:
	s_clause 0x1
	s_load_b32 s4, s[0:1], 0x1c
	s_load_b128 s[0:3], s[0:1], 0x0
	s_waitcnt lgkmcnt(0)
	s_and_b32 s4, s4, 0xffff
	s_delay_alu instid0(SALU_CYCLE_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_mad_u64_u32 v[1:2], null, s15, s4, v[0:1]
	v_ashrrev_i32_e32 v2, 31, v1
	s_delay_alu instid0(VALU_DEP_1) | instskip(NEXT) | instid1(VALU_DEP_1)
	v_lshlrev_b64 v[3:4], 2, v[1:2]
	v_add_co_u32 v3, vcc_lo, s0, v3
	s_delay_alu instid0(VALU_DEP_2)
	v_add_co_ci_u32_e32 v4, vcc_lo, s1, v4, vcc_lo
	global_load_b32 v0, v[3:4], off
	s_waitcnt vmcnt(0)
	v_cvt_i32_f32_e32 v3, v0
	v_add_co_u32 v0, vcc_lo, s2, v1
	v_add_co_ci_u32_e32 v1, vcc_lo, s3, v2, vcc_lo
	global_store_b8 v[0:1], v3, off
	s_nop 0
	s_sendmsg sendmsg(MSG_DEALLOC_VGPRS)
	s_endpgm
	.section	.rodata,"a",@progbits
	.p2align	6, 0x0
	.amdhsa_kernel _Z10float_castPfPc
		.amdhsa_group_segment_fixed_size 0
		.amdhsa_private_segment_fixed_size 0
		.amdhsa_kernarg_size 272
		.amdhsa_user_sgpr_count 15
		.amdhsa_user_sgpr_dispatch_ptr 0
		.amdhsa_user_sgpr_queue_ptr 0
		.amdhsa_user_sgpr_kernarg_segment_ptr 1
		.amdhsa_user_sgpr_dispatch_id 0
		.amdhsa_user_sgpr_private_segment_size 0
		.amdhsa_wavefront_size32 1
		.amdhsa_uses_dynamic_stack 0
		.amdhsa_enable_private_segment 0
		.amdhsa_system_sgpr_workgroup_id_x 1
		.amdhsa_system_sgpr_workgroup_id_y 0
		.amdhsa_system_sgpr_workgroup_id_z 0
		.amdhsa_system_sgpr_workgroup_info 0
		.amdhsa_system_vgpr_workitem_id 0
		.amdhsa_next_free_vgpr 5
		.amdhsa_next_free_sgpr 16
		.amdhsa_float_round_mode_32 0
		.amdhsa_float_round_mode_16_64 0
		.amdhsa_float_denorm_mode_32 3
		.amdhsa_float_denorm_mode_16_64 3
		.amdhsa_dx10_clamp 1
		.amdhsa_ieee_mode 1
		.amdhsa_fp16_overflow 0
		.amdhsa_workgroup_processor_mode 1
		.amdhsa_memory_ordered 1
		.amdhsa_forward_progress 0
		.amdhsa_shared_vgpr_count 0
		.amdhsa_exception_fp_ieee_invalid_op 0
		.amdhsa_exception_fp_denorm_src 0
		.amdhsa_exception_fp_ieee_div_zero 0
		.amdhsa_exception_fp_ieee_overflow 0
		.amdhsa_exception_fp_ieee_underflow 0
		.amdhsa_exception_fp_ieee_inexact 0
		.amdhsa_exception_int_div_zero 0
	.end_amdhsa_kernel
	.text
.Lfunc_end2:
	.size	_Z10float_castPfPc, .Lfunc_end2-_Z10float_castPfPc
                                        ; -- End function
	.section	.AMDGPU.csdata,"",@progbits
; Kernel info:
; codeLenInByte = 124
; NumSgprs: 18
; NumVgprs: 5
; ScratchSize: 0
; MemoryBound: 0
; FloatMode: 240
; IeeeMode: 1
; LDSByteSize: 0 bytes/workgroup (compile time only)
; SGPRBlocks: 2
; VGPRBlocks: 0
; NumSGPRsForWavesPerEU: 18
; NumVGPRsForWavesPerEU: 5
; Occupancy: 16
; WaveLimiterHint : 0
; COMPUTE_PGM_RSRC2:SCRATCH_EN: 0
; COMPUTE_PGM_RSRC2:USER_SGPR: 15
; COMPUTE_PGM_RSRC2:TRAP_HANDLER: 0
; COMPUTE_PGM_RSRC2:TGID_X_EN: 1
; COMPUTE_PGM_RSRC2:TGID_Y_EN: 0
; COMPUTE_PGM_RSRC2:TGID_Z_EN: 0
; COMPUTE_PGM_RSRC2:TIDIG_COMP_CNT: 0
	.text
	.p2alignl 7, 3214868480
	.fill 96, 4, 3214868480
	.protected	cTaps                   ; @cTaps
	.type	cTaps,@object
	.section	.bss,"aw",@nobits
	.globl	cTaps
	.p2align	4, 0x0
cTaps:
	.zero	2048
	.size	cTaps, 2048

	.protected	cCos                    ; @cCos
	.type	cCos,@object
	.globl	cCos
	.p2align	4, 0x0
cCos:
	.zero	32000
	.size	cCos, 32000

	.type	__hip_cuid_,@object             ; @__hip_cuid_
	.globl	__hip_cuid_
__hip_cuid_:
	.byte	0                               ; 0x0
	.size	__hip_cuid_, 1

	.ident	"AMD clang version 18.0.0git (https://github.com/RadeonOpenCompute/llvm-project roc-6.3.2 25012 e5bf7e55c91490b07c49d8960fa7983d864936c4)"
	.section	".note.GNU-stack","",@progbits
	.addrsig
	.addrsig_sym cTaps
	.addrsig_sym cCos
	.addrsig_sym __hip_cuid_
	.amdgpu_metadata
---
amdhsa.kernels:
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .offset:         16
        .size:           4
        .value_kind:     by_value
      - .offset:         20
        .size:           4
        .value_kind:     by_value
      - .offset:         24
        .size:           4
        .value_kind:     by_value
      - .offset:         32
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         36
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         40
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         44
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         46
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         48
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         50
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         52
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         54
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         96
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 288
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z3mixPcPfiii
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z3mixPcPfiii.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     5
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .offset:         16
        .size:           4
        .value_kind:     by_value
      - .offset:         20
        .size:           4
        .value_kind:     by_value
      - .offset:         24
        .size:           4
        .value_kind:     by_value
      - .offset:         28
        .size:           4
        .value_kind:     by_value
      - .offset:         32
        .size:           4
        .value_kind:     by_value
      - .offset:         36
        .size:           4
        .value_kind:     by_value
      - .offset:         40
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         44
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         48
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         52
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         54
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         56
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         58
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         60
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         62
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         80
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         88
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         96
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         104
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 296
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z10simple_firPfS_iiiiii
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z10simple_firPfS_iiiiii.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     5
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
  - .args:
      - .address_space:  global
        .offset:         0
        .size:           8
        .value_kind:     global_buffer
      - .address_space:  global
        .offset:         8
        .size:           8
        .value_kind:     global_buffer
      - .offset:         16
        .size:           4
        .value_kind:     hidden_block_count_x
      - .offset:         20
        .size:           4
        .value_kind:     hidden_block_count_y
      - .offset:         24
        .size:           4
        .value_kind:     hidden_block_count_z
      - .offset:         28
        .size:           2
        .value_kind:     hidden_group_size_x
      - .offset:         30
        .size:           2
        .value_kind:     hidden_group_size_y
      - .offset:         32
        .size:           2
        .value_kind:     hidden_group_size_z
      - .offset:         34
        .size:           2
        .value_kind:     hidden_remainder_x
      - .offset:         36
        .size:           2
        .value_kind:     hidden_remainder_y
      - .offset:         38
        .size:           2
        .value_kind:     hidden_remainder_z
      - .offset:         56
        .size:           8
        .value_kind:     hidden_global_offset_x
      - .offset:         64
        .size:           8
        .value_kind:     hidden_global_offset_y
      - .offset:         72
        .size:           8
        .value_kind:     hidden_global_offset_z
      - .offset:         80
        .size:           2
        .value_kind:     hidden_grid_dims
    .group_segment_fixed_size: 0
    .kernarg_segment_align: 8
    .kernarg_segment_size: 272
    .language:       OpenCL C
    .language_version:
      - 2
      - 0
    .max_flat_workgroup_size: 1024
    .name:           _Z10float_castPfPc
    .private_segment_fixed_size: 0
    .sgpr_count:     18
    .sgpr_spill_count: 0
    .symbol:         _Z10float_castPfPc.kd
    .uniform_work_group_size: 1
    .uses_dynamic_stack: false
    .vgpr_count:     5
    .vgpr_spill_count: 0
    .wavefront_size: 32
    .workgroup_processor_mode: 1
amdhsa.target:   amdgcn-amd-amdhsa--gfx1100
amdhsa.version:
  - 1
  - 2
...

	.end_amdgpu_metadata
