Skip to content
This repository has been archived by the owner on Jan 12, 2024. It is now read-only.

Commit

Permalink
CR changes
Browse files Browse the repository at this point in the history
  • Loading branch information
kuzminrobin committed Feb 6, 2021
1 parent debfa49 commit dc623c1
Show file tree
Hide file tree
Showing 11 changed files with 530 additions and 557 deletions.
8 changes: 0 additions & 8 deletions src/QirRuntime/lib/QIR/bridge-qis.ll
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,6 @@ define void @__quantum__qis__z__ctl(%Array* %.ctls, %Qubit* %.q) {

; LLVM intrinsics (https://llvm.org/docs/LangRef.html):
declare double @llvm.sqrt.f64(double %.val)
;declare double @llvm.ceil.f64(double %Val)

; Native implementations:
declare i1 @quantum__qis__isnan__body(double %d)
Expand Down Expand Up @@ -319,10 +318,3 @@ define double @__quantum__qis__sqrt__body(double %d) { ; https://en.cpprefe
%result = call double @llvm.sqrt.f64(double %d)
ret double %result
}

;define i64 @__quantum__qis__ceiling__body(double %d) {
; %doubleResult = call double @llvm.ceil.f64(double %d)
; %result = call i64 @quantum__qis__doubleasint__body(double $doubleResult) ; Should be the same as DoubleAsInt in https://github.com/microsoft/qsharp-runtime/pull/497/files
; ret i64 %result
;}

8 changes: 2 additions & 6 deletions src/QirRuntime/lib/QIR/intrinsicsMath.cpp
Original file line number Diff line number Diff line change
@@ -1,16 +1,12 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

#include <cmath>
#include "quantum__qis.hpp"

extern "C"
{

// Declarations:
bool quantum__qis__isnan__body(double d);
double quantum__qis__inf__body();
bool quantum__qis__isinf__body(double d);

// Implementations:
bool quantum__qis__isnan__body(double d)
{
Expand Down
5 changes: 5 additions & 0 deletions src/QirRuntime/lib/QIR/quantum__qis.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,4 +59,9 @@ extern "C"
QIR_SHARED_API void quantum__qis__y__ctl(QirArray*, QUBIT*); // NOLINT
QIR_SHARED_API void quantum__qis__z__body(QUBIT*); // NOLINT
QIR_SHARED_API void quantum__qis__z__ctl(QirArray*, QUBIT*); // NOLINT

QIR_SHARED_API bool quantum__qis__isnan__body(double d); // NOLINT
QIR_SHARED_API double quantum__qis__infinity__body(); // NOLINT
QIR_SHARED_API bool quantum__qis__isinf__body(double d); // NOLINT

}
1 change: 0 additions & 1 deletion src/QirRuntime/test/QIR-dynamic/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ add_executable(qir-dynamic-tests
target_link_libraries(qir-dynamic-tests PUBLIC
${QIR_TESTS_LIBS}
qdk
qir-qis-support
)

target_include_directories(qir-dynamic-tests PUBLIC
Expand Down
3 changes: 2 additions & 1 deletion src/QirRuntime/test/QIR-static/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ add_custom_target(qir_static_test_lib DEPENDS ${QIR_TESTS_LIBS})
#
add_executable(qir-static-tests
qir-driver.cpp
qir-test-math.cpp)
qir-test-math.cpp
)

target_link_libraries(qir-static-tests PUBLIC
${QIR_TESTS_LIBS}
Expand Down
5 changes: 5 additions & 0 deletions src/QirRuntime/test/QIR-static/compiler/QirTarget.qs
Original file line number Diff line number Diff line change
Expand Up @@ -5,22 +5,27 @@ namespace Microsoft.Quantum.Intrinsic {

open Microsoft.Quantum.Targeting;

@Inline()
function NAN() : Double {
body intrinsic;
}

@Inline()
function IsNan(d: Double) : Bool {
body intrinsic;
}

@Inline()
function INFINITY() : Double {
body intrinsic;
}

@Inline()
function IsInf(d: Double) : Bool {
body intrinsic;
}

@Inline()
function Sqrt(d : Double) : Double {
body intrinsic;
}
Expand Down
2 changes: 1 addition & 1 deletion src/QirRuntime/test/QIR-static/qir-test-arrays.qs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ namespace Microsoft.Quantum.Testing.QIR
let res1 = TestControlled();
let res2 = TestPartials(17, 42);
let res3 = Test_Qubit_Result_Management();
let res4 = TestSqrt();
let res4 = SqrtTest();
}

return sum;
Expand Down
6 changes: 4 additions & 2 deletions src/QirRuntime/test/QIR-static/qir-test-math.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#include <cstdint>

#include "catch.hpp"

extern "C" uint64_t Microsoft__Quantum__Testing__QIR__Math__TestSqrt__body(); // NOLINT
extern "C" uint64_t Microsoft__Quantum__Testing__QIR__Math__SqrtTest__body(); // NOLINT

TEST_CASE("QIR: math.sqrt", "[qir.math][qir.math.sqrt]")
{
REQUIRE(0 == Microsoft__Quantum__Testing__QIR__Math__TestSqrt__body());
REQUIRE(0 == Microsoft__Quantum__Testing__QIR__Math__SqrtTest__body());
}
22 changes: 9 additions & 13 deletions src/QirRuntime/test/QIR-static/qir-test-math.qs
Original file line number Diff line number Diff line change
@@ -1,24 +1,20 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

namespace Microsoft.Quantum.Testing.QIR.Math
{
open Microsoft.Quantum.Intrinsic;

function TestSqrt() : Int
{
mutable testResult = 0;

if( 2.0 != Sqrt( 4.0) ) { set testResult = 1; }
else { if( 3.0 != Sqrt( 9.0) ) { set testResult = 2; }
else { if( 10.0 != Sqrt(100.0) ) { set testResult = 3; }
function SqrtTest() : Int {
if( 2.0 != Sqrt( 4.0) ) { return 1; }
if( 3.0 != Sqrt( 9.0) ) { return 2; }
if(10.0 != Sqrt(100.0) ) { return 3; }

else { if( not IsNan(Sqrt(-5.0))) { set testResult = 4; }
else { if( not IsNan(Sqrt(NAN()))) { set testResult = 5; }
else { if( not IsInf(Sqrt(INFINITY()))) { set testResult = 6; }
}}}}}
if( not IsNan(Sqrt(-5.0))) { return 4; }
if( not IsNan(Sqrt(NAN()))) { return 5; }
if( not IsInf(Sqrt(INFINITY()))) { return 6; }

return testResult;
return 0;
}
}

Loading

0 comments on commit dc623c1

Please sign in to comment.