cpu full
parent
d85ee21d5b
commit
3a8fbfd762
@ -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;
|
||||
}
|
@ -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);
|
||||
//}
|
@ -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 New Issue