Skip to content

Commit e212104

Browse files
committed
20% speedup from earlier, closer to original. maybe can make more improvements to start getting real gains on new TTI system
1 parent ccfdb2a commit e212104

12 files changed

Lines changed: 4745 additions & 4598 deletions

BOOTSTRAP/cli.c

Lines changed: 4631 additions & 4566 deletions
Large diffs are not rendered by default.

BOOTSTRAP/monolithic.lsts

Lines changed: 57 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@ let :Blob current_allocated_memory(): U64 = (
142142
let .into(b: Bool, tt: Type<String>): String = if b then "true" else "false";
143143
let .into(i: U8, tt: Type<String>): String = (i as U64).into(type(String));
144144
let .into(i: USize, tt: Type<String>): String = (i as U64).into(type(String));
145+
let .into(i: U32, tt: Type<String>): String = (i as U64).into(type(String));
145146

146147
let .into(i: I64, tt: Type<String>): String = (
147148
let od = mk-owned-data(type(U8), 20_sz);
@@ -196,6 +197,8 @@ let .into(i: U64, tt: Type<String>): String = (
196197
String(0 as USize, cs-length, od)
197198
);
198199

200+
let .to-hex(i: U32): String = (i as U64).to-hex;
201+
199202
let .to-hex(i: U64): String = (
200203
let buff = mk-vector(type(U8), 17);
201204
let rpt = 16_u64;
@@ -2496,7 +2499,45 @@ let .into(l: Tuple<w,x,y,z>, tt: Type<String>): String = (
24962499

24972500
type alias U16 suffix _u16 = U64;
24982501

2499-
type alias U32 suffix _u32 = U64;
2502+
type opaque alias U32 suffix _u32 = C<"uint32_t">;
2503+
2504+
declare-binop( $"!=", raw-type(U32), raw-type(U32), raw-type(Bool), ( l"("; x; l"!="; y; l")"; ) );
2505+
declare-binop( $"==", raw-type(U32), raw-type(U32), raw-type(Bool), ( l"("; x; l"=="; y; l")"; ) );
2506+
declare-binop( $"<", raw-type(U32), raw-type(U32), raw-type(Bool), ( l"("; x; l"<"; y; l")"; ) );
2507+
declare-binop( $"<=", raw-type(U32), raw-type(U32), raw-type(Bool), ( l"("; x; l"<="; y; l")"; ) );
2508+
declare-binop( $">", raw-type(U32), raw-type(U32), raw-type(Bool), ( l"("; x; l">"; y; l")"; ) );
2509+
declare-binop( $">=", raw-type(U32), raw-type(U32), raw-type(Bool), ( l"("; x; l">="; y; l")"; ) );
2510+
2511+
declare-binop( $"&", raw-type(U32), raw-type(U32), raw-type(U32), ( l"("; x; l"&"; y; l")"; ) );
2512+
declare-binop( $"|", raw-type(U32), raw-type(U32), raw-type(U32), ( l"("; x; l"|"; y; l")"; ) );
2513+
declare-binop( $"^", raw-type(U32), raw-type(U32), raw-type(U32), ( l"("; x; l"^"; y; l")"; ) );
2514+
declare-binop( $"+", raw-type(U32), raw-type(U32), raw-type(U32), ( l"("; x; l"+"; y; l")"; ) );
2515+
declare-binop( $"-", raw-type(U32), raw-type(U32), raw-type(U32), ( l"("; x; l"-"; y; l")"; ) );
2516+
declare-binop( $"/", raw-type(U32), raw-type(U32), raw-type(U32), ( l"("; x; l"/"; y; l")"; ) );
2517+
declare-binop( $"%", raw-type(U32), raw-type(U32), raw-type(U32), ( l"("; x; l"%"; y; l")"; ) );
2518+
declare-binop( $"*", raw-type(U32), raw-type(U32), raw-type(U32), ( l"("; x; l"*"; y; l")"; ) );
2519+
2520+
declare-binop( $"<<", raw-type(U32), raw-type(U32), raw-type(U32), ( l"("; x; l"<<"; y; l")"; ) );
2521+
declare-binop( $">>", raw-type(U32), raw-type(U32), raw-type(U32), ( l"("; x; l">>"; y; l")"; ) );
2522+
2523+
declare-unop( $"~", raw-type(U32), raw-type(U32), ( l"((uint32_t)(~"; x; l"))"; ) );
2524+
2525+
let non-zero(x: U32): Bool = x != 0;
2526+
2527+
let min(l: U32, r: U32): U32 = (
2528+
if l < r then l else r
2529+
);
2530+
let max(l: U32, r: U32): U32 = (
2531+
if l > r then l else r
2532+
);
2533+
2534+
let cmp(l: U32, r: U32): Ord = (
2535+
if l < r then LessThan
2536+
else if l > r then GreaterThan
2537+
else Equal
2538+
);
2539+
2540+
let hash(x: U32): U64 = x as U64;
25002541

25012542
type opaque alias U64 suffix _u64 = C<"uint64_t">;
25022543

@@ -2561,7 +2602,7 @@ let to-u64(s: CString): U64 = (
25612602
);
25622603

25632604
type opaque alias U8 suffix _u8
2564-
implies C<"int">, USize, U64, I64, C<"size_t">
2605+
implies C<"int">, USize, U32, U64, I64, C<"size_t">
25652606
= C<"uint8_t">;
25662607

25672608
declare-binop( $"!=", raw-type(U8), raw-type(U8), raw-type(Bool), ( l"("; x; l"!="; y; l")"; ) );
@@ -2603,7 +2644,7 @@ let hash(x: U8): U64 = x as U64;
26032644
let non-zero(x: U8): Bool = x != 0;
26042645

26052646
type opaque alias USize suffix _sz
2606-
implies U64, C<"size_t">
2647+
implies U32, U64, C<"size_t">
26072648
= C<"size_t">;
26082649

26092650
declare-binop( $"!=", raw-type(USize), raw-type(USize), raw-type(Bool), ( l"("; x; l"!="; y; l")"; ) );
@@ -6446,7 +6487,7 @@ let .ground-tag-and-arity(tt: Type): (U32,U32) = (
64466487
TGround { tag:interned-tag-array, parameters:[_.. TAny{}..] } => (interned-tag-array.primary, 2_u32);
64476488
TGround { tag:interned-tag-array, parameters:[_.. array-base..] } => (
64486489
let ga = array-base.ground-tag-and-arity;
6449-
( ga.first, ga.second + 1000 )
6490+
( ga.first, ga.second + 1000_u32 )
64506491
);
64516492
TGround { tag:interned-tag-sized, parameters:[_..] } => (0_u32, 9999999_u32);
64526493
TGround { tag=tag, parameters=parameters } => (tag.primary, parameters.length as U32);
@@ -6487,7 +6528,7 @@ let hash(tt: Type): U64 = (
64876528
result
64886529
);
64896530
TGround{tag=tag,parameters=parameters} => hash(tag) + hash(parameters);
6490-
TId{id=id} => id;
6531+
TId{id=id} => id as U64;
64916532
}
64926533
);
64936534

@@ -6544,7 +6585,7 @@ let intern-type-tag-single(tag: CString): U32 = (
65446585
}
65456586
);
65466587

6547-
let hash(t: TypeTagIntern): U32 = (
6588+
let hash(t: TypeTagIntern): U64 = (
65486589
if t.second != 0
65496590
then hash(t.second)
65506591
else hash(t.first)
@@ -6903,7 +6944,7 @@ let .simple-tag(tt: Type): CString = (
69036944
let .simple-interned-tag(tt: Type): TypeTagIntern = (
69046945
match tt {
69056946
TGround { tag=tag } => tag;
6906-
_ => TypeTagIntern(0,0);
6947+
_ => TypeTagIntern(0_u32,0_u32);
69076948
}
69086949
);
69096950

@@ -11708,15 +11749,15 @@ let std-c-decorate-pointer(tt: Type, ptr: CTerm): Type = (
1170811749
let std-c-type-of-integer(i: String): Type = (
1170911750
if i.has-prefix("-") {
1171011751
let n = to-u64(tail(i).into(type(CString)));
11711-
if n <= 128 then type-c-uint8 else
11712-
if n <= 32768 then type-c-uint16 else
11713-
if n <= 2147483648 then type-c-uint32 else
11752+
if n <= 128_u64 then type-c-uint8 else
11753+
if n <= 32768_u64 then type-c-uint16 else
11754+
if n <= 2147483648_u64 then type-c-uint32 else
1171411755
type-c-uint64
1171511756
} else {
1171611757
let n = to-u64(i.into(type(CString)));
11717-
if n <= 255 then type-c-int8 else
11718-
if n <= 65535 then type-c-int16 else
11719-
if n <= 4294967295 then type-c-int32 else
11758+
if n <= 255_u64 then type-c-int8 else
11759+
if n <= 65535_u64 then type-c-int16 else
11760+
if n <= 4294967295_u64 then type-c-int32 else
1172011761
type-c-int64
1172111762
};
1172211763
);
@@ -15477,9 +15518,9 @@ let mk-lsts-token(s: String): Token = (
1547715518
ds = tail(ds);
1547815519
};
1547915520
let magnitude = to-u64(ds);
15480-
if (is-negative and magnitude <= 128) or magnitude <= 255 then order = 8
15481-
else if (is-negative and magnitude <= 32768) or magnitude <= 65535 then order = 16
15482-
else if (is-negative and magnitude <= 2147483648) or magnitude <= 4294967295 then order = 32;
15521+
if (is-negative and magnitude <= 128_u64) or magnitude <= 255 then order = 8
15522+
else if (is-negative and magnitude <= 32768_u64) or magnitude <= 65535_u64 then order = 16
15523+
else if (is-negative and magnitude <= 2147483648_u64) or magnitude <= 4294967295_u64 then order = 32;
1548315524
};
1548415525
match (is-negative as U64, order) {
1548515526
Tuple{ first:0_u64, second:8_u64 } => us = us + c"_u8";

PLUGINS/FRONTEND/C/c-ast-to-lm-ast.lsts

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -614,15 +614,15 @@ let std-c-decorate-pointer(tt: Type, ptr: CTerm): Type = (
614614
let std-c-type-of-integer(i: String): Type = (
615615
if i.has-prefix("-") {
616616
let n = to-u64(tail(i).into(type(CString)));
617-
if n <= 128 then type-c-uint8 else
618-
if n <= 32768 then type-c-uint16 else
619-
if n <= 2147483648 then type-c-uint32 else
617+
if n <= 128_u64 then type-c-uint8 else
618+
if n <= 32768_u64 then type-c-uint16 else
619+
if n <= 2147483648_u64 then type-c-uint32 else
620620
type-c-uint64
621621
} else {
622622
let n = to-u64(i.into(type(CString)));
623-
if n <= 255 then type-c-int8 else
624-
if n <= 65535 then type-c-int16 else
625-
if n <= 4294967295 then type-c-int32 else
623+
if n <= 255_u64 then type-c-int8 else
624+
if n <= 65535_u64 then type-c-int16 else
625+
if n <= 4294967295_u64 then type-c-int32 else
626626
type-c-int64
627627
};
628628
);

PLUGINS/FRONTEND/LSTS/mk-lsts-token.lsts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,9 @@ let mk-lsts-token(s: String): Token = (
1212
ds = tail(ds);
1313
};
1414
let magnitude = to-u64(ds);
15-
if (is-negative and magnitude <= 128) or magnitude <= 255 then order = 8
16-
else if (is-negative and magnitude <= 32768) or magnitude <= 65535 then order = 16
17-
else if (is-negative and magnitude <= 2147483648) or magnitude <= 4294967295 then order = 32;
15+
if (is-negative and magnitude <= 128_u64) or magnitude <= 255 then order = 8
16+
else if (is-negative and magnitude <= 32768_u64) or magnitude <= 65535_u64 then order = 16
17+
else if (is-negative and magnitude <= 2147483648_u64) or magnitude <= 4294967295_u64 then order = 32;
1818
};
1919
match (is-negative as U64, order) {
2020
Tuple{ first:0_u64, second:8_u64 } => us = us + c"_u8";

SRC/type-ground-tag-and-arity.lsts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ let .ground-tag-and-arity(tt: Type): (U32,U32) = (
44
TGround { tag:interned-tag-array, parameters:[_.. TAny{}..] } => (interned-tag-array.primary, 2_u32);
55
TGround { tag:interned-tag-array, parameters:[_.. array-base..] } => (
66
let ga = array-base.ground-tag-and-arity;
7-
( ga.first, ga.second + 1000 )
7+
( ga.first, ga.second + 1000_u32 )
88
);
99
TGround { tag:interned-tag-sized, parameters:[_..] } => (0_u32, 9999999_u32);
1010
TGround { tag=tag, parameters=parameters } => (tag.primary, parameters.length as U32);

SRC/type-hash.lsts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ let hash(tt: Type): U64 = (
99
result
1010
);
1111
TGround{tag=tag,parameters=parameters} => hash(tag) + hash(parameters);
12-
TId{id=id} => id;
12+
TId{id=id} => id as U64;
1313
}
1414
);

SRC/type-intern-type-tag.lsts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ let intern-type-tag-single(tag: CString): U32 = (
5252
}
5353
);
5454

55-
let hash(t: TypeTagIntern): U32 = (
55+
let hash(t: TypeTagIntern): U64 = (
5656
if t.second != 0
5757
then hash(t.second)
5858
else hash(t.first)

SRC/type-simple-tag.lsts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ let .simple-tag(tt: Type): CString = (
99
let .simple-interned-tag(tt: Type): TypeTagIntern = (
1010
match tt {
1111
TGround { tag=tag } => tag;
12-
_ => TypeTagIntern(0,0);
12+
_ => TypeTagIntern(0_u32,0_u32);
1313
}
1414
);

lib/core/baremetal-into.lsts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
let .into(b: Bool, tt: Type<String>): String = if b then "true" else "false";
33
let .into(i: U8, tt: Type<String>): String = (i as U64).into(type(String));
44
let .into(i: USize, tt: Type<String>): String = (i as U64).into(type(String));
5+
let .into(i: U32, tt: Type<String>): String = (i as U64).into(type(String));
56

67
let .into(i: I64, tt: Type<String>): String = (
78
let od = mk-owned-data(type(U8), 20_sz);
@@ -56,6 +57,8 @@ let .into(i: U64, tt: Type<String>): String = (
5657
String(0 as USize, cs-length, od)
5758
);
5859

60+
let .to-hex(i: U32): String = (i as U64).to-hex;
61+
5962
let .to-hex(i: U64): String = (
6063
let buff = mk-vector(type(U8), 17);
6164
let rpt = 16_u64;

lib/core/u32.lsts

Lines changed: 39 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,40 @@
11

2-
type alias U32 suffix _u32 = U64;
2+
type opaque alias U32 suffix _u32 = C<"uint32_t">;
3+
4+
declare-binop( $"!=", raw-type(U32), raw-type(U32), raw-type(Bool), ( l"("; x; l"!="; y; l")"; ) );
5+
declare-binop( $"==", raw-type(U32), raw-type(U32), raw-type(Bool), ( l"("; x; l"=="; y; l")"; ) );
6+
declare-binop( $"<", raw-type(U32), raw-type(U32), raw-type(Bool), ( l"("; x; l"<"; y; l")"; ) );
7+
declare-binop( $"<=", raw-type(U32), raw-type(U32), raw-type(Bool), ( l"("; x; l"<="; y; l")"; ) );
8+
declare-binop( $">", raw-type(U32), raw-type(U32), raw-type(Bool), ( l"("; x; l">"; y; l")"; ) );
9+
declare-binop( $">=", raw-type(U32), raw-type(U32), raw-type(Bool), ( l"("; x; l">="; y; l")"; ) );
10+
11+
declare-binop( $"&", raw-type(U32), raw-type(U32), raw-type(U32), ( l"("; x; l"&"; y; l")"; ) );
12+
declare-binop( $"|", raw-type(U32), raw-type(U32), raw-type(U32), ( l"("; x; l"|"; y; l")"; ) );
13+
declare-binop( $"^", raw-type(U32), raw-type(U32), raw-type(U32), ( l"("; x; l"^"; y; l")"; ) );
14+
declare-binop( $"+", raw-type(U32), raw-type(U32), raw-type(U32), ( l"("; x; l"+"; y; l")"; ) );
15+
declare-binop( $"-", raw-type(U32), raw-type(U32), raw-type(U32), ( l"("; x; l"-"; y; l")"; ) );
16+
declare-binop( $"/", raw-type(U32), raw-type(U32), raw-type(U32), ( l"("; x; l"/"; y; l")"; ) );
17+
declare-binop( $"%", raw-type(U32), raw-type(U32), raw-type(U32), ( l"("; x; l"%"; y; l")"; ) );
18+
declare-binop( $"*", raw-type(U32), raw-type(U32), raw-type(U32), ( l"("; x; l"*"; y; l")"; ) );
19+
20+
declare-binop( $"<<", raw-type(U32), raw-type(U32), raw-type(U32), ( l"("; x; l"<<"; y; l")"; ) );
21+
declare-binop( $">>", raw-type(U32), raw-type(U32), raw-type(U32), ( l"("; x; l">>"; y; l")"; ) );
22+
23+
declare-unop( $"~", raw-type(U32), raw-type(U32), ( l"((uint32_t)(~"; x; l"))"; ) );
24+
25+
let non-zero(x: U32): Bool = x != 0;
26+
27+
let min(l: U32, r: U32): U32 = (
28+
if l < r then l else r
29+
);
30+
let max(l: U32, r: U32): U32 = (
31+
if l > r then l else r
32+
);
33+
34+
let cmp(l: U32, r: U32): Ord = (
35+
if l < r then LessThan
36+
else if l > r then GreaterThan
37+
else Equal
38+
);
39+
40+
let hash(x: U32): U64 = x as U64;

0 commit comments

Comments
 (0)