// File: tomfunkhouser[P]gaps/pkgs/jpeg/jfdctint.c
// Function: jpeg_fdct_islow
GLOBAL(void)
jpeg_fdct_islow (DCTELEM * data)
{
  INT32 tmp0, tmp1, tmp2, tmp3, tmp4, tmp5, tmp6, tmp7;
  INT32 tmp10, tmp11, tmp12, tmp13;
  INT32 z1, z2, z3, z4, z5;
  DCTELEM *dataptr;
  int ctr;
  SHIFT_TEMPS

  /* Pass 1: process rows. */
  /* Note results are scaled up by sqrt(8) compared to a true DCT; */
  /* furthermore, we scale the results by 2**PASS1_BITS. */

  dataptr = data;
  for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
    tmp0 = dataptr[0] + dataptr[7];
    tmp7 = dataptr[0] - dataptr[7];
    tmp1 = dataptr[1] + dataptr[6];
    tmp6 = dataptr[1] - dataptr[6];
    tmp2 = dataptr[2] + dataptr[5];
    tmp5 = dataptr[2] - dataptr[5];
    tmp3 = dataptr[3] + dataptr[4];
    tmp4 = dataptr[3] - dataptr[4];
    
    /* Even part per LL&M figure 1 --- note that published figure is faulty;
     * rotator "sqrt(2)*c1" should be "sqrt(2)*c6".
     */
    
    tmp10 = tmp0 + tmp3;
    tmp13 = tmp0 - tmp3;
    tmp11 = tmp1 + tmp2;
    tmp12 = tmp1 - tmp2;
    
    dataptr[0] = (DCTELEM) ((tmp10 + tmp11) << PASS1_BITS);
    dataptr[4] = (DCTELEM) ((tmp10 - tmp11) << PASS1_BITS);
    
    z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
    dataptr[2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
				   CONST_BITS-PASS1_BITS);
    dataptr[6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
				   CONST_BITS-PASS1_BITS);
    
    /* Odd part per figure 8 --- note paper omits factor of sqrt(2).
     * cK represents cos(K*pi/16).
     * i0..i3 in the paper are tmp4..tmp7 here.
     */
    
    z1 = tmp4 + tmp7;
    z2 = tmp5 + tmp6;
    z3 = tmp4 + tmp6;
    z4 = tmp5 + tmp7;
    z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
    
    tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
    tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
    tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
    tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
    z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
    z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
    z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
    z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
    
    z3 += z5;
    z4 += z5;
    
    dataptr[7] = (DCTELEM) DESCALE(tmp4 + z1 + z3, CONST_BITS-PASS1_BITS);
    dataptr[5] = (DCTELEM) DESCALE(tmp5 + z2 + z4, CONST_BITS-PASS1_BITS);
    dataptr[3] = (DCTELEM) DESCALE(tmp6 + z2 + z3, CONST_BITS-PASS1_BITS);
    dataptr[1] = (DCTELEM) DESCALE(tmp7 + z1 + z4, CONST_BITS-PASS1_BITS);
    
    dataptr += DCTSIZE;		/* advance pointer to next row */
  }

  /* Pass 2: process columns.
   * We remove the PASS1_BITS scaling, but leave the results scaled up
   * by an overall factor of 8.
   */

  dataptr = data;
  for (ctr = DCTSIZE-1; ctr >= 0; ctr--) {
    tmp0 = dataptr[DCTSIZE*0] + dataptr[DCTSIZE*7];
    tmp7 = dataptr[DCTSIZE*0] - dataptr[DCTSIZE*7];
    tmp1 = dataptr[DCTSIZE*1] + dataptr[DCTSIZE*6];
    tmp6 = dataptr[DCTSIZE*1] - dataptr[DCTSIZE*6];
    tmp2 = dataptr[DCTSIZE*2] + dataptr[DCTSIZE*5];
    tmp5 = dataptr[DCTSIZE*2] - dataptr[DCTSIZE*5];
    tmp3 = dataptr[DCTSIZE*3] + dataptr[DCTSIZE*4];
    tmp4 = dataptr[DCTSIZE*3] - dataptr[DCTSIZE*4];
    
    /* Even part per LL&M figure 1 --- note that published figure is faulty;
     * rotator "sqrt(2)*c1" should be "sqrt(2)*c6".
     */
    
    tmp10 = tmp0 + tmp3;
    tmp13 = tmp0 - tmp3;
    tmp11 = tmp1 + tmp2;
    tmp12 = tmp1 - tmp2;
    
    dataptr[DCTSIZE*0] = (DCTELEM) DESCALE(tmp10 + tmp11, PASS1_BITS);
    dataptr[DCTSIZE*4] = (DCTELEM) DESCALE(tmp10 - tmp11, PASS1_BITS);
    
    z1 = MULTIPLY(tmp12 + tmp13, FIX_0_541196100);
    dataptr[DCTSIZE*2] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp13, FIX_0_765366865),
					   CONST_BITS+PASS1_BITS);
    dataptr[DCTSIZE*6] = (DCTELEM) DESCALE(z1 + MULTIPLY(tmp12, - FIX_1_847759065),
					   CONST_BITS+PASS1_BITS);
    
    /* Odd part per figure 8 --- note paper omits factor of sqrt(2).
     * cK represents cos(K*pi/16).
     * i0..i3 in the paper are tmp4..tmp7 here.
     */
    
    z1 = tmp4 + tmp7;
    z2 = tmp5 + tmp6;
    z3 = tmp4 + tmp6;
    z4 = tmp5 + tmp7;
    z5 = MULTIPLY(z3 + z4, FIX_1_175875602); /* sqrt(2) * c3 */
    
    tmp4 = MULTIPLY(tmp4, FIX_0_298631336); /* sqrt(2) * (-c1+c3+c5-c7) */
    tmp5 = MULTIPLY(tmp5, FIX_2_053119869); /* sqrt(2) * ( c1+c3-c5+c7) */
    tmp6 = MULTIPLY(tmp6, FIX_3_072711026); /* sqrt(2) * ( c1+c3+c5-c7) */
    tmp7 = MULTIPLY(tmp7, FIX_1_501321110); /* sqrt(2) * ( c1+c3-c5-c7) */
    z1 = MULTIPLY(z1, - FIX_0_899976223); /* sqrt(2) * (c7-c3) */
    z2 = MULTIPLY(z2, - FIX_2_562915447); /* sqrt(2) * (-c1-c3) */
    z3 = MULTIPLY(z3, - FIX_1_961570560); /* sqrt(2) * (-c3-c5) */
    z4 = MULTIPLY(z4, - FIX_0_390180644); /* sqrt(2) * (c5-c3) */
    
    z3 += z5;
    z4 += z5;
    
    dataptr[DCTSIZE*7] = (DCTELEM) DESCALE(tmp4 + z1 + z3,
					   CONST_BITS+PASS1_BITS);
    dataptr[DCTSIZE*5] = (DCTELEM) DESCALE(tmp5 + z2 + z4,
					   CONST_BITS+PASS1_BITS);
    dataptr[DCTSIZE*3] = (DCTELEM) DESCALE(tmp6 + z2 + z3,
					   CONST_BITS+PASS1_BITS);
    dataptr[DCTSIZE*1] = (DCTELEM) DESCALE(tmp7 + z1 + z4,
					   CONST_BITS+PASS1_BITS);
    
    dataptr++;			/* advance pointer to next column */
  }
}

// Assembly:
subq $0x20, %rsp
movq %rdi, 0x18(%rsp)
movq 0x18(%rsp), %rax
movq %rax, -0x78(%rsp)
movl $0x7, -0x7c(%rsp)
cmpl $0x0, -0x7c(%rsp)
jl 0xe1fee
movq -0x78(%rsp), %rax
movl (%rax), %eax
movq -0x78(%rsp), %rcx
addl 0x1c(%rcx), %eax
cltq
movq %rax, 0x10(%rsp)
movq -0x78(%rsp), %rax
movl (%rax), %eax
movq -0x78(%rsp), %rcx
subl 0x1c(%rcx), %eax
cltq
movq %rax, -0x28(%rsp)
movq -0x78(%rsp), %rax
movl 0x4(%rax), %eax
movq -0x78(%rsp), %rcx
addl 0x18(%rcx), %eax
cltq
movq %rax, 0x8(%rsp)
movq -0x78(%rsp), %rax
movl 0x4(%rax), %eax
movq -0x78(%rsp), %rcx
subl 0x18(%rcx), %eax
cltq
movq %rax, -0x20(%rsp)
movq -0x78(%rsp), %rax
movl 0x8(%rax), %eax
movq -0x78(%rsp), %rcx
addl 0x14(%rcx), %eax
cltq
movq %rax, (%rsp)
movq -0x78(%rsp), %rax
movl 0x8(%rax), %eax
movq -0x78(%rsp), %rcx
subl 0x14(%rcx), %eax
cltq
movq %rax, -0x18(%rsp)
movq -0x78(%rsp), %rax
movl 0xc(%rax), %eax
movq -0x78(%rsp), %rcx
addl 0x10(%rcx), %eax
cltq
movq %rax, -0x8(%rsp)
movq -0x78(%rsp), %rax
movl 0xc(%rax), %eax
movq -0x78(%rsp), %rcx
subl 0x10(%rcx), %eax
cltq
movq %rax, -0x10(%rsp)
movq 0x10(%rsp), %rax
addq -0x8(%rsp), %rax
movq %rax, -0x30(%rsp)
movq 0x10(%rsp), %rax
subq -0x8(%rsp), %rax
movq %rax, -0x48(%rsp)
movq 0x8(%rsp), %rax
addq (%rsp), %rax
movq %rax, -0x38(%rsp)
movq 0x8(%rsp), %rax
subq (%rsp), %rax
movq %rax, -0x40(%rsp)
movq -0x30(%rsp), %rax
addq -0x38(%rsp), %rax
shlq $0x2, %rax
movl %eax, %ecx
movq -0x78(%rsp), %rax
movl %ecx, (%rax)
movq -0x30(%rsp), %rax
subq -0x38(%rsp), %rax
shlq $0x2, %rax
movl %eax, %ecx
movq -0x78(%rsp), %rax
movl %ecx, 0x10(%rax)
movq -0x40(%rsp), %rax
addq -0x48(%rsp), %rax
imulq $0x1151, %rax, %rax     # imm = 0x1151
movq %rax, -0x50(%rsp)
movq -0x50(%rsp), %rax
imulq $0x187e, -0x48(%rsp), %rcx # imm = 0x187E
addq %rcx, %rax
addq $0x400, %rax            # imm = 0x400
sarq $0xb, %rax
movl %eax, %ecx
movq -0x78(%rsp), %rax
movl %ecx, 0x8(%rax)
movq -0x50(%rsp), %rax
imulq $-0x3b21, -0x40(%rsp), %rcx # imm = 0xC4DF
addq %rcx, %rax
addq $0x400, %rax            # imm = 0x400
sarq $0xb, %rax
movl %eax, %ecx
movq -0x78(%rsp), %rax
movl %ecx, 0x18(%rax)
movq -0x10(%rsp), %rax
addq -0x28(%rsp), %rax
movq %rax, -0x50(%rsp)
movq -0x18(%rsp), %rax
addq -0x20(%rsp), %rax
movq %rax, -0x58(%rsp)
movq -0x10(%rsp), %rax
addq -0x20(%rsp), %rax
movq %rax, -0x60(%rsp)
movq -0x18(%rsp), %rax
addq -0x28(%rsp), %rax
movq %rax, -0x68(%rsp)
movq -0x60(%rsp), %rax
addq -0x68(%rsp), %rax
imulq $0x25a1, %rax, %rax     # imm = 0x25A1
movq %rax, -0x70(%rsp)
imulq $0x98e, -0x10(%rsp), %rax # imm = 0x98E
movq %rax, -0x10(%rsp)
imulq $0x41b3, -0x18(%rsp), %rax # imm = 0x41B3
movq %rax, -0x18(%rsp)
imulq $0x6254, -0x20(%rsp), %rax # imm = 0x6254
movq %rax, -0x20(%rsp)
imulq $0x300b, -0x28(%rsp), %rax # imm = 0x300B
movq %rax, -0x28(%rsp)
imulq $-0x1ccd, -0x50(%rsp), %rax # imm = 0xE333
movq %rax, -0x50(%rsp)
imulq $-0x5203, -0x58(%rsp), %rax # imm = 0xADFD
movq %rax, -0x58(%rsp)
imulq $-0x3ec5, -0x60(%rsp), %rax # imm = 0xC13B
movq %rax, -0x60(%rsp)
imulq $-0xc7c, -0x68(%rsp), %rax # imm = 0xF384
movq %rax, -0x68(%rsp)
movq -0x70(%rsp), %rax
addq -0x60(%rsp), %rax
movq %rax, -0x60(%rsp)
movq -0x70(%rsp), %rax
addq -0x68(%rsp), %rax
movq %rax, -0x68(%rsp)
movq -0x10(%rsp), %rax
addq -0x50(%rsp), %rax
addq -0x60(%rsp), %rax
addq $0x400, %rax            # imm = 0x400
sarq $0xb, %rax
movl %eax, %ecx
movq -0x78(%rsp), %rax
movl %ecx, 0x1c(%rax)
movq -0x18(%rsp), %rax
addq -0x58(%rsp), %rax
addq -0x68(%rsp), %rax
addq $0x400, %rax            # imm = 0x400
sarq $0xb, %rax
movl %eax, %ecx
movq -0x78(%rsp), %rax
movl %ecx, 0x14(%rax)
movq -0x20(%rsp), %rax
addq -0x58(%rsp), %rax
addq -0x60(%rsp), %rax
addq $0x400, %rax            # imm = 0x400
sarq $0xb, %rax
movl %eax, %ecx
movq -0x78(%rsp), %rax
movl %ecx, 0xc(%rax)
movq -0x28(%rsp), %rax
addq -0x50(%rsp), %rax
addq -0x68(%rsp), %rax
addq $0x400, %rax            # imm = 0x400
sarq $0xb, %rax
movl %eax, %ecx
movq -0x78(%rsp), %rax
movl %ecx, 0x4(%rax)
movq -0x78(%rsp), %rax
addq $0x20, %rax
movq %rax, -0x78(%rsp)
movl -0x7c(%rsp), %eax
addl $-0x1, %eax
movl %eax, -0x7c(%rsp)
jmp 0xe1cdb
movq 0x18(%rsp), %rax
movq %rax, -0x78(%rsp)
movl $0x7, -0x7c(%rsp)
cmpl $0x0, -0x7c(%rsp)
jl 0xe233f
movq -0x78(%rsp), %rax
movl (%rax), %eax
movq -0x78(%rsp), %rcx
addl 0xe0(%rcx), %eax
cltq
movq %rax, 0x10(%rsp)
movq -0x78(%rsp), %rax
movl (%rax), %eax
movq -0x78(%rsp), %rcx
subl 0xe0(%rcx), %eax
cltq
movq %rax, -0x28(%rsp)
movq -0x78(%rsp), %rax
movl 0x20(%rax), %eax
movq -0x78(%rsp), %rcx
addl 0xc0(%rcx), %eax
cltq
movq %rax, 0x8(%rsp)
movq -0x78(%rsp), %rax
movl 0x20(%rax), %eax
movq -0x78(%rsp), %rcx
subl 0xc0(%rcx), %eax
cltq
movq %rax, -0x20(%rsp)
movq -0x78(%rsp), %rax
movl 0x40(%rax), %eax
movq -0x78(%rsp), %rcx
addl 0xa0(%rcx), %eax
cltq
movq %rax, (%rsp)
movq -0x78(%rsp), %rax
movl 0x40(%rax), %eax
movq -0x78(%rsp), %rcx
subl 0xa0(%rcx), %eax
cltq
movq %rax, -0x18(%rsp)
movq -0x78(%rsp), %rax
movl 0x60(%rax), %eax
movq -0x78(%rsp), %rcx
addl 0x80(%rcx), %eax
cltq
movq %rax, -0x8(%rsp)
movq -0x78(%rsp), %rax
movl 0x60(%rax), %eax
movq -0x78(%rsp), %rcx
subl 0x80(%rcx), %eax
cltq
movq %rax, -0x10(%rsp)
movq 0x10(%rsp), %rax
addq -0x8(%rsp), %rax
movq %rax, -0x30(%rsp)
movq 0x10(%rsp), %rax
subq -0x8(%rsp), %rax
movq %rax, -0x48(%rsp)
movq 0x8(%rsp), %rax
addq (%rsp), %rax
movq %rax, -0x38(%rsp)
movq 0x8(%rsp), %rax
subq (%rsp), %rax
movq %rax, -0x40(%rsp)
movq -0x30(%rsp), %rax
addq -0x38(%rsp), %rax
addq $0x2, %rax
sarq $0x2, %rax
movl %eax, %ecx
movq -0x78(%rsp), %rax
movl %ecx, (%rax)
movq -0x30(%rsp), %rax
subq -0x38(%rsp), %rax
addq $0x2, %rax
sarq $0x2, %rax
movl %eax, %ecx
movq -0x78(%rsp), %rax
movl %ecx, 0x80(%rax)
movq -0x40(%rsp), %rax
addq -0x48(%rsp), %rax
imulq $0x1151, %rax, %rax     # imm = 0x1151
movq %rax, -0x50(%rsp)
movq -0x50(%rsp), %rax
imulq $0x187e, -0x48(%rsp), %rcx # imm = 0x187E
addq %rcx, %rax
addq $0x4000, %rax           # imm = 0x4000
sarq $0xf, %rax
movl %eax, %ecx
movq -0x78(%rsp), %rax
movl %ecx, 0x40(%rax)
movq -0x50(%rsp), %rax
imulq $-0x3b21, -0x40(%rsp), %rcx # imm = 0xC4DF
addq %rcx, %rax
addq $0x4000, %rax           # imm = 0x4000
sarq $0xf, %rax
movl %eax, %ecx
movq -0x78(%rsp), %rax
movl %ecx, 0xc0(%rax)
movq -0x10(%rsp), %rax
addq -0x28(%rsp), %rax
movq %rax, -0x50(%rsp)
movq -0x18(%rsp), %rax
addq -0x20(%rsp), %rax
movq %rax, -0x58(%rsp)
movq -0x10(%rsp), %rax
addq -0x20(%rsp), %rax
movq %rax, -0x60(%rsp)
movq -0x18(%rsp), %rax
addq -0x28(%rsp), %rax
movq %rax, -0x68(%rsp)
movq -0x60(%rsp), %rax
addq -0x68(%rsp), %rax
imulq $0x25a1, %rax, %rax     # imm = 0x25A1
movq %rax, -0x70(%rsp)
imulq $0x98e, -0x10(%rsp), %rax # imm = 0x98E
movq %rax, -0x10(%rsp)
imulq $0x41b3, -0x18(%rsp), %rax # imm = 0x41B3
movq %rax, -0x18(%rsp)
imulq $0x6254, -0x20(%rsp), %rax # imm = 0x6254
movq %rax, -0x20(%rsp)
imulq $0x300b, -0x28(%rsp), %rax # imm = 0x300B
movq %rax, -0x28(%rsp)
imulq $-0x1ccd, -0x50(%rsp), %rax # imm = 0xE333
movq %rax, -0x50(%rsp)
imulq $-0x5203, -0x58(%rsp), %rax # imm = 0xADFD
movq %rax, -0x58(%rsp)
imulq $-0x3ec5, -0x60(%rsp), %rax # imm = 0xC13B
movq %rax, -0x60(%rsp)
imulq $-0xc7c, -0x68(%rsp), %rax # imm = 0xF384
movq %rax, -0x68(%rsp)
movq -0x70(%rsp), %rax
addq -0x60(%rsp), %rax
movq %rax, -0x60(%rsp)
movq -0x70(%rsp), %rax
addq -0x68(%rsp), %rax
movq %rax, -0x68(%rsp)
movq -0x10(%rsp), %rax
addq -0x50(%rsp), %rax
addq -0x60(%rsp), %rax
addq $0x4000, %rax           # imm = 0x4000
sarq $0xf, %rax
movl %eax, %ecx
movq -0x78(%rsp), %rax
movl %ecx, 0xe0(%rax)
movq -0x18(%rsp), %rax
addq -0x58(%rsp), %rax
addq -0x68(%rsp), %rax
addq $0x4000, %rax           # imm = 0x4000
sarq $0xf, %rax
movl %eax, %ecx
movq -0x78(%rsp), %rax
movl %ecx, 0xa0(%rax)
movq -0x20(%rsp), %rax
addq -0x58(%rsp), %rax
addq -0x60(%rsp), %rax
addq $0x4000, %rax           # imm = 0x4000
sarq $0xf, %rax
movl %eax, %ecx
movq -0x78(%rsp), %rax
movl %ecx, 0x60(%rax)
movq -0x28(%rsp), %rax
addq -0x50(%rsp), %rax
addq -0x68(%rsp), %rax
addq $0x4000, %rax           # imm = 0x4000
sarq $0xf, %rax
movl %eax, %ecx
movq -0x78(%rsp), %rax
movl %ecx, 0x20(%rax)
movq -0x78(%rsp), %rax
addq $0x4, %rax
movq %rax, -0x78(%rsp)
movl -0x7c(%rsp), %eax
addl $-0x1, %eax
movl %eax, -0x7c(%rsp)
jmp 0xe2000
addq $0x20, %rsp
retq
nopw %cs:(%rax,%rax)
nop