// File: ke6jjj[P]r-dat/DifferentialClockDetector.cc
// Function: DifferentialClockDetector::EvaluateClock()
void
DifferentialClockDetector::EvaluateClock()
{
  int i, maxI, minI;
  float max, min, ratio;

  for (max = min = mWindow[0], i = 1, maxI = 0; i < mWindowSize; i++)
  {
    //
    // Find the highest peak.
    //
    if (mWindow[i] > max) {
      max = mWindow[i];
      maxI = i;
    }
    //
    // And the lowest valley.
    //
    if (mWindow[i] < min)
      min = mWindow[i];
  }
  
  if (maxI != mMaximumDiffPos) {
    //
    // We've found a new maximum differential position.
    // In the future we might calculate clock error here.
    //
    mMaximumDiffPos = maxI;

    //
    // Queue up the next firing position.
    //
    mNextSyncPos = FirePosition(mMaximumDiffPos, mWindowSize);
  }
  
  //
  // If there is a significant difference between the highest
  // peak and the lowest valley then we have a good clock signal.
  //
  if (max > 0.0)
    ratio = min / max;
  else
    ratio = 0.0;

  bool newDetectionState = ratio <= mDetectionThresholdRatio;

  if (newDetectionState != mDetected && mListener != NULL) {
    mListener->ClockDetected(newDetectionState);
  }

  mDetected = newDetectionState;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x30, %rsp
movq %rdi, -0x8(%rbp)
movq -0x8(%rbp), %rax
movq %rax, -0x30(%rbp)
movq 0x10(%rax), %rax
movss (%rax), %xmm0
movss %xmm0, -0x1c(%rbp)
movss %xmm0, -0x18(%rbp)
movl $0x1, -0xc(%rbp)
movl $0x0, -0x10(%rbp)
movq -0x30(%rbp), %rcx
movslq -0xc(%rbp), %rax
cmpq (%rcx), %rax
jae 0xd182
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0xc(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
ucomiss -0x18(%rbp), %xmm0
jbe 0xd144
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0xc(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
movss %xmm0, -0x18(%rbp)
movl -0xc(%rbp), %eax
movl %eax, -0x10(%rbp)
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0xc(%rbp), %rcx
movss (%rax,%rcx,4), %xmm1
movss -0x1c(%rbp), %xmm0
ucomiss %xmm1, %xmm0
jbe 0xd175
movq -0x30(%rbp), %rax
movq 0x10(%rax), %rax
movslq -0xc(%rbp), %rcx
movss (%rax,%rcx,4), %xmm0
movss %xmm0, -0x1c(%rbp)
jmp 0xd177
movl -0xc(%rbp), %eax
addl $0x1, %eax
movl %eax, -0xc(%rbp)
jmp 0xd104
movq -0x30(%rbp), %rcx
movslq -0x10(%rbp), %rax
cmpq 0x20(%rcx), %rax
je 0xd1b3
movq -0x30(%rbp), %rax
movslq -0x10(%rbp), %rcx
movq %rcx, 0x20(%rax)
movq 0x20(%rax), %rdi
movq (%rax), %rsi
callq 0xcf90
movq %rax, %rcx
movq -0x30(%rbp), %rax
movq %rcx, 0x30(%rax)
movss -0x18(%rbp), %xmm0
cvtss2sd %xmm0, %xmm0
xorps %xmm1, %xmm1
ucomisd %xmm1, %xmm0
jbe 0xd1d6
movss -0x1c(%rbp), %xmm0
divss -0x18(%rbp), %xmm0
movss %xmm0, -0x20(%rbp)
jmp 0xd1de
xorps %xmm0, %xmm0
movss %xmm0, -0x20(%rbp)
movq -0x30(%rbp), %rcx
movss -0x20(%rbp), %xmm1
movss 0xc(%rcx), %xmm0
ucomiss %xmm1, %xmm0
setae %al
andb $0x1, %al
movb %al, -0x21(%rbp)
movb -0x21(%rbp), %al
andb $0x1, %al
movzbl %al, %eax
movb 0x1c(%rcx), %cl
andb $0x1, %cl
movzbl %cl, %ecx
cmpl %ecx, %eax
je 0xd22d
movq -0x30(%rbp), %rax
cmpq $0x0, 0x40(%rax)
je 0xd22d
movq -0x30(%rbp), %rax
movq 0x40(%rax), %rdi
movb -0x21(%rbp), %cl
movq (%rdi), %rax
andb $0x1, %cl
movzbl %cl, %esi
callq *(%rax)
movq -0x30(%rbp), %rax
movb -0x21(%rbp), %cl
andb $0x1, %cl
movb %cl, 0x1c(%rax)
addq $0x30, %rsp
popq %rbp
retq