Debian Codegraph @

debian/missing-sources/safe_arch/src/x86_x64/sse4_2.rs

raw
1 #![cfg(target_feature = "sse4.2")]
2
3 use super::*;
4
5 /// Lanewise `a > b` with lanes as `i64`.
6 ///
7 /// All bits 1 for true (`-1`), all bit 0 for false (`0`).
8 ///
9 /// * **Intrinsic:** [`_mm_cmpgt_epi64`]
10 /// * **Assembly:** `pcmpgtq xmm, xmm`
11 #[must_use]
12 #[inline(always)]
13 #[cfg_attr(docsrs, doc(cfg(target_feature = "sse4.2")))]
14 pub fn cmp_gt_mask_i64_m128i(a: m128i, b: m128i) -> m128i {
15 m128i(unsafe { _mm_cmpgt_epi64(a.0, b.0) })
16 }
17
18 /// Accumulates the `u8` into a running CRC32 value.
19 ///
20 /// * **Intrinsic:** [`_mm_crc32_u8`]
21 /// * **Assembly:** `crc32 r32, r8`
22 #[must_use]
23 #[inline(always)]
24 #[cfg_attr(docsrs, doc(cfg(target_feature = "sse4.2")))]
25 pub fn crc32_u8(crc: u32, v: u8) -> u32 {
26 unsafe { _mm_crc32_u8(crc, v) }
27 }
28
29 /// Accumulates the `u16` into a running CRC32 value.
30 ///
31 /// * **Intrinsic:** [`_mm_crc32_u16`]
32 /// * **Assembly:** `crc32 r32, r16`
33 #[must_use]
34 #[inline(always)]
35 #[cfg_attr(docsrs, doc(cfg(target_feature = "sse4.2")))]
36 pub fn crc32_u16(crc: u32, v: u16) -> u32 {
37 unsafe { _mm_crc32_u16(crc, v) }
38 }
39
40 /// Accumulates the `u32` into a running CRC32 value.
41 ///
42 /// * **Intrinsic:** [`_mm_crc32_u32`]
43 /// * **Assembly:** `crc32 r32, r32`
44 #[must_use]
45 #[inline(always)]
46 #[cfg_attr(docsrs, doc(cfg(target_feature = "sse4.2")))]
47 pub fn crc32_u32(crc: u32, v: u32) -> u32 {
48 unsafe { _mm_crc32_u32(crc, v) }
49 }
50
51 /// Accumulates the `u64` into a running CRC32 value.
52 ///
53 /// **Note:** Has a different return type from the other crc32 functions.
54 ///
55 /// * **Intrinsic:** [`_mm_crc32_u64`]
56 /// * **Assembly:** `crc32 r64, r64`
57 #[must_use]
58 #[inline(always)]
59 #[cfg(target_arch = "x86_64")]
60 #[cfg_attr(docsrs, doc(cfg(target_feature = "sse4.2")))]
61 pub fn crc32_u64(crc: u64, v: u64) -> u64 {
62 unsafe { _mm_crc32_u64(crc, v) }
63 }
64
65 /// string segment elements are u8 values
66 pub const STR_CMP_U8: i32 = _SIDD_UBYTE_OPS;
67 /// string segment elements are u16 values
68 pub const STR_CMP_U16: i32 = _SIDD_UWORD_OPS;
69 /// string segment elements are i8 values
70 pub const STR_CMP_I8: i32 = _SIDD_SBYTE_OPS;
71 /// string segment elements are i16 values
72 pub const STR_CMP_I16: i32 = _SIDD_SWORD_OPS;
73
74 /// Matches when _any_ haystack character equals _any_ needle character,
75 /// regardless of position.
76 pub const STR_CMP_EQ_ANY: i32 = _SIDD_CMP_EQUAL_ANY;
77 /// Interprets consecutive pairs of characters in the needle as `(low..=high)`
78 /// ranges to compare each haystack character to.
79 pub const STR_CMP_RANGES: i32 = _SIDD_CMP_RANGES;
80 /// Matches when a character position in the needle is equal to the character at
81 /// the same position in the haystack.
82 pub const STR_CMP_EQ_EACH: i32 = _SIDD_CMP_EQUAL_EACH;
83 /// Matches when the complete needle string is a substring somewhere in the
84 /// haystack.
85 pub const STR_CMP_EQ_ORDERED: i32 = _SIDD_CMP_EQUAL_ORDERED;
86
87 /// Return the index of the first match found.
88 pub const STR_CMP_FIRST_MATCH: i32 = _SIDD_LEAST_SIGNIFICANT;
89 /// Return the index of the last match found.
90 pub const STR_CMP_LAST_MATCH: i32 = _SIDD_MOST_SIGNIFICANT;
91
92 /// Return the bitwise mask of matches.
93 pub const STR_CMP_BIT_MASK: i32 = _SIDD_BIT_MASK;
94 /// Return the lanewise mask of matches.
95 pub const STR_CMP_UNIT_MASK: i32 = _SIDD_UNIT_MASK;
96
97 /// Search for `needle` in `haystack, with implicit string length.
98 ///
99 /// In the constant you need to provide (combine with `|`):
100 /// * A comparison unit: `STR_CMP_U8`, `STR_CMP_U16`, `STR_CMP_I8`, or
101 /// `STR_CMP_I16`.
102 /// * A comparison op: `STR_CMP_EQ_ANY`, `STR_CMP_RANGES`, `STR_CMP_EQ_EACH`, or
103 /// `STR_CMP_EQ_ORDERED`.
104 /// * The desired output: `STR_CMP_FIRST_MATCH` or `STR_CMP_LAST_MATCH`.
105 ///
106 /// The first 0 unit is a null terminator for the string. If the string has no 0
107 /// units then the string ends at the end of the register.
108 ///
109 /// If there's no match the output is the length of the haystack.
110 ///
111 /// * **Intrinsic:** [`_mm_cmpistri`]
112 /// * **Assembly:** `pcmpistri xmm, xmm, imm8`
113 #[must_use]
114 #[inline(always)]
115 #[cfg(target_arch = "x86_64")]
116 #[cfg_attr(docsrs, doc(cfg(target_feature = "sse4.2")))]
117 pub fn search_implicit_str_for_index<const IMM: i32>(
118 needle: m128i, haystack: m128i,
119 ) -> i32 {
120 unsafe { _mm_cmpistri(needle.0, haystack.0, IMM) }
121 }
122
123 /// Search for `needle` in `haystack, with explicit string length.
124 ///
125 /// In the constant you need to provide (combine with `|`):
126 /// * A comparison unit: `STR_CMP_U8`, `STR_CMP_U16`, `STR_CMP_I8`, or
127 /// `STR_CMP_I16`.
128 /// * A comparison op: `STR_CMP_EQ_ANY`, `STR_CMP_RANGES`, `STR_CMP_EQ_EACH`, or
129 /// `STR_CMP_EQ_ORDERED`.
130 /// * The desired output: `STR_CMP_FIRST_MATCH` or `STR_CMP_LAST_MATCH`.
131 ///
132 /// If there's no match the output is the length of the haystack.
133 ///
134 /// * **Intrinsic:** [`_mm_cmpestri`]
135 /// * **Assembly:** `pcmpestri xmm, xmm, imm8`
136 #[must_use]
137 #[inline(always)]
138 #[cfg(target_arch = "x86_64")]
139 #[cfg_attr(docsrs, doc(cfg(target_feature = "sse4.2")))]
140 pub fn search_explicit_str_for_index<const IMM: i32>(
141 needle: m128i, needle_len: i32, haystack: m128i, haystack_len: i32,
142 ) -> i32 {
143 unsafe { _mm_cmpestri(needle.0, needle_len, haystack.0, haystack_len, IMM) }
144 }
145
146 /// Search for `needle` in `haystack, with implicit string length.
147 ///
148 /// In the constant you need to provide (combine with `|`):
149 /// * A comparison unit: `STR_CMP_U8`, `STR_CMP_U16`, `STR_CMP_I8`, or
150 /// `STR_CMP_I16`.
151 /// * A comparison op: `STR_CMP_EQ_ANY`, `STR_CMP_RANGES`, `STR_CMP_EQ_EACH`, or
152 /// `STR_CMP_EQ_ORDERED`.
153 /// * The desired out mask style: `STR_CMP_BIT_MASK` or `STR_CMP_UNIT_MASK`.
154 ///
155 /// The first 0 unit is a null terminator for the string. If the string has no 0
156 /// units then the string ends at the end of the register.
157 ///
158 /// * **Intrinsic:** [`_mm_cmpistrm`]
159 /// * **Assembly:** `pcmpistrm xmm, xmm, imm8`
160 #[must_use]
161 #[inline(always)]
162 #[cfg(target_arch = "x86_64")]
163 #[cfg_attr(docsrs, doc(cfg(target_feature = "sse4.2")))]
164 pub fn search_implicit_str_for_mask<const IMM: i32>(
165 needle: m128i, haystack: m128i,
166 ) -> m128i {
167 m128i(unsafe { _mm_cmpistrm(needle.0, haystack.0, IMM) })
168 }
169
170 /// Search for `needle` in `haystack, with explicit string length.
171 ///
172 /// In the constant you need to provide (combine with `|`):
173 /// * A comparison unit: `STR_CMP_U8`, `STR_CMP_U16`, `STR_CMP_I8`, or
174 /// `STR_CMP_I16`.
175 /// * A comparison op: `STR_CMP_EQ_ANY`, `STR_CMP_RANGES`, `STR_CMP_EQ_EACH`, or
176 /// `STR_CMP_EQ_ORDERED`.
177 /// * The desired out mask style: `STR_CMP_BIT_MASK` or `STR_CMP_UNIT_MASK`.
178 ///
179 /// If there's no match the output is the length of the haystack.
180 ///
181 /// * **Intrinsic:** [`_mm_cmpestrm`]
182 /// * **Assembly:** `pcmpestrm xmm, xmm, imm8`
183 #[must_use]
184 #[inline(always)]
185 #[cfg(target_arch = "x86_64")]
186 #[cfg_attr(docsrs, doc(cfg(target_feature = "sse4.2")))]
187 pub fn search_explicit_str_for_mask<const IMM: i32>(
188 needle: m128i, needle_len: i32, haystack: m128i, haystack_len: i32,
189 ) -> m128i {
190 m128i(unsafe {
191 _mm_cmpestrm(needle.0, needle_len, haystack.0, haystack_len, IMM)
192 })
193 }
194