microsoft/qdk

Public

mirrored from https://github.com/microsoft/qdkAvailable

CodeCommitsIssuesPull requestsActionsInsightsSecurity
iadavis/pipeline-issue-debugging

Branches

Tags

  • No tags available.
0Branches0Tags
Go to file
Add file
Code

Clone

HTTPS

Download ZIP

source/compiler/qsc_codegen/src/qir/instruction_tests/double.rs

479lines · modecode

1// Copyright (c) Microsoft Corporation.
2// Licensed under the MIT License.
3
4use core::f64::consts::{E, PI};
5
6use crate::qir::ToQir;
7use expect_test::expect;
8use qsc_rir::rir::{
9 FcmpConditionCode, Instruction, Literal, Operand, Program, Ty, Variable, VariableId,
10};
11
12#[test]
13#[should_panic(expected = "unsupported type double for add")]
14fn add_double_literals() {
15 let inst = Instruction::Add(
16 Operand::Literal(Literal::Double(PI)),
17 Operand::Literal(Literal::Double(E)),
18 Variable {
19 variable_id: VariableId(0),
20 ty: Ty::Double,
21 },
22 );
23 let _ = &inst.to_qir(&Program::default());
24}
25
26#[test]
27#[should_panic(expected = "unsupported type double for sub")]
28fn sub_double_literals() {
29 let inst = Instruction::Sub(
30 Operand::Literal(Literal::Double(PI)),
31 Operand::Literal(Literal::Double(E)),
32 Variable {
33 variable_id: VariableId(0),
34 ty: Ty::Double,
35 },
36 );
37 let _ = &inst.to_qir(&Program::default());
38}
39
40#[test]
41#[should_panic(expected = "unsupported type double for mul")]
42fn mul_double_literals() {
43 let inst = Instruction::Mul(
44 Operand::Literal(Literal::Double(PI)),
45 Operand::Literal(Literal::Double(E)),
46 Variable {
47 variable_id: VariableId(0),
48 ty: Ty::Double,
49 },
50 );
51 let _ = &inst.to_qir(&Program::default());
52}
53
54#[test]
55#[should_panic(expected = "unsupported type double for sdiv")]
56fn sdiv_double_literals() {
57 let inst = Instruction::Sdiv(
58 Operand::Literal(Literal::Double(PI)),
59 Operand::Literal(Literal::Double(E)),
60 Variable {
61 variable_id: VariableId(0),
62 ty: Ty::Double,
63 },
64 );
65 let _ = &inst.to_qir(&Program::default());
66}
67
68#[test]
69fn fadd_double_literals() {
70 let inst = Instruction::Fadd(
71 Operand::Literal(Literal::Double(PI)),
72 Operand::Literal(Literal::Double(E)),
73 Variable {
74 variable_id: VariableId(0),
75 ty: Ty::Double,
76 },
77 );
78 expect![" %var_0 = fadd double 3.141592653589793, 2.718281828459045"]
79 .assert_eq(&inst.to_qir(&Program::default()));
80}
81
82#[test]
83#[should_panic(expected = "unsupported type double for ashr")]
84fn ashr_double_literals() {
85 let inst = Instruction::Ashr(
86 Operand::Literal(Literal::Double(PI)),
87 Operand::Literal(Literal::Double(E)),
88 Variable {
89 variable_id: VariableId(0),
90 ty: Ty::Double,
91 },
92 );
93 let _ = &inst.to_qir(&Program::default());
94}
95
96#[test]
97#[should_panic(expected = "unsupported type double for and")]
98fn bitwise_and_double_literals() {
99 let inst = Instruction::BitwiseAnd(
100 Operand::Literal(Literal::Double(PI)),
101 Operand::Literal(Literal::Double(E)),
102 Variable {
103 variable_id: VariableId(0),
104 ty: Ty::Double,
105 },
106 );
107 let _ = &inst.to_qir(&Program::default());
108}
109
110#[test]
111#[should_panic(expected = "unsupported type double for not")]
112fn bitwise_not_double_literals() {
113 let inst = Instruction::BitwiseNot(
114 Operand::Literal(Literal::Double(PI)),
115 Variable {
116 variable_id: VariableId(0),
117 ty: Ty::Double,
118 },
119 );
120 let _ = &inst.to_qir(&Program::default());
121}
122
123#[test]
124#[should_panic(expected = "unsupported type double for or")]
125fn bitwise_or_double_literals() {
126 let inst = Instruction::BitwiseOr(
127 Operand::Literal(Literal::Double(PI)),
128 Operand::Literal(Literal::Double(E)),
129 Variable {
130 variable_id: VariableId(0),
131 ty: Ty::Double,
132 },
133 );
134 let _ = &inst.to_qir(&Program::default());
135}
136
137#[test]
138#[should_panic(expected = "unsupported type double for xor")]
139fn bitwise_xor_double_literals() {
140 let inst = Instruction::BitwiseXor(
141 Operand::Literal(Literal::Double(PI)),
142 Operand::Literal(Literal::Double(E)),
143 Variable {
144 variable_id: VariableId(0),
145 ty: Ty::Double,
146 },
147 );
148 let _ = &inst.to_qir(&Program::default());
149}
150
151#[test]
152fn fadd_double_variables() {
153 let inst = Instruction::Fadd(
154 Operand::Variable(Variable {
155 variable_id: VariableId(1),
156 ty: Ty::Double,
157 }),
158 Operand::Variable(Variable {
159 variable_id: VariableId(2),
160 ty: Ty::Double,
161 }),
162 Variable {
163 variable_id: VariableId(0),
164 ty: Ty::Double,
165 },
166 );
167 expect![" %var_0 = fadd double %var_1, %var_2"].assert_eq(&inst.to_qir(&Program::default()));
168}
169
170#[test]
171fn fcmp_oeq_double_literals() {
172 let inst = Instruction::Fcmp(
173 FcmpConditionCode::OrderedAndEqual,
174 Operand::Literal(Literal::Double(PI)),
175 Operand::Literal(Literal::Double(E)),
176 Variable {
177 variable_id: VariableId(0),
178 ty: Ty::Boolean,
179 },
180 );
181 expect![" %var_0 = fcmp oeq double 3.141592653589793, 2.718281828459045"]
182 .assert_eq(&inst.to_qir(&Program::default()));
183}
184
185#[test]
186fn fcmp_oeq_double_variables() {
187 let inst = Instruction::Fcmp(
188 FcmpConditionCode::OrderedAndEqual,
189 Operand::Variable(Variable {
190 variable_id: VariableId(1),
191 ty: Ty::Double,
192 }),
193 Operand::Variable(Variable {
194 variable_id: VariableId(2),
195 ty: Ty::Double,
196 }),
197 Variable {
198 variable_id: VariableId(0),
199 ty: Ty::Boolean,
200 },
201 );
202 expect![" %var_0 = fcmp oeq double %var_1, %var_2"]
203 .assert_eq(&inst.to_qir(&Program::default()));
204}
205
206#[test]
207fn fcmp_one_double_literals() {
208 let inst = Instruction::Fcmp(
209 FcmpConditionCode::OrderedAndNotEqual,
210 Operand::Literal(Literal::Double(PI)),
211 Operand::Literal(Literal::Double(E)),
212 Variable {
213 variable_id: VariableId(0),
214 ty: Ty::Boolean,
215 },
216 );
217 expect![" %var_0 = fcmp one double 3.141592653589793, 2.718281828459045"]
218 .assert_eq(&inst.to_qir(&Program::default()));
219}
220
221#[test]
222fn fcmp_one_double_variables() {
223 let inst = Instruction::Fcmp(
224 FcmpConditionCode::OrderedAndNotEqual,
225 Operand::Variable(Variable {
226 variable_id: VariableId(1),
227 ty: Ty::Double,
228 }),
229 Operand::Variable(Variable {
230 variable_id: VariableId(2),
231 ty: Ty::Double,
232 }),
233 Variable {
234 variable_id: VariableId(0),
235 ty: Ty::Boolean,
236 },
237 );
238 expect![" %var_0 = fcmp one double %var_1, %var_2"]
239 .assert_eq(&inst.to_qir(&Program::default()));
240}
241#[test]
242fn fcmp_olt_double_literals() {
243 let inst = Instruction::Fcmp(
244 FcmpConditionCode::OrderedAndLessThan,
245 Operand::Literal(Literal::Double(PI)),
246 Operand::Literal(Literal::Double(E)),
247 Variable {
248 variable_id: VariableId(0),
249 ty: Ty::Boolean,
250 },
251 );
252 expect![" %var_0 = fcmp olt double 3.141592653589793, 2.718281828459045"]
253 .assert_eq(&inst.to_qir(&Program::default()));
254}
255
256#[test]
257fn fcmp_olt_double_variables() {
258 let inst = Instruction::Fcmp(
259 FcmpConditionCode::OrderedAndLessThan,
260 Operand::Variable(Variable {
261 variable_id: VariableId(1),
262 ty: Ty::Double,
263 }),
264 Operand::Variable(Variable {
265 variable_id: VariableId(2),
266 ty: Ty::Double,
267 }),
268 Variable {
269 variable_id: VariableId(0),
270 ty: Ty::Boolean,
271 },
272 );
273 expect![" %var_0 = fcmp olt double %var_1, %var_2"]
274 .assert_eq(&inst.to_qir(&Program::default()));
275}
276#[test]
277fn fcmp_ole_double_literals() {
278 let inst = Instruction::Fcmp(
279 FcmpConditionCode::OrderedAndLessThanOrEqual,
280 Operand::Literal(Literal::Double(PI)),
281 Operand::Literal(Literal::Double(E)),
282 Variable {
283 variable_id: VariableId(0),
284 ty: Ty::Boolean,
285 },
286 );
287 expect![" %var_0 = fcmp ole double 3.141592653589793, 2.718281828459045"]
288 .assert_eq(&inst.to_qir(&Program::default()));
289}
290
291#[test]
292fn fcmp_ole_double_variables() {
293 let inst = Instruction::Fcmp(
294 FcmpConditionCode::OrderedAndLessThanOrEqual,
295 Operand::Variable(Variable {
296 variable_id: VariableId(1),
297 ty: Ty::Double,
298 }),
299 Operand::Variable(Variable {
300 variable_id: VariableId(2),
301 ty: Ty::Double,
302 }),
303 Variable {
304 variable_id: VariableId(0),
305 ty: Ty::Boolean,
306 },
307 );
308 expect![" %var_0 = fcmp ole double %var_1, %var_2"]
309 .assert_eq(&inst.to_qir(&Program::default()));
310}
311#[test]
312fn fcmp_ogt_double_literals() {
313 let inst = Instruction::Fcmp(
314 FcmpConditionCode::OrderedAndGreaterThan,
315 Operand::Literal(Literal::Double(PI)),
316 Operand::Literal(Literal::Double(E)),
317 Variable {
318 variable_id: VariableId(0),
319 ty: Ty::Boolean,
320 },
321 );
322 expect![" %var_0 = fcmp ogt double 3.141592653589793, 2.718281828459045"]
323 .assert_eq(&inst.to_qir(&Program::default()));
324}
325
326#[test]
327fn fcmp_ogt_double_variables() {
328 let inst = Instruction::Fcmp(
329 FcmpConditionCode::OrderedAndGreaterThan,
330 Operand::Variable(Variable {
331 variable_id: VariableId(1),
332 ty: Ty::Double,
333 }),
334 Operand::Variable(Variable {
335 variable_id: VariableId(2),
336 ty: Ty::Double,
337 }),
338 Variable {
339 variable_id: VariableId(0),
340 ty: Ty::Boolean,
341 },
342 );
343 expect![" %var_0 = fcmp ogt double %var_1, %var_2"]
344 .assert_eq(&inst.to_qir(&Program::default()));
345}
346#[test]
347fn fcmp_oge_double_literals() {
348 let inst = Instruction::Fcmp(
349 FcmpConditionCode::OrderedAndGreaterThanOrEqual,
350 Operand::Literal(Literal::Double(PI)),
351 Operand::Literal(Literal::Double(E)),
352 Variable {
353 variable_id: VariableId(0),
354 ty: Ty::Boolean,
355 },
356 );
357 expect![" %var_0 = fcmp oge double 3.141592653589793, 2.718281828459045"]
358 .assert_eq(&inst.to_qir(&Program::default()));
359}
360
361#[test]
362fn fcmp_oge_double_variables() {
363 let inst = Instruction::Fcmp(
364 FcmpConditionCode::OrderedAndGreaterThanOrEqual,
365 Operand::Variable(Variable {
366 variable_id: VariableId(1),
367 ty: Ty::Double,
368 }),
369 Operand::Variable(Variable {
370 variable_id: VariableId(2),
371 ty: Ty::Double,
372 }),
373 Variable {
374 variable_id: VariableId(0),
375 ty: Ty::Boolean,
376 },
377 );
378 expect![" %var_0 = fcmp oge double %var_1, %var_2"]
379 .assert_eq(&inst.to_qir(&Program::default()));
380}
381
382#[test]
383fn fmul_double_literals() {
384 let inst = Instruction::Fmul(
385 Operand::Literal(Literal::Double(PI)),
386 Operand::Literal(Literal::Double(E)),
387 Variable {
388 variable_id: VariableId(0),
389 ty: Ty::Double,
390 },
391 );
392 expect![" %var_0 = fmul double 3.141592653589793, 2.718281828459045"]
393 .assert_eq(&inst.to_qir(&Program::default()));
394}
395
396#[test]
397fn fmul_double_variables() {
398 let inst = Instruction::Fmul(
399 Operand::Variable(Variable {
400 variable_id: VariableId(1),
401 ty: Ty::Double,
402 }),
403 Operand::Variable(Variable {
404 variable_id: VariableId(2),
405 ty: Ty::Double,
406 }),
407 Variable {
408 variable_id: VariableId(0),
409 ty: Ty::Double,
410 },
411 );
412 expect![" %var_0 = fmul double %var_1, %var_2"].assert_eq(&inst.to_qir(&Program::default()));
413}
414
415#[test]
416fn fdiv_double_literals() {
417 let inst = Instruction::Fdiv(
418 Operand::Literal(Literal::Double(PI)),
419 Operand::Literal(Literal::Double(E)),
420 Variable {
421 variable_id: VariableId(0),
422 ty: Ty::Double,
423 },
424 );
425 expect![" %var_0 = fdiv double 3.141592653589793, 2.718281828459045"]
426 .assert_eq(&inst.to_qir(&Program::default()));
427}
428
429#[test]
430fn fdiv_double_variables() {
431 let inst = Instruction::Fdiv(
432 Operand::Variable(Variable {
433 variable_id: VariableId(1),
434 ty: Ty::Double,
435 }),
436 Operand::Variable(Variable {
437 variable_id: VariableId(2),
438 ty: Ty::Double,
439 }),
440 Variable {
441 variable_id: VariableId(0),
442 ty: Ty::Double,
443 },
444 );
445 expect![" %var_0 = fdiv double %var_1, %var_2"].assert_eq(&inst.to_qir(&Program::default()));
446}
447
448#[test]
449fn fsub_double_literals() {
450 let inst = Instruction::Fsub(
451 Operand::Literal(Literal::Double(PI)),
452 Operand::Literal(Literal::Double(E)),
453 Variable {
454 variable_id: VariableId(0),
455 ty: Ty::Double,
456 },
457 );
458 expect![" %var_0 = fsub double 3.141592653589793, 2.718281828459045"]
459 .assert_eq(&inst.to_qir(&Program::default()));
460}
461
462#[test]
463fn fsub_double_variables() {
464 let inst = Instruction::Fsub(
465 Operand::Variable(Variable {
466 variable_id: VariableId(1),
467 ty: Ty::Double,
468 }),
469 Operand::Variable(Variable {
470 variable_id: VariableId(2),
471 ty: Ty::Double,
472 }),
473 Variable {
474 variable_id: VariableId(0),
475 ty: Ty::Double,
476 },
477 );
478 expect![" %var_0 = fsub double %var_1, %var_2"].assert_eq(&inst.to_qir(&Program::default()));
479}
480