// File: jstaursky[P]hutch/src/Sleigh/slghpatexpress.cc
// Function: TokenPattern::buildLittleBlock(int, int, int, long)
PatternBlock *TokenPattern::buildLittleBlock(int4 size,int4 bitstart,int4 bitend,intb value)

{				// Build pattern block given a littleendian contiguous
				// range of bits and a value for those bits
  PatternBlock *tmpblock,*block;
  int4 startbit,endbit;

  block = (PatternBlock *)0;

  // we need to convert a bit range specified on a little endian token where the
  // bit indices label the least sig bit as 0 into a bit range on big endian bytes
  // where the indices label the most sig bit as 0.  The reversal due to
  // little->big endian cancels part of the reversal due to least->most sig bit
  // labelling, but not on the lower 3 bits.  So the transform becomes
  // leave the upper bits the same, but transform the lower 3-bit value x into 7-x.

  startbit = (bitstart/8) * 8;	// Get the high-order portion of little/LSB labelling
  endbit = (bitend/8) * 8;
  bitend = bitend % 8;		// Get the low-order portion of little/LSB labelling
  bitstart = bitstart % 8;

  if (startbit == endbit) {
    startbit += 7 - bitend;
    endbit += 7 - bitstart;
    block = buildSingle(startbit,endbit,(uintm)value);
  }
  else {
    block = buildSingle(startbit,startbit+(7-bitstart),(uintm)value);
    value >>= (8-bitstart);	// Cut off bits we just encoded
    startbit += 8;
    while(startbit != endbit) {
      tmpblock = buildSingle(startbit,startbit+7,(uintm)value);
      if (block == (PatternBlock *)0)
	block = tmpblock;
      else {
	PatternBlock *newblock = block->intersect(tmpblock);
	delete block;
	delete tmpblock;
	block = newblock;
      }
      value >>= 8;
      startbit += 8;
    }
    tmpblock = buildSingle(endbit+(7-bitend),endbit+7,(uintm)value);
    if (block == (PatternBlock *)0)
      block = tmpblock;
    else {
      PatternBlock *newblock = block->intersect(tmpblock);
      delete block;
      delete tmpblock;
      block = newblock;
    }
  }
  return block;
}

// Assembly:
subq $0x68, %rsp
movl %edi, 0x64(%rsp)
movl %esi, 0x60(%rsp)
movl %edx, 0x5c(%rsp)
movq %rcx, 0x50(%rsp)
movq $0x0, 0x40(%rsp)
movl 0x60(%rsp), %eax
movl $0x8, %ecx
cltd
idivl %ecx
shll $0x3, %eax
movl %eax, 0x3c(%rsp)
movl 0x5c(%rsp), %eax
movl $0x8, %ecx
cltd
idivl %ecx
shll $0x3, %eax
movl %eax, 0x38(%rsp)
movl 0x5c(%rsp), %eax
movl $0x8, %ecx
cltd
idivl %ecx
movl %edx, 0x5c(%rsp)
movl 0x60(%rsp), %eax
movl $0x8, %ecx
cltd
idivl %ecx
movl %edx, 0x60(%rsp)
movl 0x3c(%rsp), %eax
cmpl 0x38(%rsp), %eax
jne 0x126d9e
movl $0x7, %eax
subl 0x5c(%rsp), %eax
addl 0x3c(%rsp), %eax
movl %eax, 0x3c(%rsp)
movl $0x7, %eax
subl 0x60(%rsp), %eax
addl 0x38(%rsp), %eax
movl %eax, 0x38(%rsp)
movl 0x3c(%rsp), %edi
movl 0x38(%rsp), %esi
movq 0x50(%rsp), %rax
movl %eax, %edx
callq 0xe1db0
movq %rax, 0x40(%rsp)
jmp 0x126f5e
movl 0x3c(%rsp), %edi
movl 0x3c(%rsp), %esi
movl $0x7, %eax
subl 0x60(%rsp), %eax
addl %eax, %esi
movq 0x50(%rsp), %rax
movl %eax, %edx
callq 0xe1db0
movq %rax, 0x40(%rsp)
movl $0x8, %ecx
subl 0x60(%rsp), %ecx
movq 0x50(%rsp), %rax
movl %ecx, %ecx
sarq %cl, %rax
movq %rax, 0x50(%rsp)
movl 0x3c(%rsp), %eax
addl $0x8, %eax
movl %eax, 0x3c(%rsp)
movl 0x3c(%rsp), %eax
cmpl 0x38(%rsp), %eax
je 0x126eb1
movl 0x3c(%rsp), %edi
movl 0x3c(%rsp), %esi
addl $0x7, %esi
movq 0x50(%rsp), %rax
movl %eax, %edx
callq 0xe1db0
movq %rax, 0x48(%rsp)
cmpq $0x0, 0x40(%rsp)
jne 0x126e23
movq 0x48(%rsp), %rax
movq %rax, 0x40(%rsp)
jmp 0x126e93
movq 0x40(%rsp), %rdi
movq 0x48(%rsp), %rsi
callq 0xdb440
movq %rax, 0x30(%rsp)
movq 0x40(%rsp), %rax
movq %rax, 0x20(%rsp)
cmpq $0x0, %rax
je 0x126e60
movq 0x20(%rsp), %rdi
callq 0xd2d60
movq 0x20(%rsp), %rdi
movl $0x38, %esi
callq 0xd8620
movq 0x48(%rsp), %rax
movq %rax, 0x18(%rsp)
cmpq $0x0, %rax
je 0x126e89
movq 0x18(%rsp), %rdi
callq 0xd2d60
movq 0x18(%rsp), %rdi
movl $0x38, %esi
callq 0xd8620
movq 0x30(%rsp), %rax
movq %rax, 0x40(%rsp)
movq 0x50(%rsp), %rax
sarq $0x8, %rax
movq %rax, 0x50(%rsp)
movl 0x3c(%rsp), %eax
addl $0x8, %eax
movl %eax, 0x3c(%rsp)
jmp 0x126de5
movl 0x38(%rsp), %edi
movl $0x7, %eax
subl 0x5c(%rsp), %eax
addl %eax, %edi
movl 0x38(%rsp), %esi
addl $0x7, %esi
movq 0x50(%rsp), %rax
movl %eax, %edx
callq 0xe1db0
movq %rax, 0x48(%rsp)
cmpq $0x0, 0x40(%rsp)
jne 0x126eec
movq 0x48(%rsp), %rax
movq %rax, 0x40(%rsp)
jmp 0x126f5c
movq 0x40(%rsp), %rdi
movq 0x48(%rsp), %rsi
callq 0xdb440
movq %rax, 0x28(%rsp)
movq 0x40(%rsp), %rax
movq %rax, 0x10(%rsp)
cmpq $0x0, %rax
je 0x126f29
movq 0x10(%rsp), %rdi
callq 0xd2d60
movq 0x10(%rsp), %rdi
movl $0x38, %esi
callq 0xd8620
movq 0x48(%rsp), %rax
movq %rax, 0x8(%rsp)
cmpq $0x0, %rax
je 0x126f52
movq 0x8(%rsp), %rdi
callq 0xd2d60
movq 0x8(%rsp), %rdi
movl $0x38, %esi
callq 0xd8620
movq 0x28(%rsp), %rax
movq %rax, 0x40(%rsp)
jmp 0x126f5e
movq 0x40(%rsp), %rax
addq $0x68, %rsp
retq
nopl (%rax,%rax)