// File: jstaursky[P]hutch/src/Sleigh/float.cc
// Function: FloatFormat::getHostFloat(unsigned long, FloatFormat::floatclass*) const
double FloatFormat::getHostFloat(uintb encoding,floatclass *type) const

{
  bool sgn = extractSign(encoding);
  uintb frac = extractFractionalCode(encoding);
  int4 exp = extractExponentCode(encoding);
  bool normal = true;

  if (exp == 0) {
    if ( frac == 0 ) {		// Floating point zero
      *type = zero;
      // FIXME:  add on sign-bit  for +0 or -0 allowed by standard
      return sgn ? -0.0 : +0.0;
    }
    *type = denormalized;
    // Number is denormalized
    normal = false;
  }
  else if (exp == maxexponent) {
    if ( frac == 0 ) {		// Floating point infinity
      *type = infinity;
      // FIXME: add on sign-bit for +inf or -inf allowed by standard
      return sgn ? -INFINITY : +INFINITY;
    }
    *type = nan;
    // encoding is "Not a Number" NaN
    return sgn ? -NAN : +NAN; // Sign is usually ignored
  }
  else
    *type = normalized;

  // Get "true" exponent and fractional
  exp -= bias;
  if (normal && jbitimplied) {
    frac >>= 1;			// Make room for 1 jbit
    uintb highbit = 1;
    highbit <<= 8*sizeof(uintb)-1;
    frac |= highbit;		// Stick bit in at top
  }
  return createFloat(sgn,frac,exp);
}

// Assembly:
subq $0x68, %rsp
movq %rdi, 0x58(%rsp)
movq %rsi, 0x50(%rsp)
movq %rdx, 0x48(%rsp)
movq 0x58(%rsp), %rdi
movq %rdi, 0x20(%rsp)
movq 0x50(%rsp), %rsi
callq 0xd6dd0
movq 0x20(%rsp), %rdi
andb $0x1, %al
movb %al, 0x47(%rsp)
movq 0x50(%rsp), %rsi
callq 0xd1a90
movq 0x20(%rsp), %rdi
movq %rax, 0x38(%rsp)
movq 0x50(%rsp), %rsi
callq 0xdad40
movl %eax, 0x34(%rsp)
movb $0x1, 0x33(%rsp)
cmpl $0x0, 0x34(%rsp)
jne 0xe8934
cmpq $0x0, 0x38(%rsp)
jne 0xe891f
movq 0x48(%rsp), %rax
movl $0x2, (%rax)
movb 0x47(%rsp), %al
movsd 0x9e881(%rip), %xmm0    # 0x187170
xorps %xmm1, %xmm1
movsd %xmm1, 0x10(%rsp)
testb $0x1, %al
movsd %xmm0, 0x18(%rsp)
jne 0xe890e
movsd 0x10(%rsp), %xmm0
movsd %xmm0, 0x18(%rsp)
movsd 0x18(%rsp), %xmm0
movsd %xmm0, 0x60(%rsp)
jmp 0xe8a6d
movq 0x48(%rsp), %rax
movl $0x4, (%rax)
movb $0x0, 0x33(%rsp)
jmp 0xe89f9
movq 0x20(%rsp), %rcx
movl 0x34(%rsp), %eax
cmpl 0x1c(%rcx), %eax
jne 0xe89ec
cmpq $0x0, 0x38(%rsp)
jne 0xe899e
movq 0x48(%rsp), %rax
movl $0x1, (%rax)
movb 0x47(%rsp), %al
movss 0x9e823(%rip), %xmm0    # 0x187188
movss 0x9e81f(%rip), %xmm1    # 0x18718c
movss %xmm1, 0x8(%rsp)
testb $0x1, %al
movss %xmm0, 0xc(%rsp)
jne 0xe8989
movss 0x8(%rsp), %xmm0
movss %xmm0, 0xc(%rsp)
movss 0xc(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x60(%rsp)
jmp 0xe8a6d
movq 0x48(%rsp), %rax
movl $0x3, (%rax)
movb 0x47(%rsp), %al
movss 0x9e7cb(%rip), %xmm0    # 0x187180
movss 0x9e7c7(%rip), %xmm1    # 0x187184
movss %xmm1, (%rsp)
testb $0x1, %al
movss %xmm0, 0x4(%rsp)
jne 0xe89d7
movss (%rsp), %xmm0
movss %xmm0, 0x4(%rsp)
movss 0x4(%rsp), %xmm0
cvtss2sd %xmm0, %xmm0
movsd %xmm0, 0x60(%rsp)
jmp 0xe8a6d
movq 0x48(%rsp), %rax
movl $0x0, (%rax)
jmp 0xe89f9
movq 0x20(%rsp), %rax
movl 0x18(%rax), %ecx
movl 0x34(%rsp), %eax
subl %ecx, %eax
movl %eax, 0x34(%rsp)
testb $0x1, 0x33(%rsp)
je 0xe8a50
movq 0x20(%rsp), %rax
testb $0x1, 0x20(%rax)
je 0xe8a50
movq 0x38(%rsp), %rax
shrq %rax
movq %rax, 0x38(%rsp)
movq $0x1, 0x28(%rsp)
movq 0x28(%rsp), %rax
shlq $0x3f, %rax
movq %rax, 0x28(%rsp)
movq 0x28(%rsp), %rax
orq 0x38(%rsp), %rax
movq %rax, 0x38(%rsp)
movb 0x47(%rsp), %al
movq 0x38(%rsp), %rsi
movl 0x34(%rsp), %edx
andb $0x1, %al
movzbl %al, %edi
callq 0xd9d80
movsd %xmm0, 0x60(%rsp)
movsd 0x60(%rsp), %xmm0
addq $0x68, %rsp
retq
nopl (%rax,%rax)