// File: sundale[P]gcode/rs274ngc/interp_cycles.cc
// Function: Interp::convert_cycle_g83(block_struct*, int, double, double, double, double, double, double)
int Interp::convert_cycle_g83(block_pointer block,
                              CANON_PLANE plane, //!< selected plane                  
                              double x,  //!< x-value where cycle is executed 
                              double y,  //!< y-value where cycle is executed 
                              double r,  //!< initial z-value                 
                              double clear_z,    //!< z-value of clearance plane      
                              double bottom_z,   //!< value of z at bottom of cycle   
                              double delta)      //!< size of z-axis feed increment   
{
  double current_depth;
  double rapid_delta;

  /* Moved the check for negative Q values here as a sign
     may be used with user defined M functions
     Thanks to Billy Singleton for pointing it out... */
  CHKS((delta <= 0.0), NCE_NEGATIVE_OR_ZERO_Q_VALUE_USED);

  rapid_delta = G83_RAPID_DELTA;
  if (_setup.length_units == CANON_UNITS_MM)
    rapid_delta = (rapid_delta * 25.4);

  for (current_depth = (r - delta);
       current_depth > bottom_z; current_depth = (current_depth - delta)) {
    cycle_feed(block, plane, x, y, current_depth);
    cycle_traverse(block, plane, x, y, clear_z);
    cycle_traverse(block, plane, x, y, current_depth + rapid_delta);
  }
  cycle_feed(block, plane, x, y, bottom_z);
  cycle_traverse(block, plane, x, y, clear_z);

  return INTERP_OK;
}

// Assembly:
pushq %rbp
movq %rsp, %rbp
subq $0x70, %rsp
movq %rdi, -0x10(%rbp)
movq %rsi, -0x18(%rbp)
movl %edx, -0x1c(%rbp)
movsd %xmm0, -0x28(%rbp)
movsd %xmm1, -0x30(%rbp)
movsd %xmm2, -0x38(%rbp)
movsd %xmm3, -0x40(%rbp)
movsd %xmm4, -0x48(%rbp)
movsd %xmm5, -0x50(%rbp)
movq -0x10(%rbp), %rax
movq %rax, -0x68(%rbp)
xorps %xmm0, %xmm0
ucomisd -0x50(%rbp), %xmm0
jb 0x379dc
jmp 0x37909
leaq 0x44439(%rip), %rdi     # 0x7bd49
callq 0x10380
movq -0x68(%rbp), %rdi
movq %rax, %rsi
movb $0x0, %al
callq 0x10df0
movq 0x4f636(%rip), %rax     # 0x86f60
movl $0x0, 0xd670(%rax)
movq 0x4f625(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rax
movq 0x4f617(%rip), %rdi     # 0x86f60
addq $0xc6d0, %rdi           # imm = 0xC6D0
imulq $0x50, %rax, %rax
addq %rax, %rdi
leaq 0x44409(%rip), %rsi     # 0x7bd67
movl $0x50, %edx
callq 0x10840
movq 0x4f5f1(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x4f5e3(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, 0x4f(%rax)
movq 0x4f5cb(%rip), %rax     # 0x86f60
movl 0xd670(%rax), %ecx
addl $0x1, %ecx
movq 0x4f5bb(%rip), %rax     # 0x86f60
movl %ecx, 0xd670(%rax)
movq 0x4f5ae(%rip), %rax     # 0x86f60
movslq 0xd670(%rax), %rcx
movq 0x4f5a0(%rip), %rax     # 0x86f60
addq $0xc6d0, %rax           # imm = 0xC6D0
imulq $0x50, %rcx, %rcx
addq %rcx, %rax
movb $0x0, (%rax)
movl $0x5, -0x4(%rbp)
jmp 0x37ae0
jmp 0x379de
movsd 0x43b52(%rip), %xmm0    # 0x7b538
movsd %xmm0, -0x60(%rbp)
movq 0x4f56e(%rip), %rax     # 0x86f60
cmpl $0x2, 0x1690(%rax)
jne 0x37a0d
movsd 0x41445(%rip), %xmm0    # 0x78e48
mulsd -0x60(%rbp), %xmm0
movsd %xmm0, -0x60(%rbp)
movsd -0x38(%rbp), %xmm0
subsd -0x50(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
movsd -0x58(%rbp), %xmm0
ucomisd -0x48(%rbp), %xmm0
jbe 0x37a9b
movq -0x68(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
movsd -0x28(%rbp), %xmm0
movsd -0x30(%rbp), %xmm1
movsd -0x58(%rbp), %xmm2
callq 0x10290
movq -0x68(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
movsd -0x28(%rbp), %xmm0
movsd -0x30(%rbp), %xmm1
movsd -0x40(%rbp), %xmm2
callq 0x11bf0
movq -0x68(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
movsd -0x28(%rbp), %xmm0
movsd -0x30(%rbp), %xmm1
movsd -0x58(%rbp), %xmm2
addsd -0x60(%rbp), %xmm2
callq 0x11bf0
movsd -0x58(%rbp), %xmm0
subsd -0x50(%rbp), %xmm0
movsd %xmm0, -0x58(%rbp)
jmp 0x37a1c
movq -0x68(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
movsd -0x28(%rbp), %xmm0
movsd -0x30(%rbp), %xmm1
movsd -0x48(%rbp), %xmm2
callq 0x10290
movq -0x68(%rbp), %rdi
movq -0x18(%rbp), %rsi
movl -0x1c(%rbp), %edx
movsd -0x28(%rbp), %xmm0
movsd -0x30(%rbp), %xmm1
movsd -0x40(%rbp), %xmm2
callq 0x11bf0
movl $0x0, -0x4(%rbp)
movl -0x4(%rbp), %eax
addq $0x70, %rsp
popq %rbp
retq
nopl (%rax)