MCPcopy Create free account
hub / github.com/bytecodealliance/wasmtime / insert_cmp

Function insert_cmp

cranelift/fuzzgen/src/function_generator.rs:179–232  ·  view source on GitHub ↗
(
    fgen: &mut FunctionGenerator,
    builder: &mut FunctionBuilder,
    opcode: Opcode,
    args: &[Type],
    rets: &[Type],
)

Source from the content-addressed store, hash-verified

177}
178
179fn insert_cmp(
180 fgen: &mut FunctionGenerator,
181 builder: &mut FunctionBuilder,
182 opcode: Opcode,
183 args: &[Type],
184 rets: &[Type],
185) -> Result<()> {
186 let lhs = fgen.get_variable_of_type(args[0])?;
187 let lhs = builder.use_var(lhs);
188
189 let rhs = fgen.get_variable_of_type(args[1])?;
190 let rhs = builder.use_var(rhs);
191
192 let res = if opcode == Opcode::Fcmp {
193 let cc = *fgen.u.choose(FloatCC::all())?;
194
195 // We filter out condition codes that aren't supported by the target at
196 // this point after randomly choosing one, instead of randomly choosing a
197 // supported one, to avoid invalidating the corpus when these get implemented.
198 let unimplemented_cc = match (fgen.isa.triple().architecture, cc) {
199 // Some FloatCC's are not implemented on AArch64, see:
200 // https://github.com/bytecodealliance/wasmtime/issues/4850
201 (Architecture::Aarch64(_), FloatCC::OrderedNotEqual) => true,
202 (Architecture::Aarch64(_), FloatCC::UnorderedOrEqual) => true,
203
204 // Not implemented on aarch64 for vectors
205 (Architecture::Aarch64(_), FloatCC::UnorderedOrLessThan)
206 | (Architecture::Aarch64(_), FloatCC::UnorderedOrLessThanOrEqual)
207 | (Architecture::Aarch64(_), FloatCC::UnorderedOrGreaterThan)
208 | (Architecture::Aarch64(_), FloatCC::UnorderedOrGreaterThanOrEqual) => {
209 args[0].is_vector()
210 }
211
212 // These are not implemented on x86_64, for vectors.
213 (Architecture::X86_64, FloatCC::UnorderedOrEqual | FloatCC::OrderedNotEqual) => {
214 args[0].is_vector()
215 }
216 _ => false,
217 };
218 if unimplemented_cc {
219 return Err(arbitrary::Error::IncorrectFormat.into());
220 }
221
222 builder.ins().fcmp(cc, lhs, rhs)
223 } else {
224 let cc = *fgen.u.choose(IntCC::all())?;
225 builder.ins().icmp(cc, lhs, rhs)
226 };
227
228 let var = fgen.get_variable_of_type(rets[0])?;
229 builder.def_var(var, res);
230
231 Ok(())
232}
233
234fn insert_const(
235 fgen: &mut FunctionGenerator,

Callers

nothing calls this directly

Calls 8

OkFunction · 0.85
get_variable_of_typeMethod · 0.80
fcmpMethod · 0.80
use_varMethod · 0.45
tripleMethod · 0.45
is_vectorMethod · 0.45
insMethod · 0.45
def_varMethod · 0.45

Tested by

no test coverage detected