summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjonsykkel <jonrevold@gmail.com>2020-04-06 14:43:40 +0200
committerjonsykkel <jonrevold@gmail.com>2020-04-06 14:43:40 +0200
commit7b09424e449ff290a1e2397305abafb3a2eeef59 (patch)
treea6d3bd6a70db6dbdc5f2792887f38a14d4d75f1a
parentc400208232b21c3eceb7d07d2cbf2d4d7b22845c (diff)
downloadct_sequence-7b09424e449ff290a1e2397305abafb3a2eeef59.tar.gz
VORK
-rw-r--r--src/a0.c11
-rw-r--r--src/a1.c53
-rw-r--r--src/a2.c28
-rw-r--r--src/main.c10
4 files changed, 47 insertions, 55 deletions
diff --git a/src/a0.c b/src/a0.c
index 5eed926..bee7ab9 100644
--- a/src/a0.c
+++ b/src/a0.c
@@ -13,11 +13,12 @@ algo_t a0 = {
.loop = a0_loop,
};
-static uint32_t *m;
+static uint32_t *m; //mammory
void a0_init(uint64_t n){
- size_t size;
+ size_t size; //size
+ t = 0;
size = sizeof(uint32_t)*n;
m = calloc(size,1);
if(!m) fuk("memory\n");
@@ -26,10 +27,10 @@ void a0_init(uint64_t n){
void a0_loop(uint64_t x0,uint64_t x1){
uint32_t x1_32 = x1;
for(uint32_t x = x0;x < x1_32;x++){
- uint32_t z;
- z = m[t];
+ uint32_t r; //index readed
+ r = m[t];
m[t] = x;
- t = z == 0 ? 0 : x-z;
+ t = r == 0 ? 0 : x-r;
}
}
diff --git a/src/a1.c b/src/a1.c
index 7cecf41..e47b0b0 100644
--- a/src/a1.c
+++ b/src/a1.c
@@ -3,7 +3,7 @@
#include <stdlib.h>
#include <string.h>
-#define BITS 36
+#define BITS 36
void a1_init (uint64_t n);
void a1_loop (uint64_t x0,uint64_t x1);
@@ -15,12 +15,12 @@ algo_t a1 = {
.loop = a1_loop,
};
-static uint8_t *m;
-static uint64_t load_store(uint64_t t,uint64_t i);
+static uint8_t *m; //mammory
void a1_init(uint64_t n){
- size_t size;
+ size_t size; //size
+ t = 0;
size = sizeof(uint8_t)*n*BITS>>3;
m = calloc(size,1);
if(!m) fuk("memory\n");
@@ -28,33 +28,24 @@ void a1_init(uint64_t n){
void a1_loop(uint64_t x0,uint64_t x1){
for(uint64_t x = x0;x < x1;x++){
- uint64_t z;
- z = load_store(t,x);
- t = z == 0 ? 0 : x-z;
+ uint8_t *p; //addr of first bytE
+ uint64_t r; //index readed
+ uint64_t w; //index to write
+
+ p = m+(t*BITS>>3);
+ r = 0;
+ w = x;
+ memcpy(&r,p,5);
+ if(t & 1){
+ r >>= 4;
+ w <<= 4;
+ w |= p[0] & 0x0F;
+ }else{
+ r &= 0x0000000FFFFFFFFF;
+ w |= (uint64_t)(p[4] & 0xF0)<<32;
+ }
+ memcpy(p,&w,5);
+ t = r == 0 ? 0 : x-r;
}
}
-static uint64_t load_store(uint64_t t,uint64_t i){
- uint64_t r;
- uint8_t *p;
-
- r = 0;
- p = m+(t*BITS>>3);
- memcpy(&r,p,5);
- if(t & 1){
- r >>= 4;
- }else{
- r &= 0x0000000FFFFFFFFF;
- }
-
- if(t & 1){
- i <<= 4;
- i |= p[0] & 0x0F;
- }else{
- i |= (uint64_t)(p[4] & 0xF0)<<32;
- }
- memcpy(p,&i,5);
-
- return r;
-}
-
diff --git a/src/a2.c b/src/a2.c
index d0d735b..13dcc87 100644
--- a/src/a2.c
+++ b/src/a2.c
@@ -3,7 +3,7 @@
#include <stdlib.h>
#include <string.h>
-#define W 3
+#define WIDTH 3
void a2_init (uint64_t n);
void a2_loop (uint64_t x0,uint64_t x1);
@@ -15,28 +15,28 @@ algo_t a2 = {
.loop = a2_loop,
};
-static uint8_t *m;
+static uint8_t *m; //mammory
void a2_init(uint64_t n){
- size_t size;
+ size_t size; //size
- size = sizeof(uint8_t)*W*n;
- m = aalloc(4096,size);
- memset(m,0xFF,size);
+ t = 0;
+ size = sizeof(uint8_t)*WIDTH*n;
+ m = calloc(size,1);
if(!m) fuk("memory\n");
}
void a2_loop(uint64_t x0,uint64_t x1){
uint32_t x1_32 = x1;
for(uint32_t x = x0;x < x1_32;x++){
- uint32_t z;
- uint8_t *p;
-
- z = 0;
- p = &m[t*W];
- memcpy(&z,p,W);
- memcpy(p,&x,W);
- t = z == 0x00FFFFFF ? 0 : x-z;
+ uint32_t r; //index readed
+ uint8_t *p; //addr of elemten
+
+ r = 0;
+ p = &m[t*WIDTH];
+ memcpy(&r,p,WIDTH);
+ memcpy(p,&x,WIDTH);
+ t = r == 0 ? 0 : x-r;
}
}
diff --git a/src/main.c b/src/main.c
index 44a1838..69a8007 100644
--- a/src/main.c
+++ b/src/main.c
@@ -9,11 +9,9 @@
#include <windows.h>
#endif
-uint64_t t;
-
-static ftimer_t ft;
-
-static algo_t *algo;
+uint64_t t; //termik
+static ftimer_t ft; //timmer
+static algo_t *algo; //vat tek 2 usE
void fuk(char const *fmt,...){
va_list args;
@@ -112,12 +110,14 @@ int main(int argc,char **argv){
printf("n = %llu\n",n);
fflush(stdout);
+ //for(size_t x = 0;x < 10;x++){
algo->init(n);
ftimer_init(&ft);
calc(n);
printf("t = %llu\n",t);
fflush(stdout);
+ //}
return 0;
}