Data update
This commit is contained in:
parent
ed705008a8
commit
0df55f9f24
2196 changed files with 32999 additions and 3075 deletions
|
|
@ -0,0 +1,62 @@
|
|||
.section .text
|
||||
.globl insertion_sort
|
||||
|
||||
// C equivalent at bottom
|
||||
/* void insertion_sort(int *arr, size_t len);
|
||||
* X0: pointer to &a[0]
|
||||
* X1: index of one past the last element of arr
|
||||
* Preconditions:
|
||||
* - Arg 1 (X0) is not a null pointer
|
||||
* - Arg 2 (X1) is not zero
|
||||
*/
|
||||
#define ARR_BEGIN x0
|
||||
#define ARR_END x2
|
||||
#define I x3
|
||||
#define J x4
|
||||
#define OUTER_TMP w6
|
||||
#define INNER_TMP w5
|
||||
insertion_sort:
|
||||
add ARR_END, ARR_BEGIN, x1, LSL #2
|
||||
add I, ARR_BEGIN, #4
|
||||
b 2f
|
||||
// goto test;
|
||||
// do {
|
||||
0:
|
||||
ldr OUTER_TMP, [I] // OUTER_TMP = *I;
|
||||
|
||||
// int INNER_TMP, *J;
|
||||
// for (J = I; J != &arr[0] && (INNER_TMP = J[-1]) > OUTER_TMP; J--)
|
||||
// *J = INNER_TMP;
|
||||
mov J, I
|
||||
b 3f
|
||||
1:
|
||||
// Loop body
|
||||
str INNER_TMP, [J], #-4
|
||||
3:
|
||||
// Loop test
|
||||
cmp J, ARR_BEGIN
|
||||
b.eq 1f
|
||||
ldr INNER_TMP, [J, #-4]
|
||||
cmp INNER_TMP, OUTER_TMP
|
||||
b.gt 1b
|
||||
1:
|
||||
str OUTER_TMP, [J] // *J = OUTER_TMP
|
||||
add I, I, #4
|
||||
// test:; } while (I < &arr[len]);
|
||||
2:
|
||||
cmp I, ARR_END
|
||||
b.lo 0b
|
||||
ret
|
||||
|
||||
/*
|
||||
// First I wrote this C code, then I hand-compiled it to the above assembly.
|
||||
void insertion_sort(int arr[], size_t len) {
|
||||
int x, *pi, *pj;
|
||||
for (pi = &a[1]; pi != &arr[len]; pi++) {
|
||||
x = *pi;
|
||||
for (pj = pi; pj != &a[0] && pj[-1] > x; pj--)
|
||||
*pj = pj[-1];
|
||||
*pj = x;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
|
@ -7,7 +7,7 @@ extension op
|
|||
|
||||
insertionSort(int first, int last)
|
||||
{
|
||||
for(int i := first + 1, i <= last, i += 1)
|
||||
for(int i := first + 1; i <= last; i += 1)
|
||||
{
|
||||
var entry := self[i];
|
||||
int j := i;
|
||||
|
|
|
|||
|
|
@ -0,0 +1,19 @@
|
|||
$ENTRY Go {
|
||||
, 7 6 5 9 8 4 3 1 2 0: e.Arr
|
||||
= <Prout e.Arr>
|
||||
<Prout <Sort e.Arr>>;
|
||||
};
|
||||
|
||||
Sort {
|
||||
(e.S) = e.S;
|
||||
(e.S) s.I e.X = <Sort (<Insert s.I e.S>) e.X>;
|
||||
e.X = <Sort () e.X>;
|
||||
};
|
||||
|
||||
Insert {
|
||||
s.N = s.N;
|
||||
s.N s.M e.X, <Compare s.N s.M>: {
|
||||
'+' = s.M <Insert s.N e.X>;
|
||||
s.C = s.N s.M e.X;
|
||||
};
|
||||
};
|
||||
|
|
@ -10,8 +10,8 @@ var insertionSort = Fn.new { |a|
|
|||
}
|
||||
}
|
||||
|
||||
var as = [ [4, 65, 2, -31, 0, 99, 2, 83, 782, 1], [7, 5, 2, 6, 1, 4, 2, 6, 3] ]
|
||||
for (a in as) {
|
||||
var array = [ [4, 65, 2, -31, 0, 99, 2, 83, 782, 1], [7, 5, 2, 6, 1, 4, 2, 6, 3] ]
|
||||
for (a in array) {
|
||||
System.print("Before: %(a)")
|
||||
insertionSort.call(a)
|
||||
System.print("After : %(a)")
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
import "/sort" for Sort
|
||||
import "./sort" for Sort
|
||||
|
||||
var as = [ [4, 65, 2, -31, 0, 99, 2, 83, 782, 1], [7, 5, 2, 6, 1, 4, 2, 6, 3] ]
|
||||
for (a in as) {
|
||||
var array = [ [4, 65, 2, -31, 0, 99, 2, 83, 782, 1], [7, 5, 2, 6, 1, 4, 2, 6, 3] ]
|
||||
for (a in array) {
|
||||
System.print("Before: %(a)")
|
||||
Sort.insertion(a)
|
||||
System.print("After : %(a)")
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue