Skip to content

Commit d7ac3da

Browse files
committed
Run coremark with floats enabled
1 parent 739ab85 commit d7ac3da

File tree

5 files changed

+59
-26
lines changed

5 files changed

+59
-26
lines changed

Makefile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ rust: $(RUST_PROGRAMS)
1414

1515
.PHONY: coremark
1616
coremark:
17-
cd coremark/coremark && $(MAKE) PORT_DIR=../mlogv32 ITERATIONS=10 load
17+
cd coremark/coremark && $(MAKE) PORT_DIR=../mlogv32 ITERATIONS=10 clean load
1818

1919
$(ASM_PROGRAMS): %: build/%.bin build/%.dump
2020

coremark/mlogv32/core_portme.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ Original Author: Shay Gal-on
2929
Define to 1 if the platform supports floating point.
3030
*/
3131
#ifndef HAS_FLOAT
32-
#define HAS_FLOAT 0
32+
#define HAS_FLOAT 1
3333
#endif
3434
/* Configuration : HAS_TIME_H
3535
Define to 1 if platform has the time.h header file,
@@ -70,8 +70,7 @@ Original Author: Shay Gal-on
7070
#endif
7171
#endif
7272
#ifndef COMPILER_FLAGS
73-
#define COMPILER_FLAGS \
74-
FLAGS_STR /* "Please put compiler flags here (e.g. -o3)" */
73+
#define COMPILER_FLAGS FLAGS_STR
7574
#endif
7675
#ifndef MEM_LOCATION
7776
#define MEM_LOCATION "STACK"

coremark/mlogv32/core_portme.mak

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -32,30 +32,30 @@ LD = riscv32-unknown-elf-gcc
3232
AS = riscv32-unknown-elf-gcc
3333
# Flag : CFLAGS
3434
# Use this flag to define compiler options. Note, you can add compiler options from the command line using XCFLAGS="other flags"
35-
PORT_CFLAGS = -march=$(RISCV_ARCH) --compile -O0 -g -nostdlib -nostartfiles
36-
FLAGS_STR = "$(PORT_CFLAGS) $(XCFLAGS) $(XLFLAGS) $(LFLAGS_END)"
37-
CFLAGS = $(PORT_CFLAGS) -I$(PORT_DIR) -I. -DFLAGS_STR=\"$(FLAGS_STR)\"
35+
PORT_CFLAGS = -march=$(RISCV_ARCH) -O0 -g -ffreestanding
36+
FLAGS_STR = "$(strip $(PORT_CFLAGS) $(XCFLAGS) $(XLFLAGS) $(LFLAGS_END)) "
37+
CFLAGS = $(PORT_CFLAGS) --compile -I$(PORT_DIR) -I. -DFLAGS_STR=\"$(FLAGS_STR)\"
3838
#Flag : LFLAGS_END
3939
# Define any libraries needed for linking or other flags that should come at the end of the link line (e.g. linker scripts).
4040
# Note : On certain platforms, the default clock_gettime implementation is supported but requires linking of librt.
4141
SEPARATE_COMPILE=1
4242
# Flag : SEPARATE_COMPILE
4343
# You must also define below how to create an object file, and how to link.
4444
OBJOUT = -o
45-
LFLAGS = -T$(PORT_DIR)/../../rust/mlogv32/link.x -nostartfiles
45+
LFLAGS = -T$(PORT_DIR)/../../rust/mlogv32/link.x
4646
ASFLAGS = --compile
4747
OFLAG = -o
4848
COUT = -c
4949

50-
LFLAGS_END =
50+
LFLAGS_END = -nostartfiles -nolibc
5151
# Flag : PORT_SRCS
5252
# Port specific source files can be added here
5353
# You may also need cvt.c if the fcvt functions are not provided as intrinsics by your compiler!
54-
PORT_SRCS = $(PORT_DIR)/core_portme.c $(PORT_DIR)/ee_printf.c $(PORT_DIR)/ecall.c $(PORT_DIR)/entry.s
54+
PORT_SRCS = $(PORT_DIR)/core_portme.c $(PORT_DIR)/ee_printf.c $(PORT_DIR)/ecall.c $(PORT_DIR)/entry.s $(PORT_DIR)/cvt.c
5555
vpath %.c $(PORT_DIR)
5656
vpath %.s $(PORT_DIR)
5757

58-
PORT_OBJS = $(PORT_DIR)/core_portme.o $(PORT_DIR)/ee_printf.o $(PORT_DIR)/ecall.o $(PORT_DIR)/entry.o
58+
PORT_OBJS = $(PORT_DIR)/core_portme.o $(PORT_DIR)/ee_printf.o $(PORT_DIR)/ecall.o $(PORT_DIR)/entry.o $(PORT_DIR)/cvt.o
5959

6060
# Flag : LOAD
6161
# For a simple port, we assume self hosted compile and run, no load needed.

coremark/mlogv32/cvt.c

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,42 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1313
See the License for the specific language governing permissions and
1414
limitations under the License.
1515
*/
16-
#include <math.h>
1716
#define CVTBUFSIZE 80
1817
static char CVTBUF[CVTBUFSIZE];
1918

19+
double modf(double x, double *iptr)
20+
{
21+
union {double f; unsigned long long i;} u = {x};
22+
unsigned long long mask;
23+
int e = (int)(u.i>>52 & 0x7ff) - 0x3ff;
24+
25+
/* no fractional part */
26+
if (e >= 52) {
27+
*iptr = x;
28+
if (e == 0x400 && u.i<<12 != 0) /* nan */
29+
return x;
30+
u.i &= 1ULL<<63;
31+
return u.f;
32+
}
33+
34+
/* no integral part*/
35+
if (e < 0) {
36+
u.i &= 1ULL<<63;
37+
*iptr = u.f;
38+
return x;
39+
}
40+
41+
mask = -1ULL>>12>>e;
42+
if ((u.i & mask) == 0) {
43+
*iptr = x;
44+
u.i &= 1ULL<<63;
45+
return u.f;
46+
}
47+
u.i &= ~mask;
48+
*iptr = u.f;
49+
return x - u.f;
50+
}
51+
2052
static char *
2153
cvt(double arg, int ndigits, int *decpt, int *sign, char *buf, int eflag)
2254
{

coremark/mlogv32/ee_printf.c

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -660,7 +660,7 @@ ee_vsprintf(char *buf, const char *fmt, va_list args)
660660
return str - buf;
661661
}
662662

663-
static unsigned int print_width = 0;
663+
static unsigned int print_x = 7;
664664
static unsigned int print_y = 508;
665665

666666
void
@@ -670,7 +670,7 @@ uart_send_char(char c)
670670
}
671671

672672
void init_printf() {
673-
print_width = 0;
673+
print_x = 7;
674674
print_y = 508;
675675
ecall(0, 0, 0, 0, 0, 0, 0, DrawReset);
676676
ecall(0, 0, 0, 0, 0, 0, 0, DrawClear);
@@ -685,31 +685,33 @@ ee_printf(const char *fmt, ...)
685685
va_list args;
686686
int n = 0;
687687

688-
int new_print_y = print_y;
688+
int old_print_x = print_x;
689+
int old_print_y = print_y;
689690

690691
va_start(args, fmt);
691692
ee_vsprintf(buf, fmt, args);
692693
va_end(args);
693694
p = buf;
694695
while (*p)
695696
{
696-
uart_send_char(*p);
697-
n++;
698-
p++;
699-
print_width += 1;
700-
if (*p == '\n' || print_width > 70) {
701-
if (print_width > 70) {
697+
if (*p == '\n') {
698+
print_x = 7;
699+
print_y -= 13;
700+
} else {
701+
print_x += 7;
702+
if (print_x > 504) {
702703
uart_send_char('\n');
704+
print_x = 7;
705+
print_y -= 13;
703706
}
704-
new_print_y -= 13;
705-
print_width = 0;
706707
}
708+
uart_send_char(*p);
709+
n++;
710+
p++;
707711
}
708712

709-
ecall(7, print_y, 7, 0, 0, 0, 0, DrawPrint);
713+
ecall(old_print_x, old_print_y, 7, 0, 0, 0, 0, DrawPrint);
710714
ecall(0, 0, 0, 0, 0, 0, 0, DrawFlush);
711-
print_width = 0;
712-
print_y = new_print_y;
713715

714716
return n;
715717
}

0 commit comments

Comments
 (0)