/* Max offset is achieved with index = 0x7FFF giving an offset of 0x27B (32-bit machine) or 0x477 (64-bit machine). Min offset is achieved with index = */
INT16 VmReadIndex16(IN VM_CONTEXT *VmPtr, IN UINT32 CodeOffset)
/* Max offset is achieved with index = 0x7FFF giving an offset of 0x27B (32-bit machine) or 0x477 (64-bit machine). Min offset is achieved with index = */
INT16 VmReadIndex16(IN VM_CONTEXT *VmPtr, IN UINT32 CodeOffset)
{
  UINT16  Index;
  INT16   Offset;
  INT16   ConstUnits;
  INT16   NaturalUnits;
  INT16   NBits;
  INT16   Mask;
  Index = VmReadCode16 (VmPtr, CodeOffset);
  NBits = (INT16)((Index & 0x7000) >> 12);
  NBits *= 2;
  Mask = (INT16)((INT16) ~0 << NBits);
  NaturalUnits = (INT16)(Index &~Mask);
  ConstUnits = (INT16)(((Index &~0xF000) & Mask) >> NBits);
  Offset = (INT16)(NaturalUnits * sizeof (UINTN) + ConstUnits);
  if ((Index & 0x8000) != 0) {
    Offset = (INT16)((INT32)Offset * -1);
  }
  return Offset;
}