summaryrefslogtreecommitdiff
path: root/test/2024-InvariantNegativeLoop/src/Main.java
diff options
context:
space:
mode:
author anuvarsh <anuvarshini.bc@intel.com> 2019-06-24 17:45:36 +0530
committer Nicolas Geoffray <ngeoffray@google.com> 2019-06-26 08:20:48 +0000
commit41249cd548d60d72b94532b00a261332451fd6f2 (patch)
tree454392f0835f3fdd193a523d5c36f6f8fff30800 /test/2024-InvariantNegativeLoop/src/Main.java
parent5be5260cfec2fc0a8c21ef1a08e7144523a8bfcd (diff)
Tests for Invariant Loops
Test: ./test.py --host Change-Id: I6c2631af2c62a41b1811f646804d395bb0cefa35 Signed-off-by: anuvarsh <anuvarshini.bc@intel.com>
Diffstat (limited to 'test/2024-InvariantNegativeLoop/src/Main.java')
-rw-r--r--test/2024-InvariantNegativeLoop/src/Main.java51
1 files changed, 51 insertions, 0 deletions
diff --git a/test/2024-InvariantNegativeLoop/src/Main.java b/test/2024-InvariantNegativeLoop/src/Main.java
new file mode 100644
index 0000000000..5e729f826f
--- /dev/null
+++ b/test/2024-InvariantNegativeLoop/src/Main.java
@@ -0,0 +1,51 @@
+/*
+ * Copyright (C) 2019 The Android Open Source Project
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+public class Main {
+
+ public static void assertFloatEquals(float expected, float result) {
+ if (expected != result) {
+ throw new Error("Expected: " + expected + ", found: " + result);
+ }
+ }
+
+ public int loop() {
+ float used1 = 1;
+ float used2 = 2;
+ float used3 = 3;
+ float used4 = 4;
+ float invar1 = 15;
+ float invar2 = 25;
+ float invar3 = 35;
+ float invar4 = 45;
+ float i = 0.5f;
+
+ do {
+ used1 = invar1 + invar2;
+ used2 = invar2 - invar3;
+ used3 = invar3 * invar4;
+ used4 = invar1 * invar2 - invar3 + invar4;
+ i += 0.5f;
+ } while (i < 5000.25f);
+ assertFloatEquals(Float.floatToIntBits(used1 + used2 + used3 + used4), 1157152768);
+ return Float.floatToIntBits(used1 + used2 + used3 + used4);
+ }
+
+ public static void main(String[] args) {
+ int res = new Main().loop();
+ }
+}