From 8c4ff011886f9e4b5f90298fd59b6c6a5522fd5e Mon Sep 17 00:00:00 2001
From: Yuya Hamamachi <yuya.hamamachi.sx@renesas.com>
Date: Wed, 15 Feb 2023 17:04:59 +0900
Subject: [PATCH 8/9] vm_atk2: vm2_atk2: Add dhrystone benchmark

Signed-off-by: Yuya Hamamachi <yuya.hamamachi.sx@renesas.com>
---
 .gitignore                     |  1 +
 vm_atk2/Makefile.ccrh          |  4 +--
 vm_atk2/Makefile.ghs           |  4 +--
 vm_atk2/vm2_atk2/Makefile      |  6 ++++
 vm_atk2/vm2_atk2/dhry.h        |  1 +
 vm_atk2/vm2_atk2/dhry_1.c      |  1 +
 vm_atk2/vm2_atk2/dhry_2.c      |  1 +
 vm_atk2/vm2_atk2/sample1_vm2.c | 58 +++++++++++++++++++++++++++++++++-
 8 files changed, 71 insertions(+), 5 deletions(-)
 create mode 120000 vm_atk2/vm2_atk2/dhry.h
 create mode 120000 vm_atk2/vm2_atk2/dhry_1.c
 create mode 120000 vm_atk2/vm2_atk2/dhry_2.c

diff --git a/.gitignore b/.gitignore
index f86968e..48fa4e6 100644
--- a/.gitignore
+++ b/.gitignore
@@ -6,3 +6,4 @@
 *.map
 Makefile.depend
 depend
+dhrystone*
\ No newline at end of file
diff --git a/vm_atk2/Makefile.ccrh b/vm_atk2/Makefile.ccrh
index f78558c..38c1e42 100644
--- a/vm_atk2/Makefile.ccrh
+++ b/vm_atk2/Makefile.ccrh
@@ -198,10 +198,10 @@ APPL_CFG_INPUT := $(foreach file,$(CFGNAME),$(file).arxml)
 APPL_DIR = $(APPLDIR) $(SRCDIR)/library
 APPL_ASMOBJS = hvc_asm.obj
 ifdef USE_CXX
-  APPL_CXXOBJS = $(APPLNAME).obj 
+  APPL_CXXOBJS = $(APPLNAME).obj $(ADD_OBJ)
   APPL_COBJS =
 else
-  APPL_COBJS = $(APPLNAME).obj 
+  APPL_COBJS = $(APPLNAME).obj $(ADD_OBJ)
 endif
 APPL_CFLAGS =
 APPL_LIBS =
diff --git a/vm_atk2/Makefile.ghs b/vm_atk2/Makefile.ghs
index e4c91ef..f2d150c 100644
--- a/vm_atk2/Makefile.ghs
+++ b/vm_atk2/Makefile.ghs
@@ -205,10 +205,10 @@ APPL_CFG_INPUT := $(foreach file,$(CFGNAME),$(file).arxml)
 APPL_DIR = $(APPLDIR) $(SRCDIR)/library
 APPL_ASMOBJS = hvc_asm.o
 ifdef USE_CXX
-  APPL_CXXOBJS = $(APPLNAME).o 
+  APPL_CXXOBJS = $(APPLNAME).o $(ADD_OBJ)
   APPL_COBJS =
 else
-  APPL_COBJS = $(APPLNAME).o 
+  APPL_COBJS = $(APPLNAME).o $(ADD_OBJ)
 endif
 APPL_CFLAGS =
 APPL_LIBS =
diff --git a/vm_atk2/vm2_atk2/Makefile b/vm_atk2/vm2_atk2/Makefile
index 7b55690..1bbbb73 100644
--- a/vm_atk2/vm2_atk2/Makefile
+++ b/vm_atk2/vm2_atk2/Makefile
@@ -23,10 +23,16 @@ endif
 
 OBJNAME = atk2-sc1_vm2
 
+CDEFS := $(CDEFS) -DTIME
+
 ifeq ($(COMPILER),GHS)
+CDEFS := $(CDEFS) -D__GHS_HEAP__
+ADD_OBJ = dhry_1.o dhry_2.o
 include ../Makefile.ghs
 endif
 
 ifeq ($(COMPILER),CCRH)
+LDFLAGS := -library=lib\\v850e3v5\\libmalloc.lib
+ADD_OBJ = dhry_1.obj dhry_2.obj
 include ../Makefile.ccrh
 endif
diff --git a/vm_atk2/vm2_atk2/dhry.h b/vm_atk2/vm2_atk2/dhry.h
new file mode 120000
index 0000000..26a896f
--- /dev/null
+++ b/vm_atk2/vm2_atk2/dhry.h
@@ -0,0 +1 @@
+./dhrystone/dhry.h
\ No newline at end of file
diff --git a/vm_atk2/vm2_atk2/dhry_1.c b/vm_atk2/vm2_atk2/dhry_1.c
new file mode 120000
index 0000000..7cd1b64
--- /dev/null
+++ b/vm_atk2/vm2_atk2/dhry_1.c
@@ -0,0 +1 @@
+./dhrystone/dhry_1.c
\ No newline at end of file
diff --git a/vm_atk2/vm2_atk2/dhry_2.c b/vm_atk2/vm2_atk2/dhry_2.c
new file mode 120000
index 0000000..aa840d6
--- /dev/null
+++ b/vm_atk2/vm2_atk2/dhry_2.c
@@ -0,0 +1 @@
+./dhrystone/dhry_2.c
\ No newline at end of file
diff --git a/vm_atk2/vm2_atk2/sample1_vm2.c b/vm_atk2/vm2_atk2/sample1_vm2.c
index 0ac63f7..5edcbfb 100644
--- a/vm_atk2/vm2_atk2/sample1_vm2.c
+++ b/vm_atk2/vm2_atk2/sample1_vm2.c
@@ -546,6 +546,58 @@ static const char8			*alarm_name_tbl[] = {
 volatile uint32 g_timer_cnt = 0;
 #define TICK_TO_MSEC(n) (n*10)
 #define TICK_TO_SEC(n)  (n/100)
+uint32 time() {return TICK_TO_SEC(g_timer_cnt);}
+
+/**
+ * Benchmark related definision
+*/
+#ifdef __GHS_HEAP__
+#define HEAPSIZE 4096
+volatile char __ghsend_heap[HEAPSIZE*2];
+volatile char* __ghsbegin_heap = &__ghsend_heap[HEAPSIZE*2-1];
+#endif
+volatile uint8 shared_memory[16][16];
+volatile uint8 result_array[4][17];
+extern void dhrystone_main(void);
+void float_to_char(uint8 input_array[], float input) {
+  uint8 i, n;
+  uint8 ascii_offset = 0x20; // 0x30 = '0' / 0x20 = ' '
+  float tmp;
+
+  for (i=0; i<16; ++i){
+    tmp = input;
+    if (i < 8) {
+      for(n=i+1; n<8;++n)
+        tmp = tmp / 10;
+    }
+    else {
+      for(n=7; n<i; ++n)
+        tmp = tmp * 10;
+    }
+
+    if((int)tmp%10 != 0 || i == 7)
+      ascii_offset = 0x30; // changed at once
+
+    input_array[i+(i/8)] = (ascii_offset + (int)tmp%10); // if (i==8) i+1, else i
+  }
+  input_array[8] = '.';
+  input_array[16] = '\0';
+}
+void int_to_char(uint8 input_array[], int input) {
+  uint8 i, n;
+  uint8 ascii_offset = 0x20; // 0x30 = '0' / 0x20 = ' '
+  int tmp;
+
+  for (i=0; i<16; ++i){
+    tmp = input;
+      for(n=i+1; n<16;++n)
+        tmp = tmp / 10;
+    if((int)tmp%10 != 0)
+      ascii_offset = 0x30; // changed at once
+
+    input_array[i] = (ascii_offset + (int)tmp%10); // if (i==8) i+1, else i
+  }
+}
 
 /*
  *  ユーザメイン関数
@@ -686,7 +738,11 @@ TASK(Task3)
 	uint32 wait_cnt = 0;
 	uint32 dummy = 0;
 	syslog(LOG_INFO, "TASK3 is called");
-	
+
+	dhrystone_main();
+
+	ms_sleep(100);
+
 	while (1) {
 		ms_sleep(1000);
 		syslog(LOG_INFO, "g_timer_cnt = %u", g_timer_cnt);
-- 
2.34.1

