Function miri::shims::x86::sse42::compare_strings

source ·
fn compare_strings<'tcx>(
    this: &mut MiriInterpCx<'tcx>,
    str1: &OpTy<'tcx>,
    str2: &OpTy<'tcx>,
    len: Option<(u64, u64)>,
    imm: u8,
) -> InterpResult<'tcx, i32>
Expand description

The main worker for the string comparison intrinsics, where the given strings are analyzed according to the given immediate byte.

§Arguments

  • str1 - The first string argument. It is always a length 16 array of bytes or a length 8 array of two-byte words.

  • str2 - The second string argument. It is always a length 16 array of bytes or a length 8 array of two-byte words.

  • len is the length values of the supplied strings. It is distinct from the operand length in that it describes how much of str1 and str2 will be used for the calculation and may be smaller than the array length of str1 and str2. The string length is counted in bytes if using byte operands and in two-byte words when using two-byte word operands. If the value is None, the length of a string is determined by the first null value inside the string.

  • imm is the immediate byte argument supplied to the intrinsic. The byte influences the operation as follows:

    0babccddef
      || | |||- Use of bytes vs use of two-byte words inside the operation.
      || | ||
      || | ||- Use of signed values versus use of unsigned values.
      || | |
      || | |- The comparison operation performed. A total of four operations are available.
      || |    * Equal any: Checks which characters of `str2` are inside `str1`.
      || |    * String ranges: Check if characters in `str2` are inside the provided character ranges.
      || |      Adjacent characters in `str1` constitute one range.
      || |    * String comparison: Mark positions where `str1` and `str2` have the same character.
      || |    * Substring search: Mark positions where `str1` is a substring in `str2`.
      || |
      || |- Result Polarity. The result bits may be subjected to a bitwise complement
      ||    if these bits are set.
      ||
      ||- Output selection. This bit has two meanings depending on the instruction.
      |   If the instruction is generating a mask, it distinguishes between a bit mask
      |   and a byte mask. Otherwise it distinguishes between the most significand bit
      |   and the least significand bit when generating an index.
      |
      |- This bit is ignored. It is expected that this bit is set to zero, but it is
         not a requirement.
    

§Returns

A result mask. The bit at index i inside the mask is set if ‘str2’ starting at i fulfills the test as defined inside the immediate byte. The mask may be negated if negation flags inside the immediate byte are set.

For more information, see the Intel Software Developer’s Manual, Vol. 2b, Chapter 4.1.