Module Ocaml_simd_sse.String
Refer to the Intel Intrinsics Guide (SSE4.2) for detailed specifications.
https://www.intel.com/content/www/us/en/docs/intrinsics-guide/index.html
String comparisons: cmp[e,i]str[m,a,c,i,o,s,z] ~a ~b
Each intrinsic inputs two [int8x16,int16x8] vectors representing strings.
The comparison operation is specified by a ppx_simd directive: [%bytes] for
byte strings, and [%words] for word strings.
---- Lengths
e : the lengths of the strings are given as parameters [a_len] and [b_len].
i : the strings are assumed to be either null-terminated or full-vector-length.
---- Returns
m : return a vector mask indicating which characters passed the condition.
- With [Bit_mask]: set only the bottom [16,8] bits of the mask.
- With [Vec_mask]: set each [byte,word] of the mask to [0xff,0xffff].
a : return 1 if y is full-length and the comparison mask is zero
c : return 1 if the comparison mask is non-zero
i : return the index of the [first,last] character that passed the comparison,
_ based on [Least_sig,Most_sig].
o : return the least significant bit of the comparison mask
s : return 1 if x is not full-length
z : return 1 if y is not full-length
---- Examples
Finding the index of the first byte that differs:
[Byte.cmpistri [%bytes Signed, Eq_each, Masked_neg, Least_sig] ~a ~b]
Creating a mask of bytes that are ASCII decimal digits:
[
let a = Int8x16.const 0x30 0x31 0x32 0x33 0x34 0x35 0x36 0x37 0x38 0x39 0x30 0x30 0x30 0x30 0x30 0x30 in
Byte.cmpistrm [%bytes Signed, Eq_any, Pos, Vec_mask] ~a ~b
]
Checking if any byte is not an ASCII letter:
[
let a = Int8x16.const 0x41 0x5A 0x61 0x7A 0x41 0x5A 0x61 0x7A 0x41 0x5A 0x61 0x7A 0x41 0x5A 0x61 0x7A in
Byte.cmpistrc [%bytes Signed, In_range, Masked_neg] ~a ~b
]
Finding the index of the first byte of the first occurance of a in b:
[Byte.cmpistri [%bytes Signed, Eq_ordered, Pos, Least_sig] ~a ~b]