1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
#![cfg(target_feature = "sse4.2")]

use super::*;

/// Lanewise `a > b` with lanes as `i64`.
///
/// All bits 1 for true (`-1`), all bit 0 for false (`0`).
/// ```
/// # use safe_arch::*;
/// let a = m128i::from([1_i64, 3]);
/// let b = m128i::from([0_i64, 3]);
/// let c: [i64; 2] = cmp_gt_mask_i64_m128i(a, b).into();
/// assert_eq!(c, [-1_i64, 0]);
/// ```
#[must_use]
#[inline(always)]
#[cfg_attr(docs_rs, doc(cfg(target_feature = "sse4.2")))]
pub fn cmp_gt_mask_i64_m128i(a: m128i, b: m128i) -> m128i {
  m128i(unsafe { _mm_cmpgt_epi64(a.0, b.0) })
}

/// Accumulates the `u8` into a running CRC32 value.
/// ```
/// # use safe_arch::*;
/// assert_eq!(crc32_u8(u32::MAX, u8::MAX), 16777215_u32);
/// ```
#[must_use]
#[inline(always)]
#[cfg_attr(docs_rs, doc(cfg(target_feature = "sse4.2")))]
pub fn crc32_u8(crc: u32, v: u8) -> u32 {
  unsafe { _mm_crc32_u8(crc, v) }
}

/// Accumulates the `u16` into a running CRC32 value.
/// ```
/// # use safe_arch::*;
/// assert_eq!(crc32_u16(u32::MAX, u16::MAX), 65535_u32);
/// ```
#[must_use]
#[inline(always)]
#[cfg_attr(docs_rs, doc(cfg(target_feature = "sse4.2")))]
pub fn crc32_u16(crc: u32, v: u16) -> u32 {
  unsafe { _mm_crc32_u16(crc, v) }
}

/// Accumulates the `u32` into a running CRC32 value.
/// ```
/// # use safe_arch::*;
/// assert_eq!(crc32_u32(u32::MAX, u32::MAX), 0_u32);
/// ```
#[must_use]
#[inline(always)]
#[cfg_attr(docs_rs, doc(cfg(target_feature = "sse4.2")))]
pub fn crc32_u32(crc: u32, v: u32) -> u32 {
  unsafe { _mm_crc32_u32(crc, v) }
}

/// Accumulates the `u64` into a running CRC32 value.
///
/// Note that, unlike with the other `crc32` functions, the running CRC32 input
/// and output is a `u64` value _in addition_ to the new value to accumulate
/// being a `u64`.
///
/// ```
/// # use safe_arch::*;
/// assert_eq!(crc32_u64(u64::MAX, u64::MAX), 3080238136_u64);
/// ```
#[must_use]
#[inline(always)]
#[cfg(target_arch = "x86_64")]
#[cfg_attr(docs_rs, doc(cfg(target_feature = "sse4.2")))]
pub fn crc32_u64(crc: u64, v: u64) -> u64 {
  unsafe { _mm_crc32_u64(crc, v) }
}

/// Looks for `$needle` in `$haystack` and gives the index of the either the
/// first or last match.
///
/// > This is a fairly flexible operation, and so I apologize in advance.
///
/// * The "needle" is the string you're looking _for_.
/// * The "haystack" is the string you're looking _inside of_.
/// * The lengths of each string can be "explicit" or "implicit".
///   * "explicit" is specified with `[str, len]` pairs.
///   * "implicit" just ends at the first `\0`.
///   * Either way a string doesn't go past the end of the register.
/// * You need to pick a "char type", which can be any of `u8`, `i8`, `u16`,
///   `i16`. These operations always operate on `m128i` registers, but the
///   interpretation of the data is configurable.
/// * You need to pick the search operation, which determines how the `needle`
///   is compared to the `haystack`:
///   * `EqAny`: Matches when _any_ haystack character equals _any_ needle
///     character, regardless of position.
///   * `CmpRanges`: Interprets consecutive pairs of characters in the needle as
///     `(low..=high)` ranges to compare each haystack character to.
///   * `CmpEqEach`: Matches when a character position in the needle is equal to
///     the character at the same position in the haystack.
///   * `CmpEqOrdered`: Matches when the complete needle string is a substring
///     somewhere in the haystack.
/// * Finally, you need to specify if you're looking for the `FirstMatch` or
///   `LastMatch`.
///   * If no match is found the output will be the length of the haystack.
///
/// It's a lot to take in. Hopefully the examples below can help clarify how
/// things work. They all use `u8` since Rust string literals are UTF-8, but
/// it's the same with the other character types.
///
/// ## EqAny
/// ```
/// # use safe_arch::*;
/// let hay: m128i = m128i::from(*b"some test words.");
///
/// // explicit needle length
/// let needle: m128i = m128i::from(*b"e_______________");
/// let i: i32 =
///   string_search_for_index!([needle, 1], [hay, 16], u8, EqAny, FirstMatch);
/// assert_eq!(i, 3);
/// let i: i32 =
///   string_search_for_index!([needle, 1], [hay, 16], u8, EqAny, LastMatch);
/// assert_eq!(i, 6);
///
/// // implicit needle length
/// let needle: m128i = m128i::from(*b"e\0______________");
/// let i: i32 = string_search_for_index!(needle, hay, u8, EqAny, FirstMatch);
/// assert_eq!(i, 3);
/// let i: i32 = string_search_for_index!(needle, hay, u8, EqAny, LastMatch);
/// assert_eq!(i, 6);
///
/// // more than one needle character will match any of them, though we
/// // don't get info about _which_ needle character matched.
/// let needle: m128i = m128i::from(*b"et\0_____________");
/// let i: i32 = string_search_for_index!(needle, hay, u8, EqAny, FirstMatch);
/// assert_eq!(i, 3);
/// let i: i32 = string_search_for_index!(needle, hay, u8, EqAny, LastMatch);
/// assert_eq!(i, 8);
/// ```
/// ## CmpRanges
/// ```
/// # use safe_arch::*;
/// let hay: m128i = m128i::from(*b"some test words.");
/// let needle: m128i = m128i::from(*b"vz\0_____________");
/// let i: i32 = string_search_for_index!(needle, hay, u8, CmpRanges, FirstMatch);
/// assert_eq!(i, 10); // matches the 'w'
/// ```
/// ## CmpEqEach
/// ```
/// # use safe_arch::*;
/// let hay: m128i = m128i::from(*b"some test words.");
/// let needle: m128i = m128i::from(*b"_____test_______");
/// let i: i32 = string_search_for_index!(needle, hay, u8, CmpEqEach, FirstMatch);
/// assert_eq!(i, 5); // start of "test"
/// let i: i32 = string_search_for_index!(needle, hay, u8, CmpEqEach, LastMatch);
/// assert_eq!(i, 8); // end of "test"
/// ```
/// ## CmpEqOrdered
/// ```
/// # use safe_arch::*;
/// let hay: m128i = m128i::from(*b"some test words.");
/// let needle: m128i = m128i::from(*b"words\0__________");
/// let i: i32 =
///   string_search_for_index!(needle, hay, u8, CmpEqOrdered, FirstMatch);
/// assert_eq!(i, 10); // This is where the "words" substring begins
/// ```
#[macro_export]
#[cfg_attr(docs_rs, doc(cfg(target_feature = "sse4.2")))]
macro_rules! string_search_for_index {
  ([$needle:expr, $needle_len:expr], [$haystack:expr, $haystack_len:expr], $char_type:tt, $search_op:tt, $index_end:tt) => {{
    $crate::string_search_for_index!(
      @_raw_explicit_len
      $needle,
      $needle_len,
      $haystack,
      $haystack_len,
      $crate::string_search_for_index!(@_char_type $char_type)
      | $crate::string_search_for_index!(@_search_op $search_op)
      | $crate::string_search_for_index!(@_index_end $index_end)
    )
  }};

  ($needle:expr, $haystack:expr, $char_type:tt, $search_op:tt, $index_end:tt) => {{
    $crate::string_search_for_index!(
      @_raw_implicit_len
      $needle,
      $haystack,
      $crate::string_search_for_index!(@_char_type $char_type)
      | $crate::string_search_for_index!(@_search_op $search_op)
      | $crate::string_search_for_index!(@_index_end $index_end)
    )
  }};

  // Character types

  (@_char_type u8) => {{
    #[cfg(target_arch = "x86")]
    use ::core::arch::x86::_SIDD_UBYTE_OPS;
    #[cfg(target_arch = "x86_64")]
    use ::core::arch::x86_64::_SIDD_UBYTE_OPS;
    _SIDD_UBYTE_OPS
  }};
  (@_char_type u16) => {{
    #[cfg(target_arch = "x86")]
    use ::core::arch::x86::_SIDD_UWORD_OPS;
    #[cfg(target_arch = "x86_64")]
    use ::core::arch::x86_64::_SIDD_UWORD_OPS;
    _SIDD_UWORD_OPS
  }};
  (@_char_type i8) => {{
    #[cfg(target_arch = "x86")]
    use ::core::arch::x86::_SIDD_SBYTE_OPS;
    #[cfg(target_arch = "x86_64")]
    use ::core::arch::x86_64::_SIDD_SBYTE_OPS;
    _SIDD_SBYTE_OPS
  }};
  (@_char_type i16) => {{
    #[cfg(target_arch = "x86")]
    use ::core::arch::x86::_SIDD_SWORD_OPS;
    #[cfg(target_arch = "x86_64")]
    use ::core::arch::x86_64::_SIDD_SWORD_OPS;
    _SIDD_SWORD_OPS
  }};
  (@_char_type $unknown:tt) => {
    compile_error!("legal character types are: u8, u16, i8, i16")
  };

  // Search styles

  (@_search_op EqAny) => {{
    #[cfg(target_arch = "x86")]
    use ::core::arch::x86::_SIDD_CMP_EQUAL_ANY;
    #[cfg(target_arch = "x86_64")]
    use ::core::arch::x86_64::_SIDD_CMP_EQUAL_ANY;
    _SIDD_CMP_EQUAL_ANY
  }};
  (@_search_op CmpRanges) => {{
    #[cfg(target_arch = "x86")]
    use ::core::arch::x86::_SIDD_CMP_RANGES;
    #[cfg(target_arch = "x86_64")]
    use ::core::arch::x86_64::_SIDD_CMP_RANGES;
    _SIDD_CMP_RANGES
  }};
  (@_search_op CmpEqEach) => {{
    #[cfg(target_arch = "x86")]
    use ::core::arch::x86::_SIDD_CMP_EQUAL_EACH;
    #[cfg(target_arch = "x86_64")]
    use ::core::arch::x86_64::_SIDD_CMP_EQUAL_EACH;
    _SIDD_CMP_EQUAL_EACH
  }};
  (@_search_op CmpEqOrdered) => {{
    #[cfg(target_arch = "x86")]
    use ::core::arch::x86::_SIDD_CMP_EQUAL_ORDERED;
    #[cfg(target_arch = "x86_64")]
    use ::core::arch::x86_64::_SIDD_CMP_EQUAL_ORDERED;
    _SIDD_CMP_EQUAL_ORDERED
  }};
  (@_search_op $unknown:tt) => {
    compile_error!(
      "legal search operations are: EqAny, CmpRanges, CmpEqEach, CmpEqOrdered"
    )
  };

  // Index end

  (@_index_end FirstMatch) => {{
    #[cfg(target_arch = "x86")]
    use ::core::arch::x86::_SIDD_LEAST_SIGNIFICANT;
    #[cfg(target_arch = "x86_64")]
    use ::core::arch::x86_64::_SIDD_LEAST_SIGNIFICANT;
    _SIDD_LEAST_SIGNIFICANT
  }};
  (@_index_end LastMatch) => {{
    #[cfg(target_arch = "x86")]
    use ::core::arch::x86::_SIDD_MOST_SIGNIFICANT;
    #[cfg(target_arch = "x86_64")]
    use ::core::arch::x86_64::_SIDD_MOST_SIGNIFICANT;
    _SIDD_MOST_SIGNIFICANT
  }};
  (@_index_end $unknown:tt) => {
    compile_error!("legal index args are: FirstMatch, LastMatch")
  };

  // The final, actual, calls to the intrinsic.

  (@_raw_explicit_len $needle:expr, $needle_len:expr, $haystack:expr, $haystack_len:expr, $imm:expr) => {{
    let a: m128i = $needle;
    let la: i32 = $needle_len;
    let b: m128i = $haystack;
    let lb: i32 = $haystack_len;
    const IMM: i32 = $imm as i32;
    #[cfg(target_arch = "x86")]
    use ::core::arch::x86::_mm_cmpestri;
    #[cfg(target_arch = "x86_64")]
    use ::core::arch::x86_64::_mm_cmpestri;
    unsafe { _mm_cmpestri(a.0, la, b.0, lb, IMM) }
  }};

  (@_raw_implicit_len $needle:expr, $haystack:expr, $imm:expr) => {{
    let a: m128i = $needle;
    let b: m128i = $haystack;
    const IMM: i32 = $imm as i32;
    #[cfg(target_arch = "x86")]
    use ::core::arch::x86::_mm_cmpistri;
    #[cfg(target_arch = "x86_64")]
    use ::core::arch::x86_64::_mm_cmpistri;
    unsafe { _mm_cmpistri(a.0, b.0, IMM) }
  }};
}

/// Looks for `$needle` in `$haystack` and gives the mask of where the matches
/// were.
///
/// > This is a fairly flexible operation, and so I apologize in advance.
///
/// * The "needle" is the string you're looking _for_.
/// * The "haystack" is the string you're looking _inside of_.
/// * The lengths of each string can be "explicit" or "implicit".
///   * "explicit" is specified with `[str, len]` pairs.
///   * "implicit" just ends at the first `\0`.
///   * Either way a string doesn't go past the end of the register.
/// * You need to pick a "char type", which can be any of `u8`, `i8`, `u16`,
///   `i16`. These operations always operate on `m128i` registers, but the
///   interpretation of the data is configurable.
/// * You need to pick the search operation, which determines how the `needle`
///   is compared to the `haystack`:
///   * `EqAny`: Matches when _any_ haystack character equals _any_ needle
///     character, regardless of position.
///   * `CmpRanges`: Interprets consecutive pairs of characters in the needle as
///     `(low..=high)` ranges to compare each haystack character to.
///   * `CmpEqEach`: Matches when a character position in the needle is equal to
///     the character at the same position in the haystack.
///   * `CmpEqOrdered`: Matches when the complete needle string is a substring
///     somewhere in the haystack.
/// * Finally, you need to specify if you want to have a `BitMask` or a
///   `UnitMask`.
///   * With a `BitMask`, each bit in the output will be set if there was a
///     match at that position of the haystack.
///   * In the `UnitMask` case, each "unit" in the output will be set if there's
///     a match at that position in the haystack. The size of a unit is set by
///     the "char type" you select (either 8 bits or 16 bits at a time).
///
/// It's a lot to take in. Hopefully the examples below can help clarify how
/// things work. They all use `u8` since Rust string literals are UTF-8, but
/// it's the same with the other character types.
///
/// ## EqAny
/// ```
/// # use safe_arch::*;
/// let hay: m128i = m128i::from(*b"some test words.");
///
/// // explicit needle length
/// let needle: m128i = m128i::from(*b"e_______________");
/// let i: u128 =
///   string_search_for_mask!([needle, 1], [hay, 16], u8, EqAny, BitMask).into();
/// assert_eq!(i, 0b0000000001001000);
/// let i: [i8; 16] =
///   string_search_for_mask!([needle, 1], [hay, 16], u8, EqAny, UnitMask).into();
/// assert_eq!(i, [0, 0, 0, -1, 0, 0, -1, 0, 0, 0, 0, 0, 0, 0, 0, 0]);
///
/// // implicit needle length
/// let needle: m128i = m128i::from(*b"e\0______________");
/// let i: u128 = string_search_for_mask!(needle, hay, u8, EqAny, BitMask).into();
/// assert_eq!(i, 0b0000000001001000);
///
/// // more than one needle character will match any of them, though we
/// // don't get info about _which_ needle character matched.
/// let needle: m128i = m128i::from(*b"et\0_____________");
/// let i: u128 = string_search_for_mask!(needle, hay, u8, EqAny, BitMask).into();
/// assert_eq!(i, 0b0000000101101000);
/// ```
/// ## CmpRanges
/// ```
/// # use safe_arch::*;
/// let hay: m128i = m128i::from(*b"some test words.");
/// let needle: m128i = m128i::from(*b"am\0_____________");
/// let i: u128 =
///   string_search_for_mask!(needle, hay, u8, CmpRanges, BitMask).into();
/// assert_eq!(i, 0b0010000001001100);
/// ```
/// ## CmpEqEach
/// ```
/// # use safe_arch::*;
/// let hay: m128i = m128i::from(*b"some test words.");
/// let needle: m128i = m128i::from(*b"_____test_______");
/// let i: u128 =
///   string_search_for_mask!(needle, hay, u8, CmpEqEach, BitMask).into();
/// assert_eq!(i, 0b0000000111100000);
/// ```
/// ## CmpEqOrdered
/// ```
/// # use safe_arch::*;
/// let hay: m128i = m128i::from(*b"some test words.");
/// let needle: m128i = m128i::from(*b"words\0__________");
/// let i: u128 =
///   string_search_for_mask!(needle, hay, u8, CmpEqOrdered, BitMask).into();
/// assert_eq!(i, 0b00000010000000000); // one bit at the start of the match
/// ```
#[macro_export]
#[cfg_attr(docs_rs, doc(cfg(target_feature = "sse4.2")))]
macro_rules! string_search_for_mask {
  ([$needle:expr, $needle_len:expr], [$haystack:expr, $haystack_len:expr], $char_type:tt, $search_op:tt, $mask_style:tt) => {{
    $crate::string_search_for_mask!(
      @_raw_explicit_len
      $needle,
      $needle_len,
      $haystack,
      $haystack_len,
      $crate::string_search_for_mask!(@_char_type $char_type)
      | $crate::string_search_for_mask!(@_search_op $search_op)
      | $crate::string_search_for_mask!(@_mask_style $mask_style)
    )
  }};

  ($needle:expr, $haystack:expr, $char_type:tt, $search_op:tt, $mask_style:tt) => {{
    $crate::string_search_for_mask!(
      @_raw_implicit_len
      $needle,
      $haystack,
      $crate::string_search_for_mask!(@_char_type $char_type)
      | $crate::string_search_for_mask!(@_search_op $search_op)
      | $crate::string_search_for_mask!(@_mask_style $mask_style)
    )
  }};

  // Character types

  (@_char_type u8) => {{
    #[cfg(target_arch = "x86")]
    use ::core::arch::x86::_SIDD_UBYTE_OPS;
    #[cfg(target_arch = "x86_64")]
    use ::core::arch::x86_64::_SIDD_UBYTE_OPS;
    _SIDD_UBYTE_OPS
  }};
  (@_char_type u16) => {{
    #[cfg(target_arch = "x86")]
    use ::core::arch::x86::_SIDD_UWORD_OPS;
    #[cfg(target_arch = "x86_64")]
    use ::core::arch::x86_64::_SIDD_UWORD_OPS;
    _SIDD_UWORD_OPS
  }};
  (@_char_type i8) => {{
    #[cfg(target_arch = "x86")]
    use ::core::arch::x86::_SIDD_SBYTE_OPS;
    #[cfg(target_arch = "x86_64")]
    use ::core::arch::x86_64::_SIDD_SBYTE_OPS;
    _SIDD_SBYTE_OPS
  }};
  (@_char_type i16) => {{
    #[cfg(target_arch = "x86")]
    use ::core::arch::x86::_SIDD_SWORD_OPS;
    #[cfg(target_arch = "x86_64")]
    use ::core::arch::x86_64::_SIDD_SWORD_OPS;
    _SIDD_SWORD_OPS
  }};
  (@_char_type $unknown:tt) => {
    compile_error!("legal character types are: u8, u16, i8, i16")
  };

  // Search styles

  (@_search_op EqAny) => {{
    #[cfg(target_arch = "x86")]
    use ::core::arch::x86::_SIDD_CMP_EQUAL_ANY;
    #[cfg(target_arch = "x86_64")]
    use ::core::arch::x86_64::_SIDD_CMP_EQUAL_ANY;
    _SIDD_CMP_EQUAL_ANY
  }};
  (@_search_op CmpRanges) => {{
    #[cfg(target_arch = "x86")]
    use ::core::arch::x86::_SIDD_CMP_RANGES;
    #[cfg(target_arch = "x86_64")]
    use ::core::arch::x86_64::_SIDD_CMP_RANGES;
    _SIDD_CMP_RANGES
  }};
  (@_search_op CmpEqEach) => {{
    #[cfg(target_arch = "x86")]
    use ::core::arch::x86::_SIDD_CMP_EQUAL_EACH;
    #[cfg(target_arch = "x86_64")]
    use ::core::arch::x86_64::_SIDD_CMP_EQUAL_EACH;
    _SIDD_CMP_EQUAL_EACH
  }};
  (@_search_op CmpEqOrdered) => {{
    #[cfg(target_arch = "x86")]
    use ::core::arch::x86::_SIDD_CMP_EQUAL_ORDERED;
    #[cfg(target_arch = "x86_64")]
    use ::core::arch::x86_64::_SIDD_CMP_EQUAL_ORDERED;
    _SIDD_CMP_EQUAL_ORDERED
  }};
  (@_search_op $unknown:tt) => {
    compile_error!(
      "legal search operations are: EqAny, CmpRanges, CmpEqEach, CmpEqOrdered"
    )
  };

  // Mask output style

  (@_mask_style BitMask) => {{
    #[cfg(target_arch = "x86")]
    use ::core::arch::x86::_SIDD_BIT_MASK;
    #[cfg(target_arch = "x86_64")]
    use ::core::arch::x86_64::_SIDD_BIT_MASK;
    _SIDD_BIT_MASK
  }};
  (@_mask_style UnitMask) => {{
    #[cfg(target_arch = "x86")]
    use ::core::arch::x86::_SIDD_UNIT_MASK;
    #[cfg(target_arch = "x86_64")]
    use ::core::arch::x86_64::_SIDD_UNIT_MASK;
    _SIDD_UNIT_MASK
  }};
  (@_mask_style $unknown:tt) => {
    compile_error!("legal str mask style are: BitMask, UnitMask")
  };

  // The final, actual, calls to the intrinsic.

  (@_raw_explicit_len $needle:expr, $needle_len:expr, $haystack:expr, $haystack_len:expr, $imm:expr) => {{
    let a: m128i = $needle;
    let la: i32 = $needle_len;
    let b: m128i = $haystack;
    let lb: i32 = $haystack_len;
    const IMM: i32 = $imm as i32;
    #[cfg(target_arch = "x86")]
    use ::core::arch::x86::_mm_cmpestrm;
    #[cfg(target_arch = "x86_64")]
    use ::core::arch::x86_64::_mm_cmpestrm;
    m128i(unsafe { _mm_cmpestrm(a.0, la, b.0, lb, IMM) })
  }};

  (@_raw_implicit_len $needle:expr, $haystack:expr, $imm:expr) => {{
    let a: m128i = $needle;
    let b: m128i = $haystack;
    const IMM: i32 = $imm as i32;
    #[cfg(target_arch = "x86")]
    use ::core::arch::x86::_mm_cmpistrm;
    #[cfg(target_arch = "x86_64")]
    use ::core::arch::x86_64::_mm_cmpistrm;
    m128i(unsafe { _mm_cmpistrm(a.0, b.0, IMM) })
  }};
}