aboutsummaryrefslogtreecommitdiff
path: root/tests/programs/cabi_o3.zc
diff options
context:
space:
mode:
Diffstat (limited to 'tests/programs/cabi_o3.zc')
-rw-r--r--tests/programs/cabi_o3.zc30
1 files changed, 30 insertions, 0 deletions
diff --git a/tests/programs/cabi_o3.zc b/tests/programs/cabi_o3.zc
new file mode 100644
index 0000000..5c9a55a
--- /dev/null
+++ b/tests/programs/cabi_o3.zc
@@ -0,0 +1,30 @@
+// native calls from o3 code: lifted into the region as micro-ops, called directly by llvm
+extern double sqrt(double);
+extern double pow(double, double);
+extern double fma(double, double, double);
+extern int snprintf9(word *buf, long cap, str fmt, long a, long b, long c, long d, long e, long f) = "snprintf";
+extern long labs(long);
+
+fn put_f(x) { asm { x @ #1220 } return 0; }
+
+o3 float norm(int n) {
+ float acc = 0.0;
+ for (int i = 1; i <= n; i++) acc = acc + sqrt(i * 1.0) + fma(1.0, 2.0, 0.5);
+ return acc;
+}
+o3 int absum(int n) {
+ int t = 0;
+ for (int i = 0; i < n; i++) t = t + labs(i - 50);
+ return t;
+}
+fn main() {
+ let buf[16];
+ let i = 0;
+ put_f(norm(100)); put_c(32);
+ put_f(pow(2.0, 0.5)); put_c(32);
+ put_n(absum(100)); put_c(10);
+ put_n(snprintf9(buf, 100, b"%ld-%ld-%ld-%ld-%ld-%ld", 1, 2, 3, 4, 5, 6)); put_c(32);
+ while (i < 11) { put_c(ld8(addr_b(buf) + i)); i++; }
+ put_c(10);
+ return 0;
+}