improve meta.unroll
This commit is contained in:
parent
22016ad488
commit
5f7b1107d1
1 changed files with 18 additions and 45 deletions
|
|
@ -140,51 +140,19 @@ for_expansion :: (v: *Named_Block, code: Code, _: For_Flags) #expand {
|
|||
}
|
||||
|
||||
for_expansion :: (loop: *Unrolled_Loop, body: Code, flags: For_Flags, loc := #caller_location) #expand {
|
||||
#assert flags & .REVERSE == 0 "reverse iteration not supported with loop unrolling (for now)";
|
||||
#assert flags & .POINTER == 0 "pointer iteration not supported with loop unrolling (for now)";
|
||||
|
||||
// runtime unroll
|
||||
#if loop.N == -1 {
|
||||
for i: 0..loop.array.count - 1 {
|
||||
for #v2 <=(flags & .REVERSE == .REVERSE) i: 0..loop.array.count - 1 {
|
||||
#if flags & .POINTER {
|
||||
`it := *(#no_abc loop.array[i]);
|
||||
}
|
||||
else {
|
||||
`it := #no_abc loop.array[i];
|
||||
}
|
||||
|
||||
`it_index := i;
|
||||
#insert,scope(body) body;
|
||||
}
|
||||
|
||||
// @todo(judah): below doesn't properly handle counts not divisible by 4,
|
||||
// so we end up going over the bounds of the array.
|
||||
|
||||
// UNROLL_AMOUNT :: 4; // @todo(judah): make this configurable?
|
||||
// unrolled_loops := loop.array.count / UNROLL_AMOUNT;
|
||||
// remainder_loops := loop.array.count % UNROLL_AMOUNT;
|
||||
// `it: loop.T;
|
||||
// for i: 0..unrolled_loops #no_abc {
|
||||
// basic.print("I: %\n", i);
|
||||
// index := i * UNROLL_AMOUNT;
|
||||
|
||||
// it_index = index + 0;
|
||||
// it = loop.array[it_index];
|
||||
// #insert,scope(body) body;
|
||||
|
||||
// it_index = index + 1;
|
||||
// it = loop.array[it_index];
|
||||
// #insert,scope(body) body;
|
||||
|
||||
// it_index = index + 2;
|
||||
// it = loop.array[it_index];
|
||||
// #insert,scope(body) body;
|
||||
|
||||
// it_index = index + 3;
|
||||
// it = loop.array[it_index];
|
||||
// #insert,scope(body) body;
|
||||
// }
|
||||
|
||||
// after_big_loop := it_index;
|
||||
// for i: 0..remainder_loops #no_abc {
|
||||
// it_index = after_big_loop + i;
|
||||
// it = loop.array[it_index];
|
||||
// #insert,scope(body) body;
|
||||
// }
|
||||
}
|
||||
// compile-time unroll
|
||||
else {
|
||||
|
|
@ -201,15 +169,20 @@ for_expansion :: (loop: *Unrolled_Loop, body: Code, flags: For_Flags, loc := #ca
|
|||
basic.append(*b, "`it: loop.T = ---;\n");
|
||||
}
|
||||
|
||||
for 0..loop.N - 1 {
|
||||
for #v2 <=(flags & .REVERSE == .REVERSE) 0..loop.N - 1 {
|
||||
basic.append(*b, "{\n");
|
||||
|
||||
if loop.T == void {
|
||||
basic.print_to_builder(*b, "\tit = %;\n", it);
|
||||
}
|
||||
else {
|
||||
#if flags & .POINTER {
|
||||
basic.print_to_builder(*b, "\tit = *(#no_abc loop.array[%]);\n", it);
|
||||
}
|
||||
else {
|
||||
basic.print_to_builder(*b, "\tit = #no_abc loop.array[%];\n", it);
|
||||
}
|
||||
}
|
||||
|
||||
basic.print_to_builder(*b, "\tit_index = %;\n", it);
|
||||
basic.append(*b, "\t#insert,scope(body) body;\n");
|
||||
|
|
@ -221,9 +194,6 @@ for_expansion :: (loop: *Unrolled_Loop, body: Code, flags: For_Flags, loc := #ca
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
#scope_file;
|
||||
|
||||
Default_Name :: "block";
|
||||
Named_Block :: struct(NAME: string) {}
|
||||
|
||||
|
|
@ -242,6 +212,9 @@ Unrolled_Loop :: struct(N: int, T: Type = void) {
|
|||
}
|
||||
}
|
||||
|
||||
|
||||
#scope_file;
|
||||
|
||||
basic :: #import "Basic"; // @future
|
||||
pp :: #import "Program_Print"; // @future
|
||||
compiler :: #import "Compiler"; // @future
|
||||
|
|
|
|||
Loading…
Reference in a new issue