// File: tomfunkhouser[P]gaps/pkgs/jpeg/jcdctmgr.c
// Function: forward_DCT_float
METHODDEF(void)
forward_DCT_float (j_compress_ptr cinfo, jpeg_component_info * compptr,
		   JSAMPARRAY sample_data, JBLOCKROW coef_blocks,
		   JDIMENSION start_row, JDIMENSION start_col,
		   JDIMENSION num_blocks)
/* This version is used for floating-point DCT implementations. */
{
  /* This routine is heavily used, so it's worth coding it tightly. */
  my_fdct_ptr fdct = (my_fdct_ptr) cinfo->fdct;
  float_DCT_method_ptr do_dct = fdct->do_float_dct;
  FAST_FLOAT * divisors = fdct->float_divisors[compptr->quant_tbl_no];
  FAST_FLOAT workspace[DCTSIZE2]; /* work area for FDCT subroutine */
  JDIMENSION bi;

  sample_data += start_row;	/* fold in the vertical offset once */

  for (bi = 0; bi < num_blocks; bi++, start_col += DCTSIZE) {
    /* Load data into workspace, applying unsigned->signed conversion */
    { register FAST_FLOAT *workspaceptr;
      register JSAMPROW elemptr;
      register int elemr;

      workspaceptr = workspace;
      for (elemr = 0; elemr < DCTSIZE; elemr++) {
	elemptr = sample_data[elemr] + start_col;
#if DCTSIZE == 8		/* unroll the inner loop */
	*workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
	*workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
	*workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
	*workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
	*workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
	*workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
	*workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
	*workspaceptr++ = (FAST_FLOAT)(GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
#else
	{ register int elemc;
	  for (elemc = DCTSIZE; elemc > 0; elemc--) {
	    *workspaceptr++ = (FAST_FLOAT)
	      (GETJSAMPLE(*elemptr++) - CENTERJSAMPLE);
	  }
	}
#endif
      }
    }

    /* Perform the DCT */
    (*do_dct) (workspace);

    /* Quantize/descale the coefficients, and store into coef_blocks[] */
    { register FAST_FLOAT temp;
      register int i;
      register JCOEFPTR output_ptr = coef_blocks[bi];

      for (i = 0; i < DCTSIZE2; i++) {
	/* Apply the quantization and scaling factor */
	temp = workspace[i] * divisors[i];
	/* Round to nearest integer.
	 * Since C does not specify the direction of rounding for negative
	 * quotients, we have to force the dividend positive for portability.
	 * The maximum coefficient size is +-16K (for 12-bit data), so this
	 * code should work for either 16-bit or 32-bit ints.
	 */
	output_ptr[i] = (JCOEF) ((int) (temp + (FAST_FLOAT) 16384.5) - 16384);
      }
    }
  }
}

// Assembly:
subq $0x178, %rsp            # imm = 0x178
movl 0x180(%rsp), %eax
movq %rdi, 0x170(%rsp)
movq %rsi, 0x168(%rsp)
movq %rdx, 0x160(%rsp)
movq %rcx, 0x158(%rsp)
movl %r8d, 0x154(%rsp)
movl %r9d, 0x150(%rsp)
movq 0x170(%rsp), %rax
movq 0x1e8(%rax), %rax
movq %rax, 0x148(%rsp)
movq 0x148(%rsp), %rax
movq 0x38(%rax), %rax
movq %rax, 0x140(%rsp)
movq 0x148(%rsp), %rax
movq 0x168(%rsp), %rcx
movslq 0x10(%rcx), %rcx
movq 0x40(%rax,%rcx,8), %rax
movq %rax, 0x138(%rsp)
movl 0x154(%rsp), %ecx
movq 0x160(%rsp), %rax
movl %ecx, %ecx
shlq $0x3, %rcx
addq %rcx, %rax
movq %rax, 0x160(%rsp)
movl $0x0, 0x2c(%rsp)
movl 0x2c(%rsp), %eax
cmpl 0x180(%rsp), %eax
jae 0xe11ff
leaq 0x30(%rsp), %rax
movq %rax, 0x20(%rsp)
movl $0x0, 0x14(%rsp)
cmpl $0x8, 0x14(%rsp)
jge 0xe1150
movq 0x160(%rsp), %rax
movslq 0x14(%rsp), %rcx
movq (%rax,%rcx,8), %rax
movl 0x150(%rsp), %ecx
addq %rcx, %rax
movq %rax, 0x18(%rsp)
movq 0x18(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, 0x18(%rsp)
movzbl (%rax), %eax
subl $0x80, %eax
cvtsi2ss %eax, %xmm0
movq 0x20(%rsp), %rax
movq %rax, %rcx
addq $0x4, %rcx
movq %rcx, 0x20(%rsp)
movss %xmm0, (%rax)
movq 0x18(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, 0x18(%rsp)
movzbl (%rax), %eax
subl $0x80, %eax
cvtsi2ss %eax, %xmm0
movq 0x20(%rsp), %rax
movq %rax, %rcx
addq $0x4, %rcx
movq %rcx, 0x20(%rsp)
movss %xmm0, (%rax)
movq 0x18(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, 0x18(%rsp)
movzbl (%rax), %eax
subl $0x80, %eax
cvtsi2ss %eax, %xmm0
movq 0x20(%rsp), %rax
movq %rax, %rcx
addq $0x4, %rcx
movq %rcx, 0x20(%rsp)
movss %xmm0, (%rax)
movq 0x18(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, 0x18(%rsp)
movzbl (%rax), %eax
subl $0x80, %eax
cvtsi2ss %eax, %xmm0
movq 0x20(%rsp), %rax
movq %rax, %rcx
addq $0x4, %rcx
movq %rcx, 0x20(%rsp)
movss %xmm0, (%rax)
movq 0x18(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, 0x18(%rsp)
movzbl (%rax), %eax
subl $0x80, %eax
cvtsi2ss %eax, %xmm0
movq 0x20(%rsp), %rax
movq %rax, %rcx
addq $0x4, %rcx
movq %rcx, 0x20(%rsp)
movss %xmm0, (%rax)
movq 0x18(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, 0x18(%rsp)
movzbl (%rax), %eax
subl $0x80, %eax
cvtsi2ss %eax, %xmm0
movq 0x20(%rsp), %rax
movq %rax, %rcx
addq $0x4, %rcx
movq %rcx, 0x20(%rsp)
movss %xmm0, (%rax)
movq 0x18(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, 0x18(%rsp)
movzbl (%rax), %eax
subl $0x80, %eax
cvtsi2ss %eax, %xmm0
movq 0x20(%rsp), %rax
movq %rax, %rcx
addq $0x4, %rcx
movq %rcx, 0x20(%rsp)
movss %xmm0, (%rax)
movq 0x18(%rsp), %rax
movq %rax, %rcx
addq $0x1, %rcx
movq %rcx, 0x18(%rsp)
movzbl (%rax), %eax
subl $0x80, %eax
cvtsi2ss %eax, %xmm0
movq 0x20(%rsp), %rax
movq %rax, %rcx
addq $0x4, %rcx
movq %rcx, 0x20(%rsp)
movss %xmm0, (%rax)
movl 0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x14(%rsp)
jmp 0xe0f85
movq 0x140(%rsp), %rax
leaq 0x30(%rsp), %rdi
callq *%rax
movq 0x158(%rsp), %rax
movl 0x2c(%rsp), %ecx
shlq $0x7, %rcx
addq %rcx, %rax
movq %rax, (%rsp)
movl $0x0, 0xc(%rsp)
cmpl $0x40, 0xc(%rsp)
jge 0xe11dc
movslq 0xc(%rsp), %rax
movss 0x30(%rsp,%rax,4), %xmm0
movq 0x138(%rsp), %rax
movslq 0xc(%rsp), %rcx
mulss (%rax,%rcx,4), %xmm0
movss %xmm0, 0x10(%rsp)
movss 0x55ba8(%rip), %xmm0    # 0x136d58
addss 0x10(%rsp), %xmm0
cvttss2si %xmm0, %eax
subl $0x4000, %eax           # imm = 0x4000
movw %ax, %dx
movq (%rsp), %rax
movslq 0xc(%rsp), %rcx
movw %dx, (%rax,%rcx,2)
movl 0xc(%rsp), %eax
addl $0x1, %eax
movl %eax, 0xc(%rsp)
jmp 0xe117e
jmp 0xe11de
movl 0x2c(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x2c(%rsp)
movl 0x150(%rsp), %eax
addl $0x8, %eax
movl %eax, 0x150(%rsp)
jmp 0xe0f62
addq $0x178, %rsp            # imm = 0x178
retq
nopw (%rax,%rax)