// File: /workspace/github_c_makefile_star2_O2/zpole[P]IICV/vl/homkermap.c
// Function: vl_homogeneouskernelmap_new
VlHomogeneousKernelMap *
vl_homogeneouskernelmap_new (VlHomogeneousKernelType kernelType,
                             double gamma,
                             vl_size order,
                             double period,
                             VlHomogeneousKernelMapWindowType windowType)
{
  int tableWidth, tableHeight ;
  VlHomogeneousKernelMap * self = vl_malloc(sizeof(VlHomogeneousKernelMap)) ;
  if (! self) return NULL ;

  assert(gamma > 0) ;

  assert(kernelType == VlHomogeneousKernelIntersection ||
         kernelType == VlHomogeneousKernelChi2 ||
         kernelType == VlHomogeneousKernelJS) ;

  assert(windowType == VlHomogeneousKernelMapWindowUniform ||
         windowType == VlHomogeneousKernelMapWindowRectangular) ;

  if (period < 0) {
    switch (windowType) {
    case VlHomogeneousKernelMapWindowUniform:
      switch (kernelType) {
      case VlHomogeneousKernelChi2:         period = 5.86 * sqrt(order + 0)  + 3.65 ; break ;
      case VlHomogeneousKernelJS:           period = 6.64 * sqrt(order + 0)  + 7.24 ; break ;
      case VlHomogeneousKernelIntersection: period = 2.38 * log(order + 0.8) + 5.6 ; break ;
      }
      break ;
    case VlHomogeneousKernelMapWindowRectangular:
      switch (kernelType) {
      case VlHomogeneousKernelChi2:         period = 8.80 * sqrt(order + 4.44) - 12.6 ; break ;
      case VlHomogeneousKernelJS:           period = 9.63 * sqrt(order + 1.00) - 2.93;  break ;
      case VlHomogeneousKernelIntersection: period = 2.00 * log(order + 0.99)  + 3.52 ; break ;
      }
      break ;
    }
    period = VL_MAX(period, 1.0) ;
  }

  self->kernelType = kernelType ;
  self->windowType = windowType ;
  self->gamma = gamma ;
  self->order = order ;
  self->period = period ;
  self->numSubdivisions = 8 + 8*order ;
  self->subdivision = 1.0 / self->numSubdivisions ;
  self->minExponent = -20 ;
  self->maxExponent = 8 ;

  tableHeight = (int) (2*self->order + 1) ;
  tableWidth = (int) (self->numSubdivisions * (self->maxExponent - self->minExponent + 1)) ;
  self->table = vl_malloc (sizeof(double) *
                           (tableHeight * tableWidth + 2*(1+self->order))) ;
  if (! self->table) {
    vl_free(self) ;
    return NULL ;
  }

  {
    vl_index exponent ;
    vl_uindex i, j ;
    double * tablep = self->table ;
    double * kappa = self->table + tableHeight * tableWidth ;
    double * freq = kappa + (1+self->order) ;
    double L = 2.0 * VL_PI / self->period ;

    /* precompute the sampled periodicized spectrum */
    j = 0 ;
    i = 0 ;
    while (i <= self->order) {
      freq[i] = j ;
      kappa[i] = vl_homogeneouskernelmap_get_smooth_spectrum(self, j * L) ;
      ++ j ;
      if (kappa[i] > 0 || j >= 3*i) ++ i ;
    }

    /* fill table */
    for (exponent  = self->minExponent ;
         exponent <= self->maxExponent ; ++ exponent) {

      double x, Lxgamma, Llogx, xgamma ;
      double sqrt2kappaLxgamma ;
      double mantissa = 1.0 ;

      for (i = 0 ; i < self->numSubdivisions ;
           ++i, mantissa += self->subdivision) {
        x = ldexp(mantissa, (int)exponent) ;
        xgamma = pow(x, self->gamma) ;
        Lxgamma = L * xgamma ;
        Llogx = L * log(x) ;

        *tablep++ = sqrt(Lxgamma * kappa[0]) ;
        for (j = 1 ; j <= self->order ; ++j) {
          sqrt2kappaLxgamma = sqrt(2.0 * Lxgamma * kappa[j]) ;
          *tablep++ = sqrt2kappaLxgamma * cos(freq[j] * Llogx) ;
          *tablep++ = sqrt2kappaLxgamma * sin(freq[j] * Llogx) ;
        }
      } /* next mantissa */
    } /* next exponent */
  }
  return self ;
}

// Assembly:
pushq %rbp
pushq %r15
pushq %r14
pushq %r13
pushq %r12
pushq %rbx
subq $0x68, %rsp
movl %edx, %ebp
movsd %xmm1, 0x8(%rsp)
movq %rsi, %r14
movsd %xmm0, 0x10(%rsp)
movl %edi, %r15d
pushq $0x50
popq %rdi
callq 0x95e0
testq %rax, %rax
je 0x156f5
movq %rax, %rbx
xorpd %xmm0, %xmm0
movsd 0x8(%rsp), %xmm1
ucomisd %xmm1, %xmm0
jbe 0x15337
cmpl $0x1, %ebp
je 0x151d2
testl %ebp, %ebp
jne 0x1532f
testl %r15d, %r15d
je 0x152ad
cmpl $0x2, %r15d
je 0x15231
cmpl $0x1, %r15d
jne 0x1532f
movq %r14, %xmm0
punpckldq 0x17fbb(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x17fc3(%rip), %xmm0    # 0x2d170
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
sqrtsd %xmm1, %xmm1
mulsd 0x18863(%rip), %xmm1    # 0x2da28
addsd 0x18863(%rip), %xmm1    # 0x2da30
jmp 0x1532f
testl %r15d, %r15d
je 0x152f1
cmpl $0x2, %r15d
je 0x1526b
cmpl $0x1, %r15d
jne 0x1532f
movq %r14, %xmm0
punpckldq 0x17f64(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x17f6c(%rip), %xmm0    # 0x2d170
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
addsd 0x187d8(%rip), %xmm1    # 0x2d9f0
sqrtsd %xmm1, %xmm1
mulsd 0x187d4(%rip), %xmm1    # 0x2d9f8
addsd 0x187d4(%rip), %xmm1    # 0x2da00
jmp 0x1532f
movq %r14, %xmm0
punpckldq 0x17f22(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x17f2a(%rip), %xmm0    # 0x2d170
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
sqrtsd %xmm1, %xmm1
mulsd 0x187ba(%rip), %xmm1    # 0x2da18
addsd 0x187ba(%rip), %xmm1    # 0x2da20
jmp 0x1532f
movq %r14, %xmm0
punpckldq 0x17ee8(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x17ef0(%rip), %xmm0    # 0x2d170
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
addsd 0x17fa4(%rip), %xmm1    # 0x2d238
sqrtsd %xmm1, %xmm1
mulsd 0x18740(%rip), %xmm1    # 0x2d9e0
addsd 0x18740(%rip), %xmm1    # 0x2d9e8
jmp 0x1532f
movq %r14, %xmm1
punpckldq 0x17ea6(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x17eae(%rip), %xmm1    # 0x2d170
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
addsd 0x17f5a(%rip), %xmm0    # 0x2d230
callq 0x9450
movapd %xmm0, %xmm1
mulsd 0x18721(%rip), %xmm1    # 0x2da08
addsd 0x18721(%rip), %xmm1    # 0x2da10
jmp 0x1532f
movq %r14, %xmm1
punpckldq 0x17e62(%rip), %xmm1 # xmm1 = xmm1[0],mem[0],xmm1[1],mem[1]
subpd 0x17e6a(%rip), %xmm1    # 0x2d170
movapd %xmm1, %xmm0
unpckhpd %xmm1, %xmm0            # xmm0 = xmm0[1],xmm1[1]
addsd %xmm1, %xmm0
addsd 0x186b6(%rip), %xmm0    # 0x2d9d0
callq 0x9450
movapd %xmm0, %xmm1
addsd %xmm0, %xmm1
addsd 0x186a9(%rip), %xmm1    # 0x2d9d8
maxsd 0x17f01(%rip), %xmm1    # 0x2d238
movl %r15d, (%rbx)
movl %ebp, 0x10(%rbx)
movsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x8(%rbx)
movq %r14, 0x18(%rbx)
movsd %xmm1, 0x20(%rbx)
leaq 0x8(,%r14,8), %rax
movq %rax, %xmm0
punpckldq 0x17dfa(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x17e02(%rip), %xmm0    # 0x2d170
movq %rax, 0x28(%rbx)
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movsd 0x17eb2(%rip), %xmm0    # 0x2d238
divsd %xmm1, %xmm0
movsd %xmm0, 0x30(%rbx)
movq $-0x14, 0x38(%rbx)
movq $0x8, 0x40(%rbx)
leal 0x1(,%r14,2), %ecx
imull %ecx, %eax
imull $0x1d, %eax, %eax
movslq %eax, %r12
leaq (%r12,%r14,2), %rax
leaq 0x10(,%rax,8), %rdi
callq 0x95e0
movq %rax, 0x48(%rbx)
testq %rax, %rax
je 0x156ed
movq %rax, %r14
leaq (%rax,%r12,8), %rax
movq 0x18(%rbx), %r13
movsd 0x17f9f(%rip), %xmm0    # 0x2d380
divsd 0x20(%rbx), %xmm0
movsd %xmm0, 0x20(%rsp)
movq %rax, 0x28(%rsp)
leaq (%rax,%r13,8), %rax
addq $0x8, %rax
movq %rax, 0x60(%rsp)
xorl %ebp, %ebp
xorpd %xmm2, %xmm2
movq %r13, %rax
xorl %r15d, %r15d
cmpq %rax, %r15
ja 0x15599
movq %rbp, %xmm0
punpckldq 0x17d40(%rip), %xmm0 # xmm0 = xmm0[0],mem[0],xmm0[1],mem[1]
subpd 0x17d48(%rip), %xmm0    # 0x2d170
movapd %xmm0, %xmm1
unpckhpd %xmm0, %xmm1            # xmm1 = xmm1[1],xmm0[1]
addsd %xmm0, %xmm1
movq 0x60(%rsp), %rax
movsd %xmm1, (%rax,%r15,8)
mulsd 0x20(%rsp), %xmm1
movapd %xmm1, 0x30(%rsp)
movsd 0x20(%rbx), %xmm0
mulsd 0x18060(%rip), %xmm0    # 0x2d4b8
movsd 0x185d8(%rip), %xmm1    # 0x2da38
divsd %xmm0, %xmm1
movapd %xmm1, %xmm0
addsd %xmm1, %xmm0
divsd 0x185cc(%rip), %xmm0    # 0x2da40
movl 0x10(%rbx), %eax
cmpl $0x1, %eax
je 0x1549b
testl %eax, %eax
jne 0x15709
movq %rbx, %rdi
movapd 0x30(%rsp), %xmm0
callq 0x159b2
xorpd %xmm2, %xmm2
jmp 0x15569
movapd %xmm1, %xmm3
xorpd 0x17bf9(%rip), %xmm3    # 0x2d0a0
xorpd %xmm4, %xmm4
movapd %xmm0, 0x50(%rsp)
movapd %xmm1, 0x40(%rsp)
ucomisd %xmm3, %xmm1
jb 0x15561
movsd %xmm4, 0x8(%rsp)
movsd 0x20(%rbx), %xmm1
movapd %xmm1, %xmm4
mulsd 0x17ce8(%rip), %xmm4    # 0x2d1c0
mulsd %xmm3, %xmm4
ucomisd %xmm2, %xmm4
movsd 0x17d50(%rip), %xmm0    # 0x2d238
movapd %xmm3, 0x10(%rsp)
jne 0x154f2
jnp 0x15510
movapd %xmm4, %xmm0
movsd %xmm4, (%rsp)
callq 0x98d0
movapd 0x10(%rsp), %xmm3
divsd (%rsp), %xmm0
movsd 0x20(%rbx), %xmm1
divsd 0x17e68(%rip), %xmm1    # 0x2d380
mulsd %xmm0, %xmm1
movsd %xmm1, (%rsp)
movapd 0x30(%rsp), %xmm0
addsd %xmm3, %xmm0
movq %rbx, %rdi
callq 0x159b2
movapd 0x10(%rsp), %xmm3
mulsd (%rsp), %xmm0
movsd 0x8(%rsp), %xmm4
addsd %xmm0, %xmm4
movapd 0x50(%rsp), %xmm0
addsd %xmm0, %xmm3
xorpd %xmm2, %xmm2
movapd 0x40(%rsp), %xmm1
jmp 0x154b7
mulsd %xmm4, %xmm0
maxsd %xmm2, %xmm0
incq %rbp
ucomisd %xmm2, %xmm0
seta %al
movq 0x28(%rsp), %rcx
movsd %xmm0, (%rcx,%r15,8)
leaq (%r15,%r15,2), %rcx
cmpq %rcx, %rbp
setae %cl
orb %al, %cl
movzbl %cl, %eax
addq %rax, %r15
movq 0x18(%rbx), %rax
jmp 0x1540a
movq 0x38(%rbx), %rdi
leaq (%r14,%r12,8), %rax
addq $0x10, %rax
movq %rax, 0x40(%rsp)
cmpq 0x40(%rbx), %rdi
jg 0x156f7
xorl %r12d, %r12d
movsd 0x17c79(%rip), %xmm0    # 0x2d238
movq %rdi, 0x50(%rsp)
cmpq 0x28(%rbx), %r12
jae 0x156e5
movsd %xmm0, 0x30(%rsp)
callq 0x90c0
movsd %xmm0, 0x10(%rsp)
movsd 0x8(%rbx), %xmm1
callq 0x9280
mulsd 0x20(%rsp), %xmm0
movsd %xmm0, (%rsp)
movsd 0x10(%rsp), %xmm0
callq 0x9450
movsd %xmm0, 0x8(%rsp)
movq 0x28(%rsp), %rax
movsd (%rax), %xmm0
mulsd (%rsp), %xmm0
ucomisd 0x179e5(%rip), %xmm0    # 0x2d000
jb 0x15623
sqrtsd %xmm0, %xmm0
jmp 0x15628
callq 0x9a00
movsd 0x8(%rsp), %xmm1
mulsd 0x20(%rsp), %xmm1
movsd %xmm1, 0x8(%rsp)
movsd %xmm0, (%r14)
addq $0x8, %r14
movsd (%rsp), %xmm0
addsd %xmm0, %xmm0
movsd %xmm0, (%rsp)
movq 0x40(%rsp), %rbp
pushq $0x1
popq %r15
cmpq 0x18(%rbx), %r15
ja 0x156cd
movsd -0x8(%rbp), %xmm0
mulsd (%rsp), %xmm0
ucomisd 0x1798e(%rip), %xmm0    # 0x2d000
jb 0x1567a
sqrtsd %xmm0, %xmm0
jmp 0x1567f
callq 0x9a00
movsd %xmm0, 0x10(%rsp)
movsd (%rbp,%r13,8), %xmm0
mulsd 0x8(%rsp), %xmm0
callq 0x9470
mulsd 0x10(%rsp), %xmm0
movsd %xmm0, (%r14)
movsd (%rbp,%r13,8), %xmm0
mulsd 0x8(%rsp), %xmm0
callq 0x98d0
mulsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x8(%r14)
addq $0x10, %r14
incq %r15
addq $0x8, %rbp
jmp 0x1565a
incq %r12
movsd 0x30(%rsp), %xmm0
addsd 0x30(%rbx), %xmm0
movq 0x50(%rsp), %rdi
jmp 0x155c4
incq %rdi
jmp 0x155aa
movq %rbx, %rdi
callq 0x95b0
xorl %ebx, %ebx
movq %rbx, %rax
addq $0x68, %rsp
popq %rbx
popq %r12
popq %r13
popq %r14
popq %r15
popq %rbp
retq
callq 0x90b0