Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

experiment: tag compact Int and Nat (as Int) #4345

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
267 changes: 180 additions & 87 deletions src/codegen/compile.ml

Large diffs are not rendered by default.

8 changes: 4 additions & 4 deletions src/mo_values/prim.ml
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ let prim trap =
| "fexp" -> fun _ v k -> k (via_float Stdlib.exp v)
| "flog" -> fun _ v k -> k (via_float Stdlib.log v)
(* TODO: refine exotic cases below to catch more errors *)
| "popcntInt8" | "popcntInt16"
| "popcntInt8" | "popcntInt16" | "popcntInt32" | "popcntInt64"
| "popcnt8" | "popcnt16" | "popcnt32" | "popcnt64" ->
fun _ v k ->
k (match v with
Expand All @@ -160,7 +160,7 @@ let prim trap =
| Int32 w -> Int32 (Int_32.popcnt w)
| Int64 w -> Int64 (Int_64.popcnt w)
| _ -> failwith "popcnt")
| "clzInt8" | "clzInt16"
| "clzInt8" | "clzInt16" | "clzInt32" | "clzInt64"
| "clz8" | "clz16" | "clz32" | "clz64" ->
fun _ v k ->
k (match v with
Expand All @@ -173,7 +173,7 @@ let prim trap =
| Int32 w -> Int32 (Int_32.clz w)
| Int64 w -> Int64 (Int_64.clz w)
| _ -> failwith "clz")
| "ctzInt8" | "ctzInt16"
| "ctzInt8" | "ctzInt16" | "ctzInt32" | "ctzInt64"
| "ctz8" | "ctz16" | "ctz32" | "ctz64" ->
fun _ v k ->
k (match v with
Expand All @@ -186,7 +186,7 @@ let prim trap =
| Int32 w -> Int32 (Int_32.ctz w)
| Int64 w -> Int64 (Int_64.ctz w)
| _ -> failwith "ctz")
| "btstInt8" | "btstInt16"
| "btstInt8" | "btstInt16" | "btstInt32" | "btstInt64"
| "btst8" | "btst16" | "btst32" | "btst64" ->
fun _ v k ->
let w, a = as_pair v
Expand Down
2 changes: 1 addition & 1 deletion src/prelude/internals.mo
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ func @digits_dec(x : Nat) : Text =
(prim "conv_Char_Text" : Char -> Text) (
(prim "num_conv_Nat32_Char" : Nat32 -> Char) (
(prim "num_wrap_Int_Nat32" : Int -> Nat32) (
x + 0x30
x + 0x30
)
)
);
Expand Down
14 changes: 7 additions & 7 deletions src/prelude/prim.mo
Original file line number Diff line number Diff line change
Expand Up @@ -217,15 +217,15 @@ func clzInt16(w : Int16) : Int16 = (prim "clzInt16" : Int16 -> Int16) w;
func ctzInt16(w : Int16) : Int16 = (prim "ctzInt16" : Int16 -> Int16) w;
func btstInt16(w : Int16, amount : Int16) : Bool = (prim "btstInt16" : (Int16, Int16) -> Int16) (w, amount) != (0 : Int16);

func popcntInt32(w : Int32) : Int32 = (prim "popcnt32" : Int32 -> Int32) w;
func clzInt32(w : Int32) : Int32 = (prim "clz32" : Int32 -> Int32) w;
func ctzInt32(w : Int32) : Int32 = (prim "ctz32" : Int32 -> Int32) w;
func popcntInt32(w : Int32) : Int32 = (prim "popcntInt32" : Int32 -> Int32) w;
func clzInt32(w : Int32) : Int32 = (prim "clzInt32" : Int32 -> Int32) w;
func ctzInt32(w : Int32) : Int32 = (prim "ctzInt32" : Int32 -> Int32) w;
func btstInt32(w : Int32, amount : Int32) : Bool = (prim "btst32" : (Int32, Int32) -> Int32)(w, amount) != (0 : Int32);

func popcntInt64(w : Int64) : Int64 = (prim "popcnt64" : Int64 -> Int64) w;
func clzInt64(w : Int64) : Int64 = (prim "clz64" : Int64 -> Int64) w;
func ctzInt64(w : Int64) : Int64 = (prim "ctz64" : Int64 -> Int64) w;
func btstInt64(w : Int64, amount : Int64) : Bool = (prim "btst64" : (Int64, Int64) -> Int64)(w, amount) != (0 : Int64);
func popcntInt64(w : Int64) : Int64 = (prim "popcntInt64" : Int64 -> Int64) w;
func clzInt64(w : Int64) : Int64 = (prim "clzInt64" : Int64 -> Int64) w;
func ctzInt64(w : Int64) : Int64 = (prim "ctzInt64" : Int64 -> Int64) w;
func btstInt64(w : Int64, amount : Int64) : Bool = (prim "btstInt64" : (Int64, Int64) -> Int64)(w, amount) != (0 : Int64);

// Float operations

Expand Down
6 changes: 3 additions & 3 deletions test/bench/ok/alloc.drun-run-opt.ok
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
ingress Completed: Reply: 0x4449444c016c01b3c4b1f204680100010a00000000000000000101
ingress Completed: Reply: 0x4449444c0000
debug.print: (+268_435_456, 2_349_044_373)
debug.print: (+268_435_456, 2_718_143_143)
ingress Err: IC0503: Canister rwlgt-iiaaa-aaaaa-aaaaa-cai trapped explicitly: assertion failed at alloc.mo:19.9-19.21
debug.print: (+268_435_456, 2_349_044_373)
debug.print: (+268_435_456, 2_718_143_143)
ingress Err: IC0503: Canister rwlgt-iiaaa-aaaaa-aaaaa-cai trapped explicitly: assertion failed at alloc.mo:19.9-19.21
debug.print: (+268_435_456, 2_349_044_373)
debug.print: (+268_435_456, 2_718_143_143)
ingress Err: IC0503: Canister rwlgt-iiaaa-aaaaa-aaaaa-cai trapped explicitly: assertion failed at alloc.mo:19.9-19.21
6 changes: 3 additions & 3 deletions test/bench/ok/alloc.drun-run.ok
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
ingress Completed: Reply: 0x4449444c016c01b3c4b1f204680100010a00000000000000000101
ingress Completed: Reply: 0x4449444c0000
debug.print: (+268_435_456, 2_433_000_122)
debug.print: (+268_435_456, 2_802_098_892)
ingress Err: IC0503: Canister rwlgt-iiaaa-aaaaa-aaaaa-cai trapped explicitly: assertion failed at alloc.mo:19.9-19.21
debug.print: (+268_435_456, 2_433_000_122)
debug.print: (+268_435_456, 2_802_098_892)
ingress Err: IC0503: Canister rwlgt-iiaaa-aaaaa-aaaaa-cai trapped explicitly: assertion failed at alloc.mo:19.9-19.21
debug.print: (+268_435_456, 2_433_000_122)
debug.print: (+268_435_456, 2_802_098_892)
ingress Err: IC0503: Canister rwlgt-iiaaa-aaaaa-aaaaa-cai trapped explicitly: assertion failed at alloc.mo:19.9-19.21
4 changes: 2 additions & 2 deletions test/bench/ok/bignum.drun-run-opt.ok
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ingress Completed: Reply: 0x4449444c016c01b3c4b1f204680100010a00000000000000000101
ingress Completed: Reply: 0x4449444c0000
debug.print: {cycles = 2_390_231; size = +59_688}
debug.print: {cycles = 2_390_411; size = +59_688}
ingress Completed: Reply: 0x4449444c0000
debug.print: {cycles = 102_991_811; size = +1_818_012}
debug.print: {cycles = 102_991_841; size = +1_818_012}
ingress Completed: Reply: 0x4449444c0000
4 changes: 2 additions & 2 deletions test/bench/ok/bignum.drun-run.ok
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
ingress Completed: Reply: 0x4449444c016c01b3c4b1f204680100010a00000000000000000101
ingress Completed: Reply: 0x4449444c0000
debug.print: {cycles = 2_494_446; size = +59_688}
debug.print: {cycles = 2_494_626; size = +59_688}
ingress Completed: Reply: 0x4449444c0000
debug.print: {cycles = 103_048_901; size = +1_818_012}
debug.print: {cycles = 103_048_931; size = +1_818_012}
ingress Completed: Reply: 0x4449444c0000
4 changes: 2 additions & 2 deletions test/bench/ok/heap-32.drun-run-opt.ok
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ingress Completed: Reply: 0x4449444c016c01b3c4b1f204680100010a00000000000000000101
ingress Completed: Reply: 0x4449444c0000
debug.print: (50_227, +34_710_184, 689_534_550)
debug.print: (50_070, +35_388_084, 705_963_069)
debug.print: (50_227, +34_710_184, 690_543_208)
debug.print: (50_070, +35_388_084, 706_920_801)
ingress Completed: Reply: 0x4449444c0000
4 changes: 2 additions & 2 deletions test/bench/ok/heap-32.drun-run.ok
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
ingress Completed: Reply: 0x4449444c016c01b3c4b1f204680100010a00000000000000000101
ingress Completed: Reply: 0x4449444c0000
debug.print: (50_227, +34_710_184, 739_371_884)
debug.print: (50_070, +35_388_084, 756_464_613)
debug.print: (50_227, +34_710_184, 740_380_542)
debug.print: (50_070, +35_388_084, 757_422_345)
ingress Completed: Reply: 0x4449444c0000
2 changes: 1 addition & 1 deletion test/bench/ok/nat16.drun-run-opt.ok
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ingress Completed: Reply: 0x4449444c016c01b3c4b1f204680100010a00000000000000000101
ingress Completed: Reply: 0x4449444c0000
debug.print: (0, 23_069_397)
debug.print: (0, 23_069_565)
ingress Completed: Reply: 0x4449444c0000
2 changes: 1 addition & 1 deletion test/bench/ok/nat16.drun-run.ok
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ingress Completed: Reply: 0x4449444c016c01b3c4b1f204680100010a00000000000000000101
ingress Completed: Reply: 0x4449444c0000
debug.print: (0, 89_128_867)
debug.print: (0, 89_129_035)
ingress Completed: Reply: 0x4449444c0000
12 changes: 6 additions & 6 deletions test/bench/ok/palindrome.drun-run-opt.ok
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
ingress Completed: Reply: 0x4449444c016c01b3c4b1f204680100010a00000000000000000101
ingress Completed: Reply: 0x4449444c0000
debug.print: (true, +1_188, 10_666)
debug.print: (false, +1_188, 10_012)
debug.print: (false, +1_188, 10_657)
debug.print: (true, +868, 11_009)
debug.print: (false, +868, 9_943)
debug.print: (false, +868, 10_978)
debug.print: (true, +1_188, 10_670)
debug.print: (false, +1_188, 10_016)
debug.print: (false, +1_188, 10_661)
debug.print: (true, +868, 11_013)
debug.print: (false, +868, 9_947)
debug.print: (false, +868, 10_982)
ingress Completed: Reply: 0x4449444c0000
12 changes: 6 additions & 6 deletions test/bench/ok/palindrome.drun-run.ok
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
ingress Completed: Reply: 0x4449444c016c01b3c4b1f204680100010a00000000000000000101
ingress Completed: Reply: 0x4449444c0000
debug.print: (true, +1_188, 11_699)
debug.print: (false, +1_188, 10_999)
debug.print: (false, +1_188, 11_689)
debug.print: (true, +868, 11_661)
debug.print: (false, +868, 10_559)
debug.print: (false, +868, 11_624)
debug.print: (true, +1_188, 11_703)
debug.print: (false, +1_188, 11_003)
debug.print: (false, +1_188, 11_693)
debug.print: (true, +868, 11_665)
debug.print: (false, +868, 10_563)
debug.print: (false, +868, 11_628)
ingress Completed: Reply: 0x4449444c0000
2 changes: 1 addition & 1 deletion test/bench/ok/region-mem.drun-run-opt.ok
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ingress Completed: Reply: 0x4449444c016c01b3c4b1f204680100010a00000000000000000101
ingress Completed: Reply: 0x4449444c0000
debug.print: {heap_diff = 0; instr_diff = 5_259_657_498}
debug.print: {heap_diff = 0; instr_diff = 5_259_657_502}
ingress Completed: Reply: 0x4449444c0000
2 changes: 1 addition & 1 deletion test/bench/ok/region-mem.drun-run.ok
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ingress Completed: Reply: 0x4449444c016c01b3c4b1f204680100010a00000000000000000101
ingress Completed: Reply: 0x4449444c0000
debug.print: {heap_diff = 0; instr_diff = 5_674_893_611}
debug.print: {heap_diff = 0; instr_diff = 5_674_893_615}
ingress Completed: Reply: 0x4449444c0000
2 changes: 1 addition & 1 deletion test/bench/ok/region0-mem.drun-run-opt.ok
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ingress Completed: Reply: 0x4449444c016c01b3c4b1f204680100010a00000000000000000101
ingress Completed: Reply: 0x4449444c0000
debug.print: {heap_diff = 0; instr_diff = 5_398_069_530}
debug.print: {heap_diff = 0; instr_diff = 5_398_069_534}
ingress Completed: Reply: 0x4449444c0000
2 changes: 1 addition & 1 deletion test/bench/ok/region0-mem.drun-run.ok
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ingress Completed: Reply: 0x4449444c016c01b3c4b1f204680100010a00000000000000000101
ingress Completed: Reply: 0x4449444c0000
debug.print: {heap_diff = 0; instr_diff = 5_926_551_851}
debug.print: {heap_diff = 0; instr_diff = 5_926_551_855}
ingress Completed: Reply: 0x4449444c0000
2 changes: 1 addition & 1 deletion test/bench/ok/stable-mem.drun-run-opt.ok
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ingress Completed: Reply: 0x4449444c016c01b3c4b1f204680100010a00000000000000000101
ingress Completed: Reply: 0x4449444c0000
debug.print: {heap_diff = 0; instr_diff = 2_818_572_570}
debug.print: {heap_diff = 0; instr_diff = 2_818_572_574}
ingress Completed: Reply: 0x4449444c0000
2 changes: 1 addition & 1 deletion test/bench/ok/stable-mem.drun-run.ok
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
ingress Completed: Reply: 0x4449444c016c01b3c4b1f204680100010a00000000000000000101
ingress Completed: Reply: 0x4449444c0000
debug.print: {heap_diff = 0; instr_diff = 3_284_140_331}
debug.print: {heap_diff = 0; instr_diff = 3_284_140_335}
ingress Completed: Reply: 0x4449444c0000
1 change: 0 additions & 1 deletion test/run-drun/ok/perf.drun-run.ok
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
ingress Completed: Reply: 0x4449444c016c01b3c4b1f204680100010a00000000000000000101
ingress Completed: Reply: 0x4449444c0000
debug.print: 50_218
ingress Completed: Reply: 0x4449444c0000
2 changes: 1 addition & 1 deletion test/run-drun/perf.mo
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ actor {
n-=1;
};
let c2 = Prim.performanceCounter(0);
Prim.debugPrint(debug_show(c2 - c1));
// Prim.debugPrint(debug_show(c2 - c1)); // too noisy for --sanity-checks
assert (c2 >= c1);
}
}
Expand Down
Loading