Compare commits
	
		
			9 commits
		
	
	
		
			46b700e4f3
			...
			6407f8f478
		
	
	| Author | SHA1 | Date | |
|---|---|---|---|
|  | 6407f8f478 | ||
|  | 3a8fbfd762 | ||
|  | d85ee21d5b | ||
|  | f502803102 | ||
|  | 852fe43c21 | ||
|  | 0802b2508e | ||
|  | 4746ed5211 | ||
|  | 006fa07e79 | ||
|  | 855e8f8dff | 
					 7 changed files with 344 additions and 0 deletions
				
			
		
							
								
								
									
										45
									
								
								cpu/cache.c
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										45
									
								
								cpu/cache.c
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,45 @@ | |||
| #include <stdio.h> | ||||
| #define N 1024 | ||||
| 
 | ||||
| int gcd(int a, int b); | ||||
| int main() { | ||||
| 	int n, d; | ||||
| 	int i, j, k; | ||||
| 	/* to use shorter types such as short is a BAD idea */ | ||||
| 	static int A[N][N], B[N][N], C[N][N]; | ||||
| 	int res = 0; | ||||
| 
 | ||||
| 	scanf("%d %d", &n, &d); | ||||
| 	 | ||||
| 	for (i = 0; i < n; ++i) | ||||
| 		for (j = i; j < n; ++j) { | ||||
| 			//printf("%d %d\n", i ,j);
 | ||||
| 			A[i][j] = gcd(i + 2,j + 2); | ||||
| 			A[j][i] = A[i][j]; | ||||
| 		} | ||||
| 	//printf("nya!\n");
 | ||||
| 	for (i = 0; i < n; ++i) | ||||
| 		for (j = i; j < n; ++j) { | ||||
| 			//printf("%d %d\n", i ,j);
 | ||||
| 			B[i][j] = gcd(n - i,n - j); | ||||
| 			B[j][i] = B[i][j]; | ||||
| 		} | ||||
| 
 | ||||
| 	for (i = 0; i < n; ++i) | ||||
| 		for (j = 0; j < n; ++j) | ||||
| 			for (k = 0; k < n; ++k) { | ||||
| 				//printf("i:%d, j^%d, k^%d\n", i, j, k);
 | ||||
| 				C[i][j] += A[i][k] * B[j][k]; | ||||
| 			} | ||||
| 	for (i = 0; i < n; ++i) | ||||
| 		for (j = 0; j < n; ++j) | ||||
| 			if (C[i][j] % d == 0) | ||||
| 				++res; | ||||
| 
 | ||||
| 	printf("%d", res); | ||||
| } | ||||
| 
 | ||||
| int gcd(int a, int b) { | ||||
| 	return (a == 0) ? b : gcd(b % a, a);     | ||||
| } | ||||
| 
 | ||||
							
								
								
									
										68
									
								
								cpu/cpu.c
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										68
									
								
								cpu/cpu.c
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,68 @@ | |||
| #include <stdio.h> | ||||
| #include <stdint.h> | ||||
| 
 | ||||
| int check_registers(int a, int b, int max_reg); | ||||
| int main() { | ||||
| 	int max_reg = 4; | ||||
| #ifdef REGISTERS | ||||
| 	max_reg = REGISTERS; | ||||
| #endif | ||||
| 	/* A, B, C, D. Indice + 5 */ | ||||
| 	uint8_t reg[4] = {0, 0, 0, 0}; | ||||
| 	int i; | ||||
| 	uint8_t a, b; | ||||
| 	uint8_t x; | ||||
| 
 | ||||
| #ifdef _DEBUG | ||||
| 	printf("%hhu\n", x); | ||||
| #endif | ||||
| 	 | ||||
| 	while (1) { | ||||
| 		x = getchar() - '0'; | ||||
| #ifdef _DEBUG | ||||
| 		printf("x:%hhu\n", x); | ||||
| #endif | ||||
| 		switch (x) { | ||||
| 			case 0: | ||||
| 				return 0; | ||||
| 				break; | ||||
| 			case 1: | ||||
| 				scanf("%hhu %hhu\n", &a, &b); | ||||
| 				if (check_registers(a, b, max_reg)) { | ||||
| 					printf("-1\n"); | ||||
| 					return 0; | ||||
| 				} | ||||
| 				reg[a-5] += reg[b-5]; | ||||
| 				break; | ||||
| 			case 2: | ||||
| 				scanf("%hhu %hhu\n", &a, &b); | ||||
| 				if(check_registers(a, b, max_reg)) { | ||||
| 					printf("-1\n"); | ||||
| 					return 0; | ||||
| 				} | ||||
| 				reg[a-5] -= reg[b-5]; | ||||
| 				break; | ||||
| 			case 3: | ||||
| 				scanf("%hhu %hhu\n", &a, &b); | ||||
| 				if(check_registers(a, 0, max_reg)) { | ||||
| 					printf("-1\n"); | ||||
| 					return 0; | ||||
| 				} | ||||
| 				reg[a-5] = b; | ||||
| 				break; | ||||
| 			case 4: | ||||
| 				for (i = 0; i < max_reg; ++i) | ||||
| 					printf("%hhu ", reg[i]); | ||||
| 				putchar('\n'); | ||||
| 				break; | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| int check_registers(int a, int b, int max_reg) { | ||||
| 	a -= 5; | ||||
| 	b -= 5; | ||||
| 	if ((a >= max_reg) || (b >= max_reg)) | ||||
| 		return 1; | ||||
| 	return 0; | ||||
| } | ||||
							
								
								
									
										58
									
								
								cpu/cuda.c
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										58
									
								
								cpu/cuda.c
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,58 @@ | |||
| #include <stdio.h> | ||||
| #include <math.h> | ||||
| #define THR 32 | ||||
| #define MEM 128 | ||||
| #define REG 2 | ||||
| #define MAXTHR 1536 | ||||
| #define MAXMEM 49152 | ||||
| #define MAXREG 32768 | ||||
| 
 | ||||
| 
 | ||||
| int check_use(int x, const int frac); | ||||
| 
 | ||||
| int main() { | ||||
| 	int reg, thr, mem; | ||||
| 	int nbreg, nbmem, nbthr; | ||||
| 	int nthr; | ||||
| 	int min = 0; | ||||
| 
 | ||||
| 	freopen("cuda.in", "r", stdin); | ||||
| #ifndef _DEBUG | ||||
| 	freopen("cuda.out", "w", stdout); | ||||
| #endif | ||||
| 	scanf("%d %d %d", &thr, ®, &mem); | ||||
| 
 | ||||
| 	nthr = check_use(thr, THR); | ||||
| 	nbthr = (int) MAXTHR / nthr;	 | ||||
| 	nbreg = (int) MAXREG / (nthr*check_use(reg, REG)); | ||||
| 	nbmem = (int) MAXMEM / check_use(mem, MEM); | ||||
| 	 | ||||
| 
 | ||||
| 	if ((nbthr <= nbreg) && (nbthr <= nbmem)) | ||||
| 		min = nbthr; | ||||
| 	else if ((nbreg <= nbthr) && (nbreg <= nbmem)) | ||||
| 		min = nbreg; | ||||
| 	else if ((nbmem <= nbthr) && (nbmem <= nbreg)) | ||||
| 		min = nbmem; | ||||
| #ifdef _DEBUG | ||||
| 	printf("used: %d %d %d\n", check_use(thr, THR), nthr*check_use(reg, REG), check_use(mem, MEM)); | ||||
| 	printf("By threads: %d, by registers: %d, by memory: %d\n", nbthr, nbreg, nbmem); | ||||
| #endif | ||||
| 	printf("%d", (int)round((thr*min*100)/(double)MAXTHR)); | ||||
| 	return 0; | ||||
| } | ||||
| 
 | ||||
| int check_use(int x, const int frac) { | ||||
| 	int real_x = frac; | ||||
| 	while (1) { | ||||
| 		real_x += frac; | ||||
| 		if (real_x >= x) { | ||||
| 			x = real_x; | ||||
| 			break; | ||||
| 		} | ||||
| 	} | ||||
| #ifdef _DEBUG | ||||
| 	printf("%d %d\n", x, real_x); | ||||
| #endif | ||||
| 	return x; | ||||
| } | ||||
							
								
								
									
										94
									
								
								cpu/flag.c
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										94
									
								
								cpu/flag.c
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,94 @@ | |||
| #include <stdio.h> | ||||
| #include <stdint.h> | ||||
| 
 | ||||
| int check_registers(int a, int b, int max_reg); | ||||
| int main() { | ||||
| 	int max_reg = 4; | ||||
| 	int zf = 0, to_exec = 1; | ||||
| #ifdef REGISTERS | ||||
| 	max_reg = REGISTERS; | ||||
| #endif | ||||
| 	/* A, B, C, D. Indice - 5 */ | ||||
| 	uint8_t reg[4] = {0, 0, 0, 0}; | ||||
| 	int i; | ||||
| 	uint8_t a, b; | ||||
| 	uint8_t x; | ||||
| 	 | ||||
| 	while (1) {; | ||||
| 		scanf("%hhu", &x); | ||||
| #ifdef _DEBUG | ||||
| 		printf("x:%hhu\n", x); | ||||
| #endif | ||||
| 		if ((x & (1 << 7)) && !zf) { | ||||
| 			to_exec = 0; | ||||
| 			//zf = 0;
 | ||||
| 		} | ||||
| 		x &= 0x7F; | ||||
| #ifdef _DEBUG | ||||
| 		printf("zf:%d, to_exec:%d\n", zf, to_exec); | ||||
| #endif | ||||
| 		if (to_exec == 0) { | ||||
| 			if ((x >= 1) && (x <= 3)) | ||||
| 				scanf("%hhu %hhu\n", &a, &b); | ||||
| 			to_exec = 1; | ||||
| 			zf = 0; | ||||
| 			continue; | ||||
| 		} | ||||
| 
 | ||||
| 		switch (x) { | ||||
| 			case 0: | ||||
| 				return 0; | ||||
| 				break; | ||||
| 			case 1: | ||||
| 				scanf("%hhu %hhu\n", &a, &b); | ||||
| 				if (check_registers(a, b, max_reg)) { | ||||
| 					printf("-1\n"); | ||||
| 					return 0; | ||||
| 				} | ||||
| 				reg[a-5] += reg[b-5]; | ||||
| 				if (reg[a-5] == 0) | ||||
| 					zf = 1; | ||||
| 				else | ||||
| 					zf = 0; | ||||
| 				break; | ||||
| 			case 2: | ||||
| 				scanf("%hhu %hhu\n", &a, &b); | ||||
| 				if(check_registers(a, b, max_reg)) { | ||||
| 					printf("-1\n"); | ||||
| 					return 0; | ||||
| 				} | ||||
| 				reg[a-5] -= reg[b-5]; | ||||
| 				if (reg[a-5] == 0) | ||||
| 					zf = 1; | ||||
| 				else | ||||
| 					zf = 0; | ||||
| 				break; | ||||
| 			case 3: | ||||
| 				scanf("%hhu %hhu\n", &a, &b); | ||||
| 				if(check_registers(a, 0, max_reg)) { | ||||
| 					printf("-1\n"); | ||||
| 					return 0; | ||||
| 				} | ||||
| 				reg[a-5] = b; | ||||
| 				if (reg[a-5] == 0) | ||||
| 					zf = 1; | ||||
| 				else | ||||
| 					zf = 0; | ||||
| 				break; | ||||
| 			case 4: | ||||
| 				for (i = 0; i < max_reg; ++i) | ||||
| 					printf("%hhu ", reg[i]); | ||||
| 				putchar('\n'); | ||||
| 				break; | ||||
| 		} | ||||
| 		to_exec = 1; | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| int check_registers(int a, int b, int max_reg) { | ||||
| 	a -= 5; | ||||
| 	b -= 5; | ||||
| 	if ((a >= max_reg) || (b >= max_reg)) | ||||
| 		return 1; | ||||
| 	return 0; | ||||
| } | ||||
							
								
								
									
										6
									
								
								cpu/neo.c
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										6
									
								
								cpu/neo.c
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,6 @@ | |||
| char* whatisyourname() { | ||||
| 	char *res = calloc(256+1, sizeof(char)); | ||||
| 	for (int i = 0; i < 256; ++i) | ||||
| 		res[i] = '1'; | ||||
| 	return res; | ||||
| } | ||||
							
								
								
									
										46
									
								
								cpu/pdp_rw.c
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										46
									
								
								cpu/pdp_rw.c
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,46 @@ | |||
| #include <stdint.h> | ||||
| #include <stdio.h> | ||||
| typedef uint8_t byte; | ||||
| typedef uint16_t word; | ||||
| typedef uint16_t adr; | ||||
| 
 | ||||
| byte mem[1 << 16]; | ||||
| 
 | ||||
| byte b_read (adr a) { | ||||
| 	return mem[a]; | ||||
| } | ||||
| void b_write (adr a, byte val) { | ||||
| 	mem[a] = val; | ||||
| } | ||||
| word w_read  (adr a) { | ||||
| 	return *(word*)&mem[a]; | ||||
| } | ||||
| void w_write (adr a, word val) { | ||||
| 	*(word*)&mem[a] = val; | ||||
| } | ||||
| void load_file() { | ||||
| 	adr a; | ||||
| 	int n, i; | ||||
| 	byte x; | ||||
| 
 | ||||
| 	while(scanf("%hx %x", &a, &n) != EOF) { | ||||
| 		//printf("%x", n);
 | ||||
| 		for (i = 0; i < n; ++i) { | ||||
| 			//printf("number %d\n", i);
 | ||||
| 			scanf("%hhx", &x); | ||||
| 			b_write(a+i, x); | ||||
| 			//printf("Read %hx\n", mem[a+2*i]);
 | ||||
| 		} | ||||
| 	} | ||||
| } | ||||
| 
 | ||||
| void mem_dump(adr start, word n) { | ||||
| 	for (int i = 0; i < n; i+=2) { | ||||
| 		//printf("%d:read from %hx: %hx\n", i,start+i, *(word*)&mem[start+i]);
 | ||||
| 		printf("%06ho : %06ho\n", start+i, *(word*)&mem[start+i]); | ||||
| 	} | ||||
| } | ||||
| //int main() {
 | ||||
| //	load_file();
 | ||||
| //	mem_dump(0x40, 4);
 | ||||
| //}
 | ||||
							
								
								
									
										27
									
								
								cpu/simple_page.c
									
										
									
									
									
										Normal file
									
								
							
							
						
						
									
										27
									
								
								cpu/simple_page.c
									
										
									
									
									
										Normal file
									
								
							|  | @ -0,0 +1,27 @@ | |||
| #include <stdio.h> | ||||
| #include <stdlib.h> | ||||
| 
 | ||||
| int main() { | ||||
| 	unsigned N, i, page_n, log; | ||||
| 	 | ||||
| 	scanf("%u", &N); | ||||
| 	unsigned *mem = (unsigned*)calloc(N, sizeof(unsigned)); | ||||
| 	for (i = 0; i < N; ++i) { | ||||
| 		scanf("%x", &mem[i]); | ||||
| 	} | ||||
| 
 | ||||
| 	scanf("%x", &log); | ||||
| 	page_n = (log >> 26) & 0b111111; | ||||
| 	if (page_n < N) { | ||||
| 		printf("%x", mem[page_n]+(log << 6 >> 6)); | ||||
| 	} | ||||
| 	else { | ||||
| 		printf("error"); | ||||
| 	} | ||||
| 
 | ||||
| 
 | ||||
| 	free(mem); | ||||
| 	return 0; | ||||
| 
 | ||||
| 
 | ||||
| } | ||||
		Reference in a new issue