summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjonsykkel <jonrevold@gmail.com>2020-04-05 03:44:06 +0200
committerjonsykkel <jonrevold@gmail.com>2020-04-05 03:44:06 +0200
commitb2b31f9b12e2ce07902106a0e95118d469cf45ab (patch)
tree54713878148862bbfd79f185071b1f1848b9c329
parent423572799b8fcb456780efd2522ad0eec167c733 (diff)
downloadct_sequence-numper3.tar.gz
-rw-r--r--src/def.h4
-rw-r--r--src/ftime.c9
-rw-r--r--src/ftime.h49
-rw-r--r--src/ftimer.c86
-rw-r--r--src/ftimer.h30
-rw-r--r--src/main.c7
6 files changed, 180 insertions, 5 deletions
diff --git a/src/def.h b/src/def.h
index ebaa1bd..0540636 100644
--- a/src/def.h
+++ b/src/def.h
@@ -12,13 +12,9 @@ typedef struct algo_t{
}algo_t;
extern uint64_t t;
-
extern algo_t a1;
extern algo_t a3;
-void a1_init (uint64_t n);
-void a1_loop (uint64_t x0,uint64_t x1);
-
void fuk (char const *fmt,...);
#endif
diff --git a/src/ftime.c b/src/ftime.c
new file mode 100644
index 0000000..ec4a963
--- /dev/null
+++ b/src/ftime.c
@@ -0,0 +1,9 @@
+#include "ftime.h"
+
+extern ftime_t ftime_add (ftime_t t1,ftime_t t2);
+extern ftime_t ftime_sub (ftime_t t1,ftime_t t2);
+extern ftime_t ftime_muli (ftime_t t,int64_t i);
+extern ftime_t ftime_divi (ftime_t t,int64_t i);
+
+extern float ftime_float(ftime_t t);
+
diff --git a/src/ftime.h b/src/ftime.h
new file mode 100644
index 0000000..74538b3
--- /dev/null
+++ b/src/ftime.h
@@ -0,0 +1,49 @@
+#ifndef OKE_FTIME_H
+#define OKE_FTIME_H
+
+#include <stdint.h>
+
+#define FTIME_SEC 0x100000000LL
+
+typedef int64_t ftime_t;
+
+inline ftime_t ftime_add (ftime_t t1,ftime_t t2);
+inline ftime_t ftime_sub (ftime_t t1,ftime_t t2);
+inline ftime_t ftime_muli (ftime_t t,int64_t i);
+inline ftime_t ftime_divi (ftime_t t,int64_t i);
+
+inline float ftime_float(ftime_t t);
+
+////////////////////////////////////////////////////////////////
+
+inline ftime_t ftime_add(ftime_t t1,ftime_t t2){
+ ftime_t r;
+ r = t1+t2;
+ return r;
+}
+
+inline ftime_t ftime_sub(ftime_t t1,ftime_t t2){
+ ftime_t r;
+ r = t1-t2;
+ return r;
+}
+
+inline ftime_t ftime_muli(ftime_t t,int64_t i){
+ ftime_t r;
+ r = t*i;
+ return r;
+}
+
+inline ftime_t ftime_divi(ftime_t t,int64_t i){
+ ftime_t r;
+ r = t/i;
+ return r;
+}
+
+inline float ftime_float(ftime_t t){
+ float f;
+ f = (float)t/(float)FTIME_SEC;
+ return f;
+}
+
+#endif
diff --git a/src/ftimer.c b/src/ftimer.c
new file mode 100644
index 0000000..aea1976
--- /dev/null
+++ b/src/ftimer.c
@@ -0,0 +1,86 @@
+#include "ftimer.h"
+
+#ifdef _WIN32
+#include <windows.h>
+static int64_t _freq (void);
+#else
+ #define NSEC_MAX 1000000000
+#endif
+static _ostime_t _time (void);
+static ftime_t _diff (ftimer_t const *ftimer,_ostime_t t1,_ostime_t t2);
+
+void ftimer_init(ftimer_t *ftimer){
+#ifdef _WIN32
+ ftimer->freq = _freq();
+#endif
+ ftimer->zero = _time();
+}
+
+void ftimer_zero(ftimer_t *ftimer){
+ ftimer->zero = _time();
+}
+
+ftime_t ftimer_time(ftimer_t const *ftimer){
+ return _diff(ftimer,_time(),ftimer->zero);
+ //return (double)(count-ftimer->zero)/(double)ftimer->freq;
+}
+
+#ifdef _WIN32
+
+static int64_t _freq(void){
+ LARGE_INTEGER li;
+ QueryPerformanceFrequency(&li);
+ return li.QuadPart;
+}
+
+static _ostime_t _time(void){
+ LARGE_INTEGER li;
+ QueryPerformanceCounter(&li);
+ return li.QuadPart;
+}
+
+static ftime_t _diff(ftimer_t const *ftimer,_ostime_t t1,_ostime_t t2){
+ ftime_t ft;
+ int64_t freq;
+ int64_t diff;
+ int64_t frc;
+
+ freq = ftimer->freq;
+ diff = t1-t2;
+ ft = (diff/freq)<<32;
+ frc = (diff%freq)<<32;
+ frc /= freq;
+ ft |= frc;
+
+ return ft;
+}
+
+#else
+
+static _ostime_t _time(void){
+ struct timespec ts;
+ clock_gettime(CLOCK_MONOTONIC,&ts);
+ return ts;
+}
+
+static ftime_t _diff(ftimer_t const *ftimer,_ostime_t t1,_ostime_t t2){
+ (void)ftimer;
+ ftime_t ft;
+ int32_t diff_sec;
+ int64_t diff_nsec;
+
+ diff_sec = t1.tv_sec-t2.tv_sec;
+ diff_nsec = t1.tv_nsec-t2.tv_nsec;
+
+ if(diff_nsec < 0){
+ diff_nsec += NSEC_MAX;
+ diff_sec -= 1;
+ }
+
+ ft = (int64_t)diff_sec<<32;
+ ft |= (diff_nsec<<32)/NSEC_MAX;
+ return ft;
+}
+
+#endif
+
diff --git a/src/ftimer.h b/src/ftimer.h
new file mode 100644
index 0000000..b5bf93d
--- /dev/null
+++ b/src/ftimer.h
@@ -0,0 +1,30 @@
+#ifndef OKE_FTIMER_H
+#define OKE_FTIMER_H
+
+#include "ftime.h"
+#ifdef _WIN32
+ #include <stdint.h>
+#else
+ #include <time.h>
+#endif
+
+#ifdef _WIN32
+typedef int64_t _ostime_t;
+#else
+typedef struct timespec _ostime_t;
+#endif
+
+typedef struct ftimer_t{
+#ifdef _WIN32
+ int64_t freq;
+#endif
+ _ostime_t zero;
+}ftimer_t;
+
+void ftimer_init(ftimer_t *ftimer);
+
+void ftimer_zero(ftimer_t *ftimer);
+ftime_t ftimer_time(ftimer_t const *ftimer);
+
+#endif
+
diff --git a/src/main.c b/src/main.c
index 693ae4b..59ee7e8 100644
--- a/src/main.c
+++ b/src/main.c
@@ -1,8 +1,13 @@
#include "def.h"
+#include "ftimer.h"
#include <stdio.h>
#include <stdint.h>
#include <string.h>
-#include <okelib2/okelib2.h>
+#include <stdarg.h>
+#include <stdlib.h>
+#ifdef _WIN32
+ #include <windows.h>
+#endif
uint64_t t;