add testcases from year 2022
This commit is contained in:
parent
26de003feb
commit
8324561db1
67
testcases/final_performance/00_bitset1.sy
Executable file
67
testcases/final_performance/00_bitset1.sy
Executable file
@ -0,0 +1,67 @@
|
||||
int set(int a[], int pos, int d){
|
||||
const int bitcount = 30;
|
||||
int x[bitcount + 1] = {};
|
||||
|
||||
x[0] = 1;
|
||||
x[1] = x[0] * 2;
|
||||
x[2] = x[1] * 2;
|
||||
x[3] = x[2] * 2;
|
||||
x[4] = x[3] * 2;
|
||||
x[5] = x[4] * 2;
|
||||
x[6] = x[5] * 2;
|
||||
x[7] = x[6] * 2;
|
||||
x[8] = x[7] * 2;
|
||||
x[9] = x[8] * 2;
|
||||
x[10] = x[9] * 2;
|
||||
|
||||
int i = 10;
|
||||
while (i < bitcount){
|
||||
i = i + 1;
|
||||
x[i] = x[i - 1] * 2;
|
||||
}
|
||||
|
||||
int v = 0;
|
||||
|
||||
if (pos / bitcount >= 10000) return 0;
|
||||
|
||||
if (a[pos / bitcount] / (x[pos % bitcount]) % 2 != d){
|
||||
if (a[pos / bitcount] / (x[pos % bitcount]) % 2 == 0)
|
||||
if (d == 1)
|
||||
v = x[pos % bitcount];
|
||||
|
||||
if (a[pos / bitcount] / x[pos % bitcount] % 2 == 1)
|
||||
if (d == 0)
|
||||
v = v - x[pos % bitcount];
|
||||
}
|
||||
|
||||
a[pos / bitcount] = a[pos / bitcount] + v;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int seed[3] = {19971231, 19981013, 1000000000 + 7};
|
||||
int staticvalue = 0;
|
||||
|
||||
int rand(){
|
||||
staticvalue = staticvalue * seed[0] + seed[1];
|
||||
staticvalue = staticvalue % seed[2];
|
||||
if (staticvalue < 0) staticvalue = seed[2] + staticvalue;
|
||||
return staticvalue;
|
||||
}
|
||||
|
||||
int a[10000] = {};
|
||||
int main(){
|
||||
|
||||
int n = getint();
|
||||
staticvalue = getint();
|
||||
starttime();
|
||||
int x, y;
|
||||
while (n > 0){
|
||||
n = n - 1;
|
||||
x = rand() % 300000;
|
||||
y = rand() % 2;
|
||||
set(a, x, y);
|
||||
}
|
||||
stoptime();
|
||||
putarray(10000, a);
|
||||
return 0;
|
||||
}
|
||||
67
testcases/final_performance/00_bitset2.sy
Executable file
67
testcases/final_performance/00_bitset2.sy
Executable file
@ -0,0 +1,67 @@
|
||||
int set(int a[], int pos, int d){
|
||||
const int bitcount = 30;
|
||||
int x[bitcount + 1] = {};
|
||||
|
||||
x[0] = 1;
|
||||
x[1] = x[0] * 2;
|
||||
x[2] = x[1] * 2;
|
||||
x[3] = x[2] * 2;
|
||||
x[4] = x[3] * 2;
|
||||
x[5] = x[4] * 2;
|
||||
x[6] = x[5] * 2;
|
||||
x[7] = x[6] * 2;
|
||||
x[8] = x[7] * 2;
|
||||
x[9] = x[8] * 2;
|
||||
x[10] = x[9] * 2;
|
||||
|
||||
int i = 10;
|
||||
while (i < bitcount){
|
||||
i = i + 1;
|
||||
x[i] = x[i - 1] * 2;
|
||||
}
|
||||
|
||||
int v = 0;
|
||||
|
||||
if (pos / bitcount >= 10000) return 0;
|
||||
|
||||
if (a[pos / bitcount] / (x[pos % bitcount]) % 2 != d){
|
||||
if (a[pos / bitcount] / (x[pos % bitcount]) % 2 == 0)
|
||||
if (d == 1)
|
||||
v = x[pos % bitcount];
|
||||
|
||||
if (a[pos / bitcount] / x[pos % bitcount] % 2 == 1)
|
||||
if (d == 0)
|
||||
v = v - x[pos % bitcount];
|
||||
}
|
||||
|
||||
a[pos / bitcount] = a[pos / bitcount] + v;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int seed[3] = {19971231, 19981013, 1000000000 + 7};
|
||||
int staticvalue = 0;
|
||||
|
||||
int rand(){
|
||||
staticvalue = staticvalue * seed[0] + seed[1];
|
||||
staticvalue = staticvalue % seed[2];
|
||||
if (staticvalue < 0) staticvalue = seed[2] + staticvalue;
|
||||
return staticvalue;
|
||||
}
|
||||
|
||||
int a[10000] = {};
|
||||
int main(){
|
||||
|
||||
int n = getint();
|
||||
staticvalue = getint();
|
||||
starttime();
|
||||
int x, y;
|
||||
while (n > 0){
|
||||
n = n - 1;
|
||||
x = rand() % 300000;
|
||||
y = rand() % 2;
|
||||
set(a, x, y);
|
||||
}
|
||||
stoptime();
|
||||
putarray(10000, a);
|
||||
return 0;
|
||||
}
|
||||
67
testcases/final_performance/00_bitset3.sy
Executable file
67
testcases/final_performance/00_bitset3.sy
Executable file
@ -0,0 +1,67 @@
|
||||
int set(int a[], int pos, int d){
|
||||
const int bitcount = 30;
|
||||
int x[bitcount + 1] = {};
|
||||
|
||||
x[0] = 1;
|
||||
x[1] = x[0] * 2;
|
||||
x[2] = x[1] * 2;
|
||||
x[3] = x[2] * 2;
|
||||
x[4] = x[3] * 2;
|
||||
x[5] = x[4] * 2;
|
||||
x[6] = x[5] * 2;
|
||||
x[7] = x[6] * 2;
|
||||
x[8] = x[7] * 2;
|
||||
x[9] = x[8] * 2;
|
||||
x[10] = x[9] * 2;
|
||||
|
||||
int i = 10;
|
||||
while (i < bitcount){
|
||||
i = i + 1;
|
||||
x[i] = x[i - 1] * 2;
|
||||
}
|
||||
|
||||
int v = 0;
|
||||
|
||||
if (pos / bitcount >= 10000) return 0;
|
||||
|
||||
if (a[pos / bitcount] / (x[pos % bitcount]) % 2 != d){
|
||||
if (a[pos / bitcount] / (x[pos % bitcount]) % 2 == 0)
|
||||
if (d == 1)
|
||||
v = x[pos % bitcount];
|
||||
|
||||
if (a[pos / bitcount] / x[pos % bitcount] % 2 == 1)
|
||||
if (d == 0)
|
||||
v = v - x[pos % bitcount];
|
||||
}
|
||||
|
||||
a[pos / bitcount] = a[pos / bitcount] + v;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int seed[3] = {19971231, 19981013, 1000000000 + 7};
|
||||
int staticvalue = 0;
|
||||
|
||||
int rand(){
|
||||
staticvalue = staticvalue * seed[0] + seed[1];
|
||||
staticvalue = staticvalue % seed[2];
|
||||
if (staticvalue < 0) staticvalue = seed[2] + staticvalue;
|
||||
return staticvalue;
|
||||
}
|
||||
|
||||
int a[10000] = {};
|
||||
int main(){
|
||||
|
||||
int n = getint();
|
||||
staticvalue = getint();
|
||||
starttime();
|
||||
int x, y;
|
||||
while (n > 0){
|
||||
n = n - 1;
|
||||
x = rand() % 300000;
|
||||
y = rand() % 2;
|
||||
set(a, x, y);
|
||||
}
|
||||
stoptime();
|
||||
putarray(10000, a);
|
||||
return 0;
|
||||
}
|
||||
89
testcases/final_performance/01_mm1.sy
Normal file
89
testcases/final_performance/01_mm1.sy
Normal file
@ -0,0 +1,89 @@
|
||||
const int N = 1024;
|
||||
|
||||
void mm(int n, int A[][N], int B[][N], int C[][N]){
|
||||
int i, j, k;
|
||||
|
||||
i = 0; j = 0;
|
||||
while (i < n){
|
||||
j = 0;
|
||||
while (j < n){
|
||||
C[i][j] = 0;
|
||||
j = j + 1;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
i = 0; j = 0; k = 0;
|
||||
|
||||
while (k < n){
|
||||
i = 0;
|
||||
while (i < n){
|
||||
if (A[i][k] == 0){
|
||||
i = i + 1;
|
||||
continue;
|
||||
}
|
||||
j = 0;
|
||||
while (j < n){
|
||||
C[i][j] = C[i][j] + A[i][k] * B[k][j];
|
||||
j = j + 1;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
k = k + 1;
|
||||
}
|
||||
}
|
||||
|
||||
int A[N][N];
|
||||
int B[N][N];
|
||||
int C[N][N];
|
||||
|
||||
int main(){
|
||||
int n = getint();
|
||||
int i, j;
|
||||
|
||||
i = 0;
|
||||
j = 0;
|
||||
while (i < n){
|
||||
j = 0;
|
||||
while (j < n){
|
||||
A[i][j] = getint();
|
||||
j = j + 1;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
i = 0;
|
||||
j = 0;
|
||||
while (i < n){
|
||||
j = 0;
|
||||
while (j < n){
|
||||
B[i][j] = getint();
|
||||
j = j + 1;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
starttime();
|
||||
|
||||
i = 0;
|
||||
while (i < 5){
|
||||
mm(n, A, B, C);
|
||||
mm(n, A, C, B);
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
int ans = 0;
|
||||
i = 0;
|
||||
while (i < n){
|
||||
j = 0;
|
||||
while (j < n){
|
||||
ans = ans + B[i][j];
|
||||
j = j + 1;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
stoptime();
|
||||
putint(ans);
|
||||
putch(10);
|
||||
|
||||
return 0;
|
||||
}
|
||||
89
testcases/final_performance/01_mm2.sy
Normal file
89
testcases/final_performance/01_mm2.sy
Normal file
@ -0,0 +1,89 @@
|
||||
const int N = 1024;
|
||||
|
||||
void mm(int n, int A[][N], int B[][N], int C[][N]){
|
||||
int i, j, k;
|
||||
|
||||
i = 0; j = 0;
|
||||
while (i < n){
|
||||
j = 0;
|
||||
while (j < n){
|
||||
C[i][j] = 0;
|
||||
j = j + 1;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
i = 0; j = 0; k = 0;
|
||||
|
||||
while (k < n){
|
||||
i = 0;
|
||||
while (i < n){
|
||||
if (A[i][k] == 0){
|
||||
i = i + 1;
|
||||
continue;
|
||||
}
|
||||
j = 0;
|
||||
while (j < n){
|
||||
C[i][j] = C[i][j] + A[i][k] * B[k][j];
|
||||
j = j + 1;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
k = k + 1;
|
||||
}
|
||||
}
|
||||
|
||||
int A[N][N];
|
||||
int B[N][N];
|
||||
int C[N][N];
|
||||
|
||||
int main(){
|
||||
int n = getint();
|
||||
int i, j;
|
||||
|
||||
i = 0;
|
||||
j = 0;
|
||||
while (i < n){
|
||||
j = 0;
|
||||
while (j < n){
|
||||
A[i][j] = getint();
|
||||
j = j + 1;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
i = 0;
|
||||
j = 0;
|
||||
while (i < n){
|
||||
j = 0;
|
||||
while (j < n){
|
||||
B[i][j] = getint();
|
||||
j = j + 1;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
starttime();
|
||||
|
||||
i = 0;
|
||||
while (i < 5){
|
||||
mm(n, A, B, C);
|
||||
mm(n, A, C, B);
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
int ans = 0;
|
||||
i = 0;
|
||||
while (i < n){
|
||||
j = 0;
|
||||
while (j < n){
|
||||
ans = ans + B[i][j];
|
||||
j = j + 1;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
stoptime();
|
||||
putint(ans);
|
||||
putch(10);
|
||||
|
||||
return 0;
|
||||
}
|
||||
89
testcases/final_performance/01_mm3.sy
Normal file
89
testcases/final_performance/01_mm3.sy
Normal file
@ -0,0 +1,89 @@
|
||||
const int N = 1024;
|
||||
|
||||
void mm(int n, int A[][N], int B[][N], int C[][N]){
|
||||
int i, j, k;
|
||||
|
||||
i = 0; j = 0;
|
||||
while (i < n){
|
||||
j = 0;
|
||||
while (j < n){
|
||||
C[i][j] = 0;
|
||||
j = j + 1;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
i = 0; j = 0; k = 0;
|
||||
|
||||
while (k < n){
|
||||
i = 0;
|
||||
while (i < n){
|
||||
if (A[i][k] == 0){
|
||||
i = i + 1;
|
||||
continue;
|
||||
}
|
||||
j = 0;
|
||||
while (j < n){
|
||||
C[i][j] = C[i][j] + A[i][k] * B[k][j];
|
||||
j = j + 1;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
k = k + 1;
|
||||
}
|
||||
}
|
||||
|
||||
int A[N][N];
|
||||
int B[N][N];
|
||||
int C[N][N];
|
||||
|
||||
int main(){
|
||||
int n = getint();
|
||||
int i, j;
|
||||
|
||||
i = 0;
|
||||
j = 0;
|
||||
while (i < n){
|
||||
j = 0;
|
||||
while (j < n){
|
||||
A[i][j] = getint();
|
||||
j = j + 1;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
i = 0;
|
||||
j = 0;
|
||||
while (i < n){
|
||||
j = 0;
|
||||
while (j < n){
|
||||
B[i][j] = getint();
|
||||
j = j + 1;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
starttime();
|
||||
|
||||
i = 0;
|
||||
while (i < 5){
|
||||
mm(n, A, B, C);
|
||||
mm(n, A, C, B);
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
int ans = 0;
|
||||
i = 0;
|
||||
while (i < n){
|
||||
j = 0;
|
||||
while (j < n){
|
||||
ans = ans + B[i][j];
|
||||
j = j + 1;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
stoptime();
|
||||
putint(ans);
|
||||
putch(10);
|
||||
|
||||
return 0;
|
||||
}
|
||||
71
testcases/final_performance/02_mv1.sy
Executable file
71
testcases/final_performance/02_mv1.sy
Executable file
@ -0,0 +1,71 @@
|
||||
int x;
|
||||
|
||||
const int N = 2010;
|
||||
|
||||
void mv(int n, int A[][N], int b[], int res[]){
|
||||
int x, y;
|
||||
y = 0;
|
||||
x = 11;
|
||||
int i, j;
|
||||
|
||||
i = 0;
|
||||
while(i < n){
|
||||
res[i] = 0;
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
j = 0;
|
||||
while (i < n){
|
||||
j = 0;
|
||||
while (j < n){
|
||||
if (A[i][j] == 0){
|
||||
x = x * b[i] + b[j];
|
||||
y = y - x;
|
||||
}else{
|
||||
res[i] = res[i] + A[i][j] * b[j];
|
||||
}
|
||||
j = j + 1;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
int A[N][N];
|
||||
int B[N];
|
||||
int C[N];
|
||||
|
||||
int main(){
|
||||
int n = getint();
|
||||
int i, j;
|
||||
|
||||
i = 0;
|
||||
|
||||
while (i < n){
|
||||
j = 0;
|
||||
while (j < n){
|
||||
A[i][j] = getint();
|
||||
j = j + 1;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
while (i < n){
|
||||
B[i] = getint();
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
starttime();
|
||||
|
||||
i = 0;
|
||||
while (i < 50){
|
||||
mv(n, A, B, C);
|
||||
mv(n, A, C, B);
|
||||
i = i + 1;
|
||||
}
|
||||
stoptime();
|
||||
|
||||
putarray(n, C);
|
||||
return 0;
|
||||
}
|
||||
71
testcases/final_performance/02_mv2.sy
Executable file
71
testcases/final_performance/02_mv2.sy
Executable file
@ -0,0 +1,71 @@
|
||||
int x;
|
||||
|
||||
const int N = 2010;
|
||||
|
||||
void mv(int n, int A[][N], int b[], int res[]){
|
||||
int x, y;
|
||||
y = 0;
|
||||
x = 11;
|
||||
int i, j;
|
||||
|
||||
i = 0;
|
||||
while(i < n){
|
||||
res[i] = 0;
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
j = 0;
|
||||
while (i < n){
|
||||
j = 0;
|
||||
while (j < n){
|
||||
if (A[i][j] == 0){
|
||||
x = x * b[i] + b[j];
|
||||
y = y - x;
|
||||
}else{
|
||||
res[i] = res[i] + A[i][j] * b[j];
|
||||
}
|
||||
j = j + 1;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
int A[N][N];
|
||||
int B[N];
|
||||
int C[N];
|
||||
|
||||
int main(){
|
||||
int n = getint();
|
||||
int i, j;
|
||||
|
||||
i = 0;
|
||||
|
||||
while (i < n){
|
||||
j = 0;
|
||||
while (j < n){
|
||||
A[i][j] = getint();
|
||||
j = j + 1;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
while (i < n){
|
||||
B[i] = getint();
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
starttime();
|
||||
|
||||
i = 0;
|
||||
while (i < 50){
|
||||
mv(n, A, B, C);
|
||||
mv(n, A, C, B);
|
||||
i = i + 1;
|
||||
}
|
||||
stoptime();
|
||||
|
||||
putarray(n, C);
|
||||
return 0;
|
||||
}
|
||||
71
testcases/final_performance/02_mv3.sy
Executable file
71
testcases/final_performance/02_mv3.sy
Executable file
@ -0,0 +1,71 @@
|
||||
int x;
|
||||
|
||||
const int N = 2010;
|
||||
|
||||
void mv(int n, int A[][N], int b[], int res[]){
|
||||
int x, y;
|
||||
y = 0;
|
||||
x = 11;
|
||||
int i, j;
|
||||
|
||||
i = 0;
|
||||
while(i < n){
|
||||
res[i] = 0;
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
j = 0;
|
||||
while (i < n){
|
||||
j = 0;
|
||||
while (j < n){
|
||||
if (A[i][j] == 0){
|
||||
x = x * b[i] + b[j];
|
||||
y = y - x;
|
||||
}else{
|
||||
res[i] = res[i] + A[i][j] * b[j];
|
||||
}
|
||||
j = j + 1;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
int A[N][N];
|
||||
int B[N];
|
||||
int C[N];
|
||||
|
||||
int main(){
|
||||
int n = getint();
|
||||
int i, j;
|
||||
|
||||
i = 0;
|
||||
|
||||
while (i < n){
|
||||
j = 0;
|
||||
while (j < n){
|
||||
A[i][j] = getint();
|
||||
j = j + 1;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
while (i < n){
|
||||
B[i] = getint();
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
starttime();
|
||||
|
||||
i = 0;
|
||||
while (i < 50){
|
||||
mv(n, A, B, C);
|
||||
mv(n, A, C, B);
|
||||
i = i + 1;
|
||||
}
|
||||
stoptime();
|
||||
|
||||
putarray(n, C);
|
||||
return 0;
|
||||
}
|
||||
106
testcases/final_performance/03_sort1.sy
Executable file
106
testcases/final_performance/03_sort1.sy
Executable file
@ -0,0 +1,106 @@
|
||||
const int base = 16;
|
||||
|
||||
int getMaxNum(int n, int arr[]){
|
||||
int ret = 0;
|
||||
int i = 0;
|
||||
while (i < n){
|
||||
if (arr[i] > ret) ret = arr[i];
|
||||
i = i + 1;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int getNumPos(int num, int pos){
|
||||
int tmp = 1;
|
||||
int i = 0;
|
||||
while (i < pos){
|
||||
num = num / base;
|
||||
i = i + 1;
|
||||
}
|
||||
return num % base;
|
||||
}
|
||||
|
||||
void radixSort(int bitround, int a[], int l, int r){
|
||||
int head[base] = {};
|
||||
int tail[base] = {};
|
||||
int cnt[base] = {};
|
||||
|
||||
if (bitround == -1 || l + 1 >= r) return;
|
||||
|
||||
{
|
||||
int i = l;
|
||||
|
||||
while (i < r){
|
||||
cnt[getNumPos(a[i], bitround)]
|
||||
= cnt[getNumPos(a[i], bitround)] + 1;
|
||||
i = i + 1;
|
||||
}
|
||||
head[0] = l;
|
||||
tail[0] = l + cnt[0];
|
||||
|
||||
i = 1;
|
||||
while (i < base){
|
||||
head[i] = tail[i - 1];
|
||||
tail[i] = head[i] + cnt[i];
|
||||
i = i + 1;
|
||||
}
|
||||
i = 0;
|
||||
while (i < base){
|
||||
while (head[i] < tail[i]){
|
||||
int v = a[head[i]];
|
||||
while (getNumPos(v, bitround) != i){
|
||||
int t = v;
|
||||
v = a[head[getNumPos(t, bitround)]];
|
||||
a[head[getNumPos(t, bitround)]] = t;
|
||||
head[getNumPos(t, bitround)] = head[getNumPos(t, bitround)] + 1;
|
||||
}
|
||||
a[head[i]] = v;
|
||||
head[i] = head[i] + 1;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
int i = l;
|
||||
|
||||
head[0] = l;
|
||||
tail[0] = l + cnt[0];
|
||||
|
||||
i = 0;
|
||||
while (i < base){
|
||||
if (i > 0){
|
||||
head[i] = tail[i - 1];
|
||||
tail[i] = head[i] + cnt[i];
|
||||
}
|
||||
radixSort(bitround - 1, a, head[i], tail[i]);
|
||||
i = i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int a[30000010];
|
||||
int ans;
|
||||
|
||||
int main(){
|
||||
int n = getarray(a);
|
||||
|
||||
starttime();
|
||||
|
||||
radixSort(8, a, 0, n);
|
||||
|
||||
int i = 0;
|
||||
while (i < n){
|
||||
ans = ans + i * (a[i] % (2 + i));
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
if (ans < 0)
|
||||
ans = -ans;
|
||||
stoptime();
|
||||
putint(ans);
|
||||
putch(10);
|
||||
return 0;
|
||||
}
|
||||
106
testcases/final_performance/03_sort2.sy
Executable file
106
testcases/final_performance/03_sort2.sy
Executable file
@ -0,0 +1,106 @@
|
||||
const int base = 16;
|
||||
|
||||
int getMaxNum(int n, int arr[]){
|
||||
int ret = 0;
|
||||
int i = 0;
|
||||
while (i < n){
|
||||
if (arr[i] > ret) ret = arr[i];
|
||||
i = i + 1;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int getNumPos(int num, int pos){
|
||||
int tmp = 1;
|
||||
int i = 0;
|
||||
while (i < pos){
|
||||
num = num / base;
|
||||
i = i + 1;
|
||||
}
|
||||
return num % base;
|
||||
}
|
||||
|
||||
void radixSort(int bitround, int a[], int l, int r){
|
||||
int head[base] = {};
|
||||
int tail[base] = {};
|
||||
int cnt[base] = {};
|
||||
|
||||
if (bitround == -1 || l + 1 >= r) return;
|
||||
|
||||
{
|
||||
int i = l;
|
||||
|
||||
while (i < r){
|
||||
cnt[getNumPos(a[i], bitround)]
|
||||
= cnt[getNumPos(a[i], bitround)] + 1;
|
||||
i = i + 1;
|
||||
}
|
||||
head[0] = l;
|
||||
tail[0] = l + cnt[0];
|
||||
|
||||
i = 1;
|
||||
while (i < base){
|
||||
head[i] = tail[i - 1];
|
||||
tail[i] = head[i] + cnt[i];
|
||||
i = i + 1;
|
||||
}
|
||||
i = 0;
|
||||
while (i < base){
|
||||
while (head[i] < tail[i]){
|
||||
int v = a[head[i]];
|
||||
while (getNumPos(v, bitround) != i){
|
||||
int t = v;
|
||||
v = a[head[getNumPos(t, bitround)]];
|
||||
a[head[getNumPos(t, bitround)]] = t;
|
||||
head[getNumPos(t, bitround)] = head[getNumPos(t, bitround)] + 1;
|
||||
}
|
||||
a[head[i]] = v;
|
||||
head[i] = head[i] + 1;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
int i = l;
|
||||
|
||||
head[0] = l;
|
||||
tail[0] = l + cnt[0];
|
||||
|
||||
i = 0;
|
||||
while (i < base){
|
||||
if (i > 0){
|
||||
head[i] = tail[i - 1];
|
||||
tail[i] = head[i] + cnt[i];
|
||||
}
|
||||
radixSort(bitround - 1, a, head[i], tail[i]);
|
||||
i = i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int a[30000010];
|
||||
int ans;
|
||||
|
||||
int main(){
|
||||
int n = getarray(a);
|
||||
|
||||
starttime();
|
||||
|
||||
radixSort(8, a, 0, n);
|
||||
|
||||
int i = 0;
|
||||
while (i < n){
|
||||
ans = ans + i * (a[i] % (2 + i));
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
if (ans < 0)
|
||||
ans = -ans;
|
||||
stoptime();
|
||||
putint(ans);
|
||||
putch(10);
|
||||
return 0;
|
||||
}
|
||||
106
testcases/final_performance/03_sort3.sy
Executable file
106
testcases/final_performance/03_sort3.sy
Executable file
@ -0,0 +1,106 @@
|
||||
const int base = 16;
|
||||
|
||||
int getMaxNum(int n, int arr[]){
|
||||
int ret = 0;
|
||||
int i = 0;
|
||||
while (i < n){
|
||||
if (arr[i] > ret) ret = arr[i];
|
||||
i = i + 1;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int getNumPos(int num, int pos){
|
||||
int tmp = 1;
|
||||
int i = 0;
|
||||
while (i < pos){
|
||||
num = num / base;
|
||||
i = i + 1;
|
||||
}
|
||||
return num % base;
|
||||
}
|
||||
|
||||
void radixSort(int bitround, int a[], int l, int r){
|
||||
int head[base] = {};
|
||||
int tail[base] = {};
|
||||
int cnt[base] = {};
|
||||
|
||||
if (bitround == -1 || l + 1 >= r) return;
|
||||
|
||||
{
|
||||
int i = l;
|
||||
|
||||
while (i < r){
|
||||
cnt[getNumPos(a[i], bitround)]
|
||||
= cnt[getNumPos(a[i], bitround)] + 1;
|
||||
i = i + 1;
|
||||
}
|
||||
head[0] = l;
|
||||
tail[0] = l + cnt[0];
|
||||
|
||||
i = 1;
|
||||
while (i < base){
|
||||
head[i] = tail[i - 1];
|
||||
tail[i] = head[i] + cnt[i];
|
||||
i = i + 1;
|
||||
}
|
||||
i = 0;
|
||||
while (i < base){
|
||||
while (head[i] < tail[i]){
|
||||
int v = a[head[i]];
|
||||
while (getNumPos(v, bitround) != i){
|
||||
int t = v;
|
||||
v = a[head[getNumPos(t, bitround)]];
|
||||
a[head[getNumPos(t, bitround)]] = t;
|
||||
head[getNumPos(t, bitround)] = head[getNumPos(t, bitround)] + 1;
|
||||
}
|
||||
a[head[i]] = v;
|
||||
head[i] = head[i] + 1;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
{
|
||||
int i = l;
|
||||
|
||||
head[0] = l;
|
||||
tail[0] = l + cnt[0];
|
||||
|
||||
i = 0;
|
||||
while (i < base){
|
||||
if (i > 0){
|
||||
head[i] = tail[i - 1];
|
||||
tail[i] = head[i] + cnt[i];
|
||||
}
|
||||
radixSort(bitround - 1, a, head[i], tail[i]);
|
||||
i = i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
int a[30000010];
|
||||
int ans;
|
||||
|
||||
int main(){
|
||||
int n = getarray(a);
|
||||
|
||||
starttime();
|
||||
|
||||
radixSort(8, a, 0, n);
|
||||
|
||||
int i = 0;
|
||||
while (i < n){
|
||||
ans = ans + i * (a[i] % (2 + i));
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
if (ans < 0)
|
||||
ans = -ans;
|
||||
stoptime();
|
||||
putint(ans);
|
||||
putch(10);
|
||||
return 0;
|
||||
}
|
||||
50
testcases/final_performance/04_spmv1.sy
Executable file
50
testcases/final_performance/04_spmv1.sy
Executable file
@ -0,0 +1,50 @@
|
||||
void spmv(int n,int xptr[], int yidx[], int vals[], int b[], int x[]){
|
||||
int i, j, k;
|
||||
i = 0;
|
||||
while (i < n){
|
||||
x[i] = 0;
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
while (i < n){
|
||||
j = xptr[i];
|
||||
while (j < xptr[i + 1]){
|
||||
x[yidx[j]] = x[yidx[j]] + vals[j];
|
||||
j = j + 1;
|
||||
}
|
||||
|
||||
j = xptr[i];
|
||||
while (j < xptr[i + 1]){
|
||||
x[yidx[j]] = x[yidx[j]] + vals[j] * (b[i] - 1);
|
||||
j = j + 1;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
const int N = 100010;
|
||||
const int M = 3000000;
|
||||
|
||||
int x[N], y[M], v[M];
|
||||
int a[N], b[N], c[N];
|
||||
|
||||
int main(){
|
||||
int n = getarray(x) - 1;
|
||||
int m = getarray(y);
|
||||
getarray(v);
|
||||
|
||||
getarray(a);
|
||||
|
||||
starttime();
|
||||
|
||||
int i = 0;
|
||||
while (i < 100){
|
||||
spmv(n, x, y, v, a, b);
|
||||
spmv(n, x, y, v, b, a);
|
||||
i=i+1;
|
||||
}
|
||||
stoptime();
|
||||
putarray(n, b);
|
||||
return 0;
|
||||
}
|
||||
50
testcases/final_performance/04_spmv2.sy
Executable file
50
testcases/final_performance/04_spmv2.sy
Executable file
@ -0,0 +1,50 @@
|
||||
void spmv(int n,int xptr[], int yidx[], int vals[], int b[], int x[]){
|
||||
int i, j, k;
|
||||
i = 0;
|
||||
while (i < n){
|
||||
x[i] = 0;
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
while (i < n){
|
||||
j = xptr[i];
|
||||
while (j < xptr[i + 1]){
|
||||
x[yidx[j]] = x[yidx[j]] + vals[j];
|
||||
j = j + 1;
|
||||
}
|
||||
|
||||
j = xptr[i];
|
||||
while (j < xptr[i + 1]){
|
||||
x[yidx[j]] = x[yidx[j]] + vals[j] * (b[i] - 1);
|
||||
j = j + 1;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
const int N = 100010;
|
||||
const int M = 3000000;
|
||||
|
||||
int x[N], y[M], v[M];
|
||||
int a[N], b[N], c[N];
|
||||
|
||||
int main(){
|
||||
int n = getarray(x) - 1;
|
||||
int m = getarray(y);
|
||||
getarray(v);
|
||||
|
||||
getarray(a);
|
||||
|
||||
starttime();
|
||||
|
||||
int i = 0;
|
||||
while (i < 100){
|
||||
spmv(n, x, y, v, a, b);
|
||||
spmv(n, x, y, v, b, a);
|
||||
i=i+1;
|
||||
}
|
||||
stoptime();
|
||||
putarray(n, b);
|
||||
return 0;
|
||||
}
|
||||
50
testcases/final_performance/04_spmv3.sy
Executable file
50
testcases/final_performance/04_spmv3.sy
Executable file
@ -0,0 +1,50 @@
|
||||
void spmv(int n,int xptr[], int yidx[], int vals[], int b[], int x[]){
|
||||
int i, j, k;
|
||||
i = 0;
|
||||
while (i < n){
|
||||
x[i] = 0;
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
while (i < n){
|
||||
j = xptr[i];
|
||||
while (j < xptr[i + 1]){
|
||||
x[yidx[j]] = x[yidx[j]] + vals[j];
|
||||
j = j + 1;
|
||||
}
|
||||
|
||||
j = xptr[i];
|
||||
while (j < xptr[i + 1]){
|
||||
x[yidx[j]] = x[yidx[j]] + vals[j] * (b[i] - 1);
|
||||
j = j + 1;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
const int N = 100010;
|
||||
const int M = 3000000;
|
||||
|
||||
int x[N], y[M], v[M];
|
||||
int a[N], b[N], c[N];
|
||||
|
||||
int main(){
|
||||
int n = getarray(x) - 1;
|
||||
int m = getarray(y);
|
||||
getarray(v);
|
||||
|
||||
getarray(a);
|
||||
|
||||
starttime();
|
||||
|
||||
int i = 0;
|
||||
while (i < 100){
|
||||
spmv(n, x, y, v, a, b);
|
||||
spmv(n, x, y, v, b, a);
|
||||
i=i+1;
|
||||
}
|
||||
stoptime();
|
||||
putarray(n, b);
|
||||
return 0;
|
||||
}
|
||||
121
testcases/final_performance/brainfuck-bootstrap.sy
Executable file
121
testcases/final_performance/brainfuck-bootstrap.sy
Executable file
@ -0,0 +1,121 @@
|
||||
// Brainfuck Interpreter
|
||||
// Reads program from stdin, interprets and outputs to stdout.
|
||||
//
|
||||
// Main optimization targets:
|
||||
// jump table, inline variables, etc.
|
||||
|
||||
int program_length = 0;
|
||||
int program[65536] = {};
|
||||
int tape[65536] = {};
|
||||
int input[65536] = {};
|
||||
int input_length = 0;
|
||||
int output[65536] = {};
|
||||
int output_length = 0;
|
||||
|
||||
int get_bf_char() {
|
||||
int get = getch();
|
||||
while (get != 62 && get != 60 && get != 43 && get != 45 && get != 91 &&
|
||||
get != 93 && get != 46 && get != 44 && get != 35) {
|
||||
get = getch();
|
||||
}
|
||||
return get;
|
||||
}
|
||||
|
||||
void read_program() {
|
||||
int get = get_bf_char();
|
||||
while (get != 35) {
|
||||
program[program_length] = get;
|
||||
get = get_bf_char();
|
||||
program_length = program_length + 1;
|
||||
}
|
||||
|
||||
// read input
|
||||
// input starts with an `i`
|
||||
int verify = getch();
|
||||
if (verify != 105) {
|
||||
return;
|
||||
}
|
||||
// and a length
|
||||
input_length = getint();
|
||||
// and a random char
|
||||
getch();
|
||||
int i = 0;
|
||||
while (i < input_length) {
|
||||
input[i] = getch();
|
||||
i = i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
void run_program() {
|
||||
int ip = 0;
|
||||
int read_head = 0;
|
||||
int input_head = 0;
|
||||
int return_address[512] = {};
|
||||
int return_address_top = 0;
|
||||
output_length = 0;
|
||||
while (ip < program_length) {
|
||||
int code = program[ip];
|
||||
if (code == 62) {
|
||||
read_head = read_head + 1;
|
||||
} else if (code == 60) {
|
||||
read_head = read_head - 1;
|
||||
} else if (code == 43) {
|
||||
tape[read_head] = tape[read_head] + 1;
|
||||
} else if (code == 45) {
|
||||
tape[read_head] = tape[read_head] - 1;
|
||||
} else if (code == 91) {
|
||||
int val = tape[read_head];
|
||||
if (val != 0) {
|
||||
return_address[return_address_top] = ip;
|
||||
return_address_top = return_address_top + 1;
|
||||
} else {
|
||||
// find the matching ]
|
||||
int loop = 1;
|
||||
while (loop > 0) {
|
||||
ip = ip + 1;
|
||||
if (program[ip] == 93) {
|
||||
loop = loop - 1;
|
||||
}
|
||||
if (program[ip] == 91) {
|
||||
loop = loop + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (code == 93) {
|
||||
int val = tape[read_head];
|
||||
if (val == 0) {
|
||||
return_address_top = return_address_top - 1;
|
||||
} else {
|
||||
ip = return_address[return_address_top - 1];
|
||||
}
|
||||
} else if (code == 46) {
|
||||
output[output_length] = tape[read_head];
|
||||
output_length = output_length + 1;
|
||||
} else if (code == 44) {
|
||||
if (input_head >= input_length) {
|
||||
tape[read_head] = 0;
|
||||
} else {
|
||||
tape[read_head] = input[input_head];
|
||||
input_head = input_head + 1;
|
||||
}
|
||||
}
|
||||
ip = ip + 1;
|
||||
}
|
||||
}
|
||||
|
||||
void output_() {
|
||||
int i = 0;
|
||||
while (i < output_length) {
|
||||
putch(output[i]);
|
||||
i = i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
read_program();
|
||||
starttime();
|
||||
run_program();
|
||||
stoptime();
|
||||
output_();
|
||||
return 0;
|
||||
}
|
||||
121
testcases/final_performance/brainfuck-mandelbrot-nerf.sy
Executable file
121
testcases/final_performance/brainfuck-mandelbrot-nerf.sy
Executable file
@ -0,0 +1,121 @@
|
||||
// Brainfuck Interpreter
|
||||
// Reads program from stdin, interprets and outputs to stdout.
|
||||
//
|
||||
// Main optimization targets:
|
||||
// jump table, inline variables, etc.
|
||||
|
||||
int program_length = 0;
|
||||
int program[65536] = {};
|
||||
int tape[65536] = {};
|
||||
int input[65536] = {};
|
||||
int input_length = 0;
|
||||
int output[65536] = {};
|
||||
int output_length = 0;
|
||||
|
||||
int get_bf_char() {
|
||||
int get = getch();
|
||||
while (get != 62 && get != 60 && get != 43 && get != 45 && get != 91 &&
|
||||
get != 93 && get != 46 && get != 44 && get != 35) {
|
||||
get = getch();
|
||||
}
|
||||
return get;
|
||||
}
|
||||
|
||||
void read_program() {
|
||||
int get = get_bf_char();
|
||||
while (get != 35) {
|
||||
program[program_length] = get;
|
||||
get = get_bf_char();
|
||||
program_length = program_length + 1;
|
||||
}
|
||||
|
||||
// read input
|
||||
// input starts with an `i`
|
||||
int verify = getch();
|
||||
if (verify != 105) {
|
||||
return;
|
||||
}
|
||||
// and a length
|
||||
input_length = getint();
|
||||
// and a random char
|
||||
getch();
|
||||
int i = 0;
|
||||
while (i < input_length) {
|
||||
input[i] = getch();
|
||||
i = i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
void run_program() {
|
||||
int ip = 0;
|
||||
int read_head = 0;
|
||||
int input_head = 0;
|
||||
int return_address[512] = {};
|
||||
int return_address_top = 0;
|
||||
output_length = 0;
|
||||
while (ip < program_length) {
|
||||
int code = program[ip];
|
||||
if (code == 62) {
|
||||
read_head = read_head + 1;
|
||||
} else if (code == 60) {
|
||||
read_head = read_head - 1;
|
||||
} else if (code == 43) {
|
||||
tape[read_head] = tape[read_head] + 1;
|
||||
} else if (code == 45) {
|
||||
tape[read_head] = tape[read_head] - 1;
|
||||
} else if (code == 91) {
|
||||
int val = tape[read_head];
|
||||
if (val != 0) {
|
||||
return_address[return_address_top] = ip;
|
||||
return_address_top = return_address_top + 1;
|
||||
} else {
|
||||
// find the matching ]
|
||||
int loop = 1;
|
||||
while (loop > 0) {
|
||||
ip = ip + 1;
|
||||
if (program[ip] == 93) {
|
||||
loop = loop - 1;
|
||||
}
|
||||
if (program[ip] == 91) {
|
||||
loop = loop + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (code == 93) {
|
||||
int val = tape[read_head];
|
||||
if (val == 0) {
|
||||
return_address_top = return_address_top - 1;
|
||||
} else {
|
||||
ip = return_address[return_address_top - 1];
|
||||
}
|
||||
} else if (code == 46) {
|
||||
output[output_length] = tape[read_head];
|
||||
output_length = output_length + 1;
|
||||
} else if (code == 44) {
|
||||
if (input_head >= input_length) {
|
||||
tape[read_head] = 0;
|
||||
} else {
|
||||
tape[read_head] = input[input_head];
|
||||
input_head = input_head + 1;
|
||||
}
|
||||
}
|
||||
ip = ip + 1;
|
||||
}
|
||||
}
|
||||
|
||||
void output_() {
|
||||
int i = 0;
|
||||
while (i < output_length) {
|
||||
putch(output[i]);
|
||||
i = i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
read_program();
|
||||
starttime();
|
||||
run_program();
|
||||
stoptime();
|
||||
output_();
|
||||
return 0;
|
||||
}
|
||||
121
testcases/final_performance/brainfuck-pi-nerf.sy
Executable file
121
testcases/final_performance/brainfuck-pi-nerf.sy
Executable file
@ -0,0 +1,121 @@
|
||||
// Brainfuck Interpreter
|
||||
// Reads program from stdin, interprets and outputs to stdout.
|
||||
//
|
||||
// Main optimization targets:
|
||||
// jump table, inline variables, etc.
|
||||
|
||||
int program_length = 0;
|
||||
int program[65536] = {};
|
||||
int tape[65536] = {};
|
||||
int input[65536] = {};
|
||||
int input_length = 0;
|
||||
int output[65536] = {};
|
||||
int output_length = 0;
|
||||
|
||||
int get_bf_char() {
|
||||
int get = getch();
|
||||
while (get != 62 && get != 60 && get != 43 && get != 45 && get != 91 &&
|
||||
get != 93 && get != 46 && get != 44 && get != 35) {
|
||||
get = getch();
|
||||
}
|
||||
return get;
|
||||
}
|
||||
|
||||
void read_program() {
|
||||
int get = get_bf_char();
|
||||
while (get != 35) {
|
||||
program[program_length] = get;
|
||||
get = get_bf_char();
|
||||
program_length = program_length + 1;
|
||||
}
|
||||
|
||||
// read input
|
||||
// input starts with an `i`
|
||||
int verify = getch();
|
||||
if (verify != 105) {
|
||||
return;
|
||||
}
|
||||
// and a length
|
||||
input_length = getint();
|
||||
// and a random char
|
||||
getch();
|
||||
int i = 0;
|
||||
while (i < input_length) {
|
||||
input[i] = getch();
|
||||
i = i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
void run_program() {
|
||||
int ip = 0;
|
||||
int read_head = 0;
|
||||
int input_head = 0;
|
||||
int return_address[512] = {};
|
||||
int return_address_top = 0;
|
||||
output_length = 0;
|
||||
while (ip < program_length) {
|
||||
int code = program[ip];
|
||||
if (code == 62) {
|
||||
read_head = read_head + 1;
|
||||
} else if (code == 60) {
|
||||
read_head = read_head - 1;
|
||||
} else if (code == 43) {
|
||||
tape[read_head] = tape[read_head] + 1;
|
||||
} else if (code == 45) {
|
||||
tape[read_head] = tape[read_head] - 1;
|
||||
} else if (code == 91) {
|
||||
int val = tape[read_head];
|
||||
if (val != 0) {
|
||||
return_address[return_address_top] = ip;
|
||||
return_address_top = return_address_top + 1;
|
||||
} else {
|
||||
// find the matching ]
|
||||
int loop = 1;
|
||||
while (loop > 0) {
|
||||
ip = ip + 1;
|
||||
if (program[ip] == 93) {
|
||||
loop = loop - 1;
|
||||
}
|
||||
if (program[ip] == 91) {
|
||||
loop = loop + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else if (code == 93) {
|
||||
int val = tape[read_head];
|
||||
if (val == 0) {
|
||||
return_address_top = return_address_top - 1;
|
||||
} else {
|
||||
ip = return_address[return_address_top - 1];
|
||||
}
|
||||
} else if (code == 46) {
|
||||
output[output_length] = tape[read_head];
|
||||
output_length = output_length + 1;
|
||||
} else if (code == 44) {
|
||||
if (input_head >= input_length) {
|
||||
tape[read_head] = 0;
|
||||
} else {
|
||||
tape[read_head] = input[input_head];
|
||||
input_head = input_head + 1;
|
||||
}
|
||||
}
|
||||
ip = ip + 1;
|
||||
}
|
||||
}
|
||||
|
||||
void output_() {
|
||||
int i = 0;
|
||||
while (i < output_length) {
|
||||
putch(output[i]);
|
||||
i = i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
read_program();
|
||||
starttime();
|
||||
run_program();
|
||||
stoptime();
|
||||
output_();
|
||||
return 0;
|
||||
}
|
||||
188
testcases/final_performance/crypto1.sy
Executable file
188
testcases/final_performance/crypto1.sy
Executable file
@ -0,0 +1,188 @@
|
||||
|
||||
|
||||
int state = 19260817;
|
||||
|
||||
int get_random() {
|
||||
state = state + (state * 8192);
|
||||
state = state + (state / 131072);
|
||||
state = state + (state * 32);
|
||||
return state;
|
||||
}
|
||||
|
||||
int rotl1(int x) {
|
||||
return x * 2 + x % 2;
|
||||
}
|
||||
|
||||
int rotl5(int x) {
|
||||
return x * 32 + x % 32;
|
||||
}
|
||||
|
||||
int rotl30(int x) {
|
||||
return x * 1073741824 + x % 1073741824;
|
||||
}
|
||||
|
||||
int _and(int a, int b) {
|
||||
// int c = 0;
|
||||
// int x = 0;
|
||||
// while (x <= 32) {
|
||||
// c = c + c;
|
||||
// if (a < 0) {
|
||||
// if (b < 0) {
|
||||
// c = c + 1;
|
||||
// }
|
||||
// }
|
||||
// a = a + a;
|
||||
// b = b + b;
|
||||
// x = x + 1;
|
||||
// }
|
||||
// return c;
|
||||
return a + b;
|
||||
}
|
||||
|
||||
int _not(int x) {
|
||||
return -1 - x;
|
||||
}
|
||||
|
||||
int _xor(int a, int b) {
|
||||
return a - _and(a, b) + b - _and(a, b);
|
||||
}
|
||||
|
||||
int _or(int a, int b) {
|
||||
return _xor(_xor(a, b), _and(a, b));
|
||||
}
|
||||
|
||||
// performs a SHA-1 hash to output.
|
||||
//
|
||||
// input is a list of ints, but only the lower 8 bits are used. Input must be
|
||||
// larger than the smallest 64 multiple.
|
||||
void pseudo_sha1(int input[], int input_len, int output[]) {
|
||||
int h0 = 1732584193;
|
||||
int h1 = -271733879;
|
||||
int h2 = -1732584194;
|
||||
int h3 = 271733878;
|
||||
int h4 = -1009589776;
|
||||
|
||||
int a;
|
||||
int b;
|
||||
int c;
|
||||
int d;
|
||||
int e;
|
||||
int f;
|
||||
int k;
|
||||
|
||||
// preprocessing
|
||||
int orig_len = input_len;
|
||||
input[input_len] = 0x80;
|
||||
input_len = input_len + 1;
|
||||
while (input_len % 64 != 60) {
|
||||
input[input_len] = 0;
|
||||
input_len = input_len + 1;
|
||||
}
|
||||
input[input_len] = orig_len / 16777216 % 256;
|
||||
input[input_len + 1] = orig_len / 65536 % 256;
|
||||
input[input_len + 2] = orig_len / 256 % 256;
|
||||
input[input_len + 3] = orig_len % 256;
|
||||
input_len = input_len + 4;
|
||||
|
||||
int chunk_start = 0;
|
||||
int words[80] = {0};
|
||||
while (chunk_start < input_len) {
|
||||
a = h0;
|
||||
b = h1;
|
||||
c = h2;
|
||||
d = h3;
|
||||
e = h4;
|
||||
|
||||
// populate words
|
||||
int i = 0;
|
||||
while (i < 16) {
|
||||
words[i] = input[chunk_start + i * 4] * 16777216 +
|
||||
input[chunk_start + i * 4 + 1] * 65536 +
|
||||
input[chunk_start + i * 4 + 2] * 256 +
|
||||
input[chunk_start + i * 4 + 3] * 1;
|
||||
i = i + 1;
|
||||
}
|
||||
while (i < 80) {
|
||||
words[i] =
|
||||
rotl1(_xor(_xor(_xor(words[i - 3], words[i - 8]), words[i - 14]),
|
||||
words[i - 16]));
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
// main loop
|
||||
i = 0;
|
||||
while (i < 80) {
|
||||
if (i < 20) {
|
||||
f = _or(_and(b, c), _and(_not(b), d));
|
||||
k = 1518500249;
|
||||
} else if (i < 40) {
|
||||
f = _xor(_xor(b, c), d);
|
||||
k = 1859775361;
|
||||
} else if (i < 60) {
|
||||
f = _or(_or(_and(b, c), _and(b, d)), _and(c, d));
|
||||
k = -1894007588;
|
||||
} else if (i < 80) {
|
||||
f = _xor(_xor(b, c), d);
|
||||
k = -899497722;
|
||||
}
|
||||
int t = rotl5(a) + f + e + k + words[i];
|
||||
e = d;
|
||||
d = c;
|
||||
c = rotl30(b);
|
||||
b = a;
|
||||
a = t;
|
||||
i = i + 1;
|
||||
}
|
||||
h0 = h0 + a;
|
||||
h1 = h1 + b;
|
||||
h2 = h2 + c;
|
||||
h3 = h3 + d;
|
||||
h4 = h4 + e;
|
||||
|
||||
chunk_start = chunk_start + 64;
|
||||
}
|
||||
output[0] = h0;
|
||||
output[1] = h1;
|
||||
output[2] = h2;
|
||||
output[3] = h3;
|
||||
output[4] = h4;
|
||||
}
|
||||
|
||||
int buffer[32768] = {0};
|
||||
|
||||
int main() {
|
||||
int rounds = 12;
|
||||
int i = 0;
|
||||
int output[5] = {0, 0, 0, 0, 0};
|
||||
int output_buf[5];
|
||||
state = getint();
|
||||
rounds = getint();
|
||||
|
||||
starttime();
|
||||
|
||||
output_buf[0] = 0;
|
||||
output_buf[1] = 0;
|
||||
output_buf[2] = 0;
|
||||
output_buf[3] = 0;
|
||||
output_buf[4] = 0;
|
||||
|
||||
while (rounds > 0) {
|
||||
int len = 32000;
|
||||
int i = 0;
|
||||
while (i < len) {
|
||||
buffer[i] = get_random() % 256;
|
||||
i = i + 1;
|
||||
}
|
||||
pseudo_sha1(buffer, len, output);
|
||||
i = 0;
|
||||
while (i < 5) {
|
||||
output_buf[i] = _xor(output_buf[i], output[i]);
|
||||
i = i + 1;
|
||||
}
|
||||
rounds = rounds - 1;
|
||||
}
|
||||
stoptime();
|
||||
|
||||
putarray(5, output_buf);
|
||||
return 0;
|
||||
}
|
||||
188
testcases/final_performance/crypto2.sy
Executable file
188
testcases/final_performance/crypto2.sy
Executable file
@ -0,0 +1,188 @@
|
||||
|
||||
|
||||
int state = 19260817;
|
||||
|
||||
int get_random() {
|
||||
state = state + (state * 8192);
|
||||
state = state + (state / 131072);
|
||||
state = state + (state * 32);
|
||||
return state;
|
||||
}
|
||||
|
||||
int rotl1(int x) {
|
||||
return x * 2 + x % 2;
|
||||
}
|
||||
|
||||
int rotl5(int x) {
|
||||
return x * 32 + x % 32;
|
||||
}
|
||||
|
||||
int rotl30(int x) {
|
||||
return x * 1073741824 + x % 1073741824;
|
||||
}
|
||||
|
||||
int _and(int a, int b) {
|
||||
// int c = 0;
|
||||
// int x = 0;
|
||||
// while (x <= 32) {
|
||||
// c = c + c;
|
||||
// if (a < 0) {
|
||||
// if (b < 0) {
|
||||
// c = c + 1;
|
||||
// }
|
||||
// }
|
||||
// a = a + a;
|
||||
// b = b + b;
|
||||
// x = x + 1;
|
||||
// }
|
||||
// return c;
|
||||
return a + b;
|
||||
}
|
||||
|
||||
int _not(int x) {
|
||||
return -1 - x;
|
||||
}
|
||||
|
||||
int _xor(int a, int b) {
|
||||
return a - _and(a, b) + b - _and(a, b);
|
||||
}
|
||||
|
||||
int _or(int a, int b) {
|
||||
return _xor(_xor(a, b), _and(a, b));
|
||||
}
|
||||
|
||||
// performs a SHA-1 hash to output.
|
||||
//
|
||||
// input is a list of ints, but only the lower 8 bits are used. Input must be
|
||||
// larger than the smallest 64 multiple.
|
||||
void pseudo_sha1(int input[], int input_len, int output[]) {
|
||||
int h0 = 1732584193;
|
||||
int h1 = -271733879;
|
||||
int h2 = -1732584194;
|
||||
int h3 = 271733878;
|
||||
int h4 = -1009589776;
|
||||
|
||||
int a;
|
||||
int b;
|
||||
int c;
|
||||
int d;
|
||||
int e;
|
||||
int f;
|
||||
int k;
|
||||
|
||||
// preprocessing
|
||||
int orig_len = input_len;
|
||||
input[input_len] = 0x80;
|
||||
input_len = input_len + 1;
|
||||
while (input_len % 64 != 60) {
|
||||
input[input_len] = 0;
|
||||
input_len = input_len + 1;
|
||||
}
|
||||
input[input_len] = orig_len / 16777216 % 256;
|
||||
input[input_len + 1] = orig_len / 65536 % 256;
|
||||
input[input_len + 2] = orig_len / 256 % 256;
|
||||
input[input_len + 3] = orig_len % 256;
|
||||
input_len = input_len + 4;
|
||||
|
||||
int chunk_start = 0;
|
||||
int words[80] = {0};
|
||||
while (chunk_start < input_len) {
|
||||
a = h0;
|
||||
b = h1;
|
||||
c = h2;
|
||||
d = h3;
|
||||
e = h4;
|
||||
|
||||
// populate words
|
||||
int i = 0;
|
||||
while (i < 16) {
|
||||
words[i] = input[chunk_start + i * 4] * 16777216 +
|
||||
input[chunk_start + i * 4 + 1] * 65536 +
|
||||
input[chunk_start + i * 4 + 2] * 256 +
|
||||
input[chunk_start + i * 4 + 3] * 1;
|
||||
i = i + 1;
|
||||
}
|
||||
while (i < 80) {
|
||||
words[i] =
|
||||
rotl1(_xor(_xor(_xor(words[i - 3], words[i - 8]), words[i - 14]),
|
||||
words[i - 16]));
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
// main loop
|
||||
i = 0;
|
||||
while (i < 80) {
|
||||
if (i < 20) {
|
||||
f = _or(_and(b, c), _and(_not(b), d));
|
||||
k = 1518500249;
|
||||
} else if (i < 40) {
|
||||
f = _xor(_xor(b, c), d);
|
||||
k = 1859775361;
|
||||
} else if (i < 60) {
|
||||
f = _or(_or(_and(b, c), _and(b, d)), _and(c, d));
|
||||
k = -1894007588;
|
||||
} else if (i < 80) {
|
||||
f = _xor(_xor(b, c), d);
|
||||
k = -899497722;
|
||||
}
|
||||
int t = rotl5(a) + f + e + k + words[i];
|
||||
e = d;
|
||||
d = c;
|
||||
c = rotl30(b);
|
||||
b = a;
|
||||
a = t;
|
||||
i = i + 1;
|
||||
}
|
||||
h0 = h0 + a;
|
||||
h1 = h1 + b;
|
||||
h2 = h2 + c;
|
||||
h3 = h3 + d;
|
||||
h4 = h4 + e;
|
||||
|
||||
chunk_start = chunk_start + 64;
|
||||
}
|
||||
output[0] = h0;
|
||||
output[1] = h1;
|
||||
output[2] = h2;
|
||||
output[3] = h3;
|
||||
output[4] = h4;
|
||||
}
|
||||
|
||||
int buffer[32768] = {0};
|
||||
|
||||
int main() {
|
||||
int rounds = 12;
|
||||
int i = 0;
|
||||
int output[5] = {0, 0, 0, 0, 0};
|
||||
int output_buf[5];
|
||||
state = getint();
|
||||
rounds = getint();
|
||||
|
||||
starttime();
|
||||
|
||||
output_buf[0] = 0;
|
||||
output_buf[1] = 0;
|
||||
output_buf[2] = 0;
|
||||
output_buf[3] = 0;
|
||||
output_buf[4] = 0;
|
||||
|
||||
while (rounds > 0) {
|
||||
int len = 32000;
|
||||
int i = 0;
|
||||
while (i < len) {
|
||||
buffer[i] = get_random() % 256;
|
||||
i = i + 1;
|
||||
}
|
||||
pseudo_sha1(buffer, len, output);
|
||||
i = 0;
|
||||
while (i < 5) {
|
||||
output_buf[i] = _xor(output_buf[i], output[i]);
|
||||
i = i + 1;
|
||||
}
|
||||
rounds = rounds - 1;
|
||||
}
|
||||
stoptime();
|
||||
|
||||
putarray(5, output_buf);
|
||||
return 0;
|
||||
}
|
||||
188
testcases/final_performance/crypto3.sy
Executable file
188
testcases/final_performance/crypto3.sy
Executable file
@ -0,0 +1,188 @@
|
||||
|
||||
|
||||
int state = 19260817;
|
||||
|
||||
int get_random() {
|
||||
state = state + (state * 8192);
|
||||
state = state + (state / 131072);
|
||||
state = state + (state * 32);
|
||||
return state;
|
||||
}
|
||||
|
||||
int rotl1(int x) {
|
||||
return x * 2 + x % 2;
|
||||
}
|
||||
|
||||
int rotl5(int x) {
|
||||
return x * 32 + x % 32;
|
||||
}
|
||||
|
||||
int rotl30(int x) {
|
||||
return x * 1073741824 + x % 1073741824;
|
||||
}
|
||||
|
||||
int _and(int a, int b) {
|
||||
// int c = 0;
|
||||
// int x = 0;
|
||||
// while (x <= 32) {
|
||||
// c = c + c;
|
||||
// if (a < 0) {
|
||||
// if (b < 0) {
|
||||
// c = c + 1;
|
||||
// }
|
||||
// }
|
||||
// a = a + a;
|
||||
// b = b + b;
|
||||
// x = x + 1;
|
||||
// }
|
||||
// return c;
|
||||
return a + b;
|
||||
}
|
||||
|
||||
int _not(int x) {
|
||||
return -1 - x;
|
||||
}
|
||||
|
||||
int _xor(int a, int b) {
|
||||
return a - _and(a, b) + b - _and(a, b);
|
||||
}
|
||||
|
||||
int _or(int a, int b) {
|
||||
return _xor(_xor(a, b), _and(a, b));
|
||||
}
|
||||
|
||||
// performs a SHA-1 hash to output.
|
||||
//
|
||||
// input is a list of ints, but only the lower 8 bits are used. Input must be
|
||||
// larger than the smallest 64 multiple.
|
||||
void pseudo_sha1(int input[], int input_len, int output[]) {
|
||||
int h0 = 1732584193;
|
||||
int h1 = -271733879;
|
||||
int h2 = -1732584194;
|
||||
int h3 = 271733878;
|
||||
int h4 = -1009589776;
|
||||
|
||||
int a;
|
||||
int b;
|
||||
int c;
|
||||
int d;
|
||||
int e;
|
||||
int f;
|
||||
int k;
|
||||
|
||||
// preprocessing
|
||||
int orig_len = input_len;
|
||||
input[input_len] = 0x80;
|
||||
input_len = input_len + 1;
|
||||
while (input_len % 64 != 60) {
|
||||
input[input_len] = 0;
|
||||
input_len = input_len + 1;
|
||||
}
|
||||
input[input_len] = orig_len / 16777216 % 256;
|
||||
input[input_len + 1] = orig_len / 65536 % 256;
|
||||
input[input_len + 2] = orig_len / 256 % 256;
|
||||
input[input_len + 3] = orig_len % 256;
|
||||
input_len = input_len + 4;
|
||||
|
||||
int chunk_start = 0;
|
||||
int words[80] = {0};
|
||||
while (chunk_start < input_len) {
|
||||
a = h0;
|
||||
b = h1;
|
||||
c = h2;
|
||||
d = h3;
|
||||
e = h4;
|
||||
|
||||
// populate words
|
||||
int i = 0;
|
||||
while (i < 16) {
|
||||
words[i] = input[chunk_start + i * 4] * 16777216 +
|
||||
input[chunk_start + i * 4 + 1] * 65536 +
|
||||
input[chunk_start + i * 4 + 2] * 256 +
|
||||
input[chunk_start + i * 4 + 3] * 1;
|
||||
i = i + 1;
|
||||
}
|
||||
while (i < 80) {
|
||||
words[i] =
|
||||
rotl1(_xor(_xor(_xor(words[i - 3], words[i - 8]), words[i - 14]),
|
||||
words[i - 16]));
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
// main loop
|
||||
i = 0;
|
||||
while (i < 80) {
|
||||
if (i < 20) {
|
||||
f = _or(_and(b, c), _and(_not(b), d));
|
||||
k = 1518500249;
|
||||
} else if (i < 40) {
|
||||
f = _xor(_xor(b, c), d);
|
||||
k = 1859775361;
|
||||
} else if (i < 60) {
|
||||
f = _or(_or(_and(b, c), _and(b, d)), _and(c, d));
|
||||
k = -1894007588;
|
||||
} else if (i < 80) {
|
||||
f = _xor(_xor(b, c), d);
|
||||
k = -899497722;
|
||||
}
|
||||
int t = rotl5(a) + f + e + k + words[i];
|
||||
e = d;
|
||||
d = c;
|
||||
c = rotl30(b);
|
||||
b = a;
|
||||
a = t;
|
||||
i = i + 1;
|
||||
}
|
||||
h0 = h0 + a;
|
||||
h1 = h1 + b;
|
||||
h2 = h2 + c;
|
||||
h3 = h3 + d;
|
||||
h4 = h4 + e;
|
||||
|
||||
chunk_start = chunk_start + 64;
|
||||
}
|
||||
output[0] = h0;
|
||||
output[1] = h1;
|
||||
output[2] = h2;
|
||||
output[3] = h3;
|
||||
output[4] = h4;
|
||||
}
|
||||
|
||||
int buffer[32768] = {0};
|
||||
|
||||
int main() {
|
||||
int rounds = 12;
|
||||
int i = 0;
|
||||
int output[5] = {0, 0, 0, 0, 0};
|
||||
int output_buf[5];
|
||||
state = getint();
|
||||
rounds = getint();
|
||||
|
||||
starttime();
|
||||
|
||||
output_buf[0] = 0;
|
||||
output_buf[1] = 0;
|
||||
output_buf[2] = 0;
|
||||
output_buf[3] = 0;
|
||||
output_buf[4] = 0;
|
||||
|
||||
while (rounds > 0) {
|
||||
int len = 32000;
|
||||
int i = 0;
|
||||
while (i < len) {
|
||||
buffer[i] = get_random() % 256;
|
||||
i = i + 1;
|
||||
}
|
||||
pseudo_sha1(buffer, len, output);
|
||||
i = 0;
|
||||
while (i < 5) {
|
||||
output_buf[i] = _xor(output_buf[i], output[i]);
|
||||
i = i + 1;
|
||||
}
|
||||
rounds = rounds - 1;
|
||||
}
|
||||
stoptime();
|
||||
|
||||
putarray(5, output_buf);
|
||||
return 0;
|
||||
}
|
||||
161
testcases/final_performance/derich1.sy
Normal file
161
testcases/final_performance/derich1.sy
Normal file
@ -0,0 +1,161 @@
|
||||
int w = 512;
|
||||
int h = 270;
|
||||
float imgIn[512][270];
|
||||
float imgOut[512][270];
|
||||
float my_y1[512][270];
|
||||
float my_y2[512][270];
|
||||
float alpha = 0.25;
|
||||
|
||||
float newExp(float x)
|
||||
{
|
||||
x = 1.0 + x / 256;
|
||||
x = x * x;
|
||||
x = x * x;
|
||||
x = x * x;
|
||||
x = x * x;
|
||||
x = x * x;
|
||||
x = x * x;
|
||||
x = x * x;
|
||||
x = x * x;
|
||||
return x;
|
||||
}
|
||||
|
||||
float newPow(float num, int n)
|
||||
{
|
||||
if (n < 0)
|
||||
return 1.0 / newPow(num, -n);
|
||||
else if (n == 0)
|
||||
return 1.0;
|
||||
else if (n > 0)
|
||||
return num * newPow(num, n - 1);
|
||||
}
|
||||
|
||||
void kernel_deriche(int w, int h, float alpha, float imgIn[][270],
|
||||
float imgOut[][270], float y1[][270], float y2[][270])
|
||||
{
|
||||
int i, j;
|
||||
float xm1, tm1, ym1, ym2;
|
||||
float xp1, xp2;
|
||||
float tp1, tp2;
|
||||
float yp1, yp2;
|
||||
|
||||
float k;
|
||||
float a1, a2, a3, a4, a5, a6, a7, a8;
|
||||
float b1, b2, c1, c2;
|
||||
|
||||
k = (1.0 - newExp(-alpha)) * (1.0 - newExp(-alpha)) /
|
||||
(1.0 + 2.0 * alpha * newExp(-alpha) - newExp(2.0 * alpha));
|
||||
a1 = k;
|
||||
a5 = k;
|
||||
a6 = k * newExp(-alpha) * (alpha - 1.0);
|
||||
a2 = a6;
|
||||
a7 = k * newExp(-alpha) * (alpha + 1.0);
|
||||
a3 = a7;
|
||||
a8 = -k * newExp(-2.0 * alpha);
|
||||
a4 = a8;
|
||||
b1 = newPow(2.0, -alpha);
|
||||
b2 = -newExp(-2.0 * alpha);
|
||||
c1 = 1;
|
||||
c2 = 1;
|
||||
i = 0;
|
||||
while (i < w)
|
||||
{
|
||||
ym1 = 0.0;
|
||||
ym2 = 0.0;
|
||||
xm1 = 0.0;
|
||||
j = 0;
|
||||
while (j < h)
|
||||
{
|
||||
y1[i][j] = a1 * imgIn[i][j] + a2 * xm1 + b1 * ym1 + b2 * ym2;
|
||||
xm1 = imgIn[i][j];
|
||||
ym2 = ym1;
|
||||
ym1 = y1[i][j];
|
||||
j = j + 1;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
i = 0;
|
||||
while (i < w)
|
||||
{
|
||||
yp1 = 0.0;
|
||||
yp2 = 0.0;
|
||||
xp1 = 0.0;
|
||||
xp2 = 0.0;
|
||||
j = h - 1;
|
||||
while (j >= 0)
|
||||
{
|
||||
y2[i][j] = a3 * xp1 + a4 * xp2 + b1 * yp1 + b2 * yp2;
|
||||
xp2 = xp1;
|
||||
xp1 = imgIn[i][j];
|
||||
yp2 = yp1;
|
||||
yp1 = y2[i][j];
|
||||
j = j - 1;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
i = 0;
|
||||
while (i < w) {
|
||||
j = 0;
|
||||
while (j < h)
|
||||
{
|
||||
imgOut[i][j] = c1 * (y1[i][j] + y2[i][j]);
|
||||
j = j + 1;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
j = 0;
|
||||
while (j < h)
|
||||
{
|
||||
tm1 = 0.0;
|
||||
ym1 = 0.0;
|
||||
ym2 = 0.0;
|
||||
i = 0;
|
||||
while (i < w)
|
||||
{
|
||||
y1[i][j] = a5 * imgOut[i][j] + a6 * tm1 + b1 * ym1 + b2 * ym2;
|
||||
tm1 = imgOut[i][j];
|
||||
ym2 = ym1;
|
||||
ym1 = y1[i][j];
|
||||
i = i + 1;
|
||||
}
|
||||
j = j + 1;
|
||||
}
|
||||
j = 0;
|
||||
while (j < h)
|
||||
{
|
||||
tp1 = 0.0;
|
||||
tp2 = 0.0;
|
||||
yp1 = 0.0;
|
||||
yp2 = 0.0;
|
||||
i = w - 1;
|
||||
while (i >= 0)
|
||||
{
|
||||
y2[i][j] = a7 * tp1 + a8 * tp2 + b1 * yp1 + b2 * yp2;
|
||||
tp2 = tp1;
|
||||
tp1 = imgOut[i][j];
|
||||
yp2 = yp1;
|
||||
yp1 = y2[i][j];
|
||||
i = i - 1;
|
||||
}
|
||||
j = j + 1;
|
||||
}
|
||||
i = 0;
|
||||
while (i < w) {
|
||||
j = 0;
|
||||
while (j < h) {
|
||||
imgOut[i][j] = c2 * (y1[i][j] + y2[i][j]);
|
||||
j = j + 1;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
getfarray(imgIn);
|
||||
starttime();
|
||||
kernel_deriche(w, h, alpha, imgIn, imgOut, my_y1, my_y2);
|
||||
stoptime();
|
||||
putfarray(w * h, imgOut);
|
||||
return 0;
|
||||
}
|
||||
161
testcases/final_performance/derich2.sy
Normal file
161
testcases/final_performance/derich2.sy
Normal file
@ -0,0 +1,161 @@
|
||||
int w = 512;
|
||||
int h = 270;
|
||||
float imgIn[512][270];
|
||||
float imgOut[512][270];
|
||||
float my_y1[512][270];
|
||||
float my_y2[512][270];
|
||||
float alpha = 0.25;
|
||||
|
||||
float newExp(float x)
|
||||
{
|
||||
x = 1.0 + x / 256;
|
||||
x = x * x;
|
||||
x = x * x;
|
||||
x = x * x;
|
||||
x = x * x;
|
||||
x = x * x;
|
||||
x = x * x;
|
||||
x = x * x;
|
||||
x = x * x;
|
||||
return x;
|
||||
}
|
||||
|
||||
float newPow(float num, int n)
|
||||
{
|
||||
if (n < 0)
|
||||
return 1.0 / newPow(num, -n);
|
||||
else if (n == 0)
|
||||
return 1.0;
|
||||
else if (n > 0)
|
||||
return num * newPow(num, n - 1);
|
||||
}
|
||||
|
||||
void kernel_deriche(int w, int h, float alpha, float imgIn[][270],
|
||||
float imgOut[][270], float y1[][270], float y2[][270])
|
||||
{
|
||||
int i, j;
|
||||
float xm1, tm1, ym1, ym2;
|
||||
float xp1, xp2;
|
||||
float tp1, tp2;
|
||||
float yp1, yp2;
|
||||
|
||||
float k;
|
||||
float a1, a2, a3, a4, a5, a6, a7, a8;
|
||||
float b1, b2, c1, c2;
|
||||
|
||||
k = (1.0 - newExp(-alpha)) * (1.0 - newExp(-alpha)) /
|
||||
(1.0 + 2.0 * alpha * newExp(-alpha) - newExp(2.0 * alpha));
|
||||
a1 = k;
|
||||
a5 = k;
|
||||
a6 = k * newExp(-alpha) * (alpha - 1.0);
|
||||
a2 = a6;
|
||||
a7 = k * newExp(-alpha) * (alpha + 1.0);
|
||||
a3 = a7;
|
||||
a8 = -k * newExp(-2.0 * alpha);
|
||||
a4 = a8;
|
||||
b1 = newPow(2.0, -alpha);
|
||||
b2 = -newExp(-2.0 * alpha);
|
||||
c1 = 1;
|
||||
c2 = 1;
|
||||
i = 0;
|
||||
while (i < w)
|
||||
{
|
||||
ym1 = 0.0;
|
||||
ym2 = 0.0;
|
||||
xm1 = 0.0;
|
||||
j = 0;
|
||||
while (j < h)
|
||||
{
|
||||
y1[i][j] = a1 * imgIn[i][j] + a2 * xm1 + b1 * ym1 + b2 * ym2;
|
||||
xm1 = imgIn[i][j];
|
||||
ym2 = ym1;
|
||||
ym1 = y1[i][j];
|
||||
j = j + 1;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
i = 0;
|
||||
while (i < w)
|
||||
{
|
||||
yp1 = 0.0;
|
||||
yp2 = 0.0;
|
||||
xp1 = 0.0;
|
||||
xp2 = 0.0;
|
||||
j = h - 1;
|
||||
while (j >= 0)
|
||||
{
|
||||
y2[i][j] = a3 * xp1 + a4 * xp2 + b1 * yp1 + b2 * yp2;
|
||||
xp2 = xp1;
|
||||
xp1 = imgIn[i][j];
|
||||
yp2 = yp1;
|
||||
yp1 = y2[i][j];
|
||||
j = j - 1;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
i = 0;
|
||||
while (i < w) {
|
||||
j = 0;
|
||||
while (j < h)
|
||||
{
|
||||
imgOut[i][j] = c1 * (y1[i][j] + y2[i][j]);
|
||||
j = j + 1;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
j = 0;
|
||||
while (j < h)
|
||||
{
|
||||
tm1 = 0.0;
|
||||
ym1 = 0.0;
|
||||
ym2 = 0.0;
|
||||
i = 0;
|
||||
while (i < w)
|
||||
{
|
||||
y1[i][j] = a5 * imgOut[i][j] + a6 * tm1 + b1 * ym1 + b2 * ym2;
|
||||
tm1 = imgOut[i][j];
|
||||
ym2 = ym1;
|
||||
ym1 = y1[i][j];
|
||||
i = i + 1;
|
||||
}
|
||||
j = j + 1;
|
||||
}
|
||||
j = 0;
|
||||
while (j < h)
|
||||
{
|
||||
tp1 = 0.0;
|
||||
tp2 = 0.0;
|
||||
yp1 = 0.0;
|
||||
yp2 = 0.0;
|
||||
i = w - 1;
|
||||
while (i >= 0)
|
||||
{
|
||||
y2[i][j] = a7 * tp1 + a8 * tp2 + b1 * yp1 + b2 * yp2;
|
||||
tp2 = tp1;
|
||||
tp1 = imgOut[i][j];
|
||||
yp2 = yp1;
|
||||
yp1 = y2[i][j];
|
||||
i = i - 1;
|
||||
}
|
||||
j = j + 1;
|
||||
}
|
||||
i = 0;
|
||||
while (i < w) {
|
||||
j = 0;
|
||||
while (j < h) {
|
||||
imgOut[i][j] = c2 * (y1[i][j] + y2[i][j]);
|
||||
j = j + 1;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
getfarray(imgIn);
|
||||
starttime();
|
||||
kernel_deriche(w, h, alpha, imgIn, imgOut, my_y1, my_y2);
|
||||
stoptime();
|
||||
putfarray(w * h, imgOut);
|
||||
return 0;
|
||||
}
|
||||
161
testcases/final_performance/derich3.sy
Normal file
161
testcases/final_performance/derich3.sy
Normal file
@ -0,0 +1,161 @@
|
||||
int w = 512;
|
||||
int h = 270;
|
||||
float imgIn[512][270];
|
||||
float imgOut[512][270];
|
||||
float my_y1[512][270];
|
||||
float my_y2[512][270];
|
||||
float alpha = 0.25;
|
||||
|
||||
float newExp(float x)
|
||||
{
|
||||
x = 1.0 + x / 256;
|
||||
x = x * x;
|
||||
x = x * x;
|
||||
x = x * x;
|
||||
x = x * x;
|
||||
x = x * x;
|
||||
x = x * x;
|
||||
x = x * x;
|
||||
x = x * x;
|
||||
return x;
|
||||
}
|
||||
|
||||
float newPow(float num, int n)
|
||||
{
|
||||
if (n < 0)
|
||||
return 1.0 / newPow(num, -n);
|
||||
else if (n == 0)
|
||||
return 1.0;
|
||||
else if (n > 0)
|
||||
return num * newPow(num, n - 1);
|
||||
}
|
||||
|
||||
void kernel_deriche(int w, int h, float alpha, float imgIn[][270],
|
||||
float imgOut[][270], float y1[][270], float y2[][270])
|
||||
{
|
||||
int i, j;
|
||||
float xm1, tm1, ym1, ym2;
|
||||
float xp1, xp2;
|
||||
float tp1, tp2;
|
||||
float yp1, yp2;
|
||||
|
||||
float k;
|
||||
float a1, a2, a3, a4, a5, a6, a7, a8;
|
||||
float b1, b2, c1, c2;
|
||||
|
||||
k = (1.0 - newExp(-alpha)) * (1.0 - newExp(-alpha)) /
|
||||
(1.0 + 2.0 * alpha * newExp(-alpha) - newExp(2.0 * alpha));
|
||||
a1 = k;
|
||||
a5 = k;
|
||||
a6 = k * newExp(-alpha) * (alpha - 1.0);
|
||||
a2 = a6;
|
||||
a7 = k * newExp(-alpha) * (alpha + 1.0);
|
||||
a3 = a7;
|
||||
a8 = -k * newExp(-2.0 * alpha);
|
||||
a4 = a8;
|
||||
b1 = newPow(2.0, -alpha);
|
||||
b2 = -newExp(-2.0 * alpha);
|
||||
c1 = 1;
|
||||
c2 = 1;
|
||||
i = 0;
|
||||
while (i < w)
|
||||
{
|
||||
ym1 = 0.0;
|
||||
ym2 = 0.0;
|
||||
xm1 = 0.0;
|
||||
j = 0;
|
||||
while (j < h)
|
||||
{
|
||||
y1[i][j] = a1 * imgIn[i][j] + a2 * xm1 + b1 * ym1 + b2 * ym2;
|
||||
xm1 = imgIn[i][j];
|
||||
ym2 = ym1;
|
||||
ym1 = y1[i][j];
|
||||
j = j + 1;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
i = 0;
|
||||
while (i < w)
|
||||
{
|
||||
yp1 = 0.0;
|
||||
yp2 = 0.0;
|
||||
xp1 = 0.0;
|
||||
xp2 = 0.0;
|
||||
j = h - 1;
|
||||
while (j >= 0)
|
||||
{
|
||||
y2[i][j] = a3 * xp1 + a4 * xp2 + b1 * yp1 + b2 * yp2;
|
||||
xp2 = xp1;
|
||||
xp1 = imgIn[i][j];
|
||||
yp2 = yp1;
|
||||
yp1 = y2[i][j];
|
||||
j = j - 1;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
i = 0;
|
||||
while (i < w) {
|
||||
j = 0;
|
||||
while (j < h)
|
||||
{
|
||||
imgOut[i][j] = c1 * (y1[i][j] + y2[i][j]);
|
||||
j = j + 1;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
j = 0;
|
||||
while (j < h)
|
||||
{
|
||||
tm1 = 0.0;
|
||||
ym1 = 0.0;
|
||||
ym2 = 0.0;
|
||||
i = 0;
|
||||
while (i < w)
|
||||
{
|
||||
y1[i][j] = a5 * imgOut[i][j] + a6 * tm1 + b1 * ym1 + b2 * ym2;
|
||||
tm1 = imgOut[i][j];
|
||||
ym2 = ym1;
|
||||
ym1 = y1[i][j];
|
||||
i = i + 1;
|
||||
}
|
||||
j = j + 1;
|
||||
}
|
||||
j = 0;
|
||||
while (j < h)
|
||||
{
|
||||
tp1 = 0.0;
|
||||
tp2 = 0.0;
|
||||
yp1 = 0.0;
|
||||
yp2 = 0.0;
|
||||
i = w - 1;
|
||||
while (i >= 0)
|
||||
{
|
||||
y2[i][j] = a7 * tp1 + a8 * tp2 + b1 * yp1 + b2 * yp2;
|
||||
tp2 = tp1;
|
||||
tp1 = imgOut[i][j];
|
||||
yp2 = yp1;
|
||||
yp1 = y2[i][j];
|
||||
i = i - 1;
|
||||
}
|
||||
j = j + 1;
|
||||
}
|
||||
i = 0;
|
||||
while (i < w) {
|
||||
j = 0;
|
||||
while (j < h) {
|
||||
imgOut[i][j] = c2 * (y1[i][j] + y2[i][j]);
|
||||
j = j + 1;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
getfarray(imgIn);
|
||||
starttime();
|
||||
kernel_deriche(w, h, alpha, imgIn, imgOut, my_y1, my_y2);
|
||||
stoptime();
|
||||
putfarray(w * h, imgOut);
|
||||
return 0;
|
||||
}
|
||||
82
testcases/final_performance/fft0.sy
Executable file
82
testcases/final_performance/fft0.sy
Executable file
@ -0,0 +1,82 @@
|
||||
const int mod = 998244353;
|
||||
int d;
|
||||
|
||||
int multiply(int a, int b){
|
||||
if (b == 0) return 0;
|
||||
if (b == 1) return a % mod;
|
||||
int cur = multiply(a, b/2);
|
||||
cur = (cur + cur) % mod;
|
||||
if (b % 2 == 1) return (cur + a) % mod;
|
||||
else return cur;
|
||||
}
|
||||
|
||||
int power(int a, int b){
|
||||
if (b == 0) return 1;
|
||||
int cur = power(a, b/2);
|
||||
cur = multiply(cur, cur);
|
||||
if (b % 2 == 1) return multiply(cur, a);
|
||||
else return cur;
|
||||
}
|
||||
const int maxlen = 2097152;
|
||||
int temp[maxlen], a[maxlen], b[maxlen], c[maxlen];
|
||||
|
||||
int memmove(int dst[], int dst_pos, int src[], int len){
|
||||
int i = 0;
|
||||
while (i < len){
|
||||
dst[dst_pos + i] = src[i];
|
||||
i = i + 1;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
int fft(int arr[], int begin_pos, int n, int w){
|
||||
if (n == 1) return 1;
|
||||
int i = 0;
|
||||
while (i < n){
|
||||
if (i % 2 == 0) temp[i / 2] = arr[i + begin_pos];
|
||||
else temp[n / 2 + i / 2] = arr[i + begin_pos];
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
memmove(arr, begin_pos, temp, n);
|
||||
fft(arr, begin_pos, n / 2, multiply(w, w));
|
||||
fft(arr, begin_pos + n / 2, n / 2, multiply(w, w));
|
||||
i = 0;
|
||||
int wn = 1;
|
||||
while (i < n / 2){
|
||||
int x = arr[begin_pos + i];
|
||||
int y = arr[begin_pos + i + n / 2];
|
||||
arr[begin_pos + i] = (x + multiply(wn, y)) % mod;
|
||||
arr[begin_pos + i + n / 2] = (x - multiply(wn, y) + mod) % mod;
|
||||
wn = multiply(wn, w);
|
||||
i = i + 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(){
|
||||
int n = getarray(a);
|
||||
int m = getarray(b);
|
||||
starttime();
|
||||
d = 1;
|
||||
while (d < n + m - 1){
|
||||
d = d * 2;
|
||||
}
|
||||
fft(a, 0, d, power(3, (mod - 1) / d));
|
||||
fft(b, 0, d, power(3, (mod - 1) / d));
|
||||
|
||||
int i = 0;
|
||||
while (i < d){
|
||||
a[i] = multiply(a[i], b[i]);
|
||||
i = i + 1;
|
||||
}
|
||||
fft(a, 0, d, power(3, mod-1 - (mod-1)/d));
|
||||
i = 0;
|
||||
while (i < d){
|
||||
a[i] = multiply(a[i], power(d, mod-2));
|
||||
i = i + 1;
|
||||
}
|
||||
stoptime();
|
||||
putarray(n + m - 1, a);
|
||||
return 0;
|
||||
}
|
||||
82
testcases/final_performance/fft1.sy
Executable file
82
testcases/final_performance/fft1.sy
Executable file
@ -0,0 +1,82 @@
|
||||
const int mod = 998244353;
|
||||
int d;
|
||||
|
||||
int multiply(int a, int b){
|
||||
if (b == 0) return 0;
|
||||
if (b == 1) return a % mod;
|
||||
int cur = multiply(a, b/2);
|
||||
cur = (cur + cur) % mod;
|
||||
if (b % 2 == 1) return (cur + a) % mod;
|
||||
else return cur;
|
||||
}
|
||||
|
||||
int power(int a, int b){
|
||||
if (b == 0) return 1;
|
||||
int cur = power(a, b/2);
|
||||
cur = multiply(cur, cur);
|
||||
if (b % 2 == 1) return multiply(cur, a);
|
||||
else return cur;
|
||||
}
|
||||
const int maxlen = 2097152;
|
||||
int temp[maxlen], a[maxlen], b[maxlen], c[maxlen];
|
||||
|
||||
int memmove(int dst[], int dst_pos, int src[], int len){
|
||||
int i = 0;
|
||||
while (i < len){
|
||||
dst[dst_pos + i] = src[i];
|
||||
i = i + 1;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
int fft(int arr[], int begin_pos, int n, int w){
|
||||
if (n == 1) return 1;
|
||||
int i = 0;
|
||||
while (i < n){
|
||||
if (i % 2 == 0) temp[i / 2] = arr[i + begin_pos];
|
||||
else temp[n / 2 + i / 2] = arr[i + begin_pos];
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
memmove(arr, begin_pos, temp, n);
|
||||
fft(arr, begin_pos, n / 2, multiply(w, w));
|
||||
fft(arr, begin_pos + n / 2, n / 2, multiply(w, w));
|
||||
i = 0;
|
||||
int wn = 1;
|
||||
while (i < n / 2){
|
||||
int x = arr[begin_pos + i];
|
||||
int y = arr[begin_pos + i + n / 2];
|
||||
arr[begin_pos + i] = (x + multiply(wn, y)) % mod;
|
||||
arr[begin_pos + i + n / 2] = (x - multiply(wn, y) + mod) % mod;
|
||||
wn = multiply(wn, w);
|
||||
i = i + 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(){
|
||||
int n = getarray(a);
|
||||
int m = getarray(b);
|
||||
starttime();
|
||||
d = 1;
|
||||
while (d < n + m - 1){
|
||||
d = d * 2;
|
||||
}
|
||||
fft(a, 0, d, power(3, (mod - 1) / d));
|
||||
fft(b, 0, d, power(3, (mod - 1) / d));
|
||||
|
||||
int i = 0;
|
||||
while (i < d){
|
||||
a[i] = multiply(a[i], b[i]);
|
||||
i = i + 1;
|
||||
}
|
||||
fft(a, 0, d, power(3, mod-1 - (mod-1)/d));
|
||||
i = 0;
|
||||
while (i < d){
|
||||
a[i] = multiply(a[i], power(d, mod-2));
|
||||
i = i + 1;
|
||||
}
|
||||
stoptime();
|
||||
putarray(n + m - 1, a);
|
||||
return 0;
|
||||
}
|
||||
82
testcases/final_performance/fft2.sy
Executable file
82
testcases/final_performance/fft2.sy
Executable file
@ -0,0 +1,82 @@
|
||||
const int mod = 998244353;
|
||||
int d;
|
||||
|
||||
int multiply(int a, int b){
|
||||
if (b == 0) return 0;
|
||||
if (b == 1) return a % mod;
|
||||
int cur = multiply(a, b/2);
|
||||
cur = (cur + cur) % mod;
|
||||
if (b % 2 == 1) return (cur + a) % mod;
|
||||
else return cur;
|
||||
}
|
||||
|
||||
int power(int a, int b){
|
||||
if (b == 0) return 1;
|
||||
int cur = power(a, b/2);
|
||||
cur = multiply(cur, cur);
|
||||
if (b % 2 == 1) return multiply(cur, a);
|
||||
else return cur;
|
||||
}
|
||||
const int maxlen = 2097152;
|
||||
int temp[maxlen], a[maxlen], b[maxlen], c[maxlen];
|
||||
|
||||
int memmove(int dst[], int dst_pos, int src[], int len){
|
||||
int i = 0;
|
||||
while (i < len){
|
||||
dst[dst_pos + i] = src[i];
|
||||
i = i + 1;
|
||||
}
|
||||
return i;
|
||||
}
|
||||
|
||||
int fft(int arr[], int begin_pos, int n, int w){
|
||||
if (n == 1) return 1;
|
||||
int i = 0;
|
||||
while (i < n){
|
||||
if (i % 2 == 0) temp[i / 2] = arr[i + begin_pos];
|
||||
else temp[n / 2 + i / 2] = arr[i + begin_pos];
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
memmove(arr, begin_pos, temp, n);
|
||||
fft(arr, begin_pos, n / 2, multiply(w, w));
|
||||
fft(arr, begin_pos + n / 2, n / 2, multiply(w, w));
|
||||
i = 0;
|
||||
int wn = 1;
|
||||
while (i < n / 2){
|
||||
int x = arr[begin_pos + i];
|
||||
int y = arr[begin_pos + i + n / 2];
|
||||
arr[begin_pos + i] = (x + multiply(wn, y)) % mod;
|
||||
arr[begin_pos + i + n / 2] = (x - multiply(wn, y) + mod) % mod;
|
||||
wn = multiply(wn, w);
|
||||
i = i + 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(){
|
||||
int n = getarray(a);
|
||||
int m = getarray(b);
|
||||
starttime();
|
||||
d = 1;
|
||||
while (d < n + m - 1){
|
||||
d = d * 2;
|
||||
}
|
||||
fft(a, 0, d, power(3, (mod - 1) / d));
|
||||
fft(b, 0, d, power(3, (mod - 1) / d));
|
||||
|
||||
int i = 0;
|
||||
while (i < d){
|
||||
a[i] = multiply(a[i], b[i]);
|
||||
i = i + 1;
|
||||
}
|
||||
fft(a, 0, d, power(3, mod-1 - (mod-1)/d));
|
||||
i = 0;
|
||||
while (i < d){
|
||||
a[i] = multiply(a[i], power(d, mod-2));
|
||||
i = i + 1;
|
||||
}
|
||||
stoptime();
|
||||
putarray(n + m - 1, a);
|
||||
return 0;
|
||||
}
|
||||
112
testcases/final_performance/gameoflife-oscillator.sy
Executable file
112
testcases/final_performance/gameoflife-oscillator.sy
Executable file
@ -0,0 +1,112 @@
|
||||
int sheet1[500][500] = {};
|
||||
int sheet2[500][500] = {};
|
||||
int active = 1;
|
||||
int width;
|
||||
int height;
|
||||
int steps;
|
||||
|
||||
void read_map() {
|
||||
width = getint();
|
||||
height = getint();
|
||||
// width <= 498, height <= 498
|
||||
steps = getint();
|
||||
getch();
|
||||
|
||||
int i = 1;
|
||||
int j = 1;
|
||||
|
||||
while (j <= height) {
|
||||
i = 1;
|
||||
while (i <= width) {
|
||||
int get = getch();
|
||||
if (get == 35) {
|
||||
sheet1[j][i] = 1;
|
||||
} else {
|
||||
sheet1[j][i] = 0;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
// line feed
|
||||
getch();
|
||||
j = j + 1;
|
||||
}
|
||||
}
|
||||
|
||||
void put_map() {
|
||||
int i = 1;
|
||||
int j = 1;
|
||||
|
||||
while (j <= height) {
|
||||
i = 1;
|
||||
while (i <= width) {
|
||||
if (sheet1[j][i] == 1) {
|
||||
putch(35);
|
||||
} else {
|
||||
putch(46);
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
// line feed
|
||||
putch(10);
|
||||
j = j + 1;
|
||||
}
|
||||
}
|
||||
|
||||
void swap12() {
|
||||
int i = 1;
|
||||
int j = 1;
|
||||
|
||||
while (j <= height) {
|
||||
i = 1;
|
||||
while (i <= width) {
|
||||
sheet1[j][i] = sheet2[j][i];
|
||||
i = i + 1;
|
||||
}
|
||||
j = j + 1;
|
||||
}
|
||||
}
|
||||
|
||||
void step(int source[][500], int target[][500]) {
|
||||
int i = 1;
|
||||
int j = 1;
|
||||
|
||||
while (j <= height) {
|
||||
i = 1;
|
||||
while (i <= width) {
|
||||
int alive_count = source[j - 1][i - 1] + source[j - 1][i] +
|
||||
source[j - 1][i + 1] + source[j][i - 1] +
|
||||
source[j][i + 1] + source[j + 1][i - 1] +
|
||||
source[j + 1][i] + source[j + 1][i + 1];
|
||||
if (source[j][i] == 1 && alive_count == 2 ) {
|
||||
target[j][i] = 1;
|
||||
} else if (alive_count == 3) {
|
||||
target[j][i] = 1;
|
||||
} else {
|
||||
target[j][i] = 0;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
j = j + 1;
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
read_map();
|
||||
starttime();
|
||||
while (steps > 0) {
|
||||
if (active == 1) {
|
||||
step(sheet1, sheet2);
|
||||
active = 2;
|
||||
} else {
|
||||
step(sheet2, sheet1);
|
||||
active = 1;
|
||||
}
|
||||
steps = steps - 1;
|
||||
}
|
||||
stoptime();
|
||||
if (active == 2) {
|
||||
swap12();
|
||||
}
|
||||
put_map();
|
||||
return 0;
|
||||
}
|
||||
112
testcases/final_performance/gameoflife-p61glidergun.sy
Executable file
112
testcases/final_performance/gameoflife-p61glidergun.sy
Executable file
@ -0,0 +1,112 @@
|
||||
int sheet1[500][500] = {};
|
||||
int sheet2[500][500] = {};
|
||||
int active = 1;
|
||||
int width;
|
||||
int height;
|
||||
int steps;
|
||||
|
||||
void read_map() {
|
||||
width = getint();
|
||||
height = getint();
|
||||
// width <= 498, height <= 498
|
||||
steps = getint();
|
||||
getch();
|
||||
|
||||
int i = 1;
|
||||
int j = 1;
|
||||
|
||||
while (j <= height) {
|
||||
i = 1;
|
||||
while (i <= width) {
|
||||
int get = getch();
|
||||
if (get == 35) {
|
||||
sheet1[j][i] = 1;
|
||||
} else {
|
||||
sheet1[j][i] = 0;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
// line feed
|
||||
getch();
|
||||
j = j + 1;
|
||||
}
|
||||
}
|
||||
|
||||
void put_map() {
|
||||
int i = 1;
|
||||
int j = 1;
|
||||
|
||||
while (j <= height) {
|
||||
i = 1;
|
||||
while (i <= width) {
|
||||
if (sheet1[j][i] == 1) {
|
||||
putch(35);
|
||||
} else {
|
||||
putch(46);
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
// line feed
|
||||
putch(10);
|
||||
j = j + 1;
|
||||
}
|
||||
}
|
||||
|
||||
void swap12() {
|
||||
int i = 1;
|
||||
int j = 1;
|
||||
|
||||
while (j <= height) {
|
||||
i = 1;
|
||||
while (i <= width) {
|
||||
sheet1[j][i] = sheet2[j][i];
|
||||
i = i + 1;
|
||||
}
|
||||
j = j + 1;
|
||||
}
|
||||
}
|
||||
|
||||
void step(int source[][500], int target[][500]) {
|
||||
int i = 1;
|
||||
int j = 1;
|
||||
|
||||
while (j <= height) {
|
||||
i = 1;
|
||||
while (i <= width) {
|
||||
int alive_count = source[j - 1][i - 1] + source[j - 1][i] +
|
||||
source[j - 1][i + 1] + source[j][i - 1] +
|
||||
source[j][i + 1] + source[j + 1][i - 1] +
|
||||
source[j + 1][i] + source[j + 1][i + 1];
|
||||
if (source[j][i] == 1 && alive_count == 2 ) {
|
||||
target[j][i] = 1;
|
||||
} else if (alive_count == 3) {
|
||||
target[j][i] = 1;
|
||||
} else {
|
||||
target[j][i] = 0;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
j = j + 1;
|
||||
}
|
||||
}
|
||||
|
||||
int main() {
|
||||
read_map();
|
||||
starttime();
|
||||
while (steps > 0) {
|
||||
if (active == 1) {
|
||||
step(sheet1, sheet2);
|
||||
active = 2;
|
||||
} else {
|
||||
step(sheet2, sheet1);
|
||||
active = 1;
|
||||
}
|
||||
steps = steps - 1;
|
||||
}
|
||||
stoptime();
|
||||
if (active == 2) {
|
||||
swap12();
|
||||
}
|
||||
put_map();
|
||||
return 0;
|
||||
}
|
||||
331
testcases/final_performance/if-combine1.sy
Normal file
331
testcases/final_performance/if-combine1.sy
Normal file
@ -0,0 +1,331 @@
|
||||
int func(int n) {
|
||||
int sum = 0;
|
||||
int i = 200;
|
||||
int j = 0;
|
||||
int s[100];
|
||||
int m = 0;
|
||||
|
||||
while (m < 100){
|
||||
s[m] = 0;
|
||||
m=m+1;
|
||||
}
|
||||
while(j < n) {
|
||||
if (i > 1){
|
||||
s[1] = 1;
|
||||
if (i > 2){
|
||||
s[2] = 2;
|
||||
if (i > 3){
|
||||
s[3] = 3;
|
||||
if (i > 4){
|
||||
s[4] = 4;
|
||||
if (i > 5){
|
||||
s[5] = 5;
|
||||
if (i > 6){
|
||||
s[6] = 6;
|
||||
if (i > 7){
|
||||
s[7] = 7;
|
||||
if (i > 8){
|
||||
s[8] = 8;
|
||||
if (i > 9){
|
||||
s[9] = 9;
|
||||
if (i > 10){
|
||||
s[10] = 10;
|
||||
if (i > 11){
|
||||
s[11] = 11;
|
||||
if (i > 12){
|
||||
s[12] = 12;
|
||||
if (i > 13){
|
||||
s[13] = 13;
|
||||
if (i > 14){
|
||||
s[14] = 14;
|
||||
if (i > 15){
|
||||
s[15] = 15;
|
||||
if (i > 16){
|
||||
s[16] = 16;
|
||||
if (i > 17){
|
||||
s[17] = 17;
|
||||
if (i > 18){
|
||||
s[18] = 18;
|
||||
if (i > 19){
|
||||
s[19] = 19;
|
||||
if (i > 20){
|
||||
s[20] = 20;
|
||||
if (i > 21){
|
||||
s[21] = 21;
|
||||
if (i > 22){
|
||||
s[22] = 22;
|
||||
if (i > 23){
|
||||
s[23] = 23;
|
||||
if (i > 24){
|
||||
s[24] = 24;
|
||||
if (i > 25){
|
||||
s[25] = 25;
|
||||
if (i > 26){
|
||||
s[26] = 26;
|
||||
if (i > 27){
|
||||
s[27] = 27;
|
||||
if (i > 28){
|
||||
s[28] = 28;
|
||||
if (i > 29){
|
||||
s[29] = 29;
|
||||
if (i > 30){
|
||||
s[30] = 30;
|
||||
if (i > 31){
|
||||
s[31] = 31;
|
||||
if (i > 32){
|
||||
s[32] = 32;
|
||||
if (i > 33){
|
||||
s[33] = 33;
|
||||
if (i > 34){
|
||||
s[34] = 34;
|
||||
if (i > 35){
|
||||
s[35] = 35;
|
||||
if (i > 36){
|
||||
s[36] = 36;
|
||||
if (i > 37){
|
||||
s[37] = 37;
|
||||
if (i > 38){
|
||||
s[38] = 38;
|
||||
if (i > 39){
|
||||
s[39] = 39;
|
||||
if (i > 40){
|
||||
s[40] = 40;
|
||||
if (i > 41){
|
||||
s[41] = 41;
|
||||
if (i > 42){
|
||||
s[42] = 42;
|
||||
if (i > 43){
|
||||
s[43] = 43;
|
||||
if (i > 44){
|
||||
s[44] = 44;
|
||||
if (i > 45){
|
||||
s[45] = 45;
|
||||
if (i > 46){
|
||||
s[46] = 46;
|
||||
if (i > 47){
|
||||
s[47] = 47;
|
||||
if (i > 48){
|
||||
s[48] = 48;
|
||||
if (i > 49){
|
||||
s[49] = 49;
|
||||
if (i > 50){
|
||||
s[50] = 50;
|
||||
if (i > 51){
|
||||
s[51] = 51;
|
||||
if (i > 52){
|
||||
s[52] = 52;
|
||||
if (i > 53){
|
||||
s[53] = 53;
|
||||
if (i > 54){
|
||||
s[54] = 54;
|
||||
if (i > 55){
|
||||
s[55] = 55;
|
||||
if (i > 56){
|
||||
s[56] = 56;
|
||||
if (i > 57){
|
||||
s[57] = 57;
|
||||
if (i > 58){
|
||||
s[58] = 58;
|
||||
if (i > 59){
|
||||
s[59] = 59;
|
||||
if (i > 60){
|
||||
s[60] = 60;
|
||||
if (i > 61){
|
||||
s[61] = 61;
|
||||
if (i > 62){
|
||||
s[62] = 62;
|
||||
if (i > 63){
|
||||
s[63] = 63;
|
||||
if (i > 64){
|
||||
s[64] = 64;
|
||||
if (i > 65){
|
||||
s[65] = 65;
|
||||
if (i > 66){
|
||||
s[66] = 66;
|
||||
if (i > 67){
|
||||
s[67] = 67;
|
||||
if (i > 68){
|
||||
s[68] = 68;
|
||||
if (i > 69){
|
||||
s[69] = 69;
|
||||
if (i > 70){
|
||||
s[70] = 70;
|
||||
if (i > 71){
|
||||
s[71] = 71;
|
||||
if (i > 72){
|
||||
s[72] = 72;
|
||||
if (i > 73){
|
||||
s[73] = 73;
|
||||
if (i > 74){
|
||||
s[74] = 74;
|
||||
if (i > 75){
|
||||
s[75] = 75;
|
||||
if (i > 76){
|
||||
s[76] = 76;
|
||||
if (i > 77){
|
||||
s[77] = 77;
|
||||
if (i > 78){
|
||||
s[78] = 78;
|
||||
if (i > 79){
|
||||
s[79] = 79;
|
||||
if (i > 80){
|
||||
s[80] = 80;
|
||||
if (i > 81){
|
||||
s[81] = 81;
|
||||
if (i > 82){
|
||||
s[82] = 82;
|
||||
if (i > 83){
|
||||
s[83] = 83;
|
||||
if (i > 84){
|
||||
s[84] = 84;
|
||||
if (i > 85){
|
||||
s[85] = 85;
|
||||
if (i > 86){
|
||||
s[86] = 86;
|
||||
if (i > 87){
|
||||
s[87] = 87;
|
||||
if (i > 88){
|
||||
s[88] = 88;
|
||||
if (i > 89){
|
||||
s[89] = 89;
|
||||
if (i > 90){
|
||||
s[90] = 90;
|
||||
if (i > 91){
|
||||
s[91] = 91;
|
||||
if (i > 92){
|
||||
s[92] = 92;
|
||||
if (i > 93){
|
||||
s[93] = 93;
|
||||
if (i > 94){
|
||||
s[94] = 94;
|
||||
if (i > 95){
|
||||
s[95] = 95;
|
||||
if (i > 96){
|
||||
s[96] = 96;
|
||||
if (i > 97){
|
||||
s[97] = 97;
|
||||
if (i > 98){
|
||||
s[98] = 98;
|
||||
if (i > 99){
|
||||
s[99] = 99;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
j=j+1;
|
||||
int m = 0;
|
||||
while (m < 100){
|
||||
sum = sum + s[m];
|
||||
m=m+1;
|
||||
}
|
||||
sum = sum % 65535;
|
||||
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
|
||||
int main() {
|
||||
starttime();
|
||||
int loopcount = getint();
|
||||
putint(func(loopcount));
|
||||
putch(10);
|
||||
stoptime();
|
||||
return 0;
|
||||
}
|
||||
|
||||
331
testcases/final_performance/if-combine2.sy
Normal file
331
testcases/final_performance/if-combine2.sy
Normal file
@ -0,0 +1,331 @@
|
||||
int func(int n) {
|
||||
int sum = 0;
|
||||
int i = 200;
|
||||
int j = 0;
|
||||
int s[100];
|
||||
int m = 0;
|
||||
|
||||
while (m < 100){
|
||||
s[m] = 0;
|
||||
m=m+1;
|
||||
}
|
||||
while(j < n) {
|
||||
if (i > 1){
|
||||
s[1] = 1;
|
||||
if (i > 2){
|
||||
s[2] = 2;
|
||||
if (i > 3){
|
||||
s[3] = 3;
|
||||
if (i > 4){
|
||||
s[4] = 4;
|
||||
if (i > 5){
|
||||
s[5] = 5;
|
||||
if (i > 6){
|
||||
s[6] = 6;
|
||||
if (i > 7){
|
||||
s[7] = 7;
|
||||
if (i > 8){
|
||||
s[8] = 8;
|
||||
if (i > 9){
|
||||
s[9] = 9;
|
||||
if (i > 10){
|
||||
s[10] = 10;
|
||||
if (i > 11){
|
||||
s[11] = 11;
|
||||
if (i > 12){
|
||||
s[12] = 12;
|
||||
if (i > 13){
|
||||
s[13] = 13;
|
||||
if (i > 14){
|
||||
s[14] = 14;
|
||||
if (i > 15){
|
||||
s[15] = 15;
|
||||
if (i > 16){
|
||||
s[16] = 16;
|
||||
if (i > 17){
|
||||
s[17] = 17;
|
||||
if (i > 18){
|
||||
s[18] = 18;
|
||||
if (i > 19){
|
||||
s[19] = 19;
|
||||
if (i > 20){
|
||||
s[20] = 20;
|
||||
if (i > 21){
|
||||
s[21] = 21;
|
||||
if (i > 22){
|
||||
s[22] = 22;
|
||||
if (i > 23){
|
||||
s[23] = 23;
|
||||
if (i > 24){
|
||||
s[24] = 24;
|
||||
if (i > 25){
|
||||
s[25] = 25;
|
||||
if (i > 26){
|
||||
s[26] = 26;
|
||||
if (i > 27){
|
||||
s[27] = 27;
|
||||
if (i > 28){
|
||||
s[28] = 28;
|
||||
if (i > 29){
|
||||
s[29] = 29;
|
||||
if (i > 30){
|
||||
s[30] = 30;
|
||||
if (i > 31){
|
||||
s[31] = 31;
|
||||
if (i > 32){
|
||||
s[32] = 32;
|
||||
if (i > 33){
|
||||
s[33] = 33;
|
||||
if (i > 34){
|
||||
s[34] = 34;
|
||||
if (i > 35){
|
||||
s[35] = 35;
|
||||
if (i > 36){
|
||||
s[36] = 36;
|
||||
if (i > 37){
|
||||
s[37] = 37;
|
||||
if (i > 38){
|
||||
s[38] = 38;
|
||||
if (i > 39){
|
||||
s[39] = 39;
|
||||
if (i > 40){
|
||||
s[40] = 40;
|
||||
if (i > 41){
|
||||
s[41] = 41;
|
||||
if (i > 42){
|
||||
s[42] = 42;
|
||||
if (i > 43){
|
||||
s[43] = 43;
|
||||
if (i > 44){
|
||||
s[44] = 44;
|
||||
if (i > 45){
|
||||
s[45] = 45;
|
||||
if (i > 46){
|
||||
s[46] = 46;
|
||||
if (i > 47){
|
||||
s[47] = 47;
|
||||
if (i > 48){
|
||||
s[48] = 48;
|
||||
if (i > 49){
|
||||
s[49] = 49;
|
||||
if (i > 50){
|
||||
s[50] = 50;
|
||||
if (i > 51){
|
||||
s[51] = 51;
|
||||
if (i > 52){
|
||||
s[52] = 52;
|
||||
if (i > 53){
|
||||
s[53] = 53;
|
||||
if (i > 54){
|
||||
s[54] = 54;
|
||||
if (i > 55){
|
||||
s[55] = 55;
|
||||
if (i > 56){
|
||||
s[56] = 56;
|
||||
if (i > 57){
|
||||
s[57] = 57;
|
||||
if (i > 58){
|
||||
s[58] = 58;
|
||||
if (i > 59){
|
||||
s[59] = 59;
|
||||
if (i > 60){
|
||||
s[60] = 60;
|
||||
if (i > 61){
|
||||
s[61] = 61;
|
||||
if (i > 62){
|
||||
s[62] = 62;
|
||||
if (i > 63){
|
||||
s[63] = 63;
|
||||
if (i > 64){
|
||||
s[64] = 64;
|
||||
if (i > 65){
|
||||
s[65] = 65;
|
||||
if (i > 66){
|
||||
s[66] = 66;
|
||||
if (i > 67){
|
||||
s[67] = 67;
|
||||
if (i > 68){
|
||||
s[68] = 68;
|
||||
if (i > 69){
|
||||
s[69] = 69;
|
||||
if (i > 70){
|
||||
s[70] = 70;
|
||||
if (i > 71){
|
||||
s[71] = 71;
|
||||
if (i > 72){
|
||||
s[72] = 72;
|
||||
if (i > 73){
|
||||
s[73] = 73;
|
||||
if (i > 74){
|
||||
s[74] = 74;
|
||||
if (i > 75){
|
||||
s[75] = 75;
|
||||
if (i > 76){
|
||||
s[76] = 76;
|
||||
if (i > 77){
|
||||
s[77] = 77;
|
||||
if (i > 78){
|
||||
s[78] = 78;
|
||||
if (i > 79){
|
||||
s[79] = 79;
|
||||
if (i > 80){
|
||||
s[80] = 80;
|
||||
if (i > 81){
|
||||
s[81] = 81;
|
||||
if (i > 82){
|
||||
s[82] = 82;
|
||||
if (i > 83){
|
||||
s[83] = 83;
|
||||
if (i > 84){
|
||||
s[84] = 84;
|
||||
if (i > 85){
|
||||
s[85] = 85;
|
||||
if (i > 86){
|
||||
s[86] = 86;
|
||||
if (i > 87){
|
||||
s[87] = 87;
|
||||
if (i > 88){
|
||||
s[88] = 88;
|
||||
if (i > 89){
|
||||
s[89] = 89;
|
||||
if (i > 90){
|
||||
s[90] = 90;
|
||||
if (i > 91){
|
||||
s[91] = 91;
|
||||
if (i > 92){
|
||||
s[92] = 92;
|
||||
if (i > 93){
|
||||
s[93] = 93;
|
||||
if (i > 94){
|
||||
s[94] = 94;
|
||||
if (i > 95){
|
||||
s[95] = 95;
|
||||
if (i > 96){
|
||||
s[96] = 96;
|
||||
if (i > 97){
|
||||
s[97] = 97;
|
||||
if (i > 98){
|
||||
s[98] = 98;
|
||||
if (i > 99){
|
||||
s[99] = 99;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
j=j+1;
|
||||
int m = 0;
|
||||
while (m < 100){
|
||||
sum = sum + s[m];
|
||||
m=m+1;
|
||||
}
|
||||
sum = sum % 65535;
|
||||
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
|
||||
int main() {
|
||||
starttime();
|
||||
int loopcount = getint();
|
||||
putint(func(loopcount));
|
||||
putch(10);
|
||||
stoptime();
|
||||
return 0;
|
||||
}
|
||||
|
||||
331
testcases/final_performance/if-combine3.sy
Normal file
331
testcases/final_performance/if-combine3.sy
Normal file
@ -0,0 +1,331 @@
|
||||
int func(int n) {
|
||||
int sum = 0;
|
||||
int i = 200;
|
||||
int j = 0;
|
||||
int s[100];
|
||||
int m = 0;
|
||||
|
||||
while (m < 100){
|
||||
s[m] = 0;
|
||||
m=m+1;
|
||||
}
|
||||
while(j < n) {
|
||||
if (i > 1){
|
||||
s[1] = 1;
|
||||
if (i > 2){
|
||||
s[2] = 2;
|
||||
if (i > 3){
|
||||
s[3] = 3;
|
||||
if (i > 4){
|
||||
s[4] = 4;
|
||||
if (i > 5){
|
||||
s[5] = 5;
|
||||
if (i > 6){
|
||||
s[6] = 6;
|
||||
if (i > 7){
|
||||
s[7] = 7;
|
||||
if (i > 8){
|
||||
s[8] = 8;
|
||||
if (i > 9){
|
||||
s[9] = 9;
|
||||
if (i > 10){
|
||||
s[10] = 10;
|
||||
if (i > 11){
|
||||
s[11] = 11;
|
||||
if (i > 12){
|
||||
s[12] = 12;
|
||||
if (i > 13){
|
||||
s[13] = 13;
|
||||
if (i > 14){
|
||||
s[14] = 14;
|
||||
if (i > 15){
|
||||
s[15] = 15;
|
||||
if (i > 16){
|
||||
s[16] = 16;
|
||||
if (i > 17){
|
||||
s[17] = 17;
|
||||
if (i > 18){
|
||||
s[18] = 18;
|
||||
if (i > 19){
|
||||
s[19] = 19;
|
||||
if (i > 20){
|
||||
s[20] = 20;
|
||||
if (i > 21){
|
||||
s[21] = 21;
|
||||
if (i > 22){
|
||||
s[22] = 22;
|
||||
if (i > 23){
|
||||
s[23] = 23;
|
||||
if (i > 24){
|
||||
s[24] = 24;
|
||||
if (i > 25){
|
||||
s[25] = 25;
|
||||
if (i > 26){
|
||||
s[26] = 26;
|
||||
if (i > 27){
|
||||
s[27] = 27;
|
||||
if (i > 28){
|
||||
s[28] = 28;
|
||||
if (i > 29){
|
||||
s[29] = 29;
|
||||
if (i > 30){
|
||||
s[30] = 30;
|
||||
if (i > 31){
|
||||
s[31] = 31;
|
||||
if (i > 32){
|
||||
s[32] = 32;
|
||||
if (i > 33){
|
||||
s[33] = 33;
|
||||
if (i > 34){
|
||||
s[34] = 34;
|
||||
if (i > 35){
|
||||
s[35] = 35;
|
||||
if (i > 36){
|
||||
s[36] = 36;
|
||||
if (i > 37){
|
||||
s[37] = 37;
|
||||
if (i > 38){
|
||||
s[38] = 38;
|
||||
if (i > 39){
|
||||
s[39] = 39;
|
||||
if (i > 40){
|
||||
s[40] = 40;
|
||||
if (i > 41){
|
||||
s[41] = 41;
|
||||
if (i > 42){
|
||||
s[42] = 42;
|
||||
if (i > 43){
|
||||
s[43] = 43;
|
||||
if (i > 44){
|
||||
s[44] = 44;
|
||||
if (i > 45){
|
||||
s[45] = 45;
|
||||
if (i > 46){
|
||||
s[46] = 46;
|
||||
if (i > 47){
|
||||
s[47] = 47;
|
||||
if (i > 48){
|
||||
s[48] = 48;
|
||||
if (i > 49){
|
||||
s[49] = 49;
|
||||
if (i > 50){
|
||||
s[50] = 50;
|
||||
if (i > 51){
|
||||
s[51] = 51;
|
||||
if (i > 52){
|
||||
s[52] = 52;
|
||||
if (i > 53){
|
||||
s[53] = 53;
|
||||
if (i > 54){
|
||||
s[54] = 54;
|
||||
if (i > 55){
|
||||
s[55] = 55;
|
||||
if (i > 56){
|
||||
s[56] = 56;
|
||||
if (i > 57){
|
||||
s[57] = 57;
|
||||
if (i > 58){
|
||||
s[58] = 58;
|
||||
if (i > 59){
|
||||
s[59] = 59;
|
||||
if (i > 60){
|
||||
s[60] = 60;
|
||||
if (i > 61){
|
||||
s[61] = 61;
|
||||
if (i > 62){
|
||||
s[62] = 62;
|
||||
if (i > 63){
|
||||
s[63] = 63;
|
||||
if (i > 64){
|
||||
s[64] = 64;
|
||||
if (i > 65){
|
||||
s[65] = 65;
|
||||
if (i > 66){
|
||||
s[66] = 66;
|
||||
if (i > 67){
|
||||
s[67] = 67;
|
||||
if (i > 68){
|
||||
s[68] = 68;
|
||||
if (i > 69){
|
||||
s[69] = 69;
|
||||
if (i > 70){
|
||||
s[70] = 70;
|
||||
if (i > 71){
|
||||
s[71] = 71;
|
||||
if (i > 72){
|
||||
s[72] = 72;
|
||||
if (i > 73){
|
||||
s[73] = 73;
|
||||
if (i > 74){
|
||||
s[74] = 74;
|
||||
if (i > 75){
|
||||
s[75] = 75;
|
||||
if (i > 76){
|
||||
s[76] = 76;
|
||||
if (i > 77){
|
||||
s[77] = 77;
|
||||
if (i > 78){
|
||||
s[78] = 78;
|
||||
if (i > 79){
|
||||
s[79] = 79;
|
||||
if (i > 80){
|
||||
s[80] = 80;
|
||||
if (i > 81){
|
||||
s[81] = 81;
|
||||
if (i > 82){
|
||||
s[82] = 82;
|
||||
if (i > 83){
|
||||
s[83] = 83;
|
||||
if (i > 84){
|
||||
s[84] = 84;
|
||||
if (i > 85){
|
||||
s[85] = 85;
|
||||
if (i > 86){
|
||||
s[86] = 86;
|
||||
if (i > 87){
|
||||
s[87] = 87;
|
||||
if (i > 88){
|
||||
s[88] = 88;
|
||||
if (i > 89){
|
||||
s[89] = 89;
|
||||
if (i > 90){
|
||||
s[90] = 90;
|
||||
if (i > 91){
|
||||
s[91] = 91;
|
||||
if (i > 92){
|
||||
s[92] = 92;
|
||||
if (i > 93){
|
||||
s[93] = 93;
|
||||
if (i > 94){
|
||||
s[94] = 94;
|
||||
if (i > 95){
|
||||
s[95] = 95;
|
||||
if (i > 96){
|
||||
s[96] = 96;
|
||||
if (i > 97){
|
||||
s[97] = 97;
|
||||
if (i > 98){
|
||||
s[98] = 98;
|
||||
if (i > 99){
|
||||
s[99] = 99;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
j=j+1;
|
||||
int m = 0;
|
||||
while (m < 100){
|
||||
sum = sum + s[m];
|
||||
m=m+1;
|
||||
}
|
||||
sum = sum % 65535;
|
||||
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
|
||||
int main() {
|
||||
starttime();
|
||||
int loopcount = getint();
|
||||
putint(func(loopcount));
|
||||
putch(10);
|
||||
stoptime();
|
||||
return 0;
|
||||
}
|
||||
|
||||
49
testcases/final_performance/large_loop_array_1.sy
Normal file
49
testcases/final_performance/large_loop_array_1.sy
Normal file
@ -0,0 +1,49 @@
|
||||
//large loop and large array caculate
|
||||
int COUNT = 500000;
|
||||
|
||||
float loop(float x[], float y[], int length) {
|
||||
int i = 0;
|
||||
float accumulator = 0.0;
|
||||
while (i < length) {
|
||||
accumulator = accumulator + x[i] * y[i];
|
||||
i = i + 1;
|
||||
}
|
||||
return accumulator;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int i = 0, j = 0;
|
||||
int len = getint();
|
||||
float x[2048];
|
||||
float y[2048];
|
||||
float total = 0.0;
|
||||
float a = 0.0;
|
||||
float b = 1.0;
|
||||
starttime();
|
||||
while ( i < COUNT) {
|
||||
if (i % 10) {
|
||||
a = 0.0;
|
||||
b = 1.0;
|
||||
} else {
|
||||
a = a + 0.1;
|
||||
b = b + 0.2;
|
||||
}
|
||||
while ( j < len) {
|
||||
x[j] = a + j;
|
||||
y[j] = b + j;
|
||||
j = j + 1;
|
||||
}
|
||||
total = total + loop(x, y, len);
|
||||
i = i + 1;
|
||||
}
|
||||
stoptime();
|
||||
if ((total - 1430318598848512.000000) <=0.000001 || (total - 1430318598848512.000000) >= -0.000001) {
|
||||
putint(0);
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
putint(1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
49
testcases/final_performance/large_loop_array_2.sy
Normal file
49
testcases/final_performance/large_loop_array_2.sy
Normal file
@ -0,0 +1,49 @@
|
||||
|
||||
int COUNT = 500000;
|
||||
|
||||
float loop(float x[], float y[], int length) {
|
||||
int i = 0;
|
||||
float accumulator = 0.0;
|
||||
while (i < length) {
|
||||
accumulator = accumulator + x[i] * y[i];
|
||||
i = i + 1;
|
||||
}
|
||||
return accumulator;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int i = 0, j = 0;
|
||||
int len = getint();
|
||||
float x[4096];
|
||||
float y[4096];
|
||||
float total = 0.0;
|
||||
float a = 0.0;
|
||||
float b = 1.0;
|
||||
starttime();
|
||||
while ( i < COUNT) {
|
||||
if (i % 10) {
|
||||
a = 0.0;
|
||||
b = 1.0;
|
||||
} else {
|
||||
a = a + 0.1;
|
||||
b = b + 0.2;
|
||||
}
|
||||
while ( j < len) {
|
||||
x[j] = a + j;
|
||||
y[j] = b + j;
|
||||
j = j + 1;
|
||||
}
|
||||
total = total + loop(x, y, len);
|
||||
i = i + 1;
|
||||
}
|
||||
stoptime();
|
||||
if ((total - 11442437121638400.000000) <=0.000001 || (total - 11442437121638400.000000) >= -0.000001) {
|
||||
putint(0);
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
putint(1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
49
testcases/final_performance/large_loop_array_3.sy
Normal file
49
testcases/final_performance/large_loop_array_3.sy
Normal file
@ -0,0 +1,49 @@
|
||||
|
||||
int COUNT = 100000;
|
||||
|
||||
float loop(float x[], float y[], int length) {
|
||||
int i = 0;
|
||||
float accumulator = 0.0;
|
||||
while (i < length) {
|
||||
accumulator = accumulator + x[i] * y[i];
|
||||
i = i + 1;
|
||||
}
|
||||
return accumulator;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int i = 0, j = 0;
|
||||
int len = getint();
|
||||
float x[8192];
|
||||
float y[8192];
|
||||
float total = 0.0;
|
||||
float a = 0.0;
|
||||
float b = 1.0;
|
||||
starttime();
|
||||
while ( i < COUNT) {
|
||||
if (i % 10) {
|
||||
a = 0.0;
|
||||
b = 1.0;
|
||||
} else {
|
||||
a = a + 0.1;
|
||||
b = b + 0.2;
|
||||
}
|
||||
while ( j < len) {
|
||||
x[j] = a + j;
|
||||
y[j] = b + j;
|
||||
j = j + 1;
|
||||
}
|
||||
total = total + loop(x, y, len);
|
||||
i = i + 1;
|
||||
}
|
||||
stoptime();
|
||||
if ((total - 18338022147751936.000000) <=0.000001 || (total - 18338022147751936.000000) >= -0.000001) {
|
||||
putint(0);
|
||||
return 0;
|
||||
}
|
||||
else {
|
||||
putint(1);
|
||||
return 1;
|
||||
}
|
||||
|
||||
}
|
||||
100
testcases/final_performance/layernorm1.sy
Normal file
100
testcases/final_performance/layernorm1.sy
Normal file
@ -0,0 +1,100 @@
|
||||
float myAbs(float x){
|
||||
if(x<0){
|
||||
x = -x;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
float sqrt(float x){
|
||||
float start = 0;
|
||||
float end = x;
|
||||
float mid = (start + end)/ 2;
|
||||
while(myAbs(mid*mid - x)>0.001){
|
||||
if(mid*mid > x){
|
||||
end = mid;
|
||||
mid = (mid + start)/2;
|
||||
}
|
||||
else{
|
||||
start = mid;
|
||||
mid = (mid + end)/2;
|
||||
}
|
||||
}
|
||||
return mid;
|
||||
}
|
||||
float a[1000][1000];
|
||||
int main(){
|
||||
int n;
|
||||
int i;
|
||||
int j;
|
||||
int k;
|
||||
float sum = 0;
|
||||
|
||||
i = 0;
|
||||
while(i<1000)
|
||||
{
|
||||
n = getfarray(a[i]);
|
||||
if(n!=1000){
|
||||
return n;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
starttime();
|
||||
|
||||
k = 0;
|
||||
while(k<100)
|
||||
{
|
||||
float mean[1000];
|
||||
i = 0;
|
||||
while(i<1000){
|
||||
j = 0;
|
||||
mean[i] = 0;
|
||||
while(j<1000){
|
||||
mean[i] = mean[i] + a[i][j];
|
||||
j = j+1;
|
||||
}
|
||||
mean[i] = mean[i] / 1000;
|
||||
i = i+1;
|
||||
}
|
||||
float var[1000];
|
||||
i = 0;
|
||||
while(i<1000){
|
||||
j = 0;
|
||||
var[i] = 0;
|
||||
while(j<1000){
|
||||
var[i] = var[i] + (a[i][j] - mean[i]) * (a[i][j] - mean[i]);
|
||||
j = j+1;
|
||||
}
|
||||
var[i] = var[i] / 1000;
|
||||
var[i] = sqrt(var[i] + 0.01);
|
||||
i = i+1;
|
||||
}
|
||||
i = 0;
|
||||
while(i<1000){
|
||||
j = 0;
|
||||
while(j<1000){
|
||||
a[i][j] = (a[i][j] - mean[i])/var[i];
|
||||
sum = sum + a[i][j];
|
||||
j = j+1;
|
||||
}
|
||||
i = i+1;
|
||||
}
|
||||
k = k + 1;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
while(i<1000){
|
||||
j = 0;
|
||||
while(j<1000){
|
||||
sum = sum + a[i][j];
|
||||
j = j+1;
|
||||
}
|
||||
i = i+1;
|
||||
}
|
||||
|
||||
stoptime();
|
||||
|
||||
putfloat(sum);
|
||||
return 0;
|
||||
}
|
||||
|
||||
100
testcases/final_performance/layernorm2.sy
Normal file
100
testcases/final_performance/layernorm2.sy
Normal file
@ -0,0 +1,100 @@
|
||||
float myAbs(float x){
|
||||
if(x<0){
|
||||
x = -x;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
float sqrt(float x){
|
||||
float start = 0;
|
||||
float end = x;
|
||||
float mid = (start + end)/ 2;
|
||||
while(myAbs(mid*mid - x)>0.001){
|
||||
if(mid*mid > x){
|
||||
end = mid;
|
||||
mid = (mid + start)/2;
|
||||
}
|
||||
else{
|
||||
start = mid;
|
||||
mid = (mid + end)/2;
|
||||
}
|
||||
}
|
||||
return mid;
|
||||
}
|
||||
float a[1000][1000];
|
||||
int main(){
|
||||
int n;
|
||||
int i;
|
||||
int j;
|
||||
int k;
|
||||
float sum = 0;
|
||||
|
||||
i = 0;
|
||||
while(i<1000)
|
||||
{
|
||||
n = getfarray(a[i]);
|
||||
if(n!=1000){
|
||||
return n;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
starttime();
|
||||
|
||||
k = 0;
|
||||
while(k<100)
|
||||
{
|
||||
float mean[1000];
|
||||
i = 0;
|
||||
while(i<1000){
|
||||
j = 0;
|
||||
mean[i] = 0;
|
||||
while(j<1000){
|
||||
mean[i] = mean[i] + a[i][j];
|
||||
j = j+1;
|
||||
}
|
||||
mean[i] = mean[i] / 1000;
|
||||
i = i+1;
|
||||
}
|
||||
float var[1000];
|
||||
i = 0;
|
||||
while(i<1000){
|
||||
j = 0;
|
||||
var[i] = 0;
|
||||
while(j<1000){
|
||||
var[i] = var[i] + (a[i][j] - mean[i]) * (a[i][j] - mean[i]);
|
||||
j = j+1;
|
||||
}
|
||||
var[i] = var[i] / 1000;
|
||||
var[i] = sqrt(var[i] + 0.01);
|
||||
i = i+1;
|
||||
}
|
||||
i = 0;
|
||||
while(i<1000){
|
||||
j = 0;
|
||||
while(j<1000){
|
||||
a[i][j] = (a[i][j] - mean[i])/var[i];
|
||||
sum = sum + a[i][j];
|
||||
j = j+1;
|
||||
}
|
||||
i = i+1;
|
||||
}
|
||||
k = k + 1;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
while(i<1000){
|
||||
j = 0;
|
||||
while(j<1000){
|
||||
sum = sum + a[i][j];
|
||||
j = j+1;
|
||||
}
|
||||
i = i+1;
|
||||
}
|
||||
|
||||
stoptime();
|
||||
|
||||
putfloat(sum);
|
||||
return 0;
|
||||
}
|
||||
|
||||
100
testcases/final_performance/layernorm3.sy
Normal file
100
testcases/final_performance/layernorm3.sy
Normal file
@ -0,0 +1,100 @@
|
||||
float myAbs(float x){
|
||||
if(x<0){
|
||||
x = -x;
|
||||
}
|
||||
return x;
|
||||
}
|
||||
|
||||
float sqrt(float x){
|
||||
float start = 0;
|
||||
float end = x;
|
||||
float mid = (start + end)/ 2;
|
||||
while(myAbs(mid*mid - x)>0.001){
|
||||
if(mid*mid > x){
|
||||
end = mid;
|
||||
mid = (mid + start)/2;
|
||||
}
|
||||
else{
|
||||
start = mid;
|
||||
mid = (mid + end)/2;
|
||||
}
|
||||
}
|
||||
return mid;
|
||||
}
|
||||
float a[1000][1000];
|
||||
int main(){
|
||||
int n;
|
||||
int i;
|
||||
int j;
|
||||
int k;
|
||||
float sum = 0;
|
||||
|
||||
i = 0;
|
||||
while(i<1000)
|
||||
{
|
||||
n = getfarray(a[i]);
|
||||
if(n!=1000){
|
||||
return n;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
starttime();
|
||||
|
||||
k = 0;
|
||||
while(k<100)
|
||||
{
|
||||
float mean[1000];
|
||||
i = 0;
|
||||
while(i<1000){
|
||||
j = 0;
|
||||
mean[i] = 0;
|
||||
while(j<1000){
|
||||
mean[i] = mean[i] + a[i][j];
|
||||
j = j+1;
|
||||
}
|
||||
mean[i] = mean[i] / 1000;
|
||||
i = i+1;
|
||||
}
|
||||
float var[1000];
|
||||
i = 0;
|
||||
while(i<1000){
|
||||
j = 0;
|
||||
var[i] = 0;
|
||||
while(j<1000){
|
||||
var[i] = var[i] + (a[i][j] - mean[i]) * (a[i][j] - mean[i]);
|
||||
j = j+1;
|
||||
}
|
||||
var[i] = var[i] / 1000;
|
||||
var[i] = sqrt(var[i] + 0.01);
|
||||
i = i+1;
|
||||
}
|
||||
i = 0;
|
||||
while(i<1000){
|
||||
j = 0;
|
||||
while(j<1000){
|
||||
a[i][j] = (a[i][j] - mean[i])/var[i];
|
||||
sum = sum + a[i][j];
|
||||
j = j+1;
|
||||
}
|
||||
i = i+1;
|
||||
}
|
||||
k = k + 1;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
while(i<1000){
|
||||
j = 0;
|
||||
while(j<1000){
|
||||
sum = sum + a[i][j];
|
||||
j = j+1;
|
||||
}
|
||||
i = i+1;
|
||||
}
|
||||
|
||||
stoptime();
|
||||
|
||||
putfloat(sum);
|
||||
return 0;
|
||||
}
|
||||
|
||||
97
testcases/final_performance/matmul1.sy
Normal file
97
testcases/final_performance/matmul1.sy
Normal file
@ -0,0 +1,97 @@
|
||||
int a[1000][1000];
|
||||
int b[1000][1000];
|
||||
int c[1000][1000];
|
||||
const int MAX = 2147483647;
|
||||
|
||||
int main(){
|
||||
int n;
|
||||
int i;
|
||||
int j;
|
||||
int k;
|
||||
int sum = 0;
|
||||
|
||||
i = 0;
|
||||
while(i<1000)
|
||||
{
|
||||
n = getarray(a[i]);
|
||||
if(n!=1000){
|
||||
return n;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
starttime();
|
||||
|
||||
i = 0;
|
||||
while(i<1000){
|
||||
j = 0;
|
||||
while(j<1000){
|
||||
b[i][j] = a[j][i];
|
||||
j = j+1;
|
||||
}
|
||||
i = i+1;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
while(i<1000){
|
||||
j = 0;
|
||||
while(j<1000){
|
||||
k = 0;
|
||||
int temp = 0;
|
||||
while(k<1000){
|
||||
temp = temp + a[i][k]*b[k][j];
|
||||
k = k+1;
|
||||
}
|
||||
c[i][j] = temp;
|
||||
j = j+1;
|
||||
}
|
||||
i = i+1;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
while(i<1000){
|
||||
j = 0;
|
||||
int temp = MAX;
|
||||
while(j<1000){
|
||||
if(c[i][j]<temp)
|
||||
{
|
||||
temp = c[i][j];
|
||||
}
|
||||
j = j+1;
|
||||
}
|
||||
j = 0;
|
||||
while(j<1000){
|
||||
c[i][j] = temp;
|
||||
j = j+1;
|
||||
}
|
||||
i = i+1;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
while(i<1000){
|
||||
j = 0;
|
||||
int temp = MAX;
|
||||
while(j<1000){
|
||||
c[i][j] = -c[j][i];
|
||||
j = j+1;
|
||||
}
|
||||
i = i+1;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
while(i<1000){
|
||||
j = 0;
|
||||
int temp = MAX;
|
||||
while(j<1000){
|
||||
sum = sum + c[i][j];
|
||||
j = j+1;
|
||||
}
|
||||
i = i+1;
|
||||
}
|
||||
|
||||
stoptime();
|
||||
|
||||
putint(sum);
|
||||
return 0;
|
||||
}
|
||||
|
||||
97
testcases/final_performance/matmul2.sy
Normal file
97
testcases/final_performance/matmul2.sy
Normal file
@ -0,0 +1,97 @@
|
||||
int a[1000][1000];
|
||||
int b[1000][1000];
|
||||
int c[1000][1000];
|
||||
const int MAX = 2147483647;
|
||||
|
||||
int main(){
|
||||
int n;
|
||||
int i;
|
||||
int j;
|
||||
int k;
|
||||
int sum = 0;
|
||||
|
||||
i = 0;
|
||||
while(i<1000)
|
||||
{
|
||||
n = getarray(a[i]);
|
||||
if(n!=1000){
|
||||
return n;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
starttime();
|
||||
|
||||
i = 0;
|
||||
while(i<1000){
|
||||
j = 0;
|
||||
while(j<1000){
|
||||
b[i][j] = a[j][i];
|
||||
j = j+1;
|
||||
}
|
||||
i = i+1;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
while(i<1000){
|
||||
j = 0;
|
||||
while(j<1000){
|
||||
k = 0;
|
||||
int temp = 0;
|
||||
while(k<1000){
|
||||
temp = temp + a[i][k]*b[k][j];
|
||||
k = k+1;
|
||||
}
|
||||
c[i][j] = temp;
|
||||
j = j+1;
|
||||
}
|
||||
i = i+1;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
while(i<1000){
|
||||
j = 0;
|
||||
int temp = MAX;
|
||||
while(j<1000){
|
||||
if(c[i][j]<temp)
|
||||
{
|
||||
temp = c[i][j];
|
||||
}
|
||||
j = j+1;
|
||||
}
|
||||
j = 0;
|
||||
while(j<1000){
|
||||
c[i][j] = temp;
|
||||
j = j+1;
|
||||
}
|
||||
i = i+1;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
while(i<1000){
|
||||
j = 0;
|
||||
int temp = MAX;
|
||||
while(j<1000){
|
||||
c[i][j] = -c[j][i];
|
||||
j = j+1;
|
||||
}
|
||||
i = i+1;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
while(i<1000){
|
||||
j = 0;
|
||||
int temp = MAX;
|
||||
while(j<1000){
|
||||
sum = sum + c[i][j];
|
||||
j = j+1;
|
||||
}
|
||||
i = i+1;
|
||||
}
|
||||
|
||||
stoptime();
|
||||
|
||||
putint(sum);
|
||||
return 0;
|
||||
}
|
||||
|
||||
97
testcases/final_performance/matmul3.sy
Normal file
97
testcases/final_performance/matmul3.sy
Normal file
@ -0,0 +1,97 @@
|
||||
int a[1000][1000];
|
||||
int b[1000][1000];
|
||||
int c[1000][1000];
|
||||
const int MAX = 2147483647;
|
||||
|
||||
int main(){
|
||||
int n;
|
||||
int i;
|
||||
int j;
|
||||
int k;
|
||||
int sum = 0;
|
||||
|
||||
i = 0;
|
||||
while(i<1000)
|
||||
{
|
||||
n = getarray(a[i]);
|
||||
if(n!=1000){
|
||||
return n;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
starttime();
|
||||
|
||||
i = 0;
|
||||
while(i<1000){
|
||||
j = 0;
|
||||
while(j<1000){
|
||||
b[i][j] = a[j][i];
|
||||
j = j+1;
|
||||
}
|
||||
i = i+1;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
while(i<1000){
|
||||
j = 0;
|
||||
while(j<1000){
|
||||
k = 0;
|
||||
int temp = 0;
|
||||
while(k<1000){
|
||||
temp = temp + a[i][k]*b[k][j];
|
||||
k = k+1;
|
||||
}
|
||||
c[i][j] = temp;
|
||||
j = j+1;
|
||||
}
|
||||
i = i+1;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
while(i<1000){
|
||||
j = 0;
|
||||
int temp = MAX;
|
||||
while(j<1000){
|
||||
if(c[i][j]<temp)
|
||||
{
|
||||
temp = c[i][j];
|
||||
}
|
||||
j = j+1;
|
||||
}
|
||||
j = 0;
|
||||
while(j<1000){
|
||||
c[i][j] = temp;
|
||||
j = j+1;
|
||||
}
|
||||
i = i+1;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
while(i<1000){
|
||||
j = 0;
|
||||
int temp = MAX;
|
||||
while(j<1000){
|
||||
c[i][j] = -c[j][i];
|
||||
j = j+1;
|
||||
}
|
||||
i = i+1;
|
||||
}
|
||||
|
||||
i = 0;
|
||||
while(i<1000){
|
||||
j = 0;
|
||||
int temp = MAX;
|
||||
while(j<1000){
|
||||
sum = sum + c[i][j];
|
||||
j = j+1;
|
||||
}
|
||||
i = i+1;
|
||||
}
|
||||
|
||||
stoptime();
|
||||
|
||||
putint(sum);
|
||||
return 0;
|
||||
}
|
||||
|
||||
64
testcases/final_performance/median0.sy
Executable file
64
testcases/final_performance/median0.sy
Executable file
@ -0,0 +1,64 @@
|
||||
int n;
|
||||
int meanless_calculation(int x, int y){
|
||||
int i = 0;
|
||||
int ret = 0;
|
||||
while (i < x && i < y){
|
||||
i = i + 1;
|
||||
ret = ret + x + i;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int swap(int arr[], int l, int r){
|
||||
int curr = arr[l];
|
||||
arr[l] = arr[r];
|
||||
arr[r] = curr;
|
||||
return meanless_calculation(l, r);
|
||||
}
|
||||
|
||||
int median(int arr[], int begin, int end, int pos){
|
||||
int pivot = arr[begin];
|
||||
|
||||
int l = begin;
|
||||
int r = end + 1;
|
||||
int xx = 0;
|
||||
while (1 == 1){
|
||||
while (l < r){
|
||||
r = r - 1;
|
||||
if(arr[r] < pivot){
|
||||
break;
|
||||
}
|
||||
xx = xx + 1;
|
||||
}
|
||||
while (l < r){
|
||||
l = l + 1;
|
||||
if(arr[l] >= pivot){
|
||||
break;
|
||||
}
|
||||
xx = xx - 1;
|
||||
}
|
||||
|
||||
if (l == r) break;
|
||||
else {
|
||||
swap(arr, l, r);
|
||||
}
|
||||
}
|
||||
arr[begin] = pivot;
|
||||
swap(arr, begin, l);
|
||||
|
||||
if (l > pos) return median(arr, begin, l, pos);
|
||||
if (l < pos) return median(arr, l + 1, end, pos);
|
||||
|
||||
return xx;
|
||||
}
|
||||
|
||||
int a[10000000];
|
||||
|
||||
int main(){
|
||||
n = getarray(a);
|
||||
starttime();
|
||||
median(a, 0, n-1, n/2);
|
||||
stoptime();
|
||||
putarray(n, a);
|
||||
return a[n/2] % 256;
|
||||
}
|
||||
64
testcases/final_performance/median1.sy
Executable file
64
testcases/final_performance/median1.sy
Executable file
@ -0,0 +1,64 @@
|
||||
int n;
|
||||
int meanless_calculation(int x, int y){
|
||||
int i = 0;
|
||||
int ret = 0;
|
||||
while (i < x && i < y){
|
||||
i = i + 1;
|
||||
ret = ret + x + i;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int swap(int arr[], int l, int r){
|
||||
int curr = arr[l];
|
||||
arr[l] = arr[r];
|
||||
arr[r] = curr;
|
||||
return meanless_calculation(l, r);
|
||||
}
|
||||
|
||||
int median(int arr[], int begin, int end, int pos){
|
||||
int pivot = arr[begin];
|
||||
|
||||
int l = begin;
|
||||
int r = end + 1;
|
||||
int xx = 0;
|
||||
while (1 == 1){
|
||||
while (l < r){
|
||||
r = r - 1;
|
||||
if(arr[r] < pivot){
|
||||
break;
|
||||
}
|
||||
xx = xx + 1;
|
||||
}
|
||||
while (l < r){
|
||||
l = l + 1;
|
||||
if(arr[l] >= pivot){
|
||||
break;
|
||||
}
|
||||
xx = xx - 1;
|
||||
}
|
||||
|
||||
if (l == r) break;
|
||||
else {
|
||||
swap(arr, l, r);
|
||||
}
|
||||
}
|
||||
arr[begin] = pivot;
|
||||
swap(arr, begin, l);
|
||||
|
||||
if (l > pos) return median(arr, begin, l, pos);
|
||||
if (l < pos) return median(arr, l + 1, end, pos);
|
||||
|
||||
return xx;
|
||||
}
|
||||
|
||||
int a[10000000];
|
||||
|
||||
int main(){
|
||||
n = getarray(a);
|
||||
starttime();
|
||||
median(a, 0, n-1, n/2);
|
||||
stoptime();
|
||||
putarray(n, a);
|
||||
return a[n/2] % 256;
|
||||
}
|
||||
64
testcases/final_performance/median2.sy
Executable file
64
testcases/final_performance/median2.sy
Executable file
@ -0,0 +1,64 @@
|
||||
int n;
|
||||
int meanless_calculation(int x, int y){
|
||||
int i = 0;
|
||||
int ret = 0;
|
||||
while (i < x && i < y){
|
||||
i = i + 1;
|
||||
ret = ret + x + i;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
int swap(int arr[], int l, int r){
|
||||
int curr = arr[l];
|
||||
arr[l] = arr[r];
|
||||
arr[r] = curr;
|
||||
return meanless_calculation(l, r);
|
||||
}
|
||||
|
||||
int median(int arr[], int begin, int end, int pos){
|
||||
int pivot = arr[begin];
|
||||
|
||||
int l = begin;
|
||||
int r = end + 1;
|
||||
int xx = 0;
|
||||
while (1 == 1){
|
||||
while (l < r){
|
||||
r = r - 1;
|
||||
if(arr[r] < pivot){
|
||||
break;
|
||||
}
|
||||
xx = xx + 1;
|
||||
}
|
||||
while (l < r){
|
||||
l = l + 1;
|
||||
if(arr[l] >= pivot){
|
||||
break;
|
||||
}
|
||||
xx = xx - 1;
|
||||
}
|
||||
|
||||
if (l == r) break;
|
||||
else {
|
||||
swap(arr, l, r);
|
||||
}
|
||||
}
|
||||
arr[begin] = pivot;
|
||||
swap(arr, begin, l);
|
||||
|
||||
if (l > pos) return median(arr, begin, l, pos);
|
||||
if (l < pos) return median(arr, l + 1, end, pos);
|
||||
|
||||
return xx;
|
||||
}
|
||||
|
||||
int a[10000000];
|
||||
|
||||
int main(){
|
||||
n = getarray(a);
|
||||
starttime();
|
||||
median(a, 0, n-1, n/2);
|
||||
stoptime();
|
||||
putarray(n, a);
|
||||
return a[n/2] % 256;
|
||||
}
|
||||
43
testcases/final_performance/recursion_fabonacci-1.sy
Normal file
43
testcases/final_performance/recursion_fabonacci-1.sy
Normal file
@ -0,0 +1,43 @@
|
||||
|
||||
|
||||
// recursive function operation
|
||||
|
||||
float fibFP(float n) {
|
||||
if (n < 2.0) {
|
||||
return 1.0;
|
||||
}
|
||||
return fibFP(n - 2.0) + fibFP(n - 1.0);
|
||||
}
|
||||
|
||||
float takFP(float x, float y, float z) {
|
||||
if (y < x)
|
||||
return takFP( takFP(x-1.0, y, z), takFP(y-1.0, z, x), takFP(z-1.0, x, y) );
|
||||
return z;
|
||||
}
|
||||
int main()
|
||||
{
|
||||
starttime();
|
||||
int n = getint();
|
||||
|
||||
float x = getfloat();
|
||||
float y = getfloat();
|
||||
float z = getfloat();
|
||||
float f1 = fibFP(28.0 + n);
|
||||
float t1 = takFP(x, y, z);
|
||||
if(f1==63245984.0){
|
||||
putch(112);
|
||||
}
|
||||
else{
|
||||
putint(1);
|
||||
|
||||
}
|
||||
if(t1==2.0){
|
||||
putch(112);
|
||||
}
|
||||
else {
|
||||
putint(1);
|
||||
}
|
||||
stoptime();
|
||||
return 0;
|
||||
|
||||
}
|
||||
43
testcases/final_performance/recursion_fabonacci-2.sy
Normal file
43
testcases/final_performance/recursion_fabonacci-2.sy
Normal file
@ -0,0 +1,43 @@
|
||||
|
||||
|
||||
// recursive function operation
|
||||
|
||||
float fibFP(float n) {
|
||||
if (n < 2.0) {
|
||||
return 1.0;
|
||||
}
|
||||
return fibFP(n - 2.0) + fibFP(n - 1.0);
|
||||
}
|
||||
|
||||
float takFP(float x, float y, float z) {
|
||||
if (y < x)
|
||||
return takFP( takFP(x-1.0, y, z), takFP(y-1.0, z, x), takFP(z-1.0, x, y) );
|
||||
return z;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
starttime();
|
||||
int n = getint();
|
||||
float x = getfloat();
|
||||
float y = getfloat();
|
||||
float z = getfloat();
|
||||
|
||||
float f1 = fibFP(28.0 + n);
|
||||
float t1 = takFP(x, y, z);
|
||||
|
||||
if(f1==39088168.0){
|
||||
putch(112);
|
||||
}
|
||||
else{
|
||||
putint(1);
|
||||
}
|
||||
if(t1==1.0){
|
||||
putch(112);
|
||||
}
|
||||
else {
|
||||
putint(1);
|
||||
}
|
||||
stoptime();
|
||||
return 0;
|
||||
}
|
||||
43
testcases/final_performance/recursion_fabonacci-3.sy
Normal file
43
testcases/final_performance/recursion_fabonacci-3.sy
Normal file
@ -0,0 +1,43 @@
|
||||
|
||||
|
||||
// recursive function operation
|
||||
|
||||
float fibFP(float n) {
|
||||
if (n < 2.0) {
|
||||
return 1.0;
|
||||
}
|
||||
return fibFP(n - 2.0) + fibFP(n - 1.0);
|
||||
}
|
||||
|
||||
float takFP(float x, float y, float z) {
|
||||
if (y < x)
|
||||
return takFP( takFP(x-1.0, y, z), takFP(y-1.0, z, x), takFP(z-1.0, x, y) );
|
||||
return z;
|
||||
}
|
||||
|
||||
int main()
|
||||
{
|
||||
starttime();
|
||||
int n = getint();
|
||||
float x = getfloat();
|
||||
float y = getfloat();
|
||||
float z = getfloat();
|
||||
|
||||
float f1 = fibFP(28.0 + n);
|
||||
float t1 = takFP(x, y, z);
|
||||
|
||||
if(f1==165580128.0){
|
||||
putch(112);
|
||||
}
|
||||
else{
|
||||
putint(1);
|
||||
}
|
||||
if(t1==2.0){
|
||||
putch(112);
|
||||
}
|
||||
else {
|
||||
putint(1);
|
||||
}
|
||||
stoptime();
|
||||
return 0;
|
||||
}
|
||||
35
testcases/final_performance/recursive_call_1.sy
Normal file
35
testcases/final_performance/recursive_call_1.sy
Normal file
@ -0,0 +1,35 @@
|
||||
float myabs(float num) {
|
||||
if(num>0){
|
||||
return num;
|
||||
}
|
||||
if(num<0){
|
||||
return -num;
|
||||
}
|
||||
}
|
||||
|
||||
float func(float data, int num) {
|
||||
if (num < 0) {
|
||||
return 0;
|
||||
}
|
||||
num=num-1;
|
||||
data = data + func(data, num);
|
||||
data = data - func(data, num);
|
||||
return data;
|
||||
}
|
||||
|
||||
int main() {
|
||||
starttime();
|
||||
float a = 1.001;
|
||||
int num = getint();
|
||||
float res;
|
||||
float expect = 0.0;
|
||||
|
||||
|
||||
res = func(a, num);
|
||||
|
||||
if (res - expect==0)
|
||||
putch(112);
|
||||
stoptime();
|
||||
return 0;
|
||||
}
|
||||
|
||||
34
testcases/final_performance/recursive_call_2.sy
Normal file
34
testcases/final_performance/recursive_call_2.sy
Normal file
@ -0,0 +1,34 @@
|
||||
float myabs(float num) {
|
||||
if(num>0){
|
||||
return num;
|
||||
}
|
||||
if(num<0){
|
||||
return -num;
|
||||
}
|
||||
}
|
||||
|
||||
float func(float data, int num) {
|
||||
if (num < 0) {
|
||||
return 0;
|
||||
}
|
||||
num=num-1;
|
||||
data = data + func(data, num);
|
||||
data = data - func(data, num);
|
||||
return data;
|
||||
}
|
||||
|
||||
int main() {
|
||||
starttime();
|
||||
float a = 1.001;
|
||||
int num = getint();
|
||||
float res;
|
||||
float expect = 0.0;
|
||||
|
||||
|
||||
res = func(a, num);
|
||||
|
||||
if (res - expect==0)
|
||||
putch(112);
|
||||
stoptime();
|
||||
return 0;
|
||||
}
|
||||
34
testcases/final_performance/recursive_call_3.sy
Normal file
34
testcases/final_performance/recursive_call_3.sy
Normal file
@ -0,0 +1,34 @@
|
||||
float myabs(float num) {
|
||||
if(num>0){
|
||||
return num;
|
||||
}
|
||||
if(num<0){
|
||||
return -num;
|
||||
}
|
||||
}
|
||||
|
||||
float func(float data, int num) {
|
||||
if (num < 0) {
|
||||
return 0;
|
||||
}
|
||||
num=num-1;
|
||||
data = data + func(data, num);
|
||||
data = data - func(data, num);
|
||||
return data;
|
||||
}
|
||||
|
||||
int main() {
|
||||
starttime();
|
||||
float a = 1.001;
|
||||
int num = getint();
|
||||
float res;
|
||||
float expect = 1.001;
|
||||
|
||||
|
||||
res = func(a, num);
|
||||
|
||||
if (res - expect==0)
|
||||
putch(112);
|
||||
stoptime();
|
||||
return 0;
|
||||
}
|
||||
93
testcases/final_performance/shuffle0.sy
Executable file
93
testcases/final_performance/shuffle0.sy
Executable file
@ -0,0 +1,93 @@
|
||||
int hashmod;
|
||||
|
||||
const int maxn = 10000000;
|
||||
const int maxm = 10000000;
|
||||
int bucket[maxn];
|
||||
int head[maxn];
|
||||
int next[maxm];
|
||||
int nextvalue[maxm];
|
||||
int key[maxm];
|
||||
int value[maxm];
|
||||
int cnt;
|
||||
|
||||
int keys[maxm];
|
||||
int values[maxm];
|
||||
int requests[maxm];
|
||||
int ans[maxm];
|
||||
|
||||
int hash(int k){
|
||||
return k % hashmod;
|
||||
}
|
||||
|
||||
int insert(int k, int v){
|
||||
int h = hash(k);
|
||||
if (head[h] == 0){
|
||||
cnt = cnt + 1;
|
||||
head[h] = cnt;
|
||||
key[cnt] = k;
|
||||
value[cnt] = v;
|
||||
next[cnt] = 0;
|
||||
nextvalue[cnt] = 0;
|
||||
return 0;
|
||||
}
|
||||
int p = head[h];
|
||||
while (p != 0){
|
||||
if (key[p] == k){
|
||||
cnt = cnt + 1;
|
||||
nextvalue[cnt] = nextvalue[p];
|
||||
nextvalue[p] = cnt;
|
||||
value[cnt] = v;
|
||||
return 1;
|
||||
}
|
||||
p = next[p];
|
||||
}
|
||||
cnt = cnt + 1;
|
||||
next[cnt] = head[h];
|
||||
head[h] = cnt;
|
||||
key[cnt] = k;
|
||||
value[cnt] = v;
|
||||
nextvalue[cnt] = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int reduce(int k){
|
||||
int h = hash(k);
|
||||
int p = head[h];
|
||||
|
||||
while (p != 0){
|
||||
if (key[p] == k){
|
||||
int ret = 0;
|
||||
int x = p;
|
||||
while (x != 0){
|
||||
ret = ret + value[x];
|
||||
x = nextvalue[x];
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
p = next[p];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(){
|
||||
hashmod = getint();
|
||||
int ks = getarray(keys);
|
||||
int vs = getarray(values);
|
||||
int ms = getarray(requests);
|
||||
|
||||
starttime();
|
||||
|
||||
int i = 0;
|
||||
while (i < ks){
|
||||
insert(keys[i], values[i]);
|
||||
i = i + 1;
|
||||
}
|
||||
i = 0;
|
||||
while (i < ms){
|
||||
ans[i] = reduce(requests[i]);
|
||||
i = i + 1;
|
||||
}
|
||||
stoptime();
|
||||
putarray(ms, ans);
|
||||
return 0;
|
||||
}
|
||||
93
testcases/final_performance/shuffle1.sy
Executable file
93
testcases/final_performance/shuffle1.sy
Executable file
@ -0,0 +1,93 @@
|
||||
int hashmod;
|
||||
|
||||
const int maxn = 10000000;
|
||||
const int maxm = 10000000;
|
||||
int bucket[maxn];
|
||||
int head[maxn];
|
||||
int next[maxm];
|
||||
int nextvalue[maxm];
|
||||
int key[maxm];
|
||||
int value[maxm];
|
||||
int cnt;
|
||||
|
||||
int keys[maxm];
|
||||
int values[maxm];
|
||||
int requests[maxm];
|
||||
int ans[maxm];
|
||||
|
||||
int hash(int k){
|
||||
return k % hashmod;
|
||||
}
|
||||
|
||||
int insert(int k, int v){
|
||||
int h = hash(k);
|
||||
if (head[h] == 0){
|
||||
cnt = cnt + 1;
|
||||
head[h] = cnt;
|
||||
key[cnt] = k;
|
||||
value[cnt] = v;
|
||||
next[cnt] = 0;
|
||||
nextvalue[cnt] = 0;
|
||||
return 0;
|
||||
}
|
||||
int p = head[h];
|
||||
while (p != 0){
|
||||
if (key[p] == k){
|
||||
cnt = cnt + 1;
|
||||
nextvalue[cnt] = nextvalue[p];
|
||||
nextvalue[p] = cnt;
|
||||
value[cnt] = v;
|
||||
return 1;
|
||||
}
|
||||
p = next[p];
|
||||
}
|
||||
cnt = cnt + 1;
|
||||
next[cnt] = head[h];
|
||||
head[h] = cnt;
|
||||
key[cnt] = k;
|
||||
value[cnt] = v;
|
||||
nextvalue[cnt] = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int reduce(int k){
|
||||
int h = hash(k);
|
||||
int p = head[h];
|
||||
|
||||
while (p != 0){
|
||||
if (key[p] == k){
|
||||
int ret = 0;
|
||||
int x = p;
|
||||
while (x != 0){
|
||||
ret = ret + value[x];
|
||||
x = nextvalue[x];
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
p = next[p];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(){
|
||||
hashmod = getint();
|
||||
int ks = getarray(keys);
|
||||
int vs = getarray(values);
|
||||
int ms = getarray(requests);
|
||||
|
||||
starttime();
|
||||
|
||||
int i = 0;
|
||||
while (i < ks){
|
||||
insert(keys[i], values[i]);
|
||||
i = i + 1;
|
||||
}
|
||||
i = 0;
|
||||
while (i < ms){
|
||||
ans[i] = reduce(requests[i]);
|
||||
i = i + 1;
|
||||
}
|
||||
stoptime();
|
||||
putarray(ms, ans);
|
||||
return 0;
|
||||
}
|
||||
93
testcases/final_performance/shuffle2.sy
Executable file
93
testcases/final_performance/shuffle2.sy
Executable file
@ -0,0 +1,93 @@
|
||||
int hashmod;
|
||||
|
||||
const int maxn = 10000000;
|
||||
const int maxm = 10000000;
|
||||
int bucket[maxn];
|
||||
int head[maxn];
|
||||
int next[maxm];
|
||||
int nextvalue[maxm];
|
||||
int key[maxm];
|
||||
int value[maxm];
|
||||
int cnt;
|
||||
|
||||
int keys[maxm];
|
||||
int values[maxm];
|
||||
int requests[maxm];
|
||||
int ans[maxm];
|
||||
|
||||
int hash(int k){
|
||||
return k % hashmod;
|
||||
}
|
||||
|
||||
int insert(int k, int v){
|
||||
int h = hash(k);
|
||||
if (head[h] == 0){
|
||||
cnt = cnt + 1;
|
||||
head[h] = cnt;
|
||||
key[cnt] = k;
|
||||
value[cnt] = v;
|
||||
next[cnt] = 0;
|
||||
nextvalue[cnt] = 0;
|
||||
return 0;
|
||||
}
|
||||
int p = head[h];
|
||||
while (p != 0){
|
||||
if (key[p] == k){
|
||||
cnt = cnt + 1;
|
||||
nextvalue[cnt] = nextvalue[p];
|
||||
nextvalue[p] = cnt;
|
||||
value[cnt] = v;
|
||||
return 1;
|
||||
}
|
||||
p = next[p];
|
||||
}
|
||||
cnt = cnt + 1;
|
||||
next[cnt] = head[h];
|
||||
head[h] = cnt;
|
||||
key[cnt] = k;
|
||||
value[cnt] = v;
|
||||
nextvalue[cnt] = 0;
|
||||
return 0;
|
||||
}
|
||||
|
||||
int reduce(int k){
|
||||
int h = hash(k);
|
||||
int p = head[h];
|
||||
|
||||
while (p != 0){
|
||||
if (key[p] == k){
|
||||
int ret = 0;
|
||||
int x = p;
|
||||
while (x != 0){
|
||||
ret = ret + value[x];
|
||||
x = nextvalue[x];
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
p = next[p];
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
int main(){
|
||||
hashmod = getint();
|
||||
int ks = getarray(keys);
|
||||
int vs = getarray(values);
|
||||
int ms = getarray(requests);
|
||||
|
||||
starttime();
|
||||
|
||||
int i = 0;
|
||||
while (i < ks){
|
||||
insert(keys[i], values[i]);
|
||||
i = i + 1;
|
||||
}
|
||||
i = 0;
|
||||
while (i < ms){
|
||||
ans[i] = reduce(requests[i]);
|
||||
i = i + 1;
|
||||
}
|
||||
stoptime();
|
||||
putarray(ms, ans);
|
||||
return 0;
|
||||
}
|
||||
51
testcases/final_performance/transpose0.sy
Executable file
51
testcases/final_performance/transpose0.sy
Executable file
@ -0,0 +1,51 @@
|
||||
int matrix[20000000];
|
||||
int a[100000];
|
||||
|
||||
int transpose(int n, int matrix[], int rowsize){
|
||||
int colsize = n / rowsize;
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
while (i < colsize){
|
||||
j = 0;
|
||||
while (j < rowsize){
|
||||
if (i < j){
|
||||
j = j + 1;
|
||||
continue;
|
||||
}
|
||||
int curr = matrix[i * rowsize + j];
|
||||
matrix[j * colsize + i] = matrix[i * rowsize + j];
|
||||
matrix[i * rowsize + j] = curr;
|
||||
j = j + 1;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int main(){
|
||||
int n = getint();
|
||||
int len = getarray(a);
|
||||
starttime();
|
||||
int i = 0;
|
||||
while (i < n){
|
||||
matrix[i] = i;
|
||||
i = i + 1;
|
||||
}
|
||||
i = 0;
|
||||
while (i < len){
|
||||
transpose(n, matrix, a[i]);
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
int ans = 0;
|
||||
i = 0;
|
||||
while (i < len){
|
||||
ans = ans + i * i * matrix[i];
|
||||
i = i + 1;
|
||||
}
|
||||
if (ans < 0) ans = -ans;
|
||||
stoptime();
|
||||
putint(ans);
|
||||
putch(10);
|
||||
return 0;
|
||||
}
|
||||
51
testcases/final_performance/transpose1.sy
Executable file
51
testcases/final_performance/transpose1.sy
Executable file
@ -0,0 +1,51 @@
|
||||
int matrix[20000000];
|
||||
int a[100000];
|
||||
|
||||
int transpose(int n, int matrix[], int rowsize){
|
||||
int colsize = n / rowsize;
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
while (i < colsize){
|
||||
j = 0;
|
||||
while (j < rowsize){
|
||||
if (i < j){
|
||||
j = j + 1;
|
||||
continue;
|
||||
}
|
||||
int curr = matrix[i * rowsize + j];
|
||||
matrix[j * colsize + i] = matrix[i * rowsize + j];
|
||||
matrix[i * rowsize + j] = curr;
|
||||
j = j + 1;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int main(){
|
||||
int n = getint();
|
||||
int len = getarray(a);
|
||||
starttime();
|
||||
int i = 0;
|
||||
while (i < n){
|
||||
matrix[i] = i;
|
||||
i = i + 1;
|
||||
}
|
||||
i = 0;
|
||||
while (i < len){
|
||||
transpose(n, matrix, a[i]);
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
int ans = 0;
|
||||
i = 0;
|
||||
while (i < len){
|
||||
ans = ans + i * i * matrix[i];
|
||||
i = i + 1;
|
||||
}
|
||||
if (ans < 0) ans = -ans;
|
||||
stoptime();
|
||||
putint(ans);
|
||||
putch(10);
|
||||
return 0;
|
||||
}
|
||||
51
testcases/final_performance/transpose2.sy
Executable file
51
testcases/final_performance/transpose2.sy
Executable file
@ -0,0 +1,51 @@
|
||||
int matrix[20000000];
|
||||
int a[100000];
|
||||
|
||||
int transpose(int n, int matrix[], int rowsize){
|
||||
int colsize = n / rowsize;
|
||||
int i = 0;
|
||||
int j = 0;
|
||||
while (i < colsize){
|
||||
j = 0;
|
||||
while (j < rowsize){
|
||||
if (i < j){
|
||||
j = j + 1;
|
||||
continue;
|
||||
}
|
||||
int curr = matrix[i * rowsize + j];
|
||||
matrix[j * colsize + i] = matrix[i * rowsize + j];
|
||||
matrix[i * rowsize + j] = curr;
|
||||
j = j + 1;
|
||||
}
|
||||
i = i + 1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
int main(){
|
||||
int n = getint();
|
||||
int len = getarray(a);
|
||||
starttime();
|
||||
int i = 0;
|
||||
while (i < n){
|
||||
matrix[i] = i;
|
||||
i = i + 1;
|
||||
}
|
||||
i = 0;
|
||||
while (i < len){
|
||||
transpose(n, matrix, a[i]);
|
||||
i = i + 1;
|
||||
}
|
||||
|
||||
int ans = 0;
|
||||
i = 0;
|
||||
while (i < len){
|
||||
ans = ans + i * i * matrix[i];
|
||||
i = i + 1;
|
||||
}
|
||||
if (ans < 0) ans = -ans;
|
||||
stoptime();
|
||||
putint(ans);
|
||||
putch(10);
|
||||
return 0;
|
||||
}
|
||||
85
testcases/final_performance/vector_mul1.sy
Normal file
85
testcases/final_performance/vector_mul1.sy
Normal file
@ -0,0 +1,85 @@
|
||||
int func(int i, int j) {
|
||||
return ((i+j) * (i+j+1) / 2 + i + 1);
|
||||
}
|
||||
|
||||
float Vectordot(float v[], float u[], int n) {
|
||||
int i = 0;
|
||||
float sum = 0;
|
||||
while (i < n) {
|
||||
sum =sum+ v[i] * u[i];
|
||||
i=i+1;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
void mult1(float v[], float out[],int n) {
|
||||
int i = 0, j = 0;
|
||||
float sum = 0;
|
||||
|
||||
while (i < n) {
|
||||
while (j < n) {
|
||||
sum =sum+ v[j] / func(i,j);
|
||||
j=j+1;
|
||||
}
|
||||
out[i] = sum;
|
||||
i=i+1;
|
||||
}
|
||||
}
|
||||
|
||||
void mult2(float v[], float out[], int n) {
|
||||
int i = 0, j = 0;
|
||||
float sum = 0;
|
||||
|
||||
while (i < n) {
|
||||
while (j < n) {
|
||||
sum =sum+ v[j] / func(j,i);
|
||||
j=j+1;
|
||||
}
|
||||
out[i] = sum;
|
||||
i=i+1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void mult_combin(float v[], float out[], int n, float tmp[]) {
|
||||
mult1(v, tmp, n);
|
||||
mult2(tmp, out, n);
|
||||
}
|
||||
|
||||
float temp = 1;
|
||||
float my_sqrt(float input) {
|
||||
while (temp - input / temp > 1e-6 || temp - input / temp < -1e-6){
|
||||
temp = (temp+input/temp)/2;
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int n = 100000;
|
||||
if (n <= 0) {
|
||||
n = 2000;
|
||||
}
|
||||
starttime();
|
||||
float vectorA[100000], vectorB[100000], Vectortmp[100000];
|
||||
|
||||
int i;
|
||||
while(i < n) {
|
||||
vectorA[i] = 1;
|
||||
i=i+1;
|
||||
}
|
||||
i = 0;
|
||||
while(i < 1000) {
|
||||
mult_combin(vectorA, vectorB, n, Vectortmp);
|
||||
mult_combin(vectorB, vectorA, n, Vectortmp);
|
||||
i=i+1;
|
||||
}
|
||||
stoptime();
|
||||
float result = my_sqrt(Vectordot(vectorA,vectorB, n) / Vectordot(vectorB,vectorB,n));
|
||||
if(result - 1.000000 <= 1e-6 && result - 1.000000 >= -1e-6){
|
||||
putint(1);
|
||||
}else{
|
||||
putint(0);
|
||||
}
|
||||
putch(10);
|
||||
return 0;
|
||||
}
|
||||
85
testcases/final_performance/vector_mul2.sy
Normal file
85
testcases/final_performance/vector_mul2.sy
Normal file
@ -0,0 +1,85 @@
|
||||
int func(int i, int j) {
|
||||
return ((i+j) * (i+j+1) / 2 + i + 1);
|
||||
}
|
||||
|
||||
float Vectordot(float v[], float u[], int n) {
|
||||
int i = 0;
|
||||
float sum = 0;
|
||||
while (i < n) {
|
||||
sum =sum+ v[i] * u[i];
|
||||
i=i+1;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
void mult1(float v[], float out[],int n) {
|
||||
int i = 0, j = 0;
|
||||
float sum = 0;
|
||||
|
||||
while (i < n) {
|
||||
while (j < n) {
|
||||
sum =sum+ v[j] / func(i,j);
|
||||
j=j+1;
|
||||
}
|
||||
out[i] = sum;
|
||||
i=i+1;
|
||||
}
|
||||
}
|
||||
|
||||
void mult2(float v[], float out[], int n) {
|
||||
int i = 0, j = 0;
|
||||
float sum = 0;
|
||||
|
||||
while (i < n) {
|
||||
while (j < n) {
|
||||
sum =sum+ v[j] / func(j,i);
|
||||
j=j+1;
|
||||
}
|
||||
out[i] = sum;
|
||||
i=i+1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void mult_combin(float v[], float out[], int n, float tmp[]) {
|
||||
mult1(v, tmp, n);
|
||||
mult2(tmp, out, n);
|
||||
}
|
||||
|
||||
float temp = 1;
|
||||
float my_sqrt(float input) {
|
||||
while (temp - input / temp > 1e-6 || temp - input / temp < -1e-6){
|
||||
temp = (temp+input/temp)/2;
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int n = 100000;
|
||||
if (n <= 0) {
|
||||
n = 2000;
|
||||
}
|
||||
starttime();
|
||||
float vectorA[100000], vectorB[100000], Vectortmp[100000];
|
||||
|
||||
int i;
|
||||
while(i < n) {
|
||||
vectorA[i] = 1;
|
||||
i=i+1;
|
||||
}
|
||||
i = 0;
|
||||
while(i < 1000) {
|
||||
mult_combin(vectorA, vectorB, n, Vectortmp);
|
||||
mult_combin(vectorB, vectorA, n, Vectortmp);
|
||||
i=i+1;
|
||||
}
|
||||
stoptime();
|
||||
float result = my_sqrt(Vectordot(vectorA,vectorB, n) / Vectordot(vectorB,vectorB,n));
|
||||
if(result - 1.000000 <= 1e-6 && result - 1.000000 >= -1e-6){
|
||||
putint(1);
|
||||
}else{
|
||||
putint(0);
|
||||
}
|
||||
putch(10);
|
||||
return 0;
|
||||
}
|
||||
85
testcases/final_performance/vector_mul3.sy
Normal file
85
testcases/final_performance/vector_mul3.sy
Normal file
@ -0,0 +1,85 @@
|
||||
int func(int i, int j) {
|
||||
return ((i+j) * (i+j+1) / 2 + i + 1);
|
||||
}
|
||||
|
||||
float Vectordot(float v[], float u[], int n) {
|
||||
int i = 0;
|
||||
float sum = 0;
|
||||
while (i < n) {
|
||||
sum =sum+ v[i] * u[i];
|
||||
i=i+1;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
|
||||
void mult1(float v[], float out[],int n) {
|
||||
int i = 0, j = 0;
|
||||
float sum = 0;
|
||||
|
||||
while (i < n) {
|
||||
while (j < n) {
|
||||
sum =sum+ v[j] / func(i,j);
|
||||
j=j+1;
|
||||
}
|
||||
out[i] = sum;
|
||||
i=i+1;
|
||||
}
|
||||
}
|
||||
|
||||
void mult2(float v[], float out[], int n) {
|
||||
int i = 0, j = 0;
|
||||
float sum = 0;
|
||||
|
||||
while (i < n) {
|
||||
while (j < n) {
|
||||
sum =sum+ v[j] / func(j,i);
|
||||
j=j+1;
|
||||
}
|
||||
out[i] = sum;
|
||||
i=i+1;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void mult_combin(float v[], float out[], int n, float tmp[]) {
|
||||
mult1(v, tmp, n);
|
||||
mult2(tmp, out, n);
|
||||
}
|
||||
|
||||
float temp = 1;
|
||||
float my_sqrt(float input) {
|
||||
while (temp - input / temp > 1e-6 || temp - input / temp < -1e-6){
|
||||
temp = (temp+input/temp)/2;
|
||||
}
|
||||
return temp;
|
||||
}
|
||||
|
||||
int main() {
|
||||
int n = 100000;
|
||||
if (n <= 0) {
|
||||
n = 2000;
|
||||
}
|
||||
starttime();
|
||||
float vectorA[100000], vectorB[100000], Vectortmp[100000];
|
||||
|
||||
int i;
|
||||
while(i < n) {
|
||||
vectorA[i] = 1;
|
||||
i=i+1;
|
||||
}
|
||||
i = 0;
|
||||
while(i < 1000) {
|
||||
mult_combin(vectorA, vectorB, n, Vectortmp);
|
||||
mult_combin(vectorB, vectorA, n, Vectortmp);
|
||||
i=i+1;
|
||||
}
|
||||
stoptime();
|
||||
float result = my_sqrt(Vectordot(vectorA,vectorB, n) / Vectordot(vectorB,vectorB,n));
|
||||
if(result - 1.000000 <= 1e-6 && result - 1.000000 >= -1e-6){
|
||||
putint(1);
|
||||
}else{
|
||||
putint(0);
|
||||
}
|
||||
putch(10);
|
||||
return 0;
|
||||
}
|
||||
3
testcases/functional/00_main.sy
Normal file
3
testcases/functional/00_main.sy
Normal file
@ -0,0 +1,3 @@
|
||||
int main(){
|
||||
return 3;
|
||||
}
|
||||
8
testcases/functional/01_var_defn2.sy
Normal file
8
testcases/functional/01_var_defn2.sy
Normal file
@ -0,0 +1,8 @@
|
||||
//test domain of global var define and local define
|
||||
int a = 3;
|
||||
int b = 5;
|
||||
|
||||
int main(){
|
||||
int a = 5;
|
||||
return a + b;
|
||||
}
|
||||
8
testcases/functional/02_var_defn3.sy
Normal file
8
testcases/functional/02_var_defn3.sy
Normal file
@ -0,0 +1,8 @@
|
||||
//test local var define
|
||||
int main(){
|
||||
int a, b0, _c;
|
||||
a = 1;
|
||||
b0 = 2;
|
||||
_c = 3;
|
||||
return b0 + _c;
|
||||
}
|
||||
4
testcases/functional/03_arr_defn2.sy
Normal file
4
testcases/functional/03_arr_defn2.sy
Normal file
@ -0,0 +1,4 @@
|
||||
int a[10][10];
|
||||
int main(){
|
||||
return 0;
|
||||
}
|
||||
9
testcases/functional/04_arr_defn3.sy
Normal file
9
testcases/functional/04_arr_defn3.sy
Normal file
@ -0,0 +1,9 @@
|
||||
//test array define
|
||||
int main(){
|
||||
int a[4][2] = {};
|
||||
int b[4][2] = {1, 2, 3, 4, 5, 6, 7, 8};
|
||||
int c[4][2] = {{1, 2}, {3, 4}, {5, 6}, {7, 8}};
|
||||
int d[4][2] = {1, 2, {3}, {5}, 7 , 8};
|
||||
int e[4][2] = {{d[2][1], c[2][1]}, {3, 4}, {5, 6}, {7, 8}};
|
||||
return e[3][1] + e[0][0] + e[0][1] + a[2][0];
|
||||
}
|
||||
9
testcases/functional/05_arr_defn4.sy
Normal file
9
testcases/functional/05_arr_defn4.sy
Normal file
@ -0,0 +1,9 @@
|
||||
int main(){
|
||||
const int a[4][2] = {{1, 2}, {3, 4}, {}, 7};
|
||||
const int N = 3;
|
||||
int b[4][2] = {};
|
||||
int c[4][2] = {1, 2, 3, 4, 5, 6, 7, 8};
|
||||
int d[N + 1][2] = {1, 2, {3}, {5}, a[3][0], 8};
|
||||
int e[4][2][1] = {{d[2][1], {c[2][1]}}, {3, 4}, {5, 6}, {7, 8}};
|
||||
return e[3][1][0] + e[0][0][0] + e[0][1][0] + d[3][0];
|
||||
}
|
||||
6
testcases/functional/06_const_var_defn2.sy
Normal file
6
testcases/functional/06_const_var_defn2.sy
Normal file
@ -0,0 +1,6 @@
|
||||
//test const gloal var define
|
||||
const int a = 10, b = 5;
|
||||
|
||||
int main(){
|
||||
return b;
|
||||
}
|
||||
5
testcases/functional/07_const_var_defn3.sy
Normal file
5
testcases/functional/07_const_var_defn3.sy
Normal file
@ -0,0 +1,5 @@
|
||||
//test const local var define
|
||||
int main(){
|
||||
const int a = 10, b = 5;
|
||||
return b;
|
||||
}
|
||||
5
testcases/functional/08_const_array_defn.sy
Normal file
5
testcases/functional/08_const_array_defn.sy
Normal file
@ -0,0 +1,5 @@
|
||||
const int a[5]={0,1,2,3,4};
|
||||
|
||||
int main(){
|
||||
return a[4];
|
||||
}
|
||||
11
testcases/functional/09_func_defn.sy
Normal file
11
testcases/functional/09_func_defn.sy
Normal file
@ -0,0 +1,11 @@
|
||||
int a;
|
||||
int func(int p){
|
||||
p = p - 1;
|
||||
return p;
|
||||
}
|
||||
int main(){
|
||||
int b;
|
||||
a = 10;
|
||||
b = func(a);
|
||||
return b;
|
||||
}
|
||||
8
testcases/functional/10_var_defn_func.sy
Normal file
8
testcases/functional/10_var_defn_func.sy
Normal file
@ -0,0 +1,8 @@
|
||||
int defn(){
|
||||
return 4;
|
||||
}
|
||||
|
||||
int main(){
|
||||
int a=defn();
|
||||
return a;
|
||||
}
|
||||
7
testcases/functional/11_add2.sy
Normal file
7
testcases/functional/11_add2.sy
Normal file
@ -0,0 +1,7 @@
|
||||
//test add
|
||||
int main(){
|
||||
int a, b;
|
||||
a = 10;
|
||||
b = -1;
|
||||
return a + b;
|
||||
}
|
||||
5
testcases/functional/12_addc.sy
Normal file
5
testcases/functional/12_addc.sy
Normal file
@ -0,0 +1,5 @@
|
||||
//test addc
|
||||
const int a = 10;
|
||||
int main(){
|
||||
return a + 5;
|
||||
}
|
||||
7
testcases/functional/13_sub2.sy
Normal file
7
testcases/functional/13_sub2.sy
Normal file
@ -0,0 +1,7 @@
|
||||
//test sub
|
||||
const int a = 10;
|
||||
int main(){
|
||||
int b;
|
||||
b = 2;
|
||||
return b - a;
|
||||
}
|
||||
6
testcases/functional/14_subc.sy
Normal file
6
testcases/functional/14_subc.sy
Normal file
@ -0,0 +1,6 @@
|
||||
//test subc
|
||||
int main(){
|
||||
int a;
|
||||
a = 10;
|
||||
return a - 2;
|
||||
}
|
||||
7
testcases/functional/15_mul.sy
Normal file
7
testcases/functional/15_mul.sy
Normal file
@ -0,0 +1,7 @@
|
||||
//test mul
|
||||
int main(){
|
||||
int a, b;
|
||||
a = 10;
|
||||
b = 5;
|
||||
return a * b;
|
||||
}
|
||||
5
testcases/functional/16_mulc.sy
Normal file
5
testcases/functional/16_mulc.sy
Normal file
@ -0,0 +1,5 @@
|
||||
//test mulc
|
||||
const int a = 5;
|
||||
int main(){
|
||||
return a * 5;
|
||||
}
|
||||
7
testcases/functional/17_div.sy
Normal file
7
testcases/functional/17_div.sy
Normal file
@ -0,0 +1,7 @@
|
||||
//test div
|
||||
int main(){
|
||||
int a, b;
|
||||
a = 10;
|
||||
b = 5;
|
||||
return a / b;
|
||||
}
|
||||
5
testcases/functional/18_divc.sy
Normal file
5
testcases/functional/18_divc.sy
Normal file
@ -0,0 +1,5 @@
|
||||
//test divc
|
||||
const int a = 10;
|
||||
int main(){
|
||||
return a / 5;
|
||||
}
|
||||
6
testcases/functional/19_mod.sy
Normal file
6
testcases/functional/19_mod.sy
Normal file
@ -0,0 +1,6 @@
|
||||
//test mod
|
||||
int main(){
|
||||
int a;
|
||||
a = 10;
|
||||
return a / 3;
|
||||
}
|
||||
6
testcases/functional/20_rem.sy
Normal file
6
testcases/functional/20_rem.sy
Normal file
@ -0,0 +1,6 @@
|
||||
//test rem
|
||||
int main(){
|
||||
int a;
|
||||
a = 10;
|
||||
return a % 3;
|
||||
}
|
||||
25
testcases/functional/21_if_test2.sy
Normal file
25
testcases/functional/21_if_test2.sy
Normal file
@ -0,0 +1,25 @@
|
||||
// test if-else-if
|
||||
int ifElseIf() {
|
||||
int a;
|
||||
a = 5;
|
||||
int b;
|
||||
b = 10;
|
||||
if(a == 6 || b == 0xb) {
|
||||
return a;
|
||||
}
|
||||
else {
|
||||
if (b == 10 && a == 1)
|
||||
a = 25;
|
||||
else if (b == 10 && a == -5)
|
||||
a = a + 15;
|
||||
else
|
||||
a = -+a;
|
||||
}
|
||||
|
||||
return a;
|
||||
}
|
||||
|
||||
int main(){
|
||||
putint(ifElseIf());
|
||||
return 0;
|
||||
}
|
||||
18
testcases/functional/22_if_test3.sy
Normal file
18
testcases/functional/22_if_test3.sy
Normal file
@ -0,0 +1,18 @@
|
||||
// test if-if-else
|
||||
int ififElse() {
|
||||
int a;
|
||||
a = 5;
|
||||
int b;
|
||||
b = 10;
|
||||
if(a == 5)
|
||||
if (b == 10)
|
||||
a = 25;
|
||||
else
|
||||
a = a + 15;
|
||||
|
||||
return (a);
|
||||
}
|
||||
|
||||
int main(){
|
||||
return (ififElse());
|
||||
}
|
||||
18
testcases/functional/23_if_test4.sy
Normal file
18
testcases/functional/23_if_test4.sy
Normal file
@ -0,0 +1,18 @@
|
||||
// test if-{if-else}
|
||||
int if_ifElse_() {
|
||||
int a;
|
||||
a = 5;
|
||||
int b;
|
||||
b = 10;
|
||||
if(a == 5){
|
||||
if (b == 10)
|
||||
a = 25;
|
||||
else
|
||||
a = a + 15;
|
||||
}
|
||||
return (a);
|
||||
}
|
||||
|
||||
int main(){
|
||||
return (if_ifElse_());
|
||||
}
|
||||
18
testcases/functional/24_if_test5.sy
Normal file
18
testcases/functional/24_if_test5.sy
Normal file
@ -0,0 +1,18 @@
|
||||
// test if-{if}-else
|
||||
int if_if_Else() {
|
||||
int a;
|
||||
a = 5;
|
||||
int b;
|
||||
b = 10;
|
||||
if(a == 5){
|
||||
if (b == 10)
|
||||
a = 25;
|
||||
}
|
||||
else
|
||||
a = a + 15;
|
||||
return (a);
|
||||
}
|
||||
|
||||
int main(){
|
||||
return (if_if_Else());
|
||||
}
|
||||
31
testcases/functional/25_while_if.sy
Normal file
31
testcases/functional/25_while_if.sy
Normal file
@ -0,0 +1,31 @@
|
||||
int get_one(int a) {
|
||||
return 1;
|
||||
}
|
||||
|
||||
int deepWhileBr(int a, int b) {
|
||||
int c;
|
||||
c = a + b;
|
||||
while (c < 75) {
|
||||
int d;
|
||||
d = 42;
|
||||
if (c < 100) {
|
||||
c = c + d;
|
||||
if (c > 99) {
|
||||
int e;
|
||||
e = d * 2;
|
||||
if (get_one(0) == 1) {
|
||||
c = e * 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return (c);
|
||||
}
|
||||
|
||||
int main() {
|
||||
int p;
|
||||
p = 2;
|
||||
p = deepWhileBr(p, p);
|
||||
putint(p);
|
||||
return 0;
|
||||
}
|
||||
18
testcases/functional/26_while_test1.sy
Normal file
18
testcases/functional/26_while_test1.sy
Normal file
@ -0,0 +1,18 @@
|
||||
int doubleWhile() {
|
||||
int i;
|
||||
i = 5;
|
||||
int j;
|
||||
j = 7;
|
||||
while (i < 100) {
|
||||
i = i + 30;
|
||||
while(j < 100){
|
||||
j = j + 6;
|
||||
}
|
||||
j = j - 100;
|
||||
}
|
||||
return (j);
|
||||
}
|
||||
|
||||
int main() {
|
||||
return doubleWhile();
|
||||
}
|
||||
31
testcases/functional/27_while_test2.sy
Normal file
31
testcases/functional/27_while_test2.sy
Normal file
@ -0,0 +1,31 @@
|
||||
int FourWhile() {
|
||||
int a;
|
||||
a = 5;
|
||||
int b;
|
||||
int c;
|
||||
b = 6;
|
||||
c = 7;
|
||||
int d;
|
||||
d = 10;
|
||||
while (a < 20) {
|
||||
a = a + 3;
|
||||
while(b < 10){
|
||||
b = b + 1;
|
||||
while(c == 7){
|
||||
c = c - 1;
|
||||
while(d < 20){
|
||||
d = d + 3;
|
||||
}
|
||||
d = d - 1;
|
||||
}
|
||||
c = c + 1;
|
||||
}
|
||||
b = b - 2;
|
||||
}
|
||||
|
||||
return (a + (b + d) + c);
|
||||
}
|
||||
|
||||
int main() {
|
||||
return FourWhile();
|
||||
}
|
||||
55
testcases/functional/28_while_test3.sy
Normal file
55
testcases/functional/28_while_test3.sy
Normal file
@ -0,0 +1,55 @@
|
||||
int g;
|
||||
int h;
|
||||
int f;
|
||||
int e;
|
||||
int EightWhile() {
|
||||
int a;
|
||||
a = 5;
|
||||
int b;
|
||||
int c;
|
||||
b = 6;
|
||||
c = 7;
|
||||
int d;
|
||||
d = 10;
|
||||
while (a < 20) {
|
||||
a = a + 3;
|
||||
while(b < 10){
|
||||
b = b + 1;
|
||||
while(c == 7){
|
||||
c = c - 1;
|
||||
while(d < 20){
|
||||
d = d + 3;
|
||||
while(e > 1){
|
||||
e = e-1;
|
||||
while(f > 2){
|
||||
f = f -2;
|
||||
while(g < 3){
|
||||
g = g +10;
|
||||
while(h < 10){
|
||||
h = h + 8;
|
||||
}
|
||||
h = h-1;
|
||||
}
|
||||
g = g- 8;
|
||||
}
|
||||
f = f + 1;
|
||||
}
|
||||
e = e + 1;
|
||||
}
|
||||
d = d - 1;
|
||||
}
|
||||
c = c + 1;
|
||||
}
|
||||
b = b - 2;
|
||||
}
|
||||
|
||||
return (a + (b + d) + c)-(e + d - g + h);
|
||||
}
|
||||
|
||||
int main() {
|
||||
g = 1;
|
||||
h = 2;
|
||||
e = 4;
|
||||
f = 6;
|
||||
return EightWhile();
|
||||
}
|
||||
15
testcases/functional/29_break.sy
Normal file
15
testcases/functional/29_break.sy
Normal file
@ -0,0 +1,15 @@
|
||||
//test break
|
||||
int main(){
|
||||
int i;
|
||||
i = 0;
|
||||
int sum;
|
||||
sum = 0;
|
||||
while(i < 100){
|
||||
if(i == 50){
|
||||
break;
|
||||
}
|
||||
sum = sum + i;
|
||||
i = i + 1;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
16
testcases/functional/30_continue.sy
Normal file
16
testcases/functional/30_continue.sy
Normal file
@ -0,0 +1,16 @@
|
||||
//test continue
|
||||
int main(){
|
||||
int i;
|
||||
i = 0;
|
||||
int sum;
|
||||
sum = 0;
|
||||
while(i < 100){
|
||||
if(i == 50){
|
||||
i = i + 1;
|
||||
continue;
|
||||
}
|
||||
sum = sum + i;
|
||||
i = i + 1;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
25
testcases/functional/31_while_if_test1.sy
Normal file
25
testcases/functional/31_while_if_test1.sy
Normal file
@ -0,0 +1,25 @@
|
||||
// test while-if
|
||||
int whileIf() {
|
||||
int a;
|
||||
a = 0;
|
||||
int b;
|
||||
b = 0;
|
||||
while (a < 100) {
|
||||
if (a == 5) {
|
||||
b = 25;
|
||||
}
|
||||
else if (a == 10) {
|
||||
b = 42;
|
||||
}
|
||||
else {
|
||||
b = a * 2;
|
||||
}
|
||||
a = a + 1;
|
||||
}
|
||||
return (b);
|
||||
}
|
||||
|
||||
|
||||
int main(){
|
||||
return (whileIf());
|
||||
}
|
||||
23
testcases/functional/32_while_if_test2.sy
Normal file
23
testcases/functional/32_while_if_test2.sy
Normal file
@ -0,0 +1,23 @@
|
||||
int ifWhile() {
|
||||
int a;
|
||||
a = 0;
|
||||
int b;
|
||||
b = 3;
|
||||
if (a == 5) {
|
||||
while(b == 2){
|
||||
b = b + 2;
|
||||
}
|
||||
b = b + 25;
|
||||
}
|
||||
else
|
||||
while (a < 5) {
|
||||
b = b * 2;
|
||||
a = a + 1;
|
||||
}
|
||||
return (b);
|
||||
}
|
||||
|
||||
|
||||
int main(){
|
||||
return (ifWhile());
|
||||
}
|
||||
25
testcases/functional/33_while_if_test3.sy
Normal file
25
testcases/functional/33_while_if_test3.sy
Normal file
@ -0,0 +1,25 @@
|
||||
int deepWhileBr(int a, int b) {
|
||||
int c;
|
||||
c = a + b;
|
||||
while (c < 75) {
|
||||
int d;
|
||||
d = 42;
|
||||
if (c < 100) {
|
||||
c = c + d;
|
||||
if (c > 99) {
|
||||
int e;
|
||||
e = d * 2;
|
||||
if (1 == 1) {
|
||||
c = e * 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return (c);
|
||||
}
|
||||
|
||||
int main() {
|
||||
int p;
|
||||
p = 2;
|
||||
return deepWhileBr(p, p);
|
||||
}
|
||||
11
testcases/functional/34_arr_expr_len.sy
Normal file
11
testcases/functional/34_arr_expr_len.sy
Normal file
@ -0,0 +1,11 @@
|
||||
const int N = -1;
|
||||
int arr[N + 2 * 4 - 99 / 99] = {1, 2, 33, 4, 5, 6};
|
||||
|
||||
int main() {
|
||||
int i = 0, sum = 0;
|
||||
while (i < 6) {
|
||||
sum = sum + arr[i];
|
||||
i = i + 1;
|
||||
}
|
||||
return sum;
|
||||
}
|
||||
9
testcases/functional/35_op_priority1.sy
Normal file
9
testcases/functional/35_op_priority1.sy
Normal file
@ -0,0 +1,9 @@
|
||||
//test the priority of add and mul
|
||||
int main(){
|
||||
int a, b, c, d;
|
||||
a = 10;
|
||||
b = 4;
|
||||
c = 2;
|
||||
d = 2;
|
||||
return c + a * b - d;
|
||||
}
|
||||
9
testcases/functional/36_op_priority2.sy
Normal file
9
testcases/functional/36_op_priority2.sy
Normal file
@ -0,0 +1,9 @@
|
||||
//test the priority of add and mul
|
||||
int main(){
|
||||
int a, b, c, d;
|
||||
a = 10;
|
||||
b = 4;
|
||||
c = 2;
|
||||
d = 2;
|
||||
return (c + a) * (b - d);
|
||||
}
|
||||
7
testcases/functional/37_op_priority3.sy
Normal file
7
testcases/functional/37_op_priority3.sy
Normal file
@ -0,0 +1,7 @@
|
||||
//test the priority of unary operator and binary operator
|
||||
int main(){
|
||||
int a, b;
|
||||
a = 10;
|
||||
b = 30;
|
||||
return a - -5 + b + -5;
|
||||
}
|
||||
19
testcases/functional/38_op_priority4.sy
Normal file
19
testcases/functional/38_op_priority4.sy
Normal file
@ -0,0 +1,19 @@
|
||||
int a;
|
||||
int b;
|
||||
int c;
|
||||
int d;
|
||||
int e;
|
||||
int main()
|
||||
{
|
||||
a=getint();
|
||||
b=getint();
|
||||
c=getint();
|
||||
d=getint();
|
||||
e=getint();
|
||||
int flag=0;
|
||||
if(a-b*c!=d-a/c||a*b/c==e+d||a+b+c==d+e)
|
||||
{
|
||||
flag=1;
|
||||
}
|
||||
return flag;
|
||||
}
|
||||
15
testcases/functional/39_op_priority5.sy
Normal file
15
testcases/functional/39_op_priority5.sy
Normal file
@ -0,0 +1,15 @@
|
||||
int a = 1;
|
||||
int b = 0;
|
||||
int c = 1;
|
||||
int d = 2;
|
||||
int e = 4;
|
||||
int main()
|
||||
{
|
||||
int flag=0;
|
||||
if(a * b / c == e + d && a * (a + b) + c <= d + e || a - (b * c) == d - a / c)
|
||||
{
|
||||
flag=1;
|
||||
}
|
||||
putint(flag);
|
||||
return flag;
|
||||
}
|
||||
11
testcases/functional/40_unary_op.sy
Normal file
11
testcases/functional/40_unary_op.sy
Normal file
@ -0,0 +1,11 @@
|
||||
int main() {
|
||||
int a;
|
||||
a = 10;
|
||||
if (+-!!!a) {
|
||||
a = - - -1;
|
||||
}
|
||||
else {
|
||||
a = 0;
|
||||
}
|
||||
return a;
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue
Block a user