// File: tomfunkhouser[P]gaps/pkgs/jpeg/jdmerge.c
// Function: build_ycc_rgb_table
LOCAL(void)
build_ycc_rgb_table (j_decompress_ptr cinfo)
{
  my_upsample_ptr upsample = (my_upsample_ptr) cinfo->upsample;
  int i;
  INT32 x;
  SHIFT_TEMPS

  upsample->Cr_r_tab = (int *)
    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
				(MAXJSAMPLE+1) * SIZEOF(int));
  upsample->Cb_b_tab = (int *)
    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
				(MAXJSAMPLE+1) * SIZEOF(int));
  upsample->Cr_g_tab = (INT32 *)
    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
				(MAXJSAMPLE+1) * SIZEOF(INT32));
  upsample->Cb_g_tab = (INT32 *)
    (*cinfo->mem->alloc_small) ((j_common_ptr) cinfo, JPOOL_IMAGE,
				(MAXJSAMPLE+1) * SIZEOF(INT32));

  for (i = 0, x = -CENTERJSAMPLE; i <= MAXJSAMPLE; i++, x++) {
    /* i is the actual input pixel value, in the range 0..MAXJSAMPLE */
    /* The Cb or Cr value we are thinking of is x = i - CENTERJSAMPLE */
    /* Cr=>R value is nearest int to 1.40200 * x */
    upsample->Cr_r_tab[i] = (int)
		    RIGHT_SHIFT(FIX(1.40200) * x + ONE_HALF, SCALEBITS);
    /* Cb=>B value is nearest int to 1.77200 * x */
    upsample->Cb_b_tab[i] = (int)
		    RIGHT_SHIFT(FIX(1.77200) * x + ONE_HALF, SCALEBITS);
    /* Cr=>G value is scaled-up -0.71414 * x */
    upsample->Cr_g_tab[i] = (- FIX(0.71414)) * x;
    /* Cb=>G value is scaled-up -0.34414 * x */
    /* We also add in ONE_HALF so that need not do it in inner loop */
    upsample->Cb_g_tab[i] = (- FIX(0.34414)) * x + ONE_HALF;
  }
}

// Assembly:
subq $0x28, %rsp
movq %rdi, 0x20(%rsp)
movq 0x20(%rsp), %rax
movq 0x260(%rax), %rax
movq %rax, 0x18(%rsp)
movq 0x20(%rsp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
movq 0x20(%rsp), %rdi
movl $0x1, %esi
movl $0x400, %edx            # imm = 0x400
callq *%rax
movq %rax, %rcx
movq 0x18(%rsp), %rax
movq %rcx, 0x20(%rax)
movq 0x20(%rsp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
movq 0x20(%rsp), %rdi
movl $0x1, %esi
movl $0x400, %edx            # imm = 0x400
callq *%rax
movq %rax, %rcx
movq 0x18(%rsp), %rax
movq %rcx, 0x28(%rax)
movq 0x20(%rsp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
movq 0x20(%rsp), %rdi
movl $0x1, %esi
movl $0x800, %edx            # imm = 0x800
callq *%rax
movq %rax, %rcx
movq 0x18(%rsp), %rax
movq %rcx, 0x30(%rax)
movq 0x20(%rsp), %rax
movq 0x8(%rax), %rax
movq (%rax), %rax
movq 0x20(%rsp), %rdi
movl $0x1, %esi
movl $0x800, %edx            # imm = 0x800
callq *%rax
movq %rax, %rcx
movq 0x18(%rsp), %rax
movq %rcx, 0x38(%rax)
movl $0x0, 0x14(%rsp)
movq $-0x80, 0x8(%rsp)
cmpl $0xff, 0x14(%rsp)
jg 0xf9194
imulq $0x166e9, 0x8(%rsp), %rax # imm = 0x166E9
addq $0x8000, %rax           # imm = 0x8000
sarq $0x10, %rax
movl %eax, %edx
movq 0x18(%rsp), %rax
movq 0x20(%rax), %rax
movslq 0x14(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
imulq $0x1c5a2, 0x8(%rsp), %rax # imm = 0x1C5A2
addq $0x8000, %rax           # imm = 0x8000
sarq $0x10, %rax
movl %eax, %edx
movq 0x18(%rsp), %rax
movq 0x28(%rax), %rax
movslq 0x14(%rsp), %rcx
movl %edx, (%rax,%rcx,4)
imulq $-0xb6d2, 0x8(%rsp), %rdx # imm = 0xFFFF492E
movq 0x18(%rsp), %rax
movq 0x30(%rax), %rax
movslq 0x14(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
imulq $-0x581a, 0x8(%rsp), %rdx # imm = 0xA7E6
addq $0x8000, %rdx           # imm = 0x8000
movq 0x18(%rsp), %rax
movq 0x38(%rax), %rax
movslq 0x14(%rsp), %rcx
movq %rdx, (%rax,%rcx,8)
movl 0x14(%rsp), %eax
addl $0x1, %eax
movl %eax, 0x14(%rsp)
movq 0x8(%rsp), %rax
addq $0x1, %rax
movq %rax, 0x8(%rsp)
jmp 0xf90df
addq $0x28, %rsp
retq
nopl (%rax)